@schematics/angular 14.0.0-next.8 → 14.0.0-rc.1

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 (48) hide show
  1. package/app-shell/index.js +4 -8
  2. package/application/files/src/test.ts.template +1 -1
  3. package/application/index.js +3 -3
  4. package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template +1 -1
  5. package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +5 -2
  6. package/component/index.js +9 -14
  7. package/component/schema.d.ts +4 -0
  8. package/component/schema.json +6 -0
  9. package/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template +2 -1
  10. package/directive/index.js +9 -18
  11. package/directive/schema.d.ts +4 -0
  12. package/directive/schema.json +6 -0
  13. package/e2e/index.js +5 -5
  14. package/library/files/src/test.ts.template +1 -1
  15. package/library/index.js +3 -4
  16. package/migrations/migration-collection.json +5 -0
  17. package/migrations/update-14/update-libraries-secondary-entrypoints.d.ts +10 -0
  18. package/migrations/update-14/update-libraries-secondary-entrypoints.js +51 -0
  19. package/module/index.js +8 -16
  20. package/package.json +10 -3
  21. package/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template +2 -1
  22. package/pipe/index.js +8 -17
  23. package/pipe/schema.d.ts +4 -0
  24. package/pipe/schema.json +6 -0
  25. package/service-worker/index.js +4 -8
  26. package/third_party/github.com/Microsoft/TypeScript/BUILD.bazel +4 -4
  27. package/third_party/github.com/Microsoft/TypeScript/lib/typescript.d.ts +402 -295
  28. package/third_party/github.com/Microsoft/TypeScript/lib/typescript.js +23175 -20442
  29. package/universal/index.js +3 -7
  30. package/utility/dependency.d.ts +45 -0
  31. package/utility/dependency.js +97 -0
  32. package/utility/find-module.d.ts +1 -0
  33. package/utility/find-module.js +1 -2
  34. package/utility/generate-from-files.js +2 -3
  35. package/utility/index.d.ts +10 -0
  36. package/utility/index.js +21 -0
  37. package/utility/json-file.js +1 -7
  38. package/utility/latest-versions/package.json +4 -3
  39. package/utility/latest-versions.js +1 -1
  40. package/utility/ng-ast-utils.js +2 -10
  41. package/utility/parse-name.js +0 -1
  42. package/utility/validation.js +1 -3
  43. package/utility/workspace-models.d.ts +6 -0
  44. package/utility/workspace-models.js +6 -0
  45. package/utility/workspace.d.ts +36 -3
  46. package/utility/workspace.js +70 -34
  47. package/web-worker/index.js +2 -2
  48. package/workspace/index.js +1 -2
@@ -40,11 +40,7 @@ const project_targets_1 = require("../utility/project-targets");
40
40
  const workspace_1 = require("../utility/workspace");
41
41
  const workspace_models_1 = require("../utility/workspace-models");
42
42
  function getSourceFile(host, path) {
43
- const buffer = host.read(path);
44
- if (!buffer) {
45
- throw new schematics_1.SchematicsException(`Could not find ${path}.`);
46
- }
47
- const content = buffer.toString();
43
+ const content = host.readText(path);
48
44
  const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
49
45
  return source;
50
46
  }
@@ -76,10 +72,10 @@ function getComponentTemplate(host, compPath, tmplInfo) {
76
72
  const templateUrl = tmplInfo.templateUrlProp.initializer.text;
77
73
  const dir = (0, core_1.dirname)((0, core_1.normalize)(compPath));
78
74
  const templatePath = (0, core_1.join)(dir, templateUrl);
79
- const buffer = host.read(templatePath);
80
- if (buffer) {
81
- template = buffer.toString();
75
+ try {
76
+ template = host.readText(templatePath);
82
77
  }
78
+ catch { }
83
79
  }
84
80
  return template;
85
81
  }
