@nx/devkit 19.0.3 → 19.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/devkit",
3
- "version": "19.0.3",
3
+ "version": "19.0.5",
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.3"
39
+ "@nrwl/devkit": "19.0.5"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "nx": ">= 17 <= 20"
@@ -1,10 +1,7 @@
1
- import type { ConfigurationResult } from 'nx/src/project-graph/utils/project-configuration-utils';
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>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.retrieveProjectConfigurationsWithPartialResult = exports.generateCombinations = exports.addPlugin = void 0;
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 projConfigsWithExistingNxJsonPlugins;
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
- const [nxJsonPlugins] = await (0, devkit_internals_1.loadNxPlugins)(nxJson.plugins, tree.root, true);
29
- projConfigsWithExistingNxJsonPlugins =
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
- const [corePlugins] = await (0, devkit_internals_1.loadNxPlugins)([], tree.root);
42
- projConfigsWithCorePlugins =
43
- await retrieveProjectConfigurationsWithPartialResult(corePlugins, tree.root, nxJson);
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(projConfigsWithNewPlugin.projects)) {
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
- const existingPluginCreatedTarget = projConfigsWithExistingNxJsonPlugins?.projects?.[projConfig.root]
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, projConfigsWithNewPlugin);
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;
@@ -24,8 +24,8 @@ async function* combineAsyncIterables(..._iterators) {
24
24
  iterators.shift();
25
25
  }
26
26
  const getNextAsyncIteratorValue = getNextAsyncIteratorFactory(options);
27
+ const asyncIteratorsValues = new Map(iterators.map((it, idx) => [idx, getNextAsyncIteratorValue(it, idx)]));
27
28
  try {
28
- const asyncIteratorsValues = new Map(iterators.map((it, idx) => [idx, getNextAsyncIteratorValue(it, idx)]));
29
29
  do {
30
30
  const { iterator, index } = await Promise.race(asyncIteratorsValues.values());
31
31
  if (iterator.done) {
@@ -38,7 +38,9 @@ async function* combineAsyncIterables(..._iterators) {
38
38
  } while (asyncIteratorsValues.size > 0);
39
39
  }
40
40
  finally {
41
- await Promise.allSettled(iterators.map((it) => it['return']?.()));
41
+ for (const [index, iterator] of asyncIteratorsValues.entries())
42
+ if (iterator?.['return'] !== null)
43
+ iterator['return']?.();
42
44
  }
43
45
  }
44
46
  exports.combineAsyncIterables = combineAsyncIterables;