Skip to content

Commit 4469e48

Browse files
committed
fix(@schematics/angular): do not trigger NPM install when using ---skip-install and --ssr
The `skipInstall` option was never passed to the ssr schematic, which caused NPM install to also be invoked when running `ng new --ssr`.
1 parent 220a7e8 commit 4469e48

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default function (options: ApplicationOptions): Rule {
101101
options.ssr
102102
? schematic('ssr', {
103103
project: options.name,
104+
skipInstall: true,
104105
})
105106
: noop(),
106107
options.skipPackageJson ? noop() : addDependenciesToPackageJson(options),

packages/schematics/angular/application/index_spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ describe('Application Schematic', () => {
105105
expect(_extends).toBe('../../tsconfig.json');
106106
});
107107

108+
it('should install npm dependencies when `skipInstall` is false', async () => {
109+
await schematicRunner.runSchematic(
110+
'application',
111+
{ ...defaultOptions, ssr: true, skipInstall: false },
112+
workspaceTree,
113+
);
114+
expect(schematicRunner.tasks.length).toBe(1);
115+
expect(schematicRunner.tasks[0].name).toBe('node-package');
116+
expect((schematicRunner.tasks[0].options as { command: string }).command).toBe('install');
117+
});
118+
119+
it('should not install npm dependencies when `skipInstall` is true', async () => {
120+
await schematicRunner.runSchematic(
121+
'application',
122+
{ ...defaultOptions, ssr: true, skipInstall: true },
123+
workspaceTree,
124+
);
125+
expect(schematicRunner.tasks.length).toBe(0);
126+
});
127+
108128
it('should set the skipTests flag for other schematics when using --skipTests=true', async () => {
109129
const options: ApplicationOptions = { ...defaultOptions, skipTests: true };
110130
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);

packages/schematics/angular/ssr/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import {
2222
} from '@angular-devkit/schematics';
2323
import { posix } from 'node:path';
2424
import { Schema as ServerOptions } from '../server/schema';
25-
import { DependencyType, addDependency, readWorkspace, updateWorkspace } from '../utility';
25+
import {
26+
DependencyType,
27+
InstallBehavior,
28+
addDependency,
29+
readWorkspace,
30+
updateWorkspace,
31+
} from '../utility';
2632
import { JSONFile } from '../utility/json-file';
2733
import { latestVersions } from '../utility/latest-versions';
2834
import { isStandaloneApp } from '../utility/ng-ast-utils';
@@ -288,23 +294,29 @@ function updateWebpackBuilderServerTsConfigRule(options: SSROptions): Rule {
288294
};
289295
}
290296

291-
function addDependencies(isUsingApplicationBuilder: boolean): Rule {
297+
function addDependencies({ skipInstall }: SSROptions, isUsingApplicationBuilder: boolean): Rule {
298+
const install = skipInstall ? InstallBehavior.None : InstallBehavior.Auto;
299+
292300
const rules: Rule[] = [
293301
addDependency('@angular/ssr', latestVersions.AngularSSR, {
294302
type: DependencyType.Default,
303+
install,
295304
}),
296305
addDependency('express', latestVersions['express'], {
297306
type: DependencyType.Default,
307+
install,
298308
}),
299309
addDependency('@types/express', latestVersions['@types/express'], {
300310
type: DependencyType.Dev,
311+
install,
301312
}),
302313
];
303314

304315
if (!isUsingApplicationBuilder) {
305316
rules.push(
306317
addDependency('browser-sync', latestVersions['browser-sync'], {
307318
type: DependencyType.Dev,
319+
install,
308320
}),
309321
);
310322
}
@@ -373,7 +385,7 @@ export default function (options: SSROptions): Rule {
373385
]),
374386
addServerFile(options, isStandalone),
375387
addScriptsRule(options, isUsingApplicationBuilder),
376-
addDependencies(isUsingApplicationBuilder),
388+
addDependencies(options, isUsingApplicationBuilder),
377389
]);
378390
};
379391
}

0 commit comments

Comments
 (0)