@nstudio/angular 15.0.3 → 15.0.4-rc.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nstudio/angular",
3
- "version": "15.0.3",
3
+ "version": "15.0.4-rc.0",
4
4
  "description": "Angular Plugin for xplat",
5
5
  "homepage": "https://nstudio.io/xplat",
6
6
  "repository": {
@@ -32,6 +32,6 @@
32
32
  "@nrwl/angular": "^15.0.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@nstudio/xplat": "15.0.3"
35
+ "@nstudio/xplat": "15.0.4-rc.0"
36
36
  }
37
37
  }
@@ -170,15 +170,15 @@ function addFiles(options, extra = '') {
170
170
  ])));
171
171
  }
172
172
  function updateWorkspaceSupport(options, tree, context) {
173
- return (0, workspace_1.updateJsonInTree)('package.json', (json) => {
174
- json.scripts = json.scripts || {};
175
- json.dependencies = json.dependencies || {};
176
- const angularVersion = json.dependencies['@angular/core'];
177
- json.dependencies = Object.assign(Object.assign({}, json.dependencies), { '@angular/elements': angularVersion, '@webcomponents/webcomponentsjs': '^2.6.0' });
178
- json.devDependencies = json.devDependencies || {};
179
- json.devDependencies = Object.assign(Object.assign({}, json.devDependencies), { 'http-server': '^14.1.1', 'ngx-build-plus': '^15.0.0' });
180
- return json;
181
- })(tree, context);
173
+ const packagePath = 'package.json';
174
+ const json = (0, xplat_utils_1.getJsonFromFile)(tree, packagePath);
175
+ json.scripts = json.scripts || {};
176
+ json.dependencies = json.dependencies || {};
177
+ const angularVersion = json.dependencies['@angular/core'];
178
+ json.dependencies = Object.assign(Object.assign({}, json.dependencies), { '@angular/elements': angularVersion, '@webcomponents/webcomponentsjs': '^2.6.0' });
179
+ json.devDependencies = json.devDependencies || {};
180
+ json.devDependencies = Object.assign(Object.assign({}, json.devDependencies), { 'http-server': '^14.1.1', 'ngx-build-plus': '^15.0.0' });
181
+ return (0, xplat_utils_1.updateJsonFile)(tree, packagePath, json);
182
182
  }
