Skip to content

Commit db53e8c

Browse files
authored
fix: don't resolve symbol names to paths outside the project root (#529)
* test: add a snapshot for projects referenced by directory or tsconfig * fix: keep package symbols within the project root Packages compared directories with the project root as it was passed, which can be relative or a tsconfig file, while file names are absolute paths. The comparison never matched, so the lookup walked past the project root. Resolve the root to an absolute directory, so the by-tsconfig snapshot now stops at its root like by-directory. Outside the project root, the lookup still looks for a package.json in parent directories, which is how dependencies in a hoisted node_modules get their package. When there is none up to the filesystem root, the file now keeps only its file name instead of every directory above it, such as private/tmp/repo/shared/`s.ts`/, so symbols no longer depend on where the code is checked out.
1 parent d2150a0 commit db53e8c

11 files changed

Lines changed: 108 additions & 21 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "package-boundary",
3+
"version": "1.0.0",
4+
"description": "Example TS/JS project whose packages don't have a package.json",
5+
"private": true
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function byDirectory(): string {
2+
return ''
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"rootDir": "..",
5+
"outDir": "dist"
6+
},
7+
"include": ["src", "../shared"]
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function byTsconfig(): string {
2+
return ''
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"rootDir": "..",
5+
"outDir": "dist"
6+
},
7+
"include": ["src"]
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function shared(): string {
2+
return ''
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{ "path": "./packages/by-directory" },
5+
{ "path": "./packages/by-tsconfig/tsconfig.json" }
6+
]
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// language TypeScript
2+
// < definition . . src/`by-directory.ts`/
3+
4+
export function byDirectory(): string {
5+
// ^^^^^^^^^^^ definition . . src/`by-directory.ts`/byDirectory().
6+
return ''
7+
}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// language TypeScript
2+
// < definition . . src/`by-tsconfig.ts`/
3+
4+
export function byTsconfig(): string {
5+
// ^^^^^^^^^^ definition . . src/`by-tsconfig.ts`/byTsconfig().
6+
return ''
7+
}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// language TypeScript
2+
// < definition package-boundary 1.0.0 packages/shared/`shared.ts`/
3+
4+
export function shared(): string {
5+
// ^^^^^^ definition package-boundary 1.0.0 packages/shared/`shared.ts`/shared().
6+
return ''
7+
}
8+

0 commit comments

Comments
 (0)