@angular/cli 14.0.0-next.7 → 14.0.0-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.
Files changed (50) hide show
  1. package/lib/config/schema.json +18 -0
  2. package/lib/config/workspace-schema.d.ts +12 -0
  3. package/package.json +17 -17
  4. package/src/analytics/analytics.d.ts +1 -1
  5. package/src/analytics/analytics.js +22 -20
  6. package/src/command-builder/architect-base-command-module.d.ts +9 -2
  7. package/src/command-builder/architect-base-command-module.js +65 -3
  8. package/src/command-builder/architect-command-module.d.ts +4 -1
  9. package/src/command-builder/architect-command-module.js +37 -11
  10. package/src/command-builder/command-module.d.ts +1 -1
  11. package/src/command-builder/command-module.js +21 -7
  12. package/src/command-builder/command-runner.js +41 -30
  13. package/src/command-builder/schematics-command-module.d.ts +0 -3
  14. package/src/command-builder/schematics-command-module.js +21 -23
  15. package/src/command-builder/utilities/command.d.ts +1 -1
  16. package/src/command-builder/utilities/normalize-options-middleware.d.ts +18 -0
  17. package/src/command-builder/utilities/normalize-options-middleware.js +59 -0
  18. package/src/command-builder/utilities/schematic-engine-host.d.ts +2 -2
  19. package/src/command-builder/utilities/schematic-engine-host.js +33 -18
  20. package/src/commands/analytics/settings/cli.js +2 -2
  21. package/src/commands/cache/settings/cli.d.ts +2 -2
  22. package/src/commands/cache/settings/cli.js +2 -2
  23. package/src/commands/cache/utilities.d.ts +1 -1
  24. package/src/commands/cache/utilities.js +7 -8
  25. package/src/commands/completion/cli.d.ts +16 -0
  26. package/src/commands/completion/cli.js +61 -0
  27. package/src/commands/completion/long-description.md +5 -0
  28. package/src/commands/config/cli.js +15 -14
  29. package/src/commands/deploy/cli.d.ts +2 -1
  30. package/src/commands/deploy/cli.js +27 -13
  31. package/src/commands/e2e/cli.d.ts +2 -1
  32. package/src/commands/e2e/cli.js +14 -13
  33. package/src/commands/lint/cli.d.ts +2 -1
  34. package/src/commands/lint/cli.js +6 -9
  35. package/src/commands/new/cli.js +7 -2
  36. package/src/commands/run/cli.d.ts +2 -0
  37. package/src/commands/run/cli.js +24 -0
  38. package/src/commands/update/cli.js +3 -2
  39. package/src/utilities/completion.d.ts +22 -0
  40. package/src/utilities/completion.js +219 -0
  41. package/src/utilities/config.d.ts +4 -3
  42. package/src/utilities/config.js +11 -5
  43. package/src/utilities/environment-options.d.ts +1 -0
  44. package/src/utilities/environment-options.js +8 -1
  45. package/src/utilities/json-file.js +1 -0
  46. package/src/utilities/memoize.d.ts +15 -0
  47. package/src/utilities/memoize.js +69 -0
  48. package/src/utilities/package-manager.js +13 -2
  49. package/src/utilities/prompt.d.ts +2 -0
  50. package/src/utilities/prompt.js +18 -1
@@ -17,50 +17,58 @@ const cli_1 = require("../commands/add/cli");
17
17
  const cli_2 = require("../commands/analytics/cli");
18
18
  const cli_3 = require("../commands/build/cli");
19
19
  const cli_4 = require("../commands/cache/cli");