183
183
  function createCustomElementList(componentSymbols) {
184
184
  const customElements = ['let component;'];
@@ -37,7 +37,7 @@ function default_1(options) {
37
37
  // update libs index
38
38
  (tree, context) => options.onlyProject
39
39
  ? (0, schematics_1.noop)()(tree, context)
40
- : xplat_1.XplatFeatureHelpers.adjustBarrelIndex(options, 'libs/xplat/features/src/lib/index.ts')(tree, context),
40
+ : xplat_1.XplatFeatureHelpers.adjustBarrelIndex(options, 'libs/xplat/features/src/lib/index.ts'),
41
41
  // external schematic handling
42
42
  (tree, context) => (0, schematics_1.chain)(externalChains),
43
43
  (0, workspace_1.formatFiles)({ skipFormat: options.skipFormat }),
@@ -11,9 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.sandboxHomeSetup = void 0;
13
13
  const schematics_1 = require("@angular-devkit/schematics");
14
- const workspace_1 = require("@nrwl/workspace");
15
14
  const testing_1 = require("@nstudio/xplat/testing");
16
15
  const testing_2 = require("../../utils/testing");
16
+ const xplat_utils_1 = require("@nstudio/xplat-utils");
17
17
  describe('feature schematic', () => {
18
18
  let appTree;
19
19
  const defaultOptions = {
@@ -324,7 +324,7 @@ describe('feature schematic', () => {
324
324
  appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree, true);
325
325
  // manually update home.component to prep for sandobx
326
326
  const homeCmpPath = `/apps/nativescript-viewer/src/features/home/components/home.component.html`;
327
- (0, workspace_1.createOrUpdate)(appTree, homeCmpPath, sandboxHomeSetup());
327
+ (0, xplat_utils_1.updateFile)(appTree, homeCmpPath, sandboxHomeSetup());
328
328
  // console.log('homecmp:', getFileContent(tree, homeCmpPath));
329
329
  options.onlyProject = true;
330
330
  options.adjustSandbox = true;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.config = void 0;
4
- const workspace_1 = require("@nrwl/workspace");
5
4
  const xplat_utils_1 = require("@nstudio/xplat-utils");
6
5
  exports.config = {
7
6
  requiresTarget: true,
@@ -11,9 +10,9 @@ exports.config = {
11
10
  function applitools(helperChains, options) {
12
11
  return (tree, context) => {
13
12
  // update support index
14
- helperChains.push((0, workspace_1.createOrUpdate)(tree, `/apps/${options.target}-e2e/src/support/index.ts`, updateCypressIndex()));
13
+ helperChains.push((0, xplat_utils_1.updateFile)(tree, `/apps/${options.target}-e2e/src/support/index.ts`, updateCypressIndex()));
15
14
  // update plugin index
16
- helperChains.push((0, workspace_1.createOrUpdate)(tree, `/apps/${options.target}-e2e/src/plugins/index.ts`, updateCypressPlugins()));
15
+ helperChains.push((0, xplat_utils_1.updateFile)(tree, `/apps/${options.target}-e2e/src/plugins/index.ts`, updateCypressPlugins()));
17
16
  // ensure supportFile points to updates
18
17
  const cypressConfigPath = `/apps/${options.target}-e2e/cypress.json`;
19
18
  const cypressConfig = (0, xplat_utils_1.getJsonFromFile)(tree, cypressConfigPath);
@@ -31,7 +30,7 @@ function applitools(helperChains, options) {
31
30
  packageJson.devDependencies['@applitools/eyes-cypress'] = '^3.7.1';
32
31
  helperChains.push((0, xplat_utils_1.updateJsonFile)(tree, 'package.json', packageJson));
33
32
  // update sample test
34
- helperChains.push((0, workspace_1.createOrUpdate)(tree, `/apps/${options.target}-e2e/src/integration/app.spec.ts`, updateSampleTest()));
33
+ helperChains.push((0, xplat_utils_1.updateFile)(tree, `/apps/${options.target}-e2e/src/integration/app.spec.ts`, updateSampleTest()));
35
34
  };
36
35
  }
37
36
  function note(options) {
@@ -1,16 +1,78 @@
1
1
  import * as ts from 'typescript';
2
- import { Change } from '@nrwl/workspace/src/utils/ast-utils';
3
- import { Tree } from '@angular-devkit/schematics';
4
- export declare function addToCollection(source: ts.SourceFile, barrelIndexPath: string, symbolName: string, insertSpaces?: string): Change[];
5
- export declare function addSymbolToNgModuleMetadata(source: ts.SourceFile, ngModulePath: string, metadataField: string, expression: string): Change[];
6
- export declare function removeFromNgModule(source: ts.SourceFile, modulePath: string, property: string): Change[];
7
- export declare function addImportToModule(source: ts.SourceFile, modulePath: string, symbolName: string): Change[];
8
- export declare function addImportToTestBed(source: ts.SourceFile, specPath: string, symbolName: string): Change[];
2
+ import { Tree } from '@nrwl/devkit';
3
+ declare type DecoratorName = 'Component' | 'Directive' | 'NgModule' | 'Pipe';
4
+ export declare function addToCollection(tree: Tree, source: ts.SourceFile, barrelIndexPath: string, symbolName: string, insertSpaces?: string): ts.SourceFile[];
5
+ /**
6
+ * Check if the Component, Directive or Pipe is standalone
7
+ * @param sourceFile TS Source File containing the token to check
8
+ * @param decoratorName The type of decorator to check (Component, Directive, Pipe)
9
+ */
10
+ export declare function isStandalone(sourceFile: ts.SourceFile, decoratorName: DecoratorName): boolean;
11
+ export declare function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[];
12
+ export declare function _addSymbolToNgModuleMetadata(host: Tree, source: ts.SourceFile, ngModulePath: string, metadataField: string, expression: string): ts.SourceFile;
13
+ export declare function removeFromNgModule(host: Tree, source: ts.SourceFile, modulePath: string, property: string): ts.SourceFile;
14
+ /**
15
+ * Add an import to a Standalone Component
16
+ * @param host Virtual Tree
17
+ * @param source TS Source File containing the Component
18
+ * @param componentPath The path to the Component
19
+ * @param symbolName The import to add to the Component
20
+ */
21
+ export declare function addImportToComponent(host: Tree, source: ts.SourceFile, componentPath: string, symbolName: string): ts.SourceFile;
22
+ /**
23
+ * Add an import to a Standalone Directive
24
+ * @param host Virtual Tree
25
+ * @param source TS Source File containing the Directive
26
+ * @param directivePath The path to the Directive
27
+ * @param symbolName The import to add to the Directive
28
+ */
29
+ export declare function addImportToDirective(host: Tree, source: ts.SourceFile, directivePath: string, symbolName: string): ts.SourceFile;
30
+ /**
31
+ * Add an import to a Standalone Pipe
32
+ * @param host Virtual Tree
33
+ * @param source TS Source File containing the Pipe
34
+ * @param pipePath The path to the Pipe
35
+ * @param symbolName The import to add to the Pipe
36
+ */
37
+ export declare function addImportToPipe(host: Tree, source: ts.SourceFile, pipePath: string, symbolName: string): ts.SourceFile;
38
+ /**
39
+ * Add an import to an NgModule
40
+ * @param host Virtual Tree
41
+ * @param source TS Source File containing the NgModule
42
+ * @param modulePath The path to the NgModule
43
+ * @param symbolName The import to add to the NgModule
44
+ */
45
+ export declare function addImportToModule(host: Tree, source: ts.SourceFile, modulePath: string, symbolName: string): ts.SourceFile;
46
+ export declare function addImportToTestBed(host: Tree, source: ts.SourceFile, specPath: string, symbolName: string): ts.SourceFile;
47
+ export declare function addDeclarationsToTestBed(host: Tree, source: ts.SourceFile, specPath: string, symbolName: string[]): ts.SourceFile;
48
+ export declare function replaceIntoToTestBed(host: Tree, source: ts.SourceFile, specPath: string, newSymbol: string, previousSymbol: string): ts.SourceFile;
9
49
  export declare function getBootstrapComponent(source: ts.SourceFile, moduleClassName: string): string;
10
- export declare function addRoute(ngModulePath: string, source: ts.SourceFile, route: string): Change[];
11
- export declare function addProviderToModule(source: ts.SourceFile, modulePath: string, symbolName: string): Change[];
12
- export declare function addDeclarationToModule(source: ts.SourceFile, modulePath: string, symbolName: string): Change[];
13
- export declare function addEntryComponents(source: ts.SourceFile, modulePath: string, symbolName: string): Change[];
50
+ export declare function addRouteToNgModule(host: Tree, ngModulePath: string, source: ts.SourceFile, route: string): ts.SourceFile;
51
+ /**
52
+ * Add a provider to bootstrapApplication call for Standalone Applications
53
+ * @param tree Virtual Tree
54
+ * @param filePath Path to the file containing the bootstrapApplication call
55
+ * @param providerToAdd Provider to add
56
+ */
57
+ export declare function addProviderToBootstrapApplication(tree: Tree, filePath: string, providerToAdd: string): void;
58
+ /**
59
+ * Add a provider to an NgModule
60
+ * @param host Virtual Tree
61
+ * @param source TS Source File containing the NgModule
62
+ * @param modulePath Path to the NgModule
63
+ * @param symbolName The provider to add
64
+ */
65
+ export declare function addProviderToModule(host: Tree, source: ts.SourceFile, modulePath: string, symbolName: string): ts.SourceFile;
66
+ /**
67
+ * Add a provider to a Standalone Component
68
+ * @param host Virtual Tree
69
+ * @param source TS Source File containing the Component
70
+ * @param componentPath Path to the Component
71
+ * @param symbolName The provider to add
72
+ */
73
+ export declare function addProviderToComponent(host: Tree, source: ts.SourceFile, componentPath: string, symbolName: string): ts.SourceFile;
74
+ export declare function addDeclarationToModule(host: Tree, source: ts.SourceFile, modulePath: string, symbolName: string): ts.SourceFile;
75
+ export declare function addEntryComponents(host: Tree, source: ts.SourceFile, modulePath: string, symbolName: string): ts.SourceFile;
14
76
  export declare function readBootstrapInfo(host: Tree, app: string): {
15
77
  moduleSpec: string;
16
78
  modulePath: string;
@@ -21,3 +83,5 @@ export declare function readBootstrapInfo(host: Tree, app: string): {
21
83
  bootstrapComponentFileName: string;
22
84
  };
23
85
  export declare function getDecoratorPropertyValueNode(host: Tree, modulePath: string, identifier: string, property: string, module: string): ts.Node;
86
+ export declare function getTsSourceFile(host: Tree, path: string): ts.SourceFile;
87
+ export {};
package/src/utils/ast.js CHANGED
@@ -1,28 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDecoratorPropertyValueNode = exports.readBootstrapInfo = exports.addEntryComponents = exports.addDeclarationToModule = exports.addProviderToModule = exports.addRoute = exports.getBootstrapComponent = exports.addImportToTestBed = exports.addImportToModule = exports.removeFromNgModule = exports.addSymbolToNgModuleMetadata = exports.addToCollection = void 0;
3
+ exports.getTsSourceFile = exports.getDecoratorPropertyValueNode = exports.readBootstrapInfo = exports.addEntryComponents = exports.addDeclarationToModule = exports.addProviderToComponent = exports.addProviderToModule = exports.addProviderToBootstrapApplication = exports.addRouteToNgModule = exports.getBootstrapComponent = exports.replaceIntoToTestBed = exports.addDeclarationsToTestBed = exports.addImportToTestBed = exports.addImportToModule = exports.addImportToPipe = exports.addImportToDirective = exports.addImportToComponent = exports.removeFromNgModule = exports._addSymbolToNgModuleMetadata = exports.getDecoratorMetadata = exports.isStandalone = exports.addToCollection = void 0;
4
+ const ensure_typescript_1 = require("@nrwl/js/src/utils/typescript/ensure-typescript");
5
+ const typescript_1 = require("nx/src/utils/typescript");
4
6
  const ts = require("typescript");
5
- const ast_utils_1 = require("@nrwl/workspace/src/utils/ast-utils");
6
- const path = require("path");
7
- const xplat_utils_1 = require("@nstudio/xplat-utils");
8
- function addToCollection(source, barrelIndexPath, symbolName, insertSpaces = '') {
7
+ const js_1 = require("@nrwl/js");
8
+ const path_1 = require("path");
9
+ const devkit_1 = require("@nrwl/devkit");
10
+ let tsModule;
11
+ function addToCollection(tree, source, barrelIndexPath, symbolName, insertSpaces = '') {
9
12
  const collection = getCollection(source);
10
13
  if (!collection)
11
14
  return [];
12
15
  // if (!collection) return [new NoopChange()];
13
16
  // return [new NoopChange()];
17
+ console.log('collection.hasTrailingComma:', collection.hasTrailingComma);
14
18
  if (collection.hasTrailingComma || collection.length === 0) {
15
- return [new ast_utils_1.InsertChange(barrelIndexPath, collection.end, symbolName)];
19
+ return [
20
+ (0, js_1.insertChange)(tree, source, barrelIndexPath, collection.end, symbolName),
21
+ ];
16
22
  }
17
23
  else {
18
24
  return [
19
- new ast_utils_1.InsertChange(barrelIndexPath, collection.end, `,\n${insertSpaces}${symbolName}`),
25
+ (0, js_1.insertChange)(tree, source, barrelIndexPath, collection.end, `,\n${insertSpaces}${symbolName}`),
20
26
  ];
21
27
  }
22
28
  }
23
29
  exports.addToCollection = addToCollection;
24
30
  function getCollection(source) {
25
- const allCollections = (0, ast_utils_1.findNodes)(source, ts.SyntaxKind.ArrayLiteralExpression);
31
+ const allCollections = (0, typescript_1.findNodes)(source, ts.SyntaxKind.ArrayLiteralExpression);
26
32
  // console.log('allCollections:', allCollections);
27
33
  // allCollections.forEach((i: ts.ArrayLiteralExpression) => {
28
34
  // console.log('getText:',i.getText());
@@ -35,10 +41,13 @@ function getCollection(source) {
35
41
  return null;
36
42
  }
37
43
  function _angularImportsFromNode(node, _sourceFile) {
44
+ if (!tsModule) {
45
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
46
+ }
38
47
  const ms = node.moduleSpecifier;
39
48
  let modulePath;
40
49
  switch (ms.kind) {
41
- case ts.SyntaxKind.StringLiteral:
50
+ case tsModule.SyntaxKind.StringLiteral:
42
51
  modulePath = ms.text;
43
52
  break;
44
53
  default:
@@ -54,10 +63,10 @@ function _angularImportsFromNode(node, _sourceFile) {
54
63
  }
55
64
  else if (node.importClause.namedBindings) {
56
65
  const nb = node.importClause.namedBindings;
57
- if (nb.kind == ts.SyntaxKind.NamespaceImport) {
66
+ if (nb.kind == tsModule.SyntaxKind.NamespaceImport) {
58
67
  // This is of the form `import * as name from 'path'`. Return `name.`.
59
68
  return {
60
- [nb.name.text + '.']: modulePath,
69
+ [`${nb.name.text}.`]: modulePath,
61
70
  };
62
71
  }
63
72
  else {
@@ -78,8 +87,21 @@ function _angularImportsFromNode(node, _sourceFile) {
78
87
  return {};
79
88
  }
80
89
  }
90
+ /**
91
+ * Check if the Component, Directive or Pipe is standalone
92
+ * @param sourceFile TS Source File containing the token to check
93
+ * @param decoratorName The type of decorator to check (Component, Directive, Pipe)
94
+ */
95
+ function isStandalone(sourceFile, decoratorName) {
96
+ const decoratorMetadata = getDecoratorMetadata(sourceFile, decoratorName, '@angular/core');
97
+ return decoratorMetadata.some((node) => node.getText().includes('standalone: true'));
98
+ }
99
+ exports.isStandalone = isStandalone;
81
100
  function getDecoratorMetadata(source, identifier, module) {
82
- const angularImports = (0, ast_utils_1.findNodes)(source, ts.SyntaxKind.ImportDeclaration)
101
+ if (!tsModule) {
102
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
103
+ }
104
+ const angularImports = (0, typescript_1.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration)
83
105
  .map((node) => _angularImportsFromNode(node, source))
84
106
  .reduce((acc, current) => {
85
107
  for (const key of Object.keys(current)) {
@@ -87,60 +109,65 @@ function getDecoratorMetadata(source, identifier, module) {
87
109
  }
88
110
  return acc;
89
111
  }, {});
90
- return (0, ast_utils_1.getSourceNodes)(source)
112
+ return (0, js_1.getSourceNodes)(source)
91
113
  .filter((node) => {
92
- return (node.kind == ts.SyntaxKind.Decorator &&
93
- node.expression.kind == ts.SyntaxKind.CallExpression);
114
+ return (node.kind == tsModule.SyntaxKind.Decorator &&
115
+ node.expression.kind ==
116
+ tsModule.SyntaxKind.CallExpression);
94
117
  })
95
118
  .map((node) => node.expression)
96
119
  .filter((expr) => {
97
- if (expr.expression.kind == ts.SyntaxKind.Identifier) {
120
+ if (expr.expression.kind == tsModule.SyntaxKind.Identifier) {
98
121
  const id = expr.expression;
99
122
  return (id.getFullText(source) == identifier &&
100
123
  angularImports[id.getFullText(source)] === module);
101
124
  }
102
- else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
125
+ else if (expr.expression.kind == tsModule.SyntaxKind.PropertyAccessExpression) {
103
126
  // This covers foo.NgModule when importing * as foo.
104
127
  const paExpr = expr.expression;
105
128
  // If the left expression is not an identifier, just give up at that point.
106
- if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {
129
+ if (paExpr.expression.kind !== tsModule.SyntaxKind.Identifier) {
107
130
  return false;
108
131
  }
109
132
  const id = paExpr.name.text;
110
133
  const moduleId = paExpr.expression.getText(source);
111
- return id === identifier && angularImports[moduleId + '.'] === module;
134
+ return id === identifier && angularImports[`${moduleId}.`] === module;
112
135
  }
113
136
  return false;
114
137
  })
115
138
  .filter((expr) => expr.arguments[0] &&
116
- expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)
139
+ expr.arguments[0].kind == tsModule.SyntaxKind.ObjectLiteralExpression)
117
140
  .map((expr) => expr.arguments[0]);
118
141
  }
119
- function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, expression) {
120
- const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
142
+ exports.getDecoratorMetadata = getDecoratorMetadata;
143
+ function _addSymbolToDecoratorMetadata(host, source, filePath, metadataField, expression, decoratorName) {
144
+ const nodes = getDecoratorMetadata(source, decoratorName, '@angular/core');
121
145
  let node = nodes[0]; // tslint:disable-line:no-any
122
146
  // Find the decorator declaration.
123
147
  if (!node) {
124
- return [];
148
+ return source;
149
+ }
150
+ if (!tsModule) {
151
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
125
152
  }
126
153
  // Get all the children property assignment of object literals.
127
154
  const matchingProperties = node.properties
128
- .filter((prop) => prop.kind == ts.SyntaxKind.PropertyAssignment)
155
+ .filter((prop) => prop.kind == tsModule.SyntaxKind.PropertyAssignment)
129
156
  // Filter out every fields that's not "metadataField". Also handles string literals
130
157
  // (but not expressions).
131
158
  .filter((prop) => {
132
159
  const name = prop.name;
133
160
  switch (name.kind) {
134
- case ts.SyntaxKind.Identifier:
161
+ case tsModule.SyntaxKind.Identifier:
135
162
  return name.getText(source) == metadataField;
136
- case ts.SyntaxKind.StringLiteral:
163
+ case tsModule.SyntaxKind.StringLiteral:
137
164
  return name.text == metadataField;
138
165
  }
139
166
  return false;
140
167
  });
141
168
  // Get the last node of the array literal.
142
169
  if (!matchingProperties) {
143
- return [];
170
+ return source;
144
171
  }
145
172
  if (matchingProperties.length == 0) {
146
173
  // We haven't found the field in the metadata declaration. Insert a new field.
@@ -163,13 +190,12 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, expres
163
190
  toInsert = `, ${metadataField}: [${expression}]`;
164
191
  }
165
192
  }
166
- const newMetadataProperty = new ast_utils_1.InsertChange(ngModulePath, position, toInsert);
167
- return [newMetadataProperty];
193
+ return (0, js_1.insertChange)(host, source, filePath, position, toInsert);
168
194
  }
169
195
  const assignment = matchingProperties[0];
170
196
  // If it's not an array, nothing we can do really.
171
- if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
172
- return [];
197
+ if (assignment.initializer.kind !== tsModule.SyntaxKind.ArrayLiteralExpression) {
198
+ return source;
173
199
  }
174
200
  const arrLiteral = assignment.initializer;
175
201
  if (arrLiteral.elements.length == 0) {
@@ -181,20 +207,20 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, expres
181
207
  }
182
208
  if (!node) {
183
209
  console.log('No app module found. Please add your new class to your component.');
184
- return [];
210
+ return source;
185
211
  }
186
212
  const isArray = Array.isArray(node);
187
213
  if (isArray) {
188
214
  const nodeArray = node;
189
215
  const symbolsArray = nodeArray.map((node) => node.getText());
190
216
  if (symbolsArray.includes(expression)) {
191
- return [];
217
+ return source;
192
218
  }
193
219
  node = node[node.length - 1];
194
220
  }
195
221
  let toInsert;
196
222
  let position = node.getEnd();
197
- if (!isArray && node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
223
+ if (!isArray && node.kind == tsModule.SyntaxKind.ObjectLiteralExpression) {
198
224
  // We haven't found the field in the metadata declaration. Insert a new
199
225
  // field.
200
226
  const expr = node;
@@ -215,7 +241,8 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, expres
215
241
  }
216
242
  }
217
243
  }
218
- else if (!isArray && node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
244
+ else if (!isArray &&
245
+ node.kind == tsModule.SyntaxKind.ArrayLiteralExpression) {
219
246
  // We found the field but it's empty. Insert it just before the `]`.
220
247
  position--;
221
248
  toInsert = `${expression}`;
@@ -230,54 +257,130 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, expres
230
257
  toInsert = `, ${expression}`;
231
258
  }
232
259
  }
233
- const insert = new ast_utils_1.InsertChange(ngModulePath, position, toInsert);
234
- return [insert];
260
+ return (0, js_1.insertChange)(host, source, filePath, position, toInsert);
261
+ }
262
+ function _addSymbolToNgModuleMetadata(host, source, ngModulePath, metadataField, expression) {
263
+ return _addSymbolToDecoratorMetadata(host, source, ngModulePath, metadataField, expression, 'NgModule');
235
264
  }
236
- exports.addSymbolToNgModuleMetadata = addSymbolToNgModuleMetadata;
237
- function removeFromNgModule(source, modulePath, property) {
265
+ exports._addSymbolToNgModuleMetadata = _addSymbolToNgModuleMetadata;
266
+ function removeFromNgModule(host, source, modulePath, property) {
238
267
  const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
239
268
  let node = nodes[0]; // tslint:disable-line:no-any
240
269
  // Find the decorator declaration.
241
270
  if (!node) {
242
- return [];
271
+ return source;
243
272
  }
244
273
  // Get all the children property assignment of object literals.
245
274
  const matchingProperty = getMatchingProperty(source, property, 'NgModule', '@angular/core');
246
275
  if (matchingProperty) {
247
- return [
248
- new ast_utils_1.RemoveChange(modulePath, matchingProperty.getStart(source), matchingProperty.getFullText(source)),
249
- ];
250
- }
251
- else {
252
- return [];
276
+ return (0, js_1.removeChange)(host, source, modulePath, matchingProperty.getStart(source), matchingProperty.getFullText(source));
253
277
  }
254
278
  }
255
279
  exports.removeFromNgModule = removeFromNgModule;
256
- function addImportToModule(source, modulePath, symbolName) {
257
- return addSymbolToNgModuleMetadata(source, modulePath, 'imports', symbolName);
280
+ /**
281
+ * Add an import to a Standalone Component
282
+ * @param host Virtual Tree
283
+ * @param source TS Source File containing the Component
284
+ * @param componentPath The path to the Component
285
+ * @param symbolName The import to add to the Component
286
+ */
287
+ function addImportToComponent(host, source, componentPath, symbolName) {
288
+ return _addSymbolToDecoratorMetadata(host, source, componentPath, 'imports', symbolName, 'Component');
289
+ }
290
+ exports.addImportToComponent = addImportToComponent;
291
+ /**
292
+ * Add an import to a Standalone Directive
293
+ * @param host Virtual Tree
294
+ * @param source TS Source File containing the Directive
295
+ * @param directivePath The path to the Directive
296
+ * @param symbolName The import to add to the Directive
297
+ */
298
+ function addImportToDirective(host, source, directivePath, symbolName) {
299
+ return _addSymbolToDecoratorMetadata(host, source, directivePath, 'imports', symbolName, 'Directive');
300
+ }
301
+ exports.addImportToDirective = addImportToDirective;
302
+ /**
303
+ * Add an import to a Standalone Pipe
304
+ * @param host Virtual Tree
305
+ * @param source TS Source File containing the Pipe
306
+ * @param pipePath The path to the Pipe
307
+ * @param symbolName The import to add to the Pipe
308
+ */
309
+ function addImportToPipe(host, source, pipePath, symbolName) {
310
+ return _addSymbolToDecoratorMetadata(host, source, pipePath, 'imports', symbolName, 'Pipe');
311
+ }
312
+ exports.addImportToPipe = addImportToPipe;
313
+ /**
314
+ * Add an import to an NgModule
315
+ * @param host Virtual Tree
316
+ * @param source TS Source File containing the NgModule
317
+ * @param modulePath The path to the NgModule
318
+ * @param symbolName The import to add to the NgModule
319
+ */
320
+ function addImportToModule(host, source, modulePath, symbolName) {
321
+ return _addSymbolToNgModuleMetadata(host, source, modulePath, 'imports', symbolName);
258
322
  }
259
323
  exports.addImportToModule = addImportToModule;
260
- function addImportToTestBed(source, specPath, symbolName) {
261
- const allCalls = ((0, ast_utils_1.findNodes)(source, ts.SyntaxKind.CallExpression));
324
+ function addImportToTestBed(host, source, specPath, symbolName) {
325
+ if (!tsModule) {
326
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
327
+ }
328
+ const allCalls = ((0, typescript_1.findNodes)(source, tsModule.SyntaxKind.CallExpression));
262
329
  const configureTestingModuleObjectLiterals = allCalls
263
- .filter((c) => c.expression.kind === ts.SyntaxKind.PropertyAccessExpression)
330
+ .filter((c) => c.expression.kind === tsModule.SyntaxKind.PropertyAccessExpression)
264
331
  .filter((c) => c.expression.name.getText(source) === 'configureTestingModule')
265
- .map((c) => c.arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression
332
+ .map((c) => c.arguments[0].kind === tsModule.SyntaxKind.ObjectLiteralExpression
266
333
  ? c.arguments[0]
267
334
  : null);
268
335
  if (configureTestingModuleObjectLiterals.length > 0) {
269
336
  const startPosition = configureTestingModuleObjectLiterals[0]
270
337
  .getFirstToken(source)
271
338
  .getEnd();
272
- return [
273
- new ast_utils_1.InsertChange(specPath, startPosition, `imports: [${symbolName}], `),
274
- ];
275
- }
276
- else {
277
- return [];
339
+ return (0, js_1.insertChange)(host, source, specPath, startPosition, `imports: [${symbolName}], `);
278
340
  }
341
+ return source;
279
342
  }
280
343
  exports.addImportToTestBed = addImportToTestBed;
344
+ function addDeclarationsToTestBed(host, source, specPath, symbolName) {
345
+ if (!tsModule) {
346
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
347
+ }
348
+ const allCalls = ((0, typescript_1.findNodes)(source, tsModule.SyntaxKind.CallExpression));
349
+ const configureTestingModuleObjectLiterals = allCalls
350
+ .filter((c) => c.expression.kind === tsModule.SyntaxKind.PropertyAccessExpression)
351
+ .filter((c) => c.expression.name.getText(source) === 'configureTestingModule')
352
+ .map((c) => c.arguments[0].kind === tsModule.SyntaxKind.ObjectLiteralExpression
353
+ ? c.arguments[0]
354
+ : null);
355
+ if (configureTestingModuleObjectLiterals.length > 0) {
356
+ const startPosition = configureTestingModuleObjectLiterals[0]
357
+ .getFirstToken(source)
358
+ .getEnd();
359
+ return (0, js_1.insertChange)(host, source, specPath, startPosition, `declarations: [${symbolName.join(',')}], `);
360
+ }
361
+ return source;
362
+ }
363
+ exports.addDeclarationsToTestBed = addDeclarationsToTestBed;
364
+ function replaceIntoToTestBed(host, source, specPath, newSymbol, previousSymbol) {
365
+ if (!tsModule) {
366
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
367
+ }
368
+ const allCalls = ((0, typescript_1.findNodes)(source, tsModule.SyntaxKind.CallExpression));
369
+ const configureTestingModuleObjectLiterals = allCalls
370
+ .filter((c) => c.expression.kind === tsModule.SyntaxKind.PropertyAccessExpression)
371
+ .filter((c) => c.expression.name.getText(source) === 'configureTestingModule')
372
+ .map((c) => c.arguments[0].kind === tsModule.SyntaxKind.ObjectLiteralExpression
373
+ ? c.arguments[0]
374
+ : null);
375
+ if (configureTestingModuleObjectLiterals.length > 0) {
376
+ const startPosition = configureTestingModuleObjectLiterals[0]
377
+ .getFirstToken(source)
378
+ .getEnd();
379
+ return (0, js_1.replaceChange)(host, source, specPath, startPosition, newSymbol, previousSymbol);
380
+ }
381
+ return source;
382
+ }
383
+ exports.replaceIntoToTestBed = replaceIntoToTestBed;
281
384
  function getBootstrapComponent(source, moduleClassName) {
282
385
  const bootstrap = getMatchingProperty(source, 'bootstrap', 'NgModule', '@angular/core');
283
386
  if (!bootstrap) {
@@ -300,56 +403,113 @@ function getMatchingProperty(source, property, identifier, module) {
300
403
  // Get all the children property assignment of object literals.
301
404
  return getMatchingObjectLiteralElement(node, source, property);
302
405
  }
303
- function addRoute(ngModulePath, source, route) {
406
+ function addRouteToNgModule(host, ngModulePath, source, route) {
304
407
  const routes = getListOfRoutes(source);
305
408
  if (!routes)
306
- return [];
409
+ return source;
307
410
  if (routes.hasTrailingComma || routes.length === 0) {
308
- return [new ast_utils_1.InsertChange(ngModulePath, routes.end, route)];
411
+ return (0, js_1.insertChange)(host, source, ngModulePath, routes.end, route);
309
412
  }
310
413
  else {
311
- return [new ast_utils_1.InsertChange(ngModulePath, routes.end, `, ${route}`)];
414
+ return (0, js_1.insertChange)(host, source, ngModulePath, routes.end, `, ${route}`);
312
415
  }
313
416
  }
314
- exports.addRoute = addRoute;
417
+ exports.addRouteToNgModule = addRouteToNgModule;
315
418
  function getListOfRoutes(source) {
419
+ if (!tsModule) {
420
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
421
+ }
316
422
  const imports = getMatchingProperty(source, 'imports', 'NgModule', '@angular/core');
317
- if (imports.initializer.kind === ts.SyntaxKind.ArrayLiteralExpression) {
423
+ if ((imports === null || imports === void 0 ? void 0 : imports.initializer.kind) === tsModule.SyntaxKind.ArrayLiteralExpression) {
318
424
  const a = imports.initializer;
319
- for (let e of a.elements) {
320
- if (e.kind === ts.SyntaxKind.CallExpression) {
425
+ for (const e of a.elements) {
426
+ if (e.kind === tsModule.SyntaxKind.CallExpression) {
321
427
  const ee = e;
322
428
  const text = ee.expression.getText(source);
323
429
  if ((text === 'RouterModule.forRoot' ||
324
430
  text === 'RouterModule.forChild') &&
325
431
  ee.arguments.length > 0) {
326
432
  const routes = ee.arguments[0];
327
- if (routes.kind === ts.SyntaxKind.ArrayLiteralExpression) {
433
+ if (routes.kind === tsModule.SyntaxKind.ArrayLiteralExpression) {
328
434
  return routes.elements;
329
435
  }
436
+ else if (routes.kind === tsModule.SyntaxKind.Identifier) {
437
+ // find the array expression
438
+ const variableDeclarations = (0, typescript_1.findNodes)(source, tsModule.SyntaxKind.VariableDeclaration);
439
+ const routesDeclaration = variableDeclarations.find((x) => {
440
+ return x.name.getText() === routes.getText();
441
+ });
442
+ if (routesDeclaration) {
443
+ return routesDeclaration.initializer.elements;
444
+ }
445
+ }
330
446
  }
331
447
  }
332
448
  }
333
449
  }
334
450
  return null;
335
451
  }
336
- function addProviderToModule(source, modulePath, symbolName) {
337
- return addSymbolToNgModuleMetadata(source, modulePath, 'providers', symbolName);
452
+ /**
453
+ * Add a provider to bootstrapApplication call for Standalone Applications
454
+ * @param tree Virtual Tree
455
+ * @param filePath Path to the file containing the bootstrapApplication call
456
+ * @param providerToAdd Provider to add
457
+ */
458
+ function addProviderToBootstrapApplication(tree, filePath, providerToAdd) {
459
+ (0, ensure_typescript_1.ensureTypescript)();
460
+ const { tsquery } = require('@phenomnomnominal/tsquery');
461
+ const PROVIDERS_ARRAY_SELECTOR = 'CallExpression:has(Identifier[name=bootstrapApplication]) ObjectLiteralExpression > PropertyAssignment:has(Identifier[name=providers]) > ArrayLiteralExpression';
462
+ const fileContents = tree.read(filePath, 'utf-8');
463
+ const ast = tsquery.ast(fileContents);
464
+ const providersArrayNodes = tsquery(ast, PROVIDERS_ARRAY_SELECTOR, {
465
+ visitAllChildren: true,
466
+ });
467
+ if (providersArrayNodes.length === 0) {
468
+ throw new Error(`Providers does not exist in the bootstrapApplication call within ${filePath}.`);
469
+ }
470
+ const arrayNode = providersArrayNodes[0];
471
+ const newFileContents = `${fileContents.slice(0, arrayNode.getStart() + 1)}${providerToAdd},${fileContents.slice(arrayNode.getStart() + 1, fileContents.length)}`;
472
+ tree.write(filePath, newFileContents);
473
+ }
474
+ exports.addProviderToBootstrapApplication = addProviderToBootstrapApplication;
475
+ /**
476
+ * Add a provider to an NgModule
477
+ * @param host Virtual Tree
478
+ * @param source TS Source File containing the NgModule
479
+ * @param modulePath Path to the NgModule
480
+ * @param symbolName The provider to add
481
+ */
482
+ function addProviderToModule(host, source, modulePath, symbolName) {
483
+ return _addSymbolToNgModuleMetadata(host, source, modulePath, 'providers', symbolName);
338
484
  }
339
485
  exports.addProviderToModule = addProviderToModule;
340
- function addDeclarationToModule(source, modulePath, symbolName) {
341
- return addSymbolToNgModuleMetadata(source, modulePath, 'declarations', symbolName);
486
+ /**
487
+ * Add a provider to a Standalone Component
488
+ * @param host Virtual Tree
489
+ * @param source TS Source File containing the Component
490
+ * @param componentPath Path to the Component
491
+ * @param symbolName The provider to add
492
+ */
493
+ function addProviderToComponent(host, source, componentPath, symbolName) {
494
+ return _addSymbolToDecoratorMetadata(host, source, componentPath, 'providers', symbolName, 'Component');
495
+ }
496
+ exports.addProviderToComponent = addProviderToComponent;
497
+ function addDeclarationToModule(host, source, modulePath, symbolName) {
498
+ return _addSymbolToNgModuleMetadata(host, source, modulePath, 'declarations', symbolName);
342
499
  }
343
500
  exports.addDeclarationToModule = addDeclarationToModule;
344
- function addEntryComponents(source, modulePath, symbolName) {
345
- return addSymbolToNgModuleMetadata(source, modulePath, 'entryComponents', symbolName);
501
+ function addEntryComponents(host, source, modulePath, symbolName) {
502
+ return _addSymbolToNgModuleMetadata(host, source, modulePath, 'entryComponents', symbolName);
346
503
  }
347
504
  exports.addEntryComponents = addEntryComponents;
348
505
  function readBootstrapInfo(host, app) {
349
- const config = (0, ast_utils_1.getProjectConfig)(host, app);
506
+ if (!tsModule) {
507
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
508
+ }
509
+ const config = (0, devkit_1.readProjectConfiguration)(host, app);
350
510
  let mainPath;
351
511
  try {
352
- mainPath = config.architect.build.options.main;
512
+ mainPath = config.targets.build.options.main;
353
513
  }
354
514
  catch (e) {
355
515
  throw new Error('Main file cannot be located');
@@ -358,21 +518,21 @@ function readBootstrapInfo(host, app) {
358
518
  throw new Error('Main file cannot be located');
359
519
  }
360
520
  const mainSource = host.read(mainPath).toString('utf-8');
361
- const main = ts.createSourceFile(mainPath, mainSource, ts.ScriptTarget.Latest, true);
362
- const moduleImports = (0, ast_utils_1.getImport)(main, (s) => s.indexOf('.module') > -1);
521
+ const main = tsModule.createSourceFile(mainPath, mainSource, tsModule.ScriptTarget.Latest, true);
522
+ const moduleImports = (0, js_1.getImport)(main, (s) => s.indexOf('.module') > -1);
363
523
  if (moduleImports.length !== 1) {
364
524
  throw new Error(`main.ts can only import a single module`);
365
525
  }
366
526
  const moduleImport = moduleImports[0];
367
527
  const moduleClassName = moduleImport.bindings.filter((b) => b.endsWith('Module'))[0];
368
- const modulePath = `${path.join(path.dirname(mainPath), moduleImport.moduleSpec)}.ts`;
528
+ const modulePath = `${(0, path_1.join)((0, path_1.dirname)(mainPath), moduleImport.moduleSpec)}.ts`;
369
529
  if (!host.exists(modulePath)) {
370
530
  throw new Error(`Cannot find '${modulePath}'`);
371
531
  }
372
532
  const moduleSourceText = host.read(modulePath).toString('utf-8');
373
- const moduleSource = ts.createSourceFile(modulePath, moduleSourceText, ts.ScriptTarget.Latest, true);
533
+ const moduleSource = tsModule.createSourceFile(modulePath, moduleSourceText, tsModule.ScriptTarget.Latest, true);
374
534
  const bootstrapComponentClassName = getBootstrapComponent(moduleSource, moduleClassName);
375
- const bootstrapComponentFileName = `./${path.join(path.dirname(moduleImport.moduleSpec), `${(0, xplat_utils_1.toFileName)(bootstrapComponentClassName.substring(0, bootstrapComponentClassName.length - 9))}.component`)}`;
535
+ const bootstrapComponentFileName = `./${(0, path_1.join)((0, path_1.dirname)(moduleImport.moduleSpec), `${(0, devkit_1.names)(bootstrapComponentClassName.substring(0, bootstrapComponentClassName.length - 9)).fileName}.component`)}`;
376
536
  return {
377
537
  moduleSpec: moduleImport.moduleSpec,
378
538
  mainPath,
@@ -385,25 +545,44 @@ function readBootstrapInfo(host, app) {
385
545
  }
386
546
  exports.readBootstrapInfo = readBootstrapInfo;
387
547
  function getDecoratorPropertyValueNode(host, modulePath, identifier, property, module) {
548
+ if (!tsModule) {
549
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
550
+ }
388
551
  const moduleSourceText = host.read(modulePath).toString('utf-8');
389
- const moduleSource = ts.createSourceFile(modulePath, moduleSourceText, ts.ScriptTarget.Latest, true);
552
+ const moduleSource = tsModule.createSourceFile(modulePath, moduleSourceText, tsModule.ScriptTarget.Latest, true);
390
553
  const templateNode = getMatchingProperty(moduleSource, property, identifier, module);
391
554
  return templateNode.getChildAt(templateNode.getChildCount() - 1);
392
555
  }
393
556
  exports.getDecoratorPropertyValueNode = getDecoratorPropertyValueNode;
394
557
  function getMatchingObjectLiteralElement(node, source, property) {
558
+ if (!tsModule) {
559
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
560
+ }
395
561
  return (node.properties
396
- .filter((prop) => prop.kind == ts.SyntaxKind.PropertyAssignment)
562
+ .filter((prop) => prop.kind == tsModule.SyntaxKind.PropertyAssignment)
397
563
  // Filter out every fields that's not "metadataField". Also handles string literals
398
564
  // (but not expressions).
399
565
  .filter((prop) => {
400
566
  const name = prop.name;
401
567
  switch (name.kind) {
402
- case ts.SyntaxKind.Identifier:
568
+ case tsModule.SyntaxKind.Identifier:
403
569
  return name.getText(source) === property;
404
- case ts.SyntaxKind.StringLiteral:
570
+ case tsModule.SyntaxKind.StringLiteral:
405
571
  return name.text === property;
406
572
  }
407
573
  return false;
408
574
  })[0]);
409
575
  }
576
+ function getTsSourceFile(host, path) {
577
+ if (!tsModule) {
578
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
579
+ }
580
+ const buffer = host.read(path);
581
+ if (!buffer) {
582
+ throw new Error(`Could not read TS file (${path}).`);
583
+ }
584
+ const content = buffer.toString();
585
+ const source = tsModule.createSourceFile(path, content, tsModule.ScriptTarget.Latest, true);
586
+ return source;
587
+ }
588
+ exports.getTsSourceFile = getTsSourceFile;
@@ -198,7 +198,7 @@ function getFeatureName(options) {
198
198
  }
199
199
  exports.getFeatureName = getFeatureName;
200
200
  function getNxFeaturePath(tree, featureName) {
201
- const tsConfig = (0, workspace_1.readJsonInTree)(tree, 'tsconfig.base.json');
201
+ const tsConfig = (0, xplat_utils_1.getJsonFromFile)(tree, 'tsconfig.base.json');
202
202
  if (tsConfig) {
203
203
  if (tsConfig.compilerOptions &&
204
204
  tsConfig.compilerOptions.paths &&
@@ -331,7 +331,8 @@ function adjustBarrel(type, options, prefix) {
331
331
  }
332
332
  exports.adjustBarrel = adjustBarrel;
333
333
  function adjustBarrelIndex(type, options, indexFilePath, inSubFolder, isBase, importIfSubFolder) {
334
- return (host) => {
334
+ return (host, context) => {
335
+ const devKitTree = (0, xplat_1.convertNgTreeToDevKit)(host, context);
335
336
  // console.log('adjustBarrelIndex:', indexFilePath);
336
337
  // console.log('host.exists(indexFilePath):', host.exists(indexFilePath));
337
338
  if (host.exists(indexFilePath)) {
@@ -346,45 +347,46 @@ function adjustBarrelIndex(type, options, indexFilePath, inSubFolder, isBase, im
346
347
  const symbolName = `${xplat_1.stringUtils
347
348
  .sanitize(options.subFolder)
348
349
  .toUpperCase()}_${type.toUpperCase()}S`;
349
- changes.push(...(0, xplat_1.addGlobal)(indexSourceFile, indexFilePath, `import { ${symbolName} } from './${options.subFolder}';`), ...(0, ast_1.addToCollection)(indexSourceFile, indexFilePath, `...${symbolName}`, ' '));
350
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, indexSourceFile, indexFilePath, `import { ${symbolName} } from './${options.subFolder}';`, false), ...(0, ast_1.addToCollection)(devKitTree, indexSourceFile, indexFilePath, `...${symbolName}`, ' '));
350
351
  }
351
352
  else {
352
353
  const symbolName = `${xplat_1.stringUtils.classify(name)}${xplat_1.stringUtils.capitalize(type)}`;
353
- changes.push(...(0, xplat_1.addGlobal)(indexSourceFile, indexFilePath, `import { ${symbolName} } from './${inSubFolder ? `${name}/` : ''}${name}.${type}';`), ...(0, ast_1.addToCollection)(indexSourceFile, indexFilePath, symbolName, ' '));
354
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, indexSourceFile, indexFilePath, `import { ${symbolName} } from './${inSubFolder ? `${name}/` : ''}${name}.${type}';`), ...(0, ast_1.addToCollection)(devKitTree, indexSourceFile, indexFilePath, symbolName, ' '));
354
355
  }
355
356
  }
356
357
  if (type === 'component' || type === 'service' || type === 'pipe') {
357
358
  // export symbol from barrel
358
359
  if ((isBase || importIfSubFolder) && options.subFolder) {
359
- changes.push(...(0, xplat_1.addGlobal)(indexSourceFile, indexFilePath, `export * from './${options.subFolder}';`, true));
360
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, indexSourceFile, indexFilePath, `export * from './${options.subFolder}';`, true));
360
361
  }
361
362
  else {
362
363
  const subFolder = inSubFolder ? `${name}/` : '';
363
- changes.push(...(0, xplat_1.addGlobal)(indexSourceFile, indexFilePath, `export * from './${subFolder}${name}.${isBase ? 'base-' : ''}${type}';`, true));
364
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, indexSourceFile, indexFilePath, `export * from './${subFolder}${name}.${isBase ? 'base-' : ''}${type}';`, true));
364
365
  }
365
366
  }
366
- (0, xplat_1.insert)(host, indexFilePath, changes);
367
+ // insert(devKitTree.tree, indexFilePath, changes);
367
368
  }
368
369
  else {
369
370
  options.needsIndex = true;
370
371
  }
371
- return host;
372
+ return devKitTree.tree;
372
373
  };
373
374
  }
374
375
  exports.adjustBarrelIndex = adjustBarrelIndex;
375
376
  function adjustBarrelIndexForType(type, options, indexFilePath) {
376
- return (host) => {
377
+ return (host, context) => {
378
+ const devKitTree = (0, xplat_1.convertNgTreeToDevKit)(host, context);
377
379
  if (host.exists(indexFilePath)) {
378
380
  const indexSource = host.read(indexFilePath).toString('utf-8');
379
381
  const indexSourceFile = ts.createSourceFile(indexFilePath, indexSource, ts.ScriptTarget.Latest, true);
380
382
  const changes = [];
381
- changes.push(...(0, xplat_1.addGlobal)(indexSourceFile, indexFilePath, `export * from './${type}';`, true));
382
- (0, xplat_1.insert)(host, indexFilePath, changes);
383
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, indexSourceFile, indexFilePath, `export * from './${type}';`, true));
384
+ // insert(devKitTree.tree, indexFilePath, changes);
383
385
  }
384
386
  else {
385
387
  options.needsIndex = true;
386
388
  }
387
- return host;
389
+ return devKitTree.tree;
388
390
  };
389
391
  }
390
392
  exports.adjustBarrelIndexForType = adjustBarrelIndexForType;
@@ -413,11 +415,12 @@ function adjustModule(tree, type, options, prefixPath) {
413
415
  }
414
416
  exports.adjustModule = adjustModule;
415
417
  function adjustFeatureModule(type, options, modulePath) {
416
- return (host) => {
418
+ return (host, context) => {
419
+ const devKitTree = (0, xplat_1.convertNgTreeToDevKit)(host, context);
417
420
  // console.log('adjustFeatureModule:', modulePath);
418
421
  if (host.exists(modulePath)) {
419
422
  const moduleSource = host.read(modulePath).toString('utf-8');
420
- const moduleSourceFile = ts.createSourceFile(modulePath, moduleSource, ts.ScriptTarget.Latest, true);
423
+ const moduleSourceFile = (0, ast_1.getTsSourceFile)(devKitTree, modulePath);
421
424
  const changes = [];
422
425
  let featureName;
423
426
  if (options.feature) {
@@ -463,18 +466,19 @@ function adjustFeatureModule(type, options, modulePath) {
463
466
  else {
464
467
  if (type !== 'service') {
465
468
  // add to module
466
- changes.push(...(0, xplat_1.addGlobal)(moduleSourceFile, modulePath, `import { ${collectionName} } from './${type}s';`));
467
- changes.push(...(0, ast_1.addDeclarationToModule)(moduleSourceFile, modulePath, `...${collectionName}`), ...(0, ast_1.addSymbolToNgModuleMetadata)(moduleSourceFile, modulePath, 'exports', `...${collectionName}`));
469
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, moduleSourceFile, modulePath, `import { ${collectionName} } from './${type}s';`));
470
+ changes.push((0, ast_1.addDeclarationToModule)(devKitTree, moduleSourceFile, modulePath, `...${collectionName}`), (0, ast_1._addSymbolToNgModuleMetadata)(devKitTree, moduleSourceFile, modulePath, 'exports', `...${collectionName}`));
468
471
  }
469
- (0, xplat_1.insert)(host, modulePath, changes);
472
+ // insert(devKitTree.tree, modulePath, changes);
470
473
  }
471
474
  }
472
- return host;
475
+ return devKitTree.tree;
473
476
  };
474
477
  }
475
478
  exports.adjustFeatureModule = adjustFeatureModule;
476
479
  function adjustFeatureModuleForState(options, modulePath) {
477
- return (host) => {
480
+ return (host, context) => {
481
+ const devKitTree = (0, xplat_1.convertNgTreeToDevKit)(host, context);
478
482
  // console.log('adjustFeatureModuleForState:', modulePath);
479
483
  if (host.exists(modulePath)) {
480
484
  const moduleSource = host.read(modulePath).toString('utf-8');
@@ -484,38 +488,39 @@ function adjustFeatureModuleForState(options, modulePath) {
484
488
  const name = options.name.toLowerCase();
485
489
  const changes = [];
486
490
  if (moduleSource.indexOf('StoreModule') === -1) {
487
- changes.push(...(0, xplat_1.addGlobal)(moduleSourceFile, modulePath, `import { StoreModule } from '@ngrx/store';`));
491
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, moduleSourceFile, modulePath, `import { StoreModule } from '@ngrx/store';`));
488
492
  }
489
493
  if (moduleSource.indexOf('EffectsModule') === -1) {
490
- changes.push(...(0, xplat_1.addGlobal)(moduleSourceFile, modulePath, `import { EffectsModule } from '@ngrx/effects';`));
494
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, moduleSourceFile, modulePath, `import { EffectsModule } from '@ngrx/effects';`));
491
495
  }
492
- changes.push(...(0, xplat_1.addGlobal)(moduleSourceFile, modulePath, `import { ${xplat_1.stringUtils.classify(name)}Effects } from './state/${name}.effects';`), ...(0, xplat_1.addGlobal)(moduleSourceFile, modulePath, `import { ${xplat_1.stringUtils.camelize(name)}Reducer } from './state/${name}.reducer';`), ...(0, xplat_1.addGlobal)(moduleSourceFile, modulePath, `import { ${xplat_1.stringUtils.classify(name)}State } from './state/${name}.state';`));
496
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, moduleSourceFile, modulePath, `import { ${xplat_1.stringUtils.classify(name)}Effects } from './state/${name}.effects';`), ...(0, xplat_1.addGlobal)(devKitTree, moduleSourceFile, modulePath, `import { ${xplat_1.stringUtils.camelize(name)}Reducer } from './state/${name}.reducer';`), ...(0, xplat_1.addGlobal)(devKitTree, moduleSourceFile, modulePath, `import { ${xplat_1.stringUtils.classify(name)}State } from './state/${name}.state';`));
493
497
  if (options.root) {
494
498
  if (moduleSource.indexOf('environments/environment') === -1) {
495
499
  const envFrom = isInLibs
496
500
  ? './environments/environment'
497
501
  : `@${(0, xplat_utils_1.getNpmScope)()}/xplat/core`;
498
- changes.push(...(0, xplat_1.addGlobal)(moduleSourceFile, modulePath, `import { environment } from '${envFrom}';`));
502
+ changes.push(...(0, xplat_1.addGlobal)(devKitTree, moduleSourceFile, modulePath, `import { environment } from '${envFrom}';`));
499
503
  }
500
- changes.push(...(0, ast_1.addImportToModule)(moduleSourceFile, modulePath, `StoreModule.forRoot(
504
+ changes.push((0, ast_1.addImportToModule)(devKitTree, moduleSourceFile, modulePath, `StoreModule.forRoot(
501
505
  { ${xplat_1.stringUtils.camelize(name)}: ${xplat_1.stringUtils.camelize(name)}Reducer },
502
506
  {
503
507
  initialState: { ${xplat_1.stringUtils.camelize(name)}: ${xplat_1.stringUtils.classify(name)}State.initialState }
504
508
  }
505
- ), EffectsModule.forRoot([${xplat_1.stringUtils.classify(name)}Effects])`), ...(0, ast_1.addProviderToModule)(moduleSourceFile, modulePath, `${xplat_1.stringUtils.classify(name)}Effects`));
509
+ ), EffectsModule.forRoot([${xplat_1.stringUtils.classify(name)}Effects])`), (0, ast_1.addProviderToModule)(devKitTree, moduleSourceFile, modulePath, `${xplat_1.stringUtils.classify(name)}Effects`));
506
510
  }
507
511
  else {
508
512
  // feature state
509
- changes.push(...(0, ast_1.addImportToModule)(moduleSourceFile, modulePath, `StoreModule.forFeature('${xplat_1.stringUtils.camelize(name)}', ${xplat_1.stringUtils.camelize(name)}Reducer, { initialState: ${xplat_1.stringUtils.classify(name)}State.initialState }), EffectsModule.forFeature([${xplat_1.stringUtils.classify(name)}Effects])`), ...(0, ast_1.addProviderToModule)(moduleSourceFile, modulePath, `${xplat_1.stringUtils.classify(name)}Effects`));
513
+ changes.push((0, ast_1.addImportToModule)(devKitTree, moduleSourceFile, modulePath, `StoreModule.forFeature('${xplat_1.stringUtils.camelize(name)}', ${xplat_1.stringUtils.camelize(name)}Reducer, { initialState: ${xplat_1.stringUtils.classify(name)}State.initialState }), EffectsModule.forFeature([${xplat_1.stringUtils.classify(name)}Effects])`), (0, ast_1.addProviderToModule)(devKitTree, moduleSourceFile, modulePath, `${xplat_1.stringUtils.classify(name)}Effects`));
510
514
  }
511
- (0, xplat_1.insert)(host, modulePath, changes);
515
+ // insert(devKitTree.tree, modulePath, changes);
512
516
  }
513
- return host;
517
+ return devKitTree.tree;
514
518
  };
515
519
  }
516
520
  exports.adjustFeatureModuleForState = adjustFeatureModuleForState;
517
521
  function adjustRouting(options, routingModulePaths, platform) {
518
- return (host) => {
522
+ return (host, context) => {
523
+ const devKitTree = (0, xplat_1.convertNgTreeToDevKit)(host, context);
519
524
  const featureName = options.name.toLowerCase();
520
525
  let routingModulePath;
521
526
  // check which routing naming convention might be in use
@@ -533,13 +538,13 @@ function adjustRouting(options, routingModulePaths, platform) {
533
538
  const routingSourceFile = ts.createSourceFile(routingModulePath, routingSource, ts.ScriptTarget.Latest, true);
534
539
  const changes = [];
535
540
  // add component to route config
536
- changes.push(...(0, ast_1.addToCollection)(routingSourceFile, routingModulePath, `{
541
+ changes.push(...(0, ast_1.addToCollection)(devKitTree, routingSourceFile, routingModulePath, `{
537
542
  path: '${featureName}',
538
543
  loadChildren: () => import('./features/${options.directory ? options.directory + '/' : ''}${featureName}/${featureName}.module').then(m => m.${xplat_1.stringUtils.classify(featureName)}Module)
539
544
  }`));
540
- (0, xplat_1.insert)(host, routingModulePath, changes);
545
+ // insert(devKitTree.tree, routingModulePath, changes);
541
546
  }
542
- return host;
547
+ return devKitTree.tree;
543
548
  };
544
549
  }
545
550
  exports.adjustRouting = adjustRouting;
@@ -589,7 +594,7 @@ function adjustSandbox(options, platform, appDirectory) {
589
594
  homeTemplate.slice(buttonEndIndex + 9);
590
595
  break;
591
596
  }
592
- (0, workspace_1.createOrUpdate)(tree, homeCmpPath, homeTemplate);
597
+ (0, xplat_utils_1.updateFile)(tree, homeCmpPath, homeTemplate);
593
598
  }
594
599
  else {
595
600
  throw new schematics_1.SchematicsException(`The --adjustSandbox option is only supported on the following at the moment: ${xplat_1.supportedSandboxPlatforms}`);
@@ -4,8 +4,7 @@ export declare const angularVersion = "^15.0.0";
4
4
  export declare const angularDevkitVersion = "^15.0.0";
5
5
  export declare const ngxTranslateVersion = "~14.0.0";
6
6
  export declare const ngxTranslateHttpVersion = "~7.0.0";
7
- export declare const coreJsVersion = "^3.6.5";
8
7
  export declare const rxjsVersion = "^7.5.0";
9
- export declare const zonejsVersion = "~0.12.0";
10
- export declare const jestPresetAngular = "11.0.0";
8
+ export declare const zonejsVersion = "~0.13.0";
9
+ export declare const jestPresetAngular = "~13.0.0";
11
10
  export declare const typesJest = "29.4.0";
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typesJest = exports.jestPresetAngular = exports.zonejsVersion = exports.rxjsVersion = exports.coreJsVersion = exports.ngxTranslateHttpVersion = exports.ngxTranslateVersion = exports.angularDevkitVersion = exports.angularVersion = exports.nxVersion = exports.xplatVersion = void 0;
4
- exports.xplatVersion = '15.0.3';
3
+ exports.typesJest = exports.jestPresetAngular = exports.zonejsVersion = exports.rxjsVersion = exports.ngxTranslateHttpVersion = exports.ngxTranslateVersion = exports.angularDevkitVersion = exports.angularVersion = exports.nxVersion = exports.xplatVersion = void 0;
4
+ exports.xplatVersion = '15.0.4-rc.0';
5
5
  exports.nxVersion = '^15.0.0';
6
6
  exports.angularVersion = '^15.0.0';
7
7
  exports.angularDevkitVersion = '^15.0.0';
8
8
  exports.ngxTranslateVersion = '~14.0.0';
9
9
  exports.ngxTranslateHttpVersion = '~7.0.0';
10
- exports.coreJsVersion = '^3.6.5';
11
10
  exports.rxjsVersion = '^7.5.0';
12
- exports.zonejsVersion = '~0.12.0';
13
- exports.jestPresetAngular = '11.0.0';
11
+ exports.zonejsVersion = '~0.13.0';
12
+ exports.jestPresetAngular = '~13.0.0';
14
13
  exports.typesJest = '29.4.0';
@@ -100,8 +100,9 @@ var XplatAngularHelpers;
100
100
  dependencies[`@angular/platform-browser`] = ngVersion;
101
101
  dependencies[`@angular/platform-browser-dynamic`] = ngVersion;
102
102
  dependencies[`@angular/router`] = ngVersion;
103
- dependencies[`core-js`] = versions_1.coreJsVersion;
104
- dependencies[`rxjs`] = versions_1.rxjsVersion;
103
+ if (!dependencies[`rxjs`]) {
104
+ dependencies[`rxjs`] = versions_1.rxjsVersion;
105
+ }
105
106
  dependencies[`zone.js`] = versions_1.zonejsVersion;
106
107
  devDependencies[`@angular/compiler-cli`] = ngVersion;
107
108
  devDependencies[`@angular/language-service`] = ngVersion;