@nx/devkit 19.0.0-beta.0 → 19.0.0-beta.10

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 (56) hide show
  1. package/package.json +4 -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 +6 -0
  17. package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +197 -0
  18. package/src/generators/plugin-migrations/plugin-migration-utils.d.ts +54 -0
  19. package/src/generators/plugin-migrations/plugin-migration-utils.js +78 -0
  20. package/src/generators/project-name-and-root-utils.d.ts +1 -2
  21. package/src/generators/project-name-and-root-utils.js +16 -17
  22. package/src/generators/run-tasks-in-serial.d.ts +1 -1
  23. package/src/generators/to-js.d.ts +1 -1
  24. package/src/generators/update-ts-configs-to-js.d.ts +1 -1
  25. package/src/generators/update-ts-configs-to-js.js +3 -4
  26. package/src/generators/visit-not-ignored-files.d.ts +1 -1
  27. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +1 -1
  28. package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +1 -2
  29. package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +2 -3
  30. package/src/tasks/install-packages-task.d.ts +1 -2
  31. package/src/tasks/install-packages-task.js +5 -6
  32. package/src/utils/add-plugin.d.ts +1 -1
  33. package/src/utils/add-plugin.js +12 -10
  34. package/src/utils/calculate-hash-for-create-nodes.d.ts +1 -1
  35. package/src/utils/calculate-hash-for-create-nodes.js +5 -5
  36. package/src/utils/config-utils.d.ts +1 -0
  37. package/src/utils/config-utils.js +19 -9
  38. package/src/utils/convert-nx-executor.d.ts +1 -1
  39. package/src/utils/convert-nx-executor.js +21 -16
  40. package/src/utils/get-named-inputs.d.ts +1 -1
  41. package/src/utils/get-named-inputs.js +3 -4
  42. package/src/utils/get-workspace-layout.d.ts +1 -1
  43. package/src/utils/get-workspace-layout.js +2 -3
  44. package/src/utils/invoke-nx-generator.d.ts +1 -1
  45. package/src/utils/invoke-nx-generator.js +3 -5
  46. package/src/utils/log-show-project-command.js +2 -3
  47. package/src/utils/move-dir.d.ts +1 -1
  48. package/src/utils/move-dir.js +3 -4
  49. package/src/utils/package-json.d.ts +1 -2
  50. package/src/utils/package-json.js +13 -13
  51. package/src/utils/replace-package.d.ts +1 -1
  52. package/src/utils/replace-package.js +7 -9
  53. package/src/utils/replace-project-configuration-with-plugin.d.ts +1 -1
  54. package/src/utils/replace-project-configuration-with-plugin.js +11 -11
  55. package/nx.d.ts +0 -1
  56. 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-beta.0",
3
+ "version": "19.0.0-beta.10",
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": {
@@ -35,10 +35,11 @@
35
35
  "tslib": "^2.3.0",
36
36
  "semver": "^7.5.3",
37
37
  "yargs-parser": "21.1.1",
38
- "@nrwl/devkit": "19.0.0-beta.0"
38
+ "minimatch": "9.0.3",
39
+ "@nrwl/devkit": "19.0.0-beta.10"
39
40
  },
40
41
  "peerDependencies": {
41
- "nx": ">= 16 <= 19"
42
+ "nx": ">= 17 <= 20"
42
43
  },
43
44
  "publishConfig": {
44
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
  }
