@angular/cli 14.0.0-next.4 → 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 (231) 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 +30 -15
  5. package/lib/config/workspace-schema.d.ts +6 -1
  6. package/lib/init.js +10 -9
  7. package/package.json +18 -20
  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 +304 -0
  12. package/src/command-builder/architect-base-command-module.d.ts +23 -0
  13. package/src/command-builder/architect-base-command-module.js +103 -0
  14. package/src/command-builder/architect-command-module.d.ts +22 -0
  15. package/src/command-builder/architect-command-module.js +108 -0
  16. package/src/command-builder/command-module.d.ts +89 -0
  17. package/src/command-builder/command-module.js +191 -0
  18. package/{utilities/package-json.js → src/command-builder/command-runner.d.ts} +2 -2
  19. package/src/command-builder/command-runner.js +152 -0
  20. package/src/command-builder/schematics-command-module.d.ts +46 -0
  21. package/src/command-builder/schematics-command-module.js +335 -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/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +0 -0
  29. package/{models → src/command-builder/utilities}/schematic-engine-host.js +0 -0
  30. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  31. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  32. package/src/commands/add/cli.d.ts +33 -0
  33. package/{commands/add-impl.js → src/commands/add/cli.js} +108 -80
  34. package/src/commands/add/long-description.md +7 -0
  35. package/src/commands/analytics/cli.d.ts +16 -0
  36. package/src/commands/analytics/cli.js +35 -0
  37. package/src/commands/analytics/info/cli.d.ts +16 -0
  38. package/src/commands/analytics/info/cli.js +26 -0
  39. package/src/commands/analytics/settings/cli.d.ts +35 -0
  40. package/src/commands/analytics/settings/cli.js +61 -0
  41. package/src/commands/build/cli.d.ts +16 -0
  42. package/src/commands/build/cli.js +23 -0
  43. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  44. package/src/commands/cache/clean/cli.d.ts +17 -0
  45. package/src/commands/cache/clean/cli.js +32 -0
  46. package/src/commands/cache/cli.d.ts +17 -0
  47. package/src/commands/cache/cli.js +38 -0
  48. package/src/commands/cache/info/cli.d.ts +20 -0
  49. package/src/commands/cache/info/cli.js +82 -0
  50. package/src/commands/cache/long-description.md +53 -0
  51. package/src/commands/cache/settings/cli.d.ts +27 -0
  52. package/src/commands/cache/settings/cli.js +42 -0
  53. package/src/commands/cache/utilities.d.ts +11 -0
  54. package/src/commands/cache/utilities.js +50 -0
  55. package/src/commands/config/cli.d.ts +24 -0
  56. package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
  57. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  58. package/src/commands/deploy/cli.d.ts +16 -0
  59. package/src/commands/deploy/cli.js +35 -0
  60. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  61. package/src/commands/doc/cli.d.ts +23 -0
  62. package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
  63. package/src/commands/e2e/cli.d.ts +17 -0
  64. package/src/commands/e2e/cli.js +34 -0
  65. package/src/commands/extract-i18n/cli.d.ts +15 -0
  66. package/src/commands/extract-i18n/cli.js +20 -0
  67. package/src/commands/generate/cli.d.ts +39 -0
  68. package/src/commands/generate/cli.js +145 -0
  69. package/src/commands/lint/cli.d.ts +16 -0
  70. package/src/commands/lint/cli.js +31 -0
  71. package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
  72. package/src/commands/make-this-awesome/cli.d.ts +17 -0
  73. package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
  74. package/src/commands/new/cli.d.ts +27 -0
  75. package/src/commands/new/cli.js +77 -0
  76. package/src/commands/run/cli.d.ts +23 -0
  77. package/src/commands/run/cli.js +59 -0
  78. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  79. package/src/commands/serve/cli.d.ts +16 -0
  80. package/src/commands/serve/cli.js +21 -0
  81. package/src/commands/test/cli.d.ts +16 -0
  82. package/src/commands/test/cli.js +23 -0
  83. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  84. package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +26 -9
  85. package/{commands/update-impl.js → src/commands/update/cli.js} +362 -316
  86. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  87. package/src/commands/update/schematic/index.js +33 -20
  88. package/src/commands/version/cli.d.ts +18 -0
  89. package/{commands/version-impl.js → src/commands/version/cli.js} +56 -74
  90. package/src/typings-bazel.d.ts +14 -0
  91. package/src/typings.d.ts +1 -14
  92. package/{utilities → src/utilities}/color.d.ts +0 -0
  93. package/{utilities → src/utilities}/color.js +5 -1
  94. package/{utilities → src/utilities}/config.d.ts +2 -2
  95. package/{utilities → src/utilities}/config.js +24 -16
  96. package/src/utilities/environment-options.d.ts +12 -0
  97. package/src/utilities/environment-options.js +24 -0
  98. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  99. package/{utilities → src/utilities}/find-up.js +5 -1
  100. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  101. package/{utilities → src/utilities}/json-file.js +0 -0
  102. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  103. package/{utilities → src/utilities}/log-file.js +0 -0
  104. package/src/utilities/package-manager.d.ts +41 -0
  105. package/src/utilities/package-manager.js +276 -0
  106. package/{utilities → src/utilities}/package-metadata.d.ts +15 -37
  107. package/{utilities → src/utilities}/package-metadata.js +15 -27
  108. package/{utilities → src/utilities}/package-tree.d.ts +2 -2
  109. package/{utilities → src/utilities}/package-tree.js +5 -1
  110. package/{utilities → src/utilities}/project.d.ts +0 -0
  111. package/{utilities → src/utilities}/project.js +5 -1
  112. package/{utilities → src/utilities}/prompt.d.ts +0 -0
  113. package/{utilities → src/utilities}/prompt.js +7 -3
  114. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  115. package/{utilities → src/utilities}/spinner.js +0 -0
  116. package/{utilities → src/utilities}/tty.d.ts +0 -0
  117. package/{utilities → src/utilities}/tty.js +0 -0
  118. package/{models → src/utilities}/version.d.ts +2 -1
  119. package/{models → src/utilities}/version.js +6 -6
  120. package/bin/postinstall/analytics-prompt.js +0 -27
  121. package/bin/postinstall/script.js +0 -16
  122. package/commands/add-impl.d.ts +0 -21
  123. package/commands/add.d.ts +0 -42
  124. package/commands/add.js +0 -10
  125. package/commands/add.json +0 -54
  126. package/commands/add.md +0 -10
  127. package/commands/analytics-impl.d.ts +0 -13
  128. package/commands/analytics-impl.js +0 -80
  129. package/commands/analytics-long.md +0 -8
  130. package/commands/analytics.d.ts +0 -46
  131. package/commands/analytics.js +0 -31
  132. package/commands/analytics.json +0 -37
  133. package/commands/build-impl.d.ts +0 -14
  134. package/commands/build-impl.js +0 -21
  135. package/commands/build.d.ts +0 -30
  136. package/commands/build.js +0 -10
  137. package/commands/build.json +0 -16
  138. package/commands/config-impl.d.ts +0 -15
  139. package/commands/config.d.ts +0 -34
  140. package/commands/config.js +0 -10
  141. package/commands/config.json +0 -43
  142. package/commands/definitions.json +0 -66
  143. package/commands/deploy-impl.d.ts +0 -15
  144. package/commands/deploy-impl.js +0 -36
  145. package/commands/deploy.d.ts +0 -30
  146. package/commands/deploy.js +0 -10
  147. package/commands/deploy.json +0 -34
  148. package/commands/doc-impl.d.ts +0 -13
  149. package/commands/doc.d.ts +0 -39
  150. package/commands/doc.js +0 -14
  151. package/commands/doc.json +0 -46
  152. package/commands/e2e-impl.d.ts +0 -16
  153. package/commands/e2e-impl.js +0 -36
  154. package/commands/e2e-long.md +0 -4
  155. package/commands/e2e.d.ts +0 -29
  156. package/commands/e2e.js +0 -10
  157. package/commands/e2e.json +0 -17
  158. package/commands/easter-egg-impl.d.ts +0 -12
  159. package/commands/easter-egg.d.ts +0 -14
  160. package/commands/easter-egg.js +0 -10
  161. package/commands/easter-egg.json +0 -12
  162. package/commands/extract-i18n-impl.d.ts +0 -14
  163. package/commands/extract-i18n-impl.js +0 -21
  164. package/commands/extract-i18n.d.ts +0 -29
  165. package/commands/extract-i18n.js +0 -10
  166. package/commands/extract-i18n.json +0 -15
  167. package/commands/generate-impl.d.ts +0 -18
  168. package/commands/generate-impl.js +0 -89
  169. package/commands/generate.d.ts +0 -37
  170. package/commands/generate.js +0 -10
  171. package/commands/generate.json +0 -31
  172. package/commands/help-impl.d.ts +0 -12
  173. package/commands/help-impl.js +0 -26
  174. package/commands/help-long.md +0 -7
  175. package/commands/help.d.ts +0 -17
  176. package/commands/help.js +0 -10
  177. package/commands/help.json +0 -13
  178. package/commands/lint-impl.d.ts +0 -16
  179. package/commands/lint-impl.js +0 -69
  180. package/commands/lint.d.ts +0 -29
  181. package/commands/lint.js +0 -10
  182. package/commands/lint.json +0 -36
  183. package/commands/new-impl.d.ts +0 -16
  184. package/commands/new-impl.js +0 -37
  185. package/commands/new.d.ts +0 -41
  186. package/commands/new.js +0 -10
  187. package/commands/new.json +0 -34
  188. package/commands/new.md +0 -16
  189. package/commands/run-impl.d.ts +0 -13
  190. package/commands/run-impl.js +0 -22
  191. package/commands/run.d.ts +0 -30
  192. package/commands/run.js +0 -10
  193. package/commands/run.json +0 -36
  194. package/commands/serve-impl.d.ts +0 -15
  195. package/commands/serve-impl.js +0 -24
  196. package/commands/serve.d.ts +0 -29
  197. package/commands/serve.js +0 -10
  198. package/commands/serve.json +0 -17
  199. package/commands/test-impl.d.ts +0 -15
  200. package/commands/test-impl.js +0 -22
  201. package/commands/test.d.ts +0 -29
  202. package/commands/test.js +0 -10
  203. package/commands/test.json +0 -17
  204. package/commands/update.d.ts +0 -61
  205. package/commands/update.js +0 -10
  206. package/commands/update.json +0 -78
  207. package/commands/version-impl.d.ts +0 -17
  208. package/commands/version.d.ts +0 -17
  209. package/commands/version.js +0 -10
  210. package/commands/version.json +0 -13
  211. package/commands.json +0 -20
  212. package/models/analytics.d.ts +0 -58
  213. package/models/analytics.js +0 -358
  214. package/models/architect-command.d.ts +0 -35
  215. package/models/architect-command.js +0 -364
  216. package/models/command-runner.d.ts +0 -24
  217. package/models/command-runner.js +0 -241
  218. package/models/command.d.ts +0 -34
  219. package/models/command.js +0 -143
  220. package/models/interface.d.ts +0 -196
  221. package/models/interface.js +0 -31
  222. package/models/parser.d.ts +0 -39
  223. package/models/parser.js +0 -349
  224. package/models/schematic-command.d.ts +0 -55
  225. package/models/schematic-command.js +0 -485
  226. package/utilities/install-package.d.ts +0 -16
  227. package/utilities/install-package.js +0 -193
  228. package/utilities/json-schema.d.ts +0 -17
  229. package/utilities/package-json.d.ts +0 -249
  230. package/utilities/package-manager.d.ts +0 -13
  231. package/utilities/package-manager.js +0 -106
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -29,45 +33,163 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
33
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
34
  };
