Skip to content

Commit

Permalink
fix(core): target project locator should track only hoisted external …
Browse files Browse the repository at this point in the history
…deps (#12905)
  • Loading branch information
meeroslav committed Oct 31, 2022
1 parent 28620cb commit 0c52e67
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/nx/src/utils/target-project-locator.ts
Expand Up @@ -9,9 +9,7 @@ import {

export class TargetProjectLocator {
private projectRootMappings = createProjectRootMappings(this.nodes);
private npmProjects = this.externalNodes
? Object.values(this.externalNodes)
: [];
private npmProjects = filterRootExternalDependencies(this.externalNodes);
private tsConfig = this.getRootTsConfig();
private paths = this.tsConfig.config?.compilerOptions?.paths;
private typescriptResolutionCache = new Map<string, string | null>();
Expand Down Expand Up @@ -181,6 +179,25 @@ export class TargetProjectLocator {
}
}

// matches `npm:@scope/name`, `npm:name` but not `npm:@scope/name@version` and `npm:name@version`
const ROOT_VERSION_PACKAGE_NAME_REGEX = /^npm:(?!.+@.+)/;

function filterRootExternalDependencies(
externalNodes: Record<string, ProjectGraphExternalNode>
): ProjectGraphExternalNode[] {
if (!externalNodes) {
return [];
}
const keys = Object.keys(externalNodes);
const nodes = [];
for (let i = 0; i < keys.length; i++) {
if (keys[i].match(ROOT_VERSION_PACKAGE_NAME_REGEX)) {
nodes.push(externalNodes[keys[i]]);
}
}
return nodes;
}

function createProjectRootMappings(
nodes: Record<string, ProjectGraphProjectNode>
) {
Expand Down

1 comment on commit 0c52e67

@vercel
Copy link

@vercel vercel bot commented on 0c52e67 Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-dev-nrwl.vercel.app

Please sign in to comment.