@schematics/angular 12.0.0-rc.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -20
- package/app-shell/app-shell-long.md +2 -2
- package/app-shell/index.d.ts +7 -0
- package/app-shell/index.js +17 -19
- package/app-shell/schema.d.ts +4 -4
- package/app-shell/schema.json +2 -4
- package/application/index.d.ts +7 -0
- package/application/index.js +46 -47
- package/application/other-files/app.component.html.template +0 -11
- package/application/schema.json +15 -13
- package/class/index.d.ts +7 -0
- package/class/index.js +9 -9
- package/class/schema.json +1 -3
- package/collection.json +13 -13
- package/component/index.d.ts +7 -0
- package/component/index.js +23 -20
- package/component/schema.json +3 -10
- package/directive/index.d.ts +7 -0
- package/directive/index.js +13 -13
- package/directive/schema.json +1 -3
- package/e2e/e2e-long.md +1 -1
- package/e2e/index.d.ts +7 -0
- package/e2e/index.js +20 -8
- package/e2e/schema.json +1 -3
- package/enum/files/{__name@dasherize__.enum.ts.template → __name@dasherize____type__.ts.template} +0 -0
- package/enum/index.d.ts +7 -0
- package/enum/index.js +8 -7
- package/enum/schema.d.ts +4 -0
- package/enum/schema.json +5 -3
- package/guard/files/__name@dasherize__.guard.ts.template +1 -1
- package/guard/index.d.ts +7 -0
- package/guard/index.js +20 -12
- package/guard/schema.json +3 -12
- package/interceptor/index.d.ts +7 -0
- package/interceptor/index.js +4 -4
- package/interface/index.d.ts +7 -0
- package/interface/index.js +3 -3
- package/interface/schema.json +1 -3
- package/library/index.d.ts +7 -0
- package/library/index.js +4 -4
- package/library/library-long.md +1 -1
- package/migrations/update-10/add-deprecation-rule-tslint.d.ts +7 -0
- package/migrations/update-10/add-deprecation-rule-tslint.js +8 -1
- package/migrations/update-10/remove-es5-browser-support.d.ts +1 -1
- package/migrations/update-10/remove-es5-browser-support.js +5 -9
- package/migrations/update-10/remove-solution-style-tsconfig.d.ts +7 -0
- package/migrations/update-10/remove-solution-style-tsconfig.js +4 -3
- package/migrations/update-10/rename-browserslist-config.d.ts +7 -0
- package/migrations/update-10/rename-browserslist-config.js +3 -3
- package/migrations/update-10/update-angular-config.d.ts +1 -1
- package/migrations/update-10/update-angular-config.js +2 -2
- package/migrations/update-10/update-dependencies.d.ts +1 -1
- package/migrations/update-10/update-dependencies.js +7 -0
- package/migrations/update-10/update-libraries-tslib.d.ts +1 -1
- package/migrations/update-10/update-libraries-tslib.js +1 -1
- package/migrations/update-10/update-module-and-target-compiler-options.d.ts +7 -0
- package/migrations/update-10/update-module-and-target-compiler-options.js +11 -12
- package/migrations/update-10/update-tslint.d.ts +7 -0
- package/migrations/update-10/update-tslint.js +13 -8
- package/migrations/update-11/add-declaration-map-compiler-option.d.ts +1 -1
- package/migrations/update-11/add-declaration-map-compiler-option.js +1 -1
- package/migrations/update-11/replace-ng-packagr-builder.d.ts +1 -1
- package/migrations/update-11/replace-ng-packagr-builder.js +3 -3
- package/migrations/update-11/update-angular-config.d.ts +1 -1
- package/migrations/update-11/update-angular-config.js +3 -3
- package/migrations/update-11/update-dependencies.d.ts +1 -1
- package/migrations/update-11/update-dependencies.js +7 -0
- package/migrations/update-12/production-default-config.d.ts +1 -1
- package/migrations/update-12/production-default-config.js +4 -3
- package/migrations/update-12/remove-emit-decorator-metadata.d.ts +7 -0
- package/migrations/update-12/remove-emit-decorator-metadata.js +15 -3
- package/migrations/update-12/update-angular-config.d.ts +1 -1
- package/migrations/update-12/update-angular-config.js +6 -5
- package/migrations/update-12/update-lazy-module-paths.d.ts +1 -1
- package/migrations/update-12/update-lazy-module-paths.js +9 -4
- package/migrations/update-12/update-web-workers.d.ts +1 -1
- package/migrations/update-12/update-web-workers.js +7 -0
- package/migrations/update-12/update-zonejs.d.ts +7 -0
- package/migrations/update-12/update-zonejs.js +3 -4
- package/migrations/update-9/add-tslib.d.ts +1 -1
- package/migrations/update-9/add-tslib.js +8 -1
- package/migrations/update-9/index.d.ts +1 -1
- package/migrations/update-9/index.js +2 -2
- package/migrations/update-9/ivy-libraries.d.ts +1 -1
- package/migrations/update-9/ivy-libraries.js +2 -2
- package/migrations/update-9/ngsw-config.d.ts +1 -1
- package/migrations/update-9/ngsw-config.js +7 -0
- package/migrations/update-9/remove-tsickle.d.ts +1 -1
- package/migrations/update-9/remove-tsickle.js +7 -0
- package/migrations/update-9/schematic-options.d.ts +7 -0
- package/migrations/update-9/schematic-options.js +3 -3
- package/migrations/update-9/update-app-tsconfigs.d.ts +7 -0
- package/migrations/update-9/update-app-tsconfigs.js +3 -3
- package/migrations/update-9/update-dependencies.d.ts +1 -1
- package/migrations/update-9/update-dependencies.js +7 -0
- package/migrations/update-9/update-i18n.d.ts +7 -0
- package/migrations/update-9/update-i18n.js +9 -4
- package/migrations/update-9/update-server-main-file.d.ts +1 -1
- package/migrations/update-9/update-server-main-file.js +12 -5
- package/migrations/update-9/update-workspace-config.d.ts +7 -0
- package/migrations/update-9/update-workspace-config.js +7 -0
- package/migrations/update-9/utils.d.ts +7 -0
- package/migrations/update-9/utils.js +3 -3
- package/module/index.d.ts +7 -0
- package/module/index.js +14 -16
- package/module/schema.json +2 -4
- package/ng-new/index.d.ts +1 -1
- package/ng-new/index.js +3 -5
- package/package.json +4 -4
- package/pipe/index.d.ts +7 -0
- package/pipe/index.js +8 -8
- package/pipe/schema.json +1 -3
- package/resolver/index.d.ts +7 -0
- package/resolver/index.js +9 -11
- package/resolver/schema.json +1 -3
- package/service/index.d.ts +7 -0
- package/service/index.js +4 -4
- package/service-worker/index.d.ts +7 -0
- package/service-worker/index.js +2 -2
- package/service-worker/schema.d.ts +13 -13
- package/service-worker/schema.json +1 -3
- package/universal/index.d.ts +7 -0
- package/universal/index.js +15 -14
- package/universal/schema.d.ts +4 -4
- package/universal/schema.json +6 -5
- package/utility/ast-utils.d.ts +7 -0
- package/utility/ast-utils.js +40 -45
- package/utility/change.d.ts +1 -1
- package/utility/change.js +13 -4
- package/utility/dependencies.d.ts +1 -1
- package/utility/dependencies.js +7 -0
- package/utility/find-module.d.ts +1 -1
- package/utility/find-module.js +14 -14
- package/utility/json-file.d.ts +1 -1
- package/utility/json-file.js +2 -2
- package/utility/latest-versions.d.ts +1 -1
- package/utility/latest-versions.js +3 -3
- package/utility/lint-fix.d.ts +1 -1
- package/utility/lint-fix.js +4 -4
- package/utility/ng-ast-utils.d.ts +7 -0
- package/utility/ng-ast-utils.js +8 -7
- package/utility/parse-name.d.ts +1 -1
- package/utility/parse-name.js +3 -3
- package/utility/paths.d.ts +1 -1
- package/utility/paths.js +1 -1
- package/utility/project-targets.d.ts +1 -1
- package/utility/project-targets.js +1 -1
- package/utility/test/create-app-module.d.ts +1 -1
- package/utility/test/create-app-module.js +7 -0
- package/utility/test/get-file-content.d.ts +1 -1
- package/utility/test/get-file-content.js +7 -0
- package/utility/test/index.d.ts +1 -1
- package/utility/test/index.js +7 -7
- package/utility/validation.d.ts +7 -0
- package/utility/validation.js +5 -5
- package/utility/workspace-models.d.ts +3 -3
- package/utility/workspace-models.js +3 -3
- package/utility/workspace.d.ts +1 -1
- package/utility/workspace.js +3 -3
- package/web-worker/index.d.ts +7 -0
- package/web-worker/index.js +8 -6
- package/web-worker/schema.json +1 -4
- package/workspace/files/package.json.template +2 -5
- package/workspace/index.d.ts +7 -0
- package/workspace/index.js +3 -3
- package/workspace/schema.json +1 -4
package/service/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
/**
|
|
4
3
|
* @license
|
|
5
|
-
* Copyright Google
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
6
5
|
*
|
|
7
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
8
7
|
* found in the LICENSE file at https://angular.io/license
|
|
9
8
|
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const core_1 = require("@angular-devkit/core");
|
|
11
11
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
12
12
|
const lint_fix_1 = require("../utility/lint-fix");
|
|
@@ -21,10 +21,10 @@ function default_1(options) {
|
|
|
21
21
|
options.name = parsedPath.name;
|
|
22
22
|
options.path = parsedPath.path;
|
|
23
23
|
const templateSource = schematics_1.apply(schematics_1.url('./files'), [
|
|
24
|
-
options.skipTests ? schematics_1.filter(path => !path.endsWith('.spec.ts.template')) : schematics_1.noop(),
|
|
24
|
+
options.skipTests ? schematics_1.filter((path) => !path.endsWith('.spec.ts.template')) : schematics_1.noop(),
|
|
25
25
|
schematics_1.applyTemplates({
|
|
26
26
|
...core_1.strings,
|
|
27
|
-
'if-flat': (s) => options.flat ? '' : s,
|
|
27
|
+
'if-flat': (s) => (options.flat ? '' : s),
|
|
28
28
|
...options,
|
|
29
29
|
}),
|
|
30
30
|
schematics_1.move(parsedPath.path),
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
1
8
|
import { Rule } from '@angular-devkit/schematics';
|
|
2
9
|
import { Schema as ServiceWorkerOptions } from './schema';
|
|
3
10
|
export default function (options: ServiceWorkerOptions): Rule;
|
package/service-worker/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
/**
|
|
4
3
|
* @license
|
|
5
|
-
* Copyright Google
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
6
5
|
*
|
|
7
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
8
7
|
* found in the LICENSE file at https://angular.io/license
|
|
9
8
|
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const core_1 = require("@angular-devkit/core");
|
|
11
11
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
12
12
|
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright Google
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
export interface Schema {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The name of the project.
|
|
12
|
+
*/
|
|
13
|
+
project: string;
|
|
14
|
+
/**
|
|
15
|
+
* The target to apply service worker to.
|
|
16
|
+
*/
|
|
17
|
+
target: string;
|
|
18
|
+
/**
|
|
19
|
+
* The configuration to apply service worker to.
|
|
20
|
+
*/
|
|
21
|
+
configuration: string;
|
|
22
22
|
}
|
package/universal/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
1
8
|
import { Rule } from '@angular-devkit/schematics';
|
|
2
9
|
import { Schema as UniversalOptions } from './schema';
|
|
3
10
|
export default function (options: UniversalOptions): Rule;
|
package/universal/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
/**
|
|
4
3
|
* @license
|
|
5
|
-
* Copyright Google
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
6
5
|
*
|
|
7
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
8
7
|
* found in the LICENSE file at https://angular.io/license
|
|
9
8
|
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const core_1 = require("@angular-devkit/core");
|
|
11
11
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
12
12
|
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
@@ -20,8 +20,8 @@ const project_targets_1 = require("../utility/project-targets");
|
|
|
20
20
|
const workspace_1 = require("../utility/workspace");
|
|
21
21
|
const workspace_models_1 = require("../utility/workspace-models");
|
|
22
22
|
function updateConfigFile(options, tsConfigDirectory) {
|
|
23
|
-
return workspace_1.updateWorkspace(workspace => {
|
|
24
|
-
const clientProject = workspace.projects.get(options.
|
|
23
|
+
return workspace_1.updateWorkspace((workspace) => {
|
|
24
|
+
const clientProject = workspace.projects.get(options.project);
|
|
25
25
|
if (clientProject) {
|
|
26
26
|
// In case the browser builder hashes the assets
|
|
27
27
|
// we need to add this setting to the server builder
|
|
@@ -45,7 +45,7 @@ function updateConfigFile(options, tsConfigDirectory) {
|
|
|
45
45
|
};
|
|
46
46
|
const buildTarget = clientProject.targets.get('build');
|
|
47
47
|
if (buildTarget === null || buildTarget === void 0 ? void 0 : buildTarget.options) {
|
|
48
|
-
buildTarget.options.outputPath = `dist/${options.
|
|
48
|
+
buildTarget.options.outputPath = `dist/${options.project}/browser`;
|
|
49
49
|
}
|
|
50
50
|
const buildConfigurations = buildTarget === null || buildTarget === void 0 ? void 0 : buildTarget.configurations;
|
|
51
51
|
const configurations = {};
|
|
@@ -61,7 +61,7 @@ function updateConfigFile(options, tsConfigDirectory) {
|
|
|
61
61
|
builder: workspace_models_1.Builders.Server,
|
|
62
62
|
defaultConfiguration: 'production',
|
|
63
63
|
options: {
|
|
64
|
-
outputPath: `dist/${options.
|
|
64
|
+
outputPath: `dist/${options.project}/server`,
|
|
65
65
|
main: core_1.join(core_1.normalize(clientProject.root), 'src', mainPath.endsWith('.ts') ? mainPath : mainPath + '.ts'),
|
|
66
66
|
tsConfig: serverTsConfig,
|
|
67
67
|
...((buildTarget === null || buildTarget === void 0 ? void 0 : buildTarget.options) ? getServerOptions(buildTarget === null || buildTarget === void 0 ? void 0 : buildTarget.options) : {}),
|
|
@@ -111,8 +111,8 @@ function wrapBootstrapCall(mainFile) {
|
|
|
111
111
|
}
|
|
112
112
|
// indent contents
|
|
113
113
|
const triviaWidth = bootstrapCall.getLeadingTriviaWidth();
|
|
114
|
-
const beforeText = `document.addEventListener('DOMContentLoaded', () => {\n`
|
|
115
|
-
|
|
114
|
+
const beforeText = `document.addEventListener('DOMContentLoaded', () => {\n` +
|
|
115
|
+
' '.repeat(triviaWidth > 2 ? triviaWidth + 1 : triviaWidth);
|
|
116
116
|
const afterText = `\n${triviaWidth > 2 ? ' '.repeat(triviaWidth - 1) : ''}});`;
|
|
117
117
|
// in some cases we need to cater for a trailing semicolon such as;
|
|
118
118
|
// bootstrap().catch(err => console.log(err));
|
|
@@ -128,13 +128,13 @@ function wrapBootstrapCall(mainFile) {
|
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
function findCallExpressionNode(node, text) {
|
|
131
|
-
if (ts.isCallExpression(node)
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
if (ts.isCallExpression(node) &&
|
|
132
|
+
ts.isIdentifier(node.expression) &&
|
|
133
|
+
node.expression.text === text) {
|
|
134
134
|
return node;
|
|
135
135
|
}
|
|
136
136
|
let foundNode = null;
|
|
137
|
-
ts.forEachChild(node, childNode => {
|
|
137
|
+
ts.forEachChild(node, (childNode) => {
|
|
138
138
|
foundNode = findCallExpressionNode(childNode, text);
|
|
139
139
|
if (foundNode) {
|
|
140
140
|
return true;
|
|
@@ -174,7 +174,7 @@ function addDependencies() {
|
|
|
174
174
|
function default_1(options) {
|
|
175
175
|
return async (host, context) => {
|
|
176
176
|
const workspace = await workspace_1.getWorkspace(host);
|
|
177
|
-
const clientProject = workspace.projects.get(options.
|
|
177
|
+
const clientProject = workspace.projects.get(options.project);
|
|
178
178
|
if (!clientProject || clientProject.extensions.projectType !== 'application') {
|
|
179
179
|
throw new schematics_1.SchematicsException(`Universal requires a project type of "application".`);
|
|
180
180
|
}
|
|
@@ -182,7 +182,8 @@ function default_1(options) {
|
|
|
182
182
|
if (!clientBuildTarget) {
|
|
183
183
|
throw project_targets_1.targetBuildNotFoundError();
|
|
184
184
|
}
|
|
185
|
-
const clientBuildOptions = (clientBuildTarget.options ||
|
|
185
|
+
const clientBuildOptions = (clientBuildTarget.options ||
|
|
186
|
+
{});
|
|
186
187
|
const clientTsConfig = core_1.normalize(clientBuildOptions.tsConfig);
|
|
187
188
|
const tsConfigExtends = core_1.basename(clientTsConfig);
|
|
188
189
|
// this is needed because prior to version 8, tsconfig might have been in 'src'
|
package/universal/schema.d.ts
CHANGED
|
@@ -10,14 +10,14 @@ export interface Schema {
|
|
|
10
10
|
* The app identifier to use for transition.
|
|
11
11
|
*/
|
|
12
12
|
appId?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The name of the related client app. Required in place of "project".
|
|
15
|
-
*/
|
|
16
|
-
clientProject: string;
|
|
17
13
|
/**
|
|
18
14
|
* The name of the main entry-point file.
|
|
19
15
|
*/
|
|
20
16
|
main?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The name of the project.
|
|
19
|
+
*/
|
|
20
|
+
project: string;
|
|
21
21
|
/**
|
|
22
22
|
* The name of the root NgModule class.
|
|
23
23
|
*/
|
package/universal/schema.json
CHANGED
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
"additionalProperties": false,
|
|
7
7
|
"description": "Pass this schematic to the \"run\" command to set up server-side rendering for an app.",
|
|
8
8
|
"properties": {
|
|
9
|
-
"
|
|
9
|
+
"project": {
|
|
10
10
|
"type": "string",
|
|
11
|
-
"description": "The name of the
|
|
11
|
+
"description": "The name of the project.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "projectName"
|
|
14
|
+
}
|
|
12
15
|
},
|
|
13
16
|
"appId": {
|
|
14
17
|
"type": "string",
|
|
@@ -45,7 +48,5 @@
|
|
|
45
48
|
"default": false
|
|
46
49
|
}
|
|
47
50
|
},
|
|
48
|
-
"required": [
|
|
49
|
-
"clientProject"
|
|
50
|
-
]
|
|
51
|
+
"required": ["project"]
|
|
51
52
|
}
|
package/utility/ast-utils.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
1
8
|
import * as ts from '../third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
2
9
|
import { Change } from './change';
|
|
3
10
|
/**
|
package/utility/ast-utils.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addRouteDeclarationToModule = exports.getRouterModuleDeclaration = exports.getEnvironmentExportName = exports.isImported = exports.addBootstrapToModule = exports.addExportToModule = exports.addProviderToModule = exports.addImportToModule = exports.addDeclarationToModule = exports.addSymbolToNgModuleMetadata = exports.getMetadataField = exports.getDecoratorMetadata = exports.insertAfterLastOccurrence = exports.findNode = exports.getSourceNodes = exports.findNodes = exports.insertImport = void 0;
|
|
4
2
|
/**
|
|
5
3
|
* @license
|
|
6
|
-
* Copyright Google
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
7
5
|
*
|
|
8
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
9
7
|
* found in the LICENSE file at https://angular.io/license
|
|
10
8
|
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.addRouteDeclarationToModule = exports.getRouterModuleDeclaration = exports.getEnvironmentExportName = exports.isImported = exports.addBootstrapToModule = exports.addExportToModule = exports.addProviderToModule = exports.addImportToModule = exports.addDeclarationToModule = exports.addSymbolToNgModuleMetadata = exports.getMetadataField = exports.getDecoratorMetadata = exports.insertAfterLastOccurrence = exports.findNode = exports.getSourceNodes = exports.findNodes = exports.insertImport = void 0;
|
|
11
11
|
const core_1 = require("@angular-devkit/core");
|
|
12
12
|
const ts = require("../third_party/github.com/Microsoft/TypeScript/lib/typescript");
|
|
13
13
|
const change_1 = require("./change");
|
|
@@ -24,18 +24,19 @@ function insertImport(source, fileToEdit, symbolName, fileName, isDefault = fals
|
|
|
24
24
|
const rootNode = source;
|
|
25
25
|
const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
26
26
|
// get nodes that map to import statements from the file fileName
|
|
27
|
-
const relevantImports = allImports.filter(node => {
|
|
27
|
+
const relevantImports = allImports.filter((node) => {
|
|
28
28
|
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
29
|
-
const importFiles = node
|
|
29
|
+
const importFiles = node
|
|
30
|
+
.getChildren()
|
|
30
31
|
.filter(ts.isStringLiteral)
|
|
31
|
-
.map(n => n.text);
|
|
32
|
-
return importFiles.filter(file => file === fileName).length === 1;
|
|
32
|
+
.map((n) => n.text);
|
|
33
|
+
return importFiles.filter((file) => file === fileName).length === 1;
|
|
33
34
|
});
|
|
34
35
|
if (relevantImports.length > 0) {
|
|
35
36
|
let importsAsterisk = false;
|
|
36
37
|
// imports from import file
|
|
37
38
|
const imports = [];
|
|
38
|
-
relevantImports.forEach(n => {
|
|
39
|
+
relevantImports.forEach((n) => {
|
|
39
40
|
Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
|
|
40
41
|
if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
41
42
|
importsAsterisk = true;
|
|
@@ -45,7 +46,7 @@ function insertImport(source, fileToEdit, symbolName, fileName, isDefault = fals
|
|
|
45
46
|
if (importsAsterisk) {
|
|
46
47
|
return new change_1.NoopChange();
|
|
47
48
|
}
|
|
48
|
-
const importTextNodes = imports.filter(n => n.text === symbolName);
|
|
49
|
+
const importTextNodes = imports.filter((n) => n.text === symbolName);
|
|
49
50
|
// insert import if it's not there
|
|
50
51
|
if (importTextNodes.length === 0) {
|
|
51
52
|
const fallbackPos = findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
@@ -55,8 +56,7 @@ function insertImport(source, fileToEdit, symbolName, fileName, isDefault = fals
|
|
|
55
56
|
return new change_1.NoopChange();
|
|
56
57
|
}
|
|
57
58
|
// no such import declaration exists
|
|
58
|
-
const useStrict = findNodes(rootNode, ts.isStringLiteral)
|
|
59
|
-
.filter((n) => n.text === 'use strict');
|
|
59
|
+
const useStrict = findNodes(rootNode, ts.isStringLiteral).filter((n) => n.text === 'use strict');
|
|
60
60
|
let fallbackPos = 0;
|
|
61
61
|
if (useStrict.length > 0) {
|
|
62
62
|
fallbackPos = useStrict[0].end;
|
|
@@ -125,7 +125,7 @@ function findNode(node, kind, text) {
|
|
|
125
125
|
return node;
|
|
126
126
|
}
|
|
127
127
|
let foundNode = null;
|
|
128
|
-
ts.forEachChild(node, childNode => {
|
|
128
|
+
ts.forEachChild(node, (childNode) => {
|
|
129
129
|
foundNode = foundNode || findNode(childNode, kind, text);
|
|
130
130
|
});
|
|
131
131
|
return foundNode;
|
|
@@ -168,7 +168,7 @@ function insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKin
|
|
|
168
168
|
return new change_1.InsertChange(file, lastItemPosition, toInsert);
|
|
169
169
|
}
|
|
170
170
|
exports.insertAfterLastOccurrence = insertAfterLastOccurrence;
|
|
171
|
-
function _angularImportsFromNode(node
|
|
171
|
+
function _angularImportsFromNode(node) {
|
|
172
172
|
const ms = node.moduleSpecifier;
|
|
173
173
|
let modulePath;
|
|
174
174
|
switch (ms.kind) {
|
|
@@ -198,7 +198,7 @@ function _angularImportsFromNode(node, _sourceFile) {
|
|
|
198
198
|
// This is of the form `import {a,b,c} from 'path'`
|
|
199
199
|
const namedImports = nb;
|
|
200
200
|
return namedImports.elements
|
|
201
|
-
.map((is) => is.propertyName ? is.propertyName.text : is.name.text)
|
|
201
|
+
.map((is) => (is.propertyName ? is.propertyName.text : is.name.text))
|
|
202
202
|
.reduce((acc, curr) => {
|
|
203
203
|
acc[curr] = modulePath;
|
|
204
204
|
return acc;
|
|
@@ -214,7 +214,7 @@ function _angularImportsFromNode(node, _sourceFile) {
|
|
|
214
214
|
}
|
|
215
215
|
function getDecoratorMetadata(source, identifier, module) {
|
|
216
216
|
const angularImports = findNodes(source, ts.isImportDeclaration)
|
|
217
|
-
.map((node) => _angularImportsFromNode(node
|
|
217
|
+
.map((node) => _angularImportsFromNode(node))
|
|
218
218
|
.reduce((acc, current) => {
|
|
219
219
|
for (const key of Object.keys(current)) {
|
|
220
220
|
acc[key] = current[key];
|
|
@@ -222,12 +222,12 @@ function getDecoratorMetadata(source, identifier, module) {
|
|
|
222
222
|
return acc;
|
|
223
223
|
}, {});
|
|
224
224
|
return getSourceNodes(source)
|
|
225
|
-
.filter(node => {
|
|
226
|
-
return node.kind == ts.SyntaxKind.Decorator
|
|
227
|
-
|
|
225
|
+
.filter((node) => {
|
|
226
|
+
return (node.kind == ts.SyntaxKind.Decorator &&
|
|
227
|
+
node.expression.kind == ts.SyntaxKind.CallExpression);
|
|
228
228
|
})
|
|
229
|
-
.map(node => node.expression)
|
|
230
|
-
.filter(expr => {
|
|
229
|
+
.map((node) => node.expression)
|
|
230
|
+
.filter((expr) => {
|
|
231
231
|
if (expr.expression.kind == ts.SyntaxKind.Identifier) {
|
|
232
232
|
const id = expr.expression;
|
|
233
233
|
return id.text == identifier && angularImports[id.text] === module;
|
|
@@ -241,28 +241,27 @@ function getDecoratorMetadata(source, identifier, module) {
|
|
|
241
241
|
}
|
|
242
242
|
const id = paExpr.name.text;
|
|
243
243
|
const moduleId = paExpr.expression.text;
|
|
244
|
-
return id === identifier &&
|
|
244
|
+
return id === identifier && angularImports[moduleId + '.'] === module;
|
|
245
245
|
}
|
|
246
246
|
return false;
|
|
247
247
|
})
|
|
248
|
-
.filter(expr => expr.arguments[0]
|
|
249
|
-
|
|
250
|
-
.map(expr => expr.arguments[0]);
|
|
248
|
+
.filter((expr) => expr.arguments[0] && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)
|
|
249
|
+
.map((expr) => expr.arguments[0]);
|
|
251
250
|
}
|
|
252
251
|
exports.getDecoratorMetadata = getDecoratorMetadata;
|
|
253
252
|
function getMetadataField(node, metadataField) {
|
|
254
|
-
return node.properties
|
|
253
|
+
return (node.properties
|
|
255
254
|
.filter(ts.isPropertyAssignment)
|
|
256
255
|
// Filter out every fields that's not "metadataField". Also handles string literals
|
|
257
256
|
// (but not expressions).
|
|
258
257
|
.filter(({ name }) => {
|
|
259
258
|
return (ts.isIdentifier(name) || ts.isStringLiteral(name)) && name.text === metadataField;
|
|
260
|
-
});
|
|
259
|
+
}));
|
|
261
260
|
}
|
|
262
261
|
exports.getMetadataField = getMetadataField;
|
|
263
262
|
function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath = null) {
|
|
264
263
|
const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
|
|
265
|
-
let node = nodes[0]; //
|
|
264
|
+
let node = nodes[0]; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
266
265
|
// Find the decorator declaration.
|
|
267
266
|
if (!node) {
|
|
268
267
|
return [];
|
|
@@ -285,8 +284,9 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbol
|
|
|
285
284
|
const text = node.getFullText(source);
|
|
286
285
|
const matches = text.match(/^(\r?\n)(\s*)/);
|
|
287
286
|
if (matches) {
|
|
288
|
-
toInsert =
|
|
289
|
-
|
|
287
|
+
toInsert =
|
|
288
|
+
`,${matches[0]}${metadataField}: [${matches[1]}` +
|
|
289
|
+
`${core_1.tags.indentBy(matches[2].length + 2) `${symbolName}`}${matches[0]}]`;
|
|
290
290
|
}
|
|
291
291
|
else {
|
|
292
292
|
toInsert = `, ${metadataField}: [${symbolName}]`;
|
|
@@ -317,7 +317,7 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbol
|
|
|
317
317
|
}
|
|
318
318
|
if (Array.isArray(node)) {
|
|
319
319
|
const nodeArray = node;
|
|
320
|
-
const symbolsArray = nodeArray.map(node => core_1.tags.oneLine `${node.getText()}`);
|
|
320
|
+
const symbolsArray = nodeArray.map((node) => core_1.tags.oneLine `${node.getText()}`);
|
|
321
321
|
if (symbolsArray.includes(core_1.tags.oneLine `${symbolName}`)) {
|
|
322
322
|
return [];
|
|
323
323
|
}
|
|
@@ -457,8 +457,8 @@ function getRouterModuleDeclaration(source) {
|
|
|
457
457
|
}
|
|
458
458
|
const arrLiteral = assignment.initializer;
|
|
459
459
|
return arrLiteral.elements
|
|
460
|
-
.filter(el => el.kind === ts.SyntaxKind.CallExpression)
|
|
461
|
-
.find(el => el.getText().startsWith('RouterModule'));
|
|
460
|
+
.filter((el) => el.kind === ts.SyntaxKind.CallExpression)
|
|
461
|
+
.find((el) => el.getText().startsWith('RouterModule'));
|
|
462
462
|
}
|
|
463
463
|
exports.getRouterModuleDeclaration = getRouterModuleDeclaration;
|
|
464
464
|
/**
|
|
@@ -472,8 +472,7 @@ function addRouteDeclarationToModule(source, fileToAdd, routeLiteral) {
|
|
|
472
472
|
const scopeConfigMethodArgs = routerModuleExpr.arguments;
|
|
473
473
|
if (!scopeConfigMethodArgs.length) {
|
|
474
474
|
const { line } = source.getLineAndCharacterOfPosition(routerModuleExpr.getStart());
|
|
475
|
-
throw new Error(`The router module method doesn't have arguments ` +
|
|
476
|
-
`at line ${line} in ${fileToAdd}`);
|
|
475
|
+
throw new Error(`The router module method doesn't have arguments ` + `at line ${line} in ${fileToAdd}`);
|
|
477
476
|
}
|
|
478
477
|
let routesArr;
|
|
479
478
|
const routesArg = scopeConfigMethodArgs[0];
|
|
@@ -486,9 +485,7 @@ function addRouteDeclarationToModule(source, fileToAdd, routeLiteral) {
|
|
|
486
485
|
const routesVarName = routesArg.getText();
|
|
487
486
|
let routesVar;
|
|
488
487
|
if (routesArg.kind === ts.SyntaxKind.Identifier) {
|
|
489
|
-
routesVar = source.statements
|
|
490
|
-
.filter(ts.isVariableStatement)
|
|
491
|
-
.find((v) => {
|
|
488
|
+
routesVar = source.statements.filter(ts.isVariableStatement).find((v) => {
|
|
492
489
|
return v.declarationList.declarations[0].name.getText() === routesVarName;
|
|
493
490
|
});
|
|
494
491
|
}
|
|
@@ -505,14 +502,12 @@ function addRouteDeclarationToModule(source, fileToAdd, routeLiteral) {
|
|
|
505
502
|
let insertPos = routesArr.elements.pos;
|
|
506
503
|
if (occurrencesCount > 0) {
|
|
507
504
|
const lastRouteLiteral = [...routesArr.elements].pop();
|
|
508
|
-
const lastRouteIsWildcard = ts.isObjectLiteralExpression(lastRouteLiteral)
|
|
509
|
-
&&
|
|
510
|
-
.
|
|
511
|
-
.
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
&& ts.isStringLiteral(n.initializer)
|
|
515
|
-
&& n.initializer.text === '**'));
|
|
505
|
+
const lastRouteIsWildcard = ts.isObjectLiteralExpression(lastRouteLiteral) &&
|
|
506
|
+
lastRouteLiteral.properties.some((n) => ts.isPropertyAssignment(n) &&
|
|
507
|
+
ts.isIdentifier(n.name) &&
|
|
508
|
+
n.name.text === 'path' &&
|
|
509
|
+
ts.isStringLiteral(n.initializer) &&
|
|
510
|
+
n.initializer.text === '**');
|
|
516
511
|
const indentation = text.match(/\r?\n(\r?)\s*/) || [];
|
|
517
512
|
const routeText = `${indentation[0] || ' '}${routeLiteral}`;
|
|
518
513
|
// Add the new route before the wildcard route
|
package/utility/change.d.ts
CHANGED
package/utility/change.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
10
|
exports.applyToUpdateRecorder = exports.ReplaceChange = exports.RemoveChange = exports.InsertChange = exports.NoopChange = void 0;
|
|
4
11
|
/**
|
|
@@ -10,7 +17,9 @@ class NoopChange {
|
|
|
10
17
|
this.order = Infinity;
|
|
11
18
|
this.path = null;
|
|
12
19
|
}
|
|
13
|
-
apply() {
|
|
20
|
+
apply() {
|
|
21
|
+
return Promise.resolve();
|
|
22
|
+
}
|
|
14
23
|
}
|
|
15
24
|
exports.NoopChange = NoopChange;
|
|
16
25
|
/**
|
|
@@ -31,7 +40,7 @@ class InsertChange {
|
|
|
31
40
|
* This method does not insert spaces if there is none in the original string.
|
|
32
41
|
*/
|
|
33
42
|
apply(host) {
|
|
34
|
-
return host.read(this.path).then(content => {
|
|
43
|
+
return host.read(this.path).then((content) => {
|
|
35
44
|
const prefix = content.substring(0, this.pos);
|
|
36
45
|
const suffix = content.substring(this.pos);
|
|
37
46
|
return host.write(this.path, `${prefix}${this.toAdd}${suffix}`);
|
|
@@ -54,7 +63,7 @@ class RemoveChange {
|
|
|
54
63
|
this.order = pos;
|
|
55
64
|
}
|
|
56
65
|
apply(host) {
|
|
57
|
-
return host.read(this.path).then(content => {
|
|
66
|
+
return host.read(this.path).then((content) => {
|
|
58
67
|
const prefix = content.substring(0, this.pos);
|
|
59
68
|
const suffix = content.substring(this.pos + this.toRemove.length);
|
|
60
69
|
// TODO: throw error if toRemove doesn't match removed string.
|
|
@@ -79,7 +88,7 @@ class ReplaceChange {
|
|
|
79
88
|
this.order = pos;
|
|
80
89
|
}
|
|
81
90
|
apply(host) {
|
|
82
|
-
return host.read(this.path).then(content => {
|
|
91
|
+
return host.read(this.path).then((content) => {
|
|
83
92
|
const prefix = content.substring(0, this.pos);
|
|
84
93
|
const suffix = content.substring(this.pos + this.oldText.length);
|
|
85
94
|
const text = content.substring(this.pos, this.pos + this.oldText.length);
|
package/utility/dependencies.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
10
|
exports.getPackageJsonDependency = exports.removePackageJsonDependency = exports.addPackageJsonDependency = exports.NodeDependencyType = void 0;
|
|
4
11
|
const json_file_1 = require("./json-file");
|
package/utility/find-module.d.ts
CHANGED
package/utility/find-module.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildRelativePath = exports.findModule = exports.findModuleFromOptions = exports.ROUTING_MODULE_EXT = exports.MODULE_EXT = void 0;
|
|
4
2
|
/**
|
|
5
3
|
* @license
|
|
6
|
-
* Copyright Google
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
7
5
|
*
|
|
8
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
9
7
|
* found in the LICENSE file at https://angular.io/license
|
|
10
8
|
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.buildRelativePath = exports.findModule = exports.findModuleFromOptions = exports.ROUTING_MODULE_EXT = exports.MODULE_EXT = void 0;
|
|
11
11
|
const core_1 = require("@angular-devkit/core");
|
|
12
12
|
exports.MODULE_EXT = '.module.ts';
|
|
13
13
|
exports.ROUTING_MODULE_EXT = '-routing.module.ts';
|
|
@@ -15,6 +15,7 @@ exports.ROUTING_MODULE_EXT = '-routing.module.ts';
|
|
|
15
15
|
* Find the module referred by a set of options passed to the schematics.
|
|
16
16
|
*/
|
|
17
17
|
function findModuleFromOptions(host, options) {
|
|
18
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
18
19
|
if (options.hasOwnProperty('skipImport') && options.skipImport) {
|
|
19
20
|
return undefined;
|
|
20
21
|
}
|
|
@@ -28,9 +29,7 @@ function findModuleFromOptions(host, options) {
|
|
|
28
29
|
const modulePath = core_1.normalize(`/${options.path}/${options.module}`);
|
|
29
30
|
const componentPath = core_1.normalize(`/${options.path}/${options.name}`);
|
|
30
31
|
const moduleBaseName = core_1.normalize(modulePath).split('/').pop();
|
|
31
|
-
const candidateSet = new Set([
|
|
32
|
-
core_1.normalize(options.path || '/'),
|
|
33
|
-
]);
|
|
32
|
+
const candidateSet = new Set([core_1.normalize(options.path || '/')]);
|
|
34
33
|
for (let dir = modulePath; dir != core_1.NormalizedRoot; dir = core_1.dirname(dir)) {
|
|
35
34
|
candidateSet.add(dir);
|
|
36
35
|
}
|
|
@@ -43,15 +42,15 @@ function findModuleFromOptions(host, options) {
|
|
|
43
42
|
'',
|
|
44
43
|
`${moduleBaseName}.ts`,
|
|
45
44
|
`${moduleBaseName}${moduleExt}`,
|
|
46
|
-
].map(x => core_1.join(c, x));
|
|
45
|
+
].map((x) => core_1.join(c, x));
|
|
47
46
|
for (const sc of candidateFiles) {
|
|
48
47
|
if (host.exists(sc)) {
|
|
49
48
|
return core_1.normalize(sc);
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
throw new Error(`Specified module '${options.module}' does not exist.\n`
|
|
54
|
-
|
|
52
|
+
throw new Error(`Specified module '${options.module}' does not exist.\n` +
|
|
53
|
+
`Looked in the following directories:\n ${candidatesDirs.join('\n ')}`);
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
exports.findModuleFromOptions = findModuleFromOptions;
|
|
@@ -62,8 +61,8 @@ function findModule(host, generateDir, moduleExt = exports.MODULE_EXT, routingMo
|
|
|
62
61
|
let dir = host.getDir('/' + generateDir);
|
|
63
62
|
let foundRoutingModule = false;
|
|
64
63
|
while (dir) {
|
|
65
|
-
const allMatches = dir.subfiles.filter(p => p.endsWith(moduleExt));
|
|
66
|
-
const filteredMatches = allMatches.filter(p => !p.endsWith(routingModuleExt));
|
|
64
|
+
const allMatches = dir.subfiles.filter((p) => p.endsWith(moduleExt));
|
|
65
|
+
const filteredMatches = allMatches.filter((p) => !p.endsWith(routingModuleExt));
|
|
67
66
|
foundRoutingModule = foundRoutingModule || allMatches.length !== filteredMatches.length;
|
|
68
67
|
if (filteredMatches.length == 1) {
|
|
69
68
|
return core_1.join(dir.path, filteredMatches[0]);
|
|
@@ -74,9 +73,10 @@ function findModule(host, generateDir, moduleExt = exports.MODULE_EXT, routingMo
|
|
|
74
73
|
}
|
|
75
74
|
dir = dir.parent;
|
|
76
75
|
}
|
|
77
|
-
const errorMsg = foundRoutingModule
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
const errorMsg = foundRoutingModule
|
|
77
|
+
? 'Could not find a non Routing NgModule.' +
|
|
78
|
+
`\nModules with suffix '${routingModuleExt}' are strictly reserved for routing.` +
|
|
79
|
+
'\nUse the skip-import option to skip importing in NgModule.'
|
|
80
80
|
: 'Could not find an NgModule. Use the skip-import option to skip importing in NgModule.';
|
|
81
81
|
throw new Error(errorMsg);
|
|
82
82
|
}
|