20
- const cli_5 = require("../commands/config/cli");
21
- const cli_6 = require("../commands/deploy/cli");
22
- const cli_7 = require("../commands/doc/cli");
23
- const cli_8 = require("../commands/e2e/cli");
24
- const cli_9 = require("../commands/extract-i18n/cli");
25
- const cli_10 = require("../commands/generate/cli");
26
- const cli_11 = require("../commands/lint/cli");
27
- const cli_12 = require("../commands/make-this-awesome/cli");
28
- const cli_13 = require("../commands/new/cli");
29
- const cli_14 = require("../commands/run/cli");
30
- const cli_15 = require("../commands/serve/cli");
31
- const cli_16 = require("../commands/test/cli");
32
- const cli_17 = require("../commands/update/cli");
33
- const cli_18 = require("../commands/version/cli");
20
+ const cli_5 = require("../commands/completion/cli");
21
+ const cli_6 = require("../commands/config/cli");
22
+ const cli_7 = require("../commands/deploy/cli");
23
+ const cli_8 = require("../commands/doc/cli");
24
+ const cli_9 = require("../commands/e2e/cli");
25
+ const cli_10 = require("../commands/extract-i18n/cli");
26
+ const cli_11 = require("../commands/generate/cli");
27
+ const cli_12 = require("../commands/lint/cli");
28
+ const cli_13 = require("../commands/make-this-awesome/cli");
29
+ const cli_14 = require("../commands/new/cli");
30
+ const cli_15 = require("../commands/run/cli");
31
+ const cli_16 = require("../commands/serve/cli");
32
+ const cli_17 = require("../commands/test/cli");
33
+ const cli_18 = require("../commands/update/cli");
34
+ const cli_19 = require("../commands/version/cli");
34
35
  const color_1 = require("../utilities/color");
35
36
  const config_1 = require("../utilities/config");
36
37
  const package_manager_1 = require("../utilities/package-manager");
37
38
  const command_module_1 = require("./command-module");
38
39
  const command_1 = require("./utilities/command");
39
40
  const json_help_1 = require("./utilities/json-help");
41
+ const normalize_options_middleware_1 = require("./utilities/normalize-options-middleware");
40
42
  const COMMANDS = [
41
- cli_18.VersionCommandModule,
42
- cli_7.DocCommandModule,
43
- cli_12.AwesomeCommandModule,
44
- cli_5.ConfigCommandModule,
43
+ cli_19.VersionCommandModule,
44
+ cli_8.DocCommandModule,
45
+ cli_13.AwesomeCommandModule,
46
+ cli_6.ConfigCommandModule,
45
47
  cli_2.AnalyticsCommandModule,
46
48
  cli_1.AddCommandModule,
47
- cli_10.GenerateCommandModule,
49
+ cli_11.GenerateCommandModule,
48
50
  cli_3.BuildCommandModule,
49
- cli_8.E2eCommandModule,
50
- cli_16.TestCommandModule,
51
- cli_15.ServeCommandModule,
52
- cli_9.ExtractI18nCommandModule,
53
- cli_6.DeployCommandModule,
54
- cli_11.LintCommandModule,
55
- cli_13.NewCommandModule,
56
- cli_17.UpdateCommandModule,
57
- cli_14.RunCommandModule,
51
+ cli_9.E2eCommandModule,
52
+ cli_17.TestCommandModule,
53
+ cli_16.ServeCommandModule,
54
+ cli_10.ExtractI18nCommandModule,
55
+ cli_7.DeployCommandModule,
56
+ cli_12.LintCommandModule,
57
+ cli_14.NewCommandModule,
58
+ cli_18.UpdateCommandModule,
59
+ cli_15.RunCommandModule,
58
60
  cli_4.CacheCommandModule,
61
+ cli_5.CompletionCommandModule,
59
62
  ].sort(); // Will be sorted by class name.
60
63
  const yargsParser = helpers_1.Parser;
