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

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 (63) 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 +15 -18
  7. package/src/analytics/analytics-collector.js +2 -0
  8. package/src/analytics/analytics.js +17 -16
  9. package/src/command-builder/architect-command-module.js +3 -3
  10. package/src/command-builder/command-module.d.ts +3 -2
  11. package/src/command-builder/command-runner.d.ts +1 -2
  12. package/src/command-builder/command-runner.js +50 -33
  13. package/src/command-builder/schematics-command-module.d.ts +4 -2
  14. package/src/command-builder/schematics-command-module.js +81 -41
  15. package/src/commands/add/cli.js +14 -14
  16. package/src/commands/add/long-description.md +1 -4
  17. package/src/commands/analytics/cli.d.ts +1 -1
  18. package/src/commands/analytics/info/cli.d.ts +1 -1
  19. package/src/commands/analytics/settings/cli.d.ts +1 -1
  20. package/src/commands/cache/clean/cli.d.ts +17 -0
  21. package/src/commands/cache/clean/cli.js +32 -0
  22. package/src/commands/cache/cli.d.ts +17 -0
  23. package/src/commands/cache/cli.js +38 -0
  24. package/src/commands/cache/info/cli.d.ts +20 -0
  25. package/src/commands/cache/info/cli.js +82 -0
  26. package/src/commands/cache/long-description.md +53 -0
  27. package/src/commands/cache/settings/cli.d.ts +27 -0
  28. package/src/commands/cache/settings/cli.js +42 -0
  29. package/src/commands/cache/utilities.d.ts +11 -0
  30. package/src/commands/cache/utilities.js +50 -0
  31. package/src/commands/config/cli.d.ts +1 -1
  32. package/src/commands/config/cli.js +2 -2
  33. package/src/commands/doc/cli.d.ts +1 -1
  34. package/src/commands/e2e/cli.d.ts +1 -1
  35. package/src/commands/e2e/cli.js +3 -3
  36. package/src/commands/generate/cli.d.ts +11 -1
  37. package/src/commands/generate/cli.js +54 -23
  38. package/src/commands/new/cli.d.ts +2 -0
  39. package/src/commands/new/cli.js +15 -4
  40. package/src/commands/update/cli.d.ts +1 -0
  41. package/src/commands/update/cli.js +50 -21
  42. package/src/commands/update/schematic/index.js +27 -18
  43. package/src/commands/version/cli.d.ts +0 -1
  44. package/src/commands/version/cli.js +4 -23
  45. package/src/typings-bazel.d.ts +14 -0
  46. package/src/typings.d.ts +0 -13
  47. package/src/utilities/config.d.ts +1 -2
  48. package/src/utilities/config.js +18 -41
  49. package/src/{analytics/analytics-environment-options.d.ts → utilities/environment-options.d.ts} +3 -0
  50. package/src/utilities/environment-options.js +24 -0
  51. package/src/utilities/package-manager.d.ts +33 -5
  52. package/src/utilities/package-manager.js +241 -71
  53. package/src/utilities/package-metadata.d.ts +15 -37
  54. package/src/utilities/package-metadata.js +10 -26
  55. package/src/utilities/package-tree.d.ts +2 -2
  56. package/src/utilities/prompt.js +2 -2
  57. package/bin/postinstall/analytics-prompt.js +0 -27
  58. package/bin/postinstall/script.js +0 -16
  59. package/src/analytics/analytics-environment-options.js +0 -20
  60. package/src/utilities/install-package.d.ts +0 -16
  61. package/src/utilities/install-package.js +0 -193
  62. package/src/utilities/package-json.d.ts +0 -249
  63. package/src/utilities/package-json.js +0 -9
@@ -6,27 +6,48 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
- var __importDefault = (this && this.__importDefault) || function (mod) {
10
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
11
31
  };
12
32
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.SchematicsCommandModule = void 0;
33
+ exports.SchematicsCommandModule = exports.DEFAULT_SCHEMATICS_COLLECTION = void 0;
14
34
  const core_1 = require("@angular-devkit/core");
15
35
  const schematics_1 = require("@angular-devkit/schematics");
