Skip to content

Commit 3dea2f6

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@schematics/angular): generate pnpm-workspace.yaml with allowBuilds for pnpm projects
Starting in pnpm 11, `strictDepBuilds` is enabled by default and pnpm fails with `ERR_PNPM_IGNORED_BUILDS` when any dependency in the graph declares lifecycle build scripts that are not listed in `allowBuilds` in `pnpm-workspace.yaml`. (cherry picked from commit 12a7d2a)
1 parent 075ff2a commit 3dea2f6

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
packages:
2+
- '.'
3+
4+
allowBuilds:
5+
'@parcel/watcher': false
6+
esbuild: false
7+
lmdb: false
8+
msgpackr-extract: false

‎packages/schematics/angular/workspace/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@angular-devkit/schematics';
1919
import { execSync } from 'node:child_process';
2020
import { latestVersions } from '../utility/latest-versions';
21-
import { Schema as WorkspaceOptions } from './schema';
21+
import { PackageManager, Schema as WorkspaceOptions } from './schema';
2222

2323
export default function (options: WorkspaceOptions): Rule {
2424
return () => {
@@ -48,6 +48,9 @@ export default function (options: WorkspaceOptions): Rule {
4848
return mergeWith(
4949
apply(url('./files'), [
5050
options.minimal ? filter((path) => !path.endsWith('editorconfig.template')) : noop(),
51+
packageManager !== PackageManager.Pnpm
52+
? filter((path) => !path.endsWith('pnpm-workspace.yaml.template'))
53+
: noop(),
5154
applyTemplates({
5255
utils: strings,
5356
...options,

‎packages/schematics/angular/workspace/index_spec.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
1010
import { parse as parseJson } from 'jsonc-parser';
1111
import { latestVersions } from '../utility/latest-versions';
12-
import { Schema as WorkspaceOptions } from './schema';
12+
import { PackageManager, Schema as WorkspaceOptions } from './schema';
1313

1414
describe('Workspace Schematic', () => {
1515
const schematicRunner = new SchematicTestRunner(
@@ -38,6 +38,17 @@ describe('Workspace Schematic', () => {
3838
'/tsconfig.json',
3939
]),
4040
);
41+
expect(files).not.toContain('/pnpm-workspace.yaml');
42+
});
43+
44+
it('should create pnpm-workspace.yaml with allowBuilds when packageManager is pnpm', async () => {
45+
const tree = await schematicRunner.runSchematic('workspace', {
46+
...defaultOptions,
47+
packageManager: PackageManager.Pnpm,
48+
});
49+
expect(tree.exists('/pnpm-workspace.yaml')).toBeTrue();
50+
const content = tree.readContent('/pnpm-workspace.yaml');
51+
expect(content).toContain('allowBuilds:');
4152
});
4253

4354
it('should set the name in package.json', async () => {

0 commit comments

Comments
 (0)