Skip to content

Commit e861ea4

Browse files
Copiloticlanton
andcommitted
Move onlyBuiltDependencies to package.json instead of pnpm-workspace.yaml
Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
1 parent d3f7750 commit e861ea4

8 files changed

Lines changed: 25 additions & 136 deletions

File tree

libraries/rush-lib/src/logic/installManager/InstallHelpers.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface ICommonPackageJson extends IPackageJson {
3131
packageExtensions?: typeof PnpmOptionsConfiguration.prototype.globalPackageExtensions;
3232
peerDependencyRules?: typeof PnpmOptionsConfiguration.prototype.globalPeerDependencyRules;
3333
neverBuiltDependencies?: typeof PnpmOptionsConfiguration.prototype.globalNeverBuiltDependencies;
34+
onlyBuiltDependencies?: typeof PnpmOptionsConfiguration.prototype.globalOnlyBuiltDependencies;
3435
ignoredOptionalDependencies?: typeof PnpmOptionsConfiguration.prototype.globalIgnoredOptionalDependencies;
3536
allowedDeprecatedVersions?: typeof PnpmOptionsConfiguration.prototype.globalAllowedDeprecatedVersions;
3637
patchedDependencies?: typeof PnpmOptionsConfiguration.prototype.globalPatchedDependencies;
@@ -76,6 +77,24 @@ export class InstallHelpers {
7677
commonPackageJson.pnpm.neverBuiltDependencies = pnpmOptions.globalNeverBuiltDependencies;
7778
}
7879

80+
if (pnpmOptions.globalOnlyBuiltDependencies) {
81+
if (
82+
rushConfiguration.rushConfigurationJson.pnpmVersion !== undefined &&
83+
semver.lt(rushConfiguration.rushConfigurationJson.pnpmVersion, '10.1.0')
84+
) {
85+
terminal.writeWarningLine(
86+
Colorize.yellow(
87+
`Your version of pnpm (${rushConfiguration.rushConfigurationJson.pnpmVersion}) ` +
88+
`doesn't support the "globalOnlyBuiltDependencies" field in ` +
89+
`${rushConfiguration.commonRushConfigFolder}/${RushConstants.pnpmConfigFilename}. ` +
90+
'Remove this field or upgrade to pnpm 10.1.0 or newer.'
91+
)
92+
);
93+
}
94+
95+
commonPackageJson.pnpm.onlyBuiltDependencies = pnpmOptions.globalOnlyBuiltDependencies;
96+
}
97+
7998
if (pnpmOptions.globalIgnoredOptionalDependencies) {
8099
if (
81100
rushConfiguration.rushConfigurationJson.pnpmVersion !== undefined &&

libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -468,25 +468,6 @@ export class WorkspaceInstallManager extends BaseInstallManager {
468468
workspaceFile.setCatalogs(catalogs);
469469
}
470470

471-
// Set onlyBuiltDependencies in the workspace file if specified
472-
if (pnpmOptions.globalOnlyBuiltDependencies) {
473-
if (
474-
this.rushConfiguration.rushConfigurationJson.pnpmVersion !== undefined &&
475-
semver.lt(this.rushConfiguration.rushConfigurationJson.pnpmVersion, '10.1.0')
476-
) {
477-
this._terminal.writeWarningLine(
478-
Colorize.yellow(
479-
`Your version of pnpm (${this.rushConfiguration.rushConfigurationJson.pnpmVersion}) ` +
480-
`doesn't support the "globalOnlyBuiltDependencies" field in ` +
481-
`${this.rushConfiguration.commonRushConfigFolder}/${RushConstants.pnpmConfigFilename}. ` +
482-
'Remove this field or upgrade to pnpm 10.1.0 or newer.'
483-
)
484-
);
485-
}
486-
487-
workspaceFile.setOnlyBuiltDependencies(pnpmOptions.globalOnlyBuiltDependencies);
488-
}
489-
490471
// Save the generated workspace file. Don't update the file timestamp unless the content has changed,
491472
// since "rush install" will consider this timestamp
492473
workspaceFile.save(workspaceFile.workspaceFilename, { onlyIfChanged: true });

libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,12 @@ export class PnpmOptionsConfiguration extends PackageManagerOptionsConfiguration
374374
* to run build scripts (`preinstall`, `install`, and `postinstall` lifecycle events). This is the inverse
375375
* of `globalNeverBuiltDependencies`. In PNPM 10.x, build scripts are disabled by default for security,
376376
* so this setting is required to explicitly permit specific packages to run their build scripts.
377-
* The settings are written to the `onlyBuiltDependencies` field of the `pnpm-workspace.yaml` file
378-
* that is generated by Rush during installation.
377+
* The settings are copied into the `pnpm.onlyBuiltDependencies` field of the `common/temp/package.json`
378+
* file that is generated by Rush during installation.
379379
*
380380
* (SUPPORTED ONLY IN PNPM 10.1.0 AND NEWER)
381381
*
382-
* PNPM documentation: https://pnpm.io/settings#onlybuiltdependencies
382+
* PNPM documentation: https://pnpm.io/package_json#pnpmonlybuiltdependencies
383383
*/
384384
public readonly globalOnlyBuiltDependencies: string[] | undefined;
385385

libraries/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@ const globEscape: (unescaped: string) => string = require('glob-escape'); // No
2323
* "default": {
2424
* "react": "^18.0.0"
2525
* }
26-
* },
27-
* "onlyBuiltDependencies": [
28-
* "esbuild",
29-
* "playwright"
30-
* ]
26+
* }
3127
* }
3228
*/
3329
interface IPnpmWorkspaceYaml {
3430
/** The list of local package directories */
3531
packages: string[];
3632
/** Catalog definitions for centralized version management */
3733
catalogs?: Record<string, Record<string, string>>;
38-
/** Allowlist of dependencies permitted to run build scripts (PNPM 10.1.0+) */
39-
onlyBuiltDependencies?: string[];
4034
}
4135

