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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/cli/index.d.ts +0 -1
  2. package/lib/cli/index.js +3 -30
  3. package/lib/config/schema.json +22 -3
  4. package/lib/config/workspace-schema.d.ts +5 -0
  5. package/lib/init.js +2 -5
  6. package/package.json +19 -22
  7. package/src/analytics/analytics-collector.js +2 -0
  8. package/src/analytics/analytics.d.ts +1 -1
  9. package/src/analytics/analytics.js +39 -36
  10. package/src/command-builder/architect-base-command-module.d.ts +8 -1
  11. package/src/command-builder/architect-base-command-module.js +65 -3
  12. package/src/command-builder/architect-command-module.d.ts +4 -1
  13. package/src/command-builder/architect-command-module.js +40 -14
  14. package/src/command-builder/command-module.d.ts +4 -3
  15. package/src/command-builder/command-module.js +14 -7
  16. package/src/command-builder/command-runner.d.ts +1 -2
  17. package/src/command-builder/command-runner.js +69 -36
  18. package/src/command-builder/schematics-command-module.d.ts +3 -4
  19. package/src/command-builder/schematics-command-module.js +88 -48
  20. package/src/command-builder/utilities/normalize-options-middleware.d.ts +18 -0
  21. package/src/command-builder/utilities/normalize-options-middleware.js +59 -0
  22. package/src/command-builder/utilities/schematic-engine-host.d.ts +2 -2
  23. package/src/command-builder/utilities/schematic-engine-host.js +30 -17
  24. package/src/commands/add/cli.js +14 -14
  25. package/src/commands/add/long-description.md +1 -4
  26. package/src/commands/analytics/cli.d.ts +1 -1
  27. package/src/commands/analytics/info/cli.d.ts +1 -1
  28. package/src/commands/analytics/settings/cli.d.ts +1 -1
  29. package/src/commands/analytics/settings/cli.js +2 -2
  30. package/src/commands/cache/clean/cli.d.ts +17 -0
  31. package/src/commands/cache/clean/cli.js +32 -0
  32. package/src/commands/cache/cli.d.ts +17 -0
  33. package/src/commands/cache/cli.js +38 -0
  34. package/src/commands/cache/info/cli.d.ts +20 -0
  35. package/src/commands/cache/info/cli.js +82 -0
  36. package/src/commands/cache/long-description.md +53 -0
  37. package/src/commands/cache/settings/cli.d.ts +27 -0
  38. package/src/commands/cache/settings/cli.js +42 -0
  39. package/src/commands/cache/utilities.d.ts +11 -0
  40. package/src/commands/cache/utilities.js +49 -0
  41. package/src/commands/completion/cli.d.ts +16 -0
  42. package/src/commands/completion/cli.js +31 -0
  43. package/src/commands/completion/long-description.md +1 -0
  44. package/src/commands/config/cli.d.ts +1 -1
  45. package/src/commands/config/cli.js +15 -15
  46. package/src/commands/deploy/cli.d.ts +2 -1
  47. package/src/commands/deploy/cli.js +27 -13
  48. package/src/commands/doc/cli.d.ts +1 -1
  49. package/src/commands/e2e/cli.d.ts +3 -2
  50. package/src/commands/e2e/cli.js +14 -13
  51. package/src/commands/generate/cli.d.ts +11 -1
  52. package/src/commands/generate/cli.js +54 -23
  53. package/src/commands/lint/cli.d.ts +2 -1
  54. package/src/commands/lint/cli.js +6 -9
  55. package/src/commands/new/cli.d.ts +2 -0
  56. package/src/commands/new/cli.js +22 -6
  57. package/src/commands/run/cli.d.ts +2 -0
  58. package/src/commands/run/cli.js +24 -0
  59. package/src/commands/update/cli.d.ts +1 -0
  60. package/src/commands/update/cli.js +53 -23
  61. package/src/commands/update/schematic/index.js +27 -18
  62. package/src/commands/version/cli.d.ts +0 -1
  63. package/src/commands/version/cli.js +4 -23
  64. package/src/typings-bazel.d.ts +14 -0
  65. package/src/typings.d.ts +0 -13
  66. package/src/utilities/config.d.ts +5 -5
  67. package/src/utilities/config.js +27 -44
  68. package/src/{analytics/analytics-environment-options.d.ts → utilities/environment-options.d.ts} +3 -0
  69. package/src/utilities/environment-options.js +24 -0
  70. package/src/utilities/memoize.d.ts +15 -0
  71. package/src/utilities/memoize.js +69 -0
  72. package/src/utilities/package-manager.d.ts +33 -5
  73. package/src/utilities/package-manager.js +252 -71
  74. package/src/utilities/package-metadata.d.ts +15 -37
  75. package/src/utilities/package-metadata.js +10 -26
  76. package/src/utilities/package-tree.d.ts +2 -2
  77. package/src/utilities/prompt.d.ts +2 -0
  78. package/src/utilities/prompt.js +20 -3
  79. package/bin/postinstall/analytics-prompt.js +0 -27
  80. package/bin/postinstall/script.js +0 -16
  81. package/src/analytics/analytics-environment-options.js +0 -20
  82. package/src/utilities/install-package.d.ts +0 -16
  83. package/src/utilities/install-package.js +0 -193
  84. package/src/utilities/package-json.d.ts +0 -249
  85. package/src/utilities/package-json.js +0 -9
