node-preload
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.1.4](https://github.com/cfware/node-preload/compare/v0.1.3...v0.1.4) (2019-11-01) | ||
### Features | ||
* Support running under yarn pnp ([#3](https://github.com/cfware/node-preload/issues/3)) ([15d949b](https://github.com/cfware/node-preload/commit/15d949b)), closes [istanbuljs/nyc#1204](https://github.com/istanbuljs/nyc/issues/1204) | ||
### [0.1.3](https://github.com/cfware/node-preload/compare/v0.1.2...v0.1.3) (2019-10-07) | ||
@@ -7,0 +14,0 @@ |
@@ -14,9 +14,9 @@ 'use strict'; | ||
function processNodePath(value) { | ||
function processNodePath(value, dir) { | ||
const existing = value === '' ? [] : value.split(path.delimiter); | ||
if (existing.includes(__dirname)) { | ||
if (existing.includes(dir)) { | ||
return value; | ||
} | ||
return existing.concat(__dirname).join(path.delimiter); | ||
return existing.concat(dir).join(path.delimiter); | ||
} | ||
@@ -27,3 +27,3 @@ | ||
processNodePath, | ||
needsPathEnv: __dirname.includes(' ') | ||
needsPathEnv: dir => dir.includes(' ') | ||
}; |
@@ -11,3 +11,3 @@ 'use strict'; | ||
processNodePath: undefined, | ||
needsPathEnv: false | ||
needsPathEnv: () => false | ||
}; |
@@ -68,2 +68,5 @@ 'use strict'; | ||
const nodeOptionRequireSelf = generateRequire(require.resolve('./node-preload.js')); | ||
/* istanbul ignore next: yarn specific */ | ||
const pnpapiFile = () => process.versions.pnp && require.resolve('pnpapi'); | ||
const preloadList = loadPreloadList(); | ||
@@ -74,11 +77,24 @@ const propagate = loadPropagated(); | ||
function processNodeOptions(value) { | ||
if (value.includes(nodeOptionRequireSelf)) { | ||
return value; | ||
/* istanbul ignore next: yarn specific */ | ||
const requirePNPAPI = (process.versions.pnp && generateRequire(pnpapiFile())) || ''; | ||
/* istanbul ignore next: yarn specific */ | ||
if (process.versions.pnp) { | ||
/* Need pnpapi to be first, remove so we can reinsert before node-preload */ | ||
value = value.replace(requirePNPAPI, ''); | ||
} | ||
if (value !== '') { | ||
value = ' ' + value; | ||
if (!value.includes(nodeOptionRequireSelf)) { | ||
if (value !== '') { | ||
value = ' ' + value; | ||
} | ||
value = `${nodeOptionRequireSelf}${value}`; | ||
} | ||
return `${nodeOptionRequireSelf}${value}`; | ||
/* istanbul ignore next: yarn specific */ | ||
if (process.versions.pnp) { | ||
value = `${requirePNPAPI} ${value}`; | ||
} | ||
return value; | ||
} | ||
@@ -99,6 +115,14 @@ | ||
/* istanbul ignore next */ | ||
if (needsPathEnv) { | ||
env.NODE_PATH = processNodePath(env.NODE_PATH || ''); | ||
if (needsPathEnv(__dirname)) { | ||
env.NODE_PATH = processNodePath(env.NODE_PATH || '', __dirname); | ||
} | ||
/* istanbul ignore next: yarn specific */ | ||
if (process.versions.pnp) { | ||
const pnpapiDir = path.dirname(pnpapiFile()); | ||
if (needsPathEnv(pnpapiDir)) { | ||
env.NODE_PATH = processNodePath(env.NODE_PATH || '', pnpapiDir); | ||
} | ||
} | ||
env.NODE_POLYFILL_PROPAGATE_ENV = JSON.stringify(Object.keys(propagate)); | ||
@@ -105,0 +129,0 @@ Object.entries(propagate).forEach(([name, value]) => { |
{ | ||
"name": "node-preload", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Request that Node.js child processes preload modules", | ||
@@ -5,0 +5,0 @@ "scripts": { |
12307
223