16
36
  const tools_1 = require("@angular-devkit/schematics/tools");
17
- const inquirer_1 = __importDefault(require("inquirer"));
18
37
  const config_1 = require("../utilities/config");
19
38
  const tty_1 = require("../utilities/tty");
20
39
  const command_module_1 = require("./command-module");
21
40
  const json_schema_1 = require("./utilities/json-schema");
22
41
  const schematic_engine_host_1 = require("./utilities/schematic-engine-host");
23
42
  const schematic_workflow_1 = require("./utilities/schematic-workflow");
24
- const DEFAULT_SCHEMATICS_COLLECTION = '@schematics/angular';
43
+ exports.DEFAULT_SCHEMATICS_COLLECTION = '@schematics/angular';
25
44
  class SchematicsCommandModule extends command_module_1.CommandModule {
26
45
  constructor() {
27
46
  super(...arguments);
28
47
  this.allowPrivateSchematics = false;
29
48
  this.shouldReportAnalytics = false;
49
+ this._workflowForBuilder = new Map();
50
+ this.defaultProjectDeprecationWarningShown = false;
30
51
  }
31
52
  async builder(argv) {
32
53
  return argv
@@ -62,13 +83,16 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
62
83
  return (0, json_schema_1.parseJsonSchemaToOptions)(workflow.registry, schemaJson);
63
84
  }
64
85
  getOrCreateWorkflowForBuilder(collectionName) {
65
- if (this._workflowForBuilder) {
66
- return this._workflowForBuilder;
86
+ const cached = this._workflowForBuilder.get(collectionName);
87
+ if (cached) {
88
+ return cached;
67
89
  }
68
- return (this._workflowForBuilder = new tools_1.NodeWorkflow(this.context.root, {
90
+ const workflow = new tools_1.NodeWorkflow(this.context.root, {
69
91
  resolvePaths: this.getResolvePaths(collectionName),
70
92
  engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
71
- }));
93
+ });
94
+ this._workflowForBuilder.set(collectionName, workflow);
95
+ return workflow;
72
96
  }
73
97
  async getOrCreateWorkflowForExecution(collectionName, options) {
74
98
  if (this._workflowForExecution) {
@@ -79,7 +103,7 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
79
103
  const workflow = new tools_1.NodeWorkflow(root, {
80
104
  force,
81
105
  dryRun,
82
- packageManager,
106
+ packageManager: packageManager.name,
83
107
  // A schema registry is required to allow customizing addUndefinedDefaults
84
108
  registry: new core_1.schema.CoreSchemaRegistry(schematics_1.formats.standardFormats),
85
109
  packageRegistry,
@@ -118,7 +142,7 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
118
142
  return options;
119
143
  });
120
144
  if (options.interactive !== false && (0, tty_1.isTTY)()) {
121
- workflow.registry.usePromptProvider((definitions) => {
145
+ workflow.registry.usePromptProvider(async (definitions) => {
122
146
  const questions = definitions
123
147
  .filter((definition) => !options.defaults || definition.default === undefined)
124
148
  .map((definition) => {
@@ -177,35 +201,53 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
177
201
  }
178
202
  return question;
179
203
  });
180
- return inquirer_1.default.prompt(questions);
204
+ if (questions.length) {
205
+ const { prompt } = await Promise.resolve().then(() => __importStar(require('inquirer')));
206
+ return prompt(questions);
207
+ }
208
+ else {
209
+ return {};
210
+ }
181
211
  });
182
212
  }
183
213
  return (this._workflowForExecution = workflow);
184
214
  }
185
- async getDefaultSchematicCollection() {
186
- if (this._defaultSchematicCollection) {
187
- return this._defaultSchematicCollection;
215
+ async getSchematicCollections() {
216
+ var _a;
217
+ if (this._schematicCollections) {
218
+ return this._schematicCollections;
188
219
  }
189
- let workspace = await (0, config_1.getWorkspace)('local');
220
+ const getSchematicCollections = (configSection) => {
221
+ if (!configSection) {
222
+ return undefined;
223
+ }
224
+ const { schematicCollections, defaultCollection } = configSection;
225
+ if (Array.isArray(schematicCollections)) {
226
+ return new Set(schematicCollections);
227
+ }
228
+ else if (typeof defaultCollection === 'string') {
229
+ return new Set([defaultCollection]);
230
+ }
231
+ return undefined;
232
+ };
233
+ const { workspace, globalConfiguration } = this.context;
190
234
  if (workspace) {
191
235
  const project = (0, config_1.getProjectByCwd)(workspace);
192
236
  if (project) {
193
- const value = workspace.getProjectCli(project)['defaultCollection'];
194
- if (typeof value == 'string') {
195
- return (this._defaultSchematicCollection = value);
237
+ const value = getSchematicCollections(workspace.getProjectCli(project));
238
+ if (value) {
239
+ this._schematicCollections = value;
240
+ return value;
196
241
  }
197
242
  }
198
- const value = workspace.getCli()['defaultCollection'];
199
- if (typeof value === 'string') {
200
- return (this._defaultSchematicCollection = value);
201
- }
202
243
  }
203
- workspace = await (0, config_1.getWorkspace)('global');
204
- const value = workspace === null || workspace === void 0 ? void 0 : workspace.getCli()['defaultCollection'];
205
- if (typeof value === 'string') {
206
- return (this._defaultSchematicCollection = value);
244
+ 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
+ if (value) {
246
+ this._schematicCollections = value;
247
+ return value;
207
248
  }
208
- return (this._defaultSchematicCollection = DEFAULT_SCHEMATICS_COLLECTION);
249
+ this._schematicCollections = new Set([exports.DEFAULT_SCHEMATICS_COLLECTION]);
250
+ return this._schematicCollections;
209
251
  }
210
252
  parseSchematicInfo(schematic) {
211
253
  if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
@@ -260,22 +302,20 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
260
302
  if (!workspace) {
261
303
  return undefined;
262
304
  }
263
- const projectNames = (0, config_1.getProjectsByPath)(workspace, process.cwd(), workspace.basePath);
264
- if (projectNames.length === 1) {
265
- return projectNames[0];
305
+ const projectName = (0, config_1.getProjectByCwd)(workspace);
306
+ if (projectName) {
307
+ return projectName;
266
308
  }
267
- else {
268
- if (projectNames.length > 1) {
309
+ const defaultProjectName = workspace.extensions['defaultProject'];
310
+ if (typeof defaultProjectName === 'string' && defaultProjectName) {
311
+ if (!this.defaultProjectDeprecationWarningShown) {
269
312
  logger.warn(core_1.tags.oneLine `
270
- Two or more projects are using identical roots.
271
- Unable to determine project using current working directory.
272
- Using default workspace project instead.
313
+ DEPRECATED: The 'defaultProject' workspace option has been deprecated.
314
+ The project to use will be determined from the current working directory.
273
315
  `);
316
+ this.defaultProjectDeprecationWarningShown = true;
274
317
  }
275
- const defaultProjectName = workspace.extensions['defaultProject'];
276
- if (typeof defaultProjectName === 'string' && defaultProjectName) {
277
- return defaultProjectName;
278
- }
318
+ return defaultProjectName;
279
319
  }
280
320
  return undefined;
281
321
  }
@@ -283,7 +323,7 @@ class SchematicsCommandModule extends command_module_1.CommandModule {
283
323
  const { workspace, root } = this.context;
284
324
  return workspace
285
325
  ? // Workspace
286
- collectionName === DEFAULT_SCHEMATICS_COLLECTION
326
+ collectionName === exports.DEFAULT_SCHEMATICS_COLLECTION
287
327
  ? // Favor __dirname for @schematics/angular to use the build-in version
288
328
  [__dirname, process.cwd(), root]
289
329
  : [process.cwd(), root, __dirname]
@@ -20,8 +20,6 @@ const workspace_schema_1 = require("../../../lib/config/workspace-schema");
20
20
  const analytics_1 = require("../../analytics/analytics");
21
21
  const schematics_command_module_1 = require("../../command-builder/schematics-command-module");
22
22
  const color_1 = require("../../utilities/color");
23
- const install_package_1 = require("../../utilities/install-package");
24
- const package_manager_1 = require("../../utilities/package-manager");
25
23
  const package_metadata_1 = require("../../utilities/package-metadata");
26
24
  const prompt_1 = require("../../utilities/prompt");
27
25
  const spinner_1 = require("../../utilities/spinner");
@@ -84,9 +82,9 @@ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModu
84
82
  // eslint-disable-next-line max-lines-per-function
85
83
  async run(options) {
86
84
  var _a;
87
- const { root, logger, packageManager } = this.context;
85
+ const { logger, packageManager } = this.context;
88
86
  const { verbose, registry, collection, skipConfirmation } = options;
89
- await (0, package_manager_1.ensureCompatibleNpm)(root);
87
+ packageManager.ensureCompatibility();
90
88
  let packageIdentifier;
91
89
  try {
92
90
  packageIdentifier = (0, npm_package_arg_1.default)(collection);
@@ -107,8 +105,8 @@ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModu
107
105
  }
108
106
  const spinner = new spinner_1.Spinner();
109
107
  spinner.start('Determining package manager...');
110
- const usingYarn = packageManager === workspace_schema_1.PackageManager.Yarn;
111
- spinner.info(`Using package manager: ${color_1.colors.grey(packageManager)}`);
108
+ const usingYarn = packageManager.name === workspace_schema_1.PackageManager.Yarn;
109
+ spinner.info(`Using package manager: ${color_1.colors.grey(packageManager.name)}`);
112
110
  if (packageIdentifier.name && packageIdentifier.type === 'tag' && !packageIdentifier.rawSpec) {
113
111
  // only package name provided; search for viable version
114
112
  // plus special cases for packages that did not have peer deps setup
@@ -131,7 +129,8 @@ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModu
131
129
  packageIdentifier = npm_package_arg_1.default.resolve(latestManifest.name, latestManifest.version);
132
130
  }
133
131
  // Adjust the version based on name and peer dependencies
134
- if (latestManifest && Object.keys(latestManifest.peerDependencies).length === 0) {
132
+ if ((latestManifest === null || latestManifest === void 0 ? void 0 : latestManifest.peerDependencies) &&
133
+ Object.keys(latestManifest.peerDependencies).length === 0) {
135
134
  spinner.succeed(`Found compatible package version: ${color_1.colors.grey(packageIdentifier.toString())}.`);
136
135
  }
137
136
  else if (!latestManifest || (await this.hasMismatchedPeer(latestManifest))) {
@@ -210,19 +209,19 @@ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModu
210
209
  if (savePackage === false) {
211
210
  // Temporary packages are located in a different directory
212
211
  // Hence we need to resolve them using the temp path
213
- const { status, tempNodeModules } = await (0, install_package_1.installTempPackage)(packageIdentifier.raw, packageManager, registry ? [`--registry="${registry}"`] : undefined);
212
+ const { success, tempNodeModules } = await packageManager.installTemp(packageIdentifier.raw, registry ? [`--registry="${registry}"`] : undefined);
214
213
  const resolvedCollectionPath = require.resolve((0, path_1.join)(collectionName, 'package.json'), {
215
214
  paths: [tempNodeModules],
216
215
  });
217
- if (status !== 0) {
218
- return status;
216
+ if (!success) {
217
+ return 1;
219
218
  }
220
219
  collectionName = (0, path_1.dirname)(resolvedCollectionPath);
221
220
  }
222
221
  else {
223
- const status = await (0, install_package_1.installPackage)(packageIdentifier.raw, packageManager, savePackage, registry ? [`--registry="${registry}"`] : undefined);
224
- if (status !== 0) {
225
- return status;
222
+ const success = await packageManager.install(packageIdentifier.raw, savePackage, registry ? [`--registry="${registry}"`] : undefined);
223
+ if (!success) {
224
+ return 1;
226
225
  }
227
226
  }
228
227
  return this.executeSchematic({ ...options, collection: collectionName });
@@ -301,6 +300,7 @@ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModu
301
300
  }
302
301
  }
303
302
  async findProjectVersion(name) {
303
+ var _a, _b;
304
304
  const { logger, root } = this.context;
305
305
  let installedPackage;
306
306
  try {
@@ -322,7 +322,7 @@ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModu
322
322
  }
323
323
  catch { }
324
324
  if (projectManifest) {
325
- const version = projectManifest.dependencies[name] || projectManifest.devDependencies[name];
325
+ const version = ((_a = projectManifest.dependencies) === null || _a === void 0 ? void 0 : _a[name]) || ((_b = projectManifest.devDependencies) === null || _b === void 0 ? void 0 : _b[name]);
326
326
  if (version) {
327
327
  return version;
328
328
  }
@@ -1,10 +1,7 @@
1
1
  Adds the npm package for a published library to your workspace, and configures
2
- the project in the current working directory (or the default project if you are
3
- not in a project directory) to use that library, as specified by the library's schematic.
2
+ the project in the current working directory to use that library, as specified by the library's schematic.
4
3
  For example, adding `@angular/pwa` configures your project for PWA support:
5
4
 
6
5
  ```bash
7
6
  ng add @angular/pwa
8
7
  ```
9
-
10
- The default project is the value of `defaultProject` in `angular.json`.
@@ -10,7 +10,7 @@ import { CommandModule, CommandModuleImplementation, Options } from '../../comma
10
10
  export declare class AnalyticsCommandModule extends CommandModule implements CommandModuleImplementation {
11
11
  command: string;
12
12
  describe: string;
13
- longDescriptionPath?: string | undefined;
13
+ longDescriptionPath?: string;
14
14
  builder(localYargs: Argv): Argv;
15
15
  run(_options: Options<{}>): void;
16
16
  }
@@ -10,7 +10,7 @@ import { CommandModule, CommandModuleImplementation, Options } from '../../../co
10
10
  export declare class AnalyticsInfoCommandModule extends CommandModule implements CommandModuleImplementation {
11
11
  command: string;
12
12
  describe: string;
13
- longDescriptionPath?: string | undefined;
13
+ longDescriptionPath?: string;
14
14
  builder(localYargs: Argv): Argv;
15
15
  run(_options: Options<{}>): Promise<void>;
16
16
  }
@@ -11,7 +11,7 @@ interface AnalyticsCommandArgs {
11
11
  global: boolean;
12
12
  }
13
13
  declare abstract class AnalyticsSettingModule extends CommandModule<AnalyticsCommandArgs> implements CommandModuleImplementation<AnalyticsCommandArgs> {
14
- longDescriptionPath?: string | undefined;
14
+ longDescriptionPath?: string;
15
15
  builder(localYargs: Argv): Argv<AnalyticsCommandArgs>;
16
16
  abstract run({ global }: Options<AnalyticsCommandArgs>): Promise<void>;
17
17
  }
@@ -0,0 +1,17 @@
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, CommandScope } from '../../../command-builder/command-module';
10
+ export declare class CacheCleanModule extends CommandModule implements CommandModuleImplementation {
11
+ command: string;
12
+ describe: string;
13
+ longDescriptionPath: string | undefined;
14
+ static scope: CommandScope.In;
15
+ builder(localYargs: Argv): Argv;
16
+ run(): Promise<void>;
17
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.CacheCleanModule = void 0;
11
+ const fs_1 = require("fs");
12
+ const command_module_1 = require("../../../command-builder/command-module");
13
+ const utilities_1 = require("../utilities");
14
+ class CacheCleanModule extends command_module_1.CommandModule {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.command = 'clean';
18
+ this.describe = 'Deletes persistent disk cache from disk.';
19
+ }
20
+ builder(localYargs) {
21
+ return localYargs.strict();
22
+ }
23
+ run() {
24
+ const { path } = (0, utilities_1.getCacheConfig)(this.context.workspace);
25
+ return fs_1.promises.rm(path, {
26
+ force: true,
27
+ recursive: true,
28
+ maxRetries: 3,
29
+ });
30
+ }
31
+ }
32
+ exports.CacheCleanModule = CacheCleanModule;
@@ -0,0 +1,17 @@
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, CommandScope, Options } from '../../command-builder/command-module';
10
+ export declare class CacheCommandModule extends CommandModule implements CommandModuleImplementation {
11
+ command: string;
12
+ describe: string;
13
+ longDescriptionPath: string;
14
+ static scope: CommandScope.In;
15
+ builder(localYargs: Argv): Argv;
16
+ run(_options: Options<{}>): void;
17
+ }
@@ -0,0 +1,38 @@
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.CacheCommandModule = void 0;
11
+ const path_1 = require("path");
12
+ const command_module_1 = require("../../command-builder/command-module");
13
+ const command_1 = require("../../command-builder/utilities/command");
14
+ const cli_1 = require("./clean/cli");
15
+ const cli_2 = require("./info/cli");
16
+ const cli_3 = require("./settings/cli");
17
+ class CacheCommandModule extends command_module_1.CommandModule {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.command = 'cache';
21
+ this.describe = 'Configure persistent disk cache and retrieve cache statistics.';
22
+ this.longDescriptionPath = (0, path_1.join)(__dirname, 'long-description.md');
23
+ }
24
+ builder(localYargs) {
25
+ const subcommands = [
26
+ cli_3.CacheEnableModule,
27
+ cli_3.CacheDisableModule,
28
+ cli_1.CacheCleanModule,
29
+ cli_2.CacheInfoCommandModule,
30
+ ].sort();
31
+ for (const module of subcommands) {
32
+ localYargs = (0, command_1.addCommandModuleToYargs)(localYargs, module, this.context);
33
+ }
34
+ return localYargs.demandCommand(1, command_1.demandCommandFailureMessage).strict();
35
+ }
36
+ run(_options) { }
37
+ }
38
+ exports.CacheCommandModule = CacheCommandModule;
@@ -0,0 +1,20 @@
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, CommandScope } from '../../../command-builder/command-module';
10
+ export declare class CacheInfoCommandModule extends CommandModule implements CommandModuleImplementation {
11
+ command: string;
12
+ describe: string;
13
+ longDescriptionPath?: string | undefined;
14
+ static scope: CommandScope.In;
15
+ builder(localYargs: Argv): Argv;
16
+ run(): Promise<void>;
17
+ private getSizeOfDirectory;
18
+ private formatSize;
19
+ private effectiveEnabledStatus;
20
+ }
@@ -0,0 +1,82 @@
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.CacheInfoCommandModule = void 0;
11
+ const core_1 = require("@angular-devkit/core");
12
+ const fs_1 = require("fs");
13
+ const path_1 = require("path");
14
+ const command_module_1 = require("../../../command-builder/command-module");
15
+ const environment_options_1 = require("../../../utilities/environment-options");
16
+ const utilities_1 = require("../utilities");
17
+ class CacheInfoCommandModule extends command_module_1.CommandModule {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.command = 'info';
21
+ this.describe = 'Prints persistent disk cache configuration and statistics in the console.';
22
+ }
23
+ builder(localYargs) {
24
+ return localYargs.strict();
25
+ }
26
+ async run() {
27
+ const { path, environment, enabled } = (0, utilities_1.getCacheConfig)(this.context.workspace);
28
+ this.context.logger.info(core_1.tags.stripIndents `
29
+ Enabled: ${enabled ? 'yes' : 'no'}
30
+ Environment: ${environment}
31
+ Path: ${path}
32
+ Size on disk: ${await this.getSizeOfDirectory(path)}
33
+ Effective status on current machine: ${this.effectiveEnabledStatus() ? 'enabled' : 'disabled'}
34
+ `);
35
+ }
36
+ async getSizeOfDirectory(path) {
37
+ const directoriesStack = [path];
38
+ let size = 0;
39
+ while (directoriesStack.length) {
40
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
41
+ const dirPath = directoriesStack.pop();
42
+ let entries = [];
43
+ try {
44
+ entries = await fs_1.promises.readdir(dirPath);
45
+ }
46
+ catch { }
47
+ for (const entry of entries) {
48
+ const entryPath = (0, path_1.join)(dirPath, entry);
49
+ const stats = await fs_1.promises.stat(entryPath);
50
+ if (stats.isDirectory()) {
51
+ directoriesStack.push(entryPath);
52
+ }
53
+ size += stats.size;
54
+ }
55
+ }
56
+ return this.formatSize(size);
57
+ }
58
+ formatSize(size) {
59
+ if (size <= 0) {
60
+ return '0 bytes';
61
+ }
62
+ const abbreviations = ['bytes', 'kB', 'MB', 'GB'];
63
+ const index = Math.floor(Math.log(size) / Math.log(1024));
64
+ const roundedSize = size / Math.pow(1024, index);
65
+ // bytes don't have a fraction
66
+ const fractionDigits = index === 0 ? 0 : 2;
67
+ return `${roundedSize.toFixed(fractionDigits)} ${abbreviations[index]}`;
68
+ }
69
+ effectiveEnabledStatus() {
70
+ const { enabled, environment } = (0, utilities_1.getCacheConfig)(this.context.workspace);
71
+ if (enabled) {
72
+ switch (environment) {
73
+ case 'ci':
74
+ return environment_options_1.isCI;
75
+ case 'local':
76
+ return !environment_options_1.isCI;
77
+ }
78
+ }
79
+ return enabled;
80
+ }
81
+ }
82
+ exports.CacheInfoCommandModule = CacheInfoCommandModule;
@@ -0,0 +1,53 @@
1
+ Angular CLI saves a number of cachable operations on disk by default.
2
+
3
+ When you re-run the same build, the build system restores the state of the previous build and re-uses previously performed operations, which decreases the time taken to build and test your applications and libraries.
4
+
5
+ To amend the default cache settings, add the `cli.cache` object to your [Workspace Configuration](guide/workspace-config).
6
+ The object goes under `cli.cache` at the top level of the file, outside the `projects` sections.
7
+
8
+ ```jsonc
9
+ {
10
+ "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
11
+ "version": 1,
12
+ "cli": {
13
+ "cache": {
14
+ // ...
15
+ }
16
+ },
17
+ "projects": {}
18
+ }
19
+ ```
20
+
21
+ For more information, see [cache options](guide/workspace-config#cache-options).
22
+
23
+ ### Cache environments
24
+
25
+ By default, disk cache is only enabled for local environments. The value of environment can be one of the following:
26
+
27
+ - `all` - allows disk cache on all machines.
28
+ - `local` - allows disk cache only on development machines.
29
+ - `ci` - allows disk cache only on continuous integration (Ci) systems.
30
+
31
+ To change the environment setting to `all`, run the following command:
32
+
33
+ ```bash
34
+ ng config cli.cache.environment all
35
+ ```
36
+
37
+ For more information, see `environment` in [cache options](guide/workspace-config#cache-options).
38
+
39
+ <div class="alert is-helpful">
40
+
41
+ The Angular CLI checks for the presence and value of the `CI` environment variable to determine in which environment it is running.
42
+
43
+ </div>
44
+
45
+ ### Cache path
46
+
47
+ By default, `.angular/cache` is used as a base directory to store cache results.
48
+
49
+ To change this path to `.cache/ng`, run the following command:
50
+
51
+ ```bash
52
+ ng config cli.cache.path ".cache/ng"
53
+ ```
@@ -0,0 +1,27 @@
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, CommandScope } from '../../../command-builder/command-module';
10
+ export declare class CacheDisableModule extends CommandModule implements CommandModuleImplementation {
11
+ command: string;
12
+ aliases: string;
13
+ describe: string;
14
+ longDescriptionPath: string | undefined;
15
+ static scope: CommandScope.In;
16
+ builder(localYargs: Argv): Argv;
17
+ run(): void;
18
+ }
19
+ export declare class CacheEnableModule extends CommandModule implements CommandModuleImplementation {
20
+ command: string;
21
+ aliases: string;
22
+ describe: string;
23
+ longDescriptionPath: string | undefined;
24
+ static scope: CommandScope.In;
25
+ builder(localYargs: Argv): Argv;
26
+ run(): void;
27
+ }