@schematics/angular 14.0.0-next.6 → 14.0.0-next.9

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.
@@ -198,9 +198,6 @@ function addAppToWorkspaceFile(options, appDir, folderName) {
198
198
  },
199
199
  };
200
200
  return (0, workspace_1.updateWorkspace)((workspace) => {
201
- if (workspace.projects.size === 0) {
202
- workspace.extensions.defaultProject = options.name;
203
- }
204
201
  workspace.projects.add({
205
202
  name: options.name,
206
203
  ...project,
@@ -234,7 +231,7 @@ function default_1(options) {
234
231
  const newProjectRoot = workspace.extensions.newProjectRoot || '';
235
232
  const isRootApp = options.projectRoot !== undefined;
236
233
  // If scoped project (i.e. "@foo/bar"), convert dir to "foo/bar".
237
- let folderName = options.name.startsWith('@') ? options.name.substr(1) : options.name;
234
+ let folderName = options.name.startsWith('@') ? options.name.slice(1) : options.name;
238
235
  if (/[A-Z]/.test(folderName)) {
239
236
  folderName = core_1.strings.dasherize(folderName);
240
237
  }
@@ -11,9 +11,7 @@ describe('<%= classify(name) %><%= classify(type) %>', () => {
11
11
  declarations: [ <%= classify(name) %><%= classify(type) %> ]
12
12
  })
13
13
  .compileComponents();
14
- });
15
14
 
16
- beforeEach(() => {
17
15
  fixture = TestBed.createComponent(<%= classify(name) %><%= classify(type) %>);
18
16
  component = fixture.componentInstance;
19
17
  fixture.detectChanges();
@@ -6,15 +6,15 @@ import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }
6
6
  <p>
7
7
  <%= dasherize(name) %> works!
8
8
  </p>
9
- `,<% } else { %>
10
- templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.html',<% } if(inlineStyle) { %>
9
+ `<% } else { %>
10
+ templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.html'<% } if(inlineStyle) { %>,
11
11
  styles: [<% if(displayBlock){ %>
12
12
  `
13
13
  :host {
14
14
  display: block;
15
15
  }
16
16
  `<% } %>
17
- ]<% } else if (style !== 'none') { %>
17
+ ]<% } else if (style !== 'none') { %>,
18
18
  styleUrls: ['./<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
19
19
  encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
20
20
  changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
package/library/index.js CHANGED
@@ -61,9 +61,6 @@ function addDependenciesToPackageJson() {
61
61
  }
62
62
  function addLibToWorkspaceFile(options, projectRoot, projectName) {
63
63
  return (0, workspace_1.updateWorkspace)((workspace) => {
64
- if (workspace.projects.size === 0) {
65
- workspace.extensions.defaultProject = projectName;
66
- }
67
64
  workspace.projects.add({
68
65
  name: projectName,
69
66
  root: projectRoot,
@@ -109,7 +106,7 @@ function default_1(options) {
109
106
  }
110
107
  const workspace = await (0, workspace_1.getWorkspace)(host);
111
108
  const newProjectRoot = workspace.extensions.newProjectRoot || '';
112
- let folderName = packageName.startsWith('@') ? packageName.substr(1) : packageName;
109
+ let folderName = packageName.startsWith('@') ? packageName.slice(1) : packageName;
113
110
  if (/[A-Z]/.test(folderName)) {
114
111
  folderName = core_1.strings.dasherize(folderName);
115
112
  }
@@ -14,6 +14,16 @@
14
14
  "version": "14.0.0",
15
15
  "factory": "./update-14/remove-show-circular-dependencies-option",
16
16
  "description": "Remove 'showCircularDependencies' option from browser and server builders."
17
+ },
18
+ "remove-default-project-option": {
19
+ "version": "14.0.0",
20
+ "factory": "./update-14/remove-default-project-option",
21
+ "description": "Remove 'defaultProject' option from workspace configuration. The project to use will be determined from the current working directory."
22
+ },
23
+ "replace-default-collection-option": {
24
+ "version": "14.0.0",
25
+ "factory": "./update-14/replace-default-collection-option",
26
+ "description": "Replace 'defaultCollection' option in workspace configuration with 'schematicCollections'."
17
27
  }
18
28
  }
19
29
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Rule } from '@angular-devkit/schematics';
9
+ /** Migration to remove 'defaultProject' option from angular.json. */
10
+ export default function (): Rule;
@@ -0,0 +1,17 @@
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
+ const workspace_1 = require("../../utility/workspace");
11
+ /** Migration to remove 'defaultProject' option from angular.json. */
12
+ function default_1() {
13
+ return (0, workspace_1.updateWorkspace)((workspace) => {
14
+ delete workspace.extensions['defaultProject'];
15
+ });
16
+ }
17
+ exports.default = default_1;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Rule } from '@angular-devkit/schematics';
9
+ /** Migration to replace 'defaultCollection' option in angular.json. */
10
+ export default function (): Rule;
@@ -0,0 +1,32 @@
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
+ const core_1 = require("@angular-devkit/core");
11
+ const workspace_1 = require("../../utility/workspace");
12
+ /** Migration to replace 'defaultCollection' option in angular.json. */
13
+ function default_1() {
14
+ return (0, workspace_1.updateWorkspace)((workspace) => {
15
+ // workspace level
16
+ replaceDefaultCollection(workspace.extensions['cli']);
17
+ // Project level
18
+ for (const project of workspace.projects.values()) {
19
+ replaceDefaultCollection(project.extensions['cli']);
20
+ }
21
+ });
22
+ }
23
+ exports.default = default_1;
24
+ function replaceDefaultCollection(cliExtension) {
25
+ if (cliExtension && (0, core_1.isJsonObject)(cliExtension) && cliExtension['defaultCollection']) {
26
+ // If `schematicsCollection` defined `defaultCollection` is ignored hence no need to warn.
27
+ if (!cliExtension['schematicCollections']) {
28
+ cliExtension['schematicCollections'] = [cliExtension['defaultCollection']];
29
+ }
30
+ delete cliExtension['defaultCollection'];
31
+ }
32
+ }
package/ng-new/index.js CHANGED
@@ -12,7 +12,7 @@ const tasks_1 = require("@angular-devkit/schematics/tasks");
12
12
  function default_1(options) {
13
13
  if (!options.directory) {
14
14
  // If scoped project (i.e. "@foo/bar"), convert directory to "foo/bar".
15
- options.directory = options.name.startsWith('@') ? options.name.substr(1) : options.name;
15
+ options.directory = options.name.startsWith('@') ? options.name.slice(1) : options.name;
16
16
  }
17
17
  const workspaceOptions = {
18
18
  name: options.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematics/angular",
3
- "version": "14.0.0-next.6",
3
+ "version": "14.0.0-next.9",
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.6",
19
- "@angular-devkit/schematics": "14.0.0-next.6",
18
+ "@angular-devkit/core": "14.0.0-next.9",
19
+ "@angular-devkit/schematics": "14.0.0-next.9",
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;
@@ -3,9 +3,9 @@
3
3
  "comment": "This file is needed so that depedencies are synced by Renovate.",
4
4
  "private": true,
5
5
  "dependencies": {
6
- "@types/jasmine": "~3.10.0",
6
+ "@types/jasmine": "~4.0.0",
7
7
  "@types/node": "^14.15.0",
8
- "jasmine-core": "~4.0.0",
8
+ "jasmine-core": "~4.1.0",
9
9
  "karma-chrome-launcher": "~3.1.0",
10
10
  "karma-coverage": "~2.2.0",
11
11
  "karma-jasmine-html-reporter": "~1.7.0",
@@ -110,12 +110,15 @@ export declare type TestBuilderTarget = BuilderTarget<Builders.Karma, TestBuilde
110
110
  export declare type ServeBuilderTarget = BuilderTarget<Builders.DevServer, ServeBuilderOptions>;
111
111
  export declare type ExtractI18nBuilderTarget = BuilderTarget<Builders.ExtractI18n, ExtractI18nOptions>;
112
112
  export declare type E2EBuilderTarget = BuilderTarget<Builders.Protractor, E2EOptions>;
113
+ interface WorkspaceCLISchema {
114
+ warnings?: Record<string, boolean>;
115
+ schematicCollections?: string[];
116
+ defaultCollection?: string;
117
+ }
113
118
  export interface WorkspaceSchema {
114
119
  version: 1;
115
120
  defaultProject?: string;
116
- cli?: {
117
- warnings?: Record<string, boolean>;
118
- };
121
+ cli?: WorkspaceCLISchema;
119
122
  projects: {
120
123
  [key: string]: WorkspaceProject<ProjectType.Application | ProjectType.Library>;
121
124
  };
@@ -128,9 +131,7 @@ export interface WorkspaceProject<TProjectType extends ProjectType = ProjectType
128
131
  root: string;
129
132
  sourceRoot: string;
130
133
  prefix: string;
131
- cli?: {
132
- warnings?: Record<string, boolean>;
133
- };
134
+ cli?: WorkspaceCLISchema;
134
135
  /**
135
136
  * Tool options.
136
137
  */
@@ -150,3 +151,4 @@ export interface WorkspaceTargets<TProjectType extends ProjectType = ProjectType
150
151
  'extract-i18n'?: ExtractI18nBuilderTarget;
151
152
  [key: string]: any;
152
153
  }
154
+ export {};