Skip to content

Commit 90a5a7d

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
feat(@schematics/angular): install packages when creating a new application
Fixes #12719
1 parent a3b05a0 commit 90a5a7d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
template,
2323
url,
2424
} from '@angular-devkit/schematics';
25+
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
2526
import { Schema as E2eOptions } from '../e2e/schema';
2627
import {
2728
addProjectToWorkspace,
@@ -63,8 +64,8 @@ import { Schema as ApplicationOptions } from './schema';
6364
// );
6465
// }
6566

66-
function addDependenciesToPackageJson() {
67-
return (host: Tree) => {
67+
function addDependenciesToPackageJson(options: ApplicationOptions) {
68+
return (host: Tree, context: SchematicContext) => {
6869
[
6970
{
7071
type: NodeDependencyType.Dev,
@@ -83,6 +84,10 @@ function addDependenciesToPackageJson() {
8384
},
8485
].forEach(dependency => addPackageJsonDependency(host, dependency));
8586

87+
if (!options.skipInstall) {
88+
context.addTask(new NodePackageInstallTask());
89+
}
90+
8691
return host;
8792
};
8893
}
@@ -299,7 +304,6 @@ export default function (options: ApplicationOptions): Rule {
299304

300305
return chain([
301306
addAppToWorkspaceFile(options, workspace),
302-
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
303307
mergeWith(
304308
apply(url('./files/src'), [
305309
options.minimal ? filter(minimalPathFilter) : noop(),
@@ -369,6 +373,7 @@ export default function (options: ApplicationOptions): Rule {
369373
move(sourceDir),
370374
]), MergeStrategy.Overwrite),
371375
schematic('e2e', e2eOptions),
376+
options.skipPackageJson ? noop() : addDependenciesToPackageJson(options),
372377
]);
373378
};
374379
}

packages/schematics/angular/application/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
"description": "Create a barebones project without any testing frameworks",
7373
"type": "boolean",
7474
"default": false
75+
},
76+
"skipInstall": {
77+
"description": "Skip installing dependency packages.",
78+
"type": "boolean",
79+
"default": false
7580
}
7681
},
7782
"required": [

packages/schematics/angular/ng-new/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export default function (options: NgNewOptions): Rule {
5555
style: options.style,
5656
skipTests: options.skipTests,
5757
skipPackageJson: false,
58+
// always 'skipInstall' here, so that we do it after the move
59+
skipInstall: true,
5860
};
5961

6062
return chain([

0 commit comments

Comments
 (0)