4236
export class PnpmWorkspaceFile extends BaseWorkspaceFile {
@@ -47,7 +41,6 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile {
4741

4842
private _workspacePackages: Set<string>;
4943
private _catalogs: Record<string, Record<string, string>> | undefined;
50-
private _onlyBuiltDependencies: string[] | undefined;
5144

5245
/**
5346
* The PNPM workspace file is used to specify the location of workspaces relative to the root
@@ -61,7 +54,6 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile {
6154
// If we need to support manual customization, that should be an additional parameter for "base file"
6255
this._workspacePackages = new Set<string>();
6356
this._catalogs = undefined;
64-
this._onlyBuiltDependencies = undefined;
6557
}
6658

6759
/**
@@ -72,15 +64,6 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile {
7264
this._catalogs = catalogs;
7365
}
7466

75-
/**
76-
* Sets the onlyBuiltDependencies list for the workspace.
77-
* This specifies which dependencies are allowed to run build scripts in PNPM 10.1.0+.
78-
* @param deps - An array of package names allowed to run build scripts
79-
*/
80-
public setOnlyBuiltDependencies(deps: string[] | undefined): void {
81-
this._onlyBuiltDependencies = deps;
82-
}
83-
8467
/** @override */
8568
public addPackage(packagePath: string): void {
8669
// Ensure the path is relative to the pnpm-workspace.yaml file
@@ -106,10 +89,6 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile {
10689
workspaceYaml.catalogs = this._catalogs;
10790
}
10891

109-
if (this._onlyBuiltDependencies && this._onlyBuiltDependencies.length > 0) {
110-
workspaceYaml.onlyBuiltDependencies = this._onlyBuiltDependencies;
111-
}
112-
11392
return yamlModule.dump(workspaceYaml, PNPM_SHRINKWRAP_YAML_FORMAT);
11493
}
11594
}

libraries/rush-lib/src/logic/pnpm/test/PnpmWorkspaceFile.test.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -180,61 +180,4 @@ describe(PnpmWorkspaceFile.name, () => {
180180
expect(content).toMatchSnapshot();
181181
});
182182
});
183-
184-
describe('onlyBuiltDependencies functionality', () => {
185-
it('generates workspace file with onlyBuiltDependencies', () => {
186-
const workspaceFile: PnpmWorkspaceFile = new PnpmWorkspaceFile(workspaceFilePath);
187-
workspaceFile.addPackage(path.join(projectsDir, 'app1'));
188-
189-
workspaceFile.setOnlyBuiltDependencies(['esbuild', 'playwright', '@swc/core']);
190-
191-
workspaceFile.save(workspaceFilePath, { onlyIfChanged: true });
192-
193-
const content: string = FileSystem.readFile(workspaceFilePath);
194-
expect(content).toMatchSnapshot();
195-
});
196-
197-
it('handles empty onlyBuiltDependencies array', () => {
198-
const workspaceFile: PnpmWorkspaceFile = new PnpmWorkspaceFile(workspaceFilePath);
199-
workspaceFile.addPackage(path.join(projectsDir, 'app1'));
200-
201-
workspaceFile.setOnlyBuiltDependencies([]);
202-
203-
workspaceFile.save(workspaceFilePath, { onlyIfChanged: true });
204-
205-
const content: string = FileSystem.readFile(workspaceFilePath);
206-
expect(content).toMatchSnapshot();
207-
});
208-
209-
it('handles undefined onlyBuiltDependencies', () => {
210-
const workspaceFile: PnpmWorkspaceFile = new PnpmWorkspaceFile(workspaceFilePath);
211-
workspaceFile.addPackage(path.join(projectsDir, 'app1'));
212-
213-
workspaceFile.setOnlyBuiltDependencies(undefined);
214-
215-
workspaceFile.save(workspaceFilePath, { onlyIfChanged: true });
216-
217-
const content: string = FileSystem.readFile(workspaceFilePath);
218-
expect(content).toMatchSnapshot();
219-
});
220-
221-
it('generates workspace file with both catalogs and onlyBuiltDependencies', () => {
222-
const workspaceFile: PnpmWorkspaceFile = new PnpmWorkspaceFile(workspaceFilePath);
223-
workspaceFile.addPackage(path.join(projectsDir, 'app1'));
224-
225-
workspaceFile.setCatalogs({
226-
default: {
227-
react: '^18.0.0',
228-
'react-dom': '^18.0.0'
229-
}
230-
});
231-
232-
workspaceFile.setOnlyBuiltDependencies(['esbuild', 'playwright']);
233-
234-
workspaceFile.save(workspaceFilePath, { onlyIfChanged: true });
235-
236-
const content: string = FileSystem.readFile(workspaceFilePath);
237-
expect(content).toMatchSnapshot();
238-
});
239-
});
240183
});

