Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit c306ffd

Browse files
committed
refactor: update paths to use new API of @schematics/angular
(cherry picked from commit 12cb8ea)
1 parent 414ba71 commit c306ffd

File tree

3 files changed

+44
-69
lines changed

3 files changed

+44
-69
lines changed

modules/common/schematics/ng-add/index.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,27 @@ import {
2121
url,
2222
} from '@angular-devkit/schematics';
2323
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
24+
import {
25+
DependencyType,
26+
addDependency,
27+
readWorkspace,
28+
updateWorkspace,
29+
} from '@schematics/angular/utility';
2430
import {
2531
addImportToModule,
2632
findNode,
2733
getDecoratorMetadata,
2834
} from '@schematics/angular/utility/ast-utils';
2935
import { InsertChange, applyToUpdateRecorder } from '@schematics/angular/utility/change';
30-
import {
31-
NodeDependencyType,
32-
addPackageJsonDependency,
33-
} from '@schematics/angular/utility/dependencies';
3436
import { findBootstrapModulePath } from '@schematics/angular/utility/ng-ast-utils';
35-
import { getWorkspace, updateWorkspace } from '@schematics/angular/utility/workspace';
3637
import { posix } from 'path';
3738
import * as ts from 'typescript';
3839

3940
import { Schema as NgAddOptions } from './schema';
4041