61
64
  async function runCommand(args, logger) {
62
65
  var _a, _b;
63
- const { $0, _: positional, help = false, jsonHelp = false, ...rest } = yargsParser(args, { boolean: ['help', 'json-help'], alias: { 'collection': 'c' } });
66
+ const { $0, _, help = false, jsonHelp = false, getYargsCompletions = false, ...rest } = yargsParser(args, {
67
+ boolean: ['help', 'json-help', 'get-yargs-completions'],
68
+ alias: { 'collection': 'c' },
69
+ });
70
+ // When `getYargsCompletions` is true the scriptName 'ng' at index 0 is not removed.
71
+ const positional = getYargsCompletions ? _.slice(1) : _;
64
72
  let workspace;
65
73
  let globalConfiguration;
66
74
  try {
@@ -86,6 +94,7 @@ async function runCommand(args, logger) {
86
94
  options: {
87
95
  help,
88
96
  jsonHelp,
97
+ getYargsCompletions,
89
98
  ...rest,
90
99
  },
91
100
  },
@@ -103,7 +112,8 @@ async function runCommand(args, logger) {
103
112
  }
104
113
  if (jsonHelp) {
105
114
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
- localYargs.getInternalMethods().getUsageInstance().help = () => (0, json_help_1.jsonHelpUsage)();
115
+ const usageInstance = localYargs.getInternalMethods().getUsageInstance();
116
+ usageInstance.help = () => (0, json_help_1.jsonHelpUsage)();
107
117
  }
108
118
  await localYargs
109
119
  .scriptName('ng')
@@ -135,6 +145,7 @@ async function runCommand(args, logger) {
135
145
  })
136
146
  .demandCommand(1, command_1.demandCommandFailureMessage)
137
147
  .recommendCommands()
148
+ .middleware(normalize_options_middleware_1.normalizeOptionsMiddleware)
138
149
  .version(false)
139
150
  .showHelpOnFail(false)
140
151
  .strict()
@@ -27,11 +27,8 @@ export declare abstract class SchematicsCommandModule extends CommandModule<Sche
27
27
  builder(argv: Argv): Promise<Argv<SchematicsCommandArgs>>;
28
28
  /** Get schematic schema options.*/
29
29
  protected getSchematicOptions(collection: Collection<FileSystemCollectionDescription, FileSystemSchematicDescription>, schematicName: string, workflow: NodeWorkflow): Promise<Option[]>;
30
- private _workflowForBuilder;
31
30
  protected getOrCreateWorkflowForBuilder(collectionName: string): NodeWorkflow;
32
- private _workflowForExecution;
33
31
  protected getOrCreateWorkflowForExecution(collectionName: string, options: SchematicsExecutionOptions): Promise<NodeWorkflow>;
34
- private _schematicCollections;
35
32
  protected getSchematicCollections(): Promise<Set<string>>;
36
33
  protected parseSchematicInfo(schematic: string | undefined): [collectionName: string | undefined, schematicName: string | undefined];
37
34
  protected runSchematic(options: {
@@ -22,6 +22,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
22
22
  }) : function(o, v) {
23
23
  o["default"] = v;
24
24
  });
25
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
26
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
27
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
30
+ };
25
31
  var __importStar = (this && this.__importStar) || function (mod) {
26
32
  if (mod && mod.__esModule) return mod;
27
33
  var result = {};
@@ -35,6 +41,7 @@ const core_1 = require("@angular-devkit/core");
35
41
  const schematics_1 = require("@angular-devkit/schematics");
36
42
  const tools_1 = require("@angular-devkit/schematics/tools");
37
43
  const config_1 = require("../utilities/config");
44
+ const memoize_1 = require("../utilities/memoize");
38
45
  const tty_1 = require("../utilities/tty");
39
46
  const command_module_1 = require("./command-module");
40
47
  const json_schema_1 = require("./utilities/json-schema");
@@ -46,7 +53,6 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
46
53
  super(...arguments);
47
54
  this.allowPrivateSchematics = false;
48
55
  this.shouldReportAnalytics = false;
49
- this._workflowForBuilder = new Map();
50
56
  this.defaultProjectDeprecationWarningShown = false;
51
57
  }
52
58
  async builder(argv) {
@@ -83,21 +89,12 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
83
89
  return (0, json_schema_1.parseJsonSchemaToOptions)(workflow.registry, schemaJson);
84
90
  }