@@ -7,6 +7,5 @@
7
7
  */
8
8
  export { VERSION } from '../../src/utilities/version';
9
9
  export default function (options: {
10
- testing?: boolean;
11
10
  cliArgs: string[];
12
11
  }): Promise<number>;
package/lib/cli/index.js CHANGED
@@ -13,13 +13,10 @@ const util_1 = require("util");
13
13
  const command_module_1 = require("../../src/command-builder/command-module");
14
14
  const command_runner_1 = require("../../src/command-builder/command-runner");
15
15
  const color_1 = require("../../src/utilities/color");
16
- const config_1 = require("../../src/utilities/config");
16
+ const environment_options_1 = require("../../src/utilities/environment-options");
17
17
  const log_file_1 = require("../../src/utilities/log-file");
18
- const project_1 = require("../../src/utilities/project");
19
18
  var version_1 = require("../../src/utilities/version");
20
19
  Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
21
- const debugEnv = process.env['NG_DEBUG'];
22
- const isDebug = debugEnv !== undefined && debugEnv !== '0' && debugEnv.toLowerCase() !== 'false';
23
20
  /* eslint-disable no-console */
24
21
  async function default_1(options) {
25
22
  // This node version check ensures that the requirements of the project instance of the CLI are met
@@ -30,7 +27,7 @@ async function default_1(options) {
30
27
  'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n');
31
28
  return 3;
32
29
  }
