nx 19.2.0-canary.20240528-7f11a1d → 19.2.0-canary.20240531-2cb7ecb

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. package/package.json +12 -12
  2. package/src/devkit-exports.d.ts +3 -1
  3. package/src/devkit-exports.js +5 -1
  4. package/src/devkit-internals.d.ts +1 -0
  5. package/src/devkit-internals.js +3 -1
  6. package/src/plugins/js/lock-file/pnpm-parser.js +1 -1
  7. package/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +16 -3
  8. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +2 -1
  9. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +40 -27
  10. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +2 -1
  11. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +14 -19
  12. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +32 -5
  13. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +146 -47
  14. package/src/plugins/js/utils/resolve-relative-to-dir.d.ts +5 -0
  15. package/src/plugins/js/utils/resolve-relative-to-dir.js +18 -0
  16. package/src/project-graph/error-types.d.ts +37 -19
  17. package/src/project-graph/error-types.js +31 -19
  18. package/src/project-graph/plugins/index.d.ts +1 -0
  19. package/src/project-graph/plugins/index.js +3 -1
  20. package/src/project-graph/plugins/internal-api.d.ts +2 -2
  21. package/src/project-graph/plugins/internal-api.js +33 -3
  22. package/src/project-graph/plugins/public-api.d.ts +34 -3
  23. package/src/project-graph/plugins/utils.d.ts +4 -3
  24. package/src/project-graph/plugins/utils.js +13 -26
  25. package/src/project-graph/utils/project-configuration-utils.js +89 -74
  26. package/src/tasks-runner/utils.js +18 -4
  27. package/src/utils/print-help.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "19.2.0-canary.20240528-7f11a1d",
3
+ "version": "19.2.0-canary.20240531-2cb7ecb",
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": {
@@ -69,7 +69,7 @@
69
69
  "yargs-parser": "21.1.1",
70
70
  "node-machine-id": "1.1.12",
71
71
  "ora": "5.3.0",
72
- "@nrwl/tao": "19.2.0-canary.20240528-7f11a1d"
72
+ "@nrwl/tao": "19.2.0-canary.20240531-2cb7ecb"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "@swc-node/register": "^1.8.0",
@@ -84,16 +84,16 @@
84
84
  }
85
85
  },
86
86
  "optionalDependencies": {
87
- "@nx/nx-darwin-x64": "19.2.0-canary.20240528-7f11a1d",
88
- "@nx/nx-darwin-arm64": "19.2.0-canary.20240528-7f11a1d",
89
- "@nx/nx-linux-x64-gnu": "19.2.0-canary.20240528-7f11a1d",
90
- "@nx/nx-linux-x64-musl": "19.2.0-canary.20240528-7f11a1d",
91
- "@nx/nx-win32-x64-msvc": "19.2.0-canary.20240528-7f11a1d",
92
- "@nx/nx-linux-arm64-gnu": "19.2.0-canary.20240528-7f11a1d",
93
- "@nx/nx-linux-arm64-musl": "19.2.0-canary.20240528-7f11a1d",
94
- "@nx/nx-linux-arm-gnueabihf": "19.2.0-canary.20240528-7f11a1d",
95
- "@nx/nx-win32-arm64-msvc": "19.2.0-canary.20240528-7f11a1d",
96
- "@nx/nx-freebsd-x64": "19.2.0-canary.20240528-7f11a1d"
87
+ "@nx/nx-darwin-x64": "19.2.0-canary.20240531-2cb7ecb",
88
+ "@nx/nx-darwin-arm64": "19.2.0-canary.20240531-2cb7ecb",
89
+ "@nx/nx-linux-x64-gnu": "19.2.0-canary.20240531-2cb7ecb",
90
+ "@nx/nx-linux-x64-musl": "19.2.0-canary.20240531-2cb7ecb",
91
+ "@nx/nx-win32-x64-msvc": "19.2.0-canary.20240531-2cb7ecb",
92
+ "@nx/nx-linux-arm64-gnu": "19.2.0-canary.20240531-2cb7ecb",
93
+ "@nx/nx-linux-arm64-musl": "19.2.0-canary.20240531-2cb7ecb",
94
+ "@nx/nx-linux-arm-gnueabihf": "19.2.0-canary.20240531-2cb7ecb",
95
+ "@nx/nx-win32-arm64-msvc": "19.2.0-canary.20240531-2cb7ecb",
96
+ "@nx/nx-freebsd-x64": "19.2.0-canary.20240531-2cb7ecb"
97
97
  },
