nx 20.3.0-canary.20241212-0d1c960 → 20.3.0-canary.20241214-4cd640a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "20.3.0-canary.20241212-0d1c960",
3
+ "version": "20.3.0-canary.20241214-4cd640a",
4
4
  "private": false,
5
5
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
6
6
  "repository": {
@@ -58,6 +58,7 @@
58
58
  "npm-run-path": "^4.0.1",
59
59
  "open": "^8.4.0",
60
60
  "ora": "5.3.0",
61
+ "resolve.exports": "2.0.3",
61
62
  "semver": "^7.5.3",
62
63
  "string-width": "^4.2.3",
63
64
  "tar-stream": "~2.2.0",
@@ -81,16 +82,16 @@
81
82
  }
82
83
  },
83
84
  "optionalDependencies": {
84
- "@nx/nx-darwin-arm64": "20.3.0-canary.20241212-0d1c960",
85
- "@nx/nx-darwin-x64": "20.3.0-canary.20241212-0d1c960",
86
- "@nx/nx-freebsd-x64": "20.3.0-canary.20241212-0d1c960",
87
- "@nx/nx-linux-arm-gnueabihf": "20.3.0-canary.20241212-0d1c960",
88
- "@nx/nx-linux-arm64-gnu": "20.3.0-canary.20241212-0d1c960",
89
- "@nx/nx-linux-arm64-musl": "20.3.0-canary.20241212-0d1c960",
90
- "@nx/nx-linux-x64-gnu": "20.3.0-canary.20241212-0d1c960",
91
- "@nx/nx-linux-x64-musl": "20.3.0-canary.20241212-0d1c960",
92
- "@nx/nx-win32-arm64-msvc": "20.3.0-canary.20241212-0d1c960",
93
- "@nx/nx-win32-x64-msvc": "20.3.0-canary.20241212-0d1c960"
85
+ "@nx/nx-darwin-arm64": "20.3.0-canary.20241214-4cd640a",
86
+ "@nx/nx-darwin-x64": "20.3.0-canary.20241214-4cd640a",
87
+ "@nx/nx-freebsd-x64": "20.3.0-canary.20241214-4cd640a",
88
+ "@nx/nx-linux-arm-gnueabihf": "20.3.0-canary.20241214-4cd640a",
89
+ "@nx/nx-linux-arm64-gnu": "20.3.0-canary.20241214-4cd640a",
90
+ "@nx/nx-linux-arm64-musl": "20.3.0-canary.20241214-4cd640a",
91
+ "@nx/nx-linux-x64-gnu": "20.3.0-canary.20241214-4cd640a",
92
+ "@nx/nx-linux-x64-musl": "20.3.0-canary.20241214-4cd640a",
93
+ "@nx/nx-win32-arm64-msvc": "20.3.0-canary.20241214-4cd640a",
94
+ "@nx/nx-win32-x64-msvc": "20.3.0-canary.20241214-4cd640a"
94
95
  },
95
96
  "nx-migrations": {
96
97
  "migrations": "./migrations.json",
@@ -796,7 +796,7 @@ async function getWrappedWorkspaceNodeModulesArchitectHost(workspace, root, proj
796
796
  builderName,
797
797
  description: executorConfig.description,
798
798
  optionSchema: builderInfo.schema,
799
- import: (0, schema_utils_1.resolveImplementation)(executorConfig.implementation, (0, path_1.dirname)(executorsFilePath)),
799
+ import: (0, schema_utils_1.resolveImplementation)(executorConfig.implementation, (0, path_1.dirname)(executorsFilePath), packageName, this.projects),
800
800
  };
801
801
  }
