@nx/devkit 19.1.1 → 19.1.2

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.1.1",
3
+ "version": "19.1.2",
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.1.1"
39
+ "@nrwl/devkit": "19.1.2"
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?: Tree, projectDetails?: {
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 {};
@@ -1,9 +1,10 @@
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_pluginRequiresIncludes, _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_mergeInputs, _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");
6
6
  const minimatch_1 = require("minimatch");
7
+ const node_assert_1 = require("node:assert");
7
8
  const executor_options_utils_1 = require("../executor-options-utils");
8
9
  const plugin_migration_utils_1 = require("./plugin-migration-utils");
9
10
  const devkit_exports_1 = require("nx/src/devkit-exports");
@@ -74,10 +75,10 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
74
75
  projectTarget = (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
75
76
  delete projectTarget.executor;
76
77
  (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
- });
78
+ if (projectTarget.inputs && createdTarget.inputs) {
79
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_mergeInputs).call(this, projectTarget, createdTarget);
80
+ }
81
+ projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree, { projectName, root: projectFromGraph.data.root }, createdTarget);
81
82
  if (projectTarget.options &&
82
83
  Object.keys(projectTarget.options).length === 0) {
83
84
  delete projectTarget.options;
@@ -93,6 +94,41 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
93
94
  }
94
95
  (0, devkit_exports_1.updateProjectConfiguration)(this.tree, projectName, projectConfig);
95
96
  return `${projectFromGraph.data.root}/**/*`;
97
+ }, _ExecutorToPluginMigrator_mergeInputs = function _ExecutorToPluginMigrator_mergeInputs(target, inferredTarget) {
98
+ const isInputInferred = (input) => {
99
+ return inferredTarget.inputs.some((inferredInput) => {
100
+ try {
101
+ (0, node_assert_1.deepStrictEqual)(input, inferredInput);
102
+ return true;
103
+ }
104
+ catch {
105
+ return false;
106
+ }
107
+ });
108
+ };
109
+ if (target.inputs.every(isInputInferred)) {
110
+ delete target.inputs;
111
+ return;
112
+ }
113
+ const inferredTargetExternalDependencyInput = inferredTarget.inputs.find((i) => typeof i !== 'string' && 'externalDependencies' in i);
114
+ if (!inferredTargetExternalDependencyInput) {
115
+ // plugins should normally have an externalDependencies input, but if it
116
+ // doesn't, there's nothing to merge
117
+ return;
118
+ }
119
+ const targetExternalDependencyInput = target.inputs.find((i) => typeof i !== 'string' && 'externalDependencies' in i);
120
+ if (!targetExternalDependencyInput) {
121
+ // the target doesn't have an externalDependencies input, so we can just
122
+ // add the inferred one
123
+ target.inputs.push(inferredTargetExternalDependencyInput);
124
+ }
125
+ else {
126
+ // the target has an externalDependencies input, so we need to merge them
127
+ targetExternalDependencyInput.externalDependencies = Array.from(new Set([
128
+ ...targetExternalDependencyInput.externalDependencies,
129
+ ...inferredTargetExternalDependencyInput.externalDependencies,
130
+ ]));
131
+ }
96
132
  }, _ExecutorToPluginMigrator_pluginRequiresIncludes = async function _ExecutorToPluginMigrator_pluginRequiresIncludes(targetName, plugin) {
97
133
  const loadedPlugin = new devkit_internals_1.LoadedNxPlugin({
98
134
  createNodes: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodes, "f"),
@@ -174,7 +210,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
174
210
  }
175
211
  });
176
212
  }, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor = function _ExecutorToPluginMigrator_getTargetDefaultsForExecutor() {
177
- tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").targetDefaults?.[tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")], "f");
213
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, structuredClone(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").targetDefaults?.[tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")]), "f");
178
214
  }, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot = function _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot(targetName, projectRoot) {
179
215
  const entry = Object.entries(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").get(targetName)?.projects ?? {}).find(([root]) => root === projectRoot);
180
216
  if (!entry) {
@@ -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
+ }