@nx/devkit 0.0.0-pr-22179-271588f → 0.0.0-pr-26482-ebe2dba
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/LICENSE +1 -1
- package/package.json +5 -4
- package/public-api.d.ts +1 -1
- package/public-api.js +2 -1
- package/src/executors/parse-target-string.d.ts +1 -3
- package/src/executors/parse-target-string.js +5 -9
- package/src/executors/read-target-options.d.ts +1 -2
- package/src/executors/read-target-options.js +4 -17
- package/src/generators/add-build-target-defaults.d.ts +1 -1
- package/src/generators/add-build-target-defaults.js +3 -4
- package/src/generators/artifact-name-and-directory-utils.d.ts +1 -1
- package/src/generators/artifact-name-and-directory-utils.js +37 -26
- package/src/generators/executor-options-utils.d.ts +1 -2
- package/src/generators/executor-options-utils.js +3 -6
- package/src/generators/format-files.d.ts +1 -1
- package/src/generators/format-files.js +5 -8
- package/src/generators/generate-files.d.ts +20 -2
- package/src/generators/generate-files.js +27 -5
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.d.ts +10 -0
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +286 -0
- package/src/generators/plugin-migrations/plugin-migration-utils.d.ts +62 -0
- package/src/generators/plugin-migrations/plugin-migration-utils.js +143 -0
- package/src/generators/project-name-and-root-utils.d.ts +1 -2
- package/src/generators/project-name-and-root-utils.js +16 -17
- package/src/generators/run-tasks-in-serial.d.ts +1 -1
- package/src/generators/to-js.d.ts +1 -1
- package/src/generators/update-ts-configs-to-js.d.ts +1 -1
- package/src/generators/update-ts-configs-to-js.js +3 -4
- package/src/generators/visit-not-ignored-files.d.ts +1 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +1 -1
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +1 -2
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +2 -3
- package/src/tasks/install-packages-task.d.ts +1 -2
- package/src/tasks/install-packages-task.js +5 -6
- package/src/utils/add-plugin.d.ts +13 -0
- package/src/utils/add-plugin.js +258 -0
- package/src/utils/async-iterable/combine-async-iterables.js +4 -2
- package/src/utils/binary-extensions.js +4 -0
- package/src/utils/calculate-hash-for-create-nodes.d.ts +2 -2
- package/src/utils/calculate-hash-for-create-nodes.js +6 -6
- package/src/utils/config-utils.d.ts +1 -0
- package/src/utils/config-utils.js +23 -11
- package/src/utils/convert-nx-executor.d.ts +1 -1
- package/src/utils/convert-nx-executor.js +21 -17
- package/src/utils/get-named-inputs.d.ts +1 -1
- package/src/utils/get-named-inputs.js +3 -4
- package/src/utils/get-workspace-layout.d.ts +1 -1
- package/src/utils/get-workspace-layout.js +2 -3
- package/src/utils/invoke-nx-generator.d.ts +1 -1
- package/src/utils/invoke-nx-generator.js +3 -5
- package/src/utils/log-show-project-command.js +2 -3
- package/src/utils/move-dir.d.ts +1 -1
- package/src/utils/move-dir.js +3 -4
- package/src/utils/package-json.d.ts +1 -2
- package/src/utils/package-json.js +13 -13
- package/src/utils/replace-package.d.ts +1 -1
- package/src/utils/replace-package.js +8 -9
- package/src/utils/replace-project-configuration-with-plugin.d.ts +1 -2
- package/src/utils/replace-project-configuration-with-plugin.js +12 -11
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/nx.d.ts +0 -1
- package/nx.js +0 -19
- package/src/utils/update-package-scripts.d.ts +0 -3
- package/src/utils/update-package-scripts.js +0 -175
|
@@ -0,0 +1,286 @@
|
|
|
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, _ExecutorToPluginMigrator_pluginRequiresIncludes, _ExecutorToPluginMigrator_addPlugins, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot, _ExecutorToPluginMigrator_getCreateNodesResults;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.migrateExecutorToPluginV1 = exports.migrateExecutorToPlugin = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const minimatch_1 = require("minimatch");
|
|
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
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
11
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
12
|
+
class ExecutorToPluginMigrator {
|
|
13
|
+
constructor(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, createNodesV2, specificProjectToMigrate, skipTargetFilter) {
|
|
14
|
+
_ExecutorToPluginMigrator_instances.add(this);
|
|
15
|
+
_ExecutorToPluginMigrator_projectGraph.set(this, void 0);
|
|
16
|
+
_ExecutorToPluginMigrator_executor.set(this, void 0);
|
|
17
|
+
_ExecutorToPluginMigrator_pluginPath.set(this, void 0);
|
|
18
|
+
_ExecutorToPluginMigrator_pluginOptionsBuilder.set(this, void 0);
|
|
19
|
+
_ExecutorToPluginMigrator_postTargetTransformer.set(this, void 0);
|
|
20
|
+
_ExecutorToPluginMigrator_skipTargetFilter.set(this, void 0);
|
|
21
|
+
_ExecutorToPluginMigrator_specificProjectToMigrate.set(this, void 0);
|
|
22
|
+
_ExecutorToPluginMigrator_nxJson.set(this, void 0);
|
|
23
|
+
_ExecutorToPluginMigrator_targetDefaultsForExecutor.set(this, void 0);
|
|
24
|
+
_ExecutorToPluginMigrator_targetAndProjectsToMigrate.set(this, void 0);
|
|
25
|
+
_ExecutorToPluginMigrator_pluginToAddForTarget.set(this, void 0);
|
|
26
|
+
_ExecutorToPluginMigrator_createNodes.set(this, void 0);
|
|
27
|
+
_ExecutorToPluginMigrator_createNodesV2.set(this, void 0);
|
|
28
|
+
_ExecutorToPluginMigrator_createNodesResultsForTargets.set(this, void 0);
|
|
29
|
+
this.tree = tree;
|
|
30
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_projectGraph, projectGraph, "f");
|
|
31
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_executor, executor, "f");
|
|
32
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_pluginPath, pluginPath, "f");
|
|
33
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, pluginOptionsBuilder, "f");
|
|
34
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_postTargetTransformer, postTargetTransformer, "f");
|
|
35
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodes, createNodes, "f");
|
|
36
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodesV2, createNodesV2, "f");
|
|
37
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, specificProjectToMigrate, "f");
|
|
38
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_skipTargetFilter, skipTargetFilter ?? ((...args) => [false, '']), "f");
|
|
39
|
+
}
|
|
40
|
+
async run() {
|
|
41
|
+
await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_init).call(this);
|
|
42
|
+
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").size > 0) {
|
|
43
|
+
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);
|
|
45
|
+
}
|
|
46
|
+
await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_addPlugins).call(this);
|
|
47
|
+
}
|
|
48
|
+
return tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
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() {
|
|
52
|
+
const nxJson = (0, devkit_exports_1.readNxJson)(this.tree);
|
|
53
|
+
nxJson.plugins ??= [];
|
|
54
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_nxJson, nxJson, "f");
|
|
55
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, new Map(), "f");
|
|
56
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, new Map(), "f");
|
|
57
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, new Map(), "f");
|
|
58
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getTargetDefaultsForExecutor).call(this);
|
|
59
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate).call(this);
|
|
60
|
+
await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreateNodesResults).call(this);
|
|
61
|
+
}, _ExecutorToPluginMigrator_migrateTarget = function _ExecutorToPluginMigrator_migrateTarget(targetName) {
|
|
62
|
+
const include = [];
|
|
63
|
+
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));
|
|
65
|
+
}
|
|
66
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").set(targetName, {
|
|
67
|
+
plugin: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
|
|
68
|
+
options: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName),
|
|
69
|
+
include,
|
|
70
|
+
});
|
|
71
|
+
}, _ExecutorToPluginMigrator_migrateProject = function _ExecutorToPluginMigrator_migrateProject(projectName, targetName) {
|
|
72
|
+
const projectFromGraph = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_projectGraph, "f").nodes[projectName];
|
|
73
|
+
const projectConfig = (0, devkit_exports_1.readProjectConfiguration)(this.tree, projectName);
|
|
74
|
+
const createdTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot).call(this, targetName, projectFromGraph.data.root);
|
|
75
|
+
let projectTarget = projectConfig.targets[targetName];
|
|
76
|
+
projectTarget = (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
|
|
77
|
+
delete projectTarget.executor;
|
|
78
|
+
(0, plugin_migration_utils_1.deleteMatchingProperties)(projectTarget, createdTarget);
|
|
79
|
+
if (projectTarget.inputs && createdTarget.inputs) {
|
|
80
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_mergeInputs).call(this, projectTarget, createdTarget);
|
|
81
|
+
}
|
|
82
|
+
projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree, { projectName, root: projectFromGraph.data.root }, createdTarget);
|
|
83
|
+
if (projectTarget.options &&
|
|
84
|
+
Object.keys(projectTarget.options).length === 0) {
|
|
85
|
+
delete projectTarget.options;
|
|
86
|
+
}
|
|
87
|
+
if (Object.keys(projectTarget).length > 0) {
|
|
88
|
+
projectConfig.targets[targetName] = projectTarget;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
delete projectConfig.targets[targetName];
|
|
92
|
+
}
|
|
93
|
+
if (!projectConfig['// targets']) {
|
|
94
|
+
projectConfig['// targets'] = `to see all targets run: nx show project ${projectName} --web`;
|
|
95
|
+
}
|
|
96
|
+
(0, devkit_exports_1.updateProjectConfiguration)(this.tree, projectName, projectConfig);
|
|
97
|
+
return `${projectFromGraph.data.root}/**/*`;
|
|
98
|
+
}, _ExecutorToPluginMigrator_mergeInputs = function _ExecutorToPluginMigrator_mergeInputs(target, inferredTarget) {
|
|
99
|
+
const isInputInferred = (input) => {
|
|
100
|
+
return inferredTarget.inputs.some((inferredInput) => {
|
|
101
|
+
try {
|
|
102
|
+
(0, node_assert_1.deepStrictEqual)(input, inferredInput);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
if (target.inputs.every(isInputInferred)) {
|
|
111
|
+
delete target.inputs;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const inferredTargetExternalDependencyInput = inferredTarget.inputs.find((i) => typeof i !== 'string' && 'externalDependencies' in i);
|
|
115
|
+
if (!inferredTargetExternalDependencyInput) {
|
|
116
|
+
// plugins should normally have an externalDependencies input, but if it
|
|
117
|
+
// doesn't, there's nothing to merge
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const targetExternalDependencyInput = target.inputs.find((i) => typeof i !== 'string' && 'externalDependencies' in i);
|
|
121
|
+
if (!targetExternalDependencyInput) {
|
|
122
|
+
// the target doesn't have an externalDependencies input, so we can just
|
|
123
|
+
// add the inferred one
|
|
124
|
+
target.inputs.push(inferredTargetExternalDependencyInput);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// the target has an externalDependencies input, so we need to merge them
|
|
128
|
+
targetExternalDependencyInput.externalDependencies = Array.from(new Set([
|
|
129
|
+
...targetExternalDependencyInput.externalDependencies,
|
|
130
|
+
...inferredTargetExternalDependencyInput.externalDependencies,
|
|
131
|
+
]));
|
|
132
|
+
}
|
|
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
|
+
}, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate = function _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate() {
|
|
188
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f"), (targetConfiguration, projectName, targetName, configurationName) => {
|
|
189
|
+
if (configurationName) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f") &&
|
|
193
|
+
projectName !== tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const [skipTarget, reasonTargetWasSkipped] = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_skipTargetFilter, "f").call(this, targetConfiguration);
|
|
197
|
+
if (skipTarget) {
|
|
198
|
+
const errorMsg = `${targetName} target on project "${projectName}" cannot be migrated. ${reasonTargetWasSkipped}`;
|
|
199
|
+
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")) {
|
|
200
|
+
throw new Error(errorMsg);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
console.warn(errorMsg);
|
|
204
|
+
}
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").has(targetName)) {
|
|
208
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").get(targetName).add(projectName);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").set(targetName, new Set([projectName]));
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor = function _ExecutorToPluginMigrator_getTargetDefaultsForExecutor() {
|
|
215
|
+
tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, structuredClone(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").targetDefaults?.[tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")]), "f");
|
|
216
|
+
}, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot = function _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot(targetName, projectRoot) {
|
|
217
|
+
const entry = Object.entries(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").get(targetName)?.projects ?? {}).find(([root]) => root === projectRoot);
|
|
218
|
+
if (!entry) {
|
|
219
|
+
throw new Error(`The nx plugin did not find a project inside ${projectRoot}. File an issue at https://github.com/nrwl/nx with information about your project structure.`);
|
|
220
|
+
}
|
|
221
|
+
const createdProject = entry[1];
|
|
222
|
+
const createdTarget = structuredClone(createdProject.targets[targetName]);
|
|
223
|
+
delete createdTarget.command;
|
|
224
|
+
delete createdTarget.options?.cwd;
|
|
225
|
+
return createdTarget;
|
|
226
|
+
}, _ExecutorToPluginMigrator_getCreateNodesResults = async function _ExecutorToPluginMigrator_getCreateNodesResults() {
|
|
227
|
+
if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").size === 0) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
|
|
231
|
+
const loadedPlugin = new devkit_internals_1.LoadedNxPlugin({
|
|
232
|
+
createNodesV2: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesV2, "f"),
|
|
233
|
+
createNodes: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodes, "f"),
|
|
234
|
+
name: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
|
|
235
|
+
}, {
|
|
236
|
+
plugin: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
|
|
237
|
+
options: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName),
|
|
238
|
+
});
|
|
239
|
+
let projectConfigs;
|
|
240
|
+
try {
|
|
241
|
+
projectConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], this.tree.root, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
|
|
245
|
+
projectConfigs = e.partialProjectConfigurationsResult;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
throw e;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").set(targetName, projectConfigs);
|
|
252
|
+
}
|
|
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();
|
|
257
|
+
}
|
|
258
|
+
exports.migrateExecutorToPlugin = migrateExecutorToPlugin;
|
|
259
|
+
async function migrateExecutorToPluginV1(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter) {
|
|
260
|
+
const migrator = new ExecutorToPluginMigrator(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, undefined, specificProjectToMigrate, skipTargetFilter);
|
|
261
|
+
return await migrator.run();
|
|
262
|
+
}
|
|
263
|
+
exports.migrateExecutorToPluginV1 = migrateExecutorToPluginV1;
|
|
264
|
+
// Checks if two objects are structurely equal, without caring
|
|
265
|
+
// about the order of the keys.
|
|
266
|
+
function deepEqual(a, b, logKey = '') {
|
|
267
|
+
const aKeys = Object.keys(a);
|
|
268
|
+
const bKeys = new Set(Object.keys(b));
|
|
269
|
+
if (aKeys.length !== bKeys.size) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
for (const key of aKeys) {
|
|
273
|
+
if (!bKeys.has(key)) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
if (typeof a[key] === 'object' && typeof b[key] === 'object') {
|
|
277
|
+
if (!deepEqual(a[key], b[key], logKey + '.' + key)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else if (a[key] !== b[key]) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { TargetConfiguration } from 'nx/src/devkit-exports';
|
|
2
|
+
/**
|
|
3
|
+
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
|
4
|
+
* Delete matching properties from current target.
|
|
5
|
+
*
|
|
6
|
+
* _Note: Deletes by reference_
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Run the plugin to get all the projects
|
|
10
|
+
* const { projects } = await createNodes[1](
|
|
11
|
+
* playwrightConfigPath,
|
|
12
|
+
* { targetName, ciTargetName: 'e2e-ci' },
|
|
13
|
+
* { workspaceRoot: tree.root, nxJsonConfiguration, configFiles }
|
|
14
|
+
* );
|
|
15
|
+
*
|
|
16
|
+
* // Find the project that matches the one that is being migrated
|
|
17
|
+
* const createdProject = Object.entries(projects ?? {}).find(
|
|
18
|
+
* ([root]) => root === projectFromGraph.data.root
|
|
19
|
+
* )[1];
|
|
20
|
+
*
|
|
21
|
+
* // Get the created TargetConfiguration for the target being migrated
|
|
22
|
+
* const createdTarget: TargetConfiguration<RunCommandsOptions> =
|
|
23
|
+
* createdProject.targets[targetName];
|
|
24
|
+
*
|
|
25
|
+
* // Delete specific run-commands options
|
|
26
|
+
* delete createdTarget.command;
|
|
27
|
+
* delete createdTarget.options?.cwd;
|
|
28
|
+
*
|
|
29
|
+
* // Get the TargetConfiguration for the target being migrated from project.json
|
|
30
|
+
* const projectConfig = readProjectConfiguration(tree, projectName);
|
|
31
|
+
* let targetToMigrate = projectConfig.targets[targetName];
|
|
32
|
+
*
|
|
33
|
+
* // Merge the target defaults for the executor to the target being migrated
|
|
34
|
+
* target = mergeTargetConfigurations(targetToMigrate, targetDefaultsForExecutor);
|
|
35
|
+
*
|
|
36
|
+
* // Delete executor and any additional options that are no longer necessary
|
|
37
|
+
* delete target.executor;
|
|
38
|
+
* delete target.options?.config;
|
|
39
|
+
*
|
|
40
|
+
* // Run deleteMatchingProperties to delete further options that match what the plugin creates
|
|
41
|
+
* deleteMatchingProperties(target, createdTarget);
|
|
42
|
+
*
|
|
43
|
+
* // Delete the target if it is now empty, otherwise, set it to the updated TargetConfiguration
|
|
44
|
+
* if (Object.keys(target).length > 0) {
|
|
45
|
+
* projectConfig.targets[targetName] = target;
|
|
46
|
+
* } else {
|
|
47
|
+
* delete projectConfig.targets[targetName];
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* updateProjectConfiguration(tree, projectName, projectConfig);
|
|
51
|
+
*
|
|
52
|
+
* @param targetToMigrate The target from project.json
|
|
53
|
+
* @param createdTarget The target created by the Plugin
|
|
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;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processTargetOutputs = exports.deleteMatchingProperties = void 0;
|
|
4
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
5
|
+
/**
|
|
6
|
+
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
|
7
|
+
* Delete matching properties from current target.
|
|
8
|
+
*
|
|
9
|
+
* _Note: Deletes by reference_
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Run the plugin to get all the projects
|
|
13
|
+
* const { projects } = await createNodes[1](
|
|
14
|
+
* playwrightConfigPath,
|
|
15
|
+
* { targetName, ciTargetName: 'e2e-ci' },
|
|
16
|
+
* { workspaceRoot: tree.root, nxJsonConfiguration, configFiles }
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* // Find the project that matches the one that is being migrated
|
|
20
|
+
* const createdProject = Object.entries(projects ?? {}).find(
|
|
21
|
+
* ([root]) => root === projectFromGraph.data.root
|
|
22
|
+
* )[1];
|
|
23
|
+
*
|
|
24
|
+
* // Get the created TargetConfiguration for the target being migrated
|
|
25
|
+
* const createdTarget: TargetConfiguration<RunCommandsOptions> =
|
|
26
|
+
* createdProject.targets[targetName];
|
|
27
|
+
*
|
|
28
|
+
* // Delete specific run-commands options
|
|
29
|
+
* delete createdTarget.command;
|
|
30
|
+
* delete createdTarget.options?.cwd;
|
|
31
|
+
*
|
|
32
|
+
* // Get the TargetConfiguration for the target being migrated from project.json
|
|
33
|
+
* const projectConfig = readProjectConfiguration(tree, projectName);
|
|
34
|
+
* let targetToMigrate = projectConfig.targets[targetName];
|
|
35
|
+
*
|
|
36
|
+
* // Merge the target defaults for the executor to the target being migrated
|
|
37
|
+
* target = mergeTargetConfigurations(targetToMigrate, targetDefaultsForExecutor);
|
|
38
|
+
*
|
|
39
|
+
* // Delete executor and any additional options that are no longer necessary
|
|
40
|
+
* delete target.executor;
|
|
41
|
+
* delete target.options?.config;
|
|
42
|
+
*
|
|
43
|
+
* // Run deleteMatchingProperties to delete further options that match what the plugin creates
|
|
44
|
+
* deleteMatchingProperties(target, createdTarget);
|
|
45
|
+
*
|
|
46
|
+
* // Delete the target if it is now empty, otherwise, set it to the updated TargetConfiguration
|
|
47
|
+
* if (Object.keys(target).length > 0) {
|
|
48
|
+
* projectConfig.targets[targetName] = target;
|
|
49
|
+
* } else {
|
|
50
|
+
* delete projectConfig.targets[targetName];
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* updateProjectConfiguration(tree, projectName, projectConfig);
|
|
54
|
+
*
|
|
55
|
+
* @param targetToMigrate The target from project.json
|
|
56
|
+
* @param createdTarget The target created by the Plugin
|
|
57
|
+
*/
|
|
58
|
+
function deleteMatchingProperties(targetToMigrate, createdTarget) {
|
|
59
|
+
for (const key in targetToMigrate) {
|
|
60
|
+
if (Array.isArray(targetToMigrate[key])) {
|
|
61
|
+
if (targetToMigrate[key].every((v) => createdTarget[key]?.includes(v)) &&
|
|
62
|
+
targetToMigrate[key].length === createdTarget[key]?.length) {
|
|
63
|
+
delete targetToMigrate[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (typeof targetToMigrate[key] === 'object' &&
|
|
67
|
+
typeof createdTarget[key] === 'object') {
|
|
68
|
+
deleteMatchingProperties(targetToMigrate[key], createdTarget[key]);
|
|
69
|
+
}
|
|
70
|
+
else if (targetToMigrate[key] === createdTarget[key]) {
|
|
71
|
+
delete targetToMigrate[key];
|
|
72
|
+
}
|
|
73
|
+
if (typeof targetToMigrate[key] === 'object' &&
|
|
74
|
+
Object.keys(targetToMigrate[key]).length === 0) {
|
|
75
|
+
delete targetToMigrate[key];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
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
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Tree } from 'nx/src/generators/tree';
|
|
1
|
+
import { ProjectType, Tree } from 'nx/src/devkit-exports';
|
|
3
2
|
export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
|
|
4
3
|
export type ProjectGenerationOptions = {
|
|
5
4
|
name: string;
|
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setCwd = exports.determineProjectNameAndRootOptions = void 0;
|
|
4
4
|
const enquirer_1 = require("enquirer");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const nx_1 = require("../../nx");
|
|
7
6
|
const get_workspace_layout_1 = require("../utils/get-workspace-layout");
|
|
8
7
|
const names_1 = require("../utils/names");
|
|
9
|
-
const
|
|
8
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
10
9
|
async function determineProjectNameAndRootOptions(tree, options) {
|
|
11
10
|
if (!options.projectNameAndRootFormat &&
|
|
12
11
|
(process.env.NX_INTERACTIVE !== 'true' || !isTTY())) {
|
|
@@ -45,8 +44,8 @@ function validateName(name, projectNameAndRootFormat) {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
function logDeprecationMessage(callingGenerator, formats) {
|
|
48
|
-
logger.warn(stripIndents `
|
|
49
|
-
In Nx
|
|
47
|
+
devkit_exports_1.logger.warn((0, devkit_exports_1.stripIndents) `
|
|
48
|
+
In Nx 20, generating projects will no longer derive the name and root.
|
|
50
49
|
Please provide the exact project name and root in the future.
|
|
51
50
|
Example: nx g ${callingGenerator} ${formats['derived'].projectName} --directory ${formats['derived'].projectRoot}
|
|
52
51
|
`);
|
|
@@ -86,7 +85,7 @@ async function determineFormat(formats) {
|
|
|
86
85
|
}
|
|
87
86
|
function getProjectNameAndRootFormats(tree, options) {
|
|
88
87
|
const directory = options.directory
|
|
89
|
-
? normalizePath(options.directory.replace(/^\.?\//, ''))
|
|
88
|
+
? (0, devkit_exports_1.normalizePath)(options.directory.replace(/^\.?\//, ''))
|
|
90
89
|
: undefined;
|
|
91
90
|
const { name: asProvidedParsedName, directory: asProvidedParsedDirectory } = parseNameForAsProvided(options.name);
|
|
92
91
|
if (asProvidedParsedDirectory && directory) {
|
|
@@ -106,7 +105,7 @@ function getProjectNameAndRootFormats(tree, options) {
|
|
|
106
105
|
}
|
|
107
106
|
if (asProvidedOptions.projectName.startsWith('@')) {
|
|
108
107
|
if (!options.projectNameAndRootFormat) {
|
|
109
|
-
output.warn({
|
|
108
|
+
devkit_exports_1.output.warn({
|
|
110
109
|
title: `The provided name "${options.name}" contains a scoped project name and this is not supported by the "${options.callingGenerator}" when using the "derived" format.`,
|
|
111
110
|
bodyLines: [
|
|
112
111
|
`The generator will try to generate the project "${asProvidedOptions.projectName}" using the "as-provided" format at "${asProvidedOptions.projectRoot}".`,
|
|
@@ -152,7 +151,7 @@ function getAsProvidedOptions(tree, options) {
|
|
|
152
151
|
projectRoot = options.directory;
|
|
153
152
|
}
|
|
154
153
|
else {
|
|
155
|
-
projectRoot = joinPathFragments(relativeCwd, options.directory);
|
|
154
|
+
projectRoot = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.directory);
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
else if (options.rootProject) {
|
|
@@ -162,7 +161,7 @@ function getAsProvidedOptions(tree, options) {
|
|
|
162
161
|
projectRoot = relativeCwd;
|
|
163
162
|
// append the project name to the current working directory if it doesn't end with it
|
|
164
163
|
if (!relativeCwd.endsWith(options.name)) {
|
|
165
|
-
projectRoot = joinPathFragments(relativeCwd, options.name);
|
|
164
|
+
projectRoot = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.name);
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
167
|
let importPath = undefined;
|
|
@@ -176,7 +175,7 @@ function getAsProvidedOptions(tree, options) {
|
|
|
176
175
|
const npmScope = getNpmScope(tree);
|
|
177
176
|
importPath =
|
|
178
177
|
projectRoot === '.'
|
|
179
|
-
? readJson(tree, 'package.json').name ??
|
|
178
|
+
? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
|
|
180
179
|
getImportPath(npmScope, options.name)
|
|
181
180
|
: getImportPath(npmScope, options.name);
|
|
182
181
|
}
|
|
@@ -208,7 +207,7 @@ function getDerivedOptions(tree, options) {
|
|
|
208
207
|
let projectRoot = projectDirectoryWithoutLayout;
|
|
209
208
|
if (projectDirectoryWithoutLayout !== '.') {
|
|
210
209
|
// prepend the layout directory
|
|
211
|
-
projectRoot = joinPathFragments(layoutDirectory, projectRoot);
|
|
210
|
+
projectRoot = (0, devkit_exports_1.joinPathFragments)(layoutDirectory, projectRoot);
|
|
212
211
|
}
|
|
213
212
|
let importPath;
|
|
214
213
|
if (options.projectType === 'library') {
|
|
@@ -217,7 +216,7 @@ function getDerivedOptions(tree, options) {
|
|
|
217
216
|
const npmScope = getNpmScope(tree);
|
|
218
217
|
importPath =
|
|
219
218
|
projectRoot === '.'
|
|
220
|
-
? readJson(tree, 'package.json').name ??
|
|
219
|
+
? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
|
|
221
220
|
getImportPath(npmScope, projectName)
|
|
222
221
|
: getImportPath(npmScope, projectDirectoryWithoutLayout);
|
|
223
222
|
}
|
|
@@ -245,7 +244,7 @@ function getImportPath(npmScope, name) {
|
|
|
245
244
|
}
|
|
246
245
|
function getNpmScope(tree) {
|
|
247
246
|
const { name } = tree.exists('package.json')
|
|
248
|
-
? readJson(tree, 'package.json')
|
|
247
|
+
? (0, devkit_exports_1.readJson)(tree, 'package.json')
|
|
249
248
|
: { name: null };
|
|
250
249
|
return name?.startsWith('@') ? name.split('/')[0].substring(1) : undefined;
|
|
251
250
|
}
|
|
@@ -259,22 +258,22 @@ function isTTY() {
|
|
|
259
258
|
* environment variable (see here: https://docs.npmjs.com/cli/v9/commands/npm-run-script#description).
|
|
260
259
|
*/
|
|
261
260
|
function getCwd() {
|
|
262
|
-
return process.env.INIT_CWD?.startsWith(workspaceRoot)
|
|
261
|
+
return process.env.INIT_CWD?.startsWith(devkit_exports_1.workspaceRoot)
|
|
263
262
|
? process.env.INIT_CWD
|
|
264
263
|
: process.cwd();
|
|
265
264
|
}
|
|
266
265
|
function getRelativeCwd() {
|
|
267
|
-
return normalizePath((0, path_1.relative)(workspaceRoot, getCwd())).replace(/\/$/, '');
|
|
266
|
+
return (0, devkit_exports_1.normalizePath)((0, path_1.relative)(devkit_exports_1.workspaceRoot, getCwd())).replace(/\/$/, '');
|
|
268
267
|
}
|
|
269
268
|
/**
|
|
270
269
|
* Function for setting cwd during testing
|
|
271
270
|
*/
|
|
272
271
|
function setCwd(path) {
|
|
273
|
-
process.env.INIT_CWD = (0, path_1.join)(workspaceRoot, path);
|
|
272
|
+
process.env.INIT_CWD = (0, path_1.join)(devkit_exports_1.workspaceRoot, path);
|
|
274
273
|
}
|
|
275
274
|
exports.setCwd = setCwd;
|
|
276
275
|
function parseNameForAsProvided(rawName) {
|
|
277
|
-
const directory = normalizePath(rawName);
|
|
276
|
+
const directory = (0, devkit_exports_1.normalizePath)(rawName);
|
|
278
277
|
if (rawName.includes('@')) {
|
|
279
278
|
const index = directory.lastIndexOf('@');
|
|
280
279
|
if (index === 0) {
|
|
@@ -291,7 +290,7 @@ function parseNameForAsProvided(rawName) {
|
|
|
291
290
|
return { name: rawName, directory: undefined };
|
|
292
291
|
}
|
|
293
292
|
function parseNameForDerived(rawName) {
|
|
294
|
-
const parsedName = normalizePath(rawName).split('/');
|
|
293
|
+
const parsedName = (0, devkit_exports_1.normalizePath)(rawName).split('/');
|
|
295
294
|
const name = parsedName.pop();
|
|
296
295
|
const directory = parsedName.length ? parsedName.join('/') : undefined;
|
|
297
296
|
return { name, directory };
|