Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update node-preload and use process-on-spawn #1243

Merged
merged 1 commit into from Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions bin/nyc.js
Expand Up @@ -52,15 +52,20 @@ async function main () {
}

if (!argv.useSpawnWrap) {
const { preloadAppend, propagateEnv } = require('node-preload')

nyc.require.forEach(requireModule => {
const mod = resolveFrom.silent(nyc.cwd, requireModule) || requireModule
preloadAppend(mod)
const requireModules = [
require.resolve('../lib/register-env.js'),
...nyc.require.map(mod => resolveFrom.silent(nyc.cwd, mod) || mod)
]
const preloadList = require('node-preload')
preloadList.push(
...requireModules,
require.resolve('../lib/wrap.js')
)

Object.assign(process.env, env)
requireModules.forEach(mod => {
require(mod)
})
preloadAppend(require.resolve('../lib/wrap.js'))
Object.assign(propagateEnv, env)
}

if (argv.all) {
Expand Down
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -365,8 +365,8 @@ class NYC {
// This is a bug with the spawn-wrap method where
// we cannot force propagation of NYC_PROCESS_ID.
if (!this.config.useSpawnWrap) {
const { propagateEnv } = require('node-preload')
propagateEnv.NYC_PROCESS_ID = this.processInfo.uuid
const updateVariable = require('./lib/register-env.js')
updateVariable('NYC_PROCESS_ID')
}
this._addRequireHooks()
this._wrapExit()
Expand Down
27 changes: 27 additions & 0 deletions lib/register-env.js
@@ -0,0 +1,27 @@
'use strict'

const processOnSpawn = require('process-on-spawn')

const envToCopy = {}

processOnSpawn.addListener(({ env }) => {
Object.assign(env, envToCopy)
})

const copyAtLoad = [
'NYC_CONFIG',
'NYC_CWD',
'NYC_PROCESS_ID',
'BABEL_DISABLE_CACHE',
'NYC_PROCESS_ID'
]

for (const env of copyAtLoad) {
if (env in process.env) {
envToCopy[env] = process.env[env]
}
}

module.exports = function updateVariable (envName) {
envToCopy[envName] = process.env[envName]
}