Skip to content

Commit 7b222b9

Browse files
authored
[backport][test] Pin package manager to patch versions (#93595)
1 parent a8dc24f commit 7b222b9

7 files changed

Lines changed: 38 additions & 1 deletion

File tree

test/e2e/app-dir/nx-handling/nx-handling.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('nx-handling', () => {
1111
name: '@nx-next/source',
1212
version: '0.0.0',
1313
private: true,
14+
packageManager: 'npm@10.9.2',
1415
scripts: {
1516
build: 'rm -rf dist; nx run next-nx-test:build',
1617
dev: 'nx run next-nx-test:dev',

test/e2e/filesystem-cache/filesystem-cache.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ for (const cacheEnabled of [false, true]) {
4848
files: __dirname,
4949
skipDeployment: true,
5050
packageJson: {
51+
packageManager: 'npm@10.9.2',
5152
scripts: {
5253
build: `${envVars} next build`,
5354
dev: `${envVars} next dev`,

test/e2e/handle-non-hoisted-swc-helpers/index.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createNext } from 'e2e-utils'
1+
import { createNext, isNextDev } from 'e2e-utils'
22
import { NextInstance } from 'e2e-utils'
33
import { renderViaHTTP } from 'next-test-utils'
44

@@ -24,8 +24,18 @@ describe('handle-non-hoisted-swc-helpers', () => {
2424
}
2525
`,
2626
},
27+
packageJson: {
28+
packageManager: 'npm@10.9.2',
29+
scripts: {
30+
build: 'next build',
31+
dev: 'next dev',
32+
start: 'next start',
33+
},
34+
},
2735
installCommand:
2836
'npm install; mkdir -p node_modules/next/node_modules/@swc; mv node_modules/@swc/helpers node_modules/next/node_modules/@swc/',
37+
buildCommand: 'npm run build',
38+
startCommand: isNextDev ? 'npm run dev' : 'npm run start',
2939
dependencies: {},
3040
})
3141
})

test/e2e/yarn-pnp/test/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export function runTests(
4545
},
4646
{} as { [key: string]: FileRef }
4747
),
48+
packageJson: {
49+
// Bootstrap with classic yarn; the install command below runs
50+
// `yarn set version berry` which rewrites this to the berry version.
51+
packageManager: 'yarn@1.22.22',
52+
},
4853
dependencies: {
4954
...packageJson.dependencies,
5055
...packageJson.devDependencies,

test/integration/create-next-app/package-manager/pnpm.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
command,
23
DEFAULT_FILES,
34
FULL_EXAMPLE_PATH,
45
projectFilesShouldExist,
@@ -10,6 +11,11 @@ import {
1011
const lockFile = 'pnpm-lock.yaml'
1112
const files = [...DEFAULT_FILES, lockFile]
1213

14+
// Match the monorepo's pinned pnpm so CNA's `pnpm install` doesn't drift to
15+
// whichever version corepack happens to fetch as "latest" at test time.
16+
const rootPackageManager: string =
17+
require('../../../../package.json').packageManager
18+
1319
describe('create-next-app with package manager pnpm', () => {
1420
let nextTgzFilename: string
1521

@@ -18,6 +24,8 @@ describe('create-next-app with package manager pnpm', () => {
1824
throw new Error('This test needs to be run with `node run-tests.js`.')
1925
}
2026

27+
await command('corepack', ['prepare', '--activate', rootPackageManager])
28+
2129
const pkgPaths = new Map<string, string>(
2230
JSON.parse(process.env.NEXT_TEST_PKG_PATHS)
2331
)

test/lib/create-next-install.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { linkPackages } =
99

1010
const PREFER_OFFLINE = process.env.NEXT_TEST_PREFER_OFFLINE === '1'
1111
const useRspack = process.env.NEXT_TEST_USE_RSPACK === '1'
12+
const ROOT_PACKAGE_MANAGER = require('../../package.json').packageManager
1213

1314
async function installDependencies(cwd, tmpDir) {
1415
const args = [
@@ -178,6 +179,10 @@ async function createNextInstall({
178179
path.join(installDir, 'package.json'),
179180
JSON.stringify(
180181
{
182+
// Pin packageManager so corepack doesn't auto-inject a reference
183+
// to the latest version (and rewrite this file mid-test).
184+
// Callers can override via packageJson.packageManager.
185+
packageManager: ROOT_PACKAGE_MANAGER,
181186
...packageJson,
182187
scripts,
183188
dependencies: combinedDependencies,

test/lib/next-modes/base.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ type OmitFirstArgument<F> = F extends (
7171
// prettier-ignore
7272
const nextjsReactPeerVersion = "19.2.4";
7373

74+
const ROOT_PACKAGE_MANAGER: string =
75+
require('../../../package.json').packageManager
76+
7477
export class NextInstance {
7578
protected files: ResolvedFileConfig
7679
protected overrideFiles: ResolvedFileConfig
@@ -272,6 +275,10 @@ export class NextInstance {
272275
path.join(this.testDir, 'package.json'),
273276
JSON.stringify(
274277
{
278+
// Pin packageManager so corepack doesn't auto-inject a reference
279+
// to the latest version (and rewrite this file mid-test).
280+
// Callers can override via packageJson.packageManager.
281+
packageManager: ROOT_PACKAGE_MANAGER,
275282
...this.packageJson,
276283
dependencies: {
277284
...finalDependencies,

0 commit comments

Comments
 (0)