@nx/devkit 19.0.0-rc.0 → 19.0.0-rc.1

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.0-rc.0",
3
+ "version": "19.0.0-rc.1",
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.0-rc.0"
39
+ "@nrwl/devkit": "19.0.0-rc.1"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "nx": ">= 17 <= 20"
@@ -1,5 +1,5 @@
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_configFiles, _ExecutorToPluginMigrator_createNodesResultsForTargets, _ExecutorToPluginMigrator_init, _ExecutorToPluginMigrator_migrateTarget, _ExecutorToPluginMigrator_migrateProject, _ExecutorToPluginMigrator_addPlugins, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot, _ExecutorToPluginMigrator_getCreateNodesResults;
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_configFiles, _ExecutorToPluginMigrator_createNodesResultsForTargets, _ExecutorToPluginMigrator_init, _ExecutorToPluginMigrator_migrateTarget, _ExecutorToPluginMigrator_migrateProject, _ExecutorToPluginMigrator_pluginRequiresIncludes, _ExecutorToPluginMigrator_addPlugins, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot, _ExecutorToPluginMigrator_getCreateNodesResults;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.migrateExecutorToPlugin = void 0;
5
5
  const tslib_1 = require("tslib");
@@ -41,7 +41,7 @@ class ExecutorToPluginMigrator {
41
41
  for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
42
42
  tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateTarget).call(this, targetName);
43
43
  }
44
- tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_addPlugins).call(this);
44
+ await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_addPlugins).call(this);
45
45
  }
46
46
  return tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f");
47
47
  }
@@ -93,7 +93,26 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
93
93
  }
94
94
  (0, devkit_exports_1.updateProjectConfiguration)(this.tree, projectName, projectConfig);
95
95
  return `${projectFromGraph.data.root}/**/*`;
96
- }, _ExecutorToPluginMigrator_addPlugins = function _ExecutorToPluginMigrator_addPlugins() {
96
+ }, _ExecutorToPluginMigrator_pluginRequiresIncludes = async function _ExecutorToPluginMigrator_pluginRequiresIncludes(targetName, plugin) {
97
+ const loadedPlugin = new devkit_internals_1.LoadedNxPlugin({
98
+ createNodes: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodes, "f"),
99
+ name: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
100
+ }, plugin);
101
+ const originalResults = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").get(targetName);
102
+ let resultsWithIncludes;
103
+ try {
104
+ resultsWithIncludes = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], this.tree.root, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
105
+ }
106
+ catch (e) {
107
+ if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
108
+ resultsWithIncludes = e.partialProjectConfigurationsResult;
109
+ }
110
+ else {
111
+ throw e;
112
+ }
113
+ }
114
+ return !deepEqual(originalResults, resultsWithIncludes);
115
+ }, _ExecutorToPluginMigrator_addPlugins = async function _ExecutorToPluginMigrator_addPlugins() {
97
116
  for (const [targetName, plugin] of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").entries()) {
98
117
  const pluginOptions = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName);
99
118
  const existingPlugin = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.find((plugin) => {
@@ -109,35 +128,18 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
109
128
  return true;
110
129
  });
111
130
  if (existingPlugin?.include) {
112
- for (const pluginIncludes of existingPlugin.include) {
113
- for (const projectPath of plugin.include) {
114
- if (!(0, minimatch_1.minimatch)(projectPath, pluginIncludes, { dot: true })) {
115
- existingPlugin.include.push(projectPath);
116
- }
117
- }
118
- }
119
- const allConfigFilesAreIncluded = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_configFiles, "f").every((configFile) => {
120
- for (const includePattern of existingPlugin.include) {
121
- if ((0, minimatch_1.minimatch)(configFile, includePattern, { dot: true })) {
122
- return true;
123
- }
124
- }
125
- return false;
126
- });
127
- if (allConfigFilesAreIncluded) {
128
- existingPlugin.include = undefined;
131
+ // Add to the existing plugin includes
132
+ existingPlugin.include = existingPlugin.include.concat(
133
+ // Any include that is in the new plugin's include list
134
+ plugin.include.filter((projectPath) =>
135
+ // And is not already covered by the existing plugin's include list
136
+ !existingPlugin.include.some((pluginIncludes) => (0, minimatch_1.minimatch)(projectPath, pluginIncludes, { dot: true }))));
137
+ if (!(await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_pluginRequiresIncludes).call(this, targetName, existingPlugin))) {
138
+ delete existingPlugin.include;
129
139
  }
130
140
  }
131
141
  if (!existingPlugin) {
132
- const allConfigFilesAreIncluded = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_configFiles, "f").every((configFile) => {
133
- for (const includePattern of plugin.include) {
134
- if ((0, minimatch_1.minimatch)(configFile, includePattern, { dot: true })) {
135
- return true;
136
- }
137
- }
138
- return false;
139
- });
140
- if (allConfigFilesAreIncluded) {
142
+ if (!(await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_pluginRequiresIncludes).call(this, targetName, plugin))) {
141
143
  plugin.include = undefined;
142
144
  }
143
145
  tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.push(plugin);
@@ -174,8 +176,12 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
174
176
  }, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor = function _ExecutorToPluginMigrator_getTargetDefaultsForExecutor() {
175
177
  tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").targetDefaults?.[tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")], "f");
176
178
  }, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot = function _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot(targetName, projectRoot) {
177
- const createdProject = Object.entries(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").get(targetName)?.projects ?? {}).find(([root]) => root === projectRoot)[1];
178
- const createdTarget = createdProject.targets[targetName];
179
+ const entry = Object.entries(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").get(targetName)?.projects ?? {}).find(([root]) => root === projectRoot);
180
+ if (!entry) {
181
+ 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.`);
182
+ }
183
+ const createdProject = entry[1];
184
+ const createdTarget = structuredClone(createdProject.targets[targetName]);
179
185
  delete createdTarget.command;
180
186
  delete createdTarget.options?.cwd;
181
187
  return createdTarget;
@@ -212,3 +218,26 @@ async function migrateExecutorToPlugin(tree, projectGraph, executor, pluginPath,
212
218
  return await migrator.run();
213
219
  }
214
220
  exports.migrateExecutorToPlugin = migrateExecutorToPlugin;
221
+ // Checks if two objects are structurely equal, without caring
222
+ // about the order of the keys.
223
+ function deepEqual(a, b, logKey = '') {
224
+ const aKeys = Object.keys(a);
225
+ const bKeys = new Set(Object.keys(b));
226
+ if (aKeys.length !== bKeys.size) {
227
+ return false;
228
+ }
229
+ for (const key of aKeys) {
230
+ if (!bKeys.has(key)) {
231
+ return false;
232
+ }
233
+ if (typeof a[key] === 'object' && typeof b[key] === 'object') {
234
+ if (!deepEqual(a[key], b[key], logKey + '.' + key)) {
235
+ return false;
236
+ }
237
+ }
238
+ else if (a[key] !== b[key]) {
239
+ return false;
240
+ }
241
+ }
242
+ return true;
243
+ }