@@ -23,4 +23,4 @@ getTestBed().initTestEnvironment(
23
23
  // Then we find all the tests.
24
24
  const context = require.context('./', true, /\.spec\.ts$/);
25
25
  // And load the modules.
26
- context.keys().map(context);
26
+ context.keys().forEach(context);
@@ -233,7 +233,7 @@ function default_1(options) {
233
233
  // If scoped project (i.e. "@foo/bar"), convert dir to "foo/bar".
234
234
  let folderName = options.name.startsWith('@') ? options.name.slice(1) : options.name;
235
235
  if (/[A-Z]/.test(folderName)) {
236
- folderName = core_1.strings.dasherize(folderName);
236
+ folderName = schematics_1.strings.dasherize(folderName);
237
237
  }
238
238
  const appDir = isRootApp
239
239
  ? (0, core_1.normalize)(options.projectRoot || '')
@@ -244,7 +244,7 @@ function default_1(options) {
244
244
  (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
245
245
  options.minimal ? (0, schematics_1.filter)(minimalPathFilter) : (0, schematics_1.noop)(),
246
246
  (0, schematics_1.applyTemplates)({
247
- utils: core_1.strings,
247
+ utils: schematics_1.strings,
248
248
  ...options,
249
249
  relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(appDir),
250
250
  appName: options.name,
@@ -280,7 +280,7 @@ function default_1(options) {
280
280
  ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template'))
281
281
  : (0, schematics_1.noop)(),
282
282
  (0, schematics_1.applyTemplates)({
283
- utils: core_1.strings,
283
+ utils: schematics_1.strings,
284
284
  ...options,
285
285
  selector: appRootSelector,
286
286
  ...componentOptions,
@@ -8,7 +8,7 @@ describe('<%= classify(name) %><%= classify(type) %>', () => {
8
8
 
9
9
  beforeEach(async () => {
10
10
  await TestBed.configureTestingModule({
11
- declarations: [ <%= classify(name) %><%= classify(type) %> ]
11
+ <%= standalone ? 'imports' : 'declarations' %>: [ <%= classify(name) %><%= classify(type) %> ]
12
12
  })
13
13
  .compileComponents();
14
14
 
@@ -1,7 +1,10 @@
1
- import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';
1
+ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';<% if(standalone) {%>
2
+ import { CommonModule } from '@angular/common';<% } %>
2
3
 
3
4
  @Component({<% if(!skipSelector) {%>
4
- selector: '<%= selector %>',<%}%><% if(inlineTemplate) { %>
5
+ selector: '<%= selector %>',<%}%><% if(standalone) {%>
6
+ standalone: true,
7
+ imports: [CommonModule],<%}%><% if(inlineTemplate) { %>
5
8
  template: `
6
9
  <p>
7
10
  <%= dasherize(name) %> works!
@@ -30,7 +30,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- const core_1 = require("@angular-devkit/core");
34
33
  const schematics_1 = require("@angular-devkit/schematics");
35
34
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
36
35
  const ast_utils_1 = require("../utility/ast-utils");
@@ -41,28 +40,24 @@ const validation_1 = require("../utility/validation");
41
40
  const workspace_1 = require("../utility/workspace");
42
41
  const schema_1 = require("./schema");
43
42
  function readIntoSourceFile(host, modulePath) {
44
- const text = host.read(modulePath);
45
- if (text === null) {
46
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
47
- }
48
- const sourceText = text.toString('utf-8');
43
+ const sourceText = host.readText(modulePath);
49
44
  return ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
50
45
  }
51
46
  function addDeclarationToNgModule(options) {
52
47
  return (host) => {
53
- if (options.skipImport || !options.module) {
48
+ if (options.skipImport || options.standalone || !options.module) {
54
49
  return host;
55
50
  }
56
51
  options.type = options.type != null ? options.type : 'Component';
57
52
  const modulePath = options.module;
58
53
  const source = readIntoSourceFile(host, modulePath);
59
54
  const componentPath = `/${options.path}/` +
60
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
61
- core_1.strings.dasherize(options.name) +
55
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
56
+ schematics_1.strings.dasherize(options.name) +
62
57
  (options.type ? '.' : '') +
63
- core_1.strings.dasherize(options.type);
58
+ schematics_1.strings.dasherize(options.type);
64
59
  const relativePath = (0, find_module_1.buildRelativePath)(modulePath, componentPath);
65
- const classifiedName = core_1.strings.classify(options.name) + core_1.strings.classify(options.type);
60
+ const classifiedName = schematics_1.strings.classify(options.name) + schematics_1.strings.classify(options.type);
66
61
  const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath);
67
62
  const declarationRecorder = host.beginUpdate(modulePath);
68
63
  for (const change of declarationChanges) {
@@ -75,7 +70,7 @@ function addDeclarationToNgModule(options) {
75
70
  // Need to refresh the AST because we overwrote the file in the host.
76
71
  const source = readIntoSourceFile(host, modulePath);
77
72
  const exportRecorder = host.beginUpdate(modulePath);
78
- const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(options.name) + core_1.strings.classify(options.type), relativePath);
73
+ const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, schematics_1.strings.classify(options.name) + schematics_1.strings.classify(options.type), relativePath);
79
74
  for (const change of exportChanges) {
80
75
  if (change instanceof change_1.InsertChange) {
81
76
  exportRecorder.insertLeft(change.pos, change.toAdd);
@@ -87,7 +82,7 @@ function addDeclarationToNgModule(options) {
87
82
  };
88
83
  }
89
84
  function buildSelector(options, projectPrefix) {
90
- let selector = core_1.strings.dasherize(options.name);
85
+ let selector = schematics_1.strings.dasherize(options.name);
91
86
  if (options.prefix) {
92
87
  selector = `${options.prefix}-${selector}`;
93
88
  }
@@ -119,7 +114,7 @@ function default_1(options) {
119
114
  skipStyleFile ? (0, schematics_1.filter)((path) => !path.endsWith('.__style__.template')) : (0, schematics_1.noop)(),
120
115
  options.inlineTemplate ? (0, schematics_1.filter)((path) => !path.endsWith('.html.template')) : (0, schematics_1.noop)(),
121
116
  (0, schematics_1.applyTemplates)({
122
- ...core_1.strings,
117
+ ...schematics_1.strings,
123
118
  'if-flat': (s) => (options.flat ? '' : s),
124
119
  ...options,
125
120
  }),
@@ -65,6 +65,10 @@ export interface Schema {
65
65
  * Do not create "spec.ts" test files for the new component.
66
66
  */
67
67
  skipTests?: boolean;
68
+ /**
69
+ * Whether the generated component is standalone.
70
+ */
71
+ standalone?: boolean;
68
72
  /**
69
73
  * The file extension or preprocessor to use for style files, or 'none' to skip generating
70
74
  * the style file.
@@ -48,6 +48,12 @@
48
48
  "alias": "t",
49
49
  "x-user-analytics": 10
50
50
  },
51
+ "standalone": {
52
+ "description": "Whether the generated component is standalone.",
53
+ "type": "boolean",
54
+ "default": false,
55
+ "x-user-analytics": 15
56
+ },
51
57
  "viewEncapsulation": {
52
58
  "description": "The view encapsulation strategy to use in the new component.",
53
59
  "enum": ["Emulated", "None", "ShadowDom"],
@@ -1,7 +1,8 @@
1
1
  import { Directive } from '@angular/core';
2
2
 
3
3
  @Directive({
4
- selector: '[<%= selector %>]'
4
+ selector: '[<%= selector %>]'<% if(standalone) {%>,
5
+ standalone: true<%}%>
5
6
  })
6
7
  export class <%= classify(name) %>Directive {
7
8
 
@@ -30,7 +30,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- const core_1 = require("@angular-devkit/core");
34
33
  const schematics_1 = require("@angular-devkit/schematics");
35
34
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
36
35
  const ast_utils_1 = require("../utility/ast-utils");
@@ -41,22 +40,18 @@ const validation_1 = require("../utility/validation");
41
40
  const workspace_1 = require("../utility/workspace");
42
41
  function addDeclarationToNgModule(options) {
43
42
  return (host) => {
44
- if (options.skipImport || !options.module) {
43
+ if (options.skipImport || options.standalone || !options.module) {
45
44
  return host;
46
45
  }
47
46
  const modulePath = options.module;
48
- const text = host.read(modulePath);
49
- if (text === null) {
50
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
51
- }
52
- const sourceText = text.toString('utf-8');
47
+ const sourceText = host.readText(modulePath);
53
48
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
54
49
  const directivePath = `/${options.path}/` +
55
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
56
- core_1.strings.dasherize(options.name) +
50
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
51
+ schematics_1.strings.dasherize(options.name) +
57
52
  '.directive';
58
53
  const relativePath = (0, find_module_1.buildRelativePath)(modulePath, directivePath);
59
- const classifiedName = core_1.strings.classify(`${options.name}Directive`);
54
+ const classifiedName = schematics_1.strings.classify(`${options.name}Directive`);
60
55
  const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath);
61
56
  const declarationRecorder = host.beginUpdate(modulePath);
62
57
  for (const change of declarationChanges) {
@@ -67,14 +62,10 @@ function addDeclarationToNgModule(options) {
67
62
  host.commitUpdate(declarationRecorder);
68
63
  if (options.export) {
69
64
  // Need to refresh the AST because we overwrote the file in the host.
70
- const text = host.read(modulePath);
71
- if (text === null) {
72
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
73
- }
74
- const sourceText = text.toString('utf-8');
65
+ const sourceText = host.readText(modulePath);
75
66
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
76
67
  const exportRecorder = host.beginUpdate(modulePath);
77
- const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Directive`), relativePath);
68
+ const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Directive`), relativePath);
78
69
  for (const change of exportChanges) {
79
70
  if (change instanceof change_1.InsertChange) {
80
71
  exportRecorder.insertLeft(change.pos, change.toAdd);
@@ -93,7 +84,7 @@ function buildSelector(options, projectPrefix) {
93
84
  else if (options.prefix === undefined && projectPrefix) {
94
85
  selector = `${projectPrefix}-${selector}`;
95
86
  }
96
- return core_1.strings.camelize(selector);
87
+ return schematics_1.strings.camelize(selector);
97
88
  }
98
89
  function default_1(options) {
99
90
  return async (host) => {
@@ -114,7 +105,7 @@ function default_1(options) {
114
105
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
115
106
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
116
107
  (0, schematics_1.applyTemplates)({
117
- ...core_1.strings,
108
+ ...schematics_1.strings,
118
109
  'if-flat': (s) => (options.flat ? '' : s),
119
110
  ...options,
120
111
  }),
@@ -43,4 +43,8 @@ export interface Schema {
43
43
  * Do not create "spec.ts" test files for the new class.
44
44
  */
45
45
  skipTests?: boolean;
46
+ /**
47
+ * Whether the generated directive is standalone.
48
+ */
49
+ standalone?: boolean;
46
50
  }
@@ -59,6 +59,12 @@
59
59
  "format": "html-selector",
60
60
  "description": "The HTML selector to use for this directive."
61
61
  },
62
+ "standalone": {
63
+ "description": "Whether the generated directive is standalone.",
64
+ "type": "boolean",
65
+ "default": false,
66
+ "x-user-analytics": 15
67
+ },
62
68
  "flat": {
63
69
  "type": "boolean",
64
70
  "description": "When true (the default), creates the new files at the top level of the current project.",
package/e2e/index.js CHANGED
@@ -9,11 +9,11 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  const core_1 = require("@angular-devkit/core");
11
11
  const schematics_1 = require("@angular-devkit/schematics");
12
+ const utility_1 = require("../utility");
12
13
  const dependencies_1 = require("../utility/dependencies");
13
14
  const json_file_1 = require("../utility/json-file");
14
15
  const latest_versions_1 = require("../utility/latest-versions");
15
16
  const paths_1 = require("../utility/paths");
16
- const workspace_1 = require("../utility/workspace");
17
17
  const workspace_models_1 = require("../utility/workspace-models");
18
18
  function addScriptsToPackageJson() {
19
19
  return (host) => {
@@ -27,7 +27,7 @@ function addScriptsToPackageJson() {
27
27
  function default_1(options) {
28
28
  return async (host) => {
29
29
  const appProject = options.relatedAppName;
30
- const workspace = await (0, workspace_1.getWorkspace)(host);
30
+ const workspace = await (0, utility_1.readWorkspace)(host);
31
31
  const project = workspace.projects.get(appProject);
32
32
  if (!project) {
33
33
  throw new schematics_1.SchematicsException(`Project name "${appProject}" doesn't not exist.`);
@@ -49,11 +49,11 @@ function default_1(options) {
49
49
  },
50
50
  },
51
51
  });
52
+ await (0, utility_1.writeWorkspace)(host, workspace);
52
53
  return (0, schematics_1.chain)([
53
- (0, workspace_1.updateWorkspace)(workspace),
54
54
  (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
55
55
  (0, schematics_1.applyTemplates)({
56
- utils: core_1.strings,
56
+ utils: schematics_1.strings,
57
57
  ...options,
58
58
  relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(root),
59
59
  }),
@@ -73,7 +73,7 @@ function default_1(options) {
73
73
  {
74
74
  type: dependencies_1.NodeDependencyType.Dev,
75
75
  name: 'ts-node',
76
- version: '~9.1.1',
76
+ version: latest_versions_1.latestVersions['ts-node'],
77
77
  },
78
78
  {
79
79
  type: dependencies_1.NodeDependencyType.Dev,
@@ -24,4 +24,4 @@ getTestBed().initTestEnvironment(
24
24
  // Then we find all the tests.
25
25
  const context = require.context('./', true, /\.spec\.ts$/);
26
26
  // And load the modules.
27
- context.keys().map(context);
27
+ context.keys().forEach(context);
package/library/index.js CHANGED
@@ -108,15 +108,14 @@ function default_1(options) {
108
108
  const newProjectRoot = workspace.extensions.newProjectRoot || '';
109
109
  let folderName = packageName.startsWith('@') ? packageName.slice(1) : packageName;
110
110
  if (/[A-Z]/.test(folderName)) {
111
- folderName = core_1.strings.dasherize(folderName);
111
+ folderName = schematics_1.strings.dasherize(folderName);
112
112
  }
113
113
  const projectRoot = (0, core_1.join)((0, core_1.normalize)(newProjectRoot), folderName);
114
114
  const distRoot = `dist/${folderName}`;
115
- const pathImportLib = `${distRoot}/${folderName.replace('/', '-')}`;
116
115
  const sourceDir = `${projectRoot}/src/lib`;
117
116
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
118
117
  (0, schematics_1.applyTemplates)({
119
- ...core_1.strings,
118
+ ...schematics_1.strings,
120
119
  ...options,
121
120
  packageName,
122
121
  projectRoot,
@@ -133,7 +132,7 @@ function default_1(options) {
133
132
  (0, schematics_1.mergeWith)(templateSource),
134
133
  addLibToWorkspaceFile(options, projectRoot, packageName),
135
134
  options.skipPackageJson ? (0, schematics_1.noop)() : addDependenciesToPackageJson(),
136
- options.skipTsConfig ? (0, schematics_1.noop)() : updateTsConfig(packageName, pathImportLib, distRoot),
135
+ options.skipTsConfig ? (0, schematics_1.noop)() : updateTsConfig(packageName, distRoot),
137
136
  (0, schematics_1.schematic)('module', {
138
137
  name: options.name,
139
138
  commonModule: false,
@@ -24,6 +24,11 @@
24
24
  "version": "14.0.0",
25
25
  "factory": "./update-14/replace-default-collection-option",
26
26
  "description": "Replace 'defaultCollection' option in workspace configuration with 'schematicCollections'."
27
+ },
28
+ "update-libraries-secondary-entrypoints": {
29
+ "version": "14.0.0",
30
+ "factory": "./update-14/update-libraries-secondary-entrypoints",
31
+ "description": "Remove 'package.json' files from library projects secondary entrypoints."
27
32
  }
28
33
  }
29
34
  }
@@ -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 secondary entrypoints 'package.json' files and migrate ng-packagr configurations. */
10
+ export default function (): Rule;
@@ -0,0 +1,51 @@
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
+ function* visitPackageJsonFiles(directory, includedInLookup = false) {
13
+ if (includedInLookup) {
14
+ for (const path of directory.subfiles) {
15
+ if (path !== 'package.json') {
16
+ continue;
17
+ }
18
+ yield (0, core_1.join)(directory.path, path);
19
+ }
20
+ }
21
+ for (const path of directory.subdirs) {
22
+ if (path === 'node_modules' || path.startsWith('.')) {
23
+ continue;
24
+ }
25
+ yield* visitPackageJsonFiles(directory.dir(path), true);
26
+ }
27
+ }
28
+ /** Migration to remove secondary entrypoints 'package.json' files and migrate ng-packagr configurations. */
29
+ function default_1() {
30
+ return async (tree) => {
31
+ const workspace = await (0, workspace_1.getWorkspace)(tree);
32
+ for (const project of workspace.projects.values()) {
33
+ if (project.extensions['projectType'] !== 'library' ||
34
+ ![...project.targets.values()].some(({ builder }) => builder === '@angular-devkit/build-angular:ng-packagr')) {
35
+ // Project is not a library or doesn't use ng-packagr, skip.
36
+ continue;
37
+ }
38
+ for (const path of visitPackageJsonFiles(tree.getDir(project.root))) {
39
+ const json = tree.readJson(path);
40
+ if ((0, core_1.isJsonObject)(json) && json['ngPackage']) {
41
+ // Migrate ng-packagr config to an ng-packagr config file.
42
+ const configFilePath = (0, core_1.join)((0, core_1.dirname)((0, core_1.normalize)(path)), 'ng-package.json');
43
+ tree.create(configFilePath, JSON.stringify(json['ngPackage'], undefined, 2));
44
+ }
45
+ // Delete package.json as it is no longer needed in APF 14.
46
+ tree.delete(path);
47
+ }
48
+ }
49
+ };
50
+ }
51
+ exports.default = default_1;
package/module/index.js CHANGED
@@ -41,8 +41,8 @@ const workspace_1 = require("../utility/workspace");
41
41
  const schema_1 = require("./schema");
42
42
  function buildRelativeModulePath(options, modulePath) {
43
43
  const importModulePath = (0, core_1.normalize)(`/${options.path}/` +
44
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
45
- core_1.strings.dasherize(options.name) +
44
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
45
+ schematics_1.strings.dasherize(options.name) +
46
46
  '.module');
47
47
  return (0, find_module_1.buildRelativePath)(modulePath, importModulePath);
48
48
  }
@@ -52,14 +52,10 @@ function addDeclarationToNgModule(options) {
52
52
  return host;
53
53
  }
54
54
  const modulePath = options.module;
55
- const text = host.read(modulePath);
56
- if (text === null) {
57
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
58
- }
59
- const sourceText = text.toString();
55
+ const sourceText = host.readText(modulePath);
60
56
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
61
57
  const relativePath = buildRelativeModulePath(options, modulePath);
62
- const changes = (0, ast_utils_1.addImportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Module`), relativePath);
58
+ const changes = (0, ast_utils_1.addImportToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Module`), relativePath);
63
59
  const recorder = host.beginUpdate(modulePath);
64
60
  for (const change of changes) {
65
61
  if (change instanceof change_1.InsertChange) {
@@ -85,11 +81,7 @@ function addRouteDeclarationToNgModule(options, routingModulePath) {
85
81
  else {
86
82
  path = options.module;
87
83
  }
88
- const text = host.read(path);
89
- if (!text) {
90
- throw new Error(`Couldn't find the module nor its routing module.`);
91
- }
92
- const sourceText = text.toString();
84
+ const sourceText = host.readText(path);
93
85
  const addDeclaration = (0, ast_utils_1.addRouteDeclarationToModule)(ts.createSourceFile(path, sourceText, ts.ScriptTarget.Latest, true), path, buildRoute(options, options.module));
94
86
  const recorder = host.beginUpdate(path);
95
87
  recorder.insertLeft(addDeclaration.pos, addDeclaration.toAdd);
@@ -105,7 +97,7 @@ function getRoutingModulePath(host, modulePath) {
105
97
  }
106
98
  function buildRoute(options, modulePath) {
107
99
  const relativeModulePath = buildRelativeModulePath(options, modulePath);
108
- const moduleName = `${core_1.strings.classify(options.name)}Module`;
100
+ const moduleName = `${schematics_1.strings.classify(options.name)}Module`;
109
101
  const loadChildren = `() => import('${relativeModulePath}').then(m => m.${moduleName})`;
110
102
  return `{ path: '${options.route}', loadChildren: ${loadChildren} }`;
111
103
  }
@@ -131,7 +123,7 @@ function default_1(options) {
131
123
  ? (0, schematics_1.noop)()
132
124
  : (0, schematics_1.filter)((path) => !path.endsWith('-routing.module.ts.template')),
133
125
  (0, schematics_1.applyTemplates)({
134
- ...core_1.strings,
126
+ ...schematics_1.strings,
135
127
  'if-flat': (s) => (options.flat ? '' : s),
136
128
  lazyRoute: isLazyLoadedModuleGen,
137
129
  lazyRouteWithoutRouteModule: isLazyLoadedModuleGen && !routingModulePath,
@@ -140,7 +132,7 @@ function default_1(options) {
140
132
  }),
141
133
  (0, schematics_1.move)(parsedPath.path),
142
134
  ]);
143
- const moduleDasherized = core_1.strings.dasherize(options.name);
135
+ const moduleDasherized = schematics_1.strings.dasherize(options.name);
144
136
  const modulePath = `${!options.flat ? moduleDasherized + '/' : ''}${moduleDasherized}.module.ts`;
145
137
  const componentOptions = {
146
138
  module: modulePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematics/angular",
3
- "version": "14.0.0-next.8",
3
+ "version": "14.0.0-rc.1",
4
4
  "description": "Schematics specific to Angular",
5
5
  "homepage": "https://github.com/angular/angular-cli",
6
6
  "keywords": [
@@ -13,10 +13,17 @@
13
13
  "code generation",
14
14
  "schematics"
15
15
  ],
16
+ "exports": {
17
+ "./package.json": "./package.json",
18
+ "./utility": "./utility/index.js",
19
+ "./utility/*": "./utility/*.js",
20
+ "./migrations/migration-collection.json": "./migrations/migration-collection.json",
21
+ "./*": "./*.js"
22
+ },
16
23
  "schematics": "./collection.json",
17
24
  "dependencies": {
18
- "@angular-devkit/core": "14.0.0-next.8",
19
- "@angular-devkit/schematics": "14.0.0-next.8",
25
+ "@angular-devkit/core": "14.0.0-rc.1",
26
+ "@angular-devkit/schematics": "14.0.0-rc.1",
20
27
  "jsonc-parser": "3.0.0"
21
28
  },
22
29
  "repository": {
@@ -1,7 +1,8 @@
1
1
  import { Pipe, PipeTransform } from '@angular/core';
2
2
 
3
3
  @Pipe({
4
- name: '<%= camelize(name) %>'
4
+ name: '<%= camelize(name) %>'<% if(standalone) {%>,
5
+ standalone: true<%}%>
5
6
  })
6
7
  export class <%= classify(name) %>Pipe implements PipeTransform {
7
8
 
package/pipe/index.js CHANGED
@@ -30,7 +30,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- const core_1 = require("@angular-devkit/core");
34
33
  const schematics_1 = require("@angular-devkit/schematics");
35
34
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
36
35
  const ast_utils_1 = require("../utility/ast-utils");
@@ -40,22 +39,18 @@ const parse_name_1 = require("../utility/parse-name");
40
39
  const workspace_1 = require("../utility/workspace");
41
40
  function addDeclarationToNgModule(options) {
42
41
  return (host) => {
43
- if (options.skipImport || !options.module) {
42
+ if (options.skipImport || options.standalone || !options.module) {
44
43
  return host;
45
44
  }
46
45
  const modulePath = options.module;
47
- const text = host.read(modulePath);
48
- if (text === null) {
49
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
50
- }
51
- const sourceText = text.toString('utf-8');
46
+ const sourceText = host.readText(modulePath);
52
47
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
53
48
  const pipePath = `/${options.path}/` +
54
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
55
- core_1.strings.dasherize(options.name) +
49
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
50
+ schematics_1.strings.dasherize(options.name) +
56
51
  '.pipe';
57
52
  const relativePath = (0, find_module_1.buildRelativePath)(modulePath, pipePath);
58
- const changes = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, core_1.strings.classify(`${options.name}Pipe`), relativePath);
53
+ const changes = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Pipe`), relativePath);
59
54
  const recorder = host.beginUpdate(modulePath);
60
55
  for (const change of changes) {
61
56
  if (change instanceof change_1.InsertChange) {
@@ -64,14 +59,10 @@ function addDeclarationToNgModule(options) {
64
59
  }
65
60
  host.commitUpdate(recorder);
66
61
  if (options.export) {
67
- const text = host.read(modulePath);
68
- if (text === null) {
69
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
70
- }
71
- const sourceText = text.toString('utf-8');
62
+ const sourceText = host.readText(modulePath);
72
63
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
73
64
  const exportRecorder = host.beginUpdate(modulePath);
74
- const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Pipe`), relativePath);
65
+ const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Pipe`), relativePath);
75
66
  for (const change of exportChanges) {
76
67
  if (change instanceof change_1.InsertChange) {
77
68
  exportRecorder.insertLeft(change.pos, change.toAdd);
@@ -94,7 +85,7 @@ function default_1(options) {
94
85
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
95
86
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
96
87
  (0, schematics_1.applyTemplates)({
97
- ...core_1.strings,
88
+ ...schematics_1.strings,
98
89
  'if-flat': (s) => (options.flat ? '' : s),
99
90
  ...options,
100
91
  }),
package/pipe/schema.d.ts CHANGED
@@ -34,4 +34,8 @@ export interface Schema {
34
34
  * Do not create "spec.ts" test files for the new pipe.
35
35
  */
36
36
  skipTests?: boolean;
37
+ /**
38
+ * Whether the generated pipe is standalone.
39
+ */
40
+ standalone?: boolean;
37
41
  }
package/pipe/schema.json CHANGED
@@ -45,6 +45,12 @@
45
45
  "description": "Do not import this pipe into the owning NgModule.",
46
46
  "x-user-analytics": 18
47
47
  },
48
+ "standalone": {
49
+ "description": "Whether the generated pipe is standalone.",
50
+ "type": "boolean",
51
+ "default": false,
52
+ "x-user-analytics": 15
53
+ },
48
54
  "module": {
49
55
  "type": "string",
50
56
  "description": "The declaring NgModule.",