Skip to content

Commit a69fe51

Browse files
authored
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.
1 parent ef600f2 commit a69fe51

2 files changed

Lines changed: 79 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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,78 @@ 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', () => {
157+
it('should pass ignoreScriptsFlag by default when no options are provided', async () => {
158+
const testHost = new MockHost({ '/tmp/project/node_modules': true });
159+
const pm = new PackageManager(testHost, '/tmp/project', descriptor);
160+
spyOn(testHost, 'createTempDirectory').and.resolveTo(
161+
'/tmp/project/node_modules/angular-cli-tmp-packages-abc',
162+
);
163+
spyOn(testHost, 'writeFile').and.resolveTo();
164+
spyOn(testHost, 'runCommand').and.resolveTo({ stdout: '', stderr: '' });
165+
166+
await pm.acquireTempPackage('foo@1.0.0');
167+
168+
expect(testHost.runCommand).toHaveBeenCalledWith(
169+
descriptor.binary,
170+
[descriptor.addCommand, 'foo@1.0.0', descriptor.ignoreScriptsFlag],
171+
jasmine.any(Object),
172+
);
173+
});
174+
175+
it('should not pass ignoreScriptsFlag when ignoreScripts is explicitly false', async () => {
176+
const testHost = new MockHost({ '/tmp/project/node_modules': true });
177+
const pm = new PackageManager(testHost, '/tmp/project', descriptor);
178+
spyOn(testHost, 'createTempDirectory').and.resolveTo(
179+
'/tmp/project/node_modules/angular-cli-tmp-packages-abc',
180+
);
181+
spyOn(testHost, 'writeFile').and.resolveTo();
182+
spyOn(testHost, 'runCommand').and.resolveTo({ stdout: '', stderr: '' });
183+
184+
await pm.acquireTempPackage('foo@1.0.0', { ignoreScripts: false });
185+
186+
expect(testHost.runCommand).toHaveBeenCalledWith(
187+
descriptor.binary,
188+
[descriptor.addCommand, 'foo@1.0.0'],
189+
jasmine.any(Object),
190+
);
191+
});
192+
122193
it('should copy and sanitize pnpm-workspace.yaml when package manager is pnpm and workspace file exists', async () => {
123194
const pnpmDescriptor = SUPPORTED_PACKAGE_MANAGERS['pnpm'];
124195
const testHost = new MockHost({ '/tmp/project/node_modules': true });

0 commit comments

Comments
 (0)