-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): improve resolution of packages in package manager workspac…
…es when constructing the project graph
- Loading branch information
1 parent
8266785
commit 5cc03ea
Showing
14 changed files
with
560 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,8 @@ describe('TargetProjectLocator', () => { | |
js: { | ||
packageName: '@proj/child-pm-workspaces', | ||
packageExports: undefined, | ||
isInPackageManagerWorkspaces: true, | ||
packageMain: 'index.ts', | ||
}, | ||
}, | ||
}, | ||
|
@@ -1011,6 +1013,197 @@ describe('TargetProjectLocator', () => { | |
expect(result).toEqual('npm:[email protected]'); | ||
}); | ||
}); | ||
|
||
describe('findDependencyInWorkspaceProjects', () => { | ||
it.each` | ||
exports | ||
${undefined} | ||
${'dist/index.js'} | ||
${{}} | ||
${{ '.': 'dist/index.js' }} | ||
${{ './subpath': './dist/subpath.js' }} | ||
${{ import: './dist/index.js', default: './dist/index.js' }} | ||
`( | ||
'should find "@org/pkg1" package as "pkg1" project when exports="$exports"', | ||
({ exports }) => { | ||
let projects: Record<string, ProjectGraphProjectNode> = { | ||
pkg1: { | ||
name: 'pkg1', | ||
type: 'lib' as const, | ||
data: { | ||
root: 'pkg1', | ||
metadata: { | ||
js: { | ||
packageName: '@org/pkg1', | ||
packageExports: exports, | ||
isInPackageManagerWorkspaces: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const targetProjectLocator = new TargetProjectLocator( | ||
projects, | ||
{}, | ||
new Map() | ||
); | ||
const result = | ||
targetProjectLocator.findDependencyInWorkspaceProjects('@org/pkg1'); | ||
|
||
expect(result).toEqual('pkg1'); | ||
} | ||
); | ||
|
||
it('should not match "@org/pkg2" when there is no workspace project with that package name', () => { | ||
let projects: Record<string, ProjectGraphProjectNode> = { | ||
pkg1: { | ||
name: 'pkg1', | ||
type: 'lib' as const, | ||
data: { | ||
root: 'pkg1', | ||
metadata: { | ||
js: { | ||
packageName: '@org/pkg1', | ||
isInPackageManagerWorkspaces: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const targetProjectLocator = new TargetProjectLocator( | ||
projects, | ||
{}, | ||
new Map() | ||
); | ||
const result = | ||
targetProjectLocator.findDependencyInWorkspaceProjects('@org/pkg2'); | ||
|
||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('findImportInWorkspaceProjects', () => { | ||
it.each` | ||
exports | importPath | ||
${'dist/index.js'} | ${'@org/pkg1'} | ||
${{ '.': 'dist/index.js' }} | ${'@org/pkg1'} | ||
${{ './subpath': './dist/subpath.js' }} | ${'@org/pkg1/subpath'} | ||
${{ './*': './dist/*.js' }} | ${'@org/pkg1/subpath'} | ||
${{ import: './dist/index.js', default: './dist/index.js' }} | ${'@org/pkg1'} | ||
`( | ||
'should find "$importPath" as "pkg1" project when exports="$exports"', | ||
({ exports, importPath }) => { | ||
let projects: Record<string, ProjectGraphProjectNode> = { | ||
pkg1: { | ||
name: 'pkg1', | ||
type: 'lib' as const, | ||
data: { | ||
root: 'pkg1', | ||
metadata: { | ||
js: { | ||
packageName: '@org/pkg1', | ||
packageExports: exports, | ||
isInPackageManagerWorkspaces: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const targetProjectLocator = new TargetProjectLocator( | ||
projects, | ||
{}, | ||
new Map() | ||
); | ||
const result = | ||
targetProjectLocator.findImportInWorkspaceProjects(importPath); | ||
|
||
expect(result).toEqual('pkg1'); | ||
} | ||
); | ||
|
||
it.each` | ||
exports | importPath | ||
${'dist/index.js'} | ${'@org/pkg1'} | ||
${{ '.': 'dist/index.js' }} | ${'@org/pkg1'} | ||
${{ './subpath': './dist/subpath.js' }} | ${'@org/pkg1/subpath'} | ||
${{ './*': './dist/*.js' }} | ${'@org/pkg1/subpath'} | ||
${{ import: './dist/index.js', default: './dist/index.js' }} | ${'@org/pkg1'} | ||
`( | ||
'should not find "$importPath" as "pkg1" project when exports="$exports" and isInPackageManagerWorkspaces is false', | ||
({ exports, importPath }) => { | ||
let projects: Record<string, ProjectGraphProjectNode> = { | ||
pkg1: { | ||
name: 'pkg1', | ||
type: 'lib' as const, | ||
data: { | ||
root: 'pkg1', | ||
metadata: { | ||
js: { | ||
packageName: '@org/pkg1', | ||
packageExports: exports, | ||
isInPackageManagerWorkspaces: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const targetProjectLocator = new TargetProjectLocator( | ||
projects, | ||
{}, | ||
new Map() | ||
); | ||
const result = | ||
targetProjectLocator.findImportInWorkspaceProjects(importPath); | ||
|
||
expect(result).toBeFalsy(); | ||
} | ||
); | ||
|
||
it.each` | ||
exports | importPath | ||
${undefined} | ${'@org/pkg1'} | ||
${{}} | ${'@org/pkg1'} | ||
${{ '.': 'dist/index.js' }} | ${'@org/pkg1/subpath'} | ||
${{ './subpath': './dist/subpath.js' }} | ${'@org/pkg1/subpath/extra-path'} | ||
${{ './*': './dist/*.js' }} | ${'@org/pkg1/subpath/extra-path'} | ||
${{ './feature': null }} | ${'@org/pkg1/feature'} | ||
${{ import: './dist/index.js', default: './dist/index.js' }} | ${'@org/pkg1/subpath'} | ||
`( | ||
'should not match "$importPath" when exports="$exports"', | ||
({ exports, importPath }) => { | ||
let projects: Record<string, ProjectGraphProjectNode> = { | ||
pkg1: { | ||
name: 'pkg1', | ||
type: 'lib' as const, | ||
data: { | ||
root: 'pkg1', | ||
metadata: { | ||
js: { | ||
packageName: '@org/pkg1', | ||
packageExports: exports, | ||
isInPackageManagerWorkspaces: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const targetProjectLocator = new TargetProjectLocator( | ||
projects, | ||
{}, | ||
new Map() | ||
); | ||
const result = | ||
targetProjectLocator.findImportInWorkspaceProjects(importPath); | ||
|
||
expect(result).toBeFalsy(); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe('isBuiltinModuleImport()', () => { | ||
|
Oops, something went wrong.