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