-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Uses NODE_OPTIONS with PnP instead of CLI args #6629
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,16 @@ export function hasWrapper(commander: Object, args: Array<string>): boolean { | |
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> { | ||
const pnpPath = `${config.lockfileFolder}/${PNP_FILENAME}`; | ||
|
||
let nodeOptions = process.env.NODE_OPTIONS || ''; | ||
if (await fs.exists(pnpPath)) { | ||
args = ['-r', pnpPath, ...args]; | ||
nodeOptions += ` --require ${pnpPath}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing the leading space wouldn't be an issue when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, will work 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
try { | ||
await child.spawn(NODE_BIN_PATH, args, { | ||
stdio: 'inherit', | ||
cwd: flags.into || config.cwd, | ||
env: {...process.env, NODE_OPTIONS: nodeOptions}, | ||
}); | ||
} catch (err) { | ||
throw err; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,6 @@ export const IGNORE_MANIFEST_KEYS: Set<string> = new Set(['readme', 'notice', 'l | |
// See https://github.com/yarnpkg/yarn/issues/2286. | ||
const IGNORE_CONFIG_KEYS = ['lastUpdateCheck']; | ||
|
||
async function getPnpParameters(config: Config): Promise<Array<string>> { | ||
if (await fs.exists(`${config.lockfileFolder}/${constants.PNP_FILENAME}`)) { | ||
return ['-r', `${config.lockfileFolder}/${constants.PNP_FILENAME}`]; | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
let wrappersFolder = null; | ||
|
||
export async function getWrappersFolder(config: Config): Promise<string> { | ||
|
@@ -45,7 +37,6 @@ export async function getWrappersFolder(config: Config): Promise<string> { | |
|
||
await makePortableProxyScript(process.execPath, wrappersFolder, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we unify this logic in the future and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? At most we should replace |
||
proxyBasename: 'node', | ||
prependArguments: [...(await getPnpParameters(config))], | ||
}); | ||
|
||
await makePortableProxyScript(process.execPath, wrappersFolder, { | ||
|
@@ -212,8 +203,9 @@ export async function makeEnv( | |
} | ||
} | ||
|
||
if (await fs.exists(`${config.lockfileFolder}/${constants.PNP_FILENAME}`)) { | ||
const pnpApi = dynamicRequire(`${config.lockfileFolder}/${constants.PNP_FILENAME}`); | ||
const pnpFile = `${config.lockfileFolder}/${constants.PNP_FILENAME}`; | ||
if (await fs.exists(pnpFile)) { | ||
const pnpApi = dynamicRequire(pnpFile); | ||
|
||
const packageLocator = pnpApi.findPackageLocator(`${config.cwd}/`); | ||
const packageInformation = pnpApi.getPackageInformation(packageLocator); | ||
|
@@ -227,6 +219,11 @@ export async function makeEnv( | |
|
||
pathParts.unshift(`${dependencyInformation.packageLocation}/.bin`); | ||
} | ||
|
||
// Note that NODE_OPTIONS doesn't support any style of quoting its arguments at the moment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referring to your PR on Node would be nice. Also, would be great if we can centralize some of this PnP path logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'll keep it duplicated for now - since it's very few lines, I'm concerned about over-abstracting it (since it's only used in two places and there are no reasons to think it will change) |
||
// For this reason, it won't work if the user has a space inside its $PATH | ||
env.NODE_OPTIONS = env.NODE_OPTIONS || ''; | ||
env.NODE_OPTIONS += ` --require ${pnpFile}`; | ||
} | ||
|
||
pathParts.unshift(await getWrappersFolder(config)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need two more tests:
node
args which simulates the scenario you are solving for (is this the second test, I can't really tell?)NODE_OPTIONS
env variable and make sure it is preserved.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first test tests
yarn node my-script.js'
, and the second testsyarn run my-script
. I think that should cover the first case? Will add a test for emptyNODE_OPTIONS
👍