@nx/devkit 19.0.0-canary.20240430-458f2cc → 19.0.0-canary.20240503-dbad02a

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.
Files changed (53) hide show
  1. package/package.json +3 -3
  2. package/src/executors/parse-target-string.d.ts +1 -3
  3. package/src/executors/parse-target-string.js +5 -9
  4. package/src/executors/read-target-options.d.ts +1 -2
  5. package/src/executors/read-target-options.js +4 -17
  6. package/src/generators/add-build-target-defaults.d.ts +1 -1
  7. package/src/generators/add-build-target-defaults.js +3 -4
  8. package/src/generators/artifact-name-and-directory-utils.d.ts +1 -1
  9. package/src/generators/artifact-name-and-directory-utils.js +24 -24
  10. package/src/generators/executor-options-utils.d.ts +1 -2
  11. package/src/generators/executor-options-utils.js +3 -6
  12. package/src/generators/format-files.d.ts +1 -1
  13. package/src/generators/format-files.js +5 -8
  14. package/src/generators/generate-files.d.ts +1 -1
  15. package/src/generators/generate-files.js +2 -3
  16. package/src/generators/plugin-migrations/executor-to-plugin-migrator.d.ts +3 -6
  17. package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +22 -21
  18. package/src/generators/project-name-and-root-utils.d.ts +1 -2
  19. package/src/generators/project-name-and-root-utils.js +16 -17
  20. package/src/generators/run-tasks-in-serial.d.ts +1 -1
  21. package/src/generators/to-js.d.ts +1 -1
  22. package/src/generators/update-ts-configs-to-js.d.ts +1 -1
  23. package/src/generators/update-ts-configs-to-js.js +3 -4
  24. package/src/generators/visit-not-ignored-files.d.ts +1 -1
  25. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +1 -1
  26. package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +1 -2
  27. package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +2 -3
  28. package/src/tasks/install-packages-task.d.ts +1 -2
  29. package/src/tasks/install-packages-task.js +5 -6
  30. package/src/utils/add-plugin.d.ts +1 -1
  31. package/src/utils/add-plugin.js +9 -9
  32. package/src/utils/calculate-hash-for-create-nodes.d.ts +1 -1
  33. package/src/utils/calculate-hash-for-create-nodes.js +5 -5
  34. package/src/utils/config-utils.js +5 -5
  35. package/src/utils/convert-nx-executor.d.ts +1 -1
  36. package/src/utils/convert-nx-executor.js +19 -29
  37. package/src/utils/get-named-inputs.d.ts +1 -1
  38. package/src/utils/get-named-inputs.js +3 -4
  39. package/src/utils/get-workspace-layout.d.ts +1 -1
  40. package/src/utils/get-workspace-layout.js +2 -3
  41. package/src/utils/invoke-nx-generator.d.ts +1 -1
  42. package/src/utils/invoke-nx-generator.js +3 -5
  43. package/src/utils/log-show-project-command.js +2 -3
  44. package/src/utils/move-dir.d.ts +1 -1
  45. package/src/utils/move-dir.js +3 -4
  46. package/src/utils/package-json.d.ts +1 -2
  47. package/src/utils/package-json.js +13 -13
  48. package/src/utils/replace-package.d.ts +1 -1
  49. package/src/utils/replace-package.js +7 -9
  50. package/src/utils/replace-project-configuration-with-plugin.d.ts +1 -1
  51. package/src/utils/replace-project-configuration-with-plugin.js +11 -11
  52. package/nx.d.ts +0 -1
  53. package/nx.js +0 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/devkit",
3
- "version": "19.0.0-canary.20240430-458f2cc",
3
+ "version": "19.0.0-canary.20240503-dbad02a",
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,10 +36,10 @@
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-canary.20240430-458f2cc"
39
+ "@nrwl/devkit": "19.0.0-canary.20240503-dbad02a"
40
40
  },
