@ui5/webcomponents-ngx 0.1.1-rc.1 → 0.1.1-rc.2

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.
Files changed (28) hide show
  1. package/package.json +1 -1
  2. package/schematics/add-dependencies/index.js +2 -0
  3. package/schematics/add-theming/add-theming-module.d.ts +8 -0
  4. package/schematics/add-theming/add-theming-module.js +95 -0
  5. package/schematics/add-theming/index.d.ts +1 -3
  6. package/schematics/add-theming/index.js +5 -80
  7. package/schematics/utils/find-import-local-name.d.ts +8 -0
  8. package/schematics/utils/find-import-local-name.js +58 -0
  9. package/schematics/utils/find-import-providers-from-call.d.ts +3 -0
  10. package/schematics/utils/find-import-providers-from-call.js +46 -0
  11. package/schematics/utils/find-ng-module-metadata.d.ts +7 -0
  12. package/schematics/utils/find-ng-module-metadata.js +30 -0
  13. package/schematics/utils/find-providers-literal.d.ts +3 -0
  14. package/schematics/utils/find-providers-literal.js +45 -0
  15. package/schematics/utils/getModuleDeclaration.d.ts +5 -0
  16. package/schematics/utils/getModuleDeclaration.js +51 -0
  17. package/schematics/utils/getSourceFile.d.ts +3 -0
  18. package/schematics/utils/getSourceFile.js +38 -0
  19. package/schematics/utils/has-module-import.d.ts +2 -0
  20. package/schematics/utils/has-module-import.js +52 -0
  21. package/schematics/utils/is-ng-module-expression.d.ts +3 -0
  22. package/schematics/utils/is-ng-module-expression.js +39 -0
  23. package/schematics/utils/project-main-file.d.ts +13 -0
  24. package/schematics/utils/project-main-file.js +31 -0
  25. package/schematics/utils/resolve-identifier-of-expression.d.ts +6 -0
  26. package/schematics/utils/resolve-identifier-of-expression.js +41 -0
  27. package/ui5-webcomponents-ngx-v0.1.1-rc.2.tgz +0 -0
  28. package/ui5-webcomponents-ngx-v0.1.1-rc.1.tgz +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-ngx",
