@schematics/angular 14.0.0-next.9 → 14.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/app-shell/index.js +4 -8
  2. package/app-shell/schema.json +0 -3
  3. package/application/files/src/test.ts.template +1 -1
  4. package/application/index.js +3 -3
  5. package/class/schema.json +3 -0
  6. package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template +1 -1
  7. package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +5 -2
  8. package/component/index.js +9 -14
  9. package/component/schema.d.ts +4 -0
  10. package/component/schema.json +9 -0
  11. package/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template +2 -1
  12. package/directive/index.js +9 -18
  13. package/directive/schema.d.ts +4 -0
  14. package/directive/schema.json +9 -0
  15. package/e2e/index.js +5 -5
  16. package/enum/schema.json +3 -0
  17. package/guard/schema.json +3 -0
  18. package/interceptor/schema.json +3 -0
  19. package/interface/schema.json +3 -0
  20. package/library/files/src/test.ts.template +1 -1
  21. package/library/index.js +3 -4
  22. package/migrations/migration-collection.json +5 -0
  23. package/migrations/update-14/update-libraries-secondary-entrypoints.d.ts +10 -0
  24. package/migrations/update-14/update-libraries-secondary-entrypoints.js +51 -0
  25. package/module/index.js +8 -16
  26. package/module/schema.json +3 -0
  27. package/package.json +10 -3
  28. package/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template +2 -1
  29. package/pipe/index.js +8 -17
  30. package/pipe/schema.d.ts +4 -0
  31. package/pipe/schema.json +9 -0
  32. package/resolver/schema.json +3 -0
  33. package/service/schema.json +3 -1
  34. package/service-worker/index.js +4 -8
  35. package/third_party/github.com/Microsoft/TypeScript/BUILD.bazel +4 -4
  36. package/third_party/github.com/Microsoft/TypeScript/lib/typescript.d.ts +402 -295
  37. package/third_party/github.com/Microsoft/TypeScript/lib/typescript.js +23181 -20448
  38. package/universal/index.js +3 -7
  39. package/utility/dependency.d.ts +45 -0
  40. package/utility/dependency.js +97 -0
  41. package/utility/find-module.d.ts +1 -0
  42. package/utility/find-module.js +1 -2
  43. package/utility/generate-from-files.js +2 -3
  44. package/utility/index.d.ts +10 -0
  45. package/utility/index.js +21 -0
  46. package/utility/json-file.js +1 -7
  47. package/utility/latest-versions/package.json +4 -3
  48. package/utility/latest-versions.js +1 -1
  49. package/utility/ng-ast-utils.js +2 -10
  50. package/utility/parse-name.js +0 -1
  51. package/utility/validation.js +1 -3
  52. package/utility/workspace-models.d.ts +6 -0
  53. package/utility/workspace-models.js +6 -0
  54. package/utility/workspace.d.ts +36 -3
  55. package/utility/workspace.js +70 -34
  56. package/web-worker/index.js +2 -2
  57. package/web-worker/schema.json +3 -0
  58. package/workspace/index.js +1 -2
@@ -96,11 +96,7 @@ function updateConfigFile(options, tsConfigDirectory) {
96
96
  });
97
97
  }
