Skip to content

Commit f43f339

Browse files
authored
Honour NEXT_TEST_PREFER_OFFLINE in install-native.mjs (#85850)
The `scripts/install-native.mjs` script is run in the postinstall step of the Next.js monorepo to install the published binary packages of the latest Next.js canary version. This change makes the script respect the `NEXT_TEST_PREFER_OFFLINE` environment variable, allowing it to prefer installing previously downloaded packages from the local cache. This is useful for scenarios where network access is limited or unavailable.
1 parent 6080d9c commit f43f339

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/install-native.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import fsp from 'fs/promises'
1010
)
1111
return
1212
}
13+
14+
const preferOffline = process.env.NEXT_TEST_PREFER_OFFLINE === '1'
15+
1316
let cwd = process.cwd()
1417
const { version: nextVersion } = JSON.parse(
1518
fs.readFileSync(path.join(cwd, 'packages', 'next', 'package.json'))
@@ -57,9 +60,11 @@ import fsp from 'fs/promises'
5760
fs.writeFileSync(path.join(tmpdir, 'package.json'), JSON.stringify(pkgJson))
5861
fs.writeFileSync(path.join(tmpdir, '.npmrc'), 'node-linker=hoisted')
5962

60-
let { stdout } = await execa('pnpm', ['add', `next@${nextVersion}`], {
61-
cwd: tmpdir,
62-
})
63+
const args = ['add', `next@${nextVersion}`]
64+
if (preferOffline) {
65+
args.push('--prefer-offline')
66+
}
67+
let { stdout } = await execa('pnpm', args, { cwd: tmpdir })
6368
console.log(stdout)
6469

6570
let pkgs = fs.readdirSync(path.join(tmpdir, 'node_modules/@next'))

0 commit comments

Comments
 (0)