41
41
  "peerDependencies": {
42
- "nx": ">= 16 <= 19"
42
+ "nx": ">= 17 <= 20"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
@@ -1,6 +1,4 @@
1
- import type { Target } from 'nx/src/command-line/run/run';
2
- import type { ProjectGraph } from 'nx/src/config/project-graph';
3
- import type { ExecutorContext } from 'nx/src/devkit-exports';
1
+ import { ExecutorContext, ProjectGraph, Target } from 'nx/src/devkit-exports';
4
2
  /**
5
3
  * @deprecated(v17) A project graph should be passed to parseTargetString for best accuracy.
6
4
  */
@@ -1,32 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.targetToTargetString = exports.parseTargetString = void 0;
4
- const nx_1 = require("../../nx");
5
- let { readCachedProjectGraph, splitTarget, splitByColons } = (0, nx_1.requireNx)();
6
- // TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
7
- splitTarget = splitTarget ?? require('nx/src/utils/split-target').splitTarget;
8
- splitByColons =
9
- splitByColons ?? ((s) => s.split(':'));
4
+ const devkit_exports_1 = require("nx/src/devkit-exports");
5
+ const devkit_internals_1 = require("nx/src/devkit-internals");
10
6
  function parseTargetString(targetString, projectGraphOrCtx) {
11
7
  let projectGraph = projectGraphOrCtx && 'projectGraph' in projectGraphOrCtx
12
8
  ? projectGraphOrCtx.projectGraph
13
9
  : projectGraphOrCtx;
14
10
  if (!projectGraph) {
15
11
  try {
16
- projectGraph = readCachedProjectGraph();
12
+ projectGraph = (0, devkit_exports_1.readCachedProjectGraph)();
17
13
  }
18
14
  catch (e) {
19
15
  projectGraph = { nodes: {} };
20
16
  }
21
17
  }
22
- const [maybeProject] = splitByColons(targetString);
18
+ const [maybeProject] = (0, devkit_internals_1.splitByColons)(targetString);
23
19
  if (!projectGraph.nodes[maybeProject] &&
24
20
  projectGraphOrCtx &&
25
21
  'projectName' in projectGraphOrCtx &&
26
22
  maybeProject !== projectGraphOrCtx.projectName) {
27
23
  targetString = `${projectGraphOrCtx.projectName}:${targetString}`;
28
24
  }
29
- const [project, target, configuration] = splitTarget(targetString, projectGraph);
25
+ const [project, target, configuration] = (0, devkit_internals_1.splitTarget)(targetString, projectGraph);
30
26
  if (!project || !target) {
31
27
  throw new Error(`Invalid Target String: ${targetString}`);
32
28
  }
@@ -1,5 +1,4 @@
1
- import type { Target } from 'nx/src/command-line/run/run';
2
- import type { ExecutorContext } from 'nx/src/config/misc-interfaces';
1
+ import type { ExecutorContext, Target } from 'nx/src/devkit-exports';
3
2
  /**
4
3
  * Reads and combines options for a given target.
5
4
  *
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readTargetOptions = void 0;
4
- const nx_1 = require("../../nx");
5
4
  const path_1 = require("path");
6
- let { Workspaces, getExecutorInformation, calculateDefaultProjectName, combineOptionsForExecutor, } = (0, nx_1.requireNx)();
7
- // TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
8
- combineOptionsForExecutor =
9
- combineOptionsForExecutor ??
10
- require('nx/src/utils/params').combineOptionsForExecutor;
5
+ const devkit_internals_1 = require("nx/src/devkit-internals");
11
6
  /**
12
7
  * Reads and combines options for a given target.
13
8
  *
@@ -22,17 +17,9 @@ function readTargetOptions({ project, target, configuration }, context) {
22
17
  if (!targetConfiguration) {
23
18
  throw new Error(`Unable to find target ${target} for project ${project}`);
24
19
  }
25
- // TODO(v19): remove Workspaces.
26
- const ws = new Workspaces(context.root);
27
20
  const [nodeModule, executorName] = targetConfiguration.executor.split(':');
28
- const { schema } = getExecutorInformation
29
- ? getExecutorInformation(nodeModule, executorName, context.root, context.projectsConfigurations?.projects ?? context.workspace.projects)
30
- : // TODO(v19): remove readExecutor. This is to be backwards compatible with Nx 16.5 and below.
31
- ws.readExecutor(nodeModule, executorName);
32
- const defaultProject = calculateDefaultProjectName
33
- ? calculateDefaultProjectName(context.cwd, context.root, { version: 2, projects: context.projectsConfigurations.projects }, context.nxJsonConfiguration)
34
- : // TODO(v19): remove calculateDefaultProjectName. This is to be backwards compatible with Nx 16.5 and below.
35
- ws.calculateDefaultProjectName(context.cwd, { version: 2, projects: context.projectsConfigurations.projects }, context.nxJsonConfiguration);
36
- return combineOptionsForExecutor({}, configuration ?? targetConfiguration.defaultConfiguration ?? '', targetConfiguration, schema, defaultProject, (0, path_1.relative)(context.root, context.cwd));
21
+ const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.projects ?? context.workspace.projects);
22
+ const defaultProject = (0, devkit_internals_1.calculateDefaultProjectName)(context.cwd, context.root, { version: 2, projects: context.projectsConfigurations.projects }, context.nxJsonConfiguration);
23
+ return (0, devkit_internals_1.combineOptionsForExecutor)({}, configuration ?? targetConfiguration.defaultConfiguration ?? '', targetConfiguration, schema, defaultProject, (0, path_1.relative)(context.root, context.cwd));
37
24
  }
38
25
  exports.readTargetOptions = readTargetOptions;
@@ -1,2 +1,2 @@
1
- import type { Tree } from 'nx/src/devkit-exports';
1
+ import { Tree } from 'nx/src/devkit-exports';
2
2
  export declare function addBuildTargetDefaults(tree: Tree, executorName: string, buildTargetName?: string): void;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addBuildTargetDefaults = void 0;
4
- const nx_1 = require("../../nx");
5
- const { readNxJson, updateNxJson } = (0, nx_1.requireNx)();
4
+ const devkit_exports_1 = require("nx/src/devkit-exports");
6
5
  function addBuildTargetDefaults(tree, executorName, buildTargetName = 'build') {
7
- const nxJson = readNxJson(tree);
6
+ const nxJson = (0, devkit_exports_1.readNxJson)(tree);
8
7
  nxJson.targetDefaults ??= {};
9
8
  nxJson.targetDefaults[executorName] ??= {
10
9
  cache: true,
@@ -13,6 +12,6 @@ function addBuildTargetDefaults(tree, executorName, buildTargetName = 'build') {
13
12
  ? ['production', '^production']
14
13
  : ['default', '^default'],
15
14
  };
16
- updateNxJson(tree, nxJson);
15
+ (0, devkit_exports_1.updateNxJson)(tree, nxJson);
17
16
  }
18
17
  exports.addBuildTargetDefaults = addBuildTargetDefaults;
@@ -1,4 +1,4 @@
1
- import type { Tree } from 'nx/src/generators/tree';
1
+ import { Tree } from 'nx/src/devkit-exports';
2
2
  export type NameAndDirectoryFormat = 'as-provided' | 'derived';
3
3
  export type ArtifactGenerationOptions = {
4
4
  artifactType: string;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setCwd = exports.getRelativeCwd = exports.determineArtifactNameAndDirectoryOptions = 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 names_1 = require("../utils/names");
8
- const { createProjectRootMappingsFromProjectConfigurations, findProjectForPath, getProjects, joinPathFragments, logger, normalizePath, output, workspaceRoot, } = (0, nx_1.requireNx)();
7
+ const devkit_exports_1 = require("nx/src/devkit-exports");
8
+ const devkit_internals_1 = require("nx/src/devkit-internals");
9
9
  async function determineArtifactNameAndDirectoryOptions(tree, options) {
10
10
  if (!options.nameAndDirectoryFormat &&
11
11
  (process.env.NX_INTERACTIVE !== 'true' || !isTTY())) {
@@ -53,8 +53,8 @@ async function determineFormat(formats, options) {
53
53
  return result;
54
54
  }
55
55
  function logDeprecationMessage(options, formats) {
56
- logger.warn(`
57
- In Nx 19, generating a ${options.artifactType} will no longer support providing a project and deriving the directory.
56
+ devkit_exports_1.logger.warn(`
57
+ In Nx 20, generating a ${options.artifactType} will no longer support providing a project and deriving the directory.
58
58
  Please provide the exact directory in the future.
59
59
  Example: nx g ${options.callingGenerator} ${formats['derived'].artifactName} --directory ${formats['derived'].directory}
60
60
  NOTE: The example above assumes the command is being run from the workspace root. If the command is being run from a subdirectory, the directory option should be adjusted accordingly.
@@ -62,7 +62,7 @@ NOTE: The example above assumes the command is being run from the workspace root
62
62
  }
63
63
  function getNameAndDirectoryOptionFormats(tree, options) {
64
64
  const directory = options.directory
65
- ? normalizePath(options.directory.replace(/^\.?\//, ''))
65
+ ? (0, devkit_exports_1.normalizePath)(options.directory.replace(/^\.?\//, ''))
66
66
  : undefined;
67
67
  const fileExtension = options.fileExtension ?? 'ts';
68
68
  const { name: extractedName, directory: extractedDirectory } = extractNameAndDirectoryFromName(options.name);
@@ -87,7 +87,7 @@ function getNameAndDirectoryOptionFormats(tree, options) {
87
87
  }
88
88
  if (options.disallowPathInNameForDerived && options.name.includes('/')) {
89
89
  if (!options.nameAndDirectoryFormat) {
90
- output.warn({
90
+ devkit_exports_1.output.warn({
91
91
  title: `The provided name "${options.name}" contains a path and this is not supported by the "${options.callingGenerator}" when using the "derived" format.`,
92
92
  bodyLines: [
93
93
  `The generator will try to generate the ${options.artifactType} using the "as-provided" format at "${asProvidedOptions.filePath}".`,
@@ -124,7 +124,7 @@ function getAsProvidedOptions(tree, options) {
124
124
  asProvidedDirectory = options.directory;
125
125
  }
126
126
  else {
127
- asProvidedDirectory = joinPathFragments(relativeCwd, options.directory);
127
+ asProvidedDirectory = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.directory);
128
128
  }
129
129
  }
130
130
  else {
@@ -133,7 +133,7 @@ function getAsProvidedOptions(tree, options) {
133
133
  const asProvidedProject = findProjectFromPath(tree, asProvidedDirectory);
134
134
  const asProvidedFileName = options.fileName ??
135
135
  (options.suffix ? `${options.name}.${options.suffix}` : options.name);
136
- const asProvidedFilePath = joinPathFragments(asProvidedDirectory, `${asProvidedFileName}.${options.fileExtension}`);
136
+ const asProvidedFilePath = (0, devkit_exports_1.joinPathFragments)(asProvidedDirectory, `${asProvidedFileName}.${options.fileExtension}`);
137
137
  return {
138
138
  artifactName: options.name,
139
139
  directory: asProvidedDirectory,
@@ -143,7 +143,7 @@ function getAsProvidedOptions(tree, options) {
143
143
  };
144
144
  }
145
145
  function getDerivedOptions(tree, options, asProvidedOptions, extractedDirectory) {
146
- const projects = getProjects(tree);
146
+ const projects = (0, devkit_exports_1.getProjects)(tree);
147
147
  if (options.project && !projects.has(options.project)) {
148
148
  throw new Error(`The provided project "${options.project}" does not exist! Please provide an existing project name.`);
149
149
  }
@@ -152,22 +152,22 @@ function getDerivedOptions(tree, options, asProvidedOptions, extractedDirectory)
152
152
  const derivedName = options.name;
153
153
  const baseDirectory = options.directory
154
154
  ? (0, names_1.names)(options.directory).fileName
155
- : joinPathFragments(project.sourceRoot ?? joinPathFragments(project.root, 'src'), project.projectType === 'application' ? 'app' : 'lib', extractedDirectory ?? '');
155
+ : (0, devkit_exports_1.joinPathFragments)(project.sourceRoot ?? (0, devkit_exports_1.joinPathFragments)(project.root, 'src'), project.projectType === 'application' ? 'app' : 'lib', extractedDirectory ?? '');
156
156
  const derivedDirectory = typeof options.derivedDirectory === 'string'
157
- ? joinPathFragments(project.sourceRoot ?? project.root, options.derivedDirectory, options.flat
157
+ ? (0, devkit_exports_1.joinPathFragments)(project.sourceRoot ?? project.root, options.derivedDirectory, options.flat
158
158
  ? ''
159
159
  : options.pascalCaseDirectory
160
160
  ? (0, names_1.names)(derivedName).className
161
161
  : (0, names_1.names)(derivedName).fileName)
162
162
  : options.flat
163
- ? normalizePath(baseDirectory)
164
- : joinPathFragments(baseDirectory, options.pascalCaseDirectory
163
+ ? (0, devkit_exports_1.normalizePath)(baseDirectory)
164
+ : (0, devkit_exports_1.joinPathFragments)(baseDirectory, options.pascalCaseDirectory
165
165
  ? (0, names_1.names)(derivedName).className
166
166
  : (0, names_1.names)(derivedName).fileName);
167
167
  if (options.directory &&
168
168
  !isDirectoryUnderProjectRoot(derivedDirectory, project.root)) {
169
169
  if (!options.nameAndDirectoryFormat) {
170
- output.warn({
170
+ devkit_exports_1.output.warn({
171
171
  title: `The provided directory "${options.directory}" is not under the provided project root "${project.root}".`,
172
172
  bodyLines: [
173
173
  `The generator will try to generate the ${options.artifactType} using the "as-provided" format.`,
@@ -188,7 +188,7 @@ function getDerivedOptions(tree, options, asProvidedOptions, extractedDirectory)
188
188
  ? (0, names_1.names)(derivedFileName).className
189
189
  : (0, names_1.names)(derivedFileName).fileName;
190
190
  }
191
- const derivedFilePath = joinPathFragments(derivedDirectory, `${derivedFileName}.${options.fileExtension}`);
191
+ const derivedFilePath = (0, devkit_exports_1.joinPathFragments)(derivedDirectory, `${derivedFileName}.${options.fileExtension}`);
192
192
  return {
193
193
  artifactName: derivedName,
194
194
  directory: derivedDirectory,
@@ -210,16 +210,16 @@ function validateResolvedProject(tree, project, options, normalizedDirectory) {
210
210
  }
211
211
  function findProjectFromPath(tree, path) {
212
212
  const projectConfigurations = {};
213
- const projects = getProjects(tree);
213
+ const projects = (0, devkit_exports_1.getProjects)(tree);
214
214
  for (const [projectName, project] of projects) {
215
215
  projectConfigurations[projectName] = project;
216
216
  }
217
- const projectRootMappings = createProjectRootMappingsFromProjectConfigurations(projectConfigurations);
218
- return findProjectForPath(path, projectRootMappings);
217
+ const projectRootMappings = (0, devkit_internals_1.createProjectRootMappingsFromProjectConfigurations)(projectConfigurations);
218
+ return (0, devkit_internals_1.findProjectForPath)(path, projectRootMappings);
219
219
  }
220
220
  function isDirectoryUnderProjectRoot(directory, projectRoot) {
221
- const normalizedDirectory = joinPathFragments(workspaceRoot, directory);
222
- const normalizedProjectRoot = joinPathFragments(workspaceRoot, projectRoot).replace(/\/$/, '');
221
+ const normalizedDirectory = (0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, directory);
222
+ const normalizedProjectRoot = (0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, projectRoot).replace(/\/$/, '');
223
223
  return (normalizedDirectory === normalizedProjectRoot ||
224
224
  normalizedDirectory.startsWith(`${normalizedProjectRoot}/`));
225
225
  }
@@ -227,23 +227,23 @@ function isTTY() {
227
227
  return !!process.stdout.isTTY && process.env['CI'] !== 'true';
228
228
  }
229
229
  function getRelativeCwd() {
230
- return normalizePath((0, path_1.relative)(workspaceRoot, getCwd()));
230
+ return (0, devkit_exports_1.normalizePath)((0, path_1.relative)(devkit_exports_1.workspaceRoot, getCwd()));
231
231
  }
232
232
  exports.getRelativeCwd = getRelativeCwd;
233
233
  /**
234
234
  * Function for setting cwd during testing
235
235
  */
236
236
  function setCwd(path) {
237
- process.env.INIT_CWD = (0, path_1.join)(workspaceRoot, path);
237
+ process.env.INIT_CWD = (0, path_1.join)(devkit_exports_1.workspaceRoot, path);
238
238
  }
239
239
  exports.setCwd = setCwd;
240
240
  function getCwd() {
241
- return process.env.INIT_CWD?.startsWith(workspaceRoot)
241
+ return process.env.INIT_CWD?.startsWith(devkit_exports_1.workspaceRoot)
242
242
  ? process.env.INIT_CWD
243
243
  : process.cwd();
244
244
  }
245
245
  function extractNameAndDirectoryFromName(rawName) {
246
- const parsedName = normalizePath(rawName).split('/');
246
+ const parsedName = (0, devkit_exports_1.normalizePath)(rawName).split('/');
247
247
  const name = parsedName.pop();
248
248
  const directory = parsedName.length ? parsedName.join('/') : undefined;
249
249
  return { name, directory };
@@ -1,5 +1,4 @@
1
- import type { Tree } from 'nx/src/generators/tree';
2
- import type { ProjectGraph } from 'nx/src/config/project-graph';
1
+ import { ProjectGraph, Tree } from 'nx/src/devkit-exports';
3
2
  type CallBack<T> = (currentValue: T, project: string, target: string, configuration?: string) => void;
4
3
  /**
5
4
  * Calls a function for each different options that an executor is configured with
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.forEachExecutorOptionsInGraph = exports.forEachExecutorOptions = void 0;
4
- const nx_1 = require("../../nx");
5
- const { getProjects } = (0, nx_1.requireNx)();
4
+ const devkit_exports_1 = require("nx/src/devkit-exports");
6
5
  /**
7
6
  * Calls a function for each different options that an executor is configured with
8
7
  */
@@ -15,7 +14,7 @@ executorName,
15
14
  * Callback that is called for each options configured for a builder
16
15
  */
17
16
  callback) {
18
- forEachProjectConfig(getProjects(tree), executorName, callback);
17
+ forEachProjectConfig((0, devkit_exports_1.getProjects)(tree), executorName, callback);
19
18
  }
20
19
  exports.forEachExecutorOptions = forEachExecutorOptions;
21
20
  /**
@@ -34,9 +33,7 @@ function forEachProjectConfig(projects, executorName, callback) {
34
33
  if (executorName !== target.executor) {
35
34
  continue;
36
35
  }
37
- if (target.options) {
38
- callback(target.options, projectName, targetName);
39
- }
36
+ callback(target.options ?? {}, projectName, targetName);
40
37
  if (!target.configurations) {
41
38
  continue;
42
39
  }
@@ -1,4 +1,4 @@
1
- import type { Tree } from 'nx/src/generators/tree';
1
+ import { Tree } from 'nx/src/devkit-exports';
2
2
  /**
3
3
  * Formats all the created or updated files using Prettier
4
4
  * @param tree - the file system tree
@@ -2,11 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatFiles = void 0;
4
4
  const path = require("path");
5
- const nx_1 = require("../../nx");
6
- let { updateJson, readJson, sortObjectByKeys } = (0, nx_1.requireNx)();
7
- // TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
8
- sortObjectByKeys =
9
- sortObjectByKeys ?? require('nx/src/utils/object-sort').sortObjectByKeys;
5
+ const devkit_exports_1 = require("nx/src/devkit-exports");
6
+ const devkit_internals_1 = require("nx/src/devkit-internals");
10
7
  /**
11
8
  * Formats all the created or updated files using Prettier
12
9
  * @param tree - the file system tree
@@ -56,11 +53,11 @@ function sortTsConfig(tree) {
56
53
  if (!tsConfigPath) {
57
54
  return;
58
55
  }
59
- updateJson(tree, tsConfigPath, (tsconfig) => ({
56
+ (0, devkit_exports_1.updateJson)(tree, tsConfigPath, (tsconfig) => ({
60
57
  ...tsconfig,
61
58
  compilerOptions: {
62
59
  ...tsconfig.compilerOptions,
63
- paths: sortObjectByKeys(tsconfig.compilerOptions.paths),
60
+ paths: (0, devkit_internals_1.sortObjectByKeys)(tsconfig.compilerOptions.paths),
64
61
  },
65
62
  }));
66
63
  }
@@ -79,7 +76,7 @@ function getRootTsConfigPath(tree) {
79
76
  function getChangedPrettierConfigInTree(tree) {
80
77
  if (tree.listChanges().find((file) => file.path === '.prettierrc')) {
81
78
  try {
82
- return readJson(tree, '.prettierrc');
79
+ return (0, devkit_exports_1.readJson)(tree, '.prettierrc');
83
80
  }
84
81
  catch {
85
82
  return null;
@@ -1,4 +1,4 @@
1
- import type { Tree } from 'nx/src/generators/tree';
1
+ import { Tree } from 'nx/src/devkit-exports';
2
2
  /**
3
3
  * Generates a folder of files based on provided templates.
4
4
  *
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateFiles = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path = require("path");
6
- const nx_1 = require("../../nx");
7
6
  const binary_extensions_1 = require("../utils/binary-extensions");
8
- const { logger } = (0, nx_1.requireNx)();
7
+ const devkit_exports_1 = require("nx/src/devkit-exports");
9
8
  /**
10
9
  * Generates a folder of files based on provided templates.
11
10
  *
@@ -49,7 +48,7 @@ function generateFiles(tree, srcFolder, target, substitutions) {
49
48
  });
50
49
  }
51
50
  catch (e) {
52
- logger.error(`Error in ${filePath.replace(`${tree.root}/`, '')}:`);
51
+ devkit_exports_1.logger.error(`Error in ${filePath.replace(`${tree.root}/`, '')}:`);
53
52
  throw e;
54
53
  }
55
54
  }
@@ -1,9 +1,6 @@
1
- import type { TargetConfiguration } from 'nx/src/config/workspace-json-project-json';
2
- import type { Tree } from 'nx/src/generators/tree';
3
- import type { CreateNodes } from 'nx/src/project-graph/plugins';
4
- import type { ProjectGraph } from 'nx/src/config/project-graph';
1
+ import { ProjectGraph, TargetConfiguration, Tree, CreateNodes } from 'nx/src/devkit-exports';
5
2
  type PluginOptionsBuilder<T> = (targetName: string) => T;
6
- type PostTargetTransformer = (targetConfiguration: TargetConfiguration) => TargetConfiguration;
3
+ type PostTargetTransformer = (targetConfiguration: TargetConfiguration, tree?: Tree) => TargetConfiguration;
7
4
  type SkipTargetFilter = (targetConfiguration: TargetConfiguration) => [boolean, string];
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<void>;
5
+ 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<number>;
9
6
  export {};
@@ -6,8 +6,8 @@ const tslib_1 = require("tslib");
6
6
  const minimatch_1 = require("minimatch");
7
7
  const executor_options_utils_1 = require("../executor-options-utils");
8
8
  const plugin_migration_utils_1 = require("./plugin-migration-utils");
9
- const nx_1 = require("../../../nx");
10
- const { glob, readNxJson, updateNxJson, mergeTargetConfigurations, updateProjectConfiguration, readProjectConfiguration, retrieveProjectConfigurations, LoadedNxPlugin, ProjectConfigurationsError, } = (0, nx_1.requireNx)();
9
+ const devkit_exports_1 = require("nx/src/devkit-exports");
10
+ const devkit_internals_1 = require("nx/src/devkit-internals");
11
11
  class ExecutorToPluginMigrator {
12
12
  constructor(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter) {
13
13
  _ExecutorToPluginMigrator_instances.add(this);
@@ -37,14 +37,17 @@ class ExecutorToPluginMigrator {
37
37
  }
38
38
  async run() {
39
39
  await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_init).call(this);
40
- for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
41
- tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateTarget).call(this, targetName);
40
+ if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").size > 0) {
41
+ for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
42
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateTarget).call(this, targetName);
43
+ }
44
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_addPlugins).call(this);
42
45
  }
43
- tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_addPlugins).call(this);
46
+ return tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f");
44
47
  }
45
48
  }
46
49
  _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_configFiles = new WeakMap(), _ExecutorToPluginMigrator_createNodesResultsForTargets = new WeakMap(), _ExecutorToPluginMigrator_instances = new WeakSet(), _ExecutorToPluginMigrator_init = async function _ExecutorToPluginMigrator_init() {
47
- const nxJson = readNxJson(this.tree);
50
+ const nxJson = (0, devkit_exports_1.readNxJson)(this.tree);
48
51
  nxJson.plugins ??= [];
49
52
  tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_nxJson, nxJson, "f");
50
53
  tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, new Map(), "f");
@@ -65,13 +68,13 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
65
68
  });
66
69
  }, _ExecutorToPluginMigrator_migrateProject = function _ExecutorToPluginMigrator_migrateProject(projectName, targetName) {
67
70
  const projectFromGraph = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_projectGraph, "f").nodes[projectName];
68
- const projectConfig = readProjectConfiguration(this.tree, projectName);
71
+ const projectConfig = (0, devkit_exports_1.readProjectConfiguration)(this.tree, projectName);
69
72
  const createdTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot).call(this, targetName, projectFromGraph.data.root);
70
73
  let projectTarget = projectConfig.targets[targetName];
71
- projectTarget = mergeTargetConfigurations(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
74
+ projectTarget = (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
72
75
  delete projectTarget.executor;
73
76
  (0, plugin_migration_utils_1.deleteMatchingProperties)(projectTarget, createdTarget);
74
- projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget);
77
+ projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree);
75
78
  if (projectTarget.options &&
76
79
  Object.keys(projectTarget.options).length === 0) {
77
80
  delete projectTarget.options;
@@ -82,7 +85,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
82
85
  else {
83
86
  delete projectConfig.targets[targetName];
84
87
  }
85
- updateProjectConfiguration(this.tree, projectName, projectConfig);
88
+ (0, devkit_exports_1.updateProjectConfiguration)(this.tree, projectName, projectConfig);
86
89
  return `${projectFromGraph.data.root}/**/*`;
87
90
  }, _ExecutorToPluginMigrator_addPlugins = function _ExecutorToPluginMigrator_addPlugins() {
88
91
  for (const [targetName, plugin] of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").entries()) {
@@ -123,7 +126,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
123
126
  tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.push(plugin);
124
127
  }
125
128
  }
126
- updateNxJson(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
129
+ (0, devkit_exports_1.updateNxJson)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
127
130
  }, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate = function _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate() {
128
131
  (0, executor_options_utils_1.forEachExecutorOptions)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f"), (targetConfiguration, projectName, targetName, configurationName) => {
129
132
  if (configurationName) {
@@ -151,12 +154,6 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
151
154
  tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").set(targetName, new Set([projectName]));
152
155
  }
153
156
  });
154
- if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").size === 0) {
155
- const errorMsg = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")
156
- ? `Project "${tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")}" does not contain any targets using the "${tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")}" executor. Please select a project that does.`
157
- : `Could not find any targets using the "${tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")}" executor.`;
158
- throw new Error(errorMsg);
159
- }
160
157
  }, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor = function _ExecutorToPluginMigrator_getTargetDefaultsForExecutor() {
161
158
  tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").targetDefaults?.[tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")], "f");