98
98
  "nx-migrations": {
99
99
  "migrations": "./migrations.json",
@@ -15,7 +15,9 @@ export type { WorkspaceJsonConfiguration, ProjectsConfigurations, TargetDependen
15
15
  */
16
16
  export type { Generator, GeneratorCallback, Executor, ExecutorContext, TaskGraphExecutor, GeneratorsJson, ExecutorsJson, MigrationsJson, CustomHasher, HasherContext, } from './config/misc-interfaces';
17
17
  export { workspaceLayout } from './config/configuration';
18
- export type { NxPlugin, NxPluginV2, CreateNodes, CreateNodesFunction, CreateNodesResult, CreateNodesContext, CreateDependencies, CreateDependenciesContext, CreateMetadata, CreateMetadataContext, ProjectsMetadata, } from './project-graph/plugins';
18
+ export type { NxPlugin, NxPluginV2, CreateNodes, CreateNodesFunction, CreateNodesResult, CreateNodesContext, CreateNodesContextV2, CreateNodesFunctionV2, CreateNodesResultV2, CreateNodesV2, CreateDependencies, CreateDependenciesContext, CreateMetadata, CreateMetadataContext, ProjectsMetadata, } from './project-graph/plugins';
19
+ export { AggregateCreateNodesError } from './project-graph/error-types';
20
+ export { createNodesFromFiles } from './project-graph/plugins';
19
21
  export type { NxPluginV1, ProjectTargetConfigurator, } from './utils/nx-plugin.deprecated';
20
22
  /**
21
23
  * @category Workspace
@@ -4,9 +4,13 @@
4
4
  * Try hard to not add to this API to reduce the surface area we need to maintain.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createProjectFileMapUsingProjectGraph = exports.cacheDir = exports.hashArray = exports.defaultTasksRunner = exports.getOutputsForTargetAndConfiguration = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectGraph = exports.createProjectGraphAsync = exports.reverse = exports.appRootPath = exports.workspaceRoot = exports.normalizePath = exports.joinPathFragments = exports.stripIndents = exports.writeJsonFile = exports.readJsonFile = exports.stripJsonComments = exports.serializeJson = exports.parseJson = exports.updateJson = exports.writeJson = exports.readJson = exports.validateDependency = exports.ProjectGraphBuilder = exports.DependencyType = exports.updateNxJson = exports.readNxJson = exports.glob = exports.getProjects = exports.updateProjectConfiguration = exports.removeProjectConfiguration = exports.readProjectConfiguration = exports.addProjectConfiguration = exports.runExecutor = exports.isWorkspacesEnabled = exports.getPackageManagerVersion = exports.detectPackageManager = exports.getPackageManagerCommand = exports.output = exports.logger = exports.workspaceLayout = void 0;
7
+ exports.createProjectFileMapUsingProjectGraph = exports.cacheDir = exports.hashArray = exports.defaultTasksRunner = exports.getOutputsForTargetAndConfiguration = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectGraph = exports.createProjectGraphAsync = exports.reverse = exports.appRootPath = exports.workspaceRoot = exports.normalizePath = exports.joinPathFragments = exports.stripIndents = exports.writeJsonFile = exports.readJsonFile = exports.stripJsonComments = exports.serializeJson = exports.parseJson = exports.updateJson = exports.writeJson = exports.readJson = exports.validateDependency = exports.ProjectGraphBuilder = exports.DependencyType = exports.updateNxJson = exports.readNxJson = exports.glob = exports.getProjects = exports.updateProjectConfiguration = exports.removeProjectConfiguration = exports.readProjectConfiguration = exports.addProjectConfiguration = exports.runExecutor = exports.isWorkspacesEnabled = exports.getPackageManagerVersion = exports.detectPackageManager = exports.getPackageManagerCommand = exports.output = exports.logger = exports.createNodesFromFiles = exports.AggregateCreateNodesError = exports.workspaceLayout = void 0;
8
8
  var configuration_1 = require("./config/configuration");
9
9
  Object.defineProperty(exports, "workspaceLayout", { enumerable: true, get: function () { return configuration_1.workspaceLayout; } });
10
+ var error_types_1 = require("./project-graph/error-types");
11
+ Object.defineProperty(exports, "AggregateCreateNodesError", { enumerable: true, get: function () { return error_types_1.AggregateCreateNodesError; } });
12
+ var plugins_1 = require("./project-graph/plugins");
13
+ Object.defineProperty(exports, "createNodesFromFiles", { enumerable: true, get: function () { return plugins_1.createNodesFromFiles; } });
10
14
  /**
11
15
  * @category Logger
12
16
  */
@@ -23,3 +23,4 @@ export { retrieveProjectConfigurations } from './project-graph/utils/retrieve-wo
23
23
  export { LoadedNxPlugin } from './project-graph/plugins/internal-api';
24
24
  export * from './project-graph/error-types';
25
25
  export { registerTsProject } from './plugins/js/utils/register';
26
+ export { interpolate } from './tasks-runner/utils';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerTsProject = exports.LoadedNxPlugin = exports.retrieveProjectConfigurations = exports.findProjectForPath = exports.createProjectRootMappingsFromProjectConfigurations = exports.hashWithWorkspaceContext = exports.hashObject = exports.splitByColons = exports.readModulePackageJson = exports.stripIndent = exports.sortObjectByKeys = exports.combineOptionsForExecutor = exports.splitTarget = exports.readProjectConfigurationsFromRootMap = exports.mergeTargetConfigurations = exports.retrieveProjectConfigurationsWithAngularProjects = exports.calculateDefaultProjectName = exports.readNxJsonFromDisk = exports.getExecutorInformation = exports.createTempNpmDirectory = void 0;
3
+ exports.interpolate = exports.registerTsProject = exports.LoadedNxPlugin = exports.retrieveProjectConfigurations = exports.findProjectForPath = exports.createProjectRootMappingsFromProjectConfigurations = exports.hashWithWorkspaceContext = exports.hashObject = exports.splitByColons = exports.readModulePackageJson = exports.stripIndent = exports.sortObjectByKeys = exports.combineOptionsForExecutor = exports.splitTarget = exports.readProjectConfigurationsFromRootMap = exports.mergeTargetConfigurations = exports.retrieveProjectConfigurationsWithAngularProjects = exports.calculateDefaultProjectName = exports.readNxJsonFromDisk = exports.getExecutorInformation = exports.createTempNpmDirectory = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /**
6
6
  * Note to developers: STOP! These exports are available via requireNx in @nx/devkit.
@@ -47,3 +47,5 @@ Object.defineProperty(exports, "LoadedNxPlugin", { enumerable: true, get: functi
47
47
  tslib_1.__exportStar(require("./project-graph/error-types"), exports);
48
48
  var register_1 = require("./plugins/js/utils/register");
49
49
  Object.defineProperty(exports, "registerTsProject", { enumerable: true, get: function () { return register_1.registerTsProject; } });
50
+ var utils_1 = require("./tasks-runner/utils");
51
+ Object.defineProperty(exports, "interpolate", { enumerable: true, get: function () { return utils_1.interpolate; } });
@@ -233,7 +233,7 @@ function getNodes(data, keyMap, isV5) {
233
233
  function getHoistedVersion(hoistedDependencies, packageName, isV5) {
234
234
  let version = (0, package_json_1.getHoistedPackageVersion)(packageName);
235
235
  if (!version) {
236
- const key = Object.keys(hoistedDependencies).find((k) => k.startsWith(isV5 ? `/${packageName}/` : `/${packageName}@`));
236
+ const key = Object.keys(hoistedDependencies).find((k) => k.startsWith(`/${packageName}/`));
237
237
  if (key) {
238
238
  version = parseBaseVersion(getVersion(key.slice(1), packageName), isV5);
239
239
  }
@@ -1,12 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExplicitDependencies = void 0;
4
- const explicit_project_dependencies_1 = require("./explicit-project-dependencies");
5
4
  const explicit_package_json_dependencies_1 = require("./explicit-package-json-dependencies");
5
+ const explicit_project_dependencies_1 = require("./explicit-project-dependencies");
6
+ const target_project_locator_1 = require("./target-project-locator");
6
7
  function buildExplicitDependencies(jsPluginConfig, ctx) {
7
8
  if (totalNumberOfFilesToProcess(ctx) === 0)
8
9
  return [];
9
10
  let dependencies = [];
11
+ // TODO: TargetProjectLocator is a public API, so we can't change the shape of it
12
+ // We should eventually let it accept Record<string, ProjectConfiguration> s.t. we
13
+ // don't have to reshape the CreateDependenciesContext here.
14
+ const nodes = Object.fromEntries(Object.entries(ctx.projects).map(([key, config]) => [
15
+ key,
16
+ {
17
+ name: key,
18
+ type: null,
19
+ data: config,
20
+ },
21
+ ]));
22
+ const targetProjectLocator = new target_project_locator_1.TargetProjectLocator(nodes, ctx.externalNodes);
10
23
  if (jsPluginConfig.analyzeSourceFiles === undefined ||
11
24
  jsPluginConfig.analyzeSourceFiles === true) {
12
25
  let tsExists = false;
@@ -16,12 +29,12 @@ function buildExplicitDependencies(jsPluginConfig, ctx) {
16
29
  }
17
30
  catch { }
18
31
  if (tsExists) {
19
- dependencies = dependencies.concat((0, explicit_project_dependencies_1.buildExplicitTypeScriptDependencies)(ctx));
32
+ dependencies = dependencies.concat((0, explicit_project_dependencies_1.buildExplicitTypeScriptDependencies)(ctx, targetProjectLocator));
20
33
  }
21
34
  }
22
35
  if (jsPluginConfig.analyzePackageJson === undefined ||
23
36
  jsPluginConfig.analyzePackageJson === true) {
24
- dependencies = dependencies.concat((0, explicit_package_json_dependencies_1.buildExplicitPackageJsonDependencies)(ctx));
37
+ dependencies = dependencies.concat((0, explicit_package_json_dependencies_1.buildExplicitPackageJsonDependencies)(ctx, targetProjectLocator));
25
38
  }
26
39
  return dependencies;
27
40
  }
@@ -1,3 +1,4 @@
1
1
  import { CreateDependenciesContext } from '../../../../project-graph/plugins';
2
2
  import { RawProjectGraphDependency } from '../../../../project-graph/project-graph-builder';
3
- export declare function buildExplicitPackageJsonDependencies(ctx: CreateDependenciesContext): RawProjectGraphDependency[];
3
+ import { TargetProjectLocator } from './target-project-locator';
4
+ export declare function buildExplicitPackageJsonDependencies(ctx: CreateDependenciesContext, targetProjectLocator: TargetProjectLocator): RawProjectGraphDependency[];
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExplicitPackageJsonDependencies = void 0;
4
- const file_utils_1 = require("../../../../project-graph/file-utils");
5
- const path_1 = require("path");
4
+ const node_path_1 = require("node:path");
6
5
  const project_graph_1 = require("../../../../config/project-graph");
7
- const json_1 = require("../../../../utils/json");
8
- const path_2 = require("../../../../utils/path");
6
+ const file_utils_1 = require("../../../../project-graph/file-utils");
9
7
  const project_graph_builder_1 = require("../../../../project-graph/project-graph-builder");
10
- function buildExplicitPackageJsonDependencies(ctx) {
8
+ const json_1 = require("../../../../utils/json");
9
+ const path_1 = require("../../../../utils/path");
10
+ function buildExplicitPackageJsonDependencies(ctx, targetProjectLocator) {
11
11
  const res = [];
12
12
  let packageNameMap = undefined;
13
13
  const nodes = Object.values(ctx.projects);
@@ -16,7 +16,7 @@ function buildExplicitPackageJsonDependencies(ctx) {
16
16
  if (isPackageJsonAtProjectRoot(nodes, f.file)) {
17
17
  // we only create the package name map once and only if a package.json file changes
18
18
  packageNameMap = packageNameMap || createPackageNameMap(ctx.projects);
19
- processPackageJson(source, f.file, ctx, res, packageNameMap);
19
+ processPackageJson(source, f.file, ctx, targetProjectLocator, res, packageNameMap);
20
20
  }
21
21
  });
22
22
  });
@@ -27,7 +27,7 @@ function createPackageNameMap(projects) {
27
27
  const res = {};
28
28
  for (let projectName of Object.keys(projects)) {
29
29
  try {
30
- const packageJson = (0, json_1.parseJson)((0, file_utils_1.defaultFileRead)((0, path_1.join)(projects[projectName].root, 'package.json')));
30
+ const packageJson = (0, json_1.parseJson)((0, file_utils_1.defaultFileRead)((0, node_path_1.join)(projects[projectName].root, 'package.json')));
31
31
  res[packageJson.name ?? projectName] = projectName;
32
32
  }
33
33
  catch (e) { }
@@ -36,13 +36,12 @@ function createPackageNameMap(projects) {
36
36
  }
37
37
  function isPackageJsonAtProjectRoot(nodes, fileName) {
38
38
  return (fileName.endsWith('package.json') &&
39
- nodes.find((projectNode) => (0, path_2.joinPathFragments)(projectNode.root, 'package.json') === fileName));
39
+ nodes.find((projectNode) => (0, path_1.joinPathFragments)(projectNode.root, 'package.json') === fileName));
40
40
  }
41
- function processPackageJson(sourceProject, fileName, ctx, collectedDeps, packageNameMap) {
41
+ function processPackageJson(sourceProject, fileName, ctx, targetProjectLocator, collectedDeps, packageNameMap) {
42
42
  try {
43
43
  const deps = readDeps((0, json_1.parseJson)((0, file_utils_1.defaultFileRead)(fileName)));
44
- // the name matches the import path
45
- deps.forEach((d) => {
44
+ for (const d of Object.keys(deps)) {
46
45
  // package.json refers to another project in the monorepo
47
46
  if (packageNameMap[d]) {
48
47
  const dependency = {
@@ -53,30 +52,44 @@ function processPackageJson(sourceProject, fileName, ctx, collectedDeps, package
53
52
  };
54
53
  (0, project_graph_builder_1.validateDependency)(dependency, ctx);
55
54
  collectedDeps.push(dependency);
55
+ continue;
56
56
  }
57
- else if (ctx.externalNodes[`npm:${d}`]) {
58
- const dependency = {
59
- source: sourceProject,
60
- target: `npm:${d}`,
61
- sourceFile: fileName,
62
- type: project_graph_1.DependencyType.static,
63
- };
64
- (0, project_graph_builder_1.validateDependency)(dependency, ctx);
65
- collectedDeps.push(dependency);
57
+ const externalNodeName = targetProjectLocator.findNpmProjectFromImport(d, fileName);
58
+ if (!externalNodeName) {
59
+ continue;
66
60
  }
67
- });
61
+ const dependency = {
62
+ source: sourceProject,
63
+ target: externalNodeName,
64
+ sourceFile: fileName,
65
+ type: project_graph_1.DependencyType.static,
66
+ };
67
+ (0, project_graph_builder_1.validateDependency)(dependency, ctx);
68
+ collectedDeps.push(dependency);
69
+ }
68
70
  }
69
71
  catch (e) {
70
72
  if (process.env.NX_VERBOSE_LOGGING === 'true') {
71
- console.log(e);
73
+ console.error(e);
72
74
  }
73
75
  }
74
76
  }
75
77
  function readDeps(packageJson) {
76
- return [
77
- ...Object.keys(packageJson?.dependencies ?? {}),
78
- ...Object.keys(packageJson?.devDependencies ?? {}),
79
- ...Object.keys(packageJson?.peerDependencies ?? {}),
80
- ...Object.keys(packageJson?.optionalDependencies ?? {}),
78
+ const deps = {};
79
+ /**
80
+ * We process dependencies in a rough order of increasing importance such that if a dependency is listed in multiple
81
+ * sections, the version listed under the "most important" one wins, with production dependencies being the most important.
82
+ */
83
+ const depType = [
84
+ 'optionalDependencies',
85
+ 'peerDependencies',
86
+ 'devDependencies',
87
+ 'dependencies',
81
88
  ];
89
+ for (const type of depType) {
90
+ for (const [depName, depVersion] of Object.entries(packageJson[type] || {})) {
91
+ deps[depName] = depVersion;
92
+ }
93
+ }
94
+ return deps;
82
95
  }
@@ -1,3 +1,4 @@
1
1
  import { CreateDependenciesContext } from '../../../../project-graph/plugins';
2
2
  import { RawProjectGraphDependency } from '../../../../project-graph/project-graph-builder';
3
- export declare function buildExplicitTypeScriptDependencies(ctx: CreateDependenciesContext): RawProjectGraphDependency[];
3
+ import { TargetProjectLocator } from './target-project-locator';
4
+ export declare function buildExplicitTypeScriptDependencies(ctx: CreateDependenciesContext, targetProjectLocator: TargetProjectLocator): RawProjectGraphDependency[];
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExplicitTypeScriptDependencies = void 0;
4
- const target_project_locator_1 = require("./target-project-locator");
5
- const project_graph_1 = require("../../../../config/project-graph");
6
4
  const path_1 = require("path");
7
- const workspace_root_1 = require("../../../../utils/workspace-root");
8
- const path_2 = require("../../../../utils/path");
5
+ const project_graph_1 = require("../../../../config/project-graph");
9
6
  const project_graph_builder_1 = require("../../../../project-graph/project-graph-builder");
7
+ const path_2 = require("../../../../utils/path");
8
+ const workspace_root_1 = require("../../../../utils/workspace-root");
10
9
  function isRoot(projects, projectName) {
11
10
  return projects[projectName]?.root === '.';
12
11
  }
13
12
  function convertImportToDependency(importExpr, sourceFile, source, type, targetProjectLocator) {
14
- const target = targetProjectLocator.findProjectWithImport(importExpr, sourceFile) ??
15
- `npm:${importExpr}`;
13
+ const target = targetProjectLocator.findProjectFromImport(importExpr, sourceFile);
14
+ if (!target) {
15
+ return;
16
+ }
16
17
  return {
17
18
  source,
18
19
  target,
@@ -20,19 +21,7 @@ function convertImportToDependency(importExpr, sourceFile, source, type, targetP
20
21
  type,
21
22
  };
22
23
  }
23
- function buildExplicitTypeScriptDependencies(ctx) {
24
- // TODO: TargetProjectLocator is a public API, so we can't change the shape of it
25
- // We should eventually let it accept Record<string, ProjectConfiguration> s.t. we
26
- // don't have to reshape the CreateDependenciesContext here.
27
- const nodes = Object.fromEntries(Object.entries(ctx.projects).map(([key, config]) => [
28
- key,
29
- {
30
- name: key,
31
- type: null,
32
- data: config,
33
- },
34
- ]));
35
- const targetProjectLocator = new target_project_locator_1.TargetProjectLocator(nodes, ctx.externalNodes);
24
+ function buildExplicitTypeScriptDependencies(ctx, targetProjectLocator) {
36
25
  const res = [];
37
26
  const filesToProcess = {};
38
27
  const moduleExtensions = [
@@ -63,6 +52,9 @@ function buildExplicitTypeScriptDependencies(ctx) {
63
52
  const normalizedFilePath = (0, path_2.normalizePath)((0, path_1.relative)(workspace_root_1.workspaceRoot, file));
64
53
  for (const importExpr of staticImportExpressions) {
65
54
  const dependency = convertImportToDependency(importExpr, normalizedFilePath, sourceProject, project_graph_1.DependencyType.static, targetProjectLocator);
55
+ if (!dependency) {
56
+ continue;
57
+ }
66
58
  // TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
67
59
  if (isRoot(ctx.projects, dependency.source) ||
68
60
  !isRoot(ctx.projects, dependency.target)) {
@@ -71,6 +63,9 @@ function buildExplicitTypeScriptDependencies(ctx) {
71
63
  }
72
64
  for (const importExpr of dynamicImportExpressions) {
73
65
  const dependency = convertImportToDependency(importExpr, normalizedFilePath, sourceProject, project_graph_1.DependencyType.dynamic, targetProjectLocator);
66
+ if (!dependency) {
67
+ continue;
68
+ }
74
69
  // TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
75
70
  if (isRoot(ctx.projects, dependency.source) ||
76
71
  !isRoot(ctx.projects, dependency.target)) {
@@ -1,21 +1,37 @@
1
1
  import { ProjectGraphExternalNode, ProjectGraphProjectNode } from '../../../../config/project-graph';
2
+ /**
3
+ * The key is a combination of the package name and the workspace relative directory
4
+ * containing the file importing it e.g. `lodash__packages/my-lib`, the value is the
5
+ * resolved external node name from the project graph.
6
+ */
7
+ type NpmResolutionCache = Map<string, string | null>;
8
+ export declare function isBuiltinModuleImport(importExpr: string): boolean;
2
9
  export declare class TargetProjectLocator {
3
10
  private readonly nodes;
4
11
  private readonly externalNodes;
12
+ private readonly npmResolutionCache;
5
13
  private projectRootMappings;
6
14
  private npmProjects;
7
15
  private tsConfig;
8
16
  private paths;
9
17
  private typescriptResolutionCache;
10
- private npmResolutionCache;
11
- constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes: Record<string, ProjectGraphExternalNode>);
18
+ constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes?: Record<string, ProjectGraphExternalNode>, npmResolutionCache?: NpmResolutionCache);
12
19
  /**
13
- * Find a project based on its import
20
+ * Resolve any workspace or external project that matches the given import expression,
21
+ * originating from the given filePath.
14
22
  *
15
23
  * @param importExpr
16
24
  * @param filePath
17
25
  */
18
- findProjectWithImport(importExpr: string, filePath: string): string;
26
+ findProjectFromImport(importExpr: string, filePath: string): string;
27
+ /**
28
+ * Resolve any external project that matches the given import expression,
29
+ * relative to the given file path.
30
+ *
31
+ * @param importExpr
32
+ * @param projectRoot
33
+ */
34
+ findNpmProjectFromImport(importExpr: string, fromFilePath: string): string | null;
19
35
  /**
20
36
  * Return file paths matching the import relative to the repo root
21
37
  * @param normalizedImportExpr
@@ -24,9 +40,20 @@ export declare class TargetProjectLocator {
24
40
  findPaths(normalizedImportExpr: string): string[] | undefined;
25
41
  private resolveImportWithTypescript;
26
42
  private resolveImportWithRequire;
27
- private findNpmPackage;
28
43
  private findProjectOfResolvedModule;
29
44
  private getAbsolutePath;
30
45
  private getRootTsConfig;
31
46
  private findMatchingProjectFiles;
47
+ /**
48
+ * In many cases the package.json will be directly resolvable, so we try that first.
49
+ * If, however, package exports are used and the package.json is not defined, we will
50
+ * need to resolve the main entry point of the package and traverse upwards to find the
51
+ * package.json.
52
+ *
53
+ * In some cases, such as when multiple module formats are published, the resolved package.json
54
+ * might only contain the "type" field - no "name" or "version", so in such cases we keep traversing
55
+ * until we find a package.json that contains the "name" and "version" fields.
56
+ */
57
+ private readPackageJson;
32
58
  }
59
+ export {};