Commit 2bcc5791 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by Jiachi Liu

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.
parent 6df1d205
...@@ -10,6 +10,9 @@ import fsp from 'fs/promises' ...@@ -10,6 +10,9 @@ import fsp from 'fs/promises'
) )
return return
} }
const preferOffline = process.env.NEXT_TEST_PREFER_OFFLINE === '1'
let cwd = process.cwd() let cwd = process.cwd()
const { version: nextVersion } = JSON.parse( const { version: nextVersion } = JSON.parse(
fs.readFileSync(path.join(cwd, 'packages', 'next', 'package.json')) fs.readFileSync(path.join(cwd, 'packages', 'next', 'package.json'))
...@@ -57,9 +60,11 @@ import fsp from 'fs/promises' ...@@ -57,9 +60,11 @@ import fsp from 'fs/promises'
fs.writeFileSync(path.join(tmpdir, 'package.json'), JSON.stringify(pkgJson)) fs.writeFileSync(path.join(tmpdir, 'package.json'), JSON.stringify(pkgJson))
fs.writeFileSync(path.join(tmpdir, '.npmrc'), 'node-linker=hoisted') fs.writeFileSync(path.join(tmpdir, '.npmrc'), 'node-linker=hoisted')
let { stdout } = await execa('pnpm', ['add', `next@${nextVersion}`], { const args = ['add', `next@${nextVersion}`]
cwd: tmpdir, if (preferOffline) {
}) args.push('--prefer-offline')
}
let { stdout } = await execa('pnpm', args, { cwd: tmpdir })
console.log(stdout) console.log(stdout)
let pkgs = fs.readdirSync(path.join(tmpdir, 'node_modules/@next')) let pkgs = fs.readdirSync(path.join(tmpdir, 'node_modules/@next'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment