@nx/devkit 19.2.0-beta.1 → 19.2.0-beta.3
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/executor-to-plugin-migrator.d.ts +2 -2
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +1 -4
- package/src/generators/plugin-migrations/plugin-migration-utils.d.ts +8 -0
- package/src/generators/plugin-migrations/plugin-migration-utils.js +66 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/devkit",
|
3
|
-
"version": "19.2.0-beta.
|
3
|
+
"version": "19.2.0-beta.3",
|
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.2.0-beta.
|
39
|
+
"@nrwl/devkit": "19.2.0-beta.3"
|
40
40
|
},
|
41
41
|
"peerDependencies": {
|
42
42
|
"nx": ">= 17 <= 20"
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { ProjectGraph, TargetConfiguration, Tree, CreateNodes } from 'nx/src/devkit-exports';
|
2
2
|
type PluginOptionsBuilder<T> = (targetName: string) => T;
|
3
|
-
type PostTargetTransformer = (targetConfiguration: TargetConfiguration, tree
|
3
|
+
type PostTargetTransformer = (targetConfiguration: TargetConfiguration, tree: Tree, projectDetails: {
|
4
4
|
projectName: string;
|
5
5
|
root: string;
|
6
|
-
}) => TargetConfiguration;
|
6
|
+
}, inferredTargetConfiguration: TargetConfiguration) => TargetConfiguration;
|
7
7
|
type SkipTargetFilter = (targetConfiguration: TargetConfiguration) => [boolean, string];
|
8
8
|
export declare function migrateExecutorToPlugin<T>(tree: Tree, projectGraph: ProjectGraph, executor: string, pluginPath: string, pluginOptionsBuilder: PluginOptionsBuilder<T>, postTargetTransformer: PostTargetTransformer, createNodes: CreateNodes<T>, specificProjectToMigrate?: string, skipTargetFilter?: SkipTargetFilter): Promise<Map<string, Set<string>>>;
|
9
9
|
export {};
|
@@ -74,10 +74,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
|
|
74
74
|
projectTarget = (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
|
75
75
|
delete projectTarget.executor;
|
76
76
|
(0, plugin_migration_utils_1.deleteMatchingProperties)(projectTarget, createdTarget);
|
77
|
-
projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree, {
|
78
|
-
projectName,
|
79
|
-
root: projectFromGraph.data.root,
|
80
|
-
});
|
77
|
+
projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree, { projectName, root: projectFromGraph.data.root }, createdTarget);
|
81
78
|
if (projectTarget.options &&
|
82
79
|
Object.keys(projectTarget.options).length === 0) {
|
83
80
|
delete projectTarget.options;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { TargetConfiguration } from 'nx/src/devkit-exports';
|
1
2
|
/**
|
2
3
|
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
3
4
|
* Delete matching properties from current target.
|
@@ -52,3 +53,10 @@
|
|
52
53
|
* @param createdTarget The target created by the Plugin
|
53
54
|
*/
|
54
55
|
export declare function deleteMatchingProperties(targetToMigrate: object, createdTarget: object): void;
|
56
|
+
export declare function processTargetOutputs(target: TargetConfiguration, renamedOutputOptions: Array<{
|
57
|
+
newName: string;
|
58
|
+
oldName: string;
|
59
|
+
}>, inferredTarget: TargetConfiguration, projectDetails: {
|
60
|
+
projectName: string;
|
61
|
+
projectRoot: string;
|
62
|
+
}): void;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.deleteMatchingProperties = void 0;
|
3
|
+
exports.processTargetOutputs = exports.deleteMatchingProperties = void 0;
|
4
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
4
5
|
/**
|
5
6
|
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
6
7
|
* Delete matching properties from current target.
|
@@ -76,3 +77,67 @@ function deleteMatchingProperties(targetToMigrate, createdTarget) {
|
|
76
77
|
}
|
77
78
|
}
|
78
79
|
exports.deleteMatchingProperties = deleteMatchingProperties;
|
80
|
+
function processTargetOutputs(target, renamedOutputOptions, inferredTarget, projectDetails) {
|
81
|
+
const interpolatedInferredOutputs = (inferredTarget.outputs ?? []).map((output) => (0, devkit_internals_1.interpolate)(output, {
|
82
|
+
workspaceRoot: '',
|
83
|
+
projectRoot: projectDetails.projectRoot,
|
84
|
+
projectName: projectDetails.projectName,
|
85
|
+
}));
|
86
|
+
const targetOutputs = (target.outputs ?? []).map((output) => updateOutput(output, renamedOutputOptions));
|
87
|
+
const interpolatedOutputs = targetOutputs.map((output) => (0, devkit_internals_1.interpolate)(output, {
|
88
|
+
workspaceRoot: '',
|
89
|
+
projectRoot: projectDetails.projectRoot,
|
90
|
+
projectName: projectDetails.projectName,
|
91
|
+
}));
|
92
|
+
const shouldDelete = interpolatedOutputs.every((output) => interpolatedInferredOutputs.includes(output));
|
93
|
+
if (shouldDelete) {
|
94
|
+
// all existing outputs are already inferred
|
95
|
+
delete target.outputs;
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
// move extra inferred outputs to the target outputs
|
99
|
+
for (let i = 0; i < interpolatedInferredOutputs.length; i++) {
|
100
|
+
if (!interpolatedOutputs.includes(interpolatedInferredOutputs[i])) {
|
101
|
+
targetOutputs.push(inferredTarget.outputs[i]);
|
102
|
+
interpolatedOutputs.push(interpolatedInferredOutputs[i]);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
target.outputs = targetOutputs;
|
106
|
+
}
|
107
|
+
exports.processTargetOutputs = processTargetOutputs;
|
108
|
+
function updateOutputRenamingOption(output, option, previousName) {
|
109
|
+
const newOptionToken = `{options.${option}}`;
|
110
|
+
const oldOptionToken = `{options.${previousName}}`;
|
111
|
+
if (!output.startsWith('{workspaceRoot}') &&
|
112
|
+
!output.startsWith('{projectRoot}')) {
|
113
|
+
return `{projectRoot}/${output.replace(oldOptionToken, newOptionToken)}`;
|
114
|
+
}
|
115
|
+
if (output.startsWith('{workspaceRoot}') &&
|
116
|
+
!output.startsWith('{workspaceRoot}/{projectRoot}')) {
|
117
|
+
return output
|
118
|
+
.replace('{workspaceRoot}', '{projectRoot}')
|
119
|
+
.replace(oldOptionToken, newOptionToken);
|
120
|
+
}
|
121
|
+
return output.replace(oldOptionToken, newOptionToken);
|
122
|
+
}
|
123
|
+
function updateOutput(output, renamedOutputOptions) {
|
124
|
+
if (!/{options\..*}/.test(output)) {
|
125
|
+
// output does not contain any option tokens
|
126
|
+
return output;
|
127
|
+
}
|
128
|
+
for (const { newName, oldName } of renamedOutputOptions) {
|
129
|
+
const optionToken = `{options.${oldName}}`;
|
130
|
+
if (output.includes(optionToken)) {
|
131
|
+
return updateOutputRenamingOption(output, newName, oldName);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
if (!output.startsWith('{workspaceRoot}') &&
|
135
|
+
!output.startsWith('{projectRoot}')) {
|
136
|
+
return `{projectRoot}/${output}`;
|
137
|
+
}
|
138
|
+
if (output.startsWith('{workspaceRoot}') &&
|
139
|
+
!output.startsWith('{workspaceRoot}/{projectRoot}')) {
|
140
|
+
return output.replace('{workspaceRoot}', '{projectRoot}');
|
141
|
+
}
|
142
|
+
return output;
|
143
|
+
}
|