libraries/rush-lib/src/logic/pnpm/test/__snapshots__/PnpmWorkspaceFile.test.ts.snap

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,3 @@ exports[`PnpmWorkspaceFile catalog functionality handles undefined catalog 1`] =
6565
- projects/app1
6666
"
6767
`;
68-
69-
exports[`PnpmWorkspaceFile onlyBuiltDependencies functionality generates workspace file with both catalogs and onlyBuiltDependencies 1`] = `
70-
"catalogs:
71-
default:
72-
react: ^18.0.0
73-
react-dom: ^18.0.0
74-
onlyBuiltDependencies:
75-
- esbuild
76-
- playwright
77-
packages:
78-
- projects/app1
79-
"
80-
`;
81-
82-
exports[`PnpmWorkspaceFile onlyBuiltDependencies functionality generates workspace file with onlyBuiltDependencies 1`] = `
83-
"onlyBuiltDependencies:
84-
- esbuild
85-
- playwright
86-
- '@swc/core'
87-
packages:
88-
- projects/app1
89-
"
90-
`;
91-
92-
exports[`PnpmWorkspaceFile onlyBuiltDependencies functionality handles empty onlyBuiltDependencies array 1`] = `
93-
"packages:
94-
- projects/app1
95-
"
96-
`;
97-
98-
exports[`PnpmWorkspaceFile onlyBuiltDependencies functionality handles undefined onlyBuiltDependencies 1`] = `
99-
"packages:
100-
- projects/app1
101-
"
102-
`;

libraries/rush-lib/src/logic/test/InstallHelpers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('InstallHelpers', () => {
6767
}
6868
},
6969
neverBuiltDependencies: ['fsevents', 'level'],
70+
onlyBuiltDependencies: ['esbuild', 'playwright'],
7071
pnpmFutureFeature: true
7172
}
7273
})

libraries/rush-lib/src/logic/test/pnpmConfig/common/config/rush/pnpm-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
}
1414
},
1515
"globalNeverBuiltDependencies": ["fsevents", "level"],
16+
"globalOnlyBuiltDependencies": ["esbuild", "playwright"],
1617
"globalCatalogs": {
1718
"default": {
1819
"react": "^18.0.0",

0 commit comments

Comments
 (0)