Skip to content

Commit 8848a2c

Browse files
committed
fix(@angular/cli): default ignoreScripts to true when install options are provided
Previously, `PackageManager.install()` used a parameter-level default `options = { ignoreScripts: true }`, which caused `ignoreScripts` to be `undefined` whenever any option (such as `ignorePeerDependencies` during `ng update`) was provided without explicitly specifying `ignoreScripts`. Similarly, `PackageManager.acquireTempPackage()` did not default `ignoreScripts` to `true` unless explicitly passed. Ensure `ignoreScripts` defaults to `true` in both methods unless explicitly set to `false`.
1 parent ef600f2 commit 8848a2c

2 files changed

Lines changed: 43 additions & 7 deletions

File tree

‎packages/angular/cli/src/package-managers/package-manager.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,15 @@ export class PackageManager {
391391
registry?: string;
392392
ignoreScripts?: boolean;
393393
ignorePeerDependencies?: boolean;
394-
} = { ignoreScripts: true },
394+
} = {},
395395
): Promise<void> {
396+
const { force, ignoreScripts = true, ignorePeerDependencies } = options;
396397
const flags = [
397-
options.force ? this.descriptor.forceFlag : '',
398-
options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
399-
options.ignorePeerDependencies ? (this.descriptor.ignorePeerDependenciesFlag ?? '') : '',
398+
force ? this.descriptor.forceFlag : '',
399+
ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
400+
ignorePeerDependencies ? (this.descriptor.ignorePeerDependenciesFlag ?? '') : '',
400401
].filter((flag) => flag);
402+
401403
const args = [...this.descriptor.installCommand, ...flags];
402404

403405
await this.#run(args, options);
@@ -787,9 +789,8 @@ export class PackageManager {
787789
}
788790
}
789791

790-
const flags = [options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : ''].filter(
791-
(flag) => flag,
792-
);
792+
const { ignoreScripts = true } = options;
793+
const flags = [ignoreScripts ? this.descriptor.ignoreScriptsFlag : ''].filter((flag) => flag);
793794
const args: readonly string[] = [this.descriptor.addCommand, specifier, ...flags];
794795

795796
try {

‎packages/angular/cli/src/package-managers/package-manager_spec.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,41 @@ describe('PackageManager', () => {
118118
});
119119
});
120120

121+
describe('install', () => {
122+
it('should pass ignoreScriptsFlag by default when no options are provided', async () => {
123+
const pm = new PackageManager(host, '/tmp', descriptor);
124+
await pm.install();
125+
126+
expect(runCommandSpy).toHaveBeenCalledWith(
127+
descriptor.binary,
128+
[...descriptor.installCommand, descriptor.ignoreScriptsFlag],
129+
jasmine.objectContaining({ cwd: '/tmp' }),
130+
);
131+
});
132+
133+
it('should pass ignoreScriptsFlag by default when other options are provided', async () => {
134+
const pm = new PackageManager(host, '/tmp', descriptor);
135+
await pm.install({ force: true });
136+
137+
expect(runCommandSpy).toHaveBeenCalledWith(
138+
descriptor.binary,
139+
[...descriptor.installCommand, descriptor.forceFlag, descriptor.ignoreScriptsFlag],
140+
jasmine.objectContaining({ cwd: '/tmp' }),
141+
);
142+
});
143+
144+
it('should not pass ignoreScriptsFlag when ignoreScripts is explicitly false', async () => {
145+
const pm = new PackageManager(host, '/tmp', descriptor);
146+
await pm.install({ ignoreScripts: false });
147+
148+
expect(runCommandSpy).toHaveBeenCalledWith(
149+
descriptor.binary,
150+
[...descriptor.installCommand],
151+
jasmine.objectContaining({ cwd: '/tmp' }),
152+
);
153+
});
154+
});
155+
121156
describe('acquireTempPackage', () => {
122157
it('should copy and sanitize pnpm-workspace.yaml when package manager is pnpm and workspace file exists', async () => {
123158
const pnpmDescriptor = SUPPORTED_PACKAGE_MANAGERS['pnpm'];

0 commit comments

Comments
 (0)