@schematics/angular 14.0.0-next.7 → 14.0.0-next.8

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": "@schematics/angular",
3
- "version": "14.0.0-next.7",
3
+ "version": "14.0.0-next.8",
4
4
  "description": "Schematics specific to Angular",
5
5
  "homepage": "https://github.com/angular/angular-cli",
6
6
  "keywords": [
@@ -15,8 +15,8 @@
15
15
  ],
16
16
  "schematics": "./collection.json",
17
17
  "dependencies": {
18
- "@angular-devkit/core": "14.0.0-next.7",
19
- "@angular-devkit/schematics": "14.0.0-next.7",
18
+ "@angular-devkit/core": "14.0.0-next.8",
19
+ "@angular-devkit/schematics": "14.0.0-next.8",
20
20
  "jsonc-parser": "3.0.0"
21
21
  },
22
22
  "repository": {
@@ -144,7 +144,6 @@ function getSourceNodes(sourceFile) {
144
144
  exports.getSourceNodes = getSourceNodes;
145
145
  function findNode(node, kind, text) {
146
146
  if (node.kind === kind && node.getText() === text) {
147
- // throw new Error(node.getText());
148
147
  return node;
149
148
  }
150
149
  let foundNode = null;
@@ -284,27 +283,26 @@ function getMetadataField(node, metadataField) {
284
283
  exports.getMetadataField = getMetadataField;
285
284
  function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath = null) {
286
285
  const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
287
- let node = nodes[0]; // eslint-disable-line @typescript-eslint/no-explicit-any
286
+ const node = nodes[0];
288
287
  // Find the decorator declaration.
289
- if (!node) {
288
+ if (!node || !ts.isObjectLiteralExpression(node)) {
290
289
  return [];
291
290
  }
292
291
  // Get all the children property assignment of object literals.
293
292
  const matchingProperties = getMetadataField(node, metadataField);
294
293
  if (matchingProperties.length == 0) {
295
294
  // We haven't found the field in the metadata declaration. Insert a new field.
296
- const expr = node;
297
295
  let position;
298
296
  let toInsert;
299
- if (expr.properties.length == 0) {
300
- position = expr.getEnd() - 1;
297
+ if (node.properties.length == 0) {
298
+ position = node.getEnd() - 1;
301
299
  toInsert = `\n ${metadataField}: [\n${core_1.tags.indentBy(4) `${symbolName}`}\n ]\n`;
302
300
  }
303
301
  else {
304
- node = expr.properties[expr.properties.length - 1];
305
- position = node.getEnd();
302
+ const childNode = node.properties[node.properties.length - 1];
303
+ position = childNode.getEnd();
306
304
  // Get the indentation of the last element, if any.
307
- const text = node.getFullText(source);
305
+ const text = childNode.getFullText(source);
308
306
  const matches = text.match(/^(\r?\n)(\s*)/);
309
307
  if (matches) {
310
308
  toInsert =
@@ -327,35 +325,33 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbol
327
325
  }
328
326
  const assignment = matchingProperties[0];
329
327
  // If it's not an array, nothing we can do really.
330
- if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
328
+ if (!ts.isPropertyAssignment(assignment) ||
329
+ !ts.isArrayLiteralExpression(assignment.initializer)) {
331
330
  return [];
332
331
  }
333
- const arrLiteral = assignment.initializer;
334
- if (arrLiteral.elements.length == 0) {
335
- // Forward the property.
336
- node = arrLiteral;
337
- }
338
- else {
339
- node = arrLiteral.elements;
340
- }
341
- if (Array.isArray(node)) {
342
- const nodeArray = node;
343
- const symbolsArray = nodeArray.map((node) => core_1.tags.oneLine `${node.getText()}`);
332
+ let expresssion;
333
+ const assignmentInit = assignment.initializer;
334
+ const elements = assignmentInit.elements;
335
+ if (elements.length) {
336
+ const symbolsArray = elements.map((node) => core_1.tags.oneLine `${node.getText()}`);
344
337
  if (symbolsArray.includes(core_1.tags.oneLine `${symbolName}`)) {
345
338
  return [];
346
339
  }
347
- node = node[node.length - 1];
340
+ expresssion = elements[elements.length - 1];
341
+ }
342
+ else {
343
+ expresssion = assignmentInit;
348
344
  }
349
345
  let toInsert;
350
- let position = node.getEnd();
351
- if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
346
+ let position = expresssion.getEnd();
347
+ if (ts.isArrayLiteralExpression(expresssion)) {
352
348
  // We found the field but it's empty. Insert it just before the `]`.
353
349
  position--;
354
350
  toInsert = `\n${core_1.tags.indentBy(4) `${symbolName}`}\n `;
355
351
  }
356
352
  else {
357
353
  // Get the indentation of the last element, if any.
358
- const text = node.getFullText(source);
354
+ const text = expresssion.getFullText(source);
359
355
  const matches = text.match(/^(\r?\n)(\s*)/);
360
356
  if (matches) {
361
357
  toInsert = `,${matches[1]}${core_1.tags.indentBy(matches[2].length) `${symbolName}`}`;
@@ -470,6 +466,9 @@ exports.getEnvironmentExportName = getEnvironmentExportName;
470
466
  function getRouterModuleDeclaration(source) {
471
467
  const result = getDecoratorMetadata(source, 'NgModule', '@angular/core');
472
468
  const node = result[0];
469
+ if (!node || !ts.isObjectLiteralExpression(node)) {
470
+ return undefined;
471
+ }
473
472
  const matchingProperties = getMetadataField(node, 'imports');
474
473
  if (!matchingProperties) {
475
474
  return;
@@ -490,7 +489,8 @@ exports.getRouterModuleDeclaration = getRouterModuleDeclaration;
490
489
  function addRouteDeclarationToModule(source, fileToAdd, routeLiteral) {
491
490
  const routerModuleExpr = getRouterModuleDeclaration(source);
492
491
  if (!routerModuleExpr) {
493
- throw new Error(`Couldn't find a route declaration in ${fileToAdd}.`);
492
+ throw new Error(`Couldn't find a route declaration in ${fileToAdd}.\n` +
493
+ `Use the '--module' option to specify a different routing module.`);
494
494
  }
495
495
  const scopeConfigMethodArgs = routerModuleExpr.arguments;
496
496
  if (!scopeConfigMethodArgs.length) {
@@ -38,11 +38,7 @@ function findModuleFromOptions(host, options) {
38
38
  }
39
39
  const candidatesDirs = [...candidateSet].sort((a, b) => b.length - a.length);
40
40
  for (const c of candidatesDirs) {
41
- const candidateFiles = [
42
- '',
43
- `${moduleBaseName}.ts`,
44
- `${moduleBaseName}${moduleExt}`,
45
- ].map((x) => (0, core_1.join)(c, x));
41
+ const candidateFiles = ['', `${moduleBaseName}.ts`, `${moduleBaseName}${moduleExt}`].map((x) => (0, core_1.join)(c, x));
46
42
  for (const sc of candidateFiles) {
47
43
  if (host.exists(sc)) {
48
44
  return (0, core_1.normalize)(sc);
@@ -68,7 +64,7 @@ function findModule(host, generateDir, moduleExt = exports.MODULE_EXT, routingMo
68
64
  return (0, core_1.join)(dir.path, filteredMatches[0]);
69
65
  }
70
66
  else if (filteredMatches.length > 1) {
71
- throw new Error('More than one module matches. Use the skip-import option to skip importing ' +
67
+ throw new Error(`More than one module matches. Use the '--skip-import' option to skip importing ` +
72
68
  'the component into the closest module or use the module option to specify a module.');
73
69
  }
74
70
  dir = dir.parent;
@@ -76,8 +72,8 @@ function findModule(host, generateDir, moduleExt = exports.MODULE_EXT, routingMo
76
72
  const errorMsg = foundRoutingModule
77
73
  ? 'Could not find a non Routing NgModule.' +
78
74
  `\nModules with suffix '${routingModuleExt}' are strictly reserved for routing.` +
79
- '\nUse the skip-import option to skip importing in NgModule.'
80
- : 'Could not find an NgModule. Use the skip-import option to skip importing in NgModule.';
75
+ `\nUse the '--skip-import' option to skip importing in NgModule.`
76
+ : `Could not find an NgModule. Use the '--skip-import' option to skip importing in NgModule.`;
81
77
  throw new Error(errorMsg);
82
78
  }
83
79
  exports.findModule = findModule;