From 57f989ef45ec73b1ddbb0f13fe1fc82d06968f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=E1=BA=A3i?= Date: Tue, 11 Mar 2025 08:52:59 +0700 Subject: [PATCH] fix(exec): add missing `node-options` to `recursive run` (#9264) * fix(run): add missing `node-options` to `recursive` Fixes https://github.com/pnpm/pnpm/issues/9180 * refactor: share code * refactor: remove unused field --- .changeset/polite-plants-jump.md | 6 +++++ .../plugin-commands-script-runners/src/run.ts | 14 ++++++----- .../test/runRecursive.ts | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 .changeset/polite-plants-jump.md diff --git a/.changeset/polite-plants-jump.md b/.changeset/polite-plants-jump.md new file mode 100644 index 0000000000..b36555fb21 --- /dev/null +++ b/.changeset/polite-plants-jump.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-script-runners": patch +"pnpm": patch +--- + +Add the missing `node-options` config to `recursive run` [#9180](https://github.com/pnpm/pnpm/issues/9180). diff --git a/exec/plugin-commands-script-runners/src/run.ts b/exec/plugin-commands-script-runners/src/run.ts index c60b33a3cf..576e23b044 100644 --- a/exec/plugin-commands-script-runners/src/run.ts +++ b/exec/plugin-commands-script-runners/src/run.ts @@ -202,6 +202,13 @@ export async function handler ( await runDepsStatusCheck(opts) } + if (opts.nodeOptions) { + opts.extraEnv = { + ...opts.extraEnv, + NODE_OPTIONS: opts.nodeOptions, + } + } + if (opts.recursive) { if (scriptName || Object.keys(opts.selectedProjectsGraph).length > 1) { return runRecursive(params, opts) as Promise @@ -258,15 +265,10 @@ 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, + extraEnv: opts.extraEnv, pkgRoot: dir, rawConfig: opts.rawConfig, rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')), diff --git a/exec/plugin-commands-script-runners/test/runRecursive.ts b/exec/plugin-commands-script-runners/test/runRecursive.ts index 68cbfbc345..d6621af0dd 100644 --- a/exec/plugin-commands-script-runners/test/runRecursive.ts +++ b/exec/plugin-commands-script-runners/test/runRecursive.ts @@ -1061,3 +1061,27 @@ test('pnpm recursive run report summary with --bail', async () => { expect(executionStatus[path.resolve('project-4')].status).toBe('queued') expect(executionStatus[path.resolve('project-5')].status).toBe('skipped') }) + +test('pnpm recursive run with custom node-options', async () => { + preparePackages([ + { + name: 'project-1', + version: '1.0.0', + scripts: { + build: 'node -e "assert.strictEqual(process.env.NODE_OPTIONS, \'--max-old-space-size=1200\')"', + }, + }, + ]) + + const { allProjects, selectedProjectsGraph } = await filterPackagesFromDir(process.cwd(), []) + + await run.handler({ + ...DEFAULT_OPTS, + allProjects, + dir: process.cwd(), + nodeOptions: '--max-old-space-size=1200', + recursive: true, + selectedProjectsGraph, + workspaceDir: process.cwd(), + }, ['build']) +})