@nx/devkit 19.4.0-beta.1 → 19.4.0-beta.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/package.json +2 -2
- package/src/generators/plugin-migrations/aggregate-log-util.js +3 -0
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.d.ts +19 -6
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +150 -96
- package/src/generators/plugin-migrations/plugin-migration-utils.d.ts +2 -1
- package/src/generators/plugin-migrations/plugin-migration-utils.js +13 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/devkit",
|
3
|
-
"version": "19.4.0-beta.
|
3
|
+
"version": "19.4.0-beta.2",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.",
|
6
6
|
"repository": {
|
@@ -36,7 +36,7 @@
|
|
36
36
|
"semver": "^7.5.3",
|
37
37
|
"yargs-parser": "21.1.1",
|
38
38
|
"minimatch": "9.0.3",
|
39
|
-
"@nrwl/devkit": "19.4.0-beta.
|
39
|
+
"@nrwl/devkit": "19.4.0-beta.2"
|
40
40
|
},
|
41
41
|
"peerDependencies": {
|
42
42
|
"nx": ">= 17 <= 20"
|
@@ -34,6 +34,9 @@ class AggregatedLog {
|
|
34
34
|
this.logs.clear();
|
35
35
|
}
|
36
36
|
flushLogs() {
|
37
|
+
if (this.logs.size === 0) {
|
38
|
+
return;
|
39
|
+
}
|
37
40
|
let fullLog = '';
|
38
41
|
for (const executorName of this.logs.keys()) {
|
39
42
|
fullLog = `${fullLog}${devkit_exports_1.output.bold(`Encountered the following while migrating '${executorName}':\r\n`)}`;
|
@@ -1,10 +1,23 @@
|
|
1
|
-
import {
|
2
|
-
type
|
1
|
+
import type { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';
|
2
|
+
import { type CreateNodes, type CreateNodesV2, type ProjectGraph, type TargetConfiguration, type Tree } from 'nx/src/devkit-exports';
|
3
3
|
type PostTargetTransformer = (targetConfiguration: TargetConfiguration, tree: Tree, projectDetails: {
|
4
4
|
projectName: string;
|
5
5
|
root: string;
|
6
|
-
}, inferredTargetConfiguration: TargetConfiguration) => TargetConfiguration
|
7
|
-
type SkipTargetFilter = (targetConfiguration: TargetConfiguration) =>
|
8
|
-
|
9
|
-
export declare function
|
6
|
+
}, inferredTargetConfiguration: TargetConfiguration) => TargetConfiguration | Promise<TargetConfiguration>;
|
7
|
+
type SkipTargetFilter = (targetConfiguration: TargetConfiguration) => false | string;
|
8
|
+
type SkipProjectFilter = (projectConfiguration: ProjectConfiguration) => false | string;
|
9
|
+
export declare function migrateProjectExecutorsToPlugin<T>(tree: Tree, projectGraph: ProjectGraph, pluginPath: string, createNodesV2: CreateNodesV2<T>, defaultPluginOptions: T, migrations: Array<{
|
10
|
+
executors: string[];
|
11
|
+
targetPluginOptionMapper: (targetName: string) => Partial<T>;
|
12
|
+
postTargetTransformer: PostTargetTransformer;
|
13
|
+
skipProjectFilter?: SkipProjectFilter;
|
14
|
+
skipTargetFilter?: SkipTargetFilter;
|
15
|
+
}>, specificProjectToMigrate?: string): Promise<Map<string, Record<string, string>>>;
|
16
|
+
export declare function migrateProjectExecutorsToPluginV1<T>(tree: Tree, projectGraph: ProjectGraph, pluginPath: string, createNodes: CreateNodes<T>, defaultPluginOptions: T, migrations: Array<{
|
17
|
+
executors: string[];
|
18
|
+
targetPluginOptionMapper: (targetName: string) => Partial<T>;
|
19
|
+
postTargetTransformer: PostTargetTransformer;
|
20
|
+
skipProjectFilter?: SkipProjectFilter;
|
21
|
+
skipTargetFilter?: SkipTargetFilter;
|
22
|
+
}>, specificProjectToMigrate?: string): Promise<Map<string, Record<string, string>>>;
|
10
23
|
export {};
|
@@ -1,16 +1,16 @@
|
|
1
1
|
"use strict";
|
2
|
-
var _ExecutorToPluginMigrator_instances, _ExecutorToPluginMigrator_projectGraph, _ExecutorToPluginMigrator_executor, _ExecutorToPluginMigrator_pluginPath, _ExecutorToPluginMigrator_pluginOptionsBuilder, _ExecutorToPluginMigrator_postTargetTransformer, _ExecutorToPluginMigrator_skipTargetFilter, _ExecutorToPluginMigrator_specificProjectToMigrate, _ExecutorToPluginMigrator_nxJson, _ExecutorToPluginMigrator_targetDefaultsForExecutor, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, _ExecutorToPluginMigrator_pluginToAddForTarget, _ExecutorToPluginMigrator_createNodes, _ExecutorToPluginMigrator_createNodesV2, _ExecutorToPluginMigrator_createNodesResultsForTargets, _ExecutorToPluginMigrator_init, _ExecutorToPluginMigrator_migrateTarget, _ExecutorToPluginMigrator_migrateProject, _ExecutorToPluginMigrator_mergeInputs,
|
2
|
+
var _ExecutorToPluginMigrator_instances, _ExecutorToPluginMigrator_projectGraph, _ExecutorToPluginMigrator_executor, _ExecutorToPluginMigrator_pluginPath, _ExecutorToPluginMigrator_pluginOptionsBuilder, _ExecutorToPluginMigrator_postTargetTransformer, _ExecutorToPluginMigrator_skipTargetFilter, _ExecutorToPluginMigrator_skipProjectFilter, _ExecutorToPluginMigrator_specificProjectToMigrate, _ExecutorToPluginMigrator_nxJson, _ExecutorToPluginMigrator_targetDefaultsForExecutor, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, _ExecutorToPluginMigrator_pluginToAddForTarget, _ExecutorToPluginMigrator_createNodes, _ExecutorToPluginMigrator_createNodesV2, _ExecutorToPluginMigrator_createNodesResultsForTargets, _ExecutorToPluginMigrator_skippedProjects, _ExecutorToPluginMigrator_init, _ExecutorToPluginMigrator_migrateTarget, _ExecutorToPluginMigrator_migrateProject, _ExecutorToPluginMigrator_mergeInputs, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot, _ExecutorToPluginMigrator_getCreateNodesResults;
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.
|
4
|
+
exports.migrateProjectExecutorsToPluginV1 = exports.migrateProjectExecutorsToPlugin = void 0;
|
5
5
|
const tslib_1 = require("tslib");
|
6
6
|
const minimatch_1 = require("minimatch");
|
7
7
|
const node_assert_1 = require("node:assert");
|
8
|
-
const executor_options_utils_1 = require("../executor-options-utils");
|
9
|
-
const plugin_migration_utils_1 = require("./plugin-migration-utils");
|
10
8
|
const devkit_exports_1 = require("nx/src/devkit-exports");
|
11
9
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
10
|
+
const executor_options_utils_1 = require("../executor-options-utils");
|
11
|
+
const plugin_migration_utils_1 = require("./plugin-migration-utils");
|
12
12
|
class ExecutorToPluginMigrator {
|
13
|
-
constructor(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, createNodesV2, specificProjectToMigrate,
|
13
|
+
constructor(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, createNodesV2, specificProjectToMigrate, filters) {
|
14
14
|
_ExecutorToPluginMigrator_instances.add(this);
|
15
15
|
_ExecutorToPluginMigrator_projectGraph.set(this, void 0);
|
16
16
|
_ExecutorToPluginMigrator_executor.set(this, void 0);
|
@@ -18,6 +18,7 @@ class ExecutorToPluginMigrator {
|
|
18
18
|
_ExecutorToPluginMigrator_pluginOptionsBuilder.set(this, void 0);
|
19
19
|
_ExecutorToPluginMigrator_postTargetTransformer.set(this, void 0);
|
20
20
|
_ExecutorToPluginMigrator_skipTargetFilter.set(this, void 0);
|
21
|
+
_ExecutorToPluginMigrator_skipProjectFilter.set(this, void 0);
|
21
22
|
_ExecutorToPluginMigrator_specificProjectToMigrate.set(this, void 0);
|
22
23
|
_ExecutorToPluginMigrator_nxJson.set(this, void 0);
|
23
24
|
_ExecutorToPluginMigrator_targetDefaultsForExecutor.set(this, void 0);
|
@@ -26,6 +27,7 @@ class ExecutorToPluginMigrator {
|
|
26
27
|
_ExecutorToPluginMigrator_createNodes.set(this, void 0);
|
27
28
|
_ExecutorToPluginMigrator_createNodesV2.set(this, void 0);
|
28
29
|
_ExecutorToPluginMigrator_createNodesResultsForTargets.set(this, void 0);
|
30
|
+
_ExecutorToPluginMigrator_skippedProjects.set(this, void 0);
|
29
31
|
this.tree = tree;
|
30
32
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_projectGraph, projectGraph, "f");
|
31
33
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_executor, executor, "f");
|
@@ -35,40 +37,41 @@ class ExecutorToPluginMigrator {
|
|
35
37
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodes, createNodes, "f");
|
36
38
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodesV2, createNodesV2, "f");
|
37
39
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, specificProjectToMigrate, "f");
|
38
|
-
tslib_1.__classPrivateFieldSet(this,
|
40
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_skipProjectFilter, filters?.skipProjectFilter ?? ((...args) => false), "f");
|
41
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_skipTargetFilter, filters?.skipTargetFilter ?? ((...args) => false), "f");
|
39
42
|
}
|
40
43
|
async run() {
|
41
44
|
await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_init).call(this);
|
42
45
|
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").size > 0) {
|
43
46
|
for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
|
44
|
-
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateTarget).call(this, targetName);
|
47
|
+
await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateTarget).call(this, targetName);
|
45
48
|
}
|
46
|
-
await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_addPlugins).call(this);
|
47
49
|
}
|
48
50
|
return tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f");
|
49
51
|
}
|
50
52
|
}
|
51
|
-
_ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrator_executor = new WeakMap(), _ExecutorToPluginMigrator_pluginPath = new WeakMap(), _ExecutorToPluginMigrator_pluginOptionsBuilder = new WeakMap(), _ExecutorToPluginMigrator_postTargetTransformer = new WeakMap(), _ExecutorToPluginMigrator_skipTargetFilter = new WeakMap(), _ExecutorToPluginMigrator_specificProjectToMigrate = new WeakMap(), _ExecutorToPluginMigrator_nxJson = new WeakMap(), _ExecutorToPluginMigrator_targetDefaultsForExecutor = new WeakMap(), _ExecutorToPluginMigrator_targetAndProjectsToMigrate = new WeakMap(), _ExecutorToPluginMigrator_pluginToAddForTarget = new WeakMap(), _ExecutorToPluginMigrator_createNodes = new WeakMap(), _ExecutorToPluginMigrator_createNodesV2 = new WeakMap(), _ExecutorToPluginMigrator_createNodesResultsForTargets = new WeakMap(), _ExecutorToPluginMigrator_instances = new WeakSet(), _ExecutorToPluginMigrator_init = async function _ExecutorToPluginMigrator_init() {
|
53
|
+
_ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrator_executor = new WeakMap(), _ExecutorToPluginMigrator_pluginPath = new WeakMap(), _ExecutorToPluginMigrator_pluginOptionsBuilder = new WeakMap(), _ExecutorToPluginMigrator_postTargetTransformer = new WeakMap(), _ExecutorToPluginMigrator_skipTargetFilter = new WeakMap(), _ExecutorToPluginMigrator_skipProjectFilter = new WeakMap(), _ExecutorToPluginMigrator_specificProjectToMigrate = new WeakMap(), _ExecutorToPluginMigrator_nxJson = new WeakMap(), _ExecutorToPluginMigrator_targetDefaultsForExecutor = new WeakMap(), _ExecutorToPluginMigrator_targetAndProjectsToMigrate = new WeakMap(), _ExecutorToPluginMigrator_pluginToAddForTarget = new WeakMap(), _ExecutorToPluginMigrator_createNodes = new WeakMap(), _ExecutorToPluginMigrator_createNodesV2 = new WeakMap(), _ExecutorToPluginMigrator_createNodesResultsForTargets = new WeakMap(), _ExecutorToPluginMigrator_skippedProjects = new WeakMap(), _ExecutorToPluginMigrator_instances = new WeakSet(), _ExecutorToPluginMigrator_init = async function _ExecutorToPluginMigrator_init() {
|
52
54
|
const nxJson = (0, devkit_exports_1.readNxJson)(this.tree);
|
53
55
|
nxJson.plugins ??= [];
|
54
56
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_nxJson, nxJson, "f");
|
55
57
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, new Map(), "f");
|
56
58
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, new Map(), "f");
|
57
59
|
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, new Map(), "f");
|
60
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_skippedProjects, new Set(), "f");
|
58
61
|
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getTargetDefaultsForExecutor).call(this);
|
59
62
|
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate).call(this);
|
60
63
|
await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreateNodesResults).call(this);
|
61
|
-
}, _ExecutorToPluginMigrator_migrateTarget = function _ExecutorToPluginMigrator_migrateTarget(targetName) {
|
64
|
+
}, _ExecutorToPluginMigrator_migrateTarget = async function _ExecutorToPluginMigrator_migrateTarget(targetName) {
|
62
65
|
const include = [];
|
63
66
|
for (const projectName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").get(targetName)) {
|
64
|
-
include.push(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateProject).call(this, projectName, targetName));
|
67
|
+
include.push(await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateProject).call(this, projectName, targetName));
|
65
68
|
}
|
66
69
|
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").set(targetName, {
|
67
70
|
plugin: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
|
68
71
|
options: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName),
|
69
72
|
include,
|
70
73
|
});
|
71
|
-
}, _ExecutorToPluginMigrator_migrateProject = function _ExecutorToPluginMigrator_migrateProject(projectName, targetName) {
|
74
|
+
}, _ExecutorToPluginMigrator_migrateProject = async function _ExecutorToPluginMigrator_migrateProject(projectName, targetName) {
|
72
75
|
const projectFromGraph = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_projectGraph, "f").nodes[projectName];
|
73
76
|
const projectConfig = (0, devkit_exports_1.readProjectConfiguration)(this.tree, projectName);
|
74
77
|
const createdTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot).call(this, targetName, projectFromGraph.data.root);
|
@@ -79,7 +82,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
|
|
79
82
|
if (projectTarget.inputs && createdTarget.inputs) {
|
80
83
|
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_mergeInputs).call(this, projectTarget, createdTarget);
|
81
84
|
}
|
82
|
-
projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree, { projectName, root: projectFromGraph.data.root }, createdTarget);
|
85
|
+
projectTarget = await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree, { projectName, root: projectFromGraph.data.root }, createdTarget);
|
83
86
|
if (projectTarget.options &&
|
84
87
|
Object.keys(projectTarget.options).length === 0) {
|
85
88
|
delete projectTarget.options;
|
@@ -130,72 +133,28 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
|
|
130
133
|
...inferredTargetExternalDependencyInput.externalDependencies,
|
131
134
|
]));
|
132
135
|
}
|
133
|
-
}, _ExecutorToPluginMigrator_pluginRequiresIncludes = async function _ExecutorToPluginMigrator_pluginRequiresIncludes(targetName, plugin) {
|
134
|
-
const loadedPlugin = new devkit_internals_1.LoadedNxPlugin({
|
135
|
-
createNodesV2: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesV2, "f"),
|
136
|
-
createNodes: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodes, "f"),
|
137
|
-
name: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
|
138
|
-
}, plugin);
|
139
|
-
const originalResults = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").get(targetName);
|
140
|
-
let resultsWithIncludes;
|
141
|
-
try {
|
142
|
-
resultsWithIncludes = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], this.tree.root, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
|
143
|
-
}
|
144
|
-
catch (e) {
|
145
|
-
if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
|
146
|
-
resultsWithIncludes = e.partialProjectConfigurationsResult;
|
147
|
-
}
|
148
|
-
else {
|
149
|
-
throw e;
|
150
|
-
}
|
151
|
-
}
|
152
|
-
return !deepEqual(originalResults, resultsWithIncludes);
|
153
|
-
}, _ExecutorToPluginMigrator_addPlugins = async function _ExecutorToPluginMigrator_addPlugins() {
|
154
|
-
for (const [targetName, plugin] of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").entries()) {
|
155
|
-
const pluginOptions = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName);
|
156
|
-
const existingPlugin = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.find((plugin) => {
|
157
|
-
if (typeof plugin === 'string' ||
|
158
|
-
plugin.plugin !== tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f")) {
|
159
|
-
return;
|
160
|
-
}
|
161
|
-
for (const key in plugin.options) {
|
162
|
-
if (plugin.options[key] !== pluginOptions[key]) {
|
163
|
-
return false;
|
164
|
-
}
|
165
|
-
}
|
166
|
-
return true;
|
167
|
-
});
|
168
|
-
if (existingPlugin?.include) {
|
169
|
-
// Add to the existing plugin includes
|
170
|
-
existingPlugin.include = existingPlugin.include.concat(
|
171
|
-
// Any include that is in the new plugin's include list
|
172
|
-
plugin.include.filter((projectPath) =>
|
173
|
-
// And is not already covered by the existing plugin's include list
|
174
|
-
!existingPlugin.include.some((pluginIncludes) => (0, minimatch_1.minimatch)(projectPath, pluginIncludes, { dot: true }))));
|
175
|
-
if (!(await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_pluginRequiresIncludes).call(this, targetName, existingPlugin))) {
|
176
|
-
delete existingPlugin.include;
|
177
|
-
}
|
178
|
-
}
|
179
|
-
if (!existingPlugin) {
|
180
|
-
if (!(await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_pluginRequiresIncludes).call(this, targetName, plugin))) {
|
181
|
-
plugin.include = undefined;
|
182
|
-
}
|
183
|
-
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.push(plugin);
|
184
|
-
}
|
185
|
-
}
|
186
|
-
(0, devkit_exports_1.updateNxJson)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
|
187
136
|
}, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate = function _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate() {
|
188
137
|
(0, executor_options_utils_1.forEachExecutorOptions)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f"), (targetConfiguration, projectName, targetName, configurationName) => {
|
189
|
-
if (configurationName) {
|
138
|
+
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_skippedProjects, "f").has(projectName) || configurationName) {
|
190
139
|
return;
|
191
140
|
}
|
192
141
|
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f") &&
|
193
142
|
projectName !== tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")) {
|
194
143
|
return;
|
195
144
|
}
|
196
|
-
const
|
197
|
-
if (
|
198
|
-
|
145
|
+
const skipProjectReason = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_skipProjectFilter, "f").call(this, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_projectGraph, "f").nodes[projectName].data);
|
146
|
+
if (skipProjectReason) {
|
147
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_skippedProjects, "f").add(projectName);
|
148
|
+
const errorMsg = `The "${projectName}" project cannot be migrated. ${skipProjectReason}`;
|
149
|
+
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")) {
|
150
|
+
throw new Error(errorMsg);
|
151
|
+
}
|
152
|
+
console.warn(errorMsg);
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
const skipTargetReason = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_skipTargetFilter, "f").call(this, targetConfiguration);
|
156
|
+
if (skipTargetReason) {
|
157
|
+
const errorMsg = `${targetName} target on project "${projectName}" cannot be migrated. ${skipTargetReason}`;
|
199
158
|
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")) {
|
200
159
|
throw new Error(errorMsg);
|
201
160
|
}
|
@@ -227,40 +186,135 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
|
|
227
186
|
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").size === 0) {
|
228
187
|
return;
|
229
188
|
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
189
|
+
global.NX_GRAPH_CREATION = true;
|
190
|
+
try {
|
191
|
+
for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
|
192
|
+
const result = await getCreateNodesResultsForPlugin(this.tree, {
|
193
|
+
plugin: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
|
194
|
+
options: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName),
|
195
|
+
}, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"), tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodes, "f"), tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesV2, "f"), tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
|
196
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").set(targetName, result);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
finally {
|
200
|
+
global.NX_GRAPH_CREATION = false;
|
201
|
+
}
|
202
|
+
};
|
203
|
+
async function migrateProjectExecutorsToPlugin(tree, projectGraph, pluginPath, createNodesV2, defaultPluginOptions, migrations, specificProjectToMigrate) {
|
204
|
+
const projects = await migrateProjects(tree, projectGraph, pluginPath, undefined, createNodesV2, defaultPluginOptions, migrations, specificProjectToMigrate);
|
205
|
+
return projects;
|
206
|
+
}
|
207
|
+
exports.migrateProjectExecutorsToPlugin = migrateProjectExecutorsToPlugin;
|
208
|
+
async function migrateProjectExecutorsToPluginV1(tree, projectGraph, pluginPath, createNodes, defaultPluginOptions, migrations, specificProjectToMigrate) {
|
209
|
+
const projects = await migrateProjects(tree, projectGraph, pluginPath, createNodes, undefined, defaultPluginOptions, migrations, specificProjectToMigrate);
|
210
|
+
return projects;
|
211
|
+
}
|
212
|
+
exports.migrateProjectExecutorsToPluginV1 = migrateProjectExecutorsToPluginV1;
|
213
|
+
async function migrateProjects(tree, projectGraph, pluginPath, createNodes, createNodesV2, defaultPluginOptions, migrations, specificProjectToMigrate) {
|
214
|
+
const projects = new Map();
|
215
|
+
for (const migration of migrations) {
|
216
|
+
for (const executor of migration.executors) {
|
217
|
+
const migrator = new ExecutorToPluginMigrator(tree, projectGraph, executor, pluginPath, migration.targetPluginOptionMapper, migration.postTargetTransformer, createNodes, createNodesV2, specificProjectToMigrate, {
|
218
|
+
skipProjectFilter: migration.skipProjectFilter,
|
219
|
+
skipTargetFilter: migration.skipTargetFilter,
|
220
|
+
});
|
221
|
+
const result = await migrator.run();
|
222
|
+
// invert the result to have a map of projects to their targets
|
223
|
+
for (const [target, projectList] of result.entries()) {
|
224
|
+
for (const project of projectList) {
|
225
|
+
if (!projects.has(project)) {
|
226
|
+
projects.set(project, {});
|
227
|
+
}
|
228
|
+
projects.set(project, {
|
229
|
+
...projects.get(project),
|
230
|
+
...migration.targetPluginOptionMapper(target),
|
231
|
+
});
|
232
|
+
}
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
// apply default options
|
237
|
+
for (const [project, pluginOptions] of projects.entries()) {
|
238
|
+
projects.set(project, {
|
239
|
+
...defaultPluginOptions,
|
240
|
+
...pluginOptions,
|
238
241
|
});
|
239
|
-
|
242
|
+
}
|
243
|
+
await addPluginRegistrations(tree, projects, pluginPath, createNodes, createNodesV2, defaultPluginOptions, projectGraph);
|
244
|
+
return projects;
|
245
|
+
}
|
246
|
+
async function addPluginRegistrations(tree, projects, pluginPath, createNodes, createNodesV2, defaultPluginOptions, projectGraph) {
|
247
|
+
const nxJson = (0, devkit_exports_1.readNxJson)(tree);
|
248
|
+
// collect createNodes results for each project before adding the plugins
|
249
|
+
const createNodesResults = new Map();
|
250
|
+
global.NX_GRAPH_CREATION = true;
|
251
|
+
try {
|
252
|
+
for (const [project, options] of projects.entries()) {
|
253
|
+
const projectConfigs = await getCreateNodesResultsForPlugin(tree, { plugin: pluginPath, options }, pluginPath, createNodes, createNodesV2, nxJson);
|
254
|
+
createNodesResults.set(project, projectConfigs);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
finally {
|
258
|
+
global.NX_GRAPH_CREATION = false;
|
259
|
+
}
|
260
|
+
const arePluginIncludesRequired = async (project, pluginConfiguration) => {
|
261
|
+
global.NX_GRAPH_CREATION = true;
|
262
|
+
let result;
|
240
263
|
try {
|
241
|
-
|
264
|
+
result = await getCreateNodesResultsForPlugin(tree, pluginConfiguration, pluginPath, createNodes, createNodesV2, nxJson);
|
265
|
+
}
|
266
|
+
finally {
|
267
|
+
global.NX_GRAPH_CREATION = false;
|
242
268
|
}
|
243
|
-
|
244
|
-
|
245
|
-
|
269
|
+
const originalResults = createNodesResults.get(project);
|
270
|
+
return !deepEqual(originalResults, result);
|
271
|
+
};
|
272
|
+
for (const [project, options] of projects.entries()) {
|
273
|
+
const existingPlugin = nxJson.plugins?.find((plugin) => typeof plugin !== 'string' &&
|
274
|
+
plugin.plugin === pluginPath &&
|
275
|
+
Object.keys(options).every((key) => plugin.options[key] === options[key] ||
|
276
|
+
(plugin.options[key] === undefined &&
|
277
|
+
options[key] === defaultPluginOptions[key])));
|
278
|
+
const projectIncludeGlob = `${projectGraph.nodes[project].data.root}/**/*`;
|
279
|
+
if (!existingPlugin) {
|
280
|
+
nxJson.plugins ??= [];
|
281
|
+
const plugin = {
|
282
|
+
plugin: pluginPath,
|
283
|
+
options,
|
284
|
+
include: [projectIncludeGlob],
|
285
|
+
};
|
286
|
+
if (!(await arePluginIncludesRequired(project, plugin))) {
|
287
|
+
delete plugin.include;
|
246
288
|
}
|
247
|
-
|
248
|
-
|
289
|
+
nxJson.plugins.push(plugin);
|
290
|
+
}
|
291
|
+
else if (existingPlugin.include) {
|
292
|
+
if (!existingPlugin.include.some((include) => (0, minimatch_1.minimatch)(projectIncludeGlob, include, { dot: true }))) {
|
293
|
+
existingPlugin.include.push(projectIncludeGlob);
|
294
|
+
if (!(await arePluginIncludesRequired(project, existingPlugin))) {
|
295
|
+
delete existingPlugin.include;
|
296
|
+
}
|
249
297
|
}
|
250
298
|
}
|
251
|
-
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").set(targetName, projectConfigs);
|
252
299
|
}
|
253
|
-
|
254
|
-
async function migrateExecutorToPlugin(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter) {
|
255
|
-
const migrator = new ExecutorToPluginMigrator(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, undefined, createNodes, specificProjectToMigrate, skipTargetFilter);
|
256
|
-
return await migrator.run();
|
300
|
+
(0, devkit_exports_1.updateNxJson)(tree, nxJson);
|
257
301
|
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
302
|
+
async function getCreateNodesResultsForPlugin(tree, pluginConfiguration, pluginPath, createNodes, createNodesV2, nxJson) {
|
303
|
+
let projectConfigs;
|
304
|
+
try {
|
305
|
+
const plugin = new devkit_internals_1.LoadedNxPlugin({ createNodes, createNodesV2, name: pluginPath }, pluginConfiguration);
|
306
|
+
projectConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([plugin], tree.root, nxJson);
|
307
|
+
}
|
308
|
+
catch (e) {
|
309
|
+
if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
|
310
|
+
projectConfigs = e.partialProjectConfigurationsResult;
|
311
|
+
}
|
312
|
+
else {
|
313
|
+
throw e;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
return projectConfigs;
|
262
317
|
}
|
263
|
-
exports.migrateExecutorToPluginV1 = migrateExecutorToPluginV1;
|
264
318
|
// Checks if two objects are structurely equal, without caring
|
265
319
|
// about the order of the keys.
|
266
320
|
function deepEqual(a, b, logKey = '') {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type
|
1
|
+
import { type TargetConfiguration } from 'nx/src/devkit-exports';
|
2
2
|
/**
|
3
3
|
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
4
4
|
* Delete matching properties from current target.
|
@@ -60,3 +60,4 @@ export declare function processTargetOutputs(target: TargetConfiguration, rename
|
|
60
60
|
projectName: string;
|
61
61
|
projectRoot: string;
|
62
62
|
}): void;
|
63
|
+
export declare function toProjectRelativePath(path: string, projectRoot: string): string;
|
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.processTargetOutputs = exports.deleteMatchingProperties = void 0;
|
3
|
+
exports.toProjectRelativePath = exports.processTargetOutputs = exports.deleteMatchingProperties = void 0;
|
4
|
+
const posix_1 = require("node:path/posix");
|
5
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
4
6
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
5
7
|
/**
|
6
8
|
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
@@ -105,6 +107,16 @@ function processTargetOutputs(target, renamedOutputOptions, inferredTarget, proj
|
|
105
107
|
target.outputs = targetOutputs;
|
106
108
|
}
|
107
109
|
exports.processTargetOutputs = processTargetOutputs;
|
110
|
+
function toProjectRelativePath(path, projectRoot) {
|
111
|
+
if (projectRoot === '.') {
|
112
|
+
// workspace and project root are the same, we add a leading './' which is
|
113
|
+
// required by some tools (e.g. Jest)
|
114
|
+
return path.startsWith('.') ? path : `./${path}`;
|
115
|
+
}
|
116
|
+
const relativePath = (0, posix_1.relative)((0, posix_1.resolve)(devkit_exports_1.workspaceRoot, projectRoot), (0, posix_1.resolve)(devkit_exports_1.workspaceRoot, path));
|
117
|
+
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
118
|
+
}
|
119
|
+
exports.toProjectRelativePath = toProjectRelativePath;
|
108
120
|
function updateOutputRenamingOption(output, option, previousName) {
|
109
121
|
const newOptionToken = `{options.${option}}`;
|
110
122
|
const oldOptionToken = `{options.${previousName}}`;
|