我有一个单一的环境变量需要在preinstall
期间设置(我的npm令牌需要在.npmrc
中使用以获取私有软件包)。这个特定的环境变量存储在我正在使用的配置服务(Firebase)中,因此需要从服务中获取并添加到环境中。
我尝试过各种方式,例如在节点脚本中获取它并尝试通过stdout捕获:
const { spawnSync } = require( 'child_process' );
const ls = spawnSync( 'firebase', [ 'functions:config:get', 'npm.read_only' ] );
JSON.parse(ls.stdout.toString());
// Printing this shows the correct token
我最新的尝试是这样的:
#!/bin/sh
echo 'Setting up development env';
NPM_READ_ONLY_TOKEN=`firebase functions:config:get npm.read_only`
export NPM_READ_ONLY_TOKEN=$(eval echo $NPM_READ_ONLY_TOKEN)
echo 'NPM_READ_ONLY_TOKEN => '$NPM_READ_ONLY_TOKEN;
# Prints the correct token on the screen
exit 0;
但是,当运行"./configEnv.sh && echo $NPM_READ_ONLY_TOKEN"
命令时,环境变量为空。
我该怎么做才能实现呢?