85
91
  getOrCreateWorkflowForBuilder(collectionName) {
86
- const cached = this._workflowForBuilder.get(collectionName);
87
- if (cached) {
88
- return cached;
89
- }
90
- const workflow = new tools_1.NodeWorkflow(this.context.root, {
92
+ return new tools_1.NodeWorkflow(this.context.root, {
91
93
  resolvePaths: this.getResolvePaths(collectionName),
92
94
  engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
93
95
  });
94
- this._workflowForBuilder.set(collectionName, workflow);
95
- return workflow;
96
96
  }
97
97
  async getOrCreateWorkflowForExecution(collectionName, options) {
98
- if (this._workflowForExecution) {
99
- return this._workflowForExecution;
100
- }
101
98
  const { logger, root, packageManager } = this.context;
102
99
  const { force, dryRun, packageRegistry } = options;
103
100
  const workflow = new tools_1.NodeWorkflow(root, {
@@ -112,9 +109,7 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
112
109
  optionTransforms: [
113
110
  // Add configuration file defaults
114
111
  async (schematic, current) => {
115
- const projectName = typeof current.project === 'string'
116
- ? current.project
117
- : this.getProjectName();
112
+ const projectName = typeof (current === null || current === void 0 ? void 0 : current.project) === 'string' ? current.project : this.getProjectName();
118
113
  return {
119
114
  ...(await (0, config_1.getSchematicDefaults)(schematic.collection.name, schematic.name, projectName)),
120
115
  ...current,
@@ -210,13 +205,10 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
210
205
  }
211
206
  });
212
207
  }
213
- return (this._workflowForExecution = workflow);
208
+ return workflow;
214
209
  }
215
210
  async getSchematicCollections() {
216
211
  var _a;
217
- if (this._schematicCollections) {
218
- return this._schematicCollections;
219
- }
220
212
  const getSchematicCollections = (configSection) => {
221
213
  if (!configSection) {
222
214
  return undefined;
@@ -236,18 +228,15 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
236
228
  if (project) {
237
229
  const value = getSchematicCollections(workspace.getProjectCli(project));
238
230
  if (value) {
239
- this._schematicCollections = value;
240
231
  return value;
241
232
  }
242
233
  }
243
234
  }
244
235
  const value = (_a = getSchematicCollections(workspace === null || workspace === void 0 ? void 0 : workspace.getCli())) !== null && _a !== void 0 ? _a : getSchematicCollections(globalConfiguration === null || globalConfiguration === void 0 ? void 0 : globalConfiguration.getCli());
245
236
  if (value) {
246
- this._schematicCollections = value;
247
237
  return value;
248
238
  }
249
- this._schematicCollections = new Set([exports.DEFAULT_SCHEMATICS_COLLECTION]);
250
- return this._schematicCollections;
239
+ return new Set([exports.DEFAULT_SCHEMATICS_COLLECTION]);
251
240
  }
252
241
  parseSchematicInfo(schematic) {
253
242
  if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
@@ -331,5 +320,14 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
331
320
  [__dirname, process.cwd()];
332
321
  }
333
322
  }
334
- exports.SchematicsCommandModule = SchematicsCommandModule;
335
323
  SchematicsCommandModule.scope = command_module_1.CommandScope.In;
324
+ __decorate([
325
+ memoize_1.memoize
326
+ ], SchematicsCommandModule.prototype, "getOrCreateWorkflowForBuilder", null);
327
+ __decorate([
328
+ memoize_1.memoize
329
+ ], SchematicsCommandModule.prototype, "getOrCreateWorkflowForExecution", null);
330
+ __decorate([
331
+ memoize_1.memoize
332
+ ], SchematicsCommandModule.prototype, "getSchematicCollections", null);
333
+ exports.SchematicsCommandModule = SchematicsCommandModule;
@@ -8,6 +8,6 @@
8
8
  import { Argv } from 'yargs';
9
9
  import { CommandContext, CommandModule, CommandModuleImplementation } from '../command-module';
10
10
  export declare const demandCommandFailureMessage = "You need to specify a command before moving on. Use '--help' to view the available commands.";
11
- export declare function addCommandModuleToYargs<T, U extends Partial<CommandModuleImplementation> & {
11
+ export declare function addCommandModuleToYargs<T extends object, U extends Partial<CommandModuleImplementation> & {
12
12
  new (context: CommandContext): Partial<CommandModuleImplementation> & CommandModule;
13
13
  }>(localYargs: Argv<T>, commandModule: U, context: CommandContext): Argv<T>;
@@ -0,0 +1,18 @@
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 * as yargs from 'yargs';
9
+ /**
10
+ * A Yargs middleware that normalizes non Array options when the argument has been provided multiple times.
11
+ *
12
+ * By default, when an option is non array and it is provided multiple times in the command line, yargs
13
+ * will not override it's value but instead it will be changed to an array unless `duplicate-arguments-array` is disabled.
14
+ * But this option also have an effect on real array options which isn't desired.
15
+ *
16
+ * See: https://github.com/yargs/yargs-parser/pull/163#issuecomment-516566614
17
+ */
18
+ export declare function normalizeOptionsMiddleware(args: yargs.Arguments): void;
@@ -0,0 +1,59 @@
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.normalizeOptionsMiddleware = void 0;
34
+ const yargs = __importStar(require("yargs"));
35
+ /**
36
+ * A Yargs middleware that normalizes non Array options when the argument has been provided multiple times.
37
+ *
38
+ * By default, when an option is non array and it is provided multiple times in the command line, yargs
39
+ * will not override it's value but instead it will be changed to an array unless `duplicate-arguments-array` is disabled.
40
+ * But this option also have an effect on real array options which isn't desired.
41
+ *
42
+ * See: https://github.com/yargs/yargs-parser/pull/163#issuecomment-516566614
43
+ */
44
+ function normalizeOptionsMiddleware(args) {
45
+ // `getOptions` is not included in the types even though it's public API.
46
+ // https://github.com/yargs/yargs/issues/2098
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ const { array } = yargs.getOptions();
49
+ const arrayOptions = new Set(array);
50
+ for (const [key, value] of Object.entries(args)) {
51
+ if (key !== '_' && Array.isArray(value) && !arrayOptions.has(key)) {
52
+ const newValue = value.pop();
53
+ // eslint-disable-next-line no-console
54
+ console.warn(`Option '${key}' has been specified multiple times. The value '${newValue}' will be used.`);
55
+ args[key] = newValue;
56
+ }
57
+ }
58
+ }
59
+ exports.normalizeOptionsMiddleware = normalizeOptionsMiddleware;
@@ -6,9 +6,9 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { RuleFactory } from '@angular-devkit/schematics';
9
- import { NodeModulesEngineHost } from '@angular-devkit/schematics/tools';
9
+ import { FileSystemCollectionDesc, NodeModulesEngineHost } from '@angular-devkit/schematics/tools';
10
10
  export declare class SchematicEngineHost extends NodeModulesEngineHost {
11
- protected _resolveReferenceString(refString: string, parentPath: string): {
11
+ protected _resolveReferenceString(refString: string, parentPath: string, collectionDescription?: FileSystemCollectionDesc): {
12
12
  ref: RuleFactory<{}>;
13
13
  path: string;
14
14
  } | null;
@@ -21,21 +21,18 @@ const path_1 = require("path");
21
21
  const vm_1 = require("vm");
22
22
  /**
23
23
  * Environment variable to control schematic package redirection
24
- * Default: Angular schematics only
25
24
  */
26
25
  const schematicRedirectVariable = (_a = process.env['NG_SCHEMATIC_REDIRECT']) === null || _a === void 0 ? void 0 : _a.toLowerCase();
27
- function shouldWrapSchematic(schematicFile) {
26
+ function shouldWrapSchematic(schematicFile, schematicEncapsulation) {
28
27
  // Check environment variable if present
29
- if (schematicRedirectVariable !== undefined) {
30
- switch (schematicRedirectVariable) {
31
- case '0':
32
- case 'false':
33
- case 'off':
34
- case 'none':
35
- return false;
36
- case 'all':
37
- return true;
38
- }
28
+ switch (schematicRedirectVariable) {
29
+ case '0':
30
+ case 'false':
31
+ case 'off':
32
+ case 'none':
33
+ return false;
34
+ case 'all':
35
+ return true;
39
36
  }
40
37
  const normalizedSchematicFile = schematicFile.replace(/\\/g, '/');
41
38
  // Never wrap the internal update schematic when executed directly
@@ -45,17 +42,21 @@ function shouldWrapSchematic(schematicFile) {
45
42
  !normalizedSchematicFile.includes('node_modules/@angular/cli/node_modules/')) {
46
43
  return false;
47
44
  }
48
- // Default is only first-party Angular schematic packages
45
+ // Check for first-party Angular schematic packages
49
46
  // Angular schematics are safe to use in the wrapped VM context
50
- return /\/node_modules\/@(?:angular|schematics|nguniversal)\//.test(normalizedSchematicFile);
47
+ if (/\/node_modules\/@(?:angular|schematics|nguniversal)\//.test(normalizedSchematicFile)) {
48
+ return true;
49
+ }
50
+ // Otherwise use the value of the schematic collection's encapsulation option (current default of false)
51
+ return schematicEncapsulation;
51
52
  }
52
53
  class SchematicEngineHost extends tools_1.NodeModulesEngineHost {
53
- _resolveReferenceString(refString, parentPath) {
54
+ _resolveReferenceString(refString, parentPath, collectionDescription) {
54
55
  const [path, name] = refString.split('#', 2);
55
56
  // Mimic behavior of ExportStringRef class used in default behavior
56
57
  const fullPath = path[0] === '.' ? (0, path_1.resolve)(parentPath !== null && parentPath !== void 0 ? parentPath : process.cwd(), path) : path;
57
58
  const schematicFile = require.resolve(fullPath, { paths: [parentPath] });
58
- if (shouldWrapSchematic(schematicFile)) {
59
+ if (shouldWrapSchematic(schematicFile, !!(collectionDescription === null || collectionDescription === void 0 ? void 0 : collectionDescription.encapsulation))) {
59
60
  const schematicPath = (0, path_1.dirname)(schematicFile);
60
61
  const moduleCache = new Map();
61
62
  const factoryInitializer = wrap(schematicFile, schematicPath, moduleCache, name || 'default');
@@ -66,7 +67,7 @@ class SchematicEngineHost extends tools_1.NodeModulesEngineHost {
66
67
  return { ref: factory, path: schematicPath };
67
68
  }
68
69
  // All other schematics use default behavior
69
- return super._resolveReferenceString(refString, parentPath);
70
+ return super._resolveReferenceString(refString, parentPath, collectionDescription);
70
71
  }
71
72
  }
72
73
  exports.SchematicEngineHost = SchematicEngineHost;
@@ -108,6 +109,15 @@ function wrap(schematicFile, schematicDirectory, moduleCache, exportName) {
108
109
  // Provide compatibility modules for older versions of @angular/cdk
109
110
  return legacyModules[id];
110
111
  }
112
+ else if (id.startsWith('schematics:')) {
113
+ // Schematics built-in modules use the `schematics` scheme (similar to the Node.js `node` scheme)
114
+ const builtinId = id.slice(11);
115
+ const builtinModule = loadBuiltinModule(builtinId);
116
+ if (!builtinModule) {
117
+ throw new Error(`Unknown schematics built-in module '${id}' requested from schematic '${schematicFile}'`);
118
+ }
119
+ return builtinModule;
120
+ }
111
121
  else if (id.startsWith('@angular-devkit/') || id.startsWith('@schematics/')) {
112
122
  // Files should not redirect `@angular/core` and instead use the direct
113
123
  // dependency if available. This allows old major version migrations to continue to function
@@ -151,7 +161,9 @@ function wrap(schematicFile, schematicDirectory, moduleCache, exportName) {
151
161
  const schematicCode = (0, fs_1.readFileSync)(schematicFile, 'utf8');
152
162
  // `module` is required due to @angular/localize ng-add being in UMD format
153
163
  const headerCode = '(function() {\nvar exports = {};\nvar module = { exports };\n';
154
- const footerCode = exportName ? `\nreturn exports['${exportName}'];});` : '\nreturn exports;});';
164
+ const footerCode = exportName
165
+ ? `\nreturn module.exports['${exportName}'];});`
166
+ : '\nreturn module.exports;});';
155
167
  const script = new vm_1.Script(headerCode + schematicCode + footerCode, {
156
168
  filename: schematicFile,
157
169
  lineOffset: 3,
@@ -170,3 +182,6 @@ function wrap(schematicFile, schematicDirectory, moduleCache, exportName) {
170
182
  const exportsFactory = script.runInNewContext(context);
171
183
  return exportsFactory;
172
184
  }
185
+ function loadBuiltinModule(id) {
186
+ return undefined;
187
+ }
@@ -30,7 +30,7 @@ class AnalyticsDisableModule extends AnalyticsSettingModule {
30
30
  this.describe = 'Disables analytics gathering and reporting for the user.';
31
31
  }
32
32
  async run({ global }) {
33
- (0, analytics_1.setAnalyticsConfig)(global, false);
33
+ await (0, analytics_1.setAnalyticsConfig)(global, false);
34
34
  process.stderr.write(await (0, analytics_1.getAnalyticsInfoString)());
35
35
  }
36
36
  }
@@ -43,7 +43,7 @@ class AnalyticsEnableModule extends AnalyticsSettingModule {
43
43
  this.describe = 'Enables analytics gathering and reporting for the user.';
44
44
  }
45
45
  async run({ global }) {
46
- (0, analytics_1.setAnalyticsConfig)(global, true);
46
+ await (0, analytics_1.setAnalyticsConfig)(global, true);
47
47
  process.stderr.write(await (0, analytics_1.getAnalyticsInfoString)());
48
48
  }
49
49
  }
@@ -14,7 +14,7 @@ export declare class CacheDisableModule extends CommandModule implements Command
14
14
  longDescriptionPath: string | undefined;
15
15
  static scope: CommandScope.In;
16
16
  builder(localYargs: Argv): Argv;
17
- run(): void;
17
+ run(): Promise<void>;
18
18
  }
19
19
  export declare class CacheEnableModule extends CommandModule implements CommandModuleImplementation {
20
20
  command: string;
@@ -23,5 +23,5 @@ export declare class CacheEnableModule extends CommandModule implements CommandM
23
23
  longDescriptionPath: string | undefined;
24
24
  static scope: CommandScope.In;
25
25
  builder(localYargs: Argv): Argv;
26
- run(): void;
26
+ run(): Promise<void>;
27
27
  }
@@ -21,7 +21,7 @@ class CacheDisableModule extends command_module_1.CommandModule {
21
21
  return localYargs;
22
22
  }
23
23
  run() {
24
- (0, utilities_1.updateCacheConfig)('enabled', false);
24
+ return (0, utilities_1.updateCacheConfig)(this.getWorkspaceOrThrow(), 'enabled', false);
25
25
  }
26
26
  }
27
27
  exports.CacheDisableModule = CacheDisableModule;
@@ -36,7 +36,7 @@ class CacheEnableModule extends command_module_1.CommandModule {
36
36
  return localYargs;
37
37
  }
38
38
  run() {
39
- (0, utilities_1.updateCacheConfig)('enabled', true);
39
+ return (0, utilities_1.updateCacheConfig)(this.getWorkspaceOrThrow(), 'enabled', true);
40
40
  }
41
41
  }
42
42
  exports.CacheEnableModule = CacheEnableModule;
@@ -7,5 +7,5 @@
7
7
  */
8
8
  import { Cache } from '../../../lib/config/workspace-schema';
9
9
  import { AngularWorkspace } from '../../utilities/config';
10
- export declare function updateCacheConfig<K extends keyof Cache>(key: K, value: Cache[K]): void;
10
+ export declare function updateCacheConfig<K extends keyof Cache>(workspace: AngularWorkspace, key: K, value: Cache[K]): Promise<void>;
11
11
  export declare function getCacheConfig(workspace: AngularWorkspace | undefined): Required<Cache>;
@@ -11,14 +11,13 @@ exports.getCacheConfig = exports.updateCacheConfig = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
12
  const path_1 = require("path");
13
13
  const workspace_schema_1 = require("../../../lib/config/workspace-schema");
14
- const config_1 = require("../../utilities/config");
15
- function updateCacheConfig(key, value) {
16
- const [localWorkspace] = (0, config_1.getWorkspaceRaw)('local');
17
- if (!localWorkspace) {
18
- throw new Error('Cannot find workspace configuration file.');
19
- }
20
- localWorkspace.modify(['cli', 'cache', key], value);
21
- localWorkspace.save();
14
+ function updateCacheConfig(workspace, key, value) {
15
+ var _a, _b;
16
+ var _c;
17
+ const cli = ((_a = (_c = workspace.extensions)['cli']) !== null && _a !== void 0 ? _a : (_c['cli'] = {}));
18
+ const cache = ((_b = cli['cache']) !== null && _b !== void 0 ? _b : (cli['cache'] = {}));
19
+ cache[key] = value;
20
+ return workspace.save();
22
21
  }
23
22
  exports.updateCacheConfig = updateCacheConfig;
24
23
  function getCacheConfig(workspace) {
@@ -0,0 +1,16 @@
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 { Argv } from 'yargs';
9
+ import { CommandModule, CommandModuleImplementation } from '../../command-builder/command-module';
10
+ export declare class CompletionCommandModule extends CommandModule implements CommandModuleImplementation {
11
+ command: string;
12
+ describe: string;
13
+ longDescriptionPath: string;
14
+ builder(localYargs: Argv): Argv;
15
+ run(): Promise<number>;
16
+ }
@@ -0,0 +1,61 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.CompletionCommandModule = void 0;
14
+ const path_1 = require("path");
15
+ const yargs_1 = __importDefault(require("yargs"));
16
+ const command_module_1 = require("../../command-builder/command-module");
17
+ const command_1 = require("../../command-builder/utilities/command");
18
+ const color_1 = require("../../utilities/color");
19
+ const completion_1 = require("../../utilities/completion");
20
+ class CompletionCommandModule extends command_module_1.CommandModule {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.command = 'completion';
24
+ this.describe = 'Set up Angular CLI autocompletion for your terminal.';
25
+ this.longDescriptionPath = (0, path_1.join)(__dirname, 'long-description.md');
26
+ }
27
+ builder(localYargs) {
28
+ return (0, command_1.addCommandModuleToYargs)(localYargs, CompletionScriptCommandModule, this.context);
29
+ }
30
+ async run() {
31
+ let rcFile;
32
+ try {
33
+ rcFile = await (0, completion_1.initializeAutocomplete)();
34
+ }
35
+ catch (err) {
36
+ this.context.logger.error(err.message);
37
+ return 1;
38
+ }
39
+ this.context.logger.info(`
40
+ Appended \`source <(ng completion script)\` to \`${rcFile}\`. Restart your terminal or run the following to autocomplete \`ng\` commands:
41
+
42
+ ${color_1.colors.yellow('source <(ng completion script)')}
43
+ `.trim());
44
+ return 0;
45
+ }
46
+ }
47
+ exports.CompletionCommandModule = CompletionCommandModule;
48
+ class CompletionScriptCommandModule extends command_module_1.CommandModule {
49
+ constructor() {
50
+ super(...arguments);
51
+ this.command = 'script';
52
+ this.describe = 'Generate a bash and zsh real-time type-ahead autocompletion script.';
53
+ this.longDescriptionPath = undefined;
54
+ }
55
+ builder(localYargs) {
56
+ return localYargs;
57
+ }
58
+ run() {
59
+ yargs_1.default.showCompletionScript();
60
+ }
61
+ }
@@ -0,0 +1,5 @@
1
+ To enable Bash and Zsh real-time type-ahead autocompletion, run
2
+ `ng completion` and restart your terminal.
3
+
4
+ Alternatively, append `source <(ng completion script)` to the appropriate `.bashrc`,
5
+ `.bash_profile`, `.zshrc`, `.zsh_profile`, or `.profile` file.