npm如何运行一个脚本来设置另一个npm运行脚本可以使用的系统环境

我在npm的package.json中设置了几个脚本,例如

{ "scripts": { "server:install": ". ./scripts/server-install.sh", "server:start": ". ./scripts/server-start.sh", "server:stop": ". ./scripts/server-stop.sh", "test:e2e": "jest --collectCoverage false test/**/*" } } 

server-start.sh ,我将在本地启动dynamoDB服务,并需要设置系统环境AWS_API_KEY值。 当npm run test:e2e时,该值将用于testing用例。

但问题是我在server:startAWS_API_KEY设置的值不能在test:e2e 。 看起来,server-start.sh中的variables集操作不会改变当前控制台/会话的系统variables。

我googlesearch,并尝试像:

 "server:start": "AWS_API_KEY=dummy . ./scripts/server-start.sh" 

或通过使用交叉环境

 "server:start": "cross-env-shell AWS_API_KEY=dummy && . ./scripts/server-start.sh" 

两个失败。 我能想到的唯一的想法就是将AWS_API_KEY写入〜/ .bash_profile。 我不想这样做。

任何帮助都感激不尽。