98
98
  function findBrowserModuleImport(host, modulePath) {
99
- const moduleBuffer = host.read(modulePath);
100
- if (!moduleBuffer) {
101
- throw new schematics_1.SchematicsException(`Module file (${modulePath}) not found`);
102
- }
103
- const moduleFileText = moduleBuffer.toString('utf-8');
99
+ const moduleFileText = host.readText(modulePath);
104
100
  const source = ts.createSourceFile(modulePath, moduleFileText, ts.ScriptTarget.Latest, true);
105
101
  const decoratorMetadata = (0, ast_utils_1.getDecoratorMetadata)(source, 'NgModule', '@angular/core')[0];
106
102
  const browserModuleNode = (0, ast_utils_1.findNode)(decoratorMetadata, ts.SyntaxKind.Identifier, 'BrowserModule');
@@ -230,7 +226,7 @@ function default_1(options) {
230
226
  }
231
227
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/src'), [
232
228
  (0, schematics_1.applyTemplates)({
233
- ...core_1.strings,
229
+ ...schematics_1.strings,
234
230
  ...options,
235
231
  stripTsExtension: (s) => s.replace(/\.ts$/, ''),
236
232
  hasLocalizePackage: !!(0, dependencies_1.getPackageJsonDependency)(host, '@angular/localize'),
@@ -239,7 +235,7 @@ function default_1(options) {
239
235
  ]);
240
236
  const rootSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/root'), [
241
237
  (0, schematics_1.applyTemplates)({
242
- ...core_1.strings,
238
+ ...schematics_1.strings,
243
239
  ...options,
244
240
  stripTsExtension: (s) => s.replace(/\.ts$/, ''),
245
241
  tsConfigExtends,
@@ -0,0 +1,45 @@
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
+ /**
10
+ * An enum used to specify the type of a dependency found within a package manifest
11
+ * file (`package.json`).
12
+ */
13
+ export declare enum DependencyType {
14
+ Default = "dependencies",
15
+ Dev = "devDependencies",
16
+ Peer = "peerDependencies"
17
+ }
18
+ /**
19
+ * Adds a package as a dependency to a `package.json`. By default the `package.json` located
20
+ * at the schematic's root will be used. The `manifestPath` option can be used to explicitly specify
21
+ * a `package.json` in different location. The type of the dependency can also be specified instead
22
+ * of the default of the `dependencies` section by using the `type` option for either `devDependencies`
23
+ * or `peerDependencies`.
24
+ *
25
+ * When using this rule, {@link NodePackageInstallTask} does not need to be included directly by
26
+ * a schematic. A package manager install task will be automatically scheduled as needed.
27
+ *
28
+ * @param name The name of the package to add.
29
+ * @param specifier The package specifier for the package to add. Typically a SemVer range.
30
+ * @param options An optional object that can contain the `type` of the dependency
31
+ * and/or a path (`packageJsonPath`) of a manifest file (`package.json`) to modify.
32
+ * @returns A Schematics {@link Rule}
33
+ */
34
+ export declare function addDependency(name: string, specifier: string, options?: {
35
+ /**
36
+ * The type of the dependency determines the section of the `package.json` to which the
37
+ * dependency will be added. Defaults to {@link DependencyType.Default} (`dependencies`).
38
+ */
39
+ type?: DependencyType;
40
+ /**
41
+ * The path of the package manifest file (`package.json`) that will be modified.
42
+ * Defaults to `/package.json`.
43
+ */
44
+ packageJsonPath?: string;
45
+ }): Rule;
@@ -0,0 +1,97 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.addDependency = exports.DependencyType = void 0;
34
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
35
+ const path = __importStar(require("path"));
36
+ const installTasks = new WeakMap();
37
+ /**
38
+ * An enum used to specify the type of a dependency found within a package manifest
39
+ * file (`package.json`).
40
+ */
41
+ var DependencyType;
42
+ (function (DependencyType) {
43
+ DependencyType["Default"] = "dependencies";
44
+ DependencyType["Dev"] = "devDependencies";
45
+ DependencyType["Peer"] = "peerDependencies";
46
+ })(DependencyType = exports.DependencyType || (exports.DependencyType = {}));
47
+ /**
48
+ * Adds a package as a dependency to a `package.json`. By default the `package.json` located
49
+ * at the schematic's root will be used. The `manifestPath` option can be used to explicitly specify
50
+ * a `package.json` in different location. The type of the dependency can also be specified instead
51
+ * of the default of the `dependencies` section by using the `type` option for either `devDependencies`
52
+ * or `peerDependencies`.
53
+ *
54
+ * When using this rule, {@link NodePackageInstallTask} does not need to be included directly by
55
+ * a schematic. A package manager install task will be automatically scheduled as needed.
56
+ *
57
+ * @param name The name of the package to add.
58
+ * @param specifier The package specifier for the package to add. Typically a SemVer range.
59
+ * @param options An optional object that can contain the `type` of the dependency
60
+ * and/or a path (`packageJsonPath`) of a manifest file (`package.json`) to modify.
61
+ * @returns A Schematics {@link Rule}
62
+ */
63
+ function addDependency(name, specifier, options = {}) {
64
+ const { type = DependencyType.Default, packageJsonPath = '/package.json' } = options;
65
+ return (tree, context) => {
66
+ var _a;
67
+ const manifest = tree.readJson(packageJsonPath);
68
+ const dependencySection = manifest[type];
69
+ if (!dependencySection) {
70
+ // Section is not present. The dependency can be added to a new object literal for the section.
71
+ manifest[type] = { [name]: specifier };
72
+ }
73
+ else if (dependencySection[name] === specifier) {
74
+ // Already present with same specifier
75
+ return;
76
+ }
77
+ else if (dependencySection[name]) {
78
+ // Already present but different specifier
79
+ throw new Error(`Package dependency "${name}" already exists with a different specifier.`);
80
+ }
81
+ else {
82
+ // Add new dependency in alphabetical order
83
+ const entries = Object.entries(dependencySection);
84
+ entries.push([name, specifier]);
85
+ entries.sort((a, b) => a[0].localeCompare(b[0]));
86
+ manifest[type] = Object.fromEntries(entries);
87
+ }
88
+ tree.overwrite(packageJsonPath, JSON.stringify(manifest, null, 2));
89
+ const installPaths = (_a = installTasks.get(context)) !== null && _a !== void 0 ? _a : new Set();
90
+ if (!installPaths.has(packageJsonPath)) {
91
+ context.addTask(new tasks_1.NodePackageInstallTask({ workingDirectory: path.dirname(packageJsonPath) }));
92
+ installPaths.add(packageJsonPath);
93
+ installTasks.set(context, installPaths);
94
+ }
95
+ };
96
+ }
97
+ exports.addDependency = addDependency;
@@ -15,6 +15,7 @@ export interface ModuleOptions {
15
15
  skipImport?: boolean;
16
16
  moduleExt?: string;
17
17
  routingModuleExt?: string;
18
+ standalone?: boolean;
18
19
  }
19
20
  export declare const MODULE_EXT = ".module.ts";
20
21
  export declare const ROUTING_MODULE_EXT = "-routing.module.ts";
@@ -15,8 +15,7 @@ exports.ROUTING_MODULE_EXT = '-routing.module.ts';
15
15
  * Find the module referred by a set of options passed to the schematics.
16
16
  */
17
17
  function findModuleFromOptions(host, options) {
18
- // eslint-disable-next-line no-prototype-builtins
19
- if (options.hasOwnProperty('skipImport') && options.skipImport) {
18
+ if (options.standalone || options.skipImport) {
20
19
  return undefined;
21
20
  }
22
21
  const moduleExt = options.moduleExt || exports.MODULE_EXT;
@@ -8,7 +8,6 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.generateFromFiles = void 0;
11
- const core_1 = require("@angular-devkit/core");
12
11
  const schematics_1 = require("@angular-devkit/schematics");
13
12
  const parse_name_1 = require("./parse-name");
14
13
  const workspace_1 = require("./workspace");
@@ -24,11 +23,11 @@ function generateFromFiles(options, extraTemplateValues = {}) {
24
23
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
25
24
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
26
25
  (0, schematics_1.applyTemplates)({
27
- ...core_1.strings,
26
+ ...schematics_1.strings,
28
27
  ...options,
29
28
  ...extraTemplateValues,
30
29
  }),
31
- (0, schematics_1.move)(parsedPath.path + (options.flat ? '' : '/' + core_1.strings.dasherize(options.name))),
30
+ (0, schematics_1.move)(parsedPath.path + (options.flat ? '' : '/' + schematics_1.strings.dasherize(options.name))),
32
31
  ]);
33
32
  return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource)]);
34
33
  };
@@ -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
+ export { ProjectDefinition, TargetDefinition, WorkspaceDefinition, getWorkspace as readWorkspace, updateWorkspace, writeWorkspace, } from './workspace';
9
+ export { Builders as AngularBuilder } from './workspace-models';
10
+ export { DependencyType, addDependency } from './dependency';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.addDependency = exports.DependencyType = exports.AngularBuilder = exports.writeWorkspace = exports.updateWorkspace = exports.readWorkspace = void 0;
11
+ // Workspace related rules and types
12
+ var workspace_1 = require("./workspace");
13
+ Object.defineProperty(exports, "readWorkspace", { enumerable: true, get: function () { return workspace_1.getWorkspace; } });
14
+ Object.defineProperty(exports, "updateWorkspace", { enumerable: true, get: function () { return workspace_1.updateWorkspace; } });
15
+ Object.defineProperty(exports, "writeWorkspace", { enumerable: true, get: function () { return workspace_1.writeWorkspace; } });
16
+ var workspace_models_1 = require("./workspace-models");
17
+ Object.defineProperty(exports, "AngularBuilder", { enumerable: true, get: function () { return workspace_models_1.Builders; } });
18
+ // Package dependency related rules and types
19
+ var dependency_1 = require("./dependency");
20
+ Object.defineProperty(exports, "DependencyType", { enumerable: true, get: function () { return dependency_1.DependencyType; } });
21
+ Object.defineProperty(exports, "addDependency", { enumerable: true, get: function () { return dependency_1.addDependency; } });
@@ -14,13 +14,7 @@ class JSONFile {
14
14
  constructor(host, path) {
15
15
  this.host = host;
16
16
  this.path = path;
17
- const buffer = this.host.read(this.path);
18
- if (buffer) {
19
- this.content = buffer.toString();
20
- }
21
- else {
22
- throw new Error(`Could not read '${path}'.`);
23
- }
17
+ this.content = this.host.readText(this.path);
24
18
  }
25
19
  get JsonAst() {
26
20
  if (this._jsonAst) {
@@ -9,12 +9,13 @@
9
9
  "karma-chrome-launcher": "~3.1.0",
10
10
  "karma-coverage": "~2.2.0",
11
11
  "karma-jasmine-html-reporter": "~1.7.0",
12
- "karma-jasmine": "~4.0.0",
12
+ "karma-jasmine": "~5.0.0",
13
13
  "karma": "~6.3.0",
14
- "ng-packagr": "^14.0.0-next.2",
14
+ "ng-packagr": "^14.0.0-next.8",
15
15
  "rxjs": "~7.5.0",
16
16
  "tslib": "^2.3.0",
17
- "typescript": "~4.6.2",
17
+ "ts-node": "~10.7.0",
18
+ "typescript": "~4.7.2",
18
19
  "zone.js": "~0.11.4"
19
20
  }
20
21
  }
@@ -13,7 +13,7 @@ exports.latestVersions = {
13
13
  // but ts_library doesn't support JSON inputs.
14
14
  ...require('./latest-versions/package.json')['dependencies'],
15
15
  // As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
16
- Angular: '^14.0.0-next.0',
16
+ Angular: '^14.0.0-rc.0',
17
17
  // Since @angular-devkit/build-angular and @schematics/angular are always
18
18
  // published together from the same monorepo, and they are both
19
19
  // non-experimental, they will always have the same version.
@@ -37,11 +37,7 @@ const path_1 = require("path");
37
37
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
38
38
  const ast_utils_1 = require("../utility/ast-utils");
39
39
  function findBootstrapModuleCall(host, mainPath) {
40
- const mainBuffer = host.read(mainPath);
41
- if (!mainBuffer) {
42
- throw new schematics_1.SchematicsException(`Main file (${mainPath}) not found`);
43
- }
44
- const mainText = mainBuffer.toString('utf-8');
40
+ const mainText = host.readText(mainPath);
45
41
  const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
46
42
  const allNodes = (0, ast_utils_1.getSourceNodes)(source);
47
43
  let bootstrapCall = null;
@@ -70,11 +66,7 @@ function findBootstrapModulePath(host, mainPath) {
70
66
  throw new schematics_1.SchematicsException('Bootstrap call not found');
71
67
  }
72
68
  const bootstrapModule = bootstrapCall.arguments[0];
73
- const mainBuffer = host.read(mainPath);
74
- if (!mainBuffer) {
75
- throw new schematics_1.SchematicsException(`Client application main file (${mainPath}) not found`);
76
- }
77
- const mainText = mainBuffer.toString('utf-8');
69
+ const mainText = host.readText(mainPath);
78
70
  const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
79
71
  const allNodes = (0, ast_utils_1.getSourceNodes)(source);
80
72
  const bootstrapModuleRelativePath = allNodes
@@ -8,7 +8,6 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.parseName = void 0;
11
- // import { relative, Path } from "../../../angular_devkit/core/src/virtual-fs";
12
11
  const core_1 = require("@angular-devkit/core");
13
12
  function parseName(path, name) {
14
13
  const nameWithoutPath = (0, core_1.basename)((0, core_1.normalize)(name));
@@ -8,15 +8,13 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.validateHtmlSelector = exports.htmlSelectorRe = void 0;
11
- const core_1 = require("@angular-devkit/core");
12
11
  const schematics_1 = require("@angular-devkit/schematics");
13
12
  // Must start with a letter, and must contain only alphanumeric characters or dashes.
14
13
  // When adding a dash the segment after the dash must also start with a letter.
15
14
  exports.htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/;
16
15
  function validateHtmlSelector(selector) {
17
16
  if (selector && !exports.htmlSelectorRe.test(selector)) {
18
- throw new schematics_1.SchematicsException(core_1.tags.oneLine `Selector (${selector})
19
- is invalid.`);
17
+ throw new schematics_1.SchematicsException(`Selector (${selector}) is invalid.`);
20
18
  }
21
19
  }
22
20
  exports.validateHtmlSelector = validateHtmlSelector;
@@ -9,6 +9,12 @@ export declare enum ProjectType {
9
9
  Application = "application",
10
10
  Library = "library"
11
11
  }
12
+ /**
13
+ * An enum of the official Angular builders.
14
+ * Each enum value provides the fully qualified name of the associated builder.
15
+ * This enum can be used when analyzing the `builder` fields of project configurations from the
16
+ * `angular.json` workspace file.
17
+ */
12
18
  export declare enum Builders {
13
19
  AppShell = "@angular-devkit/build-angular:app-shell",
14
20
  Server = "@angular-devkit/build-angular:server",
@@ -13,6 +13,12 @@ var ProjectType;
13
13
  ProjectType["Application"] = "application";
14
14
  ProjectType["Library"] = "library";
15
15
  })(ProjectType = exports.ProjectType || (exports.ProjectType = {}));
16
+ /**
17
+ * An enum of the official Angular builders.
18
+ * Each enum value provides the fully qualified name of the associated builder.
19
+ * This enum can be used when analyzing the `builder` fields of project configurations from the
20
+ * `angular.json` workspace file.
21
+ */
16
22
  var Builders;
17
23
  (function (Builders) {
18
24
  Builders["AppShell"] = "@angular-devkit/build-angular:app-shell";
@@ -7,9 +7,42 @@
7
7
  */
8
8
  import { json, workspaces } from '@angular-devkit/core';
9
9
  import { Rule, Tree } from '@angular-devkit/schematics';
10
- export declare function updateWorkspace(updater: (workspace: workspaces.WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>): Rule;
11
- export declare function updateWorkspace(workspace: workspaces.WorkspaceDefinition): Rule;
12
- export declare function getWorkspace(tree: Tree, path?: string): Promise<workspaces.WorkspaceDefinition>;
10
+ export declare type WorkspaceDefinition = workspaces.WorkspaceDefinition;
11
+ export declare type ProjectDefinition = workspaces.ProjectDefinition;
12
+ export declare type TargetDefinition = workspaces.TargetDefinition;
13
+ /**
14
+ * Updates the workspace file (`angular.json`) found within the root of the schematic's tree.
15
+ * The workspace object model can be directly modified within the provided updater function
16
+ * with changes being written to the workspace file after the updater function returns.
17
+ * The spacing and overall layout of the file (including comments) will be maintained where
18
+ * possible when updating the file.
19
+ *
20
+ * @param updater An update function that can be used to modify the object model for the
21
+ * workspace. A {@link WorkspaceDefinition} is provided as the first argument to the function.
22
+ */
23
+ export declare function updateWorkspace(updater: (workspace: WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>): Rule;
24
+ /**
25
+ * Reads a workspace file (`angular.json`) from the provided {@link Tree} instance.
26
+ *
27
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
28
+ * @param path The path where a workspace file should be found. If a file is specified, the file
29
+ * path will be used. If a directory is specified, the file `angular.json` will be used from
30
+ * within the specified directory. Defaults to `/angular.json`.
31
+ * @returns A {@link WorkspaceDefinition} representing the workspace found at the specified path.
32
+ */
33
+ export declare function getWorkspace(tree: Tree, path?: string): Promise<WorkspaceDefinition>;
34
+ /**
35
+ * Writes a workspace file (`angular.json`) to the provided {@link Tree} instance.
36
+ * The spacing and overall layout of an exisitng file (including comments) will be maintained where
37
+ * possible when writing the file.
38
+ *
39
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
40
+ * @param workspace The {@link WorkspaceDefinition} to write.
41
+ * @param path The path where a workspace file should be written. If a file is specified, the file
42
+ * path will be used. If not provided, the definition's underlying file path stored during reading
43
+ * will be used.
44
+ */
45
+ export declare function writeWorkspace(tree: Tree, workspace: WorkspaceDefinition, path?: string): Promise<void>;
13
46
  /**
14
47
  * Build a default project path for generating.
15
48
  * @param project The project which will have its default path generated.
@@ -7,53 +7,89 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.allTargetOptions = exports.allWorkspaceTargets = exports.createDefaultPath = exports.buildDefaultPath = exports.getWorkspace = exports.updateWorkspace = void 0;
10
+ exports.allTargetOptions = exports.allWorkspaceTargets = exports.createDefaultPath = exports.buildDefaultPath = exports.writeWorkspace = exports.getWorkspace = exports.updateWorkspace = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
12
  const schematics_1 = require("@angular-devkit/schematics");
13
13
  const workspace_models_1 = require("./workspace-models");
14
- function createHost(tree) {
15
- return {
16
- async readFile(path) {
17
- const data = tree.read(path);
18
- if (!data) {
19
- throw new Error('File not found.');
20
- }
21
- return core_1.virtualFs.fileBufferToString(data);
22
- },
23
- async writeFile(path, data) {
24
- return tree.overwrite(path, data);
25
- },
26
- async isDirectory(path) {
27
- // approximate a directory check
28
- return !tree.exists(path) && tree.getDir(path).subfiles.length > 0;
29
- },
30
- async isFile(path) {
31
- return tree.exists(path);
32
- },
33
- };
34
- }
35
- function updateWorkspace(updaterOrWorkspace) {
36
- return async (tree) => {
37
- const host = createHost(tree);
38
- if (typeof updaterOrWorkspace === 'function') {
39
- const { workspace } = await core_1.workspaces.readWorkspace('/', host);
40
- const result = await updaterOrWorkspace(workspace);
41
- await core_1.workspaces.writeWorkspace(workspace, host);
42
- return result || schematics_1.noop;
14
+ const DEFAULT_WORKSPACE_PATH = '/angular.json';
15
+ /**
16
+ * A {@link workspaces.WorkspaceHost} backed by a Schematics {@link Tree} instance.
17
+ */
18
+ class TreeWorkspaceHost {
19
+ constructor(tree) {
20
+ this.tree = tree;
21
+ }
22
+ async readFile(path) {
23
+ return this.tree.readText(path);
24
+ }
25
+ async writeFile(path, data) {
26
+ if (this.tree.exists(path)) {
27
+ this.tree.overwrite(path, data);
43
28
  }
44
29
  else {
45
- await core_1.workspaces.writeWorkspace(updaterOrWorkspace, host);
46
- return schematics_1.noop;
30
+ this.tree.create(path, data);
47
31
  }
32
+ }
33
+ async isDirectory(path) {
34
+ // approximate a directory check
35
+ return !this.tree.exists(path) && this.tree.getDir(path).subfiles.length > 0;
36
+ }
37
+ async isFile(path) {
38
+ return this.tree.exists(path);
39
+ }
40
+ }
41
+ /**
42
+ * Updates the workspace file (`angular.json`) found within the root of the schematic's tree.
43
+ * The workspace object model can be directly modified within the provided updater function
44
+ * with changes being written to the workspace file after the updater function returns.
45
+ * The spacing and overall layout of the file (including comments) will be maintained where
46
+ * possible when updating the file.
47
+ *
48
+ * @param updater An update function that can be used to modify the object model for the
49
+ * workspace. A {@link WorkspaceDefinition} is provided as the first argument to the function.
50
+ */
51
+ function updateWorkspace(updater) {
52
+ return async (tree) => {
53
+ const host = new TreeWorkspaceHost(tree);
54
+ const { workspace } = await core_1.workspaces.readWorkspace(DEFAULT_WORKSPACE_PATH, host);
55
+ const result = await updater(workspace);
56
+ await core_1.workspaces.writeWorkspace(workspace, host);
57
+ return result || schematics_1.noop;
48
58
  };
49
59
  }
50
60
  exports.updateWorkspace = updateWorkspace;
51
- async function getWorkspace(tree, path = '/') {
52
- const host = createHost(tree);
61
+ // TODO: This should be renamed `readWorkspace` once deep imports are restricted (already exported from `utility` with that name)
62
+ /**
63
+ * Reads a workspace file (`angular.json`) from the provided {@link Tree} instance.
64
+ *
65
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
66
+ * @param path The path where a workspace file should be found. If a file is specified, the file
67
+ * path will be used. If a directory is specified, the file `angular.json` will be used from
68
+ * within the specified directory. Defaults to `/angular.json`.
69
+ * @returns A {@link WorkspaceDefinition} representing the workspace found at the specified path.
70
+ */
71
+ async function getWorkspace(tree, path = DEFAULT_WORKSPACE_PATH) {
72
+ const host = new TreeWorkspaceHost(tree);
53
73
  const { workspace } = await core_1.workspaces.readWorkspace(path, host);
54
74
  return workspace;
55
75
  }
56
76
  exports.getWorkspace = getWorkspace;
77
+ /**
78
+ * Writes a workspace file (`angular.json`) to the provided {@link Tree} instance.
79
+ * The spacing and overall layout of an exisitng file (including comments) will be maintained where
80
+ * possible when writing the file.
81
+ *
82
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
83
+ * @param workspace The {@link WorkspaceDefinition} to write.
84
+ * @param path The path where a workspace file should be written. If a file is specified, the file
85
+ * path will be used. If not provided, the definition's underlying file path stored during reading
86
+ * will be used.
87
+ */
88
+ async function writeWorkspace(tree, workspace, path) {
89
+ const host = new TreeWorkspaceHost(tree);
90
+ return core_1.workspaces.writeWorkspace(workspace, host, path);
91
+ }
92
+ exports.writeWorkspace = writeWorkspace;
57
93
  /**
58
94
  * Build a default project path for generating.
59
95
  * @param project The project which will have its default path generated.
@@ -46,7 +46,7 @@ function addSnippet(options) {
46
46
  }
47
47
  `;
48
48
  // Append the worker creation snippet.
49
- const originalContent = host.read(siblingModulePath);
49
+ const originalContent = host.readText(siblingModulePath);
50
50
  host.overwrite(siblingModulePath, originalContent + '\n' + workerCreationSnippet);
51
51
  return host;
52
52
  };
@@ -72,7 +72,7 @@ function default_1(options) {
72
72
  options.name = parsedPath.name;
73
73
  options.path = parsedPath.path;
74
74
  const templateSourceWorkerCode = (0, schematics_1.apply)((0, schematics_1.url)('./files/worker'), [
75
- (0, schematics_1.applyTemplates)({ ...options, ...core_1.strings }),
75
+ (0, schematics_1.applyTemplates)({ ...options, ...schematics_1.strings }),
76
76
  (0, schematics_1.move)(parsedPath.path),
77
77
  ]);
78
78
  const root = project.root || '';
@@ -9,6 +9,9 @@
9
9
  "path": {
10
10
  "type": "string",
11
11
  "format": "path",
12
+ "$default": {
13
+ "$source": "workingDirectory"
14
+ },
12
15
  "description": "The path at which to create the worker file, relative to the current workspace.",
13
16
  "visible": false
14
17
  },
@@ -7,14 +7,13 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- const core_1 = require("@angular-devkit/core");
11
10
  const schematics_1 = require("@angular-devkit/schematics");
12
11
  const latest_versions_1 = require("../utility/latest-versions");
13
12
  function default_1(options) {
14
13
  return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
15
14
  options.minimal ? (0, schematics_1.filter)((path) => !path.endsWith('editorconfig.template')) : (0, schematics_1.noop)(),
16
15
  (0, schematics_1.applyTemplates)({
17
- utils: core_1.strings,
16
+ utils: schematics_1.strings,
18
17
  ...options,
19
18
  'dot': '.',
20
19
  latestVersions: latest_versions_1.latestVersions,