@nx/devkit 19.0.0-canary.20240427-f74aeab → 19.0.0-canary.20240502-5ded713

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 +2 -3
  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 +2 -5
  17. package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +11 -11
  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.20240427-f74aeab",
3
+ "version": "19.0.0-canary.20240502-5ded713",
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.20240427-f74aeab"
39
+ "@nrwl/devkit": "19.0.0-canary.20240502-5ded713"
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
  /**
@@ -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
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>;
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);
@@ -44,7 +44,7 @@ class ExecutorToPluginMigrator {
44
44
  }
45
45
  }
46
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 = readNxJson(this.tree);
47
+ const nxJson = (0, devkit_exports_1.readNxJson)(this.tree);
48
48
  nxJson.plugins ??= [];
49
49
  tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_nxJson, nxJson, "f");
50
50
  tslib_1.__classPrivateFieldSet(this, _ExecutorToPluginMigrator_targetAndProjectsToMigrate, new Map(), "f");
@@ -65,13 +65,13 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
65
65
  });
66
66
  }, _ExecutorToPluginMigrator_migrateProject = function _ExecutorToPluginMigrator_migrateProject(projectName, targetName) {
67
67
  const projectFromGraph = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_projectGraph, "f").nodes[projectName];
68
- const projectConfig = readProjectConfiguration(this.tree, projectName);
68
+ const projectConfig = (0, devkit_exports_1.readProjectConfiguration)(this.tree, projectName);
69
69
  const createdTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_instances, "m", _ExecutorToPluginMigrator_getCreatedTargetForProjectRoot).call(this, targetName, projectFromGraph.data.root);
70
70
  let projectTarget = projectConfig.targets[targetName];
71
- projectTarget = mergeTargetConfigurations(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
71
+ projectTarget = (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_targetDefaultsForExecutor, "f"));
72
72
  delete projectTarget.executor;
73
73
  (0, plugin_migration_utils_1.deleteMatchingProperties)(projectTarget, createdTarget);
74
- projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget);
74
+ projectTarget = tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_postTargetTransformer, "f").call(this, projectTarget, this.tree);
75
75
  if (projectTarget.options &&
76
76
  Object.keys(projectTarget.options).length === 0) {
77
77
  delete projectTarget.options;
@@ -82,7 +82,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
82
82
  else {
83
83
  delete projectConfig.targets[targetName];
84
84
  }
85
- updateProjectConfiguration(this.tree, projectName, projectConfig);
85
+ (0, devkit_exports_1.updateProjectConfiguration)(this.tree, projectName, projectConfig);
86
86
  return `${projectFromGraph.data.root}/**/*`;
87
87
  }, _ExecutorToPluginMigrator_addPlugins = function _ExecutorToPluginMigrator_addPlugins() {
88
88
  for (const [targetName, plugin] of tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_pluginToAddForTarget, "f").entries()) {
@@ -123,7 +123,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
123
123
  tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f").plugins.push(plugin);
124
124
  }
125
125
  }
126
- updateNxJson(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
126
+ (0, devkit_exports_1.updateNxJson)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_nxJson, "f"));
127
127
  }, _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate = function _ExecutorToPluginMigrator_getTargetAndProjectsToMigrate() {
128
128
  (0, executor_options_utils_1.forEachExecutorOptions)(this.tree, tslib_1.__classPrivateFieldGet(this, _ExecutorToPluginMigrator_executor, "f"), (targetConfiguration, projectName, targetName, configurationName) => {
129
129
  if (configurationName) {
@@ -167,7 +167,7 @@ _ExecutorToPluginMigrator_projectGraph = new WeakMap(), _ExecutorToPluginMigrato
167
167
  return createdTarget;
168
168
  }, _ExecutorToPluginMigrator_getCreateNodesResults = async function _ExecutorToPluginMigrator_getCreateNodesResults() {
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 {
@@ -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;
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setCwd = exports.determineProjectNameAndRootOptions = 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 get_workspace_layout_1 = require("../utils/get-workspace-layout");
8
7
  const names_1 = require("../utils/names");
9
- const { joinPathFragments, logger, normalizePath, output, readJson, stripIndents, workspaceRoot, } = (0, nx_1.requireNx)();
8
+ const devkit_exports_1 = require("nx/src/devkit-exports");
10
9
  async function determineProjectNameAndRootOptions(tree, options) {
11
10
  if (!options.projectNameAndRootFormat &&
12
11
  (process.env.NX_INTERACTIVE !== 'true' || !isTTY())) {
@@ -45,8 +44,8 @@ function validateName(name, projectNameAndRootFormat) {
45
44
  }
46
45
  }
47
46
  function logDeprecationMessage(callingGenerator, formats) {
48
- logger.warn(stripIndents `
49
- In Nx 19, generating projects will no longer derive the name and root.
47
+ devkit_exports_1.logger.warn((0, devkit_exports_1.stripIndents) `
48
+ In Nx 20, generating projects will no longer derive the name and root.
50
49
  Please provide the exact project name and root in the future.
51
50
  Example: nx g ${callingGenerator} ${formats['derived'].projectName} --directory ${formats['derived'].projectRoot}
52
51
  `);
@@ -86,7 +85,7 @@ async function determineFormat(formats) {
86
85
  }
