【发布时间】:2018-03-18 20:41:30
【问题描述】:
我想将 @test:registry = 值更新为它从 package.json 调用的 myNode.js 进程 我试图更新所有的环境,但没有奏效。 是否可以从 childproc.execSync 做到这一点?
package.json
{
"name": "test1",
"scripts": {
"postinstall": "node myNode.js",
"start": "node node_modules/xx"
}
}
myNode.js
childproc.execSync('npm install && npm run build', { cwd: '..', shell: true, stdio: 'inherit' , env : {env:process.env}})
我也试过了
childproc.execSync('npm install && npm run build', { cwd: '..', shell: true, stdio: 'inherit' , env : {env:{ 'npm_config__test_registry':value}})
然后我得到 /bin/sh: 1: npm: not foundchild_process.js:644 throw err; ^
我在创建 childproc 之前尝试打印 process.env,然后我看到了我的相关设置,但是当我尝试使用 npm config list 在 childProc 中检查它时,我看到了不同的值
当我尝试时
childproc.execSync('npm config set @test:registry:value && npm install && npm run build', { cwd: '..', shell: true, stdio: 'inherit' })
然后它起作用了。是否可以使用 execSync 中的 env 来做到这一点
【问题讨论】:
标签: javascript node.js npm