@angular/cli 14.0.0-next.1 → 14.0.0-next.12

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 (239) hide show
  1. package/bin/ng.js +3 -5
  2. package/lib/cli/index.d.ts +1 -2
  3. package/lib/cli/index.js +16 -45
  4. package/lib/config/schema.json +48 -15
  5. package/lib/config/workspace-schema.d.ts +18 -1
  6. package/lib/init.js +10 -9
  7. package/package.json +21 -23
  8. package/{models → src/analytics}/analytics-collector.d.ts +0 -0
  9. package/{models → src/analytics}/analytics-collector.js +8 -2
  10. package/src/analytics/analytics.d.ts +47 -0
  11. package/src/analytics/analytics.js +306 -0
  12. package/src/command-builder/architect-base-command-module.d.ts +30 -0
  13. package/src/command-builder/architect-base-command-module.js +165 -0
  14. package/src/command-builder/architect-command-module.d.ts +25 -0
  15. package/src/command-builder/architect-command-module.js +134 -0
  16. package/src/command-builder/command-module.d.ts +89 -0
  17. package/src/command-builder/command-module.js +198 -0
  18. package/{utilities/package-json.js → src/command-builder/command-runner.d.ts} +2 -2
  19. package/src/command-builder/command-runner.js +168 -0
  20. package/src/command-builder/schematics-command-module.d.ts +43 -0
  21. package/src/command-builder/schematics-command-module.js +333 -0
  22. package/src/command-builder/utilities/command.d.ts +13 -0
  23. package/src/command-builder/utilities/command.js +27 -0
  24. package/src/command-builder/utilities/json-help.d.ts +36 -0
  25. package/src/command-builder/utilities/json-help.js +94 -0
  26. package/src/command-builder/utilities/json-schema.d.ts +40 -0
  27. package/{utilities → src/command-builder/utilities}/json-schema.js +20 -121
  28. package/src/command-builder/utilities/normalize-options-middleware.d.ts +18 -0
  29. package/src/command-builder/utilities/normalize-options-middleware.js +59 -0
  30. package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +2 -2
  31. package/{models → src/command-builder/utilities}/schematic-engine-host.js +33 -18
  32. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  33. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  34. package/src/commands/add/cli.d.ts +33 -0
  35. package/{commands/add-impl.js → src/commands/add/cli.js} +108 -80
  36. package/src/commands/add/long-description.md +7 -0
  37. package/src/commands/analytics/cli.d.ts +16 -0
  38. package/src/commands/analytics/cli.js +35 -0
  39. package/src/commands/analytics/info/cli.d.ts +16 -0
  40. package/src/commands/analytics/info/cli.js +26 -0
  41. package/src/commands/analytics/settings/cli.d.ts +35 -0
  42. package/src/commands/analytics/settings/cli.js +61 -0
  43. package/src/commands/build/cli.d.ts +16 -0
  44. package/src/commands/build/cli.js +23 -0
  45. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  46. package/src/commands/cache/clean/cli.d.ts +17 -0
  47. package/src/commands/cache/clean/cli.js +32 -0
  48. package/src/commands/cache/cli.d.ts +17 -0
  49. package/src/commands/cache/cli.js +38 -0
  50. package/src/commands/cache/info/cli.d.ts +20 -0
  51. package/src/commands/cache/info/cli.js +82 -0
  52. package/src/commands/cache/long-description.md +53 -0
  53. package/src/commands/cache/settings/cli.d.ts +27 -0
  54. package/src/commands/cache/settings/cli.js +42 -0
  55. package/src/commands/cache/utilities.d.ts +11 -0
  56. package/src/commands/cache/utilities.js +49 -0
  57. package/src/commands/completion/cli.d.ts +16 -0
  58. package/src/commands/completion/cli.js +31 -0
  59. package/src/commands/completion/long-description.md +1 -0
  60. package/src/commands/config/cli.d.ts +24 -0
  61. package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
  62. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  63. package/src/commands/deploy/cli.d.ts +17 -0
  64. package/src/commands/deploy/cli.js +49 -0
  65. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  66. package/src/commands/doc/cli.d.ts +23 -0
  67. package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
  68. package/src/commands/e2e/cli.d.ts +18 -0
  69. package/src/commands/e2e/cli.js +35 -0
  70. package/src/commands/extract-i18n/cli.d.ts +15 -0
  71. package/src/commands/extract-i18n/cli.js +20 -0
  72. package/src/commands/generate/cli.d.ts +39 -0
  73. package/src/commands/generate/cli.js +145 -0
  74. package/src/commands/lint/cli.d.ts +17 -0
  75. package/src/commands/lint/cli.js +28 -0
  76. package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
  77. package/src/commands/make-this-awesome/cli.d.ts +17 -0
  78. package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
  79. package/src/commands/new/cli.d.ts +27 -0
  80. package/src/commands/new/cli.js +82 -0
  81. package/src/commands/run/cli.d.ts +25 -0
  82. package/src/commands/run/cli.js +83 -0
  83. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  84. package/src/commands/serve/cli.d.ts +16 -0
  85. package/src/commands/serve/cli.js +21 -0
  86. package/src/commands/test/cli.d.ts +16 -0
  87. package/src/commands/test/cli.js +23 -0
  88. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  89. package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +26 -9
  90. package/{commands/update-impl.js → src/commands/update/cli.js} +363 -316
  91. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  92. package/src/commands/update/schematic/index.js +33 -20
  93. package/src/commands/version/cli.d.ts +18 -0
  94. package/{commands/version-impl.js → src/commands/version/cli.js} +56 -74
  95. package/src/typings-bazel.d.ts +14 -0
  96. package/src/typings.d.ts +1 -14
  97. package/{utilities → src/utilities}/color.d.ts +0 -0
  98. package/{utilities → src/utilities}/color.js +5 -1
  99. package/{utilities → src/utilities}/config.d.ts +6 -5
  100. package/{utilities → src/utilities}/config.js +33 -19
  101. package/src/utilities/environment-options.d.ts +12 -0
  102. package/src/utilities/environment-options.js +24 -0
  103. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  104. package/{utilities → src/utilities}/find-up.js +5 -1
  105. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  106. package/{utilities → src/utilities}/json-file.js +1 -0
  107. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  108. package/{utilities → src/utilities}/log-file.js +0 -0
  109. package/src/utilities/memoize.d.ts +15 -0
  110. package/src/utilities/memoize.js +69 -0
  111. package/src/utilities/package-manager.d.ts +41 -0
  112. package/src/utilities/package-manager.js +287 -0
  113. package/{utilities → src/utilities}/package-metadata.d.ts +15 -37
  114. package/{utilities → src/utilities}/package-metadata.js +15 -27
  115. package/{utilities → src/utilities}/package-tree.d.ts +2 -2
  116. package/{utilities → src/utilities}/package-tree.js +5 -1
  117. package/{utilities → src/utilities}/project.d.ts +0 -0
  118. package/{utilities → src/utilities}/project.js +5 -1
  119. package/{utilities → src/utilities}/prompt.d.ts +2 -0
  120. package/{utilities → src/utilities}/prompt.js +25 -4
  121. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  122. package/{utilities → src/utilities}/spinner.js +0 -0
  123. package/{utilities → src/utilities}/tty.d.ts +0 -0
  124. package/{utilities → src/utilities}/tty.js +0 -0
  125. package/{models → src/utilities}/version.d.ts +2 -1
  126. package/{models → src/utilities}/version.js +6 -6
  127. package/bin/postinstall/analytics-prompt.js +0 -27
  128. package/bin/postinstall/script.js +0 -16
  129. package/commands/add-impl.d.ts +0 -21
  130. package/commands/add.d.ts +0 -42
  131. package/commands/add.js +0 -10
  132. package/commands/add.json +0 -54
  133. package/commands/add.md +0 -10
  134. package/commands/analytics-impl.d.ts +0 -13
  135. package/commands/analytics-impl.js +0 -80
  136. package/commands/analytics-long.md +0 -8
  137. package/commands/analytics.d.ts +0 -46
  138. package/commands/analytics.js +0 -31
  139. package/commands/analytics.json +0 -37
  140. package/commands/build-impl.d.ts +0 -14
  141. package/commands/build-impl.js +0 -21
  142. package/commands/build.d.ts +0 -30
  143. package/commands/build.js +0 -10
  144. package/commands/build.json +0 -16
  145. package/commands/config-impl.d.ts +0 -15
  146. package/commands/config.d.ts +0 -34
  147. package/commands/config.js +0 -10
  148. package/commands/config.json +0 -43
  149. package/commands/definitions.json +0 -66
  150. package/commands/deploy-impl.d.ts +0 -15
  151. package/commands/deploy-impl.js +0 -36
  152. package/commands/deploy.d.ts +0 -30
  153. package/commands/deploy.js +0 -10
  154. package/commands/deploy.json +0 -34
  155. package/commands/doc-impl.d.ts +0 -13
  156. package/commands/doc.d.ts +0 -39
  157. package/commands/doc.js +0 -14
  158. package/commands/doc.json +0 -46
  159. package/commands/e2e-impl.d.ts +0 -16
  160. package/commands/e2e-impl.js +0 -36
  161. package/commands/e2e-long.md +0 -4
  162. package/commands/e2e.d.ts +0 -29
  163. package/commands/e2e.js +0 -10
  164. package/commands/e2e.json +0 -17
  165. package/commands/easter-egg-impl.d.ts +0 -12
  166. package/commands/easter-egg.d.ts +0 -14
  167. package/commands/easter-egg.js +0 -10
  168. package/commands/easter-egg.json +0 -12
  169. package/commands/extract-i18n-impl.d.ts +0 -14
  170. package/commands/extract-i18n-impl.js +0 -32
  171. package/commands/extract-i18n.d.ts +0 -29
  172. package/commands/extract-i18n.js +0 -10
  173. package/commands/extract-i18n.json +0 -17
  174. package/commands/generate-impl.d.ts +0 -18
  175. package/commands/generate-impl.js +0 -89
  176. package/commands/generate.d.ts +0 -37
  177. package/commands/generate.js +0 -10
  178. package/commands/generate.json +0 -31
  179. package/commands/help-impl.d.ts +0 -12
  180. package/commands/help-impl.js +0 -26
  181. package/commands/help-long.md +0 -7
  182. package/commands/help.d.ts +0 -17
  183. package/commands/help.js +0 -10
  184. package/commands/help.json +0 -13
  185. package/commands/lint-impl.d.ts +0 -16
  186. package/commands/lint-impl.js +0 -69
  187. package/commands/lint.d.ts +0 -29
  188. package/commands/lint.js +0 -10
  189. package/commands/lint.json +0 -36
  190. package/commands/new-impl.d.ts +0 -16
  191. package/commands/new-impl.js +0 -37
  192. package/commands/new.d.ts +0 -41
  193. package/commands/new.js +0 -10
  194. package/commands/new.json +0 -34
  195. package/commands/new.md +0 -16
  196. package/commands/run-impl.d.ts +0 -13
  197. package/commands/run-impl.js +0 -22
  198. package/commands/run.d.ts +0 -30
  199. package/commands/run.js +0 -10
  200. package/commands/run.json +0 -36
  201. package/commands/serve-impl.d.ts +0 -15
  202. package/commands/serve-impl.js +0 -24
  203. package/commands/serve.d.ts +0 -29
  204. package/commands/serve.js +0 -10
  205. package/commands/serve.json +0 -17
  206. package/commands/test-impl.d.ts +0 -15
  207. package/commands/test-impl.js +0 -22
  208. package/commands/test.d.ts +0 -29
  209. package/commands/test.js +0 -10
  210. package/commands/test.json +0 -17
  211. package/commands/update.d.ts +0 -61
  212. package/commands/update.js +0 -10
  213. package/commands/update.json +0 -78
  214. package/commands/version-impl.d.ts +0 -17
  215. package/commands/version.d.ts +0 -17
  216. package/commands/version.js +0 -10
  217. package/commands/version.json +0 -13
  218. package/commands.json +0 -20
  219. package/models/analytics.d.ts +0 -58
  220. package/models/analytics.js +0 -358
  221. package/models/architect-command.d.ts +0 -35
  222. package/models/architect-command.js +0 -364
  223. package/models/command-runner.d.ts +0 -24
  224. package/models/command-runner.js +0 -241
  225. package/models/command.d.ts +0 -34
  226. package/models/command.js +0 -143
  227. package/models/interface.d.ts +0 -196
  228. package/models/interface.js +0 -31
  229. package/models/parser.d.ts +0 -39
  230. package/models/parser.js +0 -349
  231. package/models/schematic-command.d.ts +0 -55
  232. package/models/schematic-command.js +0 -485
  233. package/utilities/INITIAL_COMMIT_MESSAGE.txt +0 -8
  234. package/utilities/install-package.d.ts +0 -16
  235. package/utilities/install-package.js +0 -193
  236. package/utilities/json-schema.d.ts +0 -17
  237. package/utilities/package-json.d.ts +0 -249
  238. package/utilities/package-manager.d.ts +0 -13
  239. package/utilities/package-manager.js +0 -106
