mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-10 11:18:18 -04:00
6
.changeset/cold-panthers-jump.md
Normal file
6
.changeset/cold-panthers-jump.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
support `node-options` option inside `.npmrc` file when running scripts [#7596](https://github.com/pnpm/pnpm/issues/7596)
|
||||
@@ -187,6 +187,7 @@ export interface Config {
|
||||
globalDir?: string
|
||||
lockfile?: boolean
|
||||
dedupeInjectedDeps?: boolean
|
||||
nodeOptions?: string
|
||||
}
|
||||
|
||||
export interface ConfigWithDeprecatedSettings extends Config {
|
||||
|
||||
@@ -127,7 +127,6 @@ export async function handler (
|
||||
opts: Required<Pick<Config, 'selectedProjectsGraph'>> & {
|
||||
bail?: boolean
|
||||
unsafePerm?: boolean
|
||||
rawConfig: object
|
||||
reverse?: boolean
|
||||
sort?: boolean
|
||||
workspaceConcurrency?: number
|
||||
@@ -135,7 +134,7 @@ export async function handler (
|
||||
resumeFrom?: string
|
||||
reportSummary?: boolean
|
||||
implicitlyFellbackFromRun?: boolean
|
||||
} & Pick<Config, 'extraBinPaths' | 'extraEnv' | 'lockfileDir' | 'modulesDir' | 'dir' | 'userAgent' | 'recursive' | 'workspaceDir'>,
|
||||
} & Pick<Config, 'extraBinPaths' | 'extraEnv' | 'lockfileDir' | 'modulesDir' | 'dir' | 'userAgent' | 'recursive' | 'workspaceDir' | 'nodeOptions'>,
|
||||
params: string[]
|
||||
) {
|
||||
// For backward compatibility
|
||||
@@ -201,6 +200,7 @@ export async function handler (
|
||||
extraEnv: {
|
||||
...extraEnv,
|
||||
PNPM_PACKAGE_NAME: opts.selectedProjectsGraph[prefix]?.package.manifest.name,
|
||||
...(opts.nodeOptions ? { NODE_OPTIONS: opts.nodeOptions } : {}),
|
||||
},
|
||||
prependPaths,
|
||||
userAgent: opts.userAgent,
|
||||
|
||||
@@ -149,7 +149,7 @@ For options that may be used with `-r`, see "pnpm help recursive"',
|
||||
export type RunOpts =
|
||||
& Omit<RecursiveRunOpts, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>
|
||||
& { recursive?: boolean }
|
||||
& Pick<Config, 'dir' | 'engineStrict' | 'extraBinPaths' | 'reporter' | 'scriptsPrependNodePath' | 'scriptShell' | 'shellEmulator' | 'enablePrePostScripts' | 'userAgent' | 'extraEnv'>
|
||||
& Pick<Config, 'dir' | 'engineStrict' | 'extraBinPaths' | 'reporter' | 'scriptsPrependNodePath' | 'scriptShell' | 'shellEmulator' | 'enablePrePostScripts' | 'userAgent' | 'extraEnv' | 'nodeOptions'>
|
||||
& (
|
||||
& { recursive?: false }
|
||||
& Partial<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>>
|
||||
@@ -224,10 +224,16 @@ so you may run "pnpm -w run ${scriptName}"`,
|
||||
})
|
||||
}
|
||||
const concurrency = opts.workspaceConcurrency ?? 4
|
||||
|
||||
const extraEnv = {
|
||||
...opts.extraEnv,
|
||||
...(opts.nodeOptions ? { NODE_OPTIONS: opts.nodeOptions } : {}),
|
||||
}
|
||||
|
||||
const lifecycleOpts: RunLifecycleHookOptions = {
|
||||
depPath: dir,
|
||||
extraBinPaths: opts.extraBinPaths,
|
||||
extraEnv: opts.extraEnv,
|
||||
extraEnv,
|
||||
pkgRoot: dir,
|
||||
rawConfig: opts.rawConfig,
|
||||
rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
|
||||
|
||||
@@ -24,3 +24,20 @@ test('exec should set npm_config_user_agent', async () => {
|
||||
}),
|
||||
}))
|
||||
})
|
||||
|
||||
test('exec should set the NODE_OPTIONS env var', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await exec.handler({
|
||||
...DEFAULT_OPTS,
|
||||
dir: process.cwd(),
|
||||
selectedProjectsGraph: {},
|
||||
nodeOptions: '--max-old-space-size=4096',
|
||||
}, ['eslint'])
|
||||
|
||||
expect(execa).toBeCalledWith('eslint', [], expect.objectContaining({
|
||||
env: expect.objectContaining({
|
||||
NODE_OPTIONS: '--max-old-space-size=4096',
|
||||
}),
|
||||
}))
|
||||
})
|
||||
|
||||
@@ -609,3 +609,20 @@ test('pnpm run with slightly incorrect command suggests correct one', async () =
|
||||
hint: 'Command "buil" not found. Did you mean "pnpm run build"?',
|
||||
}))
|
||||
})
|
||||
|
||||
test('pnpm run with custom node-options', async () => {
|
||||
prepare({
|
||||
scripts: {
|
||||
build: 'node -e "if (process.env.NODE_OPTIONS !== \'--max-old-space-size=1200\') { process.exit(1) }"',
|
||||
},
|
||||
})
|
||||
|
||||
await run.handler({
|
||||
dir: process.cwd(),
|
||||
extraBinPaths: [],
|
||||
extraEnv: {},
|
||||
rawConfig: {},
|
||||
nodeOptions: '--max-old-space-size=1200',
|
||||
workspaceConcurrency: 1,
|
||||
}, ['build'])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user