@nx/devkit 19.0.3 → 19.1.0-beta.0
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/utils/add-plugin.d.ts +2 -5
- package/src/utils/add-plugin.js +23 -38
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/devkit",
|
3
|
-
"version": "19.0.
|
3
|
+
"version": "19.1.0-beta.0",
|
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.0.
|
39
|
+
"@nrwl/devkit": "19.1.0-beta.0"
|
40
40
|
},
|
41
41
|
"peerDependencies": {
|
42
42
|
"nx": ">= 17 <= 20"
|
@@ -1,10 +1,7 @@
|
|
1
|
-
import
|
2
|
-
import { CreateNodes, NxJsonConfiguration, Tree } from 'nx/src/devkit-exports';
|
3
|
-
import { LoadedNxPlugin } from 'nx/src/devkit-internals';
|
1
|
+
import { CreateNodes, ProjectGraph, Tree } from 'nx/src/devkit-exports';
|
4
2
|
/**
|
5
3
|
* Iterates through various forms of plugin options to find the one which does not conflict with the current graph
|
6
4
|
|
7
5
|
*/
|
8
|
-
export declare function addPlugin<PluginOptions>(tree: Tree, pluginName: string, createNodesTuple: CreateNodes<PluginOptions>, options: Partial<Record<keyof PluginOptions, PluginOptions[keyof PluginOptions][]>>, shouldUpdatePackageJsonScripts: boolean): Promise<void>;
|
6
|
+
export declare function addPlugin<PluginOptions>(tree: Tree, graph: ProjectGraph, pluginName: string, createNodesTuple: CreateNodes<PluginOptions>, options: Partial<Record<keyof PluginOptions, PluginOptions[keyof PluginOptions][]>>, shouldUpdatePackageJsonScripts: boolean): Promise<void>;
|
9
7
|
export declare function generateCombinations<T>(input: Record<string, T[]>): Record<string, T>[];
|
10
|
-
export declare function retrieveProjectConfigurationsWithPartialResult(plugins: LoadedNxPlugin[], workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
|
package/src/utils/add-plugin.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.generateCombinations = exports.addPlugin = void 0;
|
4
4
|
const yargs = require("yargs-parser");
|
5
5
|
const devkit_exports_1 = require("nx/src/devkit-exports");
|
6
6
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
@@ -8,12 +8,11 @@ const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
8
|
* Iterates through various forms of plugin options to find the one which does not conflict with the current graph
|
9
9
|
|
10
10
|
*/
|
11
|
-
async function addPlugin(tree, pluginName, createNodesTuple, options, shouldUpdatePackageJsonScripts) {
|
11
|
+
async function addPlugin(tree, graph, pluginName, createNodesTuple, options, shouldUpdatePackageJsonScripts) {
|
12
|
+
const graphNodes = Object.values(graph.nodes);
|
12
13
|
const nxJson = (0, devkit_exports_1.readNxJson)(tree);
|
13
14
|
let pluginOptions;
|
14
|
-
let
|
15
|
-
let projConfigsWithNewPlugin;
|
16
|
-
let projConfigsWithCorePlugins;
|
15
|
+
let projConfigs;
|
17
16
|
const combinations = generateCombinations(options);
|
18
17
|
optionsLoop: for (const _pluginOptions of combinations) {
|
19
18
|
pluginOptions = _pluginOptions;
|
@@ -25,11 +24,8 @@ async function addPlugin(tree, pluginName, createNodesTuple, options, shouldUpda
|
|
25
24
|
return;
|
26
25
|
}
|
27
26
|
global.NX_GRAPH_CREATION = true;
|
28
|
-
|
29
|
-
|
30
|
-
await retrieveProjectConfigurationsWithPartialResult(nxJsonPlugins, tree.root, nxJson);
|
31
|
-
projConfigsWithNewPlugin =
|
32
|
-
await retrieveProjectConfigurationsWithPartialResult([
|
27
|
+
try {
|
28
|
+
projConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([
|
33
29
|
new devkit_internals_1.LoadedNxPlugin({
|
34
30
|
name: pluginName,
|
35
31
|
createNodes: createNodesTuple,
|
@@ -38,18 +34,24 @@ async function addPlugin(tree, pluginName, createNodesTuple, options, shouldUpda
|
|
38
34
|
options: pluginOptions,
|
39
35
|
}),
|
40
36
|
], tree.root, nxJson);
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
}
|
38
|
+
catch (e) {
|
39
|
+
// Errors are okay for this because we're only running 1 plugin
|
40
|
+
if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
|
41
|
+
projConfigs = e.partialProjectConfigurationsResult;
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
throw e;
|
45
|
+
}
|
46
|
+
}
|
44
47
|
global.NX_GRAPH_CREATION = false;
|
45
|
-
for (const projConfig of Object.values(
|
48
|
+
for (const projConfig of Object.values(projConfigs.projects)) {
|
49
|
+
const node = graphNodes.find((node) => node.data.root === projConfig.root);
|
50
|
+
if (!node) {
|
51
|
+
continue;
|
52
|
+
}
|
46
53
|
for (const targetName in projConfig.targets) {
|
47
|
-
|
48
|
-
?.targets?.[targetName];
|
49
|
-
const corePluginsCreatedTarget = projConfigsWithCorePlugins?.projects?.[projConfig.root]?.targets?.[targetName];
|
50
|
-
if (existingPluginCreatedTarget ||
|
51
|
-
(corePluginsCreatedTarget &&
|
52
|
-
!(0, devkit_internals_1.deepEquals)(corePluginsCreatedTarget, (0, devkit_internals_1.mergeTargetConfigurations)(corePluginsCreatedTarget, projConfig.targets[targetName])))) {
|
54
|
+
if (node.data.targets[targetName]) {
|
53
55
|
// Conflicting Target Name, check the next one
|
54
56
|
pluginOptions = null;
|
55
57
|
continue optionsLoop;
|
@@ -67,7 +69,7 @@ async function addPlugin(tree, pluginName, createNodesTuple, options, shouldUpda
|
|
67
69
|
});
|
68
70
|
(0, devkit_exports_1.updateNxJson)(tree, nxJson);
|
69
71
|
if (shouldUpdatePackageJsonScripts) {
|
70
|
-
updatePackageScripts(tree,
|
72
|
+
updatePackageScripts(tree, projConfigs);
|
71
73
|
}
|
72
74
|
}
|
73
75
|
exports.addPlugin = addPlugin;
|
@@ -238,20 +240,3 @@ function _generateCombinations(input) {
|
|
238
240
|
return first.flatMap((value) => partialCombinations.map((combination) => [value, ...combination]));
|
239
241
|
}
|
240
242
|
}
|
241
|
-
async function retrieveProjectConfigurationsWithPartialResult(plugins, workspaceRoot, nxJson) {
|
242
|
-
let projConfigs;
|
243
|
-
try {
|
244
|
-
projConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)(plugins, workspaceRoot, nxJson);
|
245
|
-
}
|
246
|
-
catch (e) {
|
247
|
-
// Errors are okay for this because we're only running 1 plugin
|
248
|
-
if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
|
249
|
-
projConfigs = e.partialProjectConfigurationsResult;
|
250
|
-
}
|
251
|
-
else {
|
252
|
-
throw e;
|
253
|
-
}
|
254
|
-
}
|
255
|
-
return projConfigs;
|
256
|
-
}
|
257
|
-
exports.retrieveProjectConfigurationsWithPartialResult = retrieveProjectConfigurationsWithPartialResult;
|