31
35
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.UpdateCommand = void 0;
36
+ exports.UpdateCommandModule = void 0;
33
37
  const schematics_1 = require("@angular-devkit/schematics");
34
38
  const tools_1 = require("@angular-devkit/schematics/tools");
35
39
  const child_process_1 = require("child_process");
36
- const fs = __importStar(require("fs"));
40
+ const fs_1 = require("fs");
37
41
  const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
38
42
  const npm_pick_manifest_1 = __importDefault(require("npm-pick-manifest"));
39
43
  const path = __importStar(require("path"));
44
+ const path_1 = require("path");
40
45
  const semver = __importStar(require("semver"));
41
- const workspace_schema_1 = require("../lib/config/workspace-schema");
42
- const command_1 = require("../models/command");
43
- const schematic_engine_host_1 = require("../models/schematic-engine-host");
44
- const version_1 = require("../models/version");
45
- const color_1 = require("../utilities/color");
46
- const install_package_1 = require("../utilities/install-package");
47
- const log_file_1 = require("../utilities/log-file");
48
- const package_manager_1 = require("../utilities/package-manager");
49
- const package_metadata_1 = require("../utilities/package-metadata");
50
- const package_tree_1 = require("../utilities/package-tree");
51
- const UPDATE_SCHEMATIC_COLLECTION = path.join(__dirname, '../src/commands/update/schematic/collection.json');
52
- /**
53
- * Disable CLI version mismatch checks and forces usage of the invoked CLI
54
- * instead of invoking the local installed version.
55
- */
56
- const disableVersionCheckEnv = process.env['NG_DISABLE_VERSION_CHECK'];
57
- const disableVersionCheck = disableVersionCheckEnv !== undefined &&
58
- disableVersionCheckEnv !== '0' &&
59
- disableVersionCheckEnv.toLowerCase() !== 'false';
46
+ const workspace_schema_1 = require("../../../lib/config/workspace-schema");
47
+ const command_module_1 = require("../../command-builder/command-module");
48
+ const schematic_engine_host_1 = require("../../command-builder/utilities/schematic-engine-host");
49
+ const schematic_workflow_1 = require("../../command-builder/utilities/schematic-workflow");
50
+ const color_1 = require("../../utilities/color");
51
+ const environment_options_1 = require("../../utilities/environment-options");
52
+ const log_file_1 = require("../../utilities/log-file");
53
+ const package_metadata_1 = require("../../utilities/package-metadata");
54
+ const package_tree_1 = require("../../utilities/package-tree");
55
+ const version_1 = require("../../utilities/version");
60
56
  const ANGULAR_PACKAGES_REGEXP = /^@(?:angular|nguniversal)\//;
