Skip to content

Commit b1de136

Browse files
committed
Refactor pnpm flags into reusable constants
- Rename PNPM_INSTALL_FLAGS to PNPM_HOISTED_INSTALL_FLAGS for clarity - Add PNPM_INSTALL_BASE_FLAGS for isolated (non-hoisted) installs - Use PNPM_INSTALL_BASE_FLAGS for nested package installs to prevent JSON corruption from concurrent hoisted installations - Update all scripts to use the appropriate flag constants
1 parent 804d31c commit b1de136

3 files changed

Lines changed: 32 additions & 32 deletions

File tree

scripts/install-npm-packages.mjs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { cleanTestScript } from '../test/utils/script-cleaning.mjs'
1212
import { testRunners } from '../test/utils/test-runners.mjs'
1313
import { suppressMaxListenersWarning } from './utils/suppress-warnings.mjs'
1414
import { filterPackagesByChanges } from './utils/git.mjs'
15-
import { PNPM_INSTALL_ENV, PNPM_INSTALL_FLAGS } from './utils/package.mjs'
15+
import {
16+
PNPM_HOISTED_INSTALL_FLAGS,
17+
PNPM_INSTALL_BASE_FLAGS,
18+
PNPM_INSTALL_ENV,
19+
} from './utils/package.mjs'
1620
import constants from './constants.mjs'
1721
import ENV from '../registry/dist/lib/constants/ENV.js'
1822
import spinner from '../registry/dist/lib/constants/spinner.js'
@@ -444,26 +448,18 @@ async function installPackage(packageInfo) {
444448

445449
// Install any missing dependencies.
446450
// Unset NODE_ENV and CI to prevent pnpm from skipping devDependencies.
447-
await runCommand('pnpm', ['install', ...PNPM_INSTALL_FLAGS], {
451+
await runCommand('pnpm', ['install', ...PNPM_HOISTED_INSTALL_FLAGS], {
448452
cwd: packageTempDir,
449453
env: { ...process.env, ...PNPM_INSTALL_ENV },
450454
})
451455

452456
// Explicitly install dependencies in the nested package to ensure test
453457
// runners (tape, mocha, ava, etc.) are available.
454458
// Use isolated mode (not hoisted) to avoid conflicts with parent installation.
455-
await runCommand(
456-
'pnpm',
457-
[
458-
'install',
459-
'--config.confirmModulesPurge=false',
460-
'--no-frozen-lockfile',
461-
],
462-
{
463-
cwd: installedPath,
464-
env: { ...process.env, ...PNPM_INSTALL_ENV },
465-
},
466-
)
459+
await runCommand('pnpm', ['install', ...PNPM_INSTALL_BASE_FLAGS], {
460+
cwd: installedPath,
461+
env: { ...process.env, ...PNPM_INSTALL_ENV },
462+
})
467463

468464
// Apply Socket overrides to all nested dependencies recursively.
469465
await applyNestedSocketOverrides(installedPath)
@@ -520,7 +516,7 @@ async function installPackage(packageInfo) {
520516
// Unset NODE_ENV and CI to prevent pnpm from skipping devDependencies.
521517
await pRetry(
522518
async () => {
523-
await runCommand('pnpm', ['install', ...PNPM_INSTALL_FLAGS], {
519+
await runCommand('pnpm', ['install', ...PNPM_HOISTED_INSTALL_FLAGS], {
524520
cwd: packageTempDir,
525521
env: { ...process.env, ...PNPM_INSTALL_ENV },
526522
})
@@ -741,22 +737,18 @@ async function installPackage(packageInfo) {
741737

742738
// Install dependencies to ensure devDependencies (test runners) are available.
743739
// Unset NODE_ENV and CI to prevent pnpm from skipping devDependencies.
744-
await runCommand('pnpm', ['install', ...PNPM_INSTALL_FLAGS], {
740+
await runCommand('pnpm', ['install', ...PNPM_HOISTED_INSTALL_FLAGS], {
745741
cwd: packageTempDir,
746742
env: { ...process.env, ...PNPM_INSTALL_ENV },
747743
})
748744

749745
// Explicitly install dependencies in the nested package to ensure test
750746
// runners (tape, mocha, ava, etc.) are available.
751747
// Use isolated mode (not hoisted) to avoid conflicts with parent installation.
752-
await runCommand(
753-
'pnpm',
754-
['install', '--config.confirmModulesPurge=false', '--no-frozen-lockfile'],
755-
{
756-
cwd: installedPath,
757-
env: { ...process.env, ...PNPM_INSTALL_ENV },
758-
},
759-
)
748+
await runCommand('pnpm', ['install', ...PNPM_INSTALL_BASE_FLAGS], {
749+
cwd: installedPath,
750+
env: { ...process.env, ...PNPM_INSTALL_ENV },
751+
})
760752

761753
// Apply Socket overrides to all nested dependencies recursively.
762754
await applyNestedSocketOverrides(installedPath)

scripts/run-npm-package-tests.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import WIN32 from '../registry/dist/lib/constants/WIN32.js'
1111
import constants from './constants.mjs'
1212
import { filterPackagesByChanges } from './utils/git.mjs'
1313
import {
14+
PNPM_HOISTED_INSTALL_FLAGS,
15+
PNPM_INSTALL_BASE_FLAGS,
1416
PNPM_INSTALL_ENV,
15-
PNPM_INSTALL_FLAGS,
1617
buildTestEnv,
1718
runCommand,
1819
} from './utils/package.mjs'
@@ -121,13 +122,14 @@ async function runPackageTest(socketPkgName) {
121122
}
122123

123124
// First reinstall in the root (installs prod dependencies of main package).
124-
await runCommand('pnpm', ['install', ...PNPM_INSTALL_FLAGS], {
125+
await runCommand('pnpm', ['install', ...PNPM_HOISTED_INSTALL_FLAGS], {
125126
cwd: packageTempDir,
126127
env,
127128
})
128129

129130
// Then reinstall all dependencies (including devDependencies) of the nested package.
130-
await runCommand('pnpm', ['install', ...PNPM_INSTALL_FLAGS], {
131+
// Use isolated mode to avoid conflicts with parent installation.
132+
await runCommand('pnpm', ['install', ...PNPM_INSTALL_BASE_FLAGS], {
131133
cwd: installedPath,
132134
env,
133135
})

scripts/utils/package.mjs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ const PNPM_NPM_LIKE_FLAGS = [
2929
'--config.strict-peer-dependencies=false',
3030
]
3131

32-
// Additional pnpm install flags for CI-friendly behavior.
33-
const PNPM_INSTALL_FLAGS = [
34-
...PNPM_NPM_LIKE_FLAGS,
32+
// Basic pnpm install flags for CI-friendly behavior.
33+
const PNPM_INSTALL_BASE_FLAGS = [
3534
// Prevent interactive prompts in CI environments.
3635
'--config.confirmModulesPurge=false',
3736
// Allow lockfile updates (required for test package installations).
3837
'--no-frozen-lockfile',
3938
]
4039

40+
// Pnpm install flags with hoisting for npm-like behavior.
41+
const PNPM_HOISTED_INSTALL_FLAGS = [
42+
...PNPM_NPM_LIKE_FLAGS,
43+
...PNPM_INSTALL_BASE_FLAGS,
44+
]
45+
4146
// Environment override to force pnpm to install devDependencies.
4247
// By default, pnpm skips devDependencies when CI or NODE_ENV=production is detected.
4348
const PNPM_INSTALL_ENV = { CI: undefined, NODE_ENV: undefined }
@@ -442,7 +447,7 @@ async function installPackageForTesting(socketPkgName) {
442447
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 2))
443448

444449
// Install dependencies with pnpm.
445-
await runCommand('pnpm', ['install', ...PNPM_INSTALL_FLAGS], {
450+
await runCommand('pnpm', ['install', ...PNPM_HOISTED_INSTALL_FLAGS], {
446451
cwd: installedPath,
447452
})
448453

@@ -466,8 +471,9 @@ export {
466471
copySocketOverride,
467472
editablePackageJsonCache,
468473
installPackageForTesting,
474+
PNPM_HOISTED_INSTALL_FLAGS,
475+
PNPM_INSTALL_BASE_FLAGS,
469476
PNPM_INSTALL_ENV,
470-
PNPM_INSTALL_FLAGS,
471477
PNPM_NPM_LIKE_FLAGS,
472478
processWithSpinner,
473479
readCachedEditablePackageJson,

0 commit comments

Comments
 (0)