@trackunit/iris-app-build-utilities 2.10.13 → 3.0.1
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/CHANGELOG.md +45 -0
- package/package.json +2 -3
- package/src/buildMigrateSuggestion.d.ts +19 -0
- package/src/buildMigrateSuggestion.js +19 -0
- package/src/checkContentInsetAdoption.d.ts +1 -1
- package/src/checkContentInsetAdoption.js +1 -1
- package/src/checkPackageVersion.d.ts +12 -27
- package/src/checkPackageVersion.js +100 -68
- package/src/classifyPackageVersion.d.ts +78 -0
- package/src/classifyPackageVersion.js +69 -0
- package/src/reportPackageVersions.d.ts +13 -0
- package/src/reportPackageVersions.js +30 -0
- package/src/resolveLatestVersion.d.ts +10 -0
- package/src/resolveLatestVersion.js +45 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
## 3.0.1 (2026-10-29)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated iris-app-api to 2.12.18
|
|
6
|
+
|
|
7
|
+
# 3.0.0 (2026-10-29)
|
|
8
|
+
|
|
9
|
+
### 🚀 Features
|
|
10
|
+
|
|
11
|
+
- ⚠️ **iris-app-build-utilities:** one migrate suggestion instead of per-package version warnings [SDK-569] ([#27025](https://github.com/Trackunit/manager/pull/27025))
|
|
12
|
+
|
|
13
|
+
### ⚠️ Breaking Changes
|
|
14
|
+
|
|
15
|
+
- **iris-app-build-utilities:** one migrate suggestion instead of per-package version warnings [SDK-569] ([#27025](https://github.com/Trackunit/manager/pull/27025))
|
|
16
|
+
|
|
17
|
+
### 🧱 Updated Dependencies
|
|
18
|
+
|
|
19
|
+
- Updated iris-app-api to 2.12.17
|
|
20
|
+
|
|
21
|
+
### ❤️ Thank You
|
|
22
|
+
|
|
23
|
+
- Mikkel Thorbjørn Andersen @mta-trackunit
|
|
24
|
+
|
|
25
|
+
## 2.10.16 (2026-10-29)
|
|
26
|
+
|
|
27
|
+
### 🧱 Updated Dependencies
|
|
28
|
+
|
|
29
|
+
- Updated iris-app-api to 2.12.16
|
|
30
|
+
- Updated shared-utils to 1.22.13
|
|
31
|
+
|
|
32
|
+
## 2.10.15 (2026-10-29)
|
|
33
|
+
|
|
34
|
+
### 🧱 Updated Dependencies
|
|
35
|
+
|
|
36
|
+
- Updated iris-app-api to 2.12.15
|
|
37
|
+
- Updated shared-utils to 1.22.12
|
|
38
|
+
|
|
39
|
+
## 2.10.14 (2026-10-29)
|
|
40
|
+
|
|
41
|
+
### 🧱 Updated Dependencies
|
|
42
|
+
|
|
43
|
+
- Updated iris-app-api to 2.12.14
|
|
44
|
+
- Updated shared-utils to 1.22.11
|
|
45
|
+
|
|
1
46
|
## 2.10.13 (2026-10-28)
|
|
2
47
|
|
|
3
48
|
### 🧱 Updated Dependencies
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/iris-app-build-utilities",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"engines": {
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
"@nx/react": "23.3.0",
|
|
14
14
|
"tslib": "^2.6.2",
|
|
15
15
|
"csp-header": "^6.4.0",
|
|
16
|
-
"@trackunit/iris-app-api": "2.12.
|
|
16
|
+
"@trackunit/iris-app-api": "2.12.18",
|
|
17
17
|
"@nx/devkit": "23.3.0",
|
|
18
|
-
"@trackunit/shared-utils": "1.22.10",
|
|
19
18
|
"http-proxy-middleware": "3.0.5",
|
|
20
19
|
"marked": "14.1.2",
|
|
21
20
|
"pacote": "^21.5.1",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getPackageManagerCommand } from "@nx/devkit";
|
|
2
|
+
export declare const MIGRATIONS_PACKAGE = "@trackunit/migrations";
|
|
3
|
+
type PackageManagerCommands = ReturnType<typeof getPackageManagerCommand>;
|
|
4
|
+
export type BuildMigrateSuggestionInput = {
|
|
5
|
+
/** Whether the app's package.json declares `@trackunit/migrations`. */
|
|
6
|
+
readonly migrationsDeclared: boolean;
|
|
7
|
+
/** Defaults to the commands of the package manager detected in the workspace. */
|
|
8
|
+
readonly packageManagerCommand?: Pick<PackageManagerCommands, "exec" | "addDev">;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Phrases the one command that brings every `@trackunit/*` dependency up to date.
|
|
12
|
+
* Without `@trackunit/migrations` installed the generator cannot be resolved, so
|
|
13
|
+
* the install is prepended when it is not declared.
|
|
14
|
+
*
|
|
15
|
+
* @param {BuildMigrateSuggestionInput} input - Whether migrations is declared, and the package manager commands to phrase it with.
|
|
16
|
+
* @returns {string} The command to suggest, e.g. `npx nx g @trackunit/migrations:migrate`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const buildMigrateSuggestion: ({ migrationsDeclared, packageManagerCommand, }: BuildMigrateSuggestionInput) => string;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildMigrateSuggestion = exports.MIGRATIONS_PACKAGE = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
exports.MIGRATIONS_PACKAGE = "@trackunit/migrations";
|
|
6
|
+
/**
|
|
7
|
+
* Phrases the one command that brings every `@trackunit/*` dependency up to date.
|
|
8
|
+
* Without `@trackunit/migrations` installed the generator cannot be resolved, so
|
|
9
|
+
* the install is prepended when it is not declared.
|
|
10
|
+
*
|
|
11
|
+
* @param {BuildMigrateSuggestionInput} input - Whether migrations is declared, and the package manager commands to phrase it with.
|
|
12
|
+
* @returns {string} The command to suggest, e.g. `npx nx g @trackunit/migrations:migrate`.
|
|
13
|
+
*/
|
|
14
|
+
const buildMigrateSuggestion = ({ migrationsDeclared, packageManagerCommand = (0, devkit_1.getPackageManagerCommand)((0, devkit_1.detectPackageManager)()), }) => {
|
|
15
|
+
const migrate = `${packageManagerCommand.exec} nx g ${exports.MIGRATIONS_PACKAGE}:migrate`;
|
|
16
|
+
return migrationsDeclared ? migrate : `${packageManagerCommand.addDev} ${exports.MIGRATIONS_PACKAGE} && ${migrate}`;
|
|
17
|
+
};
|
|
18
|
+
exports.buildMigrateSuggestion = buildMigrateSuggestion;
|
|
19
|
+
//# sourceMappingURL=buildMigrateSuggestion.js.map
|
|
@@ -16,7 +16,7 @@ export declare const CONTENT_INSET_AFFECTED_EXTENSION_TYPES: ReadonlySet<IrisApp
|
|
|
16
16
|
/**
|
|
17
17
|
* Advisory warning when an app's resolved SDK version is at/above the content-inset
|
|
18
18
|
* cutoff but the app source has not adopted `p-content-space`. Matches the
|
|
19
|
-
* `
|
|
19
|
+
* advisory `logWarning` tone of `checkPackageVersion` — never throws.
|
|
20
20
|
*
|
|
21
21
|
* Apps that declare none of {@link CONTENT_INSET_AFFECTED_EXTENSION_TYPES} are
|
|
22
22
|
* skipped: the host never applied or removed inset for them.
|
|
@@ -24,7 +24,7 @@ exports.CONTENT_INSET_AFFECTED_EXTENSION_TYPES = new Set([
|
|
|
24
24
|
/**
|
|
25
25
|
* Advisory warning when an app's resolved SDK version is at/above the content-inset
|
|
26
26
|
* cutoff but the app source has not adopted `p-content-space`. Matches the
|
|
27
|
-
* `
|
|
27
|
+
* advisory `logWarning` tone of `checkPackageVersion` — never throws.
|
|
28
28
|
*
|
|
29
29
|
* Apps that declare none of {@link CONTENT_INSET_AFFECTED_EXTENSION_TYPES} are
|
|
30
30
|
* skipped: the host never applied or removed inset for them.
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param pkg package to look for.
|
|
4
|
-
* @param localRange local version of the package.
|
|
5
|
-
* @param range range
|
|
6
|
-
* @returns { boolean } true if its a valid version
|
|
7
|
-
*/
|
|
8
|
-
export declare const versionCheck: (pkg: string, localRange: string, range: string, throwError?: boolean) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Get the latest version of the package from the registry.
|
|
11
|
-
*
|
|
12
|
-
* @param pkg package to look for.
|
|
13
|
-
* @returns { Promise<string> } returns version
|
|
14
|
-
*/
|
|
15
|
-
export declare const getLatestRemoteVersion: (pkg: string, throwError?: boolean) => Promise<string | undefined>;
|
|
16
1
|
/**
|
|
17
2
|
* Check if the current version of the package is the same as the one in the manager.
|
|
18
3
|
*
|
|
@@ -20,18 +5,18 @@ export declare const getLatestRemoteVersion: (pkg: string, throwError?: boolean)
|
|
|
20
5
|
* @returns { boolean} true if its a valid version
|
|
21
6
|
*/
|
|
22
7
|
export declare const checkNxVersion: (managerNxVersion: string, throwError?: boolean) => Promise<boolean>;
|
|
8
|
+
export type VersionCheckOptions = {
|
|
9
|
+
/** Print at most one line summarising `@trackunit/*` drift. */
|
|
10
|
+
readonly report: boolean;
|
|
11
|
+
/** Throw on the first package found a major behind, or on packages whose latest version cannot be looked up. */
|
|
12
|
+
readonly block: boolean;
|
|
13
|
+
};
|
|
23
14
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @returns {Promise<boolean>} true if the versions are the same.
|
|
29
|
-
*/
|
|
30
|
-
export declare const checkTrackunitPackages: (dependencies: Record<string, string>, throwError?: boolean) => Promise<boolean>;
|
|
31
|
-
/**
|
|
32
|
-
* Check if the current version of the packages is the same as the one in the manager.
|
|
15
|
+
* Checks the app's `@trackunit/*` dependencies against the versions `@trackunit/migrations` would upgrade them to.
|
|
16
|
+
* The report is printed as soon as one package is found outdated, and blocking stops at the first package a major
|
|
17
|
+
* behind; lookups still in flight are left to finish unobserved. When both options are set the report is printed
|
|
18
|
+
* before throwing, so the line is visible alongside the error.
|
|
33
19
|
*
|
|
34
|
-
* @param {
|
|
35
|
-
* @returns {Promise<boolean>} true if the versions are the same.
|
|
20
|
+
* @param {VersionCheckOptions} options - Whether to print the report and whether to fail on blocking drift.
|
|
36
21
|
*/
|
|
37
|
-
export declare const checkPackageVersion: (
|
|
22
|
+
export declare const checkPackageVersion: ({ report, block }: VersionCheckOptions) => Promise<void>;
|
|
@@ -1,55 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkPackageVersion = exports.
|
|
3
|
+
exports.checkPackageVersion = exports.checkNxVersion = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const shared_utils_1 = require("@trackunit/shared-utils");
|
|
7
6
|
const child_process_1 = require("child_process");
|
|
8
|
-
const pacote = tslib_1.__importStar(require("pacote"));
|
|
9
7
|
const semver = tslib_1.__importStar(require("semver"));
|
|
8
|
+
const buildMigrateSuggestion_1 = require("./buildMigrateSuggestion");
|
|
9
|
+
const classifyPackageVersion_1 = require("./classifyPackageVersion");
|
|
10
|
+
const consoleUtils_1 = require("./plugin-shared/consoleUtils");
|
|
11
|
+
const reportPackageVersions_1 = require("./reportPackageVersions");
|
|
12
|
+
const resolveLatestVersion_1 = require("./resolveLatestVersion");
|
|
13
|
+
const TRACKUNIT_SCOPE = "@trackunit/";
|
|
14
|
+
const NX_MIGRATE_GUIDE = "https://nx.dev/docs/features/automate-updating-dependencies";
|
|
10
15
|
/**
|
|
16
|
+
* Warns when the local nx version does not satisfy the manager's, and throws when it is a major behind.
|
|
11
17
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @returns { boolean } true if its a valid version
|
|
18
|
+
* @param {string} localRange local version of nx.
|
|
19
|
+
* @param {string} range version of nx in the manager.
|
|
20
|
+
* @param {boolean} throwError whether a major-behind version should throw.
|
|
16
21
|
*/
|
|
17
|
-
const
|
|
22
|
+
const compareNxVersion = (localRange, range, throwError) => {
|
|
18
23
|
const localVersion = semver.minVersion(localRange) ?? localRange; // ('^1.0.0') => '1.0.0'
|
|
19
24
|
const remoteVersion = semver.minVersion(range) ?? range; // Assume range is in a format that semver.minVersion can handle
|
|
20
25
|
if (!semver.satisfies(localVersion, range)) {
|
|
21
|
-
const msg = `
|
|
26
|
+
const msg = `nx is outdated (installed ${localRange}, expected ${range}). Follow the nx migrate guide: ${NX_MIGRATE_GUIDE}`;
|
|
22
27
|
if (semver.major(localVersion) < semver.major(remoteVersion) && throwError) {
|
|
23
28
|
throw new Error(msg);
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.warn(`⚠️ ${msg}\n`);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
+
(0, consoleUtils_1.logWarning)(`⚠️ ${msg}`);
|
|
30
31
|
}
|
|
31
|
-
return true;
|
|
32
32
|
};
|
|
33
|
-
exports.versionCheck = versionCheck;
|
|
34
|
-
/**
|
|
35
|
-
* Get the latest version of the package from the registry.
|
|
36
|
-
*
|
|
37
|
-
* @param pkg package to look for.
|
|
38
|
-
* @returns { Promise<string> } returns version
|
|
39
|
-
*/
|
|
40
|
-
const getLatestRemoteVersion = async (pkg, throwError = true) => {
|
|
41
|
-
try {
|
|
42
|
-
const manifest = await pacote.manifest(pkg);
|
|
43
|
-
return manifest.version;
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
if (throwError) {
|
|
47
|
-
throw new Error(`Error fetching manifest for package ${pkg}. This package might need to be published, or it has been included as a dependency by mistake.`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return undefined;
|
|
51
|
-
};
|
|
52
|
-
exports.getLatestRemoteVersion = getLatestRemoteVersion;
|
|
53
33
|
/**
|
|
54
34
|
* Check if the current version of the package is the same as the one in the manager.
|
|
55
35
|
*
|
|
@@ -60,49 +40,101 @@ const checkNxVersion = async (managerNxVersion, throwError = true) => {
|
|
|
60
40
|
const currentNxVersion = (0, child_process_1.execSync)("nx --version")
|
|
61
41
|
.toString("utf-8")
|
|
62
42
|
.replace(/\r?\n|\r/, ""); // regex removes any line breaks
|
|
63
|
-
|
|
43
|
+
compareNxVersion(currentNxVersion, managerNxVersion, throwError);
|
|
44
|
+
return true;
|
|
64
45
|
};
|
|
65
46
|
exports.checkNxVersion = checkNxVersion;
|
|
47
|
+
const trackunitEntriesOf = (dependencies = {}) => Object.entries(dependencies).filter(([pkg]) => pkg.startsWith(TRACKUNIT_SCOPE));
|
|
66
48
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* @param {boolean} throwError - Whether to throw an error if the version is not the same.
|
|
71
|
-
* @returns {Promise<boolean>} true if the versions are the same.
|
|
49
|
+
* @param {PackageJson} packageJson - The app's package.json.
|
|
50
|
+
* @returns {Array<[string, string]>} Every `@trackunit/*` declaration as `[pkg, specifier]`. A package declared in both
|
|
51
|
+
* fields appears twice, since migrate judges each declaration on its own.
|
|
72
52
|
*/
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
53
|
+
const getDeclaredTrackunitPackages = ({ dependencies, devDependencies }) => [
|
|
54
|
+
...trackunitEntriesOf(dependencies),
|
|
55
|
+
...trackunitEntriesOf(devDependencies),
|
|
56
|
+
];
|
|
57
|
+
const createLatestVersionLookup = () => {
|
|
58
|
+
const lookups = new Map();
|
|
59
|
+
return pkg => {
|
|
60
|
+
const existing = lookups.get(pkg);
|
|
61
|
+
if (existing !== undefined) {
|
|
62
|
+
return existing;
|
|
82
63
|
}
|
|
64
|
+
const lookup = (0, resolveLatestVersion_1.resolveLatestVersion)(pkg);
|
|
65
|
+
lookups.set(pkg, lookup);
|
|
66
|
+
return lookup;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const statusOf = async (pkg, specifier, latestVersionOf) => {
|
|
70
|
+
if (!(0, classifyPackageVersion_1.isCheckableSpecifier)(specifier)) {
|
|
71
|
+
return { kind: "skipped", pkg };
|
|
83
72
|
}
|
|
84
|
-
|
|
73
|
+
const latest = await latestVersionOf(pkg);
|
|
74
|
+
return latest === undefined ? { kind: "unavailable", pkg } : (0, classifyPackageVersion_1.classifyPackageVersion)({ pkg, specifier, latest });
|
|
85
75
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return { trackunitDependencies, trackunitDevDependencies };
|
|
92
|
-
}
|
|
76
|
+
const isDrift = (status) => status.kind === "outdated" || status.kind === "major";
|
|
77
|
+
const isMajor = (status) => status.kind === "major" || status.kind === "unrewritableMajor";
|
|
78
|
+
const majorDriftMessage = (drift, suggestion) => drift.kind === "major"
|
|
79
|
+
? `${drift.pkg} is a major version behind (${drift.declared} -> ${drift.latest}). Run: ${suggestion}`
|
|
80
|
+
: `${drift.pkg} is a major version behind (${drift.specifier} -> ${drift.latest}). Migrate cannot rewrite "${drift.specifier}"; set it to "${drift.declared}", then run: ${suggestion}`;
|
|
93
81
|
/**
|
|
94
|
-
*
|
|
82
|
+
* @template TValue, TMatch
|
|
83
|
+
* @param {ReadonlyArray<Promise<TValue>>} promises - Lookups that may still be in flight.
|
|
84
|
+
* @param {(value: TValue) => boolean} predicate - The match to stop at.
|
|
85
|
+
* @returns {Promise<TMatch | undefined>} The first value to settle that matches, without waiting for the others; `undefined` once all have
|
|
86
|
+
* settled without a match.
|
|
87
|
+
*/
|
|
88
|
+
const firstWhere = (promises, predicate) => new Promise((resolve, reject) => {
|
|
89
|
+
let pending = promises.length;
|
|
90
|
+
if (pending === 0) {
|
|
91
|
+
resolve(undefined);
|
|
92
|
+
}
|
|
93
|
+
for (const promise of promises) {
|
|
94
|
+
promise.then(value => {
|
|
95
|
+
pending -= 1;
|
|
96
|
+
if (predicate(value)) {
|
|
97
|
+
resolve(value);
|
|
98
|
+
}
|
|
99
|
+
else if (pending === 0) {
|
|
100
|
+
resolve(undefined);
|
|
101
|
+
}
|
|
102
|
+
}, reject);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const assertAllAvailable = (statuses) => {
|
|
106
|
+
const unavailable = [...new Set(statuses.filter(status => status.kind === "unavailable").map(({ pkg }) => pkg))];
|
|
107
|
+
if (unavailable.length > 0) {
|
|
108
|
+
const names = unavailable.join(", ");
|
|
109
|
+
throw new Error(unavailable.length === 1
|
|
110
|
+
? `Error fetching manifest for package ${names}. This package might need to be published, or it has been included as a dependency by mistake.`
|
|
111
|
+
: `Error fetching manifest for packages ${names}. These packages might need to be published, or they have been included as a dependency by mistake.`);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Checks the app's `@trackunit/*` dependencies against the versions `@trackunit/migrations` would upgrade them to.
|
|
116
|
+
* The report is printed as soon as one package is found outdated, and blocking stops at the first package a major
|
|
117
|
+
* behind; lookups still in flight are left to finish unobserved. When both options are set the report is printed
|
|
118
|
+
* before throwing, so the line is visible alongside the error.
|
|
95
119
|
*
|
|
96
|
-
* @param {
|
|
97
|
-
* @returns {Promise<boolean>} true if the versions are the same.
|
|
120
|
+
* @param {VersionCheckOptions} options - Whether to print the report and whether to fail on blocking drift.
|
|
98
121
|
*/
|
|
99
|
-
const checkPackageVersion = async (
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
122
|
+
const checkPackageVersion = async ({ report, block }) => {
|
|
123
|
+
const declared = getDeclaredTrackunitPackages((0, devkit_1.readJsonFile)("package.json"));
|
|
124
|
+
const latestVersionOf = createLatestVersionLookup();
|
|
125
|
+
const lookups = declared.map(([pkg, specifier]) => statusOf(pkg, specifier, latestVersionOf));
|
|
126
|
+
const suggest = () => (0, buildMigrateSuggestion_1.buildMigrateSuggestion)({ migrationsDeclared: declared.some(([pkg]) => pkg === buildMigrateSuggestion_1.MIGRATIONS_PACKAGE) });
|
|
127
|
+
if (report) {
|
|
128
|
+
const drift = await firstWhere(lookups, isDrift);
|
|
129
|
+
(0, reportPackageVersions_1.reportPackageVersions)(drift === undefined ? await Promise.all(lookups) : [drift], suggest);
|
|
130
|
+
}
|
|
131
|
+
if (block) {
|
|
132
|
+
const major = await firstWhere(lookups, isMajor);
|
|
133
|
+
if (major !== undefined) {
|
|
134
|
+
throw new Error(majorDriftMessage(major, suggest()));
|
|
135
|
+
}
|
|
136
|
+
assertAllAvailable(await Promise.all(lookups));
|
|
137
|
+
}
|
|
106
138
|
};
|
|
107
139
|
exports.checkPackageVersion = checkPackageVersion;
|
|
108
140
|
//# sourceMappingURL=checkPackageVersion.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A declared version that `@trackunit/migrations` would rewrite to `latest`.
|
|
3
|
+
*/
|
|
4
|
+
type Drift = {
|
|
5
|
+
readonly pkg: string;
|
|
6
|
+
/** The specifier exactly as declared in package.json, e.g. `^1.14.80`. */
|
|
7
|
+
readonly specifier: string;
|
|
8
|
+
/** The normalised version without its range operator, e.g. `1.14.80`. */
|
|
9
|
+
readonly declared: string;
|
|
10
|
+
/** Latest version published to the registry. */
|
|
11
|
+
readonly latest: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* How a declared `@trackunit/*` dependency compares to the latest published version.
|
|
15
|
+
* `unrewritableMajor` is a range migrate leaves alone (e.g. `^4.2`) whose lowest allowed
|
|
16
|
+
* version is a major behind: never reported, since migrate would not fix it, but it blocks
|
|
17
|
+
* like `major`. Its `declared` is that lowest version.
|
|
18
|
+
*/
|
|
19
|
+
export type PackageVersionClassification = {
|
|
20
|
+
readonly kind: "current";
|
|
21
|
+
readonly pkg: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "skipped";
|
|
24
|
+
readonly pkg: string;
|
|
25
|
+
} | ({
|
|
26
|
+
readonly kind: "outdated";
|
|
27
|
+
} & Drift) | ({
|
|
28
|
+
readonly kind: "major";
|
|
29
|
+
} & Drift) | ({
|
|
30
|
+
readonly kind: "unrewritableMajor";
|
|
31
|
+
} & Drift);
|
|
32
|
+
/**
|
|
33
|
+
* A classified dependency, or one whose latest version could not be looked up.
|
|
34
|
+
*/
|
|
35
|
+
export type PackageVersionStatus = PackageVersionClassification | {
|
|
36
|
+
readonly kind: "unavailable";
|
|
37
|
+
readonly pkg: string;
|
|
38
|
+
};
|
|
39
|
+
export type MajorDrift = Extract<PackageVersionClassification, {
|
|
40
|
+
kind: "major";
|
|
41
|
+
}>;
|
|
42
|
+
export type UnrewritableMajorDrift = Extract<PackageVersionClassification, {
|
|
43
|
+
kind: "unrewritableMajor";
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* @param classification - A classified dependency.
|
|
47
|
+
* @returns {boolean} True when the package is at least one major version behind.
|
|
48
|
+
*/
|
|
49
|
+
export declare const isMajorDrift: (classification: PackageVersionClassification) => classification is MajorDrift;
|
|
50
|
+
export type ClassifyPackageVersionInput = {
|
|
51
|
+
/** Package name, e.g. `@trackunit/css-core`. */
|
|
52
|
+
readonly pkg: string;
|
|
53
|
+
/** Specifier as declared in the app's package.json, e.g. `^1.14.80`. */
|
|
54
|
+
readonly specifier: string;
|
|
55
|
+
/** Latest version published to the registry. */
|
|
56
|
+
readonly latest: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @param specifier - Specifier as declared in package.json, e.g. `^1.14.80` or `file:../x`.
|
|
60
|
+
* @returns {boolean} False when `classifyPackageVersion` would skip it whatever `latest` is.
|
|
61
|
+
*/
|
|
62
|
+
export declare const isRewritableSpecifier: (specifier: string) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* @param specifier - Specifier as declared in package.json.
|
|
65
|
+
* @returns {boolean} False when the specifier can never be outdated or a major behind, so it needs no lookup.
|
|
66
|
+
*/
|
|
67
|
+
export declare const isCheckableSpecifier: (specifier: string) => boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Decides how a declared dependency relates to what is published. A range that
|
|
70
|
+
* already permits `latest` is still outdated, and a major is a literal
|
|
71
|
+
* major-number gap, so a 0.x minor bump is only outdated. Ranges migrate cannot
|
|
72
|
+
* rewrite are judged by their lowest allowed version, and only for major drift.
|
|
73
|
+
*
|
|
74
|
+
* @param {ClassifyPackageVersionInput} input - The package, its declared specifier and the latest published version.
|
|
75
|
+
* @returns {PackageVersionClassification} How this package should be treated.
|
|
76
|
+
*/
|
|
77
|
+
export declare const classifyPackageVersion: ({ pkg, specifier, latest, }: ClassifyPackageVersionInput) => PackageVersionClassification;
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classifyPackageVersion = exports.isCheckableSpecifier = exports.isRewritableSpecifier = exports.isMajorDrift = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const semver = tslib_1.__importStar(require("semver"));
|
|
6
|
+
/**
|
|
7
|
+
* @param classification - A classified dependency.
|
|
8
|
+
* @returns {boolean} True when the package is at least one major version behind.
|
|
9
|
+
*/
|
|
10
|
+
const isMajorDrift = (classification) => classification.kind === "major";
|
|
11
|
+
exports.isMajorDrift = isMajorDrift;
|
|
12
|
+
// Must stay in step with `parseSpecifier` in `@trackunit/migrations`
|
|
13
|
+
// (upgrade-dependencies.ts): "outdated" means exactly "migrate would rewrite it".
|
|
14
|
+
// Mirrored rather than imported so migrations does not become a runtime dependency.
|
|
15
|
+
const RANGE_OPERATOR = /^(\^|~|>=|>)?\s*(.+)$/;
|
|
16
|
+
const declaredVersionOf = (specifier) => {
|
|
17
|
+
const version = RANGE_OPERATOR.exec(specifier.trim())?.[2];
|
|
18
|
+
return version === undefined ? undefined : (semver.valid(version) ?? undefined);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @param specifier - Specifier as declared in package.json, e.g. `^1.14.80` or `file:../x`.
|
|
22
|
+
* @returns {boolean} False when `classifyPackageVersion` would skip it whatever `latest` is.
|
|
23
|
+
*/
|
|
24
|
+
const isRewritableSpecifier = (specifier) => declaredVersionOf(specifier) !== undefined;
|
|
25
|
+
exports.isRewritableSpecifier = isRewritableSpecifier;
|
|
26
|
+
const hasLowerBound = (comparators) => comparators.some(({ operator }) => operator !== "<" && operator !== "<=");
|
|
27
|
+
// Local protocols, aliases, git URLs and dist-tags are not semver ranges; `*` permits anything.
|
|
28
|
+
// Without a lower bound (`<6.0.0`) `minVersion` would report 0.0.0, which is no floor at all.
|
|
29
|
+
const lowestVersionOf = (specifier) => {
|
|
30
|
+
const range = semver.validRange(specifier.trim());
|
|
31
|
+
if (range === null || range === "*" || !new semver.Range(range).set.every(hasLowerBound)) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
return semver.minVersion(range)?.version;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* @param specifier - Specifier as declared in package.json.
|
|
38
|
+
* @returns {boolean} False when the specifier can never be outdated or a major behind, so it needs no lookup.
|
|
39
|
+
*/
|
|
40
|
+
const isCheckableSpecifier = (specifier) => (0, exports.isRewritableSpecifier)(specifier) || lowestVersionOf(specifier) !== undefined;
|
|
41
|
+
exports.isCheckableSpecifier = isCheckableSpecifier;
|
|
42
|
+
/**
|
|
43
|
+
* Decides how a declared dependency relates to what is published. A range that
|
|
44
|
+
* already permits `latest` is still outdated, and a major is a literal
|
|
45
|
+
* major-number gap, so a 0.x minor bump is only outdated. Ranges migrate cannot
|
|
46
|
+
* rewrite are judged by their lowest allowed version, and only for major drift.
|
|
47
|
+
*
|
|
48
|
+
* @param {ClassifyPackageVersionInput} input - The package, its declared specifier and the latest published version.
|
|
49
|
+
* @returns {PackageVersionClassification} How this package should be treated.
|
|
50
|
+
*/
|
|
51
|
+
const classifyPackageVersion = ({ pkg, specifier, latest, }) => {
|
|
52
|
+
if (semver.valid(latest) === null) {
|
|
53
|
+
return { kind: "skipped", pkg };
|
|
54
|
+
}
|
|
55
|
+
const declared = declaredVersionOf(specifier);
|
|
56
|
+
if (declared === undefined) {
|
|
57
|
+
const lowest = lowestVersionOf(specifier);
|
|
58
|
+
return lowest !== undefined && semver.major(latest) > semver.major(lowest)
|
|
59
|
+
? { kind: "unrewritableMajor", pkg, specifier, declared: lowest, latest }
|
|
60
|
+
: { kind: "skipped", pkg };
|
|
61
|
+
}
|
|
62
|
+
if (!semver.gt(latest, declared)) {
|
|
63
|
+
return { kind: "current", pkg };
|
|
64
|
+
}
|
|
65
|
+
const kind = semver.major(latest) > semver.major(declared) ? "major" : "outdated";
|
|
66
|
+
return { kind, pkg, specifier, declared, latest };
|
|
67
|
+
};
|
|
68
|
+
exports.classifyPackageVersion = classifyPackageVersion;
|
|
69
|
+
//# sourceMappingURL=classifyPackageVersion.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PackageVersionStatus } from "./classifyPackageVersion";
|
|
2
|
+
/**
|
|
3
|
+
* Reports `@trackunit/*` version status as at most one line, never naming or counting packages, so it can be
|
|
4
|
+
* printed as soon as the first outdated package is found. The migrate command is suggested only when something is
|
|
5
|
+
* outdated.
|
|
6
|
+
*
|
|
7
|
+
* Output never blocks, so it always goes through `logWarning`; a red `logError`
|
|
8
|
+
* alongside a zero exit code would misrepresent what happened.
|
|
9
|
+
*
|
|
10
|
+
* @param {ReadonlyArray<PackageVersionStatus>} statuses - The statuses known so far; one outdated entry is enough.
|
|
11
|
+
* @param {() => string} suggest - Returns the command that brings every package up to date; only called when something is outdated.
|
|
12
|
+
*/
|
|
13
|
+
export declare const reportPackageVersions: (statuses: ReadonlyArray<PackageVersionStatus>, suggest: () => string) => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reportPackageVersions = void 0;
|
|
4
|
+
const consoleUtils_1 = require("./plugin-shared/consoleUtils");
|
|
5
|
+
/**
|
|
6
|
+
* Reports `@trackunit/*` version status as at most one line, never naming or counting packages, so it can be
|
|
7
|
+
* printed as soon as the first outdated package is found. The migrate command is suggested only when something is
|
|
8
|
+
* outdated.
|
|
9
|
+
*
|
|
10
|
+
* Output never blocks, so it always goes through `logWarning`; a red `logError`
|
|
11
|
+
* alongside a zero exit code would misrepresent what happened.
|
|
12
|
+
*
|
|
13
|
+
* @param {ReadonlyArray<PackageVersionStatus>} statuses - The statuses known so far; one outdated entry is enough.
|
|
14
|
+
* @param {() => string} suggest - Returns the command that brings every package up to date; only called when something is outdated.
|
|
15
|
+
*/
|
|
16
|
+
const reportPackageVersions = (statuses, suggest) => {
|
|
17
|
+
const has = (kind) => statuses.some(status => status.kind === kind);
|
|
18
|
+
if (has("outdated") || has("major")) {
|
|
19
|
+
(0, consoleUtils_1.logWarning)(`⚠️ @trackunit packages are outdated. Run: ${suggest()}`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!has("unavailable")) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
(0, consoleUtils_1.logWarning)(has("current")
|
|
26
|
+
? "⚠️ Some @trackunit packages could not be checked."
|
|
27
|
+
: "⚠️ @trackunit version check skipped: latest versions could not be looked up.");
|
|
28
|
+
};
|
|
29
|
+
exports.reportPackageVersions = reportPackageVersions;
|
|
30
|
+
//# sourceMappingURL=reportPackageVersions.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Looks up the version `@trackunit/migrations` would upgrade a package to.
|
|
3
|
+
* `pacote.manifest` filters by the running Node's `engines`, so this can be
|
|
4
|
+
* behind the registry's `latest` dist-tag.
|
|
5
|
+
*
|
|
6
|
+
* @param pkg - Package name, e.g. `@trackunit/css-core`.
|
|
7
|
+
* @returns {Promise<string | undefined>} The resolved version, or undefined when the lookup fails or takes longer
|
|
8
|
+
* than 10 seconds.
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolveLatestVersion: (pkg: string) => Promise<string | undefined>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveLatestVersion = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pacote = tslib_1.__importStar(require("pacote"));
|
|
6
|
+
// The registry must stay in step with `registryOptions` and `resolveLatestVersion` in
|
|
7
|
+
// `@trackunit/migrations` (upgrade-dependencies.ts), so the check never reports a
|
|
8
|
+
// version migrate would not move to. Mirrored rather than imported so migrations
|
|
9
|
+
// does not become a runtime dependency.
|
|
10
|
+
const registryOptions = () => process.env.TU_NPM_REGISTRY ? { registry: process.env.TU_NPM_REGISTRY } : undefined;
|
|
11
|
+
// npm-registry-fetch defaults to a 5-minute timeout plus retries, and its timeout does not
|
|
12
|
+
// cover a TCP connect that never completes (the OS gives up after ~75s), so the lookup also
|
|
13
|
+
// gets its own deadline. A timeout becomes `undefined`, so submitApp still fails closed.
|
|
14
|
+
const LOOKUP_TIMEOUT_MS = 10000;
|
|
15
|
+
const withDeadline = (promise, ms) => new Promise((resolve, reject) => {
|
|
16
|
+
const timer = setTimeout(() => resolve(undefined), ms);
|
|
17
|
+
timer.unref();
|
|
18
|
+
promise.then(value => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
resolve(value);
|
|
21
|
+
}, (error) => {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
reject(error);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Looks up the version `@trackunit/migrations` would upgrade a package to.
|
|
28
|
+
* `pacote.manifest` filters by the running Node's `engines`, so this can be
|
|
29
|
+
* behind the registry's `latest` dist-tag.
|
|
30
|
+
*
|
|
31
|
+
* @param pkg - Package name, e.g. `@trackunit/css-core`.
|
|
32
|
+
* @returns {Promise<string | undefined>} The resolved version, or undefined when the lookup fails or takes longer
|
|
33
|
+
* than 10 seconds.
|
|
34
|
+
*/
|
|
35
|
+
const resolveLatestVersion = async (pkg) => {
|
|
36
|
+
try {
|
|
37
|
+
const manifest = await withDeadline(pacote.manifest(pkg, { ...registryOptions(), timeout: LOOKUP_TIMEOUT_MS, fetchRetries: 0 }), LOOKUP_TIMEOUT_MS);
|
|
38
|
+
return manifest?.version;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.resolveLatestVersion = resolveLatestVersion;
|
|
45
|
+
//# sourceMappingURL=resolveLatestVersion.js.map
|