Skip to content

Commit

Permalink
fix(@schematics/angular): do not trigger NPM install when using `---s…
Browse files Browse the repository at this point in the history
…kip-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`.
  • Loading branch information
alan-agius4 committed Dec 22, 2023
1 parent 1867a0a commit bfd54b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default function (options: ApplicationOptions): Rule {
options.ssr
? schematic('ssr', {
project: options.name,
skipInstall: options.skipInstall,
})
: noop(),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(options),
Expand Down
20 changes: 16 additions & 4 deletions packages/schematics/angular/ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import {
} from '@angular-devkit/schematics';
import { posix } from 'node:path';
import { Schema as ServerOptions } from '../server/schema';
import { DependencyType, addDependency, readWorkspace, updateWorkspace } from '../utility';
import {
DependencyType,
InstallBehavior,
addDependency,
readWorkspace,
updateWorkspace,
} from '../utility';
import { JSONFile } from '../utility/json-file';
import { latestVersions } from '../utility/latest-versions';
import { isStandaloneApp } from '../utility/ng-ast-utils';
Expand Down Expand Up @@ -288,23 +294,29 @@ function updateWebpackBuilderServerTsConfigRule(options: SSROptions): Rule {
};
}

function addDependencies(isUsingApplicationBuilder: boolean): Rule {
function addDependencies({ skipInstall }: SSROptions, isUsingApplicationBuilder: boolean): Rule {
const install = skipInstall ? InstallBehavior.None : InstallBehavior.Auto;

const rules: Rule[] = [
addDependency('@angular/ssr', latestVersions.AngularSSR, {
type: DependencyType.Default,
install,
}),
addDependency('express', latestVersions['express'], {
type: DependencyType.Default,
install,
}),
addDependency('@types/express', latestVersions['@types/express'], {
type: DependencyType.Dev,
install,
}),
];

if (!isUsingApplicationBuilder) {
rules.push(
addDependency('browser-sync', latestVersions['browser-sync'], {
type: DependencyType.Dev,
install,
}),
);
}
Expand Down Expand Up @@ -360,7 +372,7 @@ export default function (options: SSROptions): Rule {
return chain([
schematic('server', {
...options,
skipInstall: true,
skipInstall: options.skipInstall,
}),
...(isUsingApplicationBuilder
? [
Expand All @@ -373,7 +385,7 @@ export default function (options: SSROptions): Rule {
]),
addServerFile(options, isStandalone),
addScriptsRule(options, isUsingApplicationBuilder),
addDependencies(isUsingApplicationBuilder),
addDependencies(options, isUsingApplicationBuilder),
]);
};
}

0 comments on commit bfd54b6

Please sign in to comment.