87
86
  function getProjectNameAndRootFormats(tree, options) {
88
87
  const directory = options.directory
89
- ? normalizePath(options.directory.replace(/^\.?\//, ''))
88
+ ? (0, devkit_exports_1.normalizePath)(options.directory.replace(/^\.?\//, ''))
90
89
  : undefined;
91
90
  const { name: asProvidedParsedName, directory: asProvidedParsedDirectory } = parseNameForAsProvided(options.name);
92
91
  if (asProvidedParsedDirectory && directory) {
@@ -106,7 +105,7 @@ function getProjectNameAndRootFormats(tree, options) {
106
105
  }
107
106
  if (asProvidedOptions.projectName.startsWith('@')) {
108
107
  if (!options.projectNameAndRootFormat) {
109
- output.warn({
108
+ devkit_exports_1.output.warn({
110
109
  title: `The provided name "${options.name}" contains a scoped project name and this is not supported by the "${options.callingGenerator}" when using the "derived" format.`,
111
110
  bodyLines: [
112
111
  `The generator will try to generate the project "${asProvidedOptions.projectName}" using the "as-provided" format at "${asProvidedOptions.projectRoot}".`,
@@ -152,7 +151,7 @@ function getAsProvidedOptions(tree, options) {
152
151
  projectRoot = options.directory;
153
152
  }
154
153
  else {
155
- projectRoot = joinPathFragments(relativeCwd, options.directory);
154
+ projectRoot = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.directory);
156
155
  }
157
156
  }
158
157
  else if (options.rootProject) {
@@ -162,7 +161,7 @@ function getAsProvidedOptions(tree, options) {
162
161
  projectRoot = relativeCwd;
163
162
  // append the project name to the current working directory if it doesn't end with it
164
163
  if (!relativeCwd.endsWith(options.name)) {
165
- projectRoot = joinPathFragments(relativeCwd, options.name);
164
+ projectRoot = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.name);
166
165
  }
167
166
  }
168
167
  let importPath = undefined;
@@ -176,7 +175,7 @@ function getAsProvidedOptions(tree, options) {
176
175
  const npmScope = getNpmScope(tree);
177
176
  importPath =
178
177
  projectRoot === '.'
179
- ? readJson(tree, 'package.json').name ??
178
+ ? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
180
179
  getImportPath(npmScope, options.name)
181
180
  : getImportPath(npmScope, options.name);
182
181
  }
@@ -208,7 +207,7 @@ function getDerivedOptions(tree, options) {
208
207
  let projectRoot = projectDirectoryWithoutLayout;
209
208
  if (projectDirectoryWithoutLayout !== '.') {
210
209
  // prepend the layout directory
211
- projectRoot = joinPathFragments(layoutDirectory, projectRoot);
210
+ projectRoot = (0, devkit_exports_1.joinPathFragments)(layoutDirectory, projectRoot);
212
211
  }
213
212
  let importPath;
214
213
  if (options.projectType === 'library') {
@@ -217,7 +216,7 @@ function getDerivedOptions(tree, options) {
217
216
  const npmScope = getNpmScope(tree);
218
217
  importPath =
219
218
  projectRoot === '.'
220
- ? readJson(tree, 'package.json').name ??
219
+ ? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
221
220
  getImportPath(npmScope, projectName)
222
221
  : getImportPath(npmScope, projectDirectoryWithoutLayout);
223
222
  }
@@ -245,7 +244,7 @@ function getImportPath(npmScope, name) {
245
244
  }
246
245
  function getNpmScope(tree) {
247
246
  const { name } = tree.exists('package.json')
248
- ? readJson(tree, 'package.json')
247
+ ? (0, devkit_exports_1.readJson)(tree, 'package.json')
249
248
  : { name: null };
250
249
  return name?.startsWith('@') ? name.split('/')[0].substring(1) : undefined;
251
250
  }
@@ -259,22 +258,22 @@ function isTTY() {
259
258
  * environment variable (see here: https://docs.npmjs.com/cli/v9/commands/npm-run-script#description).
260
259
  */
261
260
  function getCwd() {
262
- return process.env.INIT_CWD?.startsWith(workspaceRoot)
261
+ return process.env.INIT_CWD?.startsWith(devkit_exports_1.workspaceRoot)
263
262
  ? process.env.INIT_CWD
264
263
  : process.cwd();
265
264
  }
266
265
  function getRelativeCwd() {
267
- return normalizePath((0, path_1.relative)(workspaceRoot, getCwd())).replace(/\/$/, '');
266
+ return (0, devkit_exports_1.normalizePath)((0, path_1.relative)(devkit_exports_1.workspaceRoot, getCwd())).replace(/\/$/, '');
268
267
  }
269
268
  /**
270
269
  * Function for setting cwd during testing
271
270
  */
272
271
  function setCwd(path) {
273
- process.env.INIT_CWD = (0, path_1.join)(workspaceRoot, path);
272
+ process.env.INIT_CWD = (0, path_1.join)(devkit_exports_1.workspaceRoot, path);
274
273
  }
275
274
  exports.setCwd = setCwd;
276
275
  function parseNameForAsProvided(rawName) {
277
- const directory = normalizePath(rawName);
276
+ const directory = (0, devkit_exports_1.normalizePath)(rawName);
278
277
  if (rawName.includes('@')) {
279
278
  const index = directory.lastIndexOf('@');
280
279
  if (index === 0) {
@@ -291,7 +290,7 @@ function parseNameForAsProvided(rawName) {
291
290
  return { name: rawName, directory: undefined };
292
291
  }
293
292
  function parseNameForDerived(rawName) {
294
- const parsedName = normalizePath(rawName).split('/');
293
+ const parsedName = (0, devkit_exports_1.normalizePath)(rawName).split('/');
295
294
  const name = parsedName.pop();
296
295
  const directory = parsedName.length ? parsedName.join('/') : undefined;
297
296
  return { name, directory };