3
- "version": "0.1.1-rc.1",
3
+ "version": "0.1.1-rc.2",
4
4
  "license": "Apache-2.0",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "keywords": [
@@ -16,6 +16,8 @@ exports.addDependencies = void 0;
16
16
  const workspace_1 = require("@schematics/angular/utility/workspace");
17
17
  const tasks_1 = require("@angular-devkit/schematics/tasks");
18
18
  const package_config_1 = require("../utils/package-config");
19
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
20
+ // @ts-ignore is needed because the package.json is not available at build time
19
21
  const package_json_1 = __importDefault(require("../../package.json"));
20
22
  const commonCssPackageName = '@fundamental-styles/common-css';
21
23
  const themingNgxPackageName = '@ui5/theming-ngx';
@@ -0,0 +1,8 @@
1
+ import { SchematicContext, Tree } from "@angular-devkit/schematics";
2
+ import { ProjectDefinition } from "@schematics/angular/utility";
3
+ import { Schema } from '../schema';
4
+ import { Change } from "@schematics/angular/utility/change";
5
+ export declare function addThemingModule(host: Tree, project: ProjectDefinition, context: SchematicContext, options: Schema): {
6
+ changes: Change[];
7
+ file: string;
8
+ };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.addThemingModule = void 0;
27
+ const schematics_1 = require("@angular-devkit/schematics");
28
+ const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
29
+ const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
30
+ const getModuleDeclaration_1 = require("../utils/getModuleDeclaration");
31
+ const project_main_file_1 = require("../utils/project-main-file");
32
+ const standalone_1 = require("@schematics/angular/private/standalone");
33
+ const ts = __importStar(require("typescript"));
34
+ const find_import_providers_from_call_1 = require("../utils/find-import-providers-from-call");
35
+ const getSourceFile_1 = require("../utils/getSourceFile");
36
+ function addThemingModule(host, project, context, options) {
37
+ var _a;
38
+ try {
39
+ return addModuleToNonStandaloneApp(host, project, context, options);
40
+ }
41
+ catch (e) {
42
+ if ((_a = e.message) === null || _a === void 0 ? void 0 : _a.includes('Bootstrap call not found')) {
43
+ return addModuleToStandaloneApp(host, project, context, options);
44
+ }
45
+ else {
46
+ throw e;
47
+ }
48
+ }
49
+ }
50
+ exports.addThemingModule = addThemingModule;
51
+ function addModuleToNonStandaloneApp(host, project, context, options) {
52
+ const appModulePath = (0, ng_ast_utils_1.getAppModulePath)(host, (0, project_main_file_1.getProjectMainFile)(project));
53
+ if (!appModulePath) {
54
+ throw new schematics_1.SchematicsException('Could not find root module for defined project.');
55
+ }
56
+ const appModuleSource = (0, getSourceFile_1.getSourceFile)(host, appModulePath);
57
+ const themingModule = (0, getModuleDeclaration_1.getModuleDeclaration)(appModuleSource, 'Ui5ThemingModule');
58
+ if (themingModule) {
59
+ themingModule.getChildren(appModuleSource);
60
+ const themingModuleDecl = themingModule.getFullText();
61
+ const appModuleContent = host.readText(appModulePath).split(themingModuleDecl).join(`\nUi5ThemingModule.forRoot({defaultTheme: '${options.defaultTheme}'})`);
62
+ host.overwrite(appModulePath, appModuleContent);
63
+ context.logger.info('Found previous Ui5ThemingModule. Replaced with new one.');
64
+ return { changes: [], file: appModulePath };
65
+ }
66
+ const changes = [
67
+ ...(0, ast_utils_1.addImportToModule)(appModuleSource, appModulePath, `Ui5ThemingModule.forRoot({defaultTheme: '${options.defaultTheme}'})`, '@ui5/theming-ngx')
68
+ ];
69
+ return { changes, file: appModulePath };
70
+ }
71
+ function addModuleToStandaloneApp(host, project, context, options) {
72
+ const mainFile = (0, project_main_file_1.getProjectMainFile)(project);
73
+ const mainFileSource = (0, getSourceFile_1.getSourceFile)(host, mainFile);
74
+ const bootstrapCall = (0, standalone_1.findBootstrapApplicationCall)(mainFileSource);
75
+ if (!bootstrapCall) {
76
+ throw new schematics_1.SchematicsException('Could not find bootstrap call in main.ts');
77
+ }
78
+ const themingModuleWithDefaultTheme = `Ui5ThemingModule.forRoot({ defaultTheme: '${options.defaultTheme}' })`;
79
+ const imports = (0, find_import_providers_from_call_1.findImportProvidersFromCall)(bootstrapCall);
80
+ if (imports) {
81
+ const themingModuleImport = imports.arguments.find(arg => ts.isCallExpression(arg) && ts.isPropertyAccessExpression(arg.expression) && ts.isIdentifier(arg.expression.expression) && arg.expression.expression.text === 'Ui5ThemingModule');
82
+ if (themingModuleImport) {
83
+ const oldContent = host.readText(mainFile);
84
+ const newContent = oldContent.split(themingModuleImport.getFullText()).join(themingModuleWithDefaultTheme);
85
+ host.overwrite(mainFile, newContent);
86
+ context.logger.info('Found previous Ui5ThemingModule. Replaced with new one.');
87
+ return { changes: [], file: mainFile };
88
+ }
89
+ }
90
+ (0, standalone_1.addModuleImportToStandaloneBootstrap)(host, mainFile, themingModuleWithDefaultTheme, '@ui5/theming-ngx');
91
+ const oldContent = host.readText(mainFile);
92
+ const newContent = oldContent.replace(themingModuleWithDefaultTheme, 'Ui5ThemingModule'); // This is fixing the incorrect import
93
+ host.overwrite(mainFile, newContent);
94
+ return { changes: [], file: mainFile };
95
+ }
@@ -1,5 +1,3 @@
1
- import { Rule, Tree } from '@angular-devkit/schematics';
2
- import * as ts from 'typescript';
1
+ import { Rule } from '@angular-devkit/schematics';
3
2
  import { Schema } from '../schema';
4
3
  export declare function addTheming(options: Schema): Rule;
5
- export declare function getSourceFile(host: Tree, path: string): ts.SourceFile;
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -32,13 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
9
  });
33
10
  };
34
11
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.getSourceFile = exports.addTheming = void 0;
12
+ exports.addTheming = void 0;
36
13
  const workspace_1 = require("@schematics/angular/utility/workspace");
37
- const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
38
- const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
39
14
  const change_1 = require("@schematics/angular/utility/change");
40
15
  const schematics_1 = require("@angular-devkit/schematics");