162
159
  }, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot = function _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot(targetName, projectRoot) {
@@ -166,8 +163,11 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
166
163
  delete createdTarget.options?.cwd;
167
164
  return createdTarget;
168
165
  }, _ExecutorToPluginMigrator_getCreateNodesResults = async function _ExecutorToPluginMigrator_getCreateNodesResults() {
166
+ if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").size === 0) {
167
+ return;
168
+ }
169
169
  for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
170
- const loadedPlugin = new LoadedNxPlugin({
170
+ const loadedPlugin = new devkit_internals_1.LoadedNxPlugin({
171
171
  createNodes: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodes, "f"),
172
172
  name: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
173
173
  }, {
@@ -176,10 +176,10 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
176
176
  });
177
177
  let projectConfigs;
178
178
  try {
179
- projectConfigs = await retrieveProjectConfigurations([loadedPlugin], this.tree.root, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
179
+ projectConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], this.tree.root, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
180
180
  }
181
181
  catch (e) {
182
- if (e instanceof ProjectConfigurationsError) {
182
+ if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
183
183
  projectConfigs = e.partialProjectConfigurationsResult;
184
184
  }
185
185
  else {
@@ -192,6 +192,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
192
192
  };
193
193
  async function migrateExecutorToPlugin(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter) {
194
194
  const migrator = new ExecutorToPluginMigrator(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter);
195
- await migrator.run();
195
+ const migratedProjectsAndTargets = await migrator.run();
196
+ return migratedProjectsAndTargets.size;
196
197
  }
197
198
  exports.migrateExecutorToPlugin = migrateExecutorToPlugin;
@@ -1,5 +1,4 @@
1
- import type { ProjectType } from 'nx/src/config/workspace-json-project-json';
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;