33
- const logger = (0, node_1.createConsoleLogger)(isDebug, process.stdout, process.stderr, {
30
+ const logger = (0, node_1.createConsoleLogger)(environment_options_1.ngDebug, process.stdout, process.stderr, {
34
31
  info: (s) => (color_1.colors.enabled ? s : (0, color_1.removeColor)(s)),
35
32
  debug: (s) => (color_1.colors.enabled ? s : (0, color_1.removeColor)(s)),
36
33
  warn: (s) => (color_1.colors.enabled ? color_1.colors.bold.yellow(s) : (0, color_1.removeColor)(s)),
@@ -47,27 +44,8 @@ async function default_1(options) {
47
44
  console.error = function (...args) {
48
45
  logger.error((0, util_1.format)(...args));
49
46
  };
50
- let workspace;
51
- const workspaceFile = (0, project_1.findWorkspaceFile)();
52
- if (workspaceFile === null) {
53
- const [, localPath] = (0, config_1.getWorkspaceRaw)('local');
54
- if (localPath !== null) {
55
- logger.fatal(`An invalid configuration file was found ['${localPath}'].` +
56
- ' Please delete the file before running the command.');
57
- return 1;
58
- }
59
- }
60
- else {
61
- try {
62
- workspace = await config_1.AngularWorkspace.load(workspaceFile);
63
- }
64
- catch (e) {
65
- logger.fatal(`Unable to read workspace file '${workspaceFile}': ${e.message}`);
66
- return 1;
67
- }
68
- }
69
47
  try {
70
- return await (0, command_runner_1.runCommand)(options.cliArgs, logger, workspace);
48
+ return await (0, command_runner_1.runCommand)(options.cliArgs, logger);
71
49
  }
72
50
  catch (err) {
73
51
  if (err instanceof command_module_1.CommandModuleError) {
@@ -97,11 +75,6 @@ async function default_1(options) {
97
75
  else {
98
76
  logger.fatal('An unexpected error occurred: ' + JSON.stringify(err));
99
77
  }
100
- if (options.testing) {
101
- // eslint-disable-next-line no-debugger
102
- debugger;
103
- throw err;
104
- }
105
78
  return 1;
106
79
  }
107
80
  }
@@ -22,7 +22,8 @@
22
22
  },
23
23
  "defaultProject": {
24
24
  "type": "string",
25
- "description": "Default project name used in commands."
25
+ "description": "Default project name used in commands.",
26
+ "x-deprecated": "The project to use will be determined from the current working directory."
26
27
  },
27
28
  "projects": {
28
29
  "type": "object",
@@ -44,7 +45,16 @@
44
45
  "properties": {
45
46
  "defaultCollection": {
46
47
  "description": "The default schematics collection to use.",
47
- "type": "string"
48
+ "type": "string",
49
+ "x-deprecated": "Use 'schematicCollections' instead."
50
+ },
51
+ "schematicCollections": {
52
+ "type": "array",
53
+ "description": "The list of schematic collections to use.",
54
+ "items": {
55
+ "type": "string",
56
+ "uniqueItems": true
57
+ }
48
58
  },
49
59
  "packageManager": {
50
60
  "description": "Specify which package manager tool to use.",
@@ -175,7 +185,16 @@
175
185
  "cli": {
176
186
  "defaultCollection": {
177
187
  "description": "The default schematics collection to use.",
178
- "type": "string"
188
+ "type": "string",
189
+ "x-deprecated": "Use 'schematicCollections' instead."
190
+ },
191
+ "schematicCollections": {
192
+ "type": "array",
193
+ "description": "The list of schematic collections to use.",
194
+ "items": {
195
+ "type": "string",
196
+ "uniqueItems": true
197
+ }
179
198
  }
180
199
  },
181
200
  "schematics": {
@@ -3,6 +3,7 @@ export interface Schema {
3
3
  cli?: CliOptions;
4
4
  /**
5
5
  * Default project name used in commands.
6
+ * @deprecated The project to use will be determined from the current working directory.
6
7
  */
7
8
  defaultProject?: string;
8
9
  /**
@@ -31,6 +32,10 @@ export interface CliOptions {
31
32
  * Specify which package manager tool to use.
32
33
  */
33
34
  packageManager?: PackageManager;
35
+ /**
36
+ * The list of schematic collections to use.
37
+ */
38
+ schematicCollections?: string[];
34
39
  /**
35
40
  * Control CLI specific console warnings
36
41
  */
package/lib/init.js CHANGED
@@ -37,6 +37,7 @@ const path = __importStar(require("path"));
37
37
  const semver_1 = require("semver");
38
38
  const color_1 = require("../src/utilities/color");
39
39
  const config_1 = require("../src/utilities/config");
40
+ const environment_options_1 = require("../src/utilities/environment-options");
40
41
  const version_1 = require("../src/utilities/version");
41
42
  (async () => {
42
43
  var _a;
@@ -47,15 +48,11 @@ const version_1 = require("../src/utilities/version");
47
48
  * See: https://github.com/browserslist/browserslist/blob/819c4337456996d19db6ba953014579329e9c6e1/node.js#L324
48
49
  */
49
50
  process.env.BROWSERSLIST_IGNORE_OLD_DATA = '1';
50
- const disableVersionCheckEnv = process.env['NG_DISABLE_VERSION_CHECK'];
51
51
  /**
52
52
  * Disable CLI version mismatch checks and forces usage of the invoked CLI
53
53
  * instead of invoking the local installed version.
54
54
  */
55
- const disableVersionCheck = disableVersionCheckEnv !== undefined &&
56
- disableVersionCheckEnv !== '0' &&
57
- disableVersionCheckEnv.toLowerCase() !== 'false';
58
- if (disableVersionCheck) {
55
+ if (environment_options_1.disableVersionCheck) {
59
56
  return (await Promise.resolve().then(() => __importStar(require('./cli')))).default;
60
57
  }
61
58
  let cli;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular/cli",
3
- "version": "14.0.0-next.6",
3
+ "version": "14.0.0-next.9",
4
4
  "description": "CLI tool for Angular",
5
5
  "main": "lib/cli/index.js",
6
6
  "bin": {
@@ -14,9 +14,6 @@
14
14
  "Angular DevKit",
15
15
  "angular-cli"
16
16
  ],
17
- "scripts": {
18
- "postinstall": "node ./bin/postinstall/script.js"
19
- },
20
17
  "repository": {
21
18
  "type": "git",
22
19
  "url": "https://github.com/angular/angular-cli.git"
@@ -28,36 +25,36 @@
28
25
  },
29
26
  "homepage": "https://github.com/angular/angular-cli",
30
27
  "dependencies": {
31
- "@angular-devkit/architect": "0.1400.0-next.6",
32
- "@angular-devkit/core": "14.0.0-next.6",
33
- "@angular-devkit/schematics": "14.0.0-next.6",
34
- "@schematics/angular": "14.0.0-next.6",
28
+ "@angular-devkit/architect": "0.1400.0-next.9",
29
+ "@angular-devkit/core": "14.0.0-next.9",
30
+ "@angular-devkit/schematics": "14.0.0-next.9",
31
+ "@schematics/angular": "14.0.0-next.9",
35
32
  "@yarnpkg/lockfile": "1.1.0",
36
33
  "ansi-colors": "4.1.1",
37
- "debug": "4.3.3",
38
- "ini": "2.0.0",
39
- "inquirer": "8.2.1",
34
+ "debug": "4.3.4",
35
+ "ini": "3.0.0",
36
+ "inquirer": "8.2.2",
40
37
  "jsonc-parser": "3.0.0",
41
- "npm-package-arg": "9.0.1",
42
- "npm-pick-manifest": "7.0.0",
38
+ "npm-package-arg": "9.0.2",
39
+ "npm-pick-manifest": "7.0.1",
43
40
  "open": "8.4.0",
44
41
  "ora": "5.4.1",
45
- "pacote": "13.0.5",
42
+ "pacote": "13.1.1",
46
43
  "resolve": "1.22.0",
47
- "semver": "7.3.5",
44
+ "semver": "7.3.6",
48
45
  "symbol-observable": "4.0.0",
49
46
  "uuid": "8.3.2",
50
- "yargs": "17.3.1"
47
+ "yargs": "17.4.1"
51
48
  },
52
49
  "ng-update": {
53
50
  "migrations": "@schematics/angular/migrations/migration-collection.json",
54
51
  "packageGroup": {
55
- "@angular/cli": "14.0.0-next.6",
56
- "@angular-devkit/architect": "0.1400.0-next.6",
57
- "@angular-devkit/build-angular": "14.0.0-next.6",
58
- "@angular-devkit/build-webpack": "0.1400.0-next.6",
59
- "@angular-devkit/core": "14.0.0-next.6",
60
- "@angular-devkit/schematics": "14.0.0-next.6"
52
+ "@angular/cli": "14.0.0-next.9",
53
+ "@angular-devkit/architect": "0.1400.0-next.9",
54
+ "@angular-devkit/build-angular": "14.0.0-next.9",
55
+ "@angular-devkit/build-webpack": "0.1400.0-next.9",
56
+ "@angular-devkit/core": "14.0.0-next.9",
57
+ "@angular-devkit/schematics": "14.0.0-next.9"
61
58
  }
62
59
  },
63
60
  "engines": {
@@ -72,6 +72,8 @@ class AnalyticsCollector {
72
72
  this.parameters['cd' + core_1.analytics.NgCliAnalyticsDimensions.CpuSpeed] = Math.floor(os.cpus()[0].speed);
73
73
  this.parameters['cd' + core_1.analytics.NgCliAnalyticsDimensions.RamInGigabytes] = Math.round(os.totalmem() / (1024 * 1024 * 1024));
74
74
  this.parameters['cd' + core_1.analytics.NgCliAnalyticsDimensions.NodeVersion] = nodeVersion;
75
+ this.parameters['cd' + core_1.analytics.NgCliAnalyticsDimensions.AngularCLIMajorVersion] =
76
+ version_1.VERSION.major;
75
77
  }
76
78
  event(ec, ea, options = {}) {
77
79
  const { label: el, value: ev, metrics, dimensions } = options;
@@ -22,7 +22,7 @@ export declare function isPackageNameSafeForAnalytics(name: string): boolean;
22
22
  * @param global Which config to use. "global" for user-level, and "local" for project-level.
23
23
  * @param value Either a user ID, true to generate a new User ID, or false to disable analytics.
24
24
  */
25
- export declare function setAnalyticsConfig(global: boolean, value: string | boolean): void;
25
+ export declare function setAnalyticsConfig(global: boolean, value: string | boolean): Promise<void>;
26
26
  /**
27
27
  * Prompt the user for usage gathering permission.
28
28
  * @param force Whether to ask regardless of whether or not the user is using an interactive shell.
@@ -36,14 +36,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.getAnalyticsInfoString = exports.createAnalytics = exports.getSharedAnalytics = exports.getAnalytics = exports.promptAnalytics = exports.setAnalyticsConfig = exports.isPackageNameSafeForAnalytics = exports.analyticsPackageSafelist = exports.AnalyticsProperties = void 0;
37
37
  const core_1 = require("@angular-devkit/core");
38
38
  const debug_1 = __importDefault(require("debug"));
39
- const inquirer = __importStar(require("inquirer"));
40
39
  const uuid_1 = require("uuid");
41
40
  const color_1 = require("../utilities/color");
42
41
  const config_1 = require("../utilities/config");
42
+ const environment_options_1 = require("../utilities/environment-options");
43
43
  const tty_1 = require("../utilities/tty");
44
44
  const version_1 = require("../utilities/version");
45
45
  const analytics_collector_1 = require("./analytics-collector");
46
- const analytics_environment_options_1 = require("./analytics-environment-options");
47
46
  /* eslint-disable no-console */
48
47
  const analyticsDebug = (0, debug_1.default)('ng:analytics'); // Generate analytics, including settings and users.
49
48
  let _defaultAngularCliPropertyCache;
@@ -88,22 +87,21 @@ exports.isPackageNameSafeForAnalytics = isPackageNameSafeForAnalytics;
88
87
  * @param global Which config to use. "global" for user-level, and "local" for project-level.
89
88
  * @param value Either a user ID, true to generate a new User ID, or false to disable analytics.
90
89
  */
91
- function setAnalyticsConfig(global, value) {
90
+ async function setAnalyticsConfig(global, value) {
91
+ var _a;
92
+ var _b;
92
93
  const level = global ? 'global' : 'local';
93
94
  analyticsDebug('setting %s level analytics to: %s', level, value);
94
- const [config, configPath] = (0, config_1.getWorkspaceRaw)(level);
95
- if (!config || !configPath) {
95
+ const workspace = await (0, config_1.getWorkspace)(level);
96
+ if (!workspace) {
96
97
  throw new Error(`Could not find ${level} workspace.`);
97
98
  }
98
- const cli = config.get(['cli']);
99
- if (cli !== undefined && !core_1.json.isJsonObject(cli)) {
100
- throw new Error(`Invalid config found at ${configPath}. CLI should be an object.`);
101
- }
102
- if (value === true) {
103
- value = (0, uuid_1.v4)();
99
+ const cli = ((_a = (_b = workspace.extensions)['cli']) !== null && _a !== void 0 ? _a : (_b['cli'] = {}));
100
+ if (!workspace || !core_1.json.isJsonObject(cli)) {
101
+ throw new Error(`Invalid config found at ${workspace.filePath}. CLI should be an object.`);
104
102
  }
105
- config.modify(['cli', 'analytics'], value);
106
- config.save();
103
+ cli.analytics = value === true ? (0, uuid_1.v4)() : value;
104
+ await workspace.save();
107
105
  analyticsDebug('done');
108
106
  }
109
107
  exports.setAnalyticsConfig = setAnalyticsConfig;
@@ -115,12 +113,13 @@ exports.setAnalyticsConfig = setAnalyticsConfig;
115
113
  async function promptAnalytics(global, force = false) {
116
114
  analyticsDebug('prompting user');
117
115
  const level = global ? 'global' : 'local';
118
- const [config, configPath] = (0, config_1.getWorkspaceRaw)(level);
119
- if (!config || !configPath) {
116
+ const workspace = await (0, config_1.getWorkspace)(level);
117
+ if (!workspace) {
120
118
  throw new Error(`Could not find a ${level} workspace. Are you in a project?`);
121
119
  }
122
120
  if (force || (0, tty_1.isTTY)()) {
123
- const answers = await inquirer.prompt([
121
+ const { prompt } = await Promise.resolve().then(() => __importStar(require('inquirer')));
122
+ const answers = await prompt([
124
123
  {
125
124
  type: 'confirm',
126
125
  name: 'analytics',
@@ -133,7 +132,7 @@ async function promptAnalytics(global, force = false) {
133
132
  default: false,
134
133
  },
135
134
  ]);
136
- setAnalyticsConfig(global, answers.analytics);
135
+ await setAnalyticsConfig(global, answers.analytics);
137
136
  if (answers.analytics) {
138
137
  console.log('');
139
138
  console.log(core_1.tags.stripIndent `
@@ -169,14 +168,15 @@ exports.promptAnalytics = promptAnalytics;
169
168
  * - `undefined` when not configured.
170
169
  */
171
170
  async function getAnalytics(level) {
171
+ var _a;
172
172
  analyticsDebug('getAnalytics');
173
- if (analytics_environment_options_1.analyticsDisabled) {
173
+ if (environment_options_1.analyticsDisabled) {
174
174
  analyticsDebug('NG_CLI_ANALYTICS is false');
175
175
  return new core_1.analytics.NoopAnalytics();
176
176
  }
177
177
  try {
178
178
  const workspace = await (0, config_1.getWorkspace)(level);
179
- const analyticsConfig = workspace === null || workspace === void 0 ? void 0 : workspace.getCli()['analytics'];
179
+ const analyticsConfig = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.getCli()) === null || _a === void 0 ? void 0 : _a['analytics'];
180
180
  analyticsDebug('Workspace Analytics config found: %j', analyticsConfig);
181
181
  if (analyticsConfig === false) {
182
182
  return new core_1.analytics.NoopAnalytics();
@@ -210,15 +210,16 @@ exports.getAnalytics = getAnalytics;
210
210
  * or undefined if no sharing.
211
211
  */
212
212
  async function getSharedAnalytics() {
213
+ var _a;
213
214
  analyticsDebug('getSharedAnalytics');
214
- if (analytics_environment_options_1.analyticsShareDisabled) {
215
+ if (environment_options_1.analyticsShareDisabled) {
215
216
  analyticsDebug('NG_CLI_ANALYTICS is false');
216
217
  return undefined;
217
218
  }
218
219
  // If anything happens we just keep the NOOP analytics.
219
220
  try {
220
221
  const globalWorkspace = await (0, config_1.getWorkspace)('global');
221
- const analyticsConfig = globalWorkspace === null || globalWorkspace === void 0 ? void 0 : globalWorkspace.getCli()['analyticsSharing'];
222
+ const analyticsConfig = (_a = globalWorkspace === null || globalWorkspace === void 0 ? void 0 : globalWorkspace.getCli()) === null || _a === void 0 ? void 0 : _a['analyticsSharing'];
222
223
  if (!analyticsConfig || !analyticsConfig.tracking || !analyticsConfig.uuid) {
223
224
  return undefined;
224
225
  }
@@ -245,25 +246,26 @@ async function createAnalytics(workspace, skipPrompt = false) {
245
246
  return globalConfig;
246
247
  }
247
248
  let config = globalConfig;
248
- // Not disabled globally, check locally.
249
- if (workspace) {
250
- let localConfig = await getAnalytics('local');
251
- if (localConfig === undefined) {
249
+ // Not disabled globally, check locally or not set globally and command is run outside of workspace example: `ng new`
250
+ if (workspace || globalConfig === undefined) {
251
+ const level = workspace ? 'local' : 'global';
252
+ let localOrGlobalConfig = await getAnalytics(level);
253
+ if (localOrGlobalConfig === undefined) {
252
254
  if (!skipPrompt) {
253
- // local is not unset, prompt user.
255
+ // config is unset, prompt user.
254
256
  // TODO: This should honor the `no-interactive` option.
255
257
  // It is currently not an `ng` option but rather only an option for specific commands.
256
258
  // The concept of `ng`-wide options are needed to cleanly handle this.
257
- await promptAnalytics(false);
258
- localConfig = await getAnalytics('local');
259
+ await promptAnalytics(!workspace /** global */);
260
+ localOrGlobalConfig = await getAnalytics(level);
259
261
  }
260
262
  }
261
- if (localConfig instanceof core_1.analytics.NoopAnalytics) {
262
- return localConfig;
263
+ if (localOrGlobalConfig instanceof core_1.analytics.NoopAnalytics) {
264
+ return localOrGlobalConfig;
263
265
  }
264
- else if (localConfig) {
266
+ else if (localOrGlobalConfig) {
265
267
  // Favor local settings over global when defined.
266
- config = localConfig;
268
+ config = localOrGlobalConfig;
267
269
  }
268
270
  }
269
271
  // Get shared analytics
@@ -287,10 +289,11 @@ function analyticsConfigValueToHumanFormat(value) {
287
289
  }
288
290
  }
289
291
  async function getAnalyticsInfoString() {
290
- const [globalWorkspace] = (0, config_1.getWorkspaceRaw)('global');
291
- const [localWorkspace] = (0, config_1.getWorkspaceRaw)('local');
292
- const globalSetting = globalWorkspace === null || globalWorkspace === void 0 ? void 0 : globalWorkspace.get(['cli', 'analytics']);
293
- const localSetting = localWorkspace === null || localWorkspace === void 0 ? void 0 : localWorkspace.get(['cli', 'analytics']);
292
+ var _a, _b;
293
+ const globalWorkspace = await (0, config_1.getWorkspace)('global');
294
+ const localWorkspace = await (0, config_1.getWorkspace)('local');
295
+ const globalSetting = (_a = globalWorkspace === null || globalWorkspace === void 0 ? void 0 : globalWorkspace.getCli()) === null || _a === void 0 ? void 0 : _a['analytics'];
296
+ const localSetting = (_b = localWorkspace === null || localWorkspace === void 0 ? void 0 : localWorkspace.getCli()) === null || _b === void 0 ? void 0 : _b['analytics'];
294
297
  const analyticsInstance = await createAnalytics(!!localWorkspace /** workspace */, true /** skipPrompt */);
295
298
  return (core_1.tags.stripIndents `
296
299
  Global setting: ${analyticsConfigValueToHumanFormat(globalSetting)}
@@ -9,10 +9,14 @@ import { Architect, Target } from '@angular-devkit/architect';
9
9
  import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node';
10
10
  import { CommandModule, CommandModuleImplementation, CommandScope, OtherOptions } from './command-module';
11
11
  import { Option } from './utilities/json-schema';
12
+ export interface MissingTargetChoice {
13
+ name: string;
14
+ value: string;
15
+ }
12
16
  export declare abstract class ArchitectBaseCommandModule<T> extends CommandModule<T> implements CommandModuleImplementation<T> {
13
17
  static scope: CommandScope;
14
18
  protected shouldReportAnalytics: boolean;
15
- protected readonly missingErrorTarget: string | undefined;
19
+ protected readonly missingTargetChoices: MissingTargetChoice[] | undefined;
16
20
  protected runSingleTarget(target: Target, options: OtherOptions): Promise<number>;
17
21
  private _architectHost;
18
22
  protected getArchitectHost(): WorkspaceNodeModulesArchitectHost;
@@ -20,4 +24,7 @@ export declare abstract class ArchitectBaseCommandModule<T> extends CommandModul
20
24
  protected getArchitect(): Architect;
21
25
  protected getArchitectTargetOptions(target: Target): Promise<Option[]>;
22
26
  private warnOnMissingNodeModules;
27
+ protected getArchitectTarget(): string;
28
+ protected onMissingTarget(defaultMessage: string): Promise<1>;
29
+ private getMissingTargetPackageToInstall;
23
30
  }
@@ -11,9 +11,12 @@ exports.ArchitectBaseCommandModule = void 0;
11
11
  const architect_1 = require("@angular-devkit/architect");
12
12
  const node_1 = require("@angular-devkit/architect/node");
13
13
  const core_1 = require("@angular-devkit/core");
14
+ const child_process_1 = require("child_process");
14
15
  const fs_1 = require("fs");
15
16
  const path_1 = require("path");
16
17
  const analytics_1 = require("../analytics/analytics");
18
+ const prompt_1 = require("../utilities/prompt");
19
+ const tty_1 = require("../utilities/tty");
17
20
  const command_module_1 = require("./command-module");
18
21
  const json_schema_1 = require("./utilities/json-schema");
19
22
  class ArchitectBaseCommandModule extends command_module_1.CommandModule {
@@ -22,14 +25,13 @@ class ArchitectBaseCommandModule extends command_module_1.CommandModule {
22
25
  this.shouldReportAnalytics = false;
23
26
  }
24
27
  async runSingleTarget(target, options) {
25
- var _a;
26
28
  const architectHost = await this.getArchitectHost();
27
29
  let builderName;
28
30
  try {
29
31
  builderName = await architectHost.getBuilderNameForTarget(target);
30
32
  }
31
33
  catch (e) {
32
- throw new command_module_1.CommandModuleError((_a = this.missingErrorTarget) !== null && _a !== void 0 ? _a : e.message);
34
+ return this.onMissingTarget(e.message);
33
35
  }
34
36
  await this.reportAnalytics({
35
37
  ...(await architectHost.getOptionsForTarget(target)),
@@ -66,7 +68,13 @@ class ArchitectBaseCommandModule extends command_module_1.CommandModule {
66
68
  }
67
69
  async getArchitectTargetOptions(target) {
68
70
  const architectHost = this.getArchitectHost();
69
- const builderConf = await architectHost.getBuilderNameForTarget(target);
71
+ let builderConf;
72
+ try {
73
+ builderConf = await architectHost.getBuilderNameForTarget(target);
74
+ }
75
+ catch {
76
+ return [];
77
+ }
70
78
  let builderDesc;
71
79
  try {
72
80
  builderDesc = await architectHost.resolveBuilder(builderConf);
@@ -98,6 +106,60 @@ class ArchitectBaseCommandModule extends command_module_1.CommandModule {
98
106
  }
99
107
  this.context.logger.warn(`Node packages may not be installed. Try installing with '${this.context.packageManager} install'.`);
100
108
  }
109
+ getArchitectTarget() {
110
+ return this.commandName;
111
+ }
112
+ async onMissingTarget(defaultMessage) {
113
+ const { logger } = this.context;
114
+ const choices = this.missingTargetChoices;
115
+ if (!(choices === null || choices === void 0 ? void 0 : choices.length)) {
116
+ logger.error(defaultMessage);
117
+ return 1;
118
+ }
119
+ const missingTargetMessage = `Cannot find "${this.getArchitectTarget()}" target for the specified project.\n` +
120
+ `You can add a package that implements these capabilities.\n\n` +
121
+ `For example:\n` +
122
+ choices.map(({ name, value }) => ` ${name}: ng add ${value}`).join('\n') +
123
+ '\n';
124
+ if ((0, tty_1.isTTY)()) {
125
+ // Use prompts to ask the user if they'd like to install a package.
126
+ logger.warn(missingTargetMessage);
127
+ const packageToInstall = await this.getMissingTargetPackageToInstall(choices);
128
+ if (packageToInstall) {
129
+ // Example run: `ng add @angular-eslint/schematics`.
130
+ const binPath = (0, path_1.resolve)(__dirname, '../../bin/ng.js');
131
+ const { error } = (0, child_process_1.spawnSync)(process.execPath, [binPath, 'add', packageToInstall], {
132
+ stdio: 'inherit',
133
+ });
134
+ if (error) {
135
+ throw error;
136
+ }
137
+ }
138
+ }
139
+ else {
140
+ // Non TTY display error message.
141
+ logger.error(missingTargetMessage);
142
+ }
143
+ return 1;
144
+ }
145
+ async getMissingTargetPackageToInstall(choices) {
146
+ if (choices.length === 1) {
147
+ // Single choice
148
+ const { name, value } = choices[0];
149
+ if (await (0, prompt_1.askConfirmation)(`Would you like to add ${name} now?`, true, false)) {
150
+ return value;
151
+ }
152
+ return null;
153
+ }
154
+ // Multiple choice
155
+ return (0, prompt_1.askQuestion)(`Would you like to add a package with "${this.getArchitectTarget()}" capabilities now?`, [
156
+ {
157
+ name: 'No',
158
+ value: null,
159
+ },
160
+ ...choices,
161
+ ], 0, null);
162
+ }
101
163
  }
102
164
  exports.ArchitectBaseCommandModule = ArchitectBaseCommandModule;
103
165
  ArchitectBaseCommandModule.scope = command_module_1.CommandScope.In;
@@ -17,6 +17,9 @@ export declare abstract class ArchitectCommandModule extends ArchitectBaseComman
17
17
  builder(argv: Argv): Promise<Argv<ArchitectCommandArgs>>;
18
18
  run(options: Options<ArchitectCommandArgs> & OtherOptions): Promise<number | void>;
19
19
  private getArchitectProject;
20
- private getArchitectTarget;
21
20
  private getProjectNamesByTarget;
21
+ /** @returns a sorted list of project names to be used for auto completion. */
22
+ private getProjectChoices;
23
+ /** @returns a sorted list of configuration names to be used for auto completion. */
24
+ private getConfigurationChoices;
22
25
  }