41
- const ts = __importStar(require("typescript"));
16
+ const add_theming_module_1 = require("./add-theming-module");
42
17
  function addTheming(options) {
43
18
  return (tree, context) => (0, workspace_1.updateWorkspace)((workspace) => __awaiter(this, void 0, void 0, function* () {
44
19
  var _a;
@@ -53,27 +28,9 @@ function addTheming(options) {
53
28
  if (!buildTargetOptions) {
54
29
  throw new schematics_1.SchematicsException('Could not find build target options for defined project.');
55
30
  }
56
- if (!buildTargetOptions['main']) {
57
- throw new schematics_1.SchematicsException('Could not find main entry file for defined project.');
58
- }
59
- const rootModule = (0, ng_ast_utils_1.getAppModulePath)(tree, buildTargetOptions['main']);
60
- if (!rootModule) {
61
- throw new schematics_1.SchematicsException('Could not find root module for defined project.');
62
- }
63
- const appModuleSource = getSourceFile(tree, rootModule);
64
- const themingModule = getModuleDeclaration(appModuleSource, 'Ui5ThemingModule');
65
- if (themingModule) {
66
- themingModule.getChildren(appModuleSource);
67
- const themingModuleDecl = themingModule.getFullText();
68
- const appModuleContent = tree.readText(rootModule).split(themingModuleDecl).join(`\nUi5ThemingModule.forRoot({defaultTheme: '${options.defaultTheme}'})`);
69
- tree.overwrite(rootModule, appModuleContent);
70
- context.logger.info('Found previous Ui5ThemingModule. Replaced with new one.');
71
- return;
72
- }
73
- const changes = [];
74
- changes.push(...(0, ast_utils_1.addImportToModule)(appModuleSource, rootModule, `Ui5ThemingModule.forRoot({defaultTheme: '${options.defaultTheme}'})`, '@ui5/theming-ngx'));
75
- const exportRecorder = tree.beginUpdate(rootModule);
76
- for (const change of changes) {
31
+ const update = (0, add_theming_module_1.addThemingModule)(tree, currentWorkspace, context, options);
32
+ const exportRecorder = tree.beginUpdate(update.file);
33
+ for (const change of update.changes) {
77
34
  if (change instanceof change_1.InsertChange) {
78
35
  exportRecorder.insertLeft(change.pos, change.toAdd);
79
36
  }
@@ -82,35 +39,3 @@ function addTheming(options) {
82
39
  }));
83
40
  }
84
41
  exports.addTheming = addTheming;
85
- // Gets the ts source file from a path
86
- function getSourceFile(host, path) {
87
- const buffer = host.read(path);
88
- if (!buffer) {
89
- throw new schematics_1.SchematicsException(`Could not find file for path: ${path}`);
90
- }
91
- const text = buffer.toString('utf-8');
92
- return ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true);
93
- }
94
- exports.getSourceFile = getSourceFile;
95
- /**
96
- * Returns the RouterModule declaration from NgModule metadata, if any.
97
- */
98
- function getModuleDeclaration(source, module) {
99
- const result = (0, ast_utils_1.getDecoratorMetadata)(source, 'NgModule', '@angular/core');
100
- const node = result[0];
101
- if (!node || !ts.isObjectLiteralExpression(node)) {
102
- return undefined;
103
- }
104
- const matchingProperties = (0, ast_utils_1.getMetadataField)(node, 'imports');
105
- if (!matchingProperties) {
106
- return;
107
- }
108
- const assignment = matchingProperties[0];
109
- if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
110
- return;
111
- }
112
- const arrLiteral = assignment.initializer;
113
- return arrLiteral.elements
114
- .filter((el) => el.kind === ts.SyntaxKind.CallExpression)
115
- .find((el) => el.getText().startsWith(module));
116
- }
@@ -0,0 +1,8 @@
1
+ import * as ts from "typescript";
2
+ /**
3
+ * Finds the local name of an imported symbol. Could be the symbol name itself or its alias.
4
+ * @param sourceFile File within which to search for the import.
5
+ * @param name Actual name of the import, not its local alias.
6
+ * @param moduleName Name of the module from which the symbol is imported.
7
+ */
8
+ export declare function findImportLocalName(sourceFile: ts.SourceFile, name: string, moduleName: string): string | null;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.findImportLocalName = void 0;
27
+ const ts = __importStar(require("typescript"));
28
+ /**
29
+ * Finds the local name of an imported symbol. Could be the symbol name itself or its alias.
30
+ * @param sourceFile File within which to search for the import.
31
+ * @param name Actual name of the import, not its local alias.
32
+ * @param moduleName Name of the module from which the symbol is imported.
33
+ */
34
+ function findImportLocalName(sourceFile, name, moduleName) {
35
+ for (const node of sourceFile.statements) {
36
+ // Only look for top-level imports.
37
+ if (!ts.isImportDeclaration(node) ||
38
+ !ts.isStringLiteral(node.moduleSpecifier) ||
39
+ node.moduleSpecifier.text !== moduleName) {
40
+ continue;
41
+ }
42
+ // Filter out imports that don't have the right shape.
43
+ if (!node.importClause ||
44
+ !node.importClause.namedBindings ||
45
+ !ts.isNamedImports(node.importClause.namedBindings)) {
46
+ continue;
47
+ }
48
+ // Look through the elements of the declaration for the specific import.
49
+ for (const element of node.importClause.namedBindings.elements) {
50
+ if ((element.propertyName || element.name).text === name) {
51
+ // The local name is always in `name`.
52
+ return element.name.text;
53
+ }
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+ exports.findImportLocalName = findImportLocalName;
@@ -0,0 +1,3 @@
1
+ import * as ts from "typescript";
2
+ /** Find a call to `importProvidersFrom` within a `bootstrapApplication` call. */
3
+ export declare function findImportProvidersFromCall(bootstrapCall: ts.CallExpression): ts.CallExpression | null;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.findImportProvidersFromCall = void 0;
27
+ const ts = __importStar(require("typescript"));
28
+ const find_providers_literal_1 = require("./find-providers-literal");
29
+ const find_import_local_name_1 = require("./find-import-local-name");
30
+ /** Find a call to `importProvidersFrom` within a `bootstrapApplication` call. */
31
+ function findImportProvidersFromCall(bootstrapCall) {
32
+ const providersLiteral = (0, find_providers_literal_1.findProvidersLiteral)(bootstrapCall);
33
+ const importProvidersName = (0, find_import_local_name_1.findImportLocalName)(bootstrapCall.getSourceFile(), 'importProvidersFrom', '@angular/core');
34
+ if (providersLiteral && importProvidersName) {
35
+ for (const element of providersLiteral.elements) {
36
+ // Look for an array element that calls the `importProvidersFrom` function.
37
+ if (ts.isCallExpression(element) &&
38
+ ts.isIdentifier(element.expression) &&
39
+ element.expression.text === importProvidersName) {
40
+ return element;
41
+ }
42
+ }
43
+ }
44
+ return null;
45
+ }
46
+ exports.findImportProvidersFromCall = findImportProvidersFromCall;
@@ -0,0 +1,7 @@
1
+ import ts from "typescript";
2
+ /**
3
+ * Finds a NgModule declaration within the specified TypeScript node and returns the
4
+ * corresponding metadata for it. This function searches breadth first because
5
+ * NgModule's are usually not nested within other expressions or declarations.
6
+ */
7
+ export declare function findNgModuleMetadata(rootNode: ts.Node): ts.ObjectLiteralExpression | null;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findNgModuleMetadata = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const is_ng_module_expression_1 = require("./is-ng-module-expression");
9
+ /**
10
+ * Finds a NgModule declaration within the specified TypeScript node and returns the
11
+ * corresponding metadata for it. This function searches breadth first because
12
+ * NgModule's are usually not nested within other expressions or declarations.
13
+ */
14
+ function findNgModuleMetadata(rootNode) {
15
+ // Add immediate child nodes of the root node to the queue.
16
+ const nodeQueue = [...rootNode.getChildren()];
17
+ while (nodeQueue.length) {
18
+ const node = nodeQueue.shift();
19
+ if (typescript_1.default.isDecorator(node) &&
20
+ typescript_1.default.isCallExpression(node.expression) &&
21
+ (0, is_ng_module_expression_1.isNgModuleCallExpression)(node.expression)) {
22
+ return node.expression.arguments[0];
23
+ }
24
+ else {
25
+ nodeQueue.push(...node.getChildren());
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ exports.findNgModuleMetadata = findNgModuleMetadata;
@@ -0,0 +1,3 @@
1
+ import * as ts from "typescript";
2
+ /** Finds the `providers` array literal within a `bootstrapApplication` call. */
3
+ export declare function findProvidersLiteral(bootstrapCall: ts.CallExpression): ts.ArrayLiteralExpression | null;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.findProvidersLiteral = void 0;
27
+ const ts = __importStar(require("typescript"));
28
+ /** Finds the `providers` array literal within a `bootstrapApplication` call. */
29
+ function findProvidersLiteral(bootstrapCall) {
30
+ // The imports have to be in the second argument of
31
+ // the function which has to be an object literal.
32
+ if (bootstrapCall.arguments.length > 1 &&
33
+ ts.isObjectLiteralExpression(bootstrapCall.arguments[1])) {
34
+ for (const prop of bootstrapCall.arguments[1].properties) {
35
+ if (ts.isPropertyAssignment(prop) &&
36
+ ts.isIdentifier(prop.name) &&
37
+ prop.name.text === 'providers' &&
38
+ ts.isArrayLiteralExpression(prop.initializer)) {
39
+ return prop.initializer;
40
+ }
41
+ }
42
+ }
43
+ return null;
44
+ }
45
+ exports.findProvidersLiteral = findProvidersLiteral;
@@ -0,0 +1,5 @@
1
+ import * as ts from "typescript";
2
+ /**
3
+ * Returns the RouterModule declaration from NgModule metadata, if any.
4
+ */
5
+ export declare function getModuleDeclaration(source: ts.SourceFile, module: string): ts.Expression | undefined;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getModuleDeclaration = void 0;
27
+ const ts = __importStar(require("typescript"));
28
+ const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
29
+ /**
30
+ * Returns the RouterModule declaration from NgModule metadata, if any.
31
+ */
32
+ function getModuleDeclaration(source, module) {
33
+ const result = (0, ast_utils_1.getDecoratorMetadata)(source, 'NgModule', '@angular/core');
34
+ const node = result[0];
35
+ if (!node || !ts.isObjectLiteralExpression(node)) {
36
+ return undefined;
37
+ }
38
+ const matchingProperties = (0, ast_utils_1.getMetadataField)(node, 'imports');
39
+ if (!matchingProperties) {
40
+ return;
41
+ }
42
+ const assignment = matchingProperties[0];
43
+ if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
44
+ return;
45
+ }
46
+ const arrLiteral = assignment.initializer;
47
+ return arrLiteral.elements
48
+ .filter((el) => el.kind === ts.SyntaxKind.CallExpression)
49
+ .find((el) => el.getText().startsWith(module));
50
+ }
51
+ exports.getModuleDeclaration = getModuleDeclaration;
@@ -0,0 +1,3 @@
1
+ import { Tree } from "@angular-devkit/schematics";
2
+ import * as ts from "typescript";
3
+ export declare function getSourceFile(host: Tree, path: string): ts.SourceFile;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getSourceFile = void 0;
27
+ // Gets the ts source file from a path
28
+ const schematics_1 = require("@angular-devkit/schematics");
29
+ const ts = __importStar(require("typescript"));
30
+ function getSourceFile(host, path) {
31
+ const buffer = host.read(path);
32
+ if (!buffer) {
33
+ throw new schematics_1.SchematicsException(`Could not find file for path: ${path}`);
34
+ }
35
+ const text = buffer.toString('utf-8');
36
+ return ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true);
37
+ }
38
+ exports.getSourceFile = getSourceFile;
@@ -0,0 +1,2 @@
1
+ import { Tree } from "@angular-devkit/schematics";
2
+ export declare function hasNgModuleImport(tree: Tree, modulePath: string, className: string): boolean;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.hasNgModuleImport = void 0;
27
+ const schematics_1 = require("@angular-devkit/schematics");
28
+ const ts = __importStar(require("typescript"));
29
+ const find_ng_module_metadata_1 = require("./find-ng-module-metadata");
30
+ function hasNgModuleImport(tree, modulePath, className) {
31
+ const moduleFileContent = tree.read(modulePath);
32
+ if (!moduleFileContent) {
33
+ throw new schematics_1.SchematicsException(`Could not read Angular module file: ${modulePath}`);
34
+ }
35
+ const parsedFile = ts.createSourceFile(modulePath, moduleFileContent.toString(), ts.ScriptTarget.Latest, true);
36
+ const ngModuleMetadata = (0, find_ng_module_metadata_1.findNgModuleMetadata)(parsedFile);
37
+ if (!ngModuleMetadata) {
38
+ throw new schematics_1.SchematicsException(`Could not find NgModule declaration inside: "${modulePath}"`);
39
+ }
40
+ for (const property of ngModuleMetadata.properties) {
41
+ if (!ts.isPropertyAssignment(property) ||
42
+ property.name.getText() !== 'imports' ||
43
+ !ts.isArrayLiteralExpression(property.initializer)) {
44
+ continue;
45
+ }
46
+ if (property.initializer.elements.some(element => element.getText() === className)) {
47
+ return true;
48
+ }
49
+ }
50
+ return false;
51
+ }
52
+ exports.hasNgModuleImport = hasNgModuleImport;
@@ -0,0 +1,3 @@
1
+ import * as ts from "typescript";
2
+ /** Whether the specified call expression is referring to a NgModule definition. */
3
+ export declare function isNgModuleCallExpression(callExpression: ts.CallExpression): boolean;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.isNgModuleCallExpression = void 0;
27
+ const ts = __importStar(require("typescript"));
28
+ const resolve_identifier_of_expression_1 = require("./resolve-identifier-of-expression");
29
+ /** Whether the specified call expression is referring to a NgModule definition. */
30
+ function isNgModuleCallExpression(callExpression) {
31
+ if (!callExpression.arguments.length ||
32
+ !ts.isObjectLiteralExpression(callExpression.arguments[0])) {
33
+ return false;
34
+ }
35
+ // The `NgModule` call expression name is never referring to a `PrivateIdentifier`.
36
+ const decoratorIdentifier = (0, resolve_identifier_of_expression_1.resolveIdentifierOfExpression)(callExpression.expression);
37
+ return decoratorIdentifier ? decoratorIdentifier.text === 'NgModule' : false;
38
+ }
39
+ exports.isNgModuleCallExpression = isNgModuleCallExpression;
@@ -0,0 +1,13 @@
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
+ */
8
+ import { JsonValue, Path } from '@angular-devkit/core';
9
+ import { ProjectDefinition } from '@angular-devkit/core/src/workspace';
10
+ /** Resolves the architect options for the build target of the given project. */
11
+ export declare function getProjectTargetOptions(project: ProjectDefinition, buildTarget: string): Record<string, JsonValue | undefined>;
12
+ /** Looks for the main TypeScript file in the given project and returns its path. */
13
+ export declare function getProjectMainFile(project: ProjectDefinition): Path;
@@ -0,0 +1,31 @@
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
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.getProjectMainFile = exports.getProjectTargetOptions = void 0;
11
+ const schematics_1 = require("@angular-devkit/schematics");
12
+ /** Resolves the architect options for the build target of the given project. */
13
+ function getProjectTargetOptions(project, buildTarget) {
14
+ var _a, _b;
15
+ const options = (_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.get(buildTarget)) === null || _b === void 0 ? void 0 : _b.options;
16
+ if (!options) {
17
+ throw new schematics_1.SchematicsException(`Cannot determine project target configuration for: ${buildTarget}.`);
18
+ }
19
+ return options;
20
+ }
21
+ exports.getProjectTargetOptions = getProjectTargetOptions;
22
+ /** Looks for the main TypeScript file in the given project and returns its path. */
23
+ function getProjectMainFile(project) {
24
+ const buildOptions = getProjectTargetOptions(project, 'build');
25
+ if (!buildOptions['main']) {
26
+ throw new schematics_1.SchematicsException(`Could not find the project main file inside of the ` +
27
+ `workspace config (${project.sourceRoot})`);
28
+ }
29
+ return buildOptions['main'];
30
+ }
31
+ exports.getProjectMainFile = getProjectMainFile;
@@ -0,0 +1,6 @@
1
+ import * as ts from "typescript";
2
+ /**
3
+ * Resolves the last identifier that is part of the given expression. This helps resolving
4
+ * identifiers of nested property access expressions (e.g. myNamespace.core.NgModule).
5
+ */
6
+ export declare function resolveIdentifierOfExpression(expression: ts.Expression): ts.Identifier | null;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.resolveIdentifierOfExpression = void 0;
27
+ const ts = __importStar(require("typescript"));
28
+ /**
29
+ * Resolves the last identifier that is part of the given expression. This helps resolving
30
+ * identifiers of nested property access expressions (e.g. myNamespace.core.NgModule).
31
+ */
32
+ function resolveIdentifierOfExpression(expression) {
33
+ if (ts.isIdentifier(expression)) {
34
+ return expression;
35
+ }
36
+ else if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.name)) {
37
+ return expression.name;
38
+ }
39
+ return null;
40
+ }
41
+ exports.resolveIdentifierOfExpression = resolveIdentifierOfExpression;