@nx/devkit 23.1.0 → 23.1.2
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/dist/internal.d.ts +3 -2
- package/dist/internal.js +139 -4
- package/dist/ngcli-adapter.d.ts +1 -1
- package/dist/ngcli-adapter.js +2 -1
- package/dist/src/generators/format-files.d.ts +3 -1
- package/dist/src/generators/format-files.js +14 -2
- package/dist/src/generators/plugin-migrations/executor-to-plugin-migrator.d.ts +1 -2
- package/dist/src/generators/plugin-migrations/executor-to-plugin-migrator.js +1 -2
- package/dist/src/generators/project-name-and-root-utils.js +13 -0
- package/dist/src/generators/visit-not-ignored-files.d.ts +7 -0
- package/dist/src/generators/visit-not-ignored-files.js +35 -10
- package/dist/src/utils/add-plugin.js +11 -4
- package/dist/src/utils/installed-version.d.ts +16 -3
- package/dist/src/utils/installed-version.js +29 -4
- package/dist/src/utils/invoke-nx-generator.js +7 -3
- package/dist/src/utils/nx-ignore-internals.d.ts +23 -0
- package/dist/src/utils/nx-ignore-internals.js +36 -0
- package/dist/src/utils/package-json.js +7 -2
- package/dist/src/utils/semver.js +2 -1
- package/dist/src/utils/version-floor.d.ts +16 -4
- package/dist/src/utils/version-floor.js +71 -5
- package/package.json +27 -5
- package/dist/src/utils/catalog/index.d.ts +0 -9
- package/dist/src/utils/catalog/index.js +0 -38
- package/dist/src/utils/catalog/manager-factory.d.ts +0 -5
- package/dist/src/utils/catalog/manager-factory.js +0 -20
- package/dist/src/utils/catalog/manager-utils.d.ts +0 -9
- package/dist/src/utils/catalog/manager-utils.js +0 -215
- package/dist/src/utils/catalog/manager.d.ts +0 -40
- package/dist/src/utils/catalog/manager.js +0 -13
- package/dist/src/utils/catalog/pnpm-manager.d.ts +0 -21
- package/dist/src/utils/catalog/pnpm-manager.js +0 -151
- package/dist/src/utils/catalog/types.d.ts +0 -11
- package/dist/src/utils/catalog/types.js +0 -2
- package/dist/src/utils/catalog/yarn-manager.d.ts +0 -21
- package/dist/src/utils/catalog/yarn-manager.js +0 -151
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NOTHING_IGNORED = void 0;
|
|
4
|
+
exports.assertNxSupportsIgnoreCheckers = assertNxSupportsIgnoreCheckers;
|
|
5
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
6
|
+
/**
|
|
7
|
+
* `@nx/devkit`'s `nx` peer spans a major either side, so an older nx that
|
|
8
|
+
* predates the ignore checkers can legally be installed alongside it, and a
|
|
9
|
+
* missing CommonJS named export arrives as `undefined` rather than as a load
|
|
10
|
+
* error. The two callers want opposite things from that, so they get different
|
|
11
|
+
* helpers - see `NOTHING_IGNORED` for the other half.
|
|
12
|
+
*
|
|
13
|
+
* A tree walk cannot degrade: without a checker nothing would be ignored, and
|
|
14
|
+
* the walker would descend into `node_modules` and hand a migration every file
|
|
15
|
+
* in it to rewrite. That is worse than the older nx's own behaviour, which at
|
|
16
|
+
* least read the root `.gitignore`, so this fails instead - once, by name.
|
|
17
|
+
*/
|
|
18
|
+
function assertNxSupportsIgnoreCheckers() {
|
|
19
|
+
if (devkit_internals_1.createGitIgnoreChecker) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
throw new Error('The installed version of nx does not export the ignore checkers that @nx/devkit needs to decide which files a generator may touch. ' +
|
|
23
|
+
'This happens when nx and @nx/devkit are on different major versions. Run `nx migrate latest` to bring them into line.');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The degrade the other way, for formatting.
|
|
27
|
+
*
|
|
28
|
+
* Filtering nothing is what devkit did before the checkers existed - with no
|
|
29
|
+
* `ignorePath`, prettier's own `getFileInfo` never read the workspace's ignore
|
|
30
|
+
* files either (measured) - so an older nx gets the formatting behaviour it has
|
|
31
|
+
* always had rather than a generator that refuses to run.
|
|
32
|
+
*/
|
|
33
|
+
exports.NOTHING_IGNORED = {
|
|
34
|
+
isIgnoredFile: () => false,
|
|
35
|
+
isIgnoredDirectory: () => false,
|
|
36
|
+
};
|
|
@@ -12,7 +12,8 @@ const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const semver_1 = require("semver");
|
|
14
14
|
const install_packages_task_1 = require("../tasks/install-packages-task");
|
|
15
|
-
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports -- nx/src/utils/catalog exists since nx 22.0.0, the whole supported range; swap to the nx/src/devkit-internals re-export in v25
|
|
16
|
+
const catalog_1 = require("nx/src/utils/catalog");
|
|
16
17
|
const UNIDENTIFIED_VERSION = 'UNIDENTIFIED_VERSION';
|
|
17
18
|
const NON_SEMVER_TAGS = {
|
|
18
19
|
'*': 2,
|
|
@@ -441,7 +442,11 @@ function ensurePackage(pkgOrTree, requiredVersionOrPackage, maybeRequiredVersion
|
|
|
441
442
|
return packageMapCache.get(pkg);
|
|
442
443
|
}
|
|
443
444
|
try {
|
|
444
|
-
|
|
445
|
+
// The workspace comes first so its installed version wins; `__dirname`
|
|
446
|
+
// keeps the old behaviour as a fallback. A bare `require` would only
|
|
447
|
+
// resolve from wherever `@nx/devkit` sits, which in a monorepo can be a
|
|
448
|
+
// different copy of the package than the workspace depends on.
|
|
449
|
+
return require(require.resolve(pkg, { paths: [devkit_exports_1.workspaceRoot, __dirname] }));
|
|
445
450
|
}
|
|
446
451
|
catch (e) {
|
|
447
452
|
if (e.code === 'ERR_REQUIRE_ESM') {
|
package/dist/src/utils/semver.js
CHANGED
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.checkAndCleanWithSemver = checkAndCleanWithSemver;
|
|
4
4
|
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
5
5
|
const semver_1 = require("semver");
|
|
6
|
-
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports -- nx/src/utils/catalog exists since nx 22.0.0, the whole supported range; swap to the nx/src/devkit-internals re-export in v25
|
|
7
|
+
const catalog_1 = require("nx/src/utils/catalog");
|
|
7
8
|
function checkAndCleanWithSemver(treeOrPkgName, pkgNameOrVersion, version) {
|
|
8
9
|
const tree = typeof treeOrPkgName === 'string' ? undefined : treeOrPkgName;
|
|
9
10
|
const root = tree?.root ?? devkit_exports_1.workspaceRoot;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Tree } from 'nx/src/devkit-exports';
|
|
2
2
|
/**
|
|
3
3
|
* Throws a standardized error when a package is installed at a version below
|
|
4
4
|
* a plugin's supported floor.
|
|
@@ -15,9 +15,21 @@ export declare function throwForUnsupportedVersion(packageName: string, installe
|
|
|
15
15
|
/**
|
|
16
16
|
* Asserts that a package detected in the workspace is at or above the
|
|
17
17
|
* plugin's supported floor. No-op when the package is not detected
|
|
18
|
-
* (fresh-install path) or when declared as `latest`/`next`.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* (fresh-install path) or when declared as `latest`/`next`.
|
|
19
|
+
*
|
|
20
|
+
* Resolution order:
|
|
21
|
+
* - When the installed version satisfies the declared range, the installed
|
|
22
|
+
* version decides. This resolves open ranges (e.g. `>=4.8.4 <6.1.0`) to
|
|
23
|
+
* what is actually installed.
|
|
24
|
+
* - An exact declared version is compared to the floor directly.
|
|
25
|
+
* - A declared range that cannot reach the floor throws as unsupported. A
|
|
26
|
+
* range that straddles the floor cannot be judged without an installed
|
|
27
|
+
* version (the lockfile may pin either side), so when none resolves it
|
|
28
|
+
* throws asking to install dependencies first.
|
|
29
|
+
*
|
|
30
|
+
* Prereleases count as their release version throughout (e.g. `6.0.0-rc.1`
|
|
31
|
+
* as `6.0.0`), for installed versions, exact declared versions, and range
|
|
32
|
+
* endpoints alike.
|
|
21
33
|
*
|
|
22
34
|
* Use from generator entry points to fail fast on unsupported workspaces
|
|
23
35
|
* before writing any incompatible config.
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.throwForUnsupportedVersion = throwForUnsupportedVersion;
|
|
4
4
|
exports.assertSupportedPackageVersion = assertSupportedPackageVersion;
|
|
5
5
|
exports.assertSupportedInstalledPackageVersion = assertSupportedInstalledPackageVersion;
|
|
6
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
7
|
const semver_1 = require("semver");
|
|
7
8
|
const installed_version_1 = require("./installed-version");
|
|
8
9
|
const package_json_1 = require("./package-json");
|
|
@@ -27,9 +28,21 @@ function throwForUnsupportedVersion(packageName, installedVersion, floor) {
|
|
|
27
28
|
/**
|
|
28
29
|
* Asserts that a package detected in the workspace is at or above the
|
|
29
30
|
* plugin's supported floor. No-op when the package is not detected
|
|
30
|
-
* (fresh-install path) or when declared as `latest`/`next`.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* (fresh-install path) or when declared as `latest`/`next`.
|
|
32
|
+
*
|
|
33
|
+
* Resolution order:
|
|
34
|
+
* - When the installed version satisfies the declared range, the installed
|
|
35
|
+
* version decides. This resolves open ranges (e.g. `>=4.8.4 <6.1.0`) to
|
|
36
|
+
* what is actually installed.
|
|
37
|
+
* - An exact declared version is compared to the floor directly.
|
|
38
|
+
* - A declared range that cannot reach the floor throws as unsupported. A
|
|
39
|
+
* range that straddles the floor cannot be judged without an installed
|
|
40
|
+
* version (the lockfile may pin either side), so when none resolves it
|
|
41
|
+
* throws asking to install dependencies first.
|
|
42
|
+
*
|
|
43
|
+
* Prereleases count as their release version throughout (e.g. `6.0.0-rc.1`
|
|
44
|
+
* as `6.0.0`), for installed versions, exact declared versions, and range
|
|
45
|
+
* endpoints alike.
|
|
33
46
|
*
|
|
34
47
|
* Use from generator entry points to fail fast on unsupported workspaces
|
|
35
48
|
* before writing any incompatible config.
|
|
@@ -39,11 +52,64 @@ function assertSupportedPackageVersion(tree, packageName, minSupportedVersion) {
|
|
|
39
52
|
if (!declared || (0, installed_version_1.isNonSemverDistTag)(declared)) {
|
|
40
53
|
return;
|
|
41
54
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
55
|
+
const installed = (0, installed_version_1.getInstalledPackageVersionFromTree)(tree, packageName) ??
|
|
56
|
+
getInstalledPackageVersionFromProcess(tree, packageName);
|
|
57
|
+
if (installed) {
|
|
58
|
+
// An installed prerelease can match the declared range in either form:
|
|
59
|
+
// raw (a same-tuple prerelease comparator) or as its release version.
|
|
60
|
+
const release = (0, semver_1.coerce)(installed)?.version ?? installed;
|
|
61
|
+
if ((0, semver_1.satisfies)(installed, declared) || (0, semver_1.satisfies)(release, declared)) {
|
|
62
|
+
if ((0, semver_1.lt)(release, minSupportedVersion)) {
|
|
63
|
+
throwForUnsupportedVersion(packageName, installed, minSupportedVersion);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const cleaned = (0, semver_1.clean)(declared);
|
|
69
|
+
if (cleaned) {
|
|
70
|
+
// Strip any prerelease so it counts as its release version.
|
|
71
|
+
const release = (0, semver_1.coerce)(cleaned)?.version ?? cleaned;
|
|
72
|
+
if ((0, semver_1.lt)(release, minSupportedVersion)) {
|
|
73
|
+
throwForUnsupportedVersion(packageName, declared, minSupportedVersion);
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if ((0, semver_1.validRange)(declared)) {
|
|
78
|
+
// The `-0` floor comparator admits prereleases of the floor version, so
|
|
79
|
+
// a range reaching the floor only through its prereleases still counts.
|
|
80
|
+
if (!(0, semver_1.intersects)(declared, `>=${minSupportedVersion}-0`)) {
|
|
81
|
+
throwForUnsupportedVersion(packageName, declared, minSupportedVersion);
|
|
82
|
+
}
|
|
83
|
+
const min = (0, semver_1.minVersion)(declared);
|
|
84
|
+
const rangeMinimum = min ? `${min.major}.${min.minor}.${min.patch}` : null;
|
|
85
|
+
if (rangeMinimum && (0, semver_1.lt)(rangeMinimum, minSupportedVersion)) {
|
|
86
|
+
throw new Error(`Unable to determine the installed version of \`${packageName}\`.\n\n` +
|
|
87
|
+
` Declared: ${declared}\n` +
|
|
88
|
+
` Supported: >= ${minSupportedVersion}\n\n` +
|
|
89
|
+
`The declared range allows versions below the supported minimum. ` +
|
|
90
|
+
`Install the workspace dependencies so the installed version can be verified, then try again.`);
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const coerced = (0, semver_1.coerce)(declared)?.version;
|
|
95
|
+
if (coerced && (0, semver_1.lt)(coerced, minSupportedVersion)) {
|
|
44
96
|
throwForUnsupportedVersion(packageName, declared, minSupportedVersion);
|
|
45
97
|
}
|
|
46
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Module-resolution fallback for installs without a `node_modules` layout
|
|
101
|
+
* (e.g. Yarn PnP). Only valid when the tree is the running process's
|
|
102
|
+
* workspace; unit trees (e.g. rooted at `/virtual`) must not resolve
|
|
103
|
+
* packages from the process environment. Resolves from the workspace root
|
|
104
|
+
* only, so a copy hoisted into `.nx/installation` cannot shadow the
|
|
105
|
+
* workspace's own install.
|
|
106
|
+
*/
|
|
107
|
+
function getInstalledPackageVersionFromProcess(tree, packageName) {
|
|
108
|
+
if (tree.root !== devkit_exports_1.workspaceRoot) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return (0, installed_version_1.getInstalledPackageVersion)(packageName, [tree.root]);
|
|
112
|
+
}
|
|
47
113
|
/**
|
|
48
114
|
* Asserts that a package installed in the workspace is at or above the
|
|
49
115
|
* plugin's supported floor. No-op when the package is not resolvable from
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/devkit",
|
|
3
|
-
"version": "23.1.
|
|
3
|
+
"version": "23.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -40,6 +40,15 @@
|
|
|
40
40
|
],
|
|
41
41
|
"internal-testing-utils": [
|
|
42
42
|
"dist/internal-testing-utils.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"internal-testing-utils/mock-project-graph": [
|
|
45
|
+
"dist/internal-testing-utils/mock-project-graph.d.ts"
|
|
46
|
+
],
|
|
47
|
+
"internal-testing-utils/mock-fs": [
|
|
48
|
+
"dist/internal-testing-utils/mock-fs.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"internal-testing-utils/mock-prettier": [
|
|
51
|
+
"dist/internal-testing-utils/mock-prettier.d.ts"
|
|
43
52
|
]
|
|
44
53
|
}
|
|
45
54
|
},
|
|
@@ -50,18 +59,16 @@
|
|
|
50
59
|
},
|
|
51
60
|
"homepage": "https://nx.dev",
|
|
52
61
|
"dependencies": {
|
|
53
|
-
"@zkochan/js-yaml": "0.0.7",
|
|
54
62
|
"ejs": "5.0.1",
|
|
55
63
|
"tslib": "^2.3.0",
|
|
56
64
|
"semver": "^7.6.3",
|
|
57
65
|
"yargs-parser": "21.1.1",
|
|
58
66
|
"minimatch": "10.2.5",
|
|
59
|
-
"enquirer": "~2.3.6"
|
|
60
|
-
"yaml": "^2.8.3"
|
|
67
|
+
"enquirer": "~2.3.6"
|
|
61
68
|
},
|
|
62
69
|
"devDependencies": {
|
|
63
70
|
"jest": "30.3.0",
|
|
64
|
-
"nx": "23.1.
|
|
71
|
+
"nx": "23.1.2"
|
|
65
72
|
},
|
|
66
73
|
"peerDependencies": {
|
|
67
74
|
"nx": ">= 22 <= 24 || ^23.0.0-0"
|
|
@@ -91,6 +98,21 @@
|
|
|
91
98
|
"types": "./dist/internal-testing-utils.d.ts",
|
|
92
99
|
"default": "./dist/internal-testing-utils.js"
|
|
93
100
|
},
|
|
101
|
+
"./internal-testing-utils/mock-project-graph": {
|
|
102
|
+
"@nx/nx-source": "./internal-testing-utils/mock-project-graph.ts",
|
|
103
|
+
"types": "./dist/internal-testing-utils/mock-project-graph.d.ts",
|
|
104
|
+
"default": "./dist/internal-testing-utils/mock-project-graph.js"
|
|
105
|
+
},
|
|
106
|
+
"./internal-testing-utils/mock-fs": {
|
|
107
|
+
"@nx/nx-source": "./internal-testing-utils/mock-fs.ts",
|
|
108
|
+
"types": "./dist/internal-testing-utils/mock-fs.d.ts",
|
|
109
|
+
"default": "./dist/internal-testing-utils/mock-fs.js"
|
|
110
|
+
},
|
|
111
|
+
"./internal-testing-utils/mock-prettier": {
|
|
112
|
+
"@nx/nx-source": "./internal-testing-utils/mock-prettier.ts",
|
|
113
|
+
"types": "./dist/internal-testing-utils/mock-prettier.d.ts",
|
|
114
|
+
"default": "./dist/internal-testing-utils/mock-prettier.js"
|
|
115
|
+
},
|
|
94
116
|
"./ngcli-adapter": {
|
|
95
117
|
"@nx/nx-source": "./ngcli-adapter.ts",
|
|
96
118
|
"types": "./dist/ngcli-adapter.d.ts",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Tree } from 'nx/src/devkit-exports';
|
|
2
|
-
import { getCatalogManager } from './manager-factory';
|
|
3
|
-
import type { CatalogManager } from './manager';
|
|
4
|
-
export { type CatalogManager, getCatalogManager };
|
|
5
|
-
/**
|
|
6
|
-
* Detects which packages in a package.json use catalog references
|
|
7
|
-
* Returns Map of package name -> catalog name (undefined for default catalog)
|
|
8
|
-
*/
|
|
9
|
-
export declare function getCatalogDependenciesFromPackageJson(tree: Tree, packageJsonPath: string, manager: CatalogManager): Map<string, string | undefined>;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCatalogManager = void 0;
|
|
4
|
-
exports.getCatalogDependenciesFromPackageJson = getCatalogDependenciesFromPackageJson;
|
|
5
|
-
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
|
-
const manager_factory_1 = require("./manager-factory");
|
|
7
|
-
Object.defineProperty(exports, "getCatalogManager", { enumerable: true, get: function () { return manager_factory_1.getCatalogManager; } });
|
|
8
|
-
/**
|
|
9
|
-
* Detects which packages in a package.json use catalog references
|
|
10
|
-
* Returns Map of package name -> catalog name (undefined for default catalog)
|
|
11
|
-
*/
|
|
12
|
-
function getCatalogDependenciesFromPackageJson(tree, packageJsonPath, manager) {
|
|
13
|
-
const catalogDeps = new Map();
|
|
14
|
-
if (!tree.exists(packageJsonPath)) {
|
|
15
|
-
return catalogDeps;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const packageJson = (0, devkit_exports_1.readJson)(tree, packageJsonPath);
|
|
19
|
-
const allDependencies = {
|
|
20
|
-
...packageJson.dependencies,
|
|
21
|
-
...packageJson.devDependencies,
|
|
22
|
-
...packageJson.peerDependencies,
|
|
23
|
-
...packageJson.optionalDependencies,
|
|
24
|
-
};
|
|
25
|
-
for (const [packageName, version] of Object.entries(allDependencies || {})) {
|
|
26
|
-
if (manager.isCatalogReference(version)) {
|
|
27
|
-
const catalogRef = manager.parseCatalogReference(version);
|
|
28
|
-
if (catalogRef) {
|
|
29
|
-
catalogDeps.set(packageName, catalogRef.catalogName);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
// If we can't read the package.json, return empty map
|
|
36
|
-
}
|
|
37
|
-
return catalogDeps;
|
|
38
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCatalogManager = getCatalogManager;
|
|
4
|
-
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
5
|
-
const pnpm_manager_1 = require("./pnpm-manager");
|
|
6
|
-
const yarn_manager_1 = require("./yarn-manager");
|
|
7
|
-
/**
|
|
8
|
-
* Factory function to get the appropriate catalog manager based on the package manager
|
|
9
|
-
*/
|
|
10
|
-
function getCatalogManager(workspaceRoot) {
|
|
11
|
-
const packageManager = (0, devkit_exports_1.detectPackageManager)(workspaceRoot);
|
|
12
|
-
switch (packageManager) {
|
|
13
|
-
case 'pnpm':
|
|
14
|
-
return new pnpm_manager_1.PnpmCatalogManager();
|
|
15
|
-
case 'yarn':
|
|
16
|
-
return new yarn_manager_1.YarnCatalogManager();
|
|
17
|
-
default:
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Tree } from 'nx/src/devkit-exports';
|
|
2
|
-
import type { CatalogDefinitions } from './types';
|
|
3
|
-
export declare function readCatalogConfigFromFs(filename: string, fullPath: string): CatalogDefinitions | null;
|
|
4
|
-
export declare function readCatalogConfigFromTree(filename: string, tree: Tree): CatalogDefinitions | null;
|
|
5
|
-
export declare function updateCatalogVersionsInFile(filename: string, treeOrRoot: Tree | string, updates: Array<{
|
|
6
|
-
packageName: string;
|
|
7
|
-
version: string;
|
|
8
|
-
catalogName?: string;
|
|
9
|
-
}>): void;
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readCatalogConfigFromFs = readCatalogConfigFromFs;
|
|
4
|
-
exports.readCatalogConfigFromTree = readCatalogConfigFromTree;
|
|
5
|
-
exports.updateCatalogVersionsInFile = updateCatalogVersionsInFile;
|
|
6
|
-
// Keep in sync with packages/nx/src/utils/catalog/manager-utils.ts; the body below
|
|
7
|
-
// the imports is duplicated because @nx/devkit supports a range of nx majors and
|
|
8
|
-
// this logic isn't part of the nx surface it can import across that range.
|
|
9
|
-
const js_yaml_1 = require("@zkochan/js-yaml");
|
|
10
|
-
const node_fs_1 = require("node:fs");
|
|
11
|
-
const node_path_1 = require("node:path");
|
|
12
|
-
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
13
|
-
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
14
|
-
const yaml_1 = require("yaml");
|
|
15
|
-
// Walks `path` resolving aliases at every step so structural checks can
|
|
16
|
-
// see through `key: *anchor` references. Neither `doc.getIn` nor
|
|
17
|
-
// `doc.hasIn` traverse aliases on their own. Returns the resolved node, or
|
|
18
|
-
// `undefined` if any ancestor isn't a map.
|
|
19
|
-
function resolveAt(doc, path) {
|
|
20
|
-
let node = doc.contents;
|
|
21
|
-
for (let i = 0; i < path.length; i++) {
|
|
22
|
-
if ((0, yaml_1.isAlias)(node))
|
|
23
|
-
node = node.resolve(doc);
|
|
24
|
-
if (!(0, yaml_1.isMap)(node))
|
|
25
|
-
return undefined;
|
|
26
|
-
node = node.get(path[i], true);
|
|
27
|
-
}
|
|
28
|
-
if ((0, yaml_1.isAlias)(node))
|
|
29
|
-
node = node.resolve(doc);
|
|
30
|
-
return node;
|
|
31
|
-
}
|
|
32
|
-
function isMapAt(doc, path) {
|
|
33
|
-
return (0, yaml_1.isMap)(resolveAt(doc, path));
|
|
34
|
-
}
|
|
35
|
-
function existsAt(doc, path) {
|
|
36
|
-
return resolveAt(doc, path) !== undefined;
|
|
37
|
-
}
|
|
38
|
-
// `doc.getIn` does not traverse aliases. For aliased paths it returns
|
|
39
|
-
// undefined even when the resolved node has a value. Use the alias-aware
|
|
40
|
-
// walk and unwrap scalar nodes to their JS value.
|
|
41
|
-
function getValueAt(doc, path) {
|
|
42
|
-
const node = resolveAt(doc, path);
|
|
43
|
-
return (0, yaml_1.isScalar)(node) ? node.value : node;
|
|
44
|
-
}
|
|
45
|
-
// Walks `targetPath` resolving aliases at every step and mutates the
|
|
46
|
-
// resolved map directly so anchors are preserved. When a step is missing
|
|
47
|
-
// or holds a null placeholder (`key:` with no value), creates a fresh map
|
|
48
|
-
// inside the current parent and carries over the placeholder's comments
|
|
49
|
-
// and anchor so they aren't dropped. A dropped anchor would leave any
|
|
50
|
-
// alias referencing it unresolved and make `String(doc)` throw. Falls back
|
|
51
|
-
// to `doc.setIn` when the current parent isn't a map: an empty-document
|
|
52
|
-
// root gets bootstrapped, while a non-map value where a catalog map was
|
|
53
|
-
// expected makes `setIn` throw, surfacing the malformed config.
|
|
54
|
-
function setThroughAliases(doc, targetPath, value) {
|
|
55
|
-
let parent = doc.contents;
|
|
56
|
-
if ((0, yaml_1.isAlias)(parent))
|
|
57
|
-
parent = parent.resolve(doc);
|
|
58
|
-
for (let i = 0; i < targetPath.length - 1; i++) {
|
|
59
|
-
if (!(0, yaml_1.isMap)(parent)) {
|
|
60
|
-
doc.setIn(targetPath, value);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
let next = parent.get(targetPath[i], true);
|
|
64
|
-
const nextWasAlias = (0, yaml_1.isAlias)(next);
|
|
65
|
-
if ((0, yaml_1.isAlias)(next))
|
|
66
|
-
next = next.resolve(doc);
|
|
67
|
-
const placeholder = (0, yaml_1.isScalar)(next) && next.value === null ? next : undefined;
|
|
68
|
-
if (next === undefined || placeholder) {
|
|
69
|
-
let cur = parent;
|
|
70
|
-
for (let j = i; j < targetPath.length - 1; j++) {
|
|
71
|
-
const fresh = new yaml_1.YAMLMap();
|
|
72
|
-
if (j === i && placeholder) {
|
|
73
|
-
if (placeholder.comment)
|
|
74
|
-
fresh.comment = placeholder.comment;
|
|
75
|
-
if (placeholder.commentBefore)
|
|
76
|
-
fresh.commentBefore = placeholder.commentBefore;
|
|
77
|
-
// Copy the anchor only for a directly-held placeholder. When it
|
|
78
|
-
// was reached through an alias, the anchor still lives on the
|
|
79
|
-
// definition node, so re-emitting it here would duplicate it.
|
|
80
|
-
if (!nextWasAlias && placeholder.anchor)
|
|
81
|
-
fresh.anchor = placeholder.anchor;
|
|
82
|
-
}
|
|
83
|
-
cur.set(targetPath[j], fresh);
|
|
84
|
-
cur = fresh;
|
|
85
|
-
}
|
|
86
|
-
cur.set(targetPath[targetPath.length - 1], value);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
parent = next;
|
|
90
|
-
}
|
|
91
|
-
if (!(0, yaml_1.isMap)(parent)) {
|
|
92
|
-
doc.setIn(targetPath, value);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
parent.set(targetPath[targetPath.length - 1], value);
|
|
96
|
-
}
|
|
97
|
-
function readCatalogConfigFromFs(filename, fullPath) {
|
|
98
|
-
try {
|
|
99
|
-
return (0, devkit_internals_1.readYamlFile)(fullPath);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
devkit_exports_1.output.warn({
|
|
103
|
-
title: `Unable to parse ${filename}`,
|
|
104
|
-
bodyLines: [error.toString()],
|
|
105
|
-
});
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function readCatalogConfigFromTree(filename, tree) {
|
|
110
|
-
const content = tree.read(filename, 'utf-8');
|
|
111
|
-
try {
|
|
112
|
-
return (0, js_yaml_1.load)(content, { filename });
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
devkit_exports_1.output.warn({
|
|
116
|
-
title: `Unable to parse ${filename}`,
|
|
117
|
-
bodyLines: [error.toString()],
|
|
118
|
-
});
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function updateCatalogVersionsInFile(filename, treeOrRoot, updates) {
|
|
123
|
-
let checkExists;
|
|
124
|
-
let readYaml;
|
|
125
|
-
let writeYaml;
|
|
126
|
-
if (typeof treeOrRoot === 'string') {
|
|
127
|
-
const configPath = (0, node_path_1.join)(treeOrRoot, filename);
|
|
128
|
-
checkExists = () => (0, node_fs_1.existsSync)(configPath);
|
|
129
|
-
readYaml = () => (0, node_fs_1.readFileSync)(configPath, 'utf-8');
|
|
130
|
-
writeYaml = (content) => (0, node_fs_1.writeFileSync)(configPath, content, 'utf-8');
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
checkExists = () => treeOrRoot.exists(filename);
|
|
134
|
-
readYaml = () => treeOrRoot.read(filename, 'utf-8');
|
|
135
|
-
writeYaml = (content) => treeOrRoot.write(filename, content);
|
|
136
|
-
}
|
|
137
|
-
if (!checkExists()) {
|
|
138
|
-
devkit_exports_1.output.warn({
|
|
139
|
-
title: `No ${filename} found`,
|
|
140
|
-
bodyLines: [
|
|
141
|
-
`Cannot update catalog versions without a ${filename} file.`,
|
|
142
|
-
`Create a ${filename} file to use catalogs.`,
|
|
143
|
-
],
|
|
144
|
-
});
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
// parseDocument keeps comments and anchors so a catalog bump doesn't
|
|
149
|
-
// rewrite the user's config file.
|
|
150
|
-
const lineCounter = new yaml_1.LineCounter();
|
|
151
|
-
const doc = (0, yaml_1.parseDocument)(readYaml(), { lineCounter });
|
|
152
|
-
// parseDocument collects syntax errors instead of throwing; surface them
|
|
153
|
-
// now, with their line/column detail, rather than failing later in
|
|
154
|
-
// `String(doc)` with a generic message or skipping a no-op write on a
|
|
155
|
-
// malformed file (the previous js-yaml `load()` threw here).
|
|
156
|
-
if (doc.errors.length > 0) {
|
|
157
|
-
throw new Error(doc.errors.map((e) => e.message).join('\n'));
|
|
158
|
-
}
|
|
159
|
-
// A dangling alias (`*ref` with no matching `&ref`) is not a syntax error,
|
|
160
|
-
// so parseDocument leaves it out of doc.errors. Surface it here with the
|
|
161
|
-
// same line/column detail the old js-yaml `load()` reported; otherwise a
|
|
162
|
-
// broken reference is silently overwritten or written back untouched.
|
|
163
|
-
const unresolvedAliases = [];
|
|
164
|
-
(0, yaml_1.visit)(doc, {
|
|
165
|
-
Alias(_key, node) {
|
|
166
|
-
if (node.resolve(doc) !== undefined)
|
|
167
|
-
return;
|
|
168
|
-
const pos = node.range ? lineCounter.linePos(node.range[0]) : undefined;
|
|
169
|
-
unresolvedAliases.push(pos
|
|
170
|
-
? `Unresolved alias "${node.source}" at line ${pos.line}, column ${pos.col}`
|
|
171
|
-
: `Unresolved alias "${node.source}"`);
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
if (unresolvedAliases.length > 0) {
|
|
175
|
-
throw new Error(unresolvedAliases.join('\n'));
|
|
176
|
-
}
|
|
177
|
-
let hasChanges = false;
|
|
178
|
-
for (const update of updates) {
|
|
179
|
-
const { packageName, version, catalogName } = update;
|
|
180
|
-
const normalizedCatalogName = catalogName === 'default' ? undefined : catalogName;
|
|
181
|
-
let targetPath;
|
|
182
|
-
if (!normalizedCatalogName) {
|
|
183
|
-
// An empty `catalog:` placeholder must not claim the default route
|
|
184
|
-
// when `catalogs.default` is populated; that would create a
|
|
185
|
-
// duplicate-default config rejected by pnpm.
|
|
186
|
-
if (isMapAt(doc, ['catalog'])) {
|
|
187
|
-
targetPath = ['catalog', packageName];
|
|
188
|
-
}
|
|
189
|
-
else if (existsAt(doc, ['catalogs', 'default'])) {
|
|
190
|
-
targetPath = ['catalogs', 'default', packageName];
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
targetPath = ['catalog', packageName];
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
targetPath = ['catalogs', normalizedCatalogName, packageName];
|
|
198
|
-
}
|
|
199
|
-
if (getValueAt(doc, targetPath) !== version) {
|
|
200
|
-
setThroughAliases(doc, targetPath, version);
|
|
201
|
-
hasChanges = true;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (hasChanges) {
|
|
205
|
-
writeYaml(String(doc));
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
devkit_exports_1.output.error({
|
|
210
|
-
title: 'Failed to update catalog versions',
|
|
211
|
-
bodyLines: [error instanceof Error ? error.message : String(error)],
|
|
212
|
-
});
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Tree } from 'nx/src/devkit-exports';
|
|
2
|
-
import type { CatalogDefinitions, CatalogReference } from './types';
|
|
3
|
-
export declare function formatCatalogError(error: string, suggestions: string[]): string;
|
|
4
|
-
/**
|
|
5
|
-
* Interface for catalog managers that handle package manager-specific catalog implementations.
|
|
6
|
-
*/
|
|
7
|
-
export interface CatalogManager {
|
|
8
|
-
readonly name: string;
|
|
9
|
-
isCatalogReference(version: string): boolean;
|
|
10
|
-
parseCatalogReference(version: string): CatalogReference | null;
|
|
11
|
-
getCatalogDefinitionFilePaths(): string[];
|
|
12
|
-
/**
|
|
13
|
-
* Get catalog definitions from the workspace.
|
|
14
|
-
*/
|
|
15
|
-
getCatalogDefinitions(workspaceRoot: string): CatalogDefinitions | null;
|
|
16
|
-
getCatalogDefinitions(tree: Tree): CatalogDefinitions | null;
|
|
17
|
-
/**
|
|
18
|
-
* Resolve a catalog reference to an actual version.
|
|
19
|
-
*/
|
|
20
|
-
resolveCatalogReference(workspaceRoot: string, packageName: string, version: string): string | null;
|
|
21
|
-
resolveCatalogReference(tree: Tree, packageName: string, version: string): string | null;
|
|
22
|
-
/**
|
|
23
|
-
* Check that a catalog reference is valid.
|
|
24
|
-
*/
|
|
25
|
-
validateCatalogReference(workspaceRoot: string, packageName: string, version: string): void;
|
|
26
|
-
validateCatalogReference(tree: Tree, packageName: string, version: string): void;
|
|
27
|
-
/**
|
|
28
|
-
* Updates catalog definitions for specified packages in their respective catalogs.
|
|
29
|
-
*/
|
|
30
|
-
updateCatalogVersions(tree: Tree, updates: Array<{
|
|
31
|
-
packageName: string;
|
|
32
|
-
version: string;
|
|
33
|
-
catalogName?: string;
|
|
34
|
-
}>): void;
|
|
35
|
-
updateCatalogVersions(workspaceRoot: string, updates: Array<{
|
|
36
|
-
packageName: string;
|
|
37
|
-
version: string;
|
|
38
|
-
catalogName?: string;
|
|
39
|
-
}>): void;
|
|
40
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatCatalogError = formatCatalogError;
|
|
4
|
-
function formatCatalogError(error, suggestions) {
|
|
5
|
-
let message = error;
|
|
6
|
-
if (suggestions.length > 0) {
|
|
7
|
-
message += '\n\nSuggestions:';
|
|
8
|
-
suggestions.forEach((suggestion) => {
|
|
9
|
-
message += `\n • ${suggestion}`;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
return message;
|
|
13
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type Tree } from 'nx/src/devkit-exports';
|
|
2
|
-
import { type CatalogManager } from './manager';
|
|
3
|
-
import type { CatalogDefinitions, CatalogReference } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* PNPM-specific catalog manager implementation
|
|
6
|
-
*/
|
|
7
|
-
export declare class PnpmCatalogManager implements CatalogManager {
|
|
8
|
-
readonly name = "pnpm";
|
|
9
|
-
readonly catalogProtocol = "catalog:";
|
|
10
|
-
isCatalogReference(version: string): boolean;
|
|
11
|
-
parseCatalogReference(version: string): CatalogReference | null;
|
|
12
|
-
getCatalogDefinitionFilePaths(): string[];
|
|
13
|
-
getCatalogDefinitions(treeOrRoot: Tree | string): CatalogDefinitions | null;
|
|
14
|
-
resolveCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): string | null;
|
|
15
|
-
validateCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): void;
|
|
16
|
-
updateCatalogVersions(treeOrRoot: Tree | string, updates: Array<{
|
|
17
|
-
packageName: string;
|
|
18
|
-
version: string;
|
|
19
|
-
catalogName?: string;
|
|
20
|
-
}>): void;
|
|
21
|
-
}
|