61
- class UpdateCommand extends command_1.Command {
57
+ const UPDATE_SCHEMATIC_COLLECTION = path.join(__dirname, 'schematic/collection.json');
58
+ class UpdateCommandModule extends command_module_1.CommandModule {
62
59
  constructor() {
63
60
  super(...arguments);
64
- this.allowMissingWorkspace = true;
65
- this.packageManager = workspace_schema_1.PackageManager.Npm;
61
+ this.shouldReportAnalytics = false;
62
+ this.command = 'update [packages..]';
63
+ this.describe = 'Updates your workspace and its dependencies. See https://update.angular.io/.';
64
+ this.longDescriptionPath = (0, path_1.join)(__dirname, 'long-description.md');
65
+ }
66
+ builder(localYargs) {
67
+ return localYargs
68
+ .positional('packages', {
69
+ description: 'The names of package(s) to update.',
70
+ coerce: (value) => (typeof value === 'string' ? [value] : value),
71
+ })
72
+ .option('force', {
73
+ description: 'Ignore peer dependency version mismatches. ' +
74
+ `Passes the '--force' flag to the package manager when installing packages.`,
75
+ type: 'boolean',
76
+ default: false,
77
+ })
78
+ .option('next', {
79
+ description: 'Use the prerelease version, including beta and RCs.',
80
+ type: 'boolean',
81
+ default: false,
82
+ })
83
+ .option('migrate-only', {
84
+ description: 'Only perform a migration, do not update the installed version.',
85
+ type: 'boolean',
86
+ })
87
+ .option('name', {
88
+ description: 'The name of the migration to run. ' +
89
+ `Only available with a single package being updated, and only with 'migrate-only' option.`,
90
+ type: 'string',
91
+ implies: ['migrate-only'],
92
+ conflicts: ['to', 'from'],
93
+ })
94
+ .option('from', {
95
+ description: 'Version from which to migrate from. ' +
96
+ `Only available with a single package being updated, and only with 'migrate-only'.`,
97
+ type: 'string',
98
+ implies: ['to', 'migrate-only'],
99
+ conflicts: ['name'],
100
+ })
101
+ .option('to', {
102
+ describe: 'Version up to which to apply migrations. Only available with a single package being updated, ' +
103
+ `and only with 'migrate-only' option. Requires 'from' to be specified. Default to the installed version detected.`,
104
+ type: 'string',
105
+ implies: ['from', 'migrate-only'],
106
+ conflicts: ['name'],
107
+ })
108
+ .option('allow-dirty', {
109
+ describe: 'Whether to allow updating when the repository contains modified or untracked files.',
110
+ type: 'boolean',
111
+ default: false,
112
+ })
113
+ .option('verbose', {
114
+ describe: 'Display additional details about internal operations during execution.',
115
+ type: 'boolean',
116
+ default: false,
117
+ })
118
+ .option('create-commits', {
119
+ describe: 'Create source control commits for updates and migrations.',
120
+ type: 'boolean',
121
+ alias: ['C'],
122
+ default: false,
123
+ })
124
+ .check(({ packages, next, 'allow-dirty': allowDirty, 'migrate-only': migrateOnly }) => {
125
+ const { logger } = this.context;
126
+ // This allows the user to easily reset any changes from the update.
127
+ if ((packages === null || packages === void 0 ? void 0 : packages.length) && !this.checkCleanGit()) {
128
+ if (allowDirty) {
129
+ logger.warn('Repository is not clean. Update changes will be mixed with pre-existing changes.');
130
+ }
131
+ else {
132
+ throw new command_module_1.CommandModuleError('Repository is not clean. Please commit or stash any changes before updating.');
133
+ }
134
+ }
135
+ if (migrateOnly) {
136
+ if ((packages === null || packages === void 0 ? void 0 : packages.length) !== 1) {
137
+ throw new command_module_1.CommandModuleError(`A single package must be specified when using the 'migrate-only' option.`);
138
+ }
139
+ if (next) {
140
+ logger.warn(`'next' option has no effect when using 'migrate-only' option.`);
141
+ }
142
+ }
143
+ return true;
144
+ })
145
+ .strict();
66
146
  }
67
- async initialize(options) {
68
- this.packageManager = await (0, package_manager_1.getPackageManager)(this.context.root);
69
- this.workflow = new tools_1.NodeWorkflow(this.context.root, {
70
- packageManager: this.packageManager,
147
+ async run(options) {
148
+ var _a, _b;
149
+ const { logger, packageManager } = this.context;
150
+ packageManager.ensureCompatibility();
151
+ // Check if the current installed CLI version is older than the latest compatible version.
152
+ if (!environment_options_1.disableVersionCheck) {
153
+ const cliVersionToInstall = await this.checkCLIVersion(options.packages, options.verbose, options.next);
154
+ if (cliVersionToInstall) {
155
+ logger.warn('The installed Angular CLI version is outdated.\n' +
156
+ `Installing a temporary Angular CLI versioned ${cliVersionToInstall} to perform the update.`);
157
+ return this.runTempBinary(`@angular/cli@${cliVersionToInstall}`, process.argv.slice(2));
158
+ }
159
+ }
160
+ const packages = [];
161
+ for (const request of (_a = options.packages) !== null && _a !== void 0 ? _a : []) {
162
+ try {
163
+ const packageIdentifier = (0, npm_package_arg_1.default)(request);
164
+ // only registry identifiers are supported
165
+ if (!packageIdentifier.registry) {
166
+ logger.error(`Package '${request}' is not a registry package identifer.`);
167
+ return 1;
168
+ }
169
+ if (packages.some((v) => v.name === packageIdentifier.name)) {
170
+ logger.error(`Duplicate package '${packageIdentifier.name}' specified.`);
171
+ return 1;
172
+ }
173
+ if (options.migrateOnly && packageIdentifier.rawSpec) {
174
+ logger.warn('Package specifier has no effect when using "migrate-only" option.');
175
+ }
176
+ // If next option is used and no specifier supplied, use next tag
177
+ if (options.next && !packageIdentifier.rawSpec) {
178
+ packageIdentifier.fetchSpec = 'next';
179
+ }
180
+ packages.push(packageIdentifier);
181
+ }
182
+ catch (e) {
183
+ logger.error(e.message);
184
+ return 1;
185
+ }
186
+ }
187
+ logger.info(`Using package manager: ${color_1.colors.grey(packageManager.name)}`);
188
+ logger.info('Collecting installed dependencies...');
189
+ const rootDependencies = await (0, package_tree_1.getProjectDependencies)(this.context.root);
190
+ logger.info(`Found ${rootDependencies.size} dependencies.`);
191
+ const workflow = new tools_1.NodeWorkflow(this.context.root, {
192
+ packageManager: packageManager.name,
71
193
  packageManagerForce: options.force,
72
194
  // __dirname -> favor @schematics/update from this package
73
195
  // Otherwise, use packages from the active workspace (migrations)
@@ -75,99 +197,77 @@ class UpdateCommand extends command_1.Command {
75
197
  schemaValidation: true,
76
198
  engineHostCreator: (options) => new schematic_engine_host_1.SchematicEngineHost(options.resolvePaths),
77
199
  });
200
+ if (packages.length === 0) {
201
+ // Show status
202
+ const { success } = await this.executeSchematic(workflow, UPDATE_SCHEMATIC_COLLECTION, 'update', {
203
+ force: options.force,
204
+ next: options.next,
205
+ verbose: options.verbose,
206
+ packageManager: packageManager.name,
207
+ packages: [],
208
+ });
209
+ return success ? 0 : 1;
210
+ }
211
+ return options.migrateOnly
212
+ ? this.migrateOnly(workflow, ((_b = options.packages) !== null && _b !== void 0 ? _b : [])[0], rootDependencies, options)
213
+ : this.updatePackagesAndMigrate(workflow, rootDependencies, options, packages);
78
214
  }
79
- async executeSchematic(collection, schematic, options = {}) {
80
- let error = false;
81
- let logs = [];
82
- const files = new Set();
83
- const reporterSubscription = this.workflow.reporter.subscribe((event) => {
84
- // Strip leading slash to prevent confusion.
85
- const eventPath = event.path.startsWith('/') ? event.path.substr(1) : event.path;
86
- switch (event.kind) {
87
- case 'error':
88
- error = true;
89
- const desc = event.description == 'alreadyExist' ? 'already exists' : 'does not exist.';
90
- this.logger.error(`ERROR! ${eventPath} ${desc}.`);
91
- break;
92
- case 'update':
93
- logs.push(`${color_1.colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)`);
94
- files.add(eventPath);
95
- break;
96
- case 'create':
97
- logs.push(`${color_1.colors.green('CREATE')} ${eventPath} (${event.content.length} bytes)`);
98
- files.add(eventPath);
99
- break;
100
- case 'delete':
101
- logs.push(`${color_1.colors.yellow('DELETE')} ${eventPath}`);
102
- files.add(eventPath);
103
- break;
104
- case 'rename':
105
- const eventToPath = event.to.startsWith('/') ? event.to.substr(1) : event.to;
106
- logs.push(`${color_1.colors.blue('RENAME')} ${eventPath} => ${eventToPath}`);
107
- files.add(eventPath);
108
- break;
109
- }
110
- });
111
- const lifecycleSubscription = this.workflow.lifeCycle.subscribe((event) => {
112
- if (event.kind == 'end' || event.kind == 'post-tasks-start') {
113
- if (!error) {
114
- // Output the logging queue, no error happened.
115
- logs.forEach((log) => this.logger.info(` ${log}`));
116
- logs = [];
117
- }
118
- }
119
- });
215
+ async executeSchematic(workflow, collection, schematic, options = {}) {
216
+ const { logger } = this.context;
217
+ const workflowSubscription = (0, schematic_workflow_1.subscribeToWorkflow)(workflow, logger);
120
218
  // TODO: Allow passing a schematic instance directly
121
219
  try {
122
- await this.workflow
220
+ await workflow
123
221
  .execute({
124
222
  collection,
125
223
  schematic,
126
224
  options,
127
- logger: this.logger,
225
+ logger,
128
226
  })
129
227
  .toPromise();
130
- reporterSubscription.unsubscribe();
131
- lifecycleSubscription.unsubscribe();
132
- return { success: !error, files };
228
+ return { success: !workflowSubscription.error, files: workflowSubscription.files };
133
229
  }
134
230
  catch (e) {
135
231
  if (e instanceof schematics_1.UnsuccessfulWorkflowExecution) {
136
- this.logger.error(`${color_1.colors.symbols.cross} Migration failed. See above for further details.\n`);
232
+ logger.error(`${color_1.colors.symbols.cross} Migration failed. See above for further details.\n`);
137
233
  }
138
234
  else {
139
235
  const logPath = (0, log_file_1.writeErrorToLogFile)(e);
140
- this.logger.fatal(`${color_1.colors.symbols.cross} Migration failed: ${e.message}\n` +
236
+ logger.fatal(`${color_1.colors.symbols.cross} Migration failed: ${e.message}\n` +
141
237
  ` See "${logPath}" for further details.\n`);
142
238
  }
143
- return { success: false, files };
239
+ return { success: false, files: workflowSubscription.files };
240
+ }
241
+ finally {
242
+ workflowSubscription.unsubscribe();
144
243
  }
145
244
  }
146
245
  /**
147
246
  * @return Whether or not the migration was performed successfully.
148
247
  */
149
- async executeMigration(packageName, collectionPath, migrationName, commit) {
150
- const collection = this.workflow.engine.createCollection(collectionPath);
248
+ async executeMigration(workflow, packageName, collectionPath, migrationName, commit) {
249
+ const { logger } = this.context;
250
+ const collection = workflow.engine.createCollection(collectionPath);
151
251
  const name = collection.listSchematicNames().find((name) => name === migrationName);
152
252
  if (!name) {
153
- this.logger.error(`Cannot find migration '${migrationName}' in '${packageName}'.`);
154
- return false;
253
+ logger.error(`Cannot find migration '${migrationName}' in '${packageName}'.`);
254
+ return 1;
155
255
  }
156
- const schematic = this.workflow.engine.createSchematic(name, collection);
157
- this.logger.info(color_1.colors.cyan(`** Executing '${migrationName}' of package '${packageName}' **\n`));
158
- return this.executePackageMigrations([schematic.description], packageName, commit);
256
+ logger.info(color_1.colors.cyan(`** Executing '${migrationName}' of package '${packageName}' **\n`));
257
+ const schematic = workflow.engine.createSchematic(name, collection);
258
+ return this.executePackageMigrations(workflow, [schematic.description], packageName, commit);
159
259
  }
160
260
  /**
161
261
  * @return Whether or not the migrations were performed successfully.
162
262
  */
163
- async executeMigrations(packageName, collectionPath, from, to, commit) {
164
- const collection = this.workflow.engine.createCollection(collectionPath);
263
+ async executeMigrations(workflow, packageName, collectionPath, from, to, commit) {
264
+ const collection = workflow.engine.createCollection(collectionPath);
165
265
  const migrationRange = new semver.Range('>' + (semver.prerelease(from) ? from.split('-')[0] + '-0' : from) + ' <=' + to.split('-')[0]);
166
266
  const migrations = [];
167
267
  for (const name of collection.listSchematicNames()) {
168
- const schematic = this.workflow.engine.createSchematic(name, collection);
268
+ const schematic = workflow.engine.createSchematic(name, collection);
169
269
  const description = schematic.description;
170
- description.version = coerceVersionNumber(description.version) || undefined;
270
+ description.version = coerceVersionNumber(description.version);
171
271
  if (!description.version) {
172
272
  continue;
173
273
  }
@@ -175,27 +275,28 @@ class UpdateCommand extends command_1.Command {
175
275
  migrations.push(description);
176
276
  }
177
277
  }
178
- migrations.sort((a, b) => semver.compare(a.version, b.version) || a.name.localeCompare(b.name));
179
278
  if (migrations.length === 0) {
180
- return true;
279
+ return 0;
181
280
  }
182
- this.logger.info(color_1.colors.cyan(`** Executing migrations of package '${packageName}' **\n`));
183
- return this.executePackageMigrations(migrations, packageName, commit);
281
+ migrations.sort((a, b) => semver.compare(a.version, b.version) || a.name.localeCompare(b.name));
282
+ this.context.logger.info(color_1.colors.cyan(`** Executing migrations of package '${packageName}' **\n`));
283
+ return this.executePackageMigrations(workflow, migrations, packageName, commit);
184
284
  }
185
- async executePackageMigrations(migrations, packageName, commit = false) {
285
+ async executePackageMigrations(workflow, migrations, packageName, commit = false) {
286
+ const { logger } = this.context;
186
287
  for (const migration of migrations) {
187
288
  const [title, ...description] = migration.description.split('. ');
188
- this.logger.info(color_1.colors.cyan(color_1.colors.symbols.pointer) +
289
+ logger.info(color_1.colors.cyan(color_1.colors.symbols.pointer) +
189
290
  ' ' +
190
291
  color_1.colors.bold(title.endsWith('.') ? title : title + '.'));
191
292
  if (description.length) {
192
- this.logger.info(' ' + description.join('.\n '));
293
+ logger.info(' ' + description.join('.\n '));
193
294
  }
194
- const result = await this.executeSchematic(migration.collection.name, migration.name);
295
+ const result = await this.executeSchematic(workflow, migration.collection.name, migration.name);
195
296
  if (!result.success) {
196
- return false;
297
+ return 1;
197
298
  }
198
- this.logger.info(' Migration completed.');
299
+ logger.info(' Migration completed.');
199
300
  // Commit migration
200
301
  if (commit) {
201
302
  const commitPrefix = `${packageName} migration - ${migration.name}`;
@@ -205,188 +306,107 @@ class UpdateCommand extends command_1.Command {
205
306
  const committed = this.commit(commitMessage);
206
307
  if (!committed) {
207
308
  // Failed to commit, something went wrong. Abort the update.
208
- return false;
309
+ return 1;
209
310
  }
210
311
  }
211
- this.logger.info(''); // Extra trailing newline.
312
+ logger.info(''); // Extra trailing newline.
212
313
  }
213
- return true;
314
+ return 0;
214
315
  }
215
- // eslint-disable-next-line max-lines-per-function
216
- async run(options) {
217
- var _a;
218
- await (0, package_manager_1.ensureCompatibleNpm)(this.context.root);
219
- // Check if the current installed CLI version is older than the latest compatible version.
220
- if (!disableVersionCheck) {
221
- const cliVersionToInstall = await this.checkCLIVersion(options['--'], options.verbose, options.next);
222
- if (cliVersionToInstall) {
223
- this.logger.warn('The installed Angular CLI version is outdated.\n' +
224
- `Installing a temporary Angular CLI versioned ${cliVersionToInstall} to perform the update.`);
225
- return (0, install_package_1.runTempPackageBin)(`@angular/cli@${cliVersionToInstall}`, this.packageManager, process.argv.slice(2));
226
- }
316
+ async migrateOnly(workflow, packageName, rootDependencies, options) {
317
+ const { logger } = this.context;
318
+ const packageDependency = rootDependencies.get(packageName);
319
+ let packagePath = packageDependency === null || packageDependency === void 0 ? void 0 : packageDependency.path;
320
+ let packageNode = packageDependency === null || packageDependency === void 0 ? void 0 : packageDependency.package;
321
+ if (packageDependency && !packageNode) {
322
+ logger.error('Package found in package.json but is not installed.');
323
+ return 1;
227
324
  }
228
- const logVerbose = (message) => {
229
- if (options.verbose) {
230
- this.logger.info(message);
231
- }
232
- };
233
- const packages = [];
234
- for (const request of options['--'] || []) {
235
- try {
236
- const packageIdentifier = (0, npm_package_arg_1.default)(request);
237
- // only registry identifiers are supported
238
- if (!packageIdentifier.registry) {
239
- this.logger.error(`Package '${request}' is not a registry package identifer.`);
240
- return 1;
241
- }
242
- if (packages.some((v) => v.name === packageIdentifier.name)) {
243
- this.logger.error(`Duplicate package '${packageIdentifier.name}' specified.`);
244
- return 1;
245
- }
246
- if (options.migrateOnly && packageIdentifier.rawSpec) {
247
- this.logger.warn('Package specifier has no effect when using "migrate-only" option.');
248
- }
249
- // If next option is used and no specifier supplied, use next tag
250
- if (options.next && !packageIdentifier.rawSpec) {
251
- packageIdentifier.fetchSpec = 'next';
252
- }
253
- packages.push(packageIdentifier);
254
- }
255
- catch (e) {
256
- this.logger.error(e.message);
257
- return 1;
325
+ else if (!packageDependency) {
326
+ // Allow running migrations on transitively installed dependencies
327
+ // There can technically be nested multiple versions
328
+ // TODO: If multiple, this should find all versions and ask which one to use
329
+ const packageJson = (0, package_tree_1.findPackageJson)(this.context.root, packageName);
330
+ if (packageJson) {
331
+ packagePath = path.dirname(packageJson);
332
+ packageNode = await (0, package_tree_1.readPackageJson)(packageJson);
258
333
  }
259
334
  }
260
- if (!options.migrateOnly && (options.from || options.to)) {
261
- this.logger.error('Can only use "from" or "to" options with "migrate-only" option.');
335
+ if (!packageNode || !packagePath) {
336
+ logger.error('Package is not installed.');
262
337
  return 1;
263
338
  }
264
- // If not asking for status then check for a clean git repository.
265
- // This allows the user to easily reset any changes from the update.
266
- if (packages.length && !this.checkCleanGit()) {
267
- if (options.allowDirty) {
268
- this.logger.warn('Repository is not clean. Update changes will be mixed with pre-existing changes.');
269
- }
270
- else {
271
- this.logger.error('Repository is not clean. Please commit or stash any changes before updating.');
272
- return 2;
273
- }
339
+ const updateMetadata = packageNode['ng-update'];
340
+ let migrations = updateMetadata === null || updateMetadata === void 0 ? void 0 : updateMetadata.migrations;
341
+ if (migrations === undefined) {
342
+ logger.error('Package does not provide migrations.');
343
+ return 1;
274
344
  }
275
- this.logger.info(`Using package manager: '${this.packageManager}'`);
276
- this.logger.info('Collecting installed dependencies...');
277
- const rootDependencies = await (0, package_tree_1.getProjectDependencies)(this.context.root);
278
- this.logger.info(`Found ${rootDependencies.size} dependencies.`);
279
- if (packages.length === 0) {
280
- // Show status
281
- const { success } = await this.executeSchematic(UPDATE_SCHEMATIC_COLLECTION, 'update', {
282
- force: options.force || false,
283
- next: options.next || false,
284
- verbose: options.verbose || false,
285
- packageManager: this.packageManager,
286
- packages: [],
287
- });
288
- return success ? 0 : 1;
345
+ else if (typeof migrations !== 'string') {
346
+ logger.error('Package contains a malformed migrations field.');
347
+ return 1;
289
348
  }
290
- if (options.migrateOnly) {
291
- if (!options.from && typeof options.migrateOnly !== 'string') {
292
- this.logger.error('"from" option is required when using the "migrate-only" option without a migration name.');
293
- return 1;
294
- }
295
- else if (packages.length !== 1) {
296
- this.logger.error('A single package must be specified when using the "migrate-only" option.');
297
- return 1;
298
- }
299
- if (options.next) {
300
- this.logger.warn('"next" option has no effect when using "migrate-only" option.');
301
- }
302
- const packageName = packages[0].name;
303
- const packageDependency = rootDependencies.get(packageName);
304
- let packagePath = packageDependency === null || packageDependency === void 0 ? void 0 : packageDependency.path;
305
- let packageNode = packageDependency === null || packageDependency === void 0 ? void 0 : packageDependency.package;
306
- if (packageDependency && !packageNode) {
307
- this.logger.error('Package found in package.json but is not installed.');
308
- return 1;
309
- }
310
- else if (!packageDependency) {
311
- // Allow running migrations on transitively installed dependencies
312
- // There can technically be nested multiple versions
313
- // TODO: If multiple, this should find all versions and ask which one to use
314
- const packageJson = (0, package_tree_1.findPackageJson)(this.context.root, packageName);
315
- if (packageJson) {
316
- packagePath = path.dirname(packageJson);
317
- packageNode = await (0, package_tree_1.readPackageJson)(packageJson);
318
- }
319
- }
320
- if (!packageNode || !packagePath) {
321
- this.logger.error('Package is not installed.');
322
- return 1;
323
- }
324
- const updateMetadata = packageNode['ng-update'];
325
- let migrations = updateMetadata === null || updateMetadata === void 0 ? void 0 : updateMetadata.migrations;
326
- if (migrations === undefined) {
327
- this.logger.error('Package does not provide migrations.');
328
- return 1;
329
- }
330
- else if (typeof migrations !== 'string') {
331
- this.logger.error('Package contains a malformed migrations field.');
332
- return 1;
333
- }
334
- else if (path.posix.isAbsolute(migrations) || path.win32.isAbsolute(migrations)) {
335
- this.logger.error('Package contains an invalid migrations field. Absolute paths are not permitted.');
336
- return 1;
337
- }
338
- // Normalize slashes
339
- migrations = migrations.replace(/\\/g, '/');
340
- if (migrations.startsWith('../')) {
341
- this.logger.error('Package contains an invalid migrations field. Paths outside the package root are not permitted.');
342
- return 1;
343
- }
344
- // Check if it is a package-local location
345
- const localMigrations = path.join(packagePath, migrations);
346
- if (fs.existsSync(localMigrations)) {
347
- migrations = localMigrations;
349
+ else if (path.posix.isAbsolute(migrations) || path.win32.isAbsolute(migrations)) {
350
+ logger.error('Package contains an invalid migrations field. Absolute paths are not permitted.');
351
+ return 1;
352
+ }
353
+ // Normalize slashes
354
+ migrations = migrations.replace(/\\/g, '/');
355
+ if (migrations.startsWith('../')) {
356
+ logger.error('Package contains an invalid migrations field. Paths outside the package root are not permitted.');
357
+ return 1;
358
+ }
359
+ // Check if it is a package-local location
360
+ const localMigrations = path.join(packagePath, migrations);
361
+ if ((0, fs_1.existsSync)(localMigrations)) {
362
+ migrations = localMigrations;
363
+ }
364
+ else {
365
+ // Try to resolve from package location.
366
+ // This avoids issues with package hoisting.
367
+ try {
368
+ migrations = require.resolve(migrations, { paths: [packagePath] });
348
369
  }
349
- else {
350
- // Try to resolve from package location.
351
- // This avoids issues with package hoisting.
352
- try {
353
- migrations = require.resolve(migrations, { paths: [packagePath] });
354
- }
355
- catch (e) {
356
- if (e.code === 'MODULE_NOT_FOUND') {
357
- this.logger.error('Migrations for package were not found.');
358
- }
359
- else {
360
- this.logger.error(`Unable to resolve migrations for package. [${e.message}]`);
361
- }
362
- return 1;
370
+ catch (e) {
371
+ if (e.code === 'MODULE_NOT_FOUND') {
372
+ logger.error('Migrations for package were not found.');
363
373
  }
364
- }
365
- let result;
366
- if (typeof options.migrateOnly == 'string') {
367
- result = await this.executeMigration(packageName, migrations, options.migrateOnly, options.createCommits);
368
- }
369
- else {
370
- const from = coerceVersionNumber(options.from);
371
- if (!from) {
372
- this.logger.error(`"from" value [${options.from}] is not a valid version.`);
373
- return 1;
374
+ else {
375
+ logger.error(`Unable to resolve migrations for package. [${e.message}]`);
374
376
  }
375
- result = await this.executeMigrations(packageName, migrations, from, options.to || packageNode.version, options.createCommits);
377
+ return 1;
376
378
  }
377
- return result ? 0 : 1;
378
379
  }
380
+ if (options.name) {
381
+ return this.executeMigration(workflow, packageName, migrations, options.name, options.createCommits);
382
+ }
383
+ const from = coerceVersionNumber(options.from);
384
+ if (!from) {
385
+ logger.error(`"from" value [${options.from}] is not a valid version.`);
386
+ return 1;
387
+ }
388
+ return this.executeMigrations(workflow, packageName, migrations, from, options.to || packageNode.version, options.createCommits);
389
+ }
390
+ // eslint-disable-next-line max-lines-per-function
391
+ async updatePackagesAndMigrate(workflow, rootDependencies, options, packages) {
392
+ var _a;
393
+ const { logger } = this.context;
394
+ const logVerbose = (message) => {
395
+ if (options.verbose) {
396
+ logger.info(message);
397
+ }
398
+ };
379
399
  const requests = [];
380
400
  // Validate packages actually are part of the workspace
381
401
  for (const pkg of packages) {
382
402
  const node = rootDependencies.get(pkg.name);
383
403
  if (!(node === null || node === void 0 ? void 0 : node.package)) {
384
- this.logger.error(`Package '${pkg.name}' is not a dependency.`);
404
+ logger.error(`Package '${pkg.name}' is not a dependency.`);
385
405
  return 1;
386
406
  }
387
407
  // If a specific version is requested and matches the installed version, skip.
388
408
  if (pkg.type === 'version' && node.package.version === pkg.fetchSpec) {
389
- this.logger.info(`Package '${pkg.name}' is already at '${pkg.fetchSpec}'.`);
409
+ logger.info(`Package '${pkg.name}' is already at '${pkg.fetchSpec}'.`);
390
410
  continue;
391
411
  }
392
412
  requests.push({ identifier: pkg, node });
@@ -394,20 +414,20 @@ class UpdateCommand extends command_1.Command {
394
414
  if (requests.length === 0) {
395
415
  return 0;
396
416
  }
417
+ logger.info('Fetching dependency metadata from registry...');
397
418
  const packagesToUpdate = [];
398
- this.logger.info('Fetching dependency metadata from registry...');
399
419
  for (const { identifier: requestIdentifier, node } of requests) {
400
420
  const packageName = requestIdentifier.name;
401
421
  let metadata;
402
422
  try {
403
423
  // Metadata requests are internally cached; multiple requests for same name
404
424
  // does not result in additional network traffic
405
- metadata = await (0, package_metadata_1.fetchPackageMetadata)(packageName, this.logger, {
425
+ metadata = await (0, package_metadata_1.fetchPackageMetadata)(packageName, logger, {
406
426
  verbose: options.verbose,
407
427
  });
408
428
  }
409
429
  catch (e) {
410
- this.logger.error(`Error fetching metadata for '${packageName}': ` + e.message);
430
+ logger.error(`Error fetching metadata for '${packageName}': ` + e.message);
411
431
  return 1;
412
432
  }
413
433
  // Try to find a package version based on the user requested package specifier
@@ -442,11 +462,11 @@ class UpdateCommand extends command_1.Command {
442
462
  }
443
463
  }
444
464
  if (!manifest) {
445
- this.logger.error(`Package specified by '${requestIdentifier.raw}' does not exist within the registry.`);
465
+ logger.error(`Package specified by '${requestIdentifier.raw}' does not exist within the registry.`);
446
466
  return 1;
447
467
  }
448
468
  if (manifest.version === ((_a = node.package) === null || _a === void 0 ? void 0 : _a.version)) {
449
- this.logger.info(`Package '${packageName}' is already up to date.`);
469
+ logger.info(`Package '${packageName}' is already up to date.`);
450
470
  continue;
451
471
  }
452
472
  if (node.package && ANGULAR_PACKAGES_REGEXP.test(node.package.name)) {
@@ -458,12 +478,12 @@ class UpdateCommand extends command_1.Command {
458
478
  if (currentMajorVersion < 6) {
459
479
  // Before version 6, the major versions were not always sequential.
460
480
  // Example @angular/core skipped version 3, @angular/cli skipped versions 2-5.
461
- this.logger.error(`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
481
+ logger.error(`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
462
482
  `For more information about the update process, see https://update.angular.io/.`);
463
483
  }
464
484
  else {
465
485
  const nextMajorVersionFromCurrent = currentMajorVersion + 1;
466
- this.logger.error(`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
486
+ logger.error(`Updating multiple major versions of '${name}' at once is not supported. Please migrate each major version individually.\n` +
467
487
  `Run 'ng update ${name}@${nextMajorVersionFromCurrent}' in your workspace directory ` +
468
488
  `to update to latest '${nextMajorVersionFromCurrent}.x' version of '${name}'.\n\n` +
469
489
  `For more information about the update process, see https://update.angular.io/?v=${currentMajorVersion}.0-${nextMajorVersionFromCurrent}.0`);
@@ -476,42 +496,29 @@ class UpdateCommand extends command_1.Command {
476
496
  if (packagesToUpdate.length === 0) {
477
497
  return 0;
478
498
  }
479
- const { success } = await this.executeSchematic(UPDATE_SCHEMATIC_COLLECTION, 'update', {
480
- verbose: options.verbose || false,
481
- force: options.force || false,
482
- next: !!options.next,
483
- packageManager: this.packageManager,
499
+ const { success } = await this.executeSchematic(workflow, UPDATE_SCHEMATIC_COLLECTION, 'update', {
500
+ verbose: options.verbose,
501
+ force: options.force,
502
+ next: options.next,
503
+ packageManager: this.context.packageManager.name,
484
504
  packages: packagesToUpdate,
485
505
  });
486
506
  if (success) {
487
507
  try {
488
- // Remove existing node modules directory to provide a stronger guarantee that packages
489
- // will be hoisted into the correct locations.
490
- // The below should be removed and replaced with just `rm` when support for Node.Js 12 is removed.
491
- const { rm, rmdir } = fs.promises;
492
- if (rm) {
493
- await rm(path.join(this.context.root, 'node_modules'), {
494
- force: true,
495
- recursive: true,
496
- maxRetries: 3,
497
- });
498
- }
499
- else {
500
- await rmdir(path.join(this.context.root, 'node_modules'), {
501
- recursive: true,
502
- maxRetries: 3,
503
- });
504
- }
508
+ await fs_1.promises.rm(path.join(this.context.root, 'node_modules'), {
509
+ force: true,
510
+ recursive: true,
511
+ maxRetries: 3,
512
+ });
505
513
  }
506
514
  catch { }
507
- const result = await (0, install_package_1.installAllPackages)(this.packageManager, options.force ? ['--force'] : [], this.context.root);
508
- if (result !== 0) {
509
- return result;
515
+ const installationSuccess = await this.context.packageManager.installAll(options.force ? ['--force'] : [], this.context.root);
516
+ if (!installationSuccess) {
517
+ return 1;
510
518
  }
511
519
  }
512
520
  if (success && options.createCommits) {
513
- const committed = this.commit(`Angular CLI update for packages - ${packagesToUpdate.join(', ')}`);
514
- if (!committed) {
521
+ if (!this.commit(`Angular CLI update for packages - ${packagesToUpdate.join(', ')}`)) {
515
522
  return 1;
516
523
  }
517
524
  }
@@ -545,18 +552,18 @@ class UpdateCommand extends command_1.Command {
545
552
  catch (e) {
546
553
  if (e.code === 'MODULE_NOT_FOUND') {
547
554
  logVerbose(e.toString());
548
- this.logger.error(`Migrations for package (${migration.package}) were not found.` +
555
+ logger.error(`Migrations for package (${migration.package}) were not found.` +
549
556
  ' The package could not be found in the workspace.');
550
557
  }
551
558
  else {
552
- this.logger.error(`Unable to resolve migrations for package (${migration.package}). [${e.message}]`);
559
+ logger.error(`Unable to resolve migrations for package (${migration.package}). [${e.message}]`);
553
560
  }
554
561
  return 1;
555
562
  }
556
563
  let migrations;
557
564
  // Check if it is a package-local location
558
565
  const localMigrations = path.join(packagePath, migration.collection);
559
- if (fs.existsSync(localMigrations)) {
566
+ if ((0, fs_1.existsSync)(localMigrations)) {
560
567
  migrations = localMigrations;
561
568
  }
562
569
  else {
@@ -567,15 +574,15 @@ class UpdateCommand extends command_1.Command {
567
574
  }
568
575
  catch (e) {
569
576
  if (e.code === 'MODULE_NOT_FOUND') {
570
- this.logger.error(`Migrations for package (${migration.package}) were not found.`);
577
+ logger.error(`Migrations for package (${migration.package}) were not found.`);
571
578
  }
572
579
  else {
573
- this.logger.error(`Unable to resolve migrations for package (${migration.package}). [${e.message}]`);
580
+ logger.error(`Unable to resolve migrations for package (${migration.package}). [${e.message}]`);
574
581
  }
575
582
  return 1;
576
583
  }
577
584
  }
578
- const result = await this.executeMigrations(migration.package, migrations, migration.from, migration.to, options.createCommits);
585
+ const result = await this.executeMigrations(workflow, migration.package, migrations, migration.from, migration.to, options.createCommits);
579
586
  if (!result) {
580
587
  return 0;
581
588
  }
@@ -587,17 +594,18 @@ class UpdateCommand extends command_1.Command {
587
594
  * @return Whether or not the commit was successful.
588
595
  */
589
596
  commit(message) {
597
+ const { logger } = this.context;
590
598
  // Check if a commit is needed.
591
599
  let commitNeeded;
592
600
  try {
593
601
  commitNeeded = hasChangesToCommit();
594
602
  }
595
603
  catch (err) {
596
- this.logger.error(` Failed to read Git tree:\n${err.stderr}`);
604
+ logger.error(` Failed to read Git tree:\n${err.stderr}`);
597
605
  return false;
598
606
  }
599
607
  if (!commitNeeded) {
600
- this.logger.info(' No changes to commit after migration.');
608
+ logger.info(' No changes to commit after migration.');
601
609
  return true;
602
610
  }
603
611
  // Commit changes and abort on error.
@@ -605,20 +613,20 @@ class UpdateCommand extends command_1.Command {
605
613
  createCommit(message);
606
614
  }
607
615
  catch (err) {
608
- this.logger.error(`Failed to commit update (${message}):\n${err.stderr}`);
616
+ logger.error(`Failed to commit update (${message}):\n${err.stderr}`);
609
617
  return false;
610
618
  }
611
619
  // Notify user of the commit.
612
620
  const hash = findCurrentGitSha();
613
621
  const shortMessage = message.split('\n')[0];
614
622
  if (hash) {
615
- this.logger.info(` Committed migration step (${getShortHash(hash)}): ${shortMessage}.`);
623
+ logger.info(` Committed migration step (${getShortHash(hash)}): ${shortMessage}.`);
616
624
  }
617
625
  else {
618
626
  // Commit was successful, but reading the hash was not. Something weird happened,
619
627
  // but nothing that would stop the update. Just log the weirdness and continue.
620
- this.logger.info(` Committed migration step: ${shortMessage}.`);
621
- this.logger.warn(' Failed to look up hash of most recent commit, continuing anyways.');
628
+ logger.info(` Committed migration step: ${shortMessage}.`);
629
+ logger.warn(' Failed to look up hash of most recent commit, continuing anyways.');
622
630
  }
623
631
  return true;
624
632
  }
@@ -648,9 +656,9 @@ class UpdateCommand extends command_1.Command {
648
656
  * @returns the version to install or null when there is no update to install.
649
657
  */
650
658
  async checkCLIVersion(packagesToUpdate, verbose = false, next = false) {
651
- const { version } = await (0, package_metadata_1.fetchPackageManifest)(`@angular/cli@${this.getCLIUpdateRunnerVersion(packagesToUpdate, next)}`, this.logger, {
659
+ const { version } = await (0, package_metadata_1.fetchPackageManifest)(`@angular/cli@${this.getCLIUpdateRunnerVersion(typeof packagesToUpdate === 'string' ? [packagesToUpdate] : packagesToUpdate, next)}`, this.context.logger, {
652
660
  verbose,
653
- usingYarn: this.packageManager === workspace_schema_1.PackageManager.Yarn,
661
+ usingYarn: this.context.packageManager.name === workspace_schema_1.PackageManager.Yarn,
654
662
  });
655
663
  return version_1.VERSION.full === version ? null : version;
656
664
  }
@@ -677,16 +685,54 @@ class UpdateCommand extends command_1.Command {
677
685
  // We end up using Angular ClI v13 to run the migrations if we run the migrations using the CLI installed major version + 1 logic.
678
686
  return version_1.VERSION.major;
679
687
  }
688
+ async runTempBinary(packageName, args = []) {
689
+ const { success, tempNodeModules } = await this.context.packageManager.installTemp(packageName);
690
+ if (!success) {
691
+ return 1;
692
+ }
693
+ // Remove version/tag etc... from package name
694
+ // Ex: @angular/cli@latest -> @angular/cli
695
+ const packageNameNoVersion = packageName.substring(0, packageName.lastIndexOf('@'));
696
+ const pkgLocation = (0, path_1.join)(tempNodeModules, packageNameNoVersion);
697
+ const packageJsonPath = (0, path_1.join)(pkgLocation, 'package.json');
698
+ // Get a binary location for this package
699
+ let binPath;
700
+ if ((0, fs_1.existsSync)(packageJsonPath)) {
701
+ const content = await fs_1.promises.readFile(packageJsonPath, 'utf-8');
702
+ if (content) {
703
+ const { bin = {} } = JSON.parse(content);
704
+ const binKeys = Object.keys(bin);
705
+ if (binKeys.length) {
706
+ binPath = (0, path_1.resolve)(pkgLocation, bin[binKeys[0]]);
707
+ }
708
+ }
709
+ }
710
+ if (!binPath) {
711
+ throw new Error(`Cannot locate bin for temporary package: ${packageNameNoVersion}.`);
712
+ }
713
+ const { status, error } = (0, child_process_1.spawnSync)(process.execPath, [binPath, ...args], {
714
+ stdio: 'inherit',
715
+ env: {
716
+ ...process.env,
717
+ NG_DISABLE_VERSION_CHECK: 'true',
718
+ NG_CLI_ANALYTICS: 'false',
719
+ },
720
+ });
721
+ if (status === null && error) {
722
+ throw error;
723
+ }
724
+ return status !== null && status !== void 0 ? status : 0;
725
+ }
680
726
  }
681
- exports.UpdateCommand = UpdateCommand;
727
+ exports.UpdateCommandModule = UpdateCommandModule;
728
+ UpdateCommandModule.scope = command_module_1.CommandScope.In;
682
729
  /**
683
730
  * @return Whether or not the working directory has Git changes to commit.
684
731
  */
685
732
  function hasChangesToCommit() {
686
733
  // List all modified files not covered by .gitignore.
687
- const files = (0, child_process_1.execSync)('git ls-files -m -d -o --exclude-standard').toString();
688
734
  // If any files are returned, then there must be something to commit.
689
- return files !== '';
735
+ return (0, child_process_1.execSync)('git ls-files -m -d -o --exclude-standard').toString() !== '';
690
736
  }
691
737
  /**
692
738
  * Precondition: Must have pending changes to commit, they do not need to be staged.
@@ -704,8 +750,7 @@ function createCommit(message) {
704
750
  */
705
751
  function findCurrentGitSha() {
706
752
  try {
707
- const hash = (0, child_process_1.execSync)('git rev-parse HEAD', { encoding: 'utf8', stdio: 'pipe' });
708
- return hash.trim();
753
+ return (0, child_process_1.execSync)('git rev-parse HEAD', { encoding: 'utf8', stdio: 'pipe' }).trim();
709
754
  }
710
755
  catch {
711
756
  return null;
@@ -715,23 +760,24 @@ function getShortHash(commitHash) {
715
760
  return commitHash.slice(0, 9);
716
761
  }
717
762
  function coerceVersionNumber(version) {
763
+ var _a;
718
764
  if (!version) {
719
- return null;
765
+ return undefined;
720
766
  }
721
- if (!version.match(/^\d{1,30}\.\d{1,30}\.\d{1,30}/)) {
767
+ if (!/^\d{1,30}\.\d{1,30}\.\d{1,30}/.test(version)) {
722
768
  const match = version.match(/^\d{1,30}(\.\d{1,30})*/);
723
769
  if (!match) {
724
- return null;
770
+ return undefined;
725
771
  }
726
772
  if (!match[1]) {
727
- version = version.substr(0, match[0].length) + '.0.0' + version.substr(match[0].length);
773
+ version = version.substring(0, match[0].length) + '.0.0' + version.substring(match[0].length);
728
774
  }
729
775
  else if (!match[2]) {
730
- version = version.substr(0, match[0].length) + '.0' + version.substr(match[0].length);
776
+ version = version.substring(0, match[0].length) + '.0' + version.substring(match[0].length);
731
777
  }
732
778
  else {
733
- return null;
779
+ return undefined;
734
780
  }
735
781
  }
736
- return semver.valid(version);
782
+ return (_a = semver.valid(version)) !== null && _a !== void 0 ? _a : undefined;
737
783
  }