Skip to content

Commit f02a88a

Browse files
authored
Revert "fix(core): support subpath exports when constructing the project graph" (#29762)
Reverts #29577 There is an issue with workspaces using tsconfig path alias, and when an invalid import is found, it'll match on the wrong package due to the name matching the prefix.
1 parent 7df5737 commit f02a88a

File tree

3 files changed

+3
-71
lines changed

3 files changed

+3
-71
lines changed

packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.spec.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,52 +1011,6 @@ describe('TargetProjectLocator', () => {
10111011
expect(result).toEqual('npm:foo@0.0.1');
10121012
});
10131013
});
1014-
1015-
describe('findDependencyInWorkspaceProjects', () => {
1016-
it.each`
1017-
pkgName | project | exports | dependency
1018-
${'@org/pkg1'} | ${'pkg1'} | ${undefined} | ${'@org/pkg1'}
1019-
${'@org/pkg1'} | ${'pkg1'} | ${undefined} | ${'@org/pkg1/subpath'}
1020-
${'@org/pkg1'} | ${'pkg1'} | ${'dist/index.js'} | ${'@org/pkg1'}
1021-
${'@org/pkg1'} | ${'pkg1'} | ${{}} | ${'@org/pkg1'}
1022-
${'@org/pkg1'} | ${'pkg1'} | ${{}} | ${'@org/pkg1/subpath'}
1023-
${'@org/pkg1'} | ${'pkg1'} | ${{ '.': 'dist/index.js' }} | ${'@org/pkg1'}
1024-
${'@org/pkg1'} | ${'pkg1'} | ${{ '.': 'dist/index.js' }} | ${'@org/pkg1/subpath'}
1025-
${'@org/pkg1'} | ${'pkg1'} | ${{ './subpath': './dist/subpath.js' }} | ${'@org/pkg1'}
1026-
${'@org/pkg1'} | ${'pkg1'} | ${{ './subpath': './dist/subpath.js' }} | ${'@org/pkg1/subpath'}
1027-
${'@org/pkg1'} | ${'pkg1'} | ${{ import: './dist/index.js', default: './dist/index.js' }} | ${'@org/pkg1'}
1028-
${'@org/pkg1'} | ${'pkg1'} | ${{ import: './dist/index.js', default: './dist/index.js' }} | ${'@org/pkg1/subpath'}
1029-
`(
1030-
'should find "$dependency" as "$project" when exports="$exports"',
1031-
({ pkgName, project, exports, dependency }) => {
1032-
let projects: Record<string, ProjectGraphProjectNode> = {
1033-
[project]: {
1034-
name: project,
1035-
type: 'lib' as const,
1036-
data: {
1037-
root: project,
1038-
metadata: {
1039-
js: {
1040-
packageName: pkgName,
1041-
packageExports: exports,
1042-
},
1043-
},
1044-
},
1045-
},
1046-
};
1047-
1048-
const targetProjectLocator = new TargetProjectLocator(
1049-
projects,
1050-
{},
1051-
new Map()
1052-
);
1053-
const result =
1054-
targetProjectLocator.findDependencyInWorkspaceProjects(dependency);
1055-
1056-
expect(result).toEqual(project);
1057-
}
1058-
);
1059-
});
10601014
});
10611015

10621016
describe('isBuiltinModuleImport()', () => {

packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,7 @@ export class TargetProjectLocator {
259259
this.nodes
260260
);
261261

262-
return (
263-
this.packageEntryPointsToProjectMap[dep]?.name ??
264-
// if the package exports do not include ".", look for subpath exports
265-
Object.entries(this.packageEntryPointsToProjectMap).find(([entryPoint]) =>
266-
dep.startsWith(`${entryPoint}/`)
267-
)?.[1]?.name ??
268-
null
269-
);
262+
return this.packageEntryPointsToProjectMap[dep]?.name ?? null;
270263
}
271264

272265
private resolveImportWithTypescript(

packages/nx/src/plugins/js/utils/packages.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,13 @@ export function getPackageEntryPointsToProjectMap<
1515
}
1616

1717
const { packageName, packageExports } = metadata.js;
18-
if (
19-
!packageExports ||
20-
typeof packageExports === 'string' ||
21-
!Object.keys(packageExports).length
22-
) {
18+
if (!packageExports || typeof packageExports === 'string') {
2319
// no `exports` or it points to a file, which would be the equivalent of
2420
// an '.' export, in which case the package name is the entry point
2521
result[packageName] = project;
2622
} else {
2723
for (const entryPoint of Object.keys(packageExports)) {
28-
// if entrypoint begins with '.', it is a relative subpath export
29-
// otherwise, it is a conditional export
30-
// https://nodejs.org/api/packages.html#conditional-exports
31-
if (entryPoint.startsWith('.')) {
32-
result[join(packageName, entryPoint)] = project;
33-
} else {
34-
result[packageName] = project;
35-
}
36-
}
37-
// if there was no '.' entrypoint, ensure the package name is matched with the project
38-
if (!result[packageName]) {
39-
result[packageName] = project;
24+
result[join(packageName, entryPoint)] = project;
4025
}
4126
}
4227
}

0 commit comments

Comments
 (0)