@@ -0,0 +1,6 @@
1
+ import { ProjectGraph, TargetConfiguration, Tree, CreateNodes } from 'nx/src/devkit-exports';
2
+ type PluginOptionsBuilder<T> = (targetName: string) => T;
3
+ type PostTargetTransformer = (targetConfiguration: TargetConfiguration, tree?: Tree) => TargetConfiguration;
4
+ type SkipTargetFilter = (targetConfiguration: TargetConfiguration) => [boolean, string];
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<void>;
6
+ export {};
@@ -0,0 +1,197 @@
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;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.migrateExecutorToPlugin = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const minimatch_1 = require("minimatch");
7
+ const executor_options_utils_1 = require("../executor-options-utils");
8
+ const plugin_migration_utils_1 = require("./plugin-migration-utils");
9
+ const devkit_exports_1 = require("nx/src/devkit-exports");
10
+ const devkit_internals_1 = require("nx/src/devkit-internals");
11
+ class ExecutorToPluginMigrator {
12
+ constructor(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter) {
13
+ _ExecutorToPluginMigrator_instances.add(this);
14
+ _ExecutorToPluginMigrator_projectGraph.set(this, void 0);
15
+ _ExecutorToPluginMigrator_executor.set(this, void 0);
16
+ _ExecutorToPluginMigrator_pluginPath.set(this, void 0);
17
+ _ExecutorToPluginMigrator_pluginOptionsBuilder.set(this, void 0);
18
+ _ExecutorToPluginMigrator_postTargetTransformer.set(this, void 0);
19
+ _ExecutorToPluginMigrator_skipTargetFilter.set(this, void 0);
20
+ _ExecutorToPluginMigrator_specificProjectToMigrate.set(this, void 0);
21
+ _ExecutorToPluginMigrator_nxJson.set(this, void 0);
22
+ _ExecutorToPluginMigrator_targetDefaultsForExecutor.set(this, void 0);
23
+ _ExecutorToPluginMigrator_targetAndProjectsToMigrate.set(this, void 0);
24
+ _ExecutorToPluginMigrator_pluginToAddForTarget.set(this, void 0);
25
+ _ExecutorToPluginMigrator_createNodes.set(this, void 0);
26
+ _ExecutorToPluginMigrator_configFiles.set(this, void 0);
27
+ _ExecutorToPluginMigrator_createNodesResultsForTargets.set(this, void 0);
28
+ this.tree = tree;
29
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_projectGraph, projectGraph, "f");
30
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_executor, executor, "f");
31
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_pluginPath, pluginPath, "f");
32
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, pluginOptionsBuilder, "f");
33
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_postTargetTransformer, postTargetTransformer, "f");
34
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodes, createNodes, "f");
35
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, specificProjectToMigrate, "f");
36
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_skipTargetFilter, skipTargetFilter ?? ((...args) => [false, '']), "f");
37
+ }
38
+ async run() {
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);
42
+ }
43
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_addPlugins).call(this);
44
+ }
45
+ }
46
+ _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 = (0, devkit_exports_1.readNxJson)(this.tree);
48
+ nxJson.plugins ??= [];
49
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_nxJson, nxJson, "f");
50
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, new Map(), "f");
51
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, new Map(), "f");
52
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, new Map(), "f");
53
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getTargetDefaultsForExecutor).call(this);
54
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate).call(this);
55
+ await tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreateNodesResults).call(this);
56
+ }, _ExecutorToPluginMigrator_migrateTarget = function _ExecutorToPluginMigrator_migrateTarget(targetName) {
57
+ const include = [];
58
+ for (const projectName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").get(targetName)) {
59
+ include.push(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_migrateProject).call(this, projectName, targetName));
60
+ }
61
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").set(targetName, {
62
+ plugin: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
63
+ options: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName),
64
+ include,
65
+ });
66
+ }, _ExecutorToPluginMigrator_migrateProject = function _ExecutorToPluginMigrator_migrateProject(projectName, targetName) {
67
+ const projectFromGraph = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_projectGraph, "f").nodes[projectName];
68
+ const projectConfig = (0, devkit_exports_1.readProjectConfiguration)(this.tree, projectName);
69
+ const createdTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot).call(this, targetName, projectFromGraph.data.root);
70
+ let projectTarget = projectConfig.targets[targetName];
71
+ projectTarget = (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
72
+ delete projectTarget.executor;
73
+ (0, plugin_migration_utils_1.deleteMatchingProperties)(projectTarget, createdTarget);
74
+ projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree);
75
+ if (projectTarget.options &&
76
+ Object.keys(projectTarget.options).length === 0) {
77
+ delete projectTarget.options;
78
+ }
79
+ if (Object.keys(projectTarget).length > 0) {
80
+ projectConfig.targets[targetName] = projectTarget;
81
+ }
82
+ else {
83
+ delete projectConfig.targets[targetName];
84
+ }
85
+ (0, devkit_exports_1.updateProjectConfiguration)(this.tree, projectName, projectConfig);
86
+ return `${projectFromGraph.data.root}/**/*`;
87
+ }, _ExecutorToPluginMigrator_addPlugins = function _ExecutorToPluginMigrator_addPlugins() {
88
+ for (const [targetName, plugin] of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").entries()) {
89
+ const pluginOptions = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName);
90
+ const existingPlugin = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.find((plugin) => {
91
+ if (typeof plugin === 'string' ||
92
+ plugin.plugin !== tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f")) {
93
+ return;
94
+ }
95
+ for (const key in plugin.options) {
96
+ if (plugin.options[key] !== pluginOptions[key]) {
97
+ return false;
98
+ }
99
+ }
100
+ return true;
101
+ });
102
+ if (existingPlugin?.include) {
103
+ for (const pluginIncludes of existingPlugin.include) {
104
+ for (const projectPath of plugin.include) {
105
+ if (!(0, minimatch_1.minimatch)(projectPath, pluginIncludes, { dot: true })) {
106
+ existingPlugin.include.push(projectPath);
107
+ }
108
+ }
109
+ }
110
+ const allConfigFilesAreIncluded = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_configFiles, "f").every((configFile) => {
111
+ for (const includePattern of existingPlugin.include) {
112
+ if ((0, minimatch_1.minimatch)(configFile, includePattern, { dot: true })) {
113
+ return true;
114
+ }
115
+ }
116
+ return false;
117
+ });
118
+ if (allConfigFilesAreIncluded) {
119
+ existingPlugin.include = undefined;
120
+ }
121
+ }
122
+ if (!existingPlugin) {
123
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.push(plugin);
124
+ }
125
+ }
126
+ (0, devkit_exports_1.updateNxJson)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
127
+ }, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate = function _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate() {
128
+ (0, executor_options_utils_1.forEachExecutorOptions)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f"), (targetConfiguration, projectName, targetName, configurationName) => {
129
+ if (configurationName) {
130
+ return;
131
+ }
132
+ if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f") &&
133
+ projectName !== tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")) {
134
+ return;
135
+ }
136
+ const [skipTarget, reasonTargetWasSkipped] = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_skipTargetFilter, "f").call(this, targetConfiguration);
137
+ if (skipTarget) {
138
+ const errorMsg = `${targetName} target on project "${projectName}" cannot be migrated. ${reasonTargetWasSkipped}`;
139
+ if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_specificProjectToMigrate, "f")) {
140
+ throw new Error(errorMsg);
141
+ }
142
+ else {
143
+ console.warn(errorMsg);
144
+ }
145
+ return;
146
+ }
147
+ if (tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").has(targetName)) {
148
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").get(targetName).add(projectName);
149
+ }
150
+ else {
151
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").set(targetName, new Set([projectName]));
152
+ }
153
+ });
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
+ }, _ExecutorToPluginMigrator_getTargetDefaultsForExecutor = function _ExecutorToPluginMigrator_getTargetDefaultsForExecutor() {
161
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").targetDefaults?.[tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f")], "f");
162
+ }, _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot = function _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot(targetName, projectRoot) {
163
+ const createdProject = Object.entries(tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").get(targetName)?.projects ?? {}).find(([root]) => root === projectRoot)[1];
164
+ const createdTarget = createdProject.targets[targetName];
165
+ delete createdTarget.command;
166
+ delete createdTarget.options?.cwd;
167
+ return createdTarget;
168
+ }, _ExecutorToPluginMigrator_getCreateNodesResults = async function _ExecutorToPluginMigrator_getCreateNodesResults() {
169
+ for (const targetName of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, "f").keys()) {
170
+ const loadedPlugin = new devkit_internals_1.LoadedNxPlugin({
171
+ createNodes: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodes, "f"),
172
+ name: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
173
+ }, {
174
+ plugin: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginPath, "f"),
175
+ options: tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginOptionsBuilder, "f").call(this, targetName),
176
+ });
177
+ let projectConfigs;
178
+ try {
179
+ projectConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], this.tree.root, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
180
+ }
181
+ catch (e) {
182
+ if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
183
+ projectConfigs = e.partialProjectConfigurationsResult;
184
+ }
185
+ else {
186
+ throw e;
187
+ }
188
+ }
189
+ tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_configFiles, Array.from(projectConfigs.matchingProjectFiles), "f");
190
+ tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_createNodesResultsForTargets, "f").set(targetName, projectConfigs);
191
+ }
192
+ };
193
+ async function migrateExecutorToPlugin(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter) {
194
+ const migrator = new ExecutorToPluginMigrator(tree, projectGraph, executor, pluginPath, pluginOptionsBuilder, postTargetTransformer, createNodes, specificProjectToMigrate, skipTargetFilter);
195
+ await migrator.run();
196
+ }
197
+ exports.migrateExecutorToPlugin = migrateExecutorToPlugin;