4142
export default function (options: NgAddOptions): Rule {
4243
return async (host, context) => {
43-
const workspace = await getWorkspace(host);
44+
const workspace = await readWorkspace(host);
4445
const project = workspace.projects.get(options.project);
4546

4647
if (project.extensions.projectType !== 'application') {
@@ -59,37 +60,19 @@ export default function (options: NgAddOptions): Rule {
5960
return chain([
6061
augmentAppModuleRule(project, clientBuildTarget, options),
6162
options.ssr ? addSSRRule(project, clientBuildTarget) : noop(),
62-
options.prerender ? addPreRenderRule() : noop(),
63+
options.prerender
64+
? addDependency('@nguniversal/builders', '~0.0.0-PLACEHOLDER', {
65+
type: DependencyType.Dev,
66+
})
67+
: noop(),
6368
addScriptsRule(options),
6469
updateWorkspaceRule(options),
6570
]);
6671
};
6772
}
6873

69-
function addPreRenderRule(): Rule {
70-
return async (host) => {
71-
addPackageJsonDependency(host, {
72-
name: '@nguniversal/builders',
73-
type: NodeDependencyType.Dev,
74-
version: '~0.0.0-PLACEHOLDER',
75-
});
76-
};
77-
}
78-
7974
function addSSRRule(project: ProjectDefinition, buildTarget: TargetDefinition): Rule {
80-
return async (host) => {
81-
addPackageJsonDependency(host, {
82-
type: NodeDependencyType.Default,
83-
name: 'express',
84-
version: 'EXPRESS_VERSION',
85-
});
86-
87-
addPackageJsonDependency(host, {
88-
type: NodeDependencyType.Dev,
89-
name: '@types/express',
90-
version: 'EXPRESS_TYPES_VERSION',
91-
});
92-
75+
return async () => {
9376
const templateSource = apply(url('./files/src'), [
9477
applyTemplates({}),
9578
move(project.sourceRoot ?? '/src'),
@@ -102,7 +85,17 @@ function addSSRRule(project: ProjectDefinition, buildTarget: TargetDefinition):
10285
move(project.root),
10386
]);
10487

105-
return chain([mergeWith(templateSource), mergeWith(rootSource)]);
88+
return chain([
89+
addDependency('express', 'EXPRESS_VERSION', {
90+
type: DependencyType.Default,
91+
}),
92+
93+
addDependency('@types/express', 'EXPRESS_TYPES_VERSION', {
94+
type: DependencyType.Dev,
95+
}),
96+
mergeWith(templateSource),
97+
mergeWith(rootSource),
98+
]);
10699
};
107100
}
108101

modules/express-engine/schematics/install/index.ts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import { dirname, join, normalize, strings } from '@angular-devkit/core';
1010
import {
1111
Rule,
12-
SchematicContext,
1312
SchematicsException,
1413
Tree,
1514
apply,
@@ -21,14 +20,9 @@ import {
2120
template,
2221
url,
2322
} from '@angular-devkit/schematics';
24-
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
2523
import { Schema as UniversalOptions } from '@schematics/angular/universal/schema';
26-
import {
27-
NodeDependencyType,
28-
addPackageJsonDependency,
29-
} from '@schematics/angular/utility/dependencies';
24+
import { DependencyType, addDependency, updateWorkspace } from '@schematics/angular/utility';
3025
import { JSONFile } from '@schematics/angular/utility/json-file';
31-
import { updateWorkspace } from '@schematics/angular/utility/workspace';
3226
import * as ts from 'typescript';
3327

3428
import {
@@ -263,34 +257,22 @@ function routingInitialNavigationRule(options: UniversalOptions): Rule {
263257
};
264258
}
265259

266-
function addDependencies(options: UniversalOptions): Rule {
267-
return (host: Tree, context: SchematicContext) => {
268-
if (!options.skipInstall) {
269-
context.addTask(new NodePackageInstallTask());
270-
}
271-
addPackageJsonDependency(host, {
272-
name: '@nguniversal/builders',
273-
type: NodeDependencyType.Dev,
274-
version: '^0.0.0-PLACEHOLDER',
275-
});
276-
277-
addPackageJsonDependency(host, {
278-
type: NodeDependencyType.Default,
279-
name: '@nguniversal/express-engine',
280-
version: '^0.0.0-PLACEHOLDER',
281-
});
282-
addPackageJsonDependency(host, {
283-
type: NodeDependencyType.Default,
284-
name: 'express',
285-
version: 'EXPRESS_VERSION',
286-
});
287-
addPackageJsonDependency(host, {
288-
type: NodeDependencyType.Dev,
289-
name: '@types/express',
290-
version: 'EXPRESS_TYPES_VERSION',
291-
});
292-
293-
return host;
260+
function addDependencies(): Rule {
261+
return (_host: Tree) => {
262+
return chain([
263+
addDependency('@nguniversal/builders', '^0.0.0-PLACEHOLDER', {
264+
type: DependencyType.Dev,
265+
}),
266+
addDependency('@nguniversal/express-engine', '^0.0.0-PLACEHOLDER', {
267+
type: DependencyType.Default,
268+
}),
269+
addDependency('express', 'EXPRESS_VERSION', {
270+
type: DependencyType.Default,
271+
}),
272+
addDependency('@types/express', 'EXPRESS_TYPES_VERSION', {
273+
type: DependencyType.Dev,
274+
}),
275+
]);
294276
};
295277
}
296278

@@ -333,7 +315,7 @@ export default function (options: AddUniversalOptions): Rule {
333315
updateWorkspaceConfigRule(options),
334316
routingInitialNavigationRule(options),
335317
addServerFile(options),
336-
addDependencies(options),
318+
addDependencies(),
337319
]);
338320
};
339321
}

modules/express-engine/schematics/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import { workspaces } from '@angular-devkit/core';
1010
import { SchematicsException } from '@angular-devkit/schematics';
1111
import { Tree } from '@angular-devkit/schematics/src/tree/interface';
12-
import { getWorkspace } from '@schematics/angular/utility/workspace';
12+
import { readWorkspace } from '@schematics/angular/utility';
1313
import * as ts from 'typescript';
1414

1515
export async function getProject(
1616
host: Tree,
1717
projectName: string,
1818
): Promise<workspaces.ProjectDefinition> {
19-
const workspace = await getWorkspace(host);
19+
const workspace = await readWorkspace(host);
2020
const project = workspace.projects.get(projectName);
2121

2222
if (!project || project.extensions.projectType !== 'application') {

0 commit comments

Comments
 (0)