Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/angular/cli/src/package-managers/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,15 @@ export class PackageManager {
registry?: string;
ignoreScripts?: boolean;
ignorePeerDependencies?: boolean;
} = { ignoreScripts: true },
} = {},
): Promise<void> {
const { force, ignoreScripts = true, ignorePeerDependencies } = options;
const flags = [
options.force ? this.descriptor.forceFlag : '',
options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
options.ignorePeerDependencies ? (this.descriptor.ignorePeerDependenciesFlag ?? '') : '',
force ? this.descriptor.forceFlag : '',
ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
ignorePeerDependencies ? (this.descriptor.ignorePeerDependenciesFlag ?? '') : '',
].filter((flag) => flag);

const args = [...this.descriptor.installCommand, ...flags];

await this.#run(args, options);
Expand Down Expand Up @@ -787,9 +789,8 @@ export class PackageManager {
}
}

const flags = [options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : ''].filter(
(flag) => flag,
);
const { ignoreScripts = true } = options;
const flags = [ignoreScripts ? this.descriptor.ignoreScriptsFlag : ''].filter((flag) => flag);
const args: readonly string[] = [this.descriptor.addCommand, specifier, ...flags];

try {
Expand Down
71 changes: 71 additions & 0 deletions packages/angular/cli/src/package-managers/package-manager_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,78 @@ describe('PackageManager', () => {
});
});

describe('install', () => {
it('should pass ignoreScriptsFlag by default when no options are provided', async () => {
const pm = new PackageManager(host, '/tmp', descriptor);
await pm.install();

expect(runCommandSpy).toHaveBeenCalledWith(
descriptor.binary,
[...descriptor.installCommand, descriptor.ignoreScriptsFlag],
jasmine.objectContaining({ cwd: '/tmp' }),
);
});

it('should pass ignoreScriptsFlag by default when other options are provided', async () => {
const pm = new PackageManager(host, '/tmp', descriptor);
await pm.install({ force: true });

expect(runCommandSpy).toHaveBeenCalledWith(
descriptor.binary,
[...descriptor.installCommand, descriptor.forceFlag, descriptor.ignoreScriptsFlag],
jasmine.objectContaining({ cwd: '/tmp' }),
);
});

it('should not pass ignoreScriptsFlag when ignoreScripts is explicitly false', async () => {
const pm = new PackageManager(host, '/tmp', descriptor);
await pm.install({ ignoreScripts: false });

expect(runCommandSpy).toHaveBeenCalledWith(
descriptor.binary,
[...descriptor.installCommand],
jasmine.objectContaining({ cwd: '/tmp' }),
);
});
});

describe('acquireTempPackage', () => {
Comment thread
alan-agius4 marked this conversation as resolved.
Resolved
it('should pass ignoreScriptsFlag by default when no options are provided', async () => {
const testHost = new MockHost({ '/tmp/project/node_modules': true });
const pm = new PackageManager(testHost, '/tmp/project', descriptor);
spyOn(testHost, 'createTempDirectory').and.resolveTo(
'/tmp/project/node_modules/angular-cli-tmp-packages-abc',
);
spyOn(testHost, 'writeFile').and.resolveTo();
spyOn(testHost, 'runCommand').and.resolveTo({ stdout: '', stderr: '' });

await pm.acquireTempPackage('foo@1.0.0');

expect(testHost.runCommand).toHaveBeenCalledWith(
descriptor.binary,
[descriptor.addCommand, 'foo@1.0.0', descriptor.ignoreScriptsFlag],
jasmine.any(Object),
);
});

it('should not pass ignoreScriptsFlag when ignoreScripts is explicitly false', async () => {
const testHost = new MockHost({ '/tmp/project/node_modules': true });
const pm = new PackageManager(testHost, '/tmp/project', descriptor);
spyOn(testHost, 'createTempDirectory').and.resolveTo(
'/tmp/project/node_modules/angular-cli-tmp-packages-abc',
);
spyOn(testHost, 'writeFile').and.resolveTo();
spyOn(testHost, 'runCommand').and.resolveTo({ stdout: '', stderr: '' });

await pm.acquireTempPackage('foo@1.0.0', { ignoreScripts: false });

expect(testHost.runCommand).toHaveBeenCalledWith(
descriptor.binary,
[descriptor.addCommand, 'foo@1.0.0'],
jasmine.any(Object),
);
});

it('should copy and sanitize pnpm-workspace.yaml when package manager is pnpm and workspace file exists', async () => {
const pnpmDescriptor = SUPPORTED_PACKAGE_MANAGERS['pnpm'];
const testHost = new MockHost({ '/tmp/project/node_modules': true });
Expand Down
Loading