@nx/devkit 23.2.0-beta.2 → 23.2.0-beta.4

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.
@@ -51,6 +51,7 @@ async function determineProjectNameAndRootOptions(tree, options) {
51
51
  if (projectRoot.startsWith('..')) {
52
52
  throw new Error(`The resolved project root "${projectRoot}" is outside of the workspace root "${devkit_exports_1.workspaceRoot}".`);
53
53
  }
54
+ validateUniqueName(tree, name, projectRoot, options);
54
55
  const importPath = options.importPath ?? resolveImportPath(tree, name, projectRoot);
55
56
  return {
56
57
  projectName: name,
@@ -109,6 +110,18 @@ function validateOptions(providedName, derivedName, directory) {
109
110
  throw new Error(`The derived name from the provided directory should match the pattern "${pattern}". The derived name "${derivedName}" from the provided value "${directory}" does not match.`);
110
111
  }
111
112
  }
113
+ function validateUniqueName(tree, name, projectRoot, options) {
114
+ const existingProject = (0, devkit_exports_1.getProjects)(tree).get(name);
115
+ // A project at the resolved root is handled elsewhere with a more
116
+ // accurate error, so only error when the name is taken by a project
117
+ // located somewhere else.
118
+ if (!existingProject || existingProject.root === projectRoot) {
119
+ return;
120
+ }
121
+ throw new Error(options.name
122
+ ? `The provided name "${name}" is already used by the project at "${existingProject.root}". Please provide a unique name for the new project.`
123
+ : `The name "${name}" was derived from the provided directory "${options.directory}", but it is already used by the project at "${existingProject.root}". Please provide a unique name for the new project with the "--name" option.`);
124
+ }
112
125
  function getImportPath(npmScope, name) {
113
126
  return npmScope ? `${npmScope === '@' ? '' : '@'}${npmScope}/${name}` : name;
114
127
  }
@@ -61,8 +61,10 @@ async function _addPluginInternal(tree, graph, pluginName, pluginFactory, option
61
61
  // Errors are okay for this because we're only running 1 plugin
62
62
  if ((0, devkit_internals_1.isProjectConfigurationsError)(e)) {
63
63
  projConfigs = e.partialProjectConfigurationsResult;
64
- // ignore errors from projects with no name
65
- if (!e.errors.every(devkit_internals_1.isProjectsWithNoNameError)) {
64
+ // Ignore errors about project names: running a single plugin in
65
+ // isolation cannot resolve the real project names, and they are
66
+ // irrelevant for determining the plugin options.
67
+ if (!e.errors.every(isProjectNameError)) {
66
68
  throw e;
67
69
  }
68
70
  }
@@ -102,8 +104,10 @@ async function _addPluginInternal(tree, graph, pluginName, pluginFactory, option
102
104
  // Errors are okay for this because we're only running 1 plugin
103
105
  if ((0, devkit_internals_1.isProjectConfigurationsError)(e)) {
104
106
  projConfigs = e.partialProjectConfigurationsResult;
105
- // ignore errors from projects with no name
106
- if (!e.errors.every(devkit_internals_1.isProjectsWithNoNameError)) {
107
+ // Ignore errors about project names: running a single plugin in
108
+ // isolation cannot resolve the real project names, and they are
109
+ // irrelevant for determining the plugin options.
110
+ if (!e.errors.every(isProjectNameError)) {
107
111
  throw e;
108
112
  }
109
113
  }
@@ -125,6 +129,9 @@ async function _addPluginInternal(tree, graph, pluginName, pluginFactory, option
125
129
  updatePackageScripts(tree, projConfigs);
126
130
  }
127
131
  }
132
+ function isProjectNameError(e) {
133
+ return (0, devkit_internals_1.isProjectsWithNoNameError)(e) || (0, devkit_internals_1.isMultipleProjectsWithSameNameError)(e);
134
+ }
128
135
  function updatePackageScripts(tree, projectConfigurations) {
129
136
  for (const projectConfig of Object.values(projectConfigurations.projects)) {
130
137
  const projectRoot = projectConfig.root;
@@ -3,9 +3,10 @@ import type { PackageJson, PackageJsonDependencySection } from 'nx/src/utils/pac
3
3
  /**
4
4
  * Get the resolved version of a dependency from package.json.
5
5
  *
6
- * Retrieves a package version and automatically resolves PNPM catalog references
7
- * (e.g., "catalog:default") to their actual version strings. By default, searches
8
- * `dependencies` first, then falls back to `devDependencies`.
6
+ * Retrieves a package version and automatically resolves package manager
7
+ * catalog references (e.g., "catalog:default") to their actual version
8
+ * strings. By default, searches `dependencies` first, then falls back to
9
+ * `devDependencies`.
9
10
  *
10
11
  * **Tree-based usage** (generators and migrations):
11
12
  * Use when you have a `Tree` object, which is typical in Nx generators and migrations.
@@ -442,7 +442,11 @@ function ensurePackage(pkgOrTree, requiredVersionOrPackage, maybeRequiredVersion
442
442
  return packageMapCache.get(pkg);
443
443
  }
444
444
  try {
445
- return require(pkg);
445
+ // The workspace comes first so its installed version wins; `__dirname`
446
+ // keeps the old behaviour as a fallback. A bare `require` would only
447
+ // resolve from wherever `@nx/devkit` sits, which in a monorepo can be a
448
+ // different copy of the package than the workspace depends on.
449
+ return require(require.resolve(pkg, { paths: [devkit_exports_1.workspaceRoot, __dirname] }));
446
450
  }
447
451
  catch (e) {
448
452
  if (e.code === 'ERR_REQUIRE_ESM') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/devkit",
3
- "version": "23.2.0-beta.2",
3
+ "version": "23.2.0-beta.4",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "jest": "30.3.0",
62
- "nx": "23.2.0-beta.2"
62
+ "nx": "23.2.0-beta.4"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "nx": ">= 22 <= 24 || ^23.0.0-0"