Unverified Commit 0bded2db authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[cna] Use `allowBuilds` instead of `ignoredBuiltDependencies` when using PNPM 11+ (#94544)

parent f5718d2c
...@@ -338,7 +338,26 @@ export const installTemplate = async ({ ...@@ -338,7 +338,26 @@ export const installTemplate = async ({
// If we can't determine the version, assume latest (v10+) since we already // If we can't determine the version, assume latest (v10+) since we already
// know pnpm is being used at this point. // know pnpm is being used at this point.
const pnpmMajorVersion = getPnpmMajorVersion(); const pnpmMajorVersion = getPnpmMajorVersion();
if (pnpmMajorVersion === null || pnpmMajorVersion >= 10) { if (pnpmMajorVersion === null || pnpmMajorVersion >= 11) {
// In pnpm v11, `ignoredBuiltDependencies` (and the other build-script
// settings) were removed in favor of a single `allowBuilds` map where
// `false` denies a package from running build scripts. See
// https://pnpm.io/blog/releases/11.0
const pnpmWorkspaceYaml = [
"allowBuilds:",
// Sharp has prebuilt binaries for the platforms next-swc has binaries.
// If it needs to build binaries from source, next-swc wouldn't work either.
// See https://sharp.pixelplumbing.com/install/#:~:text=When%20using%20pnpm%2C%20add%20sharp%20to%20ignoredBuiltDependencies%20to%20silence%20warnings
" sharp: false",
// Not needed for pnpm: https://github.com/unrs/unrs-resolver/issues/193#issuecomment-3295510146
" unrs-resolver: false",
"",
].join(os.EOL);
await fs.writeFile(
path.join(root, "pnpm-workspace.yaml"),
pnpmWorkspaceYaml,
);
} else if (pnpmMajorVersion >= 10) {
const pnpmWorkspaceYaml = [ const pnpmWorkspaceYaml = [
"ignoredBuiltDependencies:", "ignoredBuiltDependencies:",
// Sharp has prebuilt binaries for the platforms next-swc has binaries. // Sharp has prebuilt binaries for the platforms next-swc has binaries.
......
import fs from 'fs'
import path from 'path'
import { import {
command, command,
DEFAULT_FILES, DEFAULT_FILES,
...@@ -91,7 +93,7 @@ describe('create-next-app with package manager pnpm', () => { ...@@ -91,7 +93,7 @@ describe('create-next-app with package manager pnpm', () => {
// 1. We only need to verify the workspace file is created/not created // 1. We only need to verify the workspace file is created/not created
// 2. The CI runs pnpm v9, but when testing v10 behavior, the workspace file // 2. The CI runs pnpm v9, but when testing v10 behavior, the workspace file
// created for v10 (without packages field) would fail with pnpm v9 // created for v10 (without packages field) would fail with pnpm v9
it('should create pnpm-workspace.yaml for pnpm v10+', async () => { it('should create pnpm-workspace.yaml with ignoredBuiltDependencies for pnpm v10', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pnpm-v10-workspace' const projectName = 'pnpm-v10-workspace'
const res = await run( const res = await run(
...@@ -120,6 +122,54 @@ describe('create-next-app with package manager pnpm', () => { ...@@ -120,6 +122,54 @@ describe('create-next-app with package manager pnpm', () => {
projectName, projectName,
files: ['package.json', 'pnpm-workspace.yaml'], files: ['package.json', 'pnpm-workspace.yaml'],
}) })
const workspaceYaml = fs.readFileSync(
path.join(cwd, projectName, 'pnpm-workspace.yaml'),
'utf8'
)
expect(workspaceYaml).toContain('ignoredBuiltDependencies:')
expect(workspaceYaml).toContain('- sharp')
expect(workspaceYaml).toContain('- unrs-resolver')
expect(workspaceYaml).not.toContain('allowBuilds:')
})
})
it('should create pnpm-workspace.yaml with allowBuilds for pnpm v11+', async () => {
await useTempDir(async (cwd) => {
const projectName = 'pnpm-v11-workspace'
const res = await run(
[
projectName,
'--ts',
'--app',
'--no-linter',
'--no-src-dir',
'--no-tailwind',
'--no-import-alias',
'--no-react-compiler',
'--no-agents-md',
'--skip-install',
],
nextTgzFilename,
{
cwd,
env: { npm_config_user_agent: 'pnpm/11.0.0 npm/? node/v20.0.0' },
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files: ['package.json', 'pnpm-workspace.yaml'],
})
const workspaceYaml = fs.readFileSync(
path.join(cwd, projectName, 'pnpm-workspace.yaml'),
'utf8'
)
expect(workspaceYaml).toContain('allowBuilds:')
expect(workspaceYaml).toContain('sharp: false')
expect(workspaceYaml).toContain('unrs-resolver: false')
expect(workspaceYaml).not.toContain('ignoredBuiltDependencies:')
}) })
}) })
......
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