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