@eui/cli 22.0.0-rc.5 → 22.0.0-rc.6
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/README.md +33 -1
- package/bin/eui-cli.js +15 -2
- package/lib/app-utils/migrate.js +88 -6
- package/lib/app-utils/upgrade.js +323 -0
- package/lib/skeletons/_angular/base/package.json +3 -3
- package/lib/skeletons/_angular/base-mobile/package.json +2 -2
- package/lib/skeletons/_angular/options/pnpm/package.json +11 -11
- package/lib/skeletons/_react/base/package.json +3 -3
- package/lib/skeletons/_react/options/pnpm/package.json +5 -5
- package/package.json +1 -1
- package/skeletons/_angular/base/src/tsconfig.spec.json +10 -0
- package/test/upgrade.test.js +308 -0
package/README.md
CHANGED
|
@@ -306,8 +306,31 @@ migration on demand.
|
|
|
306
306
|
|
|
307
307
|
```sh
|
|
308
308
|
eui-cli migrate [--groups <list>] [--only <list>] [--path <path>] [--dryRun] [--force]
|
|
309
|
+
[--to <version|tag>] [--skipInstall] [--skipUpgrade]
|
|
309
310
|
```
|
|
310
311
|
|
|
312
|
+
**Upgrade phase (v21 → v22).** The schematics ship in the target `@eui/core`, and the base `migrate`
|
|
313
|
+
schematic is skipped unless the installed `@eui/core` is that major. So when the installed
|
|
314
|
+
`@eui/core` (or, without `node_modules`, the version in `package.json`) is one major below the target,
|
|
315
|
+
`migrate` first upgrades the app, in this order:
|
|
316
|
+
|
|
317
|
+
1. bump every `@eui/*` dependency in `package.json` to `--to` (a `^`/`~` prefix is kept, other
|
|
318
|
+
dependencies are untouched, `@eui/eds-wc` has its own version line and is left alone) and add
|
|
319
|
+
`@eui/deps-base-dev` next to `@eui/deps-base` (v22 moved the build/lint/test tooling there; Angular
|
|
320
|
+
itself comes from `@eui/deps-base(-dev)`, it is not bumped separately);
|
|
321
|
+
2. install with the package manager detected from the lockfile (`pnpm-lock.yaml` → pnpm,
|
|
322
|
+
`package-lock.json` → npm, `yarn.lock` or none → yarn);
|
|
323
|
+
3. check that the installed `@eui/core` is the target major, then run the schematics. For the `eui` group
|
|
324
|
+
`migrate-eui-config-files` (package.json / tsconfig / angular.json / mock server of the generated app)
|
|
325
|
+
runs first, before `migrate-all`.
|
|
326
|
+
|
|
327
|
+
The phase is a no-op when the app is already on the target, and refuses any other starting major
|
|
328
|
+
(older than the previous one, or newer than the target). The working tree must be clean unless
|
|
329
|
+
`--force` is given (the schematics then run with `--force`, as the upgrade itself modified `package.json`
|
|
330
|
+
and the lockfile). With `--dryRun` on a not-yet-upgraded app only the `package.json` diff is shown:
|
|
331
|
+
nothing is written or installed, and the schematics are not run because they cannot run (even as a dry
|
|
332
|
+
run) before the install.
|
|
333
|
+
|
|
311
334
|
Run without arguments to pick interactively in two stages: first choose the groups (all
|
|
312
335
|
pre-selected), then for each multi-schematic group a pre-checked checklist of its individual
|
|
313
336
|
schematics — press enter to keep them all, or toggle to run a subset. Groups always run in the
|
|
@@ -324,7 +347,10 @@ Options:
|
|
|
324
347
|
- `--only <list>` - Comma/space separated specific schematic names to run within the selected groups
|
|
325
348
|
- `--path <path>` - Restrict schematics to a sub-path (eUI schematics default to `./src`)
|
|
326
349
|
- `--dryRun` - Preview changes without writing files (`ng generate --dry-run`)
|
|
327
|
-
- `--force` - Allow a dirty working tree (`ng generate --force`)
|
|
350
|
+
- `--force` - Allow a dirty working tree (upgrade phase and `ng generate --force`)
|
|
351
|
+
- `--to <version|tag>` - Target eUI version (`22.0.0`, `22.0.0-alpha.85`) or npm dist-tag (`next`); default: the version of this CLI
|
|
352
|
+
- `--skipInstall` - Update `package.json` only and stop; run the install yourself, then `eui-cli migrate --skipUpgrade`
|
|
353
|
+
- `--skipUpgrade` - Skip the upgrade phase and run the schematics on what is installed
|
|
328
354
|
|
|
329
355
|
```sh
|
|
330
356
|
# interactive, all groups + all schematics selected by default
|
|
@@ -341,6 +367,12 @@ eui-cli migrate --groups=eui --only=migrate-eui-table
|
|
|
341
367
|
|
|
342
368
|
# preview everything without writing files
|
|
343
369
|
eui-cli migrate --dryRun
|
|
370
|
+
|
|
371
|
+
# upgrade a v21 app to the `next` dist-tag (bump, install, schematics)
|
|
372
|
+
eui-cli migrate --to=next
|
|
373
|
+
|
|
374
|
+
# the same in two steps, installing yourself
|
|
375
|
+
eui-cli migrate --to=22.0.0 --skipInstall && yarn install && eui-cli migrate --skipUpgrade
|
|
344
376
|
```
|
|
345
377
|
|
|
346
378
|
> Only available for Angular-based eUI applications (an `angular.json` must be present in the
|
package/bin/eui-cli.js
CHANGED
|
@@ -118,8 +118,18 @@ program
|
|
|
118
118
|
.option('--only <list>', 'Comma/space separated specific schematic names to run within the selected groups')
|
|
119
119
|
.option('--path <path>', 'Restrict schematics to a sub-path (default: ./src for eUI schematics)')
|
|
120
120
|
.option('--dryRun', 'Run schematics in dry-run mode (no files written)')
|
|
121
|
-
.option('--force', '
|
|
121
|
+
.option('--force', 'Allow a dirty working tree (upgrade phase and ng generate --force)')
|
|
122
|
+
.option('--to <version>', 'Target eUI version or dist-tag (e.g. 22.0.0, next) for the upgrade phase (default: this cli version)')
|
|
123
|
+
.option('--skipInstall', 'Upgrade phase: update package.json but do not install (run the install yourself)')
|
|
124
|
+
.option('--skipUpgrade', 'Do not upgrade package.json / install; run the schematics on what is installed')
|
|
122
125
|
.addHelpText('after', `
|
|
126
|
+
Upgrade phase (runs first, automatically when the installed @eui/core is older than the target):
|
|
127
|
+
1. bump every @eui/* dependency in package.json to --to (^/~ kept, other deps untouched) and add @eui/deps-base-dev
|
|
128
|
+
2. install with the package manager detected from the lockfile (yarn.lock, package-lock.json, pnpm-lock.yaml)
|
|
129
|
+
3. verify the installed @eui/core major, then run the schematics (migrate-eui-config-files first)
|
|
130
|
+
Only the previous major (21.x for a 22 target) can be upgraded. With --dryRun the package.json diff is shown
|
|
131
|
+
and nothing is written or installed (the schematics cannot run before the install).
|
|
132
|
+
|
|
123
133
|
Groups:
|
|
124
134
|
angular Angular v22 migrations (https://v22.angular.dev/reference/migrations) via @angular/core
|
|
125
135
|
eui eUI breaking-change / modernisation schematics via @eui/core (migrate-all runs them all)
|
|
@@ -133,7 +143,10 @@ program
|
|
|
133
143
|
eui-cli migrate --groups=eui,angular run the eUI and Angular groups (all schematics)
|
|
134
144
|
eui-cli migrate --groups=angular --only=standalone-migration,control-flow-migration
|
|
135
145
|
eui-cli migrate --groups=eui --only=migrate-eui-table
|
|
136
|
-
eui-cli migrate --dryRun preview the migrations without writing files
|
|
146
|
+
eui-cli migrate --dryRun preview the migrations without writing files
|
|
147
|
+
eui-cli migrate --to=next upgrade a v21 app to the 'next' dist-tag, then migrate
|
|
148
|
+
eui-cli migrate --to=22.0.0 --skipInstall bump package.json only, install yourself, then --skipUpgrade
|
|
149
|
+
eui-cli migrate --skipUpgrade run the schematics only (app already on the target)`)
|
|
137
150
|
.action((options, command) => handleCommand('./scripts/migrate', options, command));
|
|
138
151
|
|
|
139
152
|
program
|
package/lib/app-utils/migrate.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
4
6
|
const childProcess = require('child_process');
|
|
5
|
-
const execFileSync = childProcess.execFileSync;
|
|
6
7
|
const { MultiSelect } = require('enquirer');
|
|
7
8
|
|
|
8
9
|
const utils = require('../utils');
|
|
10
|
+
const upgrade = require('./upgrade');
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Installs graceful cancellation handlers for the interactive enquirer prompts.
|
|
@@ -88,6 +90,22 @@ const getInstalledMajor = (pkg) => {
|
|
|
88
90
|
// The command's Angular migration group targets this Angular major only.
|
|
89
91
|
const SUPPORTED_ANGULAR_MAJOR = 22;
|
|
90
92
|
|
|
93
|
+
// Messages the Angular v22 migrations (@angular/core/schematics) throw when the project simply has
|
|
94
|
+
// nothing for them to do (e.g. a re-run, or no files under the path). Not real failures.
|
|
95
|
+
const NOTHING_TO_MIGRATE_PATTERNS = [
|
|
96
|
+
/Could not find any files to migrate/i,
|
|
97
|
+
/No files? (found )?to migrate/i,
|
|
98
|
+
/Nothing to migrate/i,
|
|
99
|
+
];
|
|
100
|
+
const isNothingToMigrate = (output) => NOTHING_TO_MIGRATE_PATTERNS.some((re) => re.test(String(output || '')));
|
|
101
|
+
|
|
102
|
+
const printSummary = (summary) => {
|
|
103
|
+
utils.logTitle('Migration summary');
|
|
104
|
+
utils.logInfo(`ran (${summary.ran.length}) : ${summary.ran.join(', ') || '-'}`);
|
|
105
|
+
utils.logInfo(`skipped, nothing to migrate (${summary.skippedNothing.length}) : ${summary.skippedNothing.join(', ') || '-'}`);
|
|
106
|
+
utils.logInfo(`not available in installed packages (${summary.notAvailable.length}) : ${summary.notAvailable.join(', ') || '-'}`);
|
|
107
|
+
};
|
|
108
|
+
|
|
91
109
|
/**
|
|
92
110
|
* Returns a copy of GROUPS filtered to the schematics actually present in each group's installed
|
|
93
111
|
* package collection. A group whose package can't be resolved is kept as-is (best effort — let
|
|
@@ -120,8 +138,11 @@ const resolveAvailableGroups = () => {
|
|
|
120
138
|
const allSchematic = group.allSchematic && available.has(group.allSchematic)
|
|
121
139
|
? group.allSchematic
|
|
122
140
|
: null;
|
|
141
|
+
const preSchematic = group.preSchematic && available.has(group.preSchematic)
|
|
142
|
+
? group.preSchematic
|
|
143
|
+
: null;
|
|
123
144
|
|
|
124
|
-
return { ...group, schematics, allSchematic };
|
|
145
|
+
return { ...group, schematics, allSchematic, preSchematic };
|
|
125
146
|
});
|
|
126
147
|
|
|
127
148
|
return { groups, skipped };
|
|
@@ -222,7 +243,12 @@ const GROUPS = [
|
|
|
222
243
|
package: '@eui/core',
|
|
223
244
|
// `migrate-all` runs every eUI migration schematic in sequence — the default for the group.
|
|
224
245
|
allSchematic: 'migrate-all',
|
|
246
|
+
// `migrate-all` does not include `migrate-eui-config-files` (package.json / tsconfig / angular.json
|
|
247
|
+
// / mock server of the generated app), so it is run explicitly BEFORE the aggregate: it has to
|
|
248
|
+
// see the config files before any source file is rewritten.
|
|
249
|
+
preSchematic: 'migrate-eui-config-files',
|
|
225
250
|
schematics: [
|
|
251
|
+
{ name: 'migrate-eui-config-files', description: 'Config files generated by eui-cli (package.json, tsconfig, angular.json, mock server)' },
|
|
226
252
|
{ name: 'migrate', description: 'Icons, modules and breaking-change replacements' },
|
|
227
253
|
{ name: 'icon-migrate', description: 'Rename deprecated eUI icon names' },
|
|
228
254
|
{ name: 'migrate-eui-tabs', description: 'eui-tabs label/content projection to header/body' },
|
|
@@ -358,6 +384,14 @@ const buildTasks = (selection) => {
|
|
|
358
384
|
|
|
359
385
|
// Whole group and an aggregate exists (e.g. eUI migrate-all) => run the aggregate.
|
|
360
386
|
if (picked === null && group.allSchematic) {
|
|
387
|
+
if (group.preSchematic) {
|
|
388
|
+
tasks.push({
|
|
389
|
+
group: group.key,
|
|
390
|
+
package: group.package,
|
|
391
|
+
schematic: group.preSchematic,
|
|
392
|
+
label: `${group.key}: ${group.preSchematic} (before ${group.allSchematic})`,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
361
395
|
tasks.push({
|
|
362
396
|
group: group.key,
|
|
363
397
|
package: group.package,
|
|
@@ -474,6 +508,22 @@ module.exports.run = async () => {
|
|
|
474
508
|
process.exit(1);
|
|
475
509
|
}
|
|
476
510
|
|
|
511
|
+
// Upgrade phase: the schematics ship in the TARGET @eui/core, so a v21 app must get its package.json
|
|
512
|
+
// bumped and its dependencies installed first. Runs before anything is resolved from node_modules.
|
|
513
|
+
const phase = upgrade.run({
|
|
514
|
+
to: args.to,
|
|
515
|
+
skipInstall: args.skipInstall,
|
|
516
|
+
skipUpgrade: args.skipUpgrade,
|
|
517
|
+
dryRun,
|
|
518
|
+
force,
|
|
519
|
+
});
|
|
520
|
+
if (!phase.proceed) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
// The upgrade itself dirtied the tree (package.json, lockfile); it was checked beforehand, so the
|
|
524
|
+
// schematics must not trip over it.
|
|
525
|
+
const schematicForce = force || phase.upgraded;
|
|
526
|
+
|
|
477
527
|
// The Angular migration group supports Angular v22 schematics only. Warn (don't hard-fail) when
|
|
478
528
|
// the installed @angular/core is a different major: the runtime filter below drops any schematic
|
|
479
529
|
// not present in the installed collection anyway, so eUI/ECL migrations can still proceed.
|
|
@@ -574,9 +624,10 @@ module.exports.run = async () => {
|
|
|
574
624
|
process.exit(1);
|
|
575
625
|
}
|
|
576
626
|
|
|
627
|
+
const summary = { ran: [], skippedNothing: [], notAvailable: skipped.map((s) => `${s.group}: ${s.name}`) };
|
|
577
628
|
const commonFlags = [];
|
|
578
629
|
if (dryRun) commonFlags.push('--dry-run');
|
|
579
|
-
if (
|
|
630
|
+
if (schematicForce) commonFlags.push('--force');
|
|
580
631
|
if (scopePath) commonFlags.push(`--path=${scopePath}`);
|
|
581
632
|
|
|
582
633
|
for (const task of tasks) {
|
|
@@ -586,20 +637,50 @@ module.exports.run = async () => {
|
|
|
586
637
|
// Build an argv array and run it WITHOUT a shell (execFileSync), so a project path containing
|
|
587
638
|
// spaces or other shell-special characters (e.g. ".../ease-portal-ui-new 3/...") is passed
|
|
588
639
|
// literally and never word-split. `ng` is a Node script, so it is invoked via `node <ng>`.
|
|
589
|
-
const
|
|
640
|
+
const extraFlags = [];
|
|
641
|
+
if (task.schematic === 'migrate-eui-config-files') {
|
|
642
|
+
// Pin the generated @eui/* entries to what is actually installed (its default, 22.0.0, may not exist yet).
|
|
643
|
+
const installed = upgrade.getInstalledEuiVersion(process.cwd());
|
|
644
|
+
// Angular CLI 22 only accepts kebab-case option names (camelCase => "Unknown argument").
|
|
645
|
+
if (installed) extraFlags.push(`--eui-version=${installed}`);
|
|
646
|
+
}
|
|
647
|
+
const ngArgs = [ng, 'generate', `${task.package}:${task.schematic}`, ...commonFlags, ...extraFlags];
|
|
590
648
|
|
|
591
|
-
utils.logInfo(`running : ng generate ${task.package}:${task.schematic} ${commonFlags.join(' ')}`.trim());
|
|
649
|
+
utils.logInfo(`running : ng generate ${task.package}:${task.schematic} ${[...commonFlags, ...extraFlags].join(' ')}`.trim());
|
|
592
650
|
|
|
651
|
+
// stdout stays inherited (live); stderr goes to a temp file so it can be inspected for the known
|
|
652
|
+
// "nothing to migrate" outcomes and still echoed to the user afterwards.
|
|
653
|
+
const errFile = path.join(os.tmpdir(), `eui-cli-migrate-${process.pid}-${summary.ran.length + summary.skippedNothing.length}.err`);
|
|
654
|
+
const errFd = fs.openSync(errFile, 'w');
|
|
655
|
+
const readStderr = () => {
|
|
656
|
+
try { return fs.readFileSync(errFile, 'utf8'); } catch (_) { return ''; }
|
|
657
|
+
};
|
|
593
658
|
try {
|
|
594
|
-
execFileSync(process.execPath, ngArgs, { cwd: process.cwd(), stdio: 'inherit' });
|
|
659
|
+
childProcess.execFileSync(process.execPath, ngArgs, { cwd: process.cwd(), stdio: ['inherit', 'inherit', errFd] });
|
|
660
|
+
const out = readStderr();
|
|
661
|
+
if (out) process.stderr.write(out);
|
|
662
|
+
summary.ran.push(`${task.package}:${task.schematic}`);
|
|
595
663
|
utils.logSuccess();
|
|
596
664
|
} catch (e) {
|
|
665
|
+
const out = readStderr();
|
|
666
|
+
if (out) process.stderr.write(out);
|
|
667
|
+
const output = [out, e && e.stderr, e && e.stdout, e && e.message].filter(Boolean).map(String).join('\n');
|
|
668
|
+
if (isNothingToMigrate(output)) {
|
|
669
|
+
utils.logWarning(`Nothing to migrate for ${task.package}:${task.schematic}, skipping.`);
|
|
670
|
+
summary.skippedNothing.push(`${task.package}:${task.schematic}`);
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
597
673
|
utils.logError(`Migration failed for ${task.package}:${task.schematic}.`);
|
|
598
674
|
utils.logErrorTrace('migrate.js', 'run', e);
|
|
675
|
+
printSummary(summary);
|
|
599
676
|
process.exit(1);
|
|
677
|
+
} finally {
|
|
678
|
+
fs.closeSync(errFd);
|
|
679
|
+
fs.rmSync(errFile, { force: true });
|
|
600
680
|
}
|
|
601
681
|
}
|
|
602
682
|
|
|
683
|
+
printSummary(summary);
|
|
603
684
|
utils.logSuccess('All selected migrations completed.');
|
|
604
685
|
};
|
|
605
686
|
|
|
@@ -608,3 +689,4 @@ module.exports.GROUPS = GROUPS;
|
|
|
608
689
|
module.exports.parseGroupsArg = parseGroupsArg;
|
|
609
690
|
module.exports.parseOnlyArg = parseOnlyArg;
|
|
610
691
|
module.exports.buildTasks = buildTasks;
|
|
692
|
+
module.exports.setActiveGroups = setActiveGroups;
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const childProcess = require('child_process');
|
|
6
|
+
|
|
7
|
+
const utils = require('../utils');
|
|
8
|
+
const config = require('../config');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* eUI upgrade phase of `eui-cli migrate`.
|
|
12
|
+
*
|
|
13
|
+
* The migration schematics ship inside `@eui/core` of the TARGET major, and the base `migrate`
|
|
14
|
+
* schematic refuses to run unless the installed `@eui/core` is that major. So a v21 application has
|
|
15
|
+
* to be upgraded first. Required order:
|
|
16
|
+
* 1. bump the `@eui/*` ranges in package.json (+ add what the v22 skeleton requires),
|
|
17
|
+
* 2. install with the application's package manager,
|
|
18
|
+
* 3. verify the installed `@eui/core` major, then let `migrate` run the schematics.
|
|
19
|
+
*
|
|
20
|
+
* Pure helpers (detection / bump / parsing) are exported separately from the side-effecting
|
|
21
|
+
* `run()` so they can be unit-tested; every child process goes through `childProcess.execFileSync`
|
|
22
|
+
* looked up at call time so tests can mock it.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// Majors an upgrade can start from: exactly one major below the target.
|
|
26
|
+
const SUPPORTED_FROM_OFFSET = 1;
|
|
27
|
+
|
|
28
|
+
// @eui packages that are NOT versioned in lock-step with @eui/core, never bumped to the target.
|
|
29
|
+
const NON_LOCKSTEP = new Set(['@eui/eds-wc']);
|
|
30
|
+
|
|
31
|
+
// Added to devDependencies when the app uses @eui/deps-base: the v22 skeleton moved the build /
|
|
32
|
+
// lint / test tooling (angular cli, eslint, vitest, ...) out of deps-base into deps-base-dev.
|
|
33
|
+
const DEPS_BASE = '@eui/deps-base';
|
|
34
|
+
const DEPS_BASE_DEV = '@eui/deps-base-dev';
|
|
35
|
+
|
|
36
|
+
// Generated v21 `resolutions` pins that break v22 (Angular 22 build needs magic-string 1.x, the v21
|
|
37
|
+
// skeleton pinned 0.30.17 and the v22 skeleton dropped it). Removed only when the value is still the
|
|
38
|
+
// generated one, so a deliberate user pin is kept.
|
|
39
|
+
const STALE_RESOLUTIONS = { 'magic-string': '0.30.17' };
|
|
40
|
+
|
|
41
|
+
const SECTIONS = ['dependencies', 'devDependencies'];
|
|
42
|
+
|
|
43
|
+
const parseMajor = (version) => {
|
|
44
|
+
const m = /^\s*[\^~>=<v\s]*(\d+)\./.exec(String(version || ''));
|
|
45
|
+
return m ? parseInt(m[1], 10) : null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const readJson = (file) => JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Installed eUI version from the app's node_modules (`@eui/core`, then `@eui/deps-base`).
|
|
52
|
+
* @returns {string|null}
|
|
53
|
+
*/
|
|
54
|
+
const getInstalledEuiVersion = (cwd) => {
|
|
55
|
+
for (const pkg of ['@eui/core', DEPS_BASE]) {
|
|
56
|
+
const file = path.join(cwd, 'node_modules', ...pkg.split('/'), 'package.json');
|
|
57
|
+
try {
|
|
58
|
+
return readJson(file).version || null;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
utils.logDebugTrace('upgrade.js', 'getInstalledEuiVersion', e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Version the app's package.json declares for `@eui/deps-base` / `@eui/core` (range as written).
|
|
68
|
+
* @returns {string|null}
|
|
69
|
+
*/
|
|
70
|
+
const getDeclaredEuiVersion = (pkgJson) => {
|
|
71
|
+
for (const name of [DEPS_BASE, '@eui/core']) {
|
|
72
|
+
for (const section of SECTIONS) {
|
|
73
|
+
const v = pkgJson[section] && pkgJson[section][name];
|
|
74
|
+
if (typeof v === 'string') {
|
|
75
|
+
return v;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** Package manager from the lockfile; yarn (the cli's own default, see lib/install.js) if none. */
|
|
83
|
+
const detectPackageManager = (cwd) => {
|
|
84
|
+
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
85
|
+
if (fs.existsSync(path.join(cwd, 'package-lock.json'))) return 'npm';
|
|
86
|
+
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn';
|
|
87
|
+
return 'yarn';
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Resolves `--to`. Default is this cli's own version. A value starting with a digit is a version;
|
|
92
|
+
* anything else is an npm dist-tag (e.g. `next`) resolved through `npm view @eui/deps-base`.
|
|
93
|
+
*/
|
|
94
|
+
const resolveTarget = (to) => {
|
|
95
|
+
if (to === undefined || to === true || to === '') {
|
|
96
|
+
return String(config.version);
|
|
97
|
+
}
|
|
98
|
+
const value = String(to).replace(/^v/, '');
|
|
99
|
+
if (/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(value)) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
if (/^\d/.test(value)) {
|
|
103
|
+
throw new Error(`Invalid --to "${to}": expected a full version such as 22.0.0 or 22.0.0-alpha.85, or a dist-tag such as next.`);
|
|
104
|
+
}
|
|
105
|
+
const out = childProcess.execFileSync('npm', ['view', `${DEPS_BASE}@${value}`, 'version'], { encoding: 'utf8' });
|
|
106
|
+
const version = String(out).trim().split('\n').pop().trim();
|
|
107
|
+
if (!/^\d+\.\d+\.\d+/.test(version)) {
|
|
108
|
+
throw new Error(`Could not resolve dist-tag "${value}" of ${DEPS_BASE} (npm returned "${version}").`);
|
|
109
|
+
}
|
|
110
|
+
return version;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const detectIndent = (text) => {
|
|
114
|
+
const m = /^([ \t]+)"/m.exec(text);
|
|
115
|
+
return m ? m[1] : 2;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Bumps every `@eui/*` dependency to `target` (keeping a ^ / ~ prefix) and adds
|
|
120
|
+
* `@eui/deps-base-dev` when the app uses `@eui/deps-base`. Everything else is left untouched;
|
|
121
|
+
* running it again on its own output is a no-op.
|
|
122
|
+
*
|
|
123
|
+
* @returns {{text: string, changes: {name:string, section:string, from:string|null, to:string}[], skipped: {name:string, version:string}[]}}
|
|
124
|
+
*/
|
|
125
|
+
const bumpPackageJson = (text, target) => {
|
|
126
|
+
const json = JSON.parse(text);
|
|
127
|
+
const changes = [];
|
|
128
|
+
const skipped = [];
|
|
129
|
+
|
|
130
|
+
for (const section of SECTIONS) {
|
|
131
|
+
const deps = json[section];
|
|
132
|
+
if (!deps) continue;
|
|
133
|
+
for (const name of Object.keys(deps)) {
|
|
134
|
+
if (!name.startsWith('@eui/') || NON_LOCKSTEP.has(name)) continue;
|
|
135
|
+
const m = /^([\^~]?)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(String(deps[name]));
|
|
136
|
+
if (!m) {
|
|
137
|
+
skipped.push({ name, version: String(deps[name]) });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (m[2] !== target) {
|
|
141
|
+
changes.push({ name, section, from: deps[name], to: m[1] + target });
|
|
142
|
+
deps[name] = m[1] + target;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const hasBase = json.dependencies && json.dependencies[DEPS_BASE] !== undefined;
|
|
148
|
+
const hasDev = SECTIONS.some((s) => json[s] && json[s][DEPS_BASE_DEV] !== undefined);
|
|
149
|
+
if (hasBase && !hasDev) {
|
|
150
|
+
// Same pin style as deps-base, put first like the skeleton does.
|
|
151
|
+
const prefix = /^[\^~]/.exec(String(json.dependencies[DEPS_BASE]));
|
|
152
|
+
const to = (prefix ? prefix[0] : '') + target;
|
|
153
|
+
json.devDependencies = { [DEPS_BASE_DEV]: to, ...(json.devDependencies || {}) };
|
|
154
|
+
changes.push({ name: DEPS_BASE_DEV, section: 'devDependencies', from: null, to });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (const [name, value] of Object.entries(STALE_RESOLUTIONS)) {
|
|
158
|
+
if (json.resolutions && json.resolutions[name] === value) {
|
|
159
|
+
delete json.resolutions[name];
|
|
160
|
+
changes.push({ name, section: 'resolutions', from: value, to: '(removed)' });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (changes.length === 0) {
|
|
165
|
+
return { text, changes, skipped };
|
|
166
|
+
}
|
|
167
|
+
const eol = text.endsWith('\n') ? '\n' : '';
|
|
168
|
+
return { text: JSON.stringify(json, null, detectIndent(text)) + eol, changes, skipped };
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Decides what the upgrade phase has to do.
|
|
173
|
+
*
|
|
174
|
+
* @returns {{action:'none'|'upgrade'|'unsupported'|'unknown', reason:string, target:string,
|
|
175
|
+
* installed:string|null, declared:string|null, needsInstall:boolean}}
|
|
176
|
+
*/
|
|
177
|
+
const planUpgrade = (cwd, target) => {
|
|
178
|
+
const pkgJson = readJson(path.join(cwd, 'package.json'));
|
|
179
|
+
const installed = getInstalledEuiVersion(cwd);
|
|
180
|
+
const declared = getDeclaredEuiVersion(pkgJson);
|
|
181
|
+
const targetMajor = parseMajor(target);
|
|
182
|
+
const current = installed || declared;
|
|
183
|
+
const major = parseMajor(current);
|
|
184
|
+
const base = { target, installed, declared };
|
|
185
|
+
|
|
186
|
+
if (major === null) {
|
|
187
|
+
return { ...base, action: 'unknown', needsInstall: false, reason: 'No @eui/deps-base or @eui/core found in package.json or node_modules; is this an eUI application?' };
|
|
188
|
+
}
|
|
189
|
+
if (major > targetMajor) {
|
|
190
|
+
return { ...base, action: 'unsupported', needsInstall: false, reason: `The application is on eUI ${current}, newer than the target ${target}; downgrades are not supported.` };
|
|
191
|
+
}
|
|
192
|
+
if (major < targetMajor - SUPPORTED_FROM_OFFSET) {
|
|
193
|
+
return { ...base, action: 'unsupported', needsInstall: false, reason: `Upgrading from eUI ${major}.x to ${targetMajor}.x is not supported; upgrade one major at a time (supported start: ${targetMajor - SUPPORTED_FROM_OFFSET}.x).` };
|
|
194
|
+
}
|
|
195
|
+
const needsInstall = installed === null || parseMajor(installed) < targetMajor;
|
|
196
|
+
const bump = bumpPackageJson(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'), target);
|
|
197
|
+
if (!needsInstall && bump.changes.length === 0) {
|
|
198
|
+
return { ...base, action: 'none', needsInstall, reason: `Already on eUI ${current}.` };
|
|
199
|
+
}
|
|
200
|
+
return { ...base, action: 'upgrade', needsInstall, reason: `eUI ${current} -> ${target}` };
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/** True when `git status` reports changes. Not a git repository / git missing => false. */
|
|
204
|
+
const isWorkingTreeDirty = (cwd) => {
|
|
205
|
+
try {
|
|
206
|
+
const out = childProcess.execFileSync('git', ['status', '--porcelain'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
207
|
+
return String(out).trim().length > 0;
|
|
208
|
+
} catch (e) {
|
|
209
|
+
utils.logDebugTrace('upgrade.js', 'isWorkingTreeDirty', e);
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const installPackages = (pm, cwd) => {
|
|
215
|
+
utils.logInfo(`running : ${pm} install`);
|
|
216
|
+
// On Windows yarn/npm/pnpm are .cmd shims, which execFile cannot start without a shell.
|
|
217
|
+
childProcess.execFileSync(pm, ['install'], { cwd, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const formatChanges = (changes) => changes.map((c) => ` ${{ devDependencies: 'dev ', resolutions: 'res ' }[c.section] || ' '}${c.name}: ${c.from === null ? '(new)' : c.from} -> ${c.to}`);
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Runs the upgrade phase.
|
|
224
|
+
*
|
|
225
|
+
* @param {{to?:string, skipInstall?:boolean, skipUpgrade?:boolean, dryRun?:boolean, force?:boolean}} opts
|
|
226
|
+
* @param {string} [cwd]
|
|
227
|
+
* @returns {{proceed:boolean, upgraded:boolean}} `proceed: false` when the schematic phase must
|
|
228
|
+
* not run (dry run on a not-yet-upgraded app). `upgraded` means package.json was rewritten, so
|
|
229
|
+
* the tree is dirty on purpose and the schematics need `--force`.
|
|
230
|
+
*/
|
|
231
|
+
const run = (opts = {}, cwd = process.cwd()) => {
|
|
232
|
+
const { skipUpgrade, skipInstall, dryRun, force } = opts;
|
|
233
|
+
if (skipUpgrade) {
|
|
234
|
+
utils.logInfo('Upgrade phase skipped (--skipUpgrade).');
|
|
235
|
+
return { proceed: true, upgraded: false };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
utils.logTitle('Upgrade phase');
|
|
239
|
+
let target;
|
|
240
|
+
try {
|
|
241
|
+
target = resolveTarget(opts.to);
|
|
242
|
+
} catch (e) {
|
|
243
|
+
utils.logError(e.message);
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const plan = planUpgrade(cwd, target);
|
|
248
|
+
if (plan.action === 'unsupported' || plan.action === 'unknown') {
|
|
249
|
+
utils.logError(plan.reason);
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
252
|
+
if (plan.action === 'none') {
|
|
253
|
+
utils.logInfo(`${plan.reason} Nothing to upgrade.`);
|
|
254
|
+
return { proceed: true, upgraded: false };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
utils.logInfo(`${plan.reason} (installed: ${plan.installed || 'none'}, package.json: ${plan.declared || 'none'})`);
|
|
258
|
+
const pkgFile = path.join(cwd, 'package.json');
|
|
259
|
+
const bump = bumpPackageJson(fs.readFileSync(pkgFile, 'utf8'), target);
|
|
260
|
+
if (bump.changes.length > 0) {
|
|
261
|
+
utils.logInfo('package.json changes:');
|
|
262
|
+
formatChanges(bump.changes).forEach((l) => console.log(l));
|
|
263
|
+
}
|
|
264
|
+
bump.skipped.forEach((s) => utils.logWarning(`Left ${s.name}@${s.version} untouched (not a plain version); check it manually.`));
|
|
265
|
+
|
|
266
|
+
const pm = detectPackageManager(cwd);
|
|
267
|
+
|
|
268
|
+
if (dryRun) {
|
|
269
|
+
utils.logWarning('Dry run: package.json was not modified and nothing was installed.');
|
|
270
|
+
if (plan.needsInstall) {
|
|
271
|
+
utils.logWarning(`The schematics ship in @eui/core ${parseMajor(target)}.x and cannot run (not even as a dry run) before it is installed.`);
|
|
272
|
+
utils.logWarning(`Re-run without --dryRun to upgrade, or upgrade manually (${pm} install) and run "eui-cli migrate --dryRun --skipUpgrade".`);
|
|
273
|
+
return { proceed: false, upgraded: false };
|
|
274
|
+
}
|
|
275
|
+
return { proceed: true, upgraded: false };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Same contract as `ng generate`: refuse to touch a dirty tree unless --force.
|
|
279
|
+
if (!force && isWorkingTreeDirty(cwd)) {
|
|
280
|
+
utils.logError('The working tree has uncommitted changes. Commit or stash them, or re-run with --force.');
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (bump.changes.length > 0) {
|
|
285
|
+
fs.writeFileSync(pkgFile, bump.text);
|
|
286
|
+
utils.logSuccess('package.json updated.');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (plan.needsInstall) {
|
|
290
|
+
if (skipInstall) {
|
|
291
|
+
// The schematics would be skipped by the base `migrate` schematic, so stop here.
|
|
292
|
+
utils.logWarning(`Install skipped (--skipInstall). Run "${pm} install", then "eui-cli migrate --skipUpgrade".`);
|
|
293
|
+
return { proceed: false, upgraded: true };
|
|
294
|
+
} else {
|
|
295
|
+
try {
|
|
296
|
+
installPackages(pm, cwd);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
utils.logError(`${pm} install failed; package.json was already updated.`);
|
|
299
|
+
utils.logErrorTrace('upgrade.js', 'run', e);
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const installed = getInstalledEuiVersion(cwd);
|
|
304
|
+
if (parseMajor(installed) !== parseMajor(target)) {
|
|
305
|
+
utils.logError(`Installed @eui/core is ${installed || 'missing'}, expected ${parseMajor(target)}.x; the schematics would be skipped.`);
|
|
306
|
+
utils.logError(`Run "${pm} install" and re-run "eui-cli migrate --skipUpgrade".`);
|
|
307
|
+
process.exit(1);
|
|
308
|
+
}
|
|
309
|
+
utils.logSuccess(`Installed @eui/core ${installed}.`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return { proceed: true, upgraded: bump.changes.length > 0 };
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
module.exports.run = run;
|
|
316
|
+
module.exports.parseMajor = parseMajor;
|
|
317
|
+
module.exports.getInstalledEuiVersion = getInstalledEuiVersion;
|
|
318
|
+
module.exports.getDeclaredEuiVersion = getDeclaredEuiVersion;
|
|
319
|
+
module.exports.detectPackageManager = detectPackageManager;
|
|
320
|
+
module.exports.resolveTarget = resolveTarget;
|
|
321
|
+
module.exports.bumpPackageJson = bumpPackageJson;
|
|
322
|
+
module.exports.planUpgrade = planUpgrade;
|
|
323
|
+
module.exports.isWorkingTreeDirty = isWorkingTreeDirty;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eui-angular-app",
|
|
3
|
-
"version": "22.0.0-rc.
|
|
3
|
+
"version": "22.0.0-rc.6",
|
|
4
4
|
"license": "EUPL-1.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"ng": "ng",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"private": true,
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@eui/deps-base": "22.0.0-rc.
|
|
23
|
+
"@eui/deps-base": "22.0.0-rc.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@eui/deps-base-dev": "22.0.0-rc.
|
|
26
|
+
"@eui/deps-base-dev": "22.0.0-rc.6",
|
|
27
27
|
"npm-run-all": "4.1.5",
|
|
28
28
|
"json-server": "1.0.0-beta.15",
|
|
29
29
|
"nodemon": "3.1.14",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eui-angular-app",
|
|
3
|
-
"version": "22.0.0-rc.
|
|
3
|
+
"version": "22.0.0-rc.6",
|
|
4
4
|
"license": "EUPL-1.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"ng": "ng",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@eui/mobile-core": "22.0.0-alpha.1",
|
|
24
24
|
"@eui/mobile-styles": "22.0.0-alpha.1",
|
|
25
|
-
"@eui/deps-base": "22.0.0-rc.
|
|
25
|
+
"@eui/deps-base": "22.0.0-rc.6"
|
|
26
26
|
},
|
|
27
27
|
"resolutions": {}
|
|
28
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eui-angular-app",
|
|
3
|
-
"version": "22.0.0-rc.
|
|
3
|
+
"version": "22.0.0-rc.6",
|
|
4
4
|
"license": "EUPL-1.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"ng": "ng",
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
"ngx-markdown": "21.1.0",
|
|
59
59
|
"prismjs": "1.30.0",
|
|
60
60
|
"@stackblitz/sdk": "1.11.1",
|
|
61
|
-
"@eui/base": "22.0.0-rc.
|
|
62
|
-
"@eui/core": "22.0.0-rc.
|
|
63
|
-
"@eui/styles": "22.0.0-rc.
|
|
64
|
-
"@eui/components": "22.0.0-rc.
|
|
65
|
-
"@eui/showcase": "22.0.0-rc.
|
|
66
|
-
"@eui/ecl": "22.0.0-rc.
|
|
67
|
-
"@eui/eds": "22.0.0-rc.
|
|
68
|
-
"@eui/eds-styles": "22.0.0-rc.
|
|
61
|
+
"@eui/base": "22.0.0-rc.6",
|
|
62
|
+
"@eui/core": "22.0.0-rc.6",
|
|
63
|
+
"@eui/styles": "22.0.0-rc.6",
|
|
64
|
+
"@eui/components": "22.0.0-rc.6",
|
|
65
|
+
"@eui/showcase": "22.0.0-rc.6",
|
|
66
|
+
"@eui/ecl": "22.0.0-rc.6",
|
|
67
|
+
"@eui/eds": "22.0.0-rc.6",
|
|
68
|
+
"@eui/eds-styles": "22.0.0-rc.6",
|
|
69
69
|
"@eui/eds-wc": "22.0.0-alpha.88",
|
|
70
|
-
"@eui/eds-shared": "22.0.0-rc.
|
|
70
|
+
"@eui/eds-shared": "22.0.0-rc.6"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@eui/cli": "22.0.0-rc.
|
|
73
|
+
"@eui/cli": "22.0.0-rc.6",
|
|
74
74
|
"@angular/compiler-cli": "22.3.0",
|
|
75
75
|
"@angular/language-service": "22.3.0",
|
|
76
76
|
"@angular/build": "22.3.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eui-react-app",
|
|
3
|
-
"version": "22.0.0-rc.
|
|
3
|
+
"version": "22.0.0-rc.6",
|
|
4
4
|
"license": "EUPL-1.1",
|
|
5
5
|
"private": true,
|
|
6
6
|
"type": "module",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"test": "vitest run"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@eui/deps-base-react": "22.0.0-rc.
|
|
18
|
+
"@eui/deps-base-react": "22.0.0-rc.6"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@eui/cli": "22.0.0-rc.
|
|
21
|
+
"@eui/cli": "22.0.0-rc.6",
|
|
22
22
|
"npm-run-all": "4.1.5",
|
|
23
23
|
"json-server": "1.0.0-beta.3",
|
|
24
24
|
"nodemon": "3.1.11",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eui-react-app",
|
|
3
|
-
"version": "22.0.0-rc.
|
|
3
|
+
"version": "22.0.0-rc.6",
|
|
4
4
|
"license": "EUPL-1.1",
|
|
5
5
|
"private": true,
|
|
6
6
|
"type": "module",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"react-dom": "19.3.0",
|
|
20
20
|
"react-router-dom": "7.18.4",
|
|
21
21
|
"luxon": "3.7.2",
|
|
22
|
-
"@eui/eds-styles": "22.0.0-rc.
|
|
23
|
-
"@eui/eds-react": "22.0.0-rc.
|
|
24
|
-
"@eui/eds-shared": "22.0.0-rc.
|
|
22
|
+
"@eui/eds-styles": "22.0.0-rc.6",
|
|
23
|
+
"@eui/eds-react": "22.0.0-rc.6",
|
|
24
|
+
"@eui/eds-shared": "22.0.0-rc.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@eui/cli": "22.0.0-rc.
|
|
27
|
+
"@eui/cli": "22.0.0-rc.6",
|
|
28
28
|
"typescript": "6.0.3",
|
|
29
29
|
"@types/react": "19.3.0",
|
|
30
30
|
"@types/react-dom": "19.3.0",
|
package/package.json
CHANGED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { test, describe, beforeEach, afterEach, mock } = require('node:test');
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const childProcess = require('child_process');
|
|
9
|
+
|
|
10
|
+
const upgrade = require('../lib/app-utils/upgrade');
|
|
11
|
+
const migrate = require('../lib/app-utils/migrate');
|
|
12
|
+
const config = require('../lib/config');
|
|
13
|
+
|
|
14
|
+
const V21_PKG = {
|
|
15
|
+
name: 'app',
|
|
16
|
+
version: '1.0.0',
|
|
17
|
+
scripts: { start: 'ng serve' },
|
|
18
|
+
dependencies: { '@eui/deps-base': '^21.5.0', lodash: '^4.0.0' },
|
|
19
|
+
devDependencies: { nodemon: '3.1.11' },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let dir;
|
|
23
|
+
const write = (rel, content) => {
|
|
24
|
+
const file = path.join(dir, rel);
|
|
25
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
26
|
+
fs.writeFileSync(file, typeof content === 'string' ? content : JSON.stringify(content, null, 2) + '\n');
|
|
27
|
+
};
|
|
28
|
+
const installEui = (version) => write('node_modules/@eui/core/package.json', { name: '@eui/core', version });
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'eui-cli-upgrade-'));
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
mock.restoreAll();
|
|
35
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('version detection', () => {
|
|
39
|
+
test('reads installed @eui/core, falls back to @eui/deps-base', () => {
|
|
40
|
+
assert.equal(upgrade.getInstalledEuiVersion(dir), null);
|
|
41
|
+
write('node_modules/@eui/deps-base/package.json', { version: '21.1.0' });
|
|
42
|
+
assert.equal(upgrade.getInstalledEuiVersion(dir), '21.1.0');
|
|
43
|
+
installEui('21.5.0');
|
|
44
|
+
assert.equal(upgrade.getInstalledEuiVersion(dir), '21.5.0');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('reads the declared version and the major', () => {
|
|
48
|
+
assert.equal(upgrade.getDeclaredEuiVersion(V21_PKG), '^21.5.0');
|
|
49
|
+
assert.equal(upgrade.getDeclaredEuiVersion({ dependencies: {} }), null);
|
|
50
|
+
assert.equal(upgrade.parseMajor('^21.5.0'), 21);
|
|
51
|
+
assert.equal(upgrade.parseMajor('22.0.0-alpha.85'), 22);
|
|
52
|
+
assert.equal(upgrade.parseMajor('next'), null);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('planUpgrade: upgrade, none, unsupported, unknown', () => {
|
|
56
|
+
write('package.json', V21_PKG);
|
|
57
|
+
installEui('21.5.0');
|
|
58
|
+
assert.equal(upgrade.planUpgrade(dir, '22.0.0').action, 'upgrade');
|
|
59
|
+
assert.equal(upgrade.planUpgrade(dir, '22.0.0').needsInstall, true);
|
|
60
|
+
assert.equal(upgrade.planUpgrade(dir, '23.0.0').action, 'unsupported'); // 21 -> 23
|
|
61
|
+
assert.equal(upgrade.planUpgrade(dir, '20.0.0').action, 'unsupported'); // downgrade
|
|
62
|
+
|
|
63
|
+
write('package.json', { ...V21_PKG, dependencies: { '@eui/deps-base': '^22.0.0', '@eui/core': '^22.0.0' }, devDependencies: { '@eui/deps-base-dev': '^22.0.0' } });
|
|
64
|
+
installEui('22.0.0');
|
|
65
|
+
assert.equal(upgrade.planUpgrade(dir, '22.0.0').action, 'none');
|
|
66
|
+
|
|
67
|
+
write('package.json', { name: 'x', dependencies: {} });
|
|
68
|
+
fs.rmSync(path.join(dir, 'node_modules'), { recursive: true });
|
|
69
|
+
assert.equal(upgrade.planUpgrade(dir, '22.0.0').action, 'unknown');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('planUpgrade: package.json already bumped but not installed still needs an install', () => {
|
|
73
|
+
write('package.json', { dependencies: { '@eui/deps-base': '22.0.0' }, devDependencies: { '@eui/deps-base-dev': '22.0.0' } });
|
|
74
|
+
installEui('21.5.0');
|
|
75
|
+
const plan = upgrade.planUpgrade(dir, '22.0.0');
|
|
76
|
+
assert.equal(plan.action, 'upgrade');
|
|
77
|
+
assert.equal(plan.needsInstall, true);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('package.json bump', () => {
|
|
82
|
+
test('bumps @eui/* keeping the prefix, leaves user deps untouched, adds deps-base-dev', () => {
|
|
83
|
+
const text = JSON.stringify({
|
|
84
|
+
...V21_PKG,
|
|
85
|
+
dependencies: { '@eui/deps-base': '^21.5.0', '@eui/cli': '~21.5.0', '@eui/eds-wc': '0.3.0', lodash: '^4.0.0' },
|
|
86
|
+
}, null, 4) + '\n';
|
|
87
|
+
const { text: out, changes } = upgrade.bumpPackageJson(text, '22.0.0-alpha.85');
|
|
88
|
+
const json = JSON.parse(out);
|
|
89
|
+
assert.equal(json.dependencies['@eui/deps-base'], '^22.0.0-alpha.85');
|
|
90
|
+
assert.equal(json.dependencies['@eui/cli'], '~22.0.0-alpha.85');
|
|
91
|
+
assert.equal(json.dependencies['@eui/eds-wc'], '0.3.0'); // not lock-step
|
|
92
|
+
assert.equal(json.dependencies.lodash, '^4.0.0');
|
|
93
|
+
assert.deepEqual(json.devDependencies, { '@eui/deps-base-dev': '^22.0.0-alpha.85', nodemon: '3.1.11' });
|
|
94
|
+
assert.equal(Object.keys(json.devDependencies)[0], '@eui/deps-base-dev');
|
|
95
|
+
assert.equal(json.scripts.start, 'ng serve');
|
|
96
|
+
assert.ok(out.startsWith('{\n "name"'), 'indent preserved');
|
|
97
|
+
assert.ok(out.endsWith('}\n'));
|
|
98
|
+
assert.equal(changes.length, 3);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('drops the stale generated magic-string resolution only, keeps user pins', () => {
|
|
102
|
+
const pkg = (r) => JSON.stringify({ dependencies: { '@eui/deps-base': '21.5.0' }, resolutions: r });
|
|
103
|
+
const a = JSON.parse(upgrade.bumpPackageJson(pkg({ 'magic-string': '0.30.17', semver: '>=7' }), '22.0.0').text);
|
|
104
|
+
assert.deepEqual(a.resolutions, { semver: '>=7' });
|
|
105
|
+
const b = JSON.parse(upgrade.bumpPackageJson(pkg({ 'magic-string': '0.31.0' }), '22.0.0').text);
|
|
106
|
+
assert.deepEqual(b.resolutions, { 'magic-string': '0.31.0' });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('is idempotent and returns the identical text when nothing changes', () => {
|
|
110
|
+
const text = JSON.stringify(V21_PKG, null, 2) + '\n';
|
|
111
|
+
const first = upgrade.bumpPackageJson(text, '22.0.0');
|
|
112
|
+
const second = upgrade.bumpPackageJson(first.text, '22.0.0');
|
|
113
|
+
assert.equal(second.changes.length, 0);
|
|
114
|
+
assert.equal(second.text, first.text);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('does not add deps-base-dev when already present or when deps-base is not used; reports non-plain versions', () => {
|
|
118
|
+
const a = upgrade.bumpPackageJson(JSON.stringify({ dependencies: { '@eui/core': '21.5.0' } }), '22.0.0');
|
|
119
|
+
assert.deepEqual(JSON.parse(a.text), { dependencies: { '@eui/core': '22.0.0' } });
|
|
120
|
+
const b = upgrade.bumpPackageJson(JSON.stringify({ dependencies: { '@eui/deps-base': 'next', '@eui/base': 'file:../base' } }), '22.0.0');
|
|
121
|
+
assert.deepEqual(b.skipped.map((s) => s.name), ['@eui/deps-base', '@eui/base']);
|
|
122
|
+
assert.equal(b.changes.length, 1); // only the added deps-base-dev
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('package manager detection', () => {
|
|
127
|
+
test('from the lockfile, yarn by default', () => {
|
|
128
|
+
assert.equal(upgrade.detectPackageManager(dir), 'yarn');
|
|
129
|
+
write('package-lock.json', '{}');
|
|
130
|
+
assert.equal(upgrade.detectPackageManager(dir), 'npm');
|
|
131
|
+
write('pnpm-lock.yaml', '');
|
|
132
|
+
assert.equal(upgrade.detectPackageManager(dir), 'pnpm');
|
|
133
|
+
fs.rmSync(path.join(dir, 'pnpm-lock.yaml'));
|
|
134
|
+
fs.rmSync(path.join(dir, 'package-lock.json'));
|
|
135
|
+
write('yarn.lock', '');
|
|
136
|
+
assert.equal(upgrade.detectPackageManager(dir), 'yarn');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('--to resolution', () => {
|
|
141
|
+
test('default is the cli version, versions pass through, dist-tags go through npm view', () => {
|
|
142
|
+
assert.equal(upgrade.resolveTarget(undefined), config.version);
|
|
143
|
+
assert.equal(upgrade.resolveTarget('22.0.0-alpha.85'), '22.0.0-alpha.85');
|
|
144
|
+
assert.equal(upgrade.resolveTarget('v22.1.0'), '22.1.0');
|
|
145
|
+
assert.throws(() => upgrade.resolveTarget('22'), /Invalid --to/);
|
|
146
|
+
const m = mock.method(childProcess, 'execFileSync', () => '22.0.0-alpha.85\n');
|
|
147
|
+
assert.equal(upgrade.resolveTarget('next'), '22.0.0-alpha.85');
|
|
148
|
+
assert.deepEqual(m.mock.calls[0].arguments.slice(0, 2), ['npm', ['view', '@eui/deps-base@next', 'version']]);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('flag parsing (utils.getArgs as fed by bin/eui-cli.js)', () => {
|
|
153
|
+
test('--to=, --skipInstall, --skipUpgrade', () => {
|
|
154
|
+
const argv = process.argv;
|
|
155
|
+
process.argv = ['node', 'eui-cli', '--to=next', '--skipInstall', '--skipUpgrade', '--dryRun'];
|
|
156
|
+
try {
|
|
157
|
+
const args = require('../lib/utils').getArgs();
|
|
158
|
+
assert.equal(args.to, 'next');
|
|
159
|
+
assert.equal(args.skipInstall, true);
|
|
160
|
+
assert.equal(args.skipUpgrade, true);
|
|
161
|
+
assert.equal(args.dryRun, true);
|
|
162
|
+
} finally {
|
|
163
|
+
process.argv = argv;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('phase ordering', () => {
|
|
169
|
+
let calls;
|
|
170
|
+
let cwd;
|
|
171
|
+
let argv;
|
|
172
|
+
const fakeExec = (pm) => (cmd, args) => {
|
|
173
|
+
calls.push([cmd === process.execPath ? 'node' : cmd, ...args].join(' '));
|
|
174
|
+
if (cmd === pm) installEui('22.0.0-alpha.85'); // the install brings v22
|
|
175
|
+
return '';
|
|
176
|
+
};
|
|
177
|
+
const setup = (extra = {}) => {
|
|
178
|
+
write('angular.json', '{}');
|
|
179
|
+
write('package.json', V21_PKG);
|
|
180
|
+
write('yarn.lock', '');
|
|
181
|
+
write('node_modules/.bin/ng', '');
|
|
182
|
+
installEui('21.5.0');
|
|
183
|
+
process.chdir(dir);
|
|
184
|
+
process.argv = ['node', 'eui-cli', '--groups=eui', '--to=22.0.0-alpha.85', ...Object.entries(extra).map(([k, v]) => (v === true ? `--${k}` : `--${k}=${v}`))];
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
beforeEach(() => {
|
|
188
|
+
calls = [];
|
|
189
|
+
cwd = process.cwd();
|
|
190
|
+
argv = process.argv;
|
|
191
|
+
mock.method(console, 'log', () => {});
|
|
192
|
+
});
|
|
193
|
+
afterEach(() => {
|
|
194
|
+
process.chdir(cwd);
|
|
195
|
+
process.argv = argv;
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('bump -> install -> config files schematic -> migrate-all, schematics get --force', async () => {
|
|
199
|
+
setup();
|
|
200
|
+
mock.method(childProcess, 'execFileSync', fakeExec('yarn'));
|
|
201
|
+
await migrate.run();
|
|
202
|
+
|
|
203
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
204
|
+
assert.equal(pkg.dependencies['@eui/deps-base'], '^22.0.0-alpha.85');
|
|
205
|
+
assert.deepEqual(calls.map((c) => c.replace(/ \S*node_modules\S*/, '')), [
|
|
206
|
+
'git status --porcelain',
|
|
207
|
+
'yarn install',
|
|
208
|
+
'node generate @eui/core:migrate-eui-config-files --force --eui-version=22.0.0-alpha.85',
|
|
209
|
+
'node generate @eui/core:migrate-all --force',
|
|
210
|
+
]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('no flag passed to ng is camelCase (Angular CLI 22 rejects them)', async () => {
|
|
214
|
+
setup({ path: 'src/app' });
|
|
215
|
+
mock.method(childProcess, 'execFileSync', fakeExec('yarn'));
|
|
216
|
+
await migrate.run();
|
|
217
|
+
const flags = calls.filter((c) => c.includes(' generate ')).flatMap((c) => c.split(' ')).filter((t) => t.startsWith('--'));
|
|
218
|
+
assert.ok(flags.length > 0);
|
|
219
|
+
assert.deepEqual(flags.filter((f) => /^--[a-z]+[A-Z]/.test(f)), []);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('"Could not find any files to migrate" skips that schematic and continues; summary printed', async () => {
|
|
223
|
+
setup({ skipUpgrade: true, groups: 'angular,eui', only: 'route-lazy-loading-migration,migrate' });
|
|
224
|
+
const logs = [];
|
|
225
|
+
mock.method(process, 'exit', (code) => { throw new Error(`exit ${code}`); });
|
|
226
|
+
mock.method(childProcess, 'execFileSync', (cmd, args) => {
|
|
227
|
+
calls.push(args.join(' '));
|
|
228
|
+
if (args.some((a) => a.includes('route-lazy-loading-migration'))) {
|
|
229
|
+
const err = new Error('Command failed');
|
|
230
|
+
err.stderr = 'Could not find any files to migrate under the path /x/src. Cannot run the route lazy loading migration.';
|
|
231
|
+
throw err;
|
|
232
|
+
}
|
|
233
|
+
return '';
|
|
234
|
+
});
|
|
235
|
+
mock.method(console, 'info', (...a) => logs.push(a.join(' ')));
|
|
236
|
+
await migrate.run();
|
|
237
|
+
assert.equal(calls.length, 2);
|
|
238
|
+
assert.ok(calls[1].includes('@eui/core:migrate'));
|
|
239
|
+
const text = logs.join('\n');
|
|
240
|
+
assert.match(text, /skipped, nothing to migrate \(1\)/);
|
|
241
|
+
assert.match(text, /ran \(1\)/);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('any other schematic failure still exits 1 and stops the run', async () => {
|
|
245
|
+
setup({ skipUpgrade: true, groups: 'angular,eui', only: 'route-lazy-loading-migration,migrate' });
|
|
246
|
+
const exit = mock.method(process, 'exit', (code) => { throw new Error(`exit ${code}`); });
|
|
247
|
+
mock.method(childProcess, 'execFileSync', (cmd, args) => {
|
|
248
|
+
calls.push(args.join(' '));
|
|
249
|
+
const err = new Error('boom');
|
|
250
|
+
err.stderr = 'TypeError: something real broke';
|
|
251
|
+
throw err;
|
|
252
|
+
});
|
|
253
|
+
mock.method(console, 'error', () => {});
|
|
254
|
+
await assert.rejects(migrate.run(), /exit 1/);
|
|
255
|
+
assert.equal(exit.mock.calls[0].arguments[0], 1);
|
|
256
|
+
assert.equal(calls.length, 1);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('--dryRun on v21: shows the diff, writes nothing, installs nothing, runs no schematic', async () => {
|
|
260
|
+
setup({ dryRun: true });
|
|
261
|
+
const before = fs.readFileSync(path.join(dir, 'package.json'), 'utf8');
|
|
262
|
+
mock.method(childProcess, 'execFileSync', fakeExec('yarn'));
|
|
263
|
+
await migrate.run();
|
|
264
|
+
assert.equal(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'), before);
|
|
265
|
+
assert.deepEqual(calls, []);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('--skipUpgrade runs the schematics only, no install, no forced --force', async () => {
|
|
269
|
+
setup({ skipUpgrade: true });
|
|
270
|
+
mock.method(childProcess, 'execFileSync', fakeExec('yarn'));
|
|
271
|
+
await migrate.run();
|
|
272
|
+
assert.ok(calls.every((c) => !c.startsWith('yarn') && !c.startsWith('git')));
|
|
273
|
+
assert.ok(calls.every((c) => !c.includes('--force')));
|
|
274
|
+
assert.equal(calls.length, 2);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test('--skipInstall bumps package.json then stops before the schematics', async () => {
|
|
278
|
+
setup({ skipInstall: true });
|
|
279
|
+
mock.method(childProcess, 'execFileSync', fakeExec('yarn'));
|
|
280
|
+
await migrate.run();
|
|
281
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).dependencies['@eui/deps-base'], '^22.0.0-alpha.85');
|
|
282
|
+
assert.deepEqual(calls, ['git status --porcelain']);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('a dirty tree is refused without --force, before anything is written', async () => {
|
|
286
|
+
setup();
|
|
287
|
+
fs.rmSync(path.join(dir, 'yarn.lock'));
|
|
288
|
+
write('package-lock.json', '{}');
|
|
289
|
+
const exit = mock.method(process, 'exit', (code) => { throw new Error(`exit ${code}`); });
|
|
290
|
+
mock.method(childProcess, 'execFileSync', (cmd, args) => {
|
|
291
|
+
calls.push([cmd, ...args].join(' '));
|
|
292
|
+
return cmd === 'git' ? ' M src/a.ts\n' : '';
|
|
293
|
+
});
|
|
294
|
+
mock.method(console, 'error', () => {});
|
|
295
|
+
await assert.rejects(migrate.run(), /exit 1/);
|
|
296
|
+
assert.equal(exit.mock.calls[0].arguments[0], 1);
|
|
297
|
+
assert.deepEqual(calls, ['git status --porcelain']);
|
|
298
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).dependencies['@eui/deps-base'], '^21.5.0');
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe('buildTasks', () => {
|
|
303
|
+
test('whole eui group: config files schematic runs before migrate-all', () => {
|
|
304
|
+
migrate.setActiveGroups(migrate.GROUPS);
|
|
305
|
+
const tasks = migrate.buildTasks({ eui: null });
|
|
306
|
+
assert.deepEqual(tasks.map((t) => t.schematic), ['migrate-eui-config-files', 'migrate-all']);
|
|
307
|
+
});
|
|
308
|
+
});
|