Skip to content

Commit 77e53a6

Browse files
vikermanhansl
authored andcommitted
fix(@schematics/angular): npm install at the end of ng g universal
1 parent 9795bb4 commit 77e53a6

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

packages/schematics/angular/universal/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import {
2525
template,
2626
url,
2727
} from '@angular-devkit/schematics';
28+
import {
29+
NodePackageInstallTask,
30+
} from '@angular-devkit/schematics/tasks';
2831
import * as ts from 'typescript';
2932
import { findNode, getDecoratorMetadata } from '../utility/ast-utils';
3033
import { InsertChange } from '../utility/change';
@@ -208,6 +211,11 @@ export default function (options: UniversalOptions): Rule {
208211
const clientArchitect = getClientArchitect(host, options);
209212
const outDir = getTsConfigOutDir(host, clientArchitect);
210213
const tsConfigExtends = basename(clientArchitect.build.options.tsConfig);
214+
215+
if (!options.skipInstall) {
216+
context.addTask(new NodePackageInstallTask());
217+
}
218+
211219
const templateSource = apply(url('./files'), [
212220
template({
213221
...strings,

packages/schematics/angular/universal/index_spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,11 @@ describe('Universal Schematic', () => {
109109
const contents = tree.readContent(filePath);
110110
expect(contents).toMatch(/document.addEventListener\('DOMContentLoaded', \(\) => {/);
111111
});
112+
113+
it('should install npm dependencies', () => {
114+
schematicRunner.runSchematic('universal', defaultOptions, appTree);
115+
expect(schematicRunner.tasks.length).toBe(1);
116+
expect(schematicRunner.tasks[0].name).toBe('node-package');
117+
expect((schematicRunner.tasks[0].options as {command: string}).command).toBe('install');
118+
});
112119
});

packages/schematics/angular/universal/schema.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ export interface Schema {
4343
* The name of the root module class.
4444
*/
4545
rootModuleClassName?: string;
46+
/**
47+
* Skip installing dependency packages.
48+
*/
49+
skipInstall?: boolean;
4650
}

packages/schematics/angular/universal/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
"type": "string",
5353
"description": "The name of the root module class.",
5454
"default": "AppServerModule"
55+
},
56+
"skipInstall": {
57+
"description": "Skip installing dependency packages.",
58+
"type": "boolean",
59+
"default": false
5560
}
5661
},
5762
"required": [

0 commit comments

Comments
 (0)