@@ -10,22 +10,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.AddCommand = void 0;
13
+ exports.AddCommandModule = void 0;
14
14
  const core_1 = require("@angular-devkit/core");
15
15
  const tools_1 = require("@angular-devkit/schematics/tools");
16
16
  const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
17
17
  const path_1 = require("path");
18
18
  const semver_1 = require("semver");
19
- const workspace_schema_1 = require("../lib/config/workspace-schema");
20
- const analytics_1 = require("../models/analytics");
21
- const schematic_command_1 = require("../models/schematic-command");
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
- const package_metadata_1 = require("../utilities/package-metadata");
26
- const prompt_1 = require("../utilities/prompt");
27
- const spinner_1 = require("../utilities/spinner");
28
- const tty_1 = require("../utilities/tty");
19
+ const workspace_schema_1 = require("../../../lib/config/workspace-schema");
20
+ const analytics_1 = require("../../analytics/analytics");
21
+ const schematics_command_module_1 = require("../../command-builder/schematics-command-module");
22
+ const color_1 = require("../../utilities/color");
23
+ const package_metadata_1 = require("../../utilities/package-metadata");
24
+ const prompt_1 = require("../../utilities/prompt");
25
+ const spinner_1 = require("../../utilities/spinner");
26
+ const tty_1 = require("../../utilities/tty");
29
27
  /**
30
28
  * The set of packages that should have certain versions excluded from consideration
31
29
  * when attempting to find a compatible version for a package.
@@ -35,34 +33,64 @@ const packageVersionExclusions = {
35
33
  // @angular/localize@9.x versions do not have peer dependencies setup
36
34
  '@angular/localize': '9.x',
37
35
  };
38
- class AddCommand extends schematic_command_1.SchematicCommand {
36
+ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModule {
39
37
  constructor() {
40
38
  super(...arguments);
39
+ this.command = 'add <collection>';
40
+ this.describe = 'Adds support for an external library to your project.';
41
+ this.longDescriptionPath = (0, path_1.join)(__dirname, 'long-description.md');
41
42
  this.allowPrivateSchematics = true;
43
+ this.schematicName = 'ng-add';
42
44
  }
43
- async initialize(options) {
44
- if (options.registry) {
45
- return super.initialize({ ...options, packageRegistry: options.registry });
45
+ async builder(argv) {
46
+ const localYargs = (await super.builder(argv))
47
+ .positional('collection', {
48
+ description: 'The package to be added.',
49
+ type: 'string',
50
+ demandOption: true,
51
+ })
52
+ .option('registry', { description: 'The NPM registry to use.', type: 'string' })
53
+ .option('verbose', {
54
+ description: 'Display additional details about internal operations during execution.',
55
+ type: 'boolean',
56
+ default: false,
57
+ })
58
+ .option('skip-confirmation', {
59
+ description: 'Skip asking a confirmation prompt before installing and executing the package. ' +
60
+ 'Ensure package name is correct prior to using this option.',
61
+ type: 'boolean',
62
+ default: false,
63
+ })
64
+ // Prior to downloading we don't know the full schema and therefore we cannot be strict on the options.
65
+ // Possibly in the future update the logic to use the following syntax:
66
+ // `ng add @angular/localize -- --package-options`.
67
+ .strict(false);
68
+ const collectionName = await this.getCollectionName();
69
+ const workflow = await this.getOrCreateWorkflowForBuilder(collectionName);
70
+ try {
71
+ const collection = workflow.engine.createCollection(collectionName);
72
+ const options = await this.getSchematicOptions(collection, this.schematicName, workflow);
73
+ return this.addSchemaOptionsToCommand(localYargs, options);
46
74
  }
47
- else {
48
- return super.initialize(options);
75
+ catch (error) {
76
+ // During `ng add` prior to the downloading of the package
77
+ // we are not able to resolve and create a collection.
78
+ // Or when the the collection value is a path to a tarball.
49
79
  }
80
+ return localYargs;
50
81
  }
51
82
  // eslint-disable-next-line max-lines-per-function
52
83
  async run(options) {
53
84
  var _a;
54
- await (0, package_manager_1.ensureCompatibleNpm)(this.context.root);
55
- if (!options.collection) {
56
- this.logger.fatal(`The "ng add" command requires a name argument to be specified eg. ` +
57
- `${color_1.colors.yellow('ng add [name] ')}. For more details, use "ng help".`);
58
- return 1;
59
- }
85
+ const { logger, packageManager } = this.context;
86
+ const { verbose, registry, collection, skipConfirmation } = options;
87
+ packageManager.ensureCompatibility();
60
88
  let packageIdentifier;
61
89
  try {
62
- packageIdentifier = (0, npm_package_arg_1.default)(options.collection);
90
+ packageIdentifier = (0, npm_package_arg_1.default)(collection);
63
91
  }
64
92
  catch (e) {
65
- this.logger.error(e.message);
93
+ logger.error(e.message);
66
94
  return 1;
67
95
  }
68
96
  if (packageIdentifier.name &&
@@ -71,29 +99,28 @@ class AddCommand extends schematic_command_1.SchematicCommand {
71
99
  const validVersion = await this.isProjectVersionValid(packageIdentifier);
72
100
  if (validVersion) {
73
101
  // Already installed so just run schematic
74
- this.logger.info('Skipping installation: Package already installed');
75
- return this.executeSchematic(packageIdentifier.name, options['--']);
102
+ logger.info('Skipping installation: Package already installed');
103
+ return this.executeSchematic({ ...options, collection: packageIdentifier.name });
76
104
  }
77
105
  }
78
106
  const spinner = new spinner_1.Spinner();
79
107
  spinner.start('Determining package manager...');
80
- const packageManager = await (0, package_manager_1.getPackageManager)(this.context.root);
81
- const usingYarn = packageManager === workspace_schema_1.PackageManager.Yarn;
82
- 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)}`);
83
110
  if (packageIdentifier.name && packageIdentifier.type === 'tag' && !packageIdentifier.rawSpec) {
84
111
  // only package name provided; search for viable version
85
112
  // plus special cases for packages that did not have peer deps setup
86
113
  spinner.start('Searching for compatible package version...');
87
114
  let packageMetadata;
88
115
  try {
89
- packageMetadata = await (0, package_metadata_1.fetchPackageMetadata)(packageIdentifier.name, this.logger, {
90
- registry: options.registry,
116
+ packageMetadata = await (0, package_metadata_1.fetchPackageMetadata)(packageIdentifier.name, logger, {
117
+ registry,
91
118
  usingYarn,
92
- verbose: options.verbose,
119
+ verbose,
93
120
  });
94
121
  }
95
122
  catch (e) {
96
- spinner.fail('Unable to load package information from registry: ' + e.message);
123
+ spinner.fail(`Unable to load package information from registry: ${e.message}`);
97
124
  return 1;
98
125
  }
99
126
  // Start with the version tagged as `latest` if it exists
@@ -102,16 +129,8 @@ class AddCommand extends schematic_command_1.SchematicCommand {
102
129
  packageIdentifier = npm_package_arg_1.default.resolve(latestManifest.name, latestManifest.version);
103
130
  }
104
131
  // Adjust the version based on name and peer dependencies
105
- if (latestManifest && Object.keys(latestManifest.peerDependencies).length === 0) {
106
- if (latestManifest.name === '@angular/pwa') {
107
- const version = await this.findProjectVersion('@angular/cli');
108
- const semverOptions = { includePrerelease: true };
109
- if (version &&
110
- (((0, semver_1.validRange)(version) && (0, semver_1.intersects)(version, '7', semverOptions)) ||
111
- ((0, semver_1.valid)(version) && (0, semver_1.satisfies)(version, '7', semverOptions)))) {
112
- packageIdentifier = npm_package_arg_1.default.resolve('@angular/pwa', '0.12');
113
- }
114
- }
132
+ if ((latestManifest === null || latestManifest === void 0 ? void 0 : latestManifest.peerDependencies) &&
133
+ Object.keys(latestManifest.peerDependencies).length === 0) {
115
134
  spinner.succeed(`Found compatible package version: ${color_1.colors.grey(packageIdentifier.toString())}.`);
116
135
  }
117
136
  else if (!latestManifest || (await this.hasMismatchedPeer(latestManifest))) {
@@ -132,7 +151,7 @@ class AddCommand extends schematic_command_1.SchematicCommand {
132
151
  }
133
152
  return true;
134
153
  });
135
- versionManifests.sort((a, b) => (0, semver_1.rcompare)(a.version, b.version, true));
154
+ versionManifests.sort((a, b) => (0, semver_1.compare)(a.version, b.version, true));
136
155
  let newIdentifier;
137
156
  for (const versionManifest of versionManifests) {
138
157
  if (!(await this.hasMismatchedPeer(versionManifest))) {
@@ -156,9 +175,9 @@ class AddCommand extends schematic_command_1.SchematicCommand {
156
175
  let savePackage;
157
176
  try {
158
177
  spinner.start('Loading package information from registry...');
159
- const manifest = await (0, package_metadata_1.fetchPackageManifest)(packageIdentifier.toString(), this.logger, {
160
- registry: options.registry,
161
- verbose: options.verbose,
178
+ const manifest = await (0, package_metadata_1.fetchPackageManifest)(packageIdentifier.toString(), logger, {
179
+ registry,
180
+ verbose,
162
181
  usingYarn,
163
182
  });
164
183
  savePackage = (_a = manifest['ng-add']) === null || _a === void 0 ? void 0 : _a.save;
@@ -174,38 +193,38 @@ class AddCommand extends schematic_command_1.SchematicCommand {
174
193
  spinner.fail(`Unable to fetch package information for '${packageIdentifier}': ${e.message}`);
175
194
  return 1;
176
195
  }
177
- if (!options.skipConfirmation) {
196
+ if (!skipConfirmation) {
178
197
  const confirmationResponse = await (0, prompt_1.askConfirmation)(`\nThe package ${color_1.colors.blue(packageIdentifier.raw)} will be installed and executed.\n` +
179
198
  'Would you like to proceed?', true, false);
180
199
  if (!confirmationResponse) {
181
200
  if (!(0, tty_1.isTTY)()) {
182
- this.logger.error('No terminal detected. ' +
201
+ logger.error('No terminal detected. ' +
183
202
  `'--skip-confirmation' can be used to bypass installation confirmation. ` +
184
203
  `Ensure package name is correct prior to '--skip-confirmation' option usage.`);
185
204
  }
186
- this.logger.error('Command aborted.');
205
+ logger.error('Command aborted.');
187
206
  return 1;
188
207
  }
189
208
  }
190
209
  if (savePackage === false) {
191
210
  // Temporary packages are located in a different directory
192
211
  // Hence we need to resolve them using the temp path
193
- const { status, tempNodeModules } = await (0, install_package_1.installTempPackage)(packageIdentifier.raw, packageManager, options.registry ? [`--registry="${options.registry}"`] : undefined);
212
+ const { success, tempNodeModules } = await packageManager.installTemp(packageIdentifier.raw, registry ? [`--registry="${registry}"`] : undefined);
194
213
  const resolvedCollectionPath = require.resolve((0, path_1.join)(collectionName, 'package.json'), {
195
214
  paths: [tempNodeModules],
196
215
  });
197
- if (status !== 0) {
198
- return status;
216
+ if (!success) {
217
+ return 1;
199
218
  }
200
219
  collectionName = (0, path_1.dirname)(resolvedCollectionPath);
201
220
  }
202
221
  else {
203
- const status = await (0, install_package_1.installPackage)(packageIdentifier.raw, packageManager, savePackage, options.registry ? [`--registry="${options.registry}"`] : undefined);
204
- if (status !== 0) {
205
- return status;
222
+ const success = await packageManager.install(packageIdentifier.raw, savePackage, registry ? [`--registry="${registry}"`] : undefined);
223
+ if (!success) {
224
+ return 1;
206
225
  }
207
226
  }
208
- return this.executeSchematic(collectionName, options['--']);
227
+ return this.executeSchematic({ ...options, collection: collectionName });
209
228
  }
210
229
  async isProjectVersionValid(packageIdentifier) {
211
230
  if (!packageIdentifier.name) {
@@ -228,16 +247,18 @@ class AddCommand extends schematic_command_1.SchematicCommand {
228
247
  }
229
248
  return validVersion;
230
249
  }
231
- async reportAnalytics(paths, options, dimensions = [], metrics = []) {
232
- const collection = options.collection;
250
+ async reportAnalytics(options, paths) {
251
+ const collection = await this.getCollectionName();
252
+ const dimensions = [];
233
253
  // Add the collection if it's safe listed.
234
254
  if (collection && (0, analytics_1.isPackageNameSafeForAnalytics)(collection)) {
235
255
  dimensions[core_1.analytics.NgCliAnalyticsDimensions.NgAddCollection] = collection;
236
256
  }
237
- else {
238
- delete dimensions[core_1.analytics.NgCliAnalyticsDimensions.NgAddCollection];
239
- }
240
- return super.reportAnalytics(paths, options, dimensions, metrics);
257
+ return super.reportAnalytics(options, paths, dimensions);
258
+ }
259
+ async getCollectionName() {
260
+ const [, collectionName] = this.context.args.positional;
261
+ return collectionName;
241
262
  }
242
263
  isPackageInstalled(name) {
243
264
  try {
@@ -251,20 +272,25 @@ class AddCommand extends schematic_command_1.SchematicCommand {
251
272
  }
252
273
  return false;
253
274
  }
254
- async executeSchematic(collectionName, options = []) {
255
- const runOptions = {
256
- schematicOptions: options,
257
- collectionName,
258
- schematicName: 'ng-add',
259
- dryRun: false,
260
- force: false,
261
- };
275
+ async executeSchematic(options) {
262
276
  try {
263
- return await this.runSchematic(runOptions);
277
+ const { verbose, skipConfirmation, interactive, force, dryRun, registry, defaults, collection: collectionName, ...schematicOptions } = options;
278
+ return await this.runSchematic({
279
+ schematicOptions,
280
+ schematicName: this.schematicName,
281
+ collectionName,
282
+ executionOptions: {
283
+ interactive,
284
+ force,
285
+ dryRun,
286
+ defaults,
287
+ packageRegistry: registry,
288
+ },
289
+ });
264
290
  }
265
291
  catch (e) {
266
292
  if (e instanceof tools_1.NodePackageDoesNotSupportSchematics) {
267
- this.logger.error(core_1.tags.oneLine `
293
+ this.context.logger.error(core_1.tags.oneLine `
268
294
  The package that you are trying to add does not support schematics. You can try using
269
295
  a different version of the package or contact the package author to add ng-add support.
270
296
  `);
@@ -274,27 +300,29 @@ class AddCommand extends schematic_command_1.SchematicCommand {
274
300
  }
275
301
  }
276
302
  async findProjectVersion(name) {
303
+ var _a, _b;
304
+ const { logger, root } = this.context;
277
305
  let installedPackage;
278
306
  try {
279
307
  installedPackage = require.resolve((0, path_1.join)(name, 'package.json'), {
280
- paths: [this.context.root],
308
+ paths: [root],
281
309
  });
282
310
  }
283
311
  catch { }
284
312
  if (installedPackage) {
285
313
  try {
286
- const installed = await (0, package_metadata_1.fetchPackageManifest)((0, path_1.dirname)(installedPackage), this.logger);
314
+ const installed = await (0, package_metadata_1.fetchPackageManifest)((0, path_1.dirname)(installedPackage), logger);
287
315
  return installed.version;
288
316
  }
289
317
  catch { }
290
318
  }
291
319
  let projectManifest;
292
320
  try {
293
- projectManifest = await (0, package_metadata_1.fetchPackageManifest)(this.context.root, this.logger);
321
+ projectManifest = await (0, package_metadata_1.fetchPackageManifest)(root, logger);
294
322
  }
295
323
  catch { }
296
324
  if (projectManifest) {
297
- 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]);
298
326
  if (version) {
299
327
  return version;
300
328
  }
@@ -308,7 +336,7 @@ class AddCommand extends schematic_command_1.SchematicCommand {
308
336
  peerIdentifier = npm_package_arg_1.default.resolve(peer, manifest.peerDependencies[peer]);
309
337
  }
310
338
  catch {
311
- this.logger.warn(`Invalid peer dependency ${peer} found in package.`);
339
+ this.context.logger.warn(`Invalid peer dependency ${peer} found in package.`);
312
340
  continue;
313
341
  }
314
342
  if (peerIdentifier.type === 'version' || peerIdentifier.type === 'range') {
@@ -336,4 +364,4 @@ class AddCommand extends schematic_command_1.SchematicCommand {
336
364
  return false;
337
365
  }
338
366
  }
339
- exports.AddCommand = AddCommand;
367
+ exports.AddCommandModule = AddCommandModule;
@@ -0,0 +1,7 @@
1
+ Adds the npm package for a published library to your workspace, and configures
2
+ the project in the current working directory to use that library, as specified by the library's schematic.
3
+ For example, adding `@angular/pwa` configures your project for PWA support:
4
+
5
+ ```bash
6
+ ng add @angular/pwa
7
+ ```
@@ -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, Options } from '../../command-builder/command-module';
10
+ export declare class AnalyticsCommandModule extends CommandModule implements CommandModuleImplementation {
11
+ command: string;
12
+ describe: string;
13
+ longDescriptionPath?: string;
14
+ builder(localYargs: Argv): Argv;
15
+ run(_options: Options<{}>): void;
16
+ }
@@ -0,0 +1,35 @@
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.AnalyticsCommandModule = void 0;
11
+ const command_module_1 = require("../../command-builder/command-module");
12
+ const command_1 = require("../../command-builder/utilities/command");
13
+ const cli_1 = require("./info/cli");
14
+ const cli_2 = require("./settings/cli");
15
+ class AnalyticsCommandModule extends command_module_1.CommandModule {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.command = 'analytics';
19
+ this.describe = 'Configures the gathering of Angular CLI usage metrics. See https://angular.io/cli/usage-analytics-gathering';
20
+ }
21
+ builder(localYargs) {
22
+ const subcommands = [
23
+ cli_1.AnalyticsInfoCommandModule,
24
+ cli_2.AnalyticsDisableModule,
25
+ cli_2.AnalyticsEnableModule,
26
+ cli_2.AnalyticsPromptModule,
27
+ ].sort(); // sort by class name.
28
+ for (const module of subcommands) {
29
+ localYargs = (0, command_1.addCommandModuleToYargs)(localYargs, module, this.context);
30
+ }
31
+ return localYargs.demandCommand(1, command_1.demandCommandFailureMessage).strict();
32
+ }
33
+ run(_options) { }
34
+ }
35
+ exports.AnalyticsCommandModule = AnalyticsCommandModule;
@@ -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, Options } from '../../../command-builder/command-module';
10
+ export declare class AnalyticsInfoCommandModule extends CommandModule implements CommandModuleImplementation {
11
+ command: string;
12
+ describe: string;
13
+ longDescriptionPath?: string;
14
+ builder(localYargs: Argv): Argv;
15
+ run(_options: Options<{}>): Promise<void>;
16
+ }
@@ -0,0 +1,26 @@
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.AnalyticsInfoCommandModule = void 0;
11
+ const analytics_1 = require("../../../analytics/analytics");
12
+ const command_module_1 = require("../../../command-builder/command-module");
13
+ class AnalyticsInfoCommandModule extends command_module_1.CommandModule {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.command = 'info';
17
+ this.describe = 'Prints analytics gathering and reporting configuration in the console.';
18
+ }
19
+ builder(localYargs) {
20
+ return localYargs.strict();
21
+ }
22
+ async run(_options) {
23
+ this.context.logger.info(await (0, analytics_1.getAnalyticsInfoString)());
24
+ }
25
+ }
26
+ exports.AnalyticsInfoCommandModule = AnalyticsInfoCommandModule;
@@ -0,0 +1,35 @@
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, Options } from '../../../command-builder/command-module';
10
+ interface AnalyticsCommandArgs {
11
+ global: boolean;
12
+ }
13
+ declare abstract class AnalyticsSettingModule extends CommandModule<AnalyticsCommandArgs> implements CommandModuleImplementation<AnalyticsCommandArgs> {
14
+ longDescriptionPath?: string;
15
+ builder(localYargs: Argv): Argv<AnalyticsCommandArgs>;
16
+ abstract run({ global }: Options<AnalyticsCommandArgs>): Promise<void>;
17
+ }
18
+ export declare class AnalyticsDisableModule extends AnalyticsSettingModule implements CommandModuleImplementation<AnalyticsCommandArgs> {
19
+ command: string;
20
+ aliases: string;
21
+ describe: string;
22
+ run({ global }: Options<AnalyticsCommandArgs>): Promise<void>;
23
+ }
24
+ export declare class AnalyticsEnableModule extends AnalyticsSettingModule implements CommandModuleImplementation<AnalyticsCommandArgs> {
25
+ command: string;
26
+ aliases: string;
27
+ describe: string;
28
+ run({ global }: Options<AnalyticsCommandArgs>): Promise<void>;
29
+ }
30
+ export declare class AnalyticsPromptModule extends AnalyticsSettingModule implements CommandModuleImplementation<AnalyticsCommandArgs> {
31
+ command: string;
32
+ describe: string;
33
+ run({ global }: Options<AnalyticsCommandArgs>): Promise<void>;
34
+ }
35
+ export {};
@@ -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
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AnalyticsPromptModule = exports.AnalyticsEnableModule = exports.AnalyticsDisableModule = void 0;
11
+ const analytics_1 = require("../../../analytics/analytics");
12
+ const command_module_1 = require("../../../command-builder/command-module");
13
+ class AnalyticsSettingModule extends command_module_1.CommandModule {
14
+ builder(localYargs) {
15
+ return localYargs
16
+ .option('global', {
17
+ description: `Configure analytics gathering and reporting globally in the caller's home directory.`,
18
+ alias: ['g'],
19
+ type: 'boolean',
20
+ default: false,
21
+ })
22
+ .strict();
23
+ }
24
+ }
25
+ class AnalyticsDisableModule extends AnalyticsSettingModule {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.command = 'disable';
29
+ this.aliases = 'off';
30
+ this.describe = 'Disables analytics gathering and reporting for the user.';
31
+ }
32
+ async run({ global }) {
33
+ await (0, analytics_1.setAnalyticsConfig)(global, false);
34
+ process.stderr.write(await (0, analytics_1.getAnalyticsInfoString)());
35
+ }
36
+ }
37
+ exports.AnalyticsDisableModule = AnalyticsDisableModule;
38
+ class AnalyticsEnableModule extends AnalyticsSettingModule {
39
+ constructor() {
40
+ super(...arguments);
41
+ this.command = 'enable';
42
+ this.aliases = 'on';
43
+ this.describe = 'Enables analytics gathering and reporting for the user.';
44
+ }
45
+ async run({ global }) {
46
+ await (0, analytics_1.setAnalyticsConfig)(global, true);
47
+ process.stderr.write(await (0, analytics_1.getAnalyticsInfoString)());
48
+ }
49
+ }
50
+ exports.AnalyticsEnableModule = AnalyticsEnableModule;
51
+ class AnalyticsPromptModule extends AnalyticsSettingModule {
52
+ constructor() {
53
+ super(...arguments);
54
+ this.command = 'prompt';
55
+ this.describe = 'Prompts the user to set the analytics gathering status interactively.';
56
+ }
57
+ async run({ global }) {
58
+ await (0, analytics_1.promptAnalytics)(global, true);
59
+ }
60
+ }
61
+ exports.AnalyticsPromptModule = AnalyticsPromptModule;
@@ -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 { ArchitectCommandModule } from '../../command-builder/architect-command-module';
9
+ import { CommandModuleImplementation } from '../../command-builder/command-module';
10
+ export declare class BuildCommandModule extends ArchitectCommandModule implements CommandModuleImplementation {
11
+ multiTarget: boolean;
12
+ command: string;
13
+ aliases: string[];
14
+ describe: string;
15
+ longDescriptionPath: string;
16
+ }
@@ -0,0 +1,23 @@
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.BuildCommandModule = void 0;
11
+ const path_1 = require("path");
12
+ const architect_command_module_1 = require("../../command-builder/architect-command-module");
13
+ class BuildCommandModule extends architect_command_module_1.ArchitectCommandModule {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.multiTarget = false;
17
+ this.command = 'build [project]';
18
+ this.aliases = ['b'];
19
+ this.describe = 'Compiles an Angular application or library into an output directory named dist/ at the given output path.';
20
+ this.longDescriptionPath = (0, path_1.join)(__dirname, 'long-description.md');
21
+ }
22
+ }
23
+ exports.BuildCommandModule = BuildCommandModule;
@@ -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;