802
802
  readExecutorsJson(nodeModule, builder, extraRequirePaths = []) {
@@ -825,14 +825,14 @@ async function getWrappedWorkspaceNodeModulesArchitectHost(workspace, root, proj
825
825
  try {
826
826
  const { executorsFilePath, executorConfig, isNgCompat } = this.readExecutorsJson(nodeModule, executor);
827
827
  const executorsDir = (0, path_1.dirname)(executorsFilePath);
828
- const schemaPath = (0, schema_utils_1.resolveSchema)(executorConfig.schema, executorsDir);
828
+ const schemaPath = (0, schema_utils_1.resolveSchema)(executorConfig.schema, executorsDir, nodeModule, this.projects);
829
829
  const schema = (0, executor_utils_1.normalizeExecutorSchema)((0, fileutils_1.readJsonFile)(schemaPath));
830
- const implementationFactory = this.getImplementationFactory(executorConfig.implementation, executorsDir);
830
+ const implementationFactory = this.getImplementationFactory(executorConfig.implementation, executorsDir, nodeModule);
831
831
  const batchImplementationFactory = executorConfig.batchImplementation
832
- ? this.getImplementationFactory(executorConfig.batchImplementation, executorsDir)
832
+ ? this.getImplementationFactory(executorConfig.batchImplementation, executorsDir, nodeModule)
833
833
  : null;
834
834
  const hasherFactory = executorConfig.hasher
835
- ? this.getImplementationFactory(executorConfig.hasher, executorsDir)
835
+ ? this.getImplementationFactory(executorConfig.hasher, executorsDir, nodeModule)
836
836
  : null;
837
837
  return {
838
838
  schema,
@@ -846,8 +846,8 @@ async function getWrappedWorkspaceNodeModulesArchitectHost(workspace, root, proj
846
846
  throw new Error(`Unable to resolve ${nodeModule}:${executor}.\n${e.message}`);
847
847
  }
848
848
  }
849
- getImplementationFactory(implementation, executorsDir) {
850
- return (0, schema_utils_1.getImplementationFactory)(implementation, executorsDir);
849
+ getImplementationFactory(implementation, executorsDir, packageName) {
850
+ return (0, schema_utils_1.getImplementationFactory)(implementation, executorsDir, packageName, this.projects);
851
851
  }
852
852
  }
853
853
  return new WrappedWorkspaceNodeModulesArchitectHost(workspace, root, projects);
@@ -13,14 +13,14 @@ function getGeneratorInformation(collectionName, generatorName, root, projects)
13
13
  const generatorConfig = generatorsJson.generators?.[normalizedGeneratorName] ||
14
14
  generatorsJson.schematics?.[normalizedGeneratorName];
15
15
  const isNgCompat = !generatorsJson.generators?.[normalizedGeneratorName];
16
- const schemaPath = (0, schema_utils_1.resolveSchema)(generatorConfig.schema, generatorsDir);
16
+ const schemaPath = (0, schema_utils_1.resolveSchema)(generatorConfig.schema, generatorsDir, collectionName, projects);
17
17
  const schema = (0, fileutils_1.readJsonFile)(schemaPath);
18
18
  if (!schema.properties || typeof schema.properties !== 'object') {
19
19
  schema.properties = {};
20
20
  }
21
21
  generatorConfig.implementation =
22
22
  generatorConfig.implementation || generatorConfig.factory;
23
- const implementationFactory = (0, schema_utils_1.getImplementationFactory)(generatorConfig.implementation, generatorsDir);
23
+ const implementationFactory = (0, schema_utils_1.getImplementationFactory)(generatorConfig.implementation, generatorsDir, collectionName, projects);
24
24
  const normalizedGeneratorConfiguration = {
25
25
  ...generatorConfig,
26
26
  aliases: generatorConfig.aliases ?? [],
@@ -29,14 +29,14 @@ function getExecutorInformation(nodeModule, executor, root, projects) {
29
29
  return cachedExecutorInformation[key];
30
30
  const { executorsFilePath, executorConfig, isNgCompat } = readExecutorJson(nodeModule, executor, root, projects);
31
31
  const executorsDir = (0, path_1.dirname)(executorsFilePath);
32
- const schemaPath = (0, schema_utils_1.resolveSchema)(executorConfig.schema, executorsDir);
32
+ const schemaPath = (0, schema_utils_1.resolveSchema)(executorConfig.schema, executorsDir, nodeModule, projects);
33
33
  const schema = normalizeExecutorSchema((0, fileutils_1.readJsonFile)(schemaPath));
34
- const implementationFactory = (0, schema_utils_1.getImplementationFactory)(executorConfig.implementation, executorsDir);
34
+ const implementationFactory = (0, schema_utils_1.getImplementationFactory)(executorConfig.implementation, executorsDir, nodeModule, projects);
35
35
  const batchImplementationFactory = executorConfig.batchImplementation
36
- ? (0, schema_utils_1.getImplementationFactory)(executorConfig.batchImplementation, executorsDir)
36
+ ? (0, schema_utils_1.getImplementationFactory)(executorConfig.batchImplementation, executorsDir, nodeModule, projects)
37
37
  : null;
38
38
  const hasherFactory = executorConfig.hasher
39
- ? (0, schema_utils_1.getImplementationFactory)(executorConfig.hasher, executorsDir)
39
+ ? (0, schema_utils_1.getImplementationFactory)(executorConfig.hasher, executorsDir, nodeModule, projects)
40
40
  : null;
41
41
  const res = {
42
42
  schema,
@@ -1,15 +1,16 @@
1
+ import type { ProjectConfiguration } from './workspace-json-project-json';
1
2
  /**
2
3
  * This function is used to get the implementation factory of an executor or generator.
3
4
  * @param implementation path to the implementation
4
5
  * @param directory path to the directory
5
6
  * @returns a function that returns the implementation
6
7
  */
7
- export declare function getImplementationFactory<T>(implementation: string, directory: string): () => T;
8
+ export declare function getImplementationFactory<T>(implementation: string, directory: string, packageName: string, projects: Record<string, ProjectConfiguration>): () => T;
8
9
  /**
9
10
  * This function is used to resolve the implementation of an executor or generator.
10
11
  * @param implementationModulePath
11
12
  * @param directory
12
13
  * @returns path to the implementation
13
14
  */
14
- export declare function resolveImplementation(implementationModulePath: string, directory: string): string;
15
- export declare function resolveSchema(schemaPath: string, directory: string): string;
15
+ export declare function resolveImplementation(implementationModulePath: string, directory: string, packageName: string, projects: Record<string, ProjectConfiguration>): string;
16
+ export declare function resolveSchema(schemaPath: string, directory: string, packageName: string, projects: Record<string, ProjectConfiguration>): string;
@@ -5,17 +5,20 @@ exports.resolveImplementation = resolveImplementation;
5
5
  exports.resolveSchema = resolveSchema;
6
6
  const fs_1 = require("fs");
7
7
  const path_1 = require("path");
8
+ const resolve_exports_1 = require("resolve.exports");
9
+ const packages_1 = require("../plugins/js/utils/packages");
8
10
  const plugins_1 = require("../project-graph/plugins");
11
+ const path_2 = require("../utils/path");
9
12
  /**
10
13
  * This function is used to get the implementation factory of an executor or generator.
11
14
  * @param implementation path to the implementation
12
15
  * @param directory path to the directory
13
16
  * @returns a function that returns the implementation
14
17
  */
15
- function getImplementationFactory(implementation, directory) {
18
+ function getImplementationFactory(implementation, directory, packageName, projects) {
16
19
  const [implementationModulePath, implementationExportName] = implementation.split('#');
17
20
  return () => {
18
- const modulePath = resolveImplementation(implementationModulePath, directory);
21
+ const modulePath = resolveImplementation(implementationModulePath, directory, packageName, projects);
19
22
  if ((0, path_1.extname)(modulePath) === '.ts') {
20
23
  (0, plugins_1.registerPluginTSTranspiler)();
21
24
  }
@@ -31,8 +34,19 @@ function getImplementationFactory(implementation, directory) {
31
34
  * @param directory
32
35
  * @returns path to the implementation
33
36
  */
34
- function resolveImplementation(implementationModulePath, directory) {
37
+ function resolveImplementation(implementationModulePath, directory, packageName, projects) {
35
38
  const validImplementations = ['', '.js', '.ts'].map((x) => implementationModulePath + x);
39
+ if (!directory.includes('node_modules')) {
40
+ // It might be a local plugin where the implementation path points to the
41
+ // outputs which might not exist or can be stale. We prioritize finding
42
+ // the implementation from the source over the outputs.
43
+ for (const maybeImplementation of validImplementations) {
44
+ const maybeImplementationFromSource = tryResolveFromSource(maybeImplementation, directory, packageName, projects);
45
+ if (maybeImplementationFromSource) {
46
+ return maybeImplementationFromSource;
47
+ }
48
+ }
49
+ }
36
50
  for (const maybeImplementation of validImplementations) {
37
51
  const maybeImplementationPath = (0, path_1.join)(directory, maybeImplementation);
38
52
  if ((0, fs_1.existsSync)(maybeImplementationPath)) {
@@ -47,7 +61,16 @@ function resolveImplementation(implementationModulePath, directory) {
47
61
  }
48
62
  throw new Error(`Could not resolve "${implementationModulePath}" from "${directory}".`);
49
63
  }
50
- function resolveSchema(schemaPath, directory) {
64
+ function resolveSchema(schemaPath, directory, packageName, projects) {
65
+ if (!directory.includes('node_modules')) {
66
+ // It might be a local plugin where the schema path points to the outputs
67
+ // which might not exist or can be stale. We prioritize finding the schema
68
+ // from the source over the outputs.
69
+ const schemaPathFromSource = tryResolveFromSource(schemaPath, directory, packageName, projects);
70
+ if (schemaPathFromSource) {
71
+ return schemaPathFromSource;
72
+ }
73
+ }
51
74
  const maybeSchemaPath = (0, path_1.join)(directory, schemaPath);
52
75
  if ((0, fs_1.existsSync)(maybeSchemaPath)) {
53
76
  return maybeSchemaPath;
@@ -56,3 +79,47 @@ function resolveSchema(schemaPath, directory) {
56
79
  paths: [directory],
57
80
  });
58
81
  }
82
+ let packageEntryPointsToProjectMap;
83
+ function tryResolveFromSource(path, directory, packageName, projects) {
84
+ packageEntryPointsToProjectMap ??=
85
+ (0, packages_1.getPackageEntryPointsToProjectMap)(projects);
86
+ const localProject = packageEntryPointsToProjectMap[packageName];
87
+ if (!localProject) {
88
+ // it doesn't match any of the package names from the local projects
89
+ return null;
90
+ }
91
+ try {
92
+ const fromExports = (0, resolve_exports_1.resolve)({
93
+ name: localProject.metadata.js.packageName,
94
+ exports: localProject.metadata.js.packageExports,
95
+ }, path, { conditions: ['development'] });
96
+ if (fromExports && fromExports.length) {
97
+ for (const exportPath of fromExports) {
98
+ if ((0, fs_1.existsSync)((0, path_1.join)(directory, exportPath))) {
99
+ return (0, path_1.join)(directory, exportPath);
100
+ }
101
+ }
102
+ }
103
+ }
104
+ catch { }
105
+ /**
106
+ * Fall back to try to "guess" the source by checking the path in some common directories:
107
+ * - the root of the project
108
+ * - the src directory
109
+ * - the src/lib directory
110
+ */
111
+ const segments = (0, path_2.normalizePath)(path).replace(/^\.\//, '').split('/');
112
+ for (let i = 1; i < segments.length; i++) {
113
+ const possiblePaths = [
114
+ (0, path_1.join)(directory, ...segments.slice(i)),
115
+ (0, path_1.join)(directory, 'src', ...segments.slice(i)),
116
+ (0, path_1.join)(directory, 'src', 'lib', ...segments.slice(i)),
117
+ ];
118
+ for (const possiblePath of possiblePaths) {
119
+ if ((0, fs_1.existsSync)(possiblePath)) {
120
+ return possiblePath;
121
+ }
122
+ }
123
+ }
124
+ return null;
125
+ }
@@ -1,3 +1,4 @@
1
+ import type { PackageJson } from '../utils/package-json';
1
2
  import type { NxJsonConfiguration, NxReleaseVersionConfiguration } from './nx-json';
2
3
  /**
3
4
  * @deprecated use ProjectsConfigurations or NxJsonConfiguration
@@ -122,6 +123,10 @@ export interface ProjectMetadata {
122
123
  }[];
123
124
  };
124
125
  };
126
+ js?: {
127
+ packageName: string;
128
+ packageExports: undefined | PackageJson['exports'];
129
+ };
125
130
  }
126
131
  export interface TargetMetadata {
127
132
  [k: string]: any;
Binary file
@@ -1,4 +1,4 @@
1
- import { CreateDependenciesContext } from '../../../../project-graph/plugins';
2
- import { RawProjectGraphDependency } from '../../../../project-graph/project-graph-builder';
1
+ import type { CreateDependenciesContext } from '../../../../project-graph/plugins';
2
+ import { type RawProjectGraphDependency } from '../../../../project-graph/project-graph-builder';
3
3
  import { TargetProjectLocator } from './target-project-locator';
4
4
  export declare function buildExplicitPackageJsonDependencies(ctx: CreateDependenciesContext, targetProjectLocator: TargetProjectLocator): RawProjectGraphDependency[];
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExplicitPackageJsonDependencies = buildExplicitPackageJsonDependencies;
4
- const node_path_1 = require("node:path");
5
4
  const project_graph_1 = require("../../../../config/project-graph");
6
5
  const file_utils_1 = require("../../../../project-graph/file-utils");
7
6
  const project_graph_builder_1 = require("../../../../project-graph/project-graph-builder");
@@ -9,43 +8,30 @@ const json_1 = require("../../../../utils/json");
9
8
  const path_1 = require("../../../../utils/path");
10
9
  function buildExplicitPackageJsonDependencies(ctx, targetProjectLocator) {
11
10
  const res = [];
12
- let packageNameMap = undefined;
13
11
  const nodes = Object.values(ctx.projects);
14
12
  Object.keys(ctx.filesToProcess.projectFileMap).forEach((source) => {
15
13
  Object.values(ctx.filesToProcess.projectFileMap[source]).forEach((f) => {
16
14
  if (isPackageJsonAtProjectRoot(nodes, f.file)) {
17
- // we only create the package name map once and only if a package.json file changes
18
- packageNameMap = packageNameMap || createPackageNameMap(ctx.projects);
19
- processPackageJson(source, f.file, ctx, targetProjectLocator, res, packageNameMap);
15
+ processPackageJson(source, f.file, ctx, targetProjectLocator, res);
20
16
  }
21
17
  });
22
18
  });
23
19
  return res;
24
20
  }
25
- function createPackageNameMap(projects) {
26
- const res = {};
27
- for (let projectName of Object.keys(projects)) {
28
- try {
29
- const packageJson = (0, json_1.parseJson)((0, file_utils_1.defaultFileRead)((0, node_path_1.join)(projects[projectName].root, 'package.json')));
30
- res[packageJson.name ?? projectName] = projectName;
31
- }
32
- catch (e) { }
33
- }
34
- return res;
35
- }
36
21
  function isPackageJsonAtProjectRoot(nodes, fileName) {
37
22
  return (fileName.endsWith('package.json') &&
38
23
  nodes.find((projectNode) => (0, path_1.joinPathFragments)(projectNode.root, 'package.json') === fileName));
39
24
  }
40
- function processPackageJson(sourceProject, fileName, ctx, targetProjectLocator, collectedDeps, packageNameMap) {
25
+ function processPackageJson(sourceProject, fileName, ctx, targetProjectLocator, collectedDeps) {
41
26
  try {
42
27
  const deps = readDeps((0, json_1.parseJson)((0, file_utils_1.defaultFileRead)(fileName)));
43
28
  for (const d of Object.keys(deps)) {
44
- // package.json refers to another project in the monorepo
45
- if (packageNameMap[d]) {
29
+ const localProject = targetProjectLocator.findDependencyInWorkspaceProjects(d);
30
+ if (localProject) {
31
+ // package.json refers to another project in the monorepo
46
32
  const dependency = {
47
33
  source: sourceProject,
48
- target: packageNameMap[d],
34
+ target: localProject,
49
35
  sourceFile: fileName,
50
36
  type: project_graph_1.DependencyType.static,
51
37
  };
@@ -1,4 +1,4 @@
1
- import { ProjectGraphExternalNode, ProjectGraphProjectNode } from '../../../../config/project-graph';
1
+ import type { ProjectGraphExternalNode, ProjectGraphProjectNode } from '../../../../config/project-graph';
2
2
  /**
3
3
  * The key is a combination of the package name and the workspace relative directory
4
4
  * containing the file importing it e.g. `lodash__packages/my-lib`, the value is the
@@ -15,6 +15,7 @@ export declare class TargetProjectLocator {
15
15
  private tsConfig;
16
16
  private paths;
17
17
  private typescriptResolutionCache;
18
+ private packageEntryPointsToProjectMap;
18
19
  constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes?: Record<string, ProjectGraphExternalNode>, npmResolutionCache?: NpmResolutionCache);
19
20
  /**
20
21
  * Resolve any workspace or external project that matches the given import expression,
@@ -38,6 +39,7 @@ export declare class TargetProjectLocator {
38
39
  * @returns
39
40
  */
40
41
  findPaths(normalizedImportExpr: string): string[] | undefined;
42
+ findDependencyInWorkspaceProjects(dep: string): string | null;
41
43
  private resolveImportWithTypescript;
42
44
  private resolveImportWithRequire;
43
45
  private findProjectOfResolvedModule;
@@ -7,10 +7,11 @@ const node_path_1 = require("node:path");
7
7
  const semver_1 = require("semver");
8
8
  const find_project_for_path_1 = require("../../../../project-graph/utils/find-project-for-path");
9
9
  const fileutils_1 = require("../../../../utils/fileutils");
10
+ const get_package_name_from_import_path_1 = require("../../../../utils/get-package-name-from-import-path");
10
11
  const workspace_root_1 = require("../../../../utils/workspace-root");
12
+ const packages_1 = require("../../utils/packages");
11
13
  const resolve_relative_to_dir_1 = require("../../utils/resolve-relative-to-dir");
12
14
  const typescript_1 = require("../../utils/typescript");
13
- const get_package_name_from_import_path_1 = require("../../../../utils/get-package-name-from-import-path");
14
15
  /**
15
16
  * Use a shared cache to avoid repeated npm package resolution work within the TargetProjectLocator.
16
17
  */
@@ -98,6 +99,12 @@ class TargetProjectLocator {
98
99
  return this.findProjectOfResolvedModule(resolvedModule);
99
100
  }
100
101
  catch { }
102
+ // fall back to see if it's a locally linked workspace project where the
103
+ // output might not exist yet
104
+ const localProject = this.findDependencyInWorkspaceProjects(importExpr);
105
+ if (localProject) {
106
+ return localProject;
107
+ }
101
108
  // nothing found, cache for later
102
109
  this.npmResolutionCache.set(importExpr, null);
103
110
  return null;
@@ -182,6 +189,10 @@ class TargetProjectLocator {
182
189
  }
183
190
  return undefined;
184
191
  }
192
+ findDependencyInWorkspaceProjects(dep) {
193
+ this.packageEntryPointsToProjectMap ??= (0, packages_1.getPackageEntryPointsToProjectMap)(this.nodes);
194
+ return this.packageEntryPointsToProjectMap[dep]?.name ?? null;
195
+ }
185
196
  resolveImportWithTypescript(normalizedImportExpr, filePath) {
186
197
  let resolvedModule;
187
198
  if (this.typescriptResolutionCache.has(normalizedImportExpr)) {
@@ -0,0 +1,3 @@
1
+ import type { ProjectGraphProjectNode } from '../../../config/project-graph';
2
+ import type { ProjectConfiguration } from '../../../config/workspace-json-project-json';
3
+ export declare function getPackageEntryPointsToProjectMap<T extends ProjectGraphProjectNode | ProjectConfiguration>(projects: Record<string, T>): Record<string, T>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageEntryPointsToProjectMap = getPackageEntryPointsToProjectMap;
4
+ const posix_1 = require("node:path/posix");
5
+ function getPackageEntryPointsToProjectMap(projects) {
6
+ const result = {};
7
+ for (const project of Object.values(projects)) {
8
+ const metadata = 'data' in project ? project.data.metadata : project.metadata;
9
+ if (!metadata?.js) {
10
+ continue;
11
+ }
12
+ const { packageName, packageExports } = metadata.js;
13
+ if (!packageExports || typeof packageExports === 'string') {
14
+ // no `exports` or it points to a file, which would be the equivalent of
15
+ // an '.' export, in which case the package name is the entry point
16
+ result[packageName] = project;
17
+ }
18
+ else {
19
+ for (const entryPoint of Object.keys(packageExports)) {
20
+ result[(0, posix_1.join)(packageName, entryPoint)] = project;
21
+ }
22
+ }
23
+ }
24
+ return result;
25
+ }
@@ -84,6 +84,12 @@ function createNodeFromPackageJson(pkgJsonPath, workspaceRoot, cache) {
84
84
  const hash = (0, file_hasher_1.hashObject)({
85
85
  ...json,
86
86
  root: projectRoot,
87
+ /**
88
+ * Increment this number to force processing the package.json again. Do it
89
+ * when the implementation of this plugin is changed and results in different
90
+ * results for the same package.json contents.
91
+ */
92
+ bust: 1,
87
93
  });
88
94
  const cached = cache[hash];
89
95
  if (cached) {
@@ -25,6 +25,7 @@ const error_types_1 = require("../error-types");
25
25
  const path = require("node:path/posix");
26
26
  const typescript_1 = require("../../plugins/js/utils/typescript");
27
27
  const load_resolved_plugin_1 = require("./load-resolved-plugin");
28
+ const packages_1 = require("../../plugins/js/utils/packages");
28
29
  function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
29
30
  try {
30
31
  const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
@@ -89,26 +90,32 @@ function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspa
89
90
  }
90
91
  return { path: path.join(root, projectConfig.root), projectConfig };
91
92
  }
93
+ let packageEntryPointsToProjectMap;
92
94
  function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
93
95
  const tsConfigPaths = readTsConfigPaths(root);
94
- const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
95
- if (possiblePaths?.length) {
96
- const projectRootMappings = new Map();
96
+ const possibleTsPaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p)))) ?? [];
97
+ const projectRootMappings = new Map();
98
+ if (possibleTsPaths.length) {
97
99
  const projectNameMap = new Map();
98
100
  for (const projectRoot in projects) {
99
101
  const project = projects[projectRoot];
100
102
  projectRootMappings.set(project.root, project.name);
101
103
  projectNameMap.set(project.name, project);
102
104
  }
103
- for (const tsConfigPath of possiblePaths) {
105
+ for (const tsConfigPath of possibleTsPaths) {
104
106
  const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
105
107
  if (nxProject) {
106
108
  return projectNameMap.get(nxProject);
107
109
  }
108
110
  }
109
- logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
110
- throw new Error('Unable to resolve local plugin with import path ' + importPath);
111
111
  }
112
+ packageEntryPointsToProjectMap ??=
113
+ (0, packages_1.getPackageEntryPointsToProjectMap)(projects);
114
+ if (packageEntryPointsToProjectMap[importPath]) {
115
+ return packageEntryPointsToProjectMap[importPath];
116
+ }
117
+ logger_1.logger.verbose('Unable to find local plugin', possibleTsPaths, projectRootMappings);
118
+ throw new Error('Unable to resolve local plugin with import path ' + importPath);
112
119
  }
113
120
  let tsconfigPaths;
114
121
  function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
@@ -35,6 +35,7 @@ export interface PackageJson {
35
35
  types?: string;
36
36
  require?: string;
37
37
  import?: string;
38
+ development?: string;
38
39
  }>;
39
40
  dependencies?: Record<string, string>;
40
41
  devDependencies?: Record<string, string>;
@@ -58,13 +58,17 @@ function buildTargetFromScript(script, scripts = {}, packageManagerCommand) {
58
58
  }
59
59
  let packageManagerCommand;
60
60
  function getMetadataFromPackageJson(packageJson) {
61
- const { scripts, nx, description } = packageJson ?? {};
61
+ const { scripts, nx, description, name, exports } = packageJson;
62
62
  const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {});
63
63
  return {
64
64
  targetGroups: {
65
65
  ...(includedScripts.length ? { 'NPM Scripts': includedScripts } : {}),
66
66
  },
67
67
  description,
68
+ js: {
69
+ packageName: name,
70
+ packageExports: exports,
71
+ },
68
72
  };
69
73
  }
70
74
  function getTagsFromPackageJson(packageJson) {