-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle relative tsconfig.json paths (#80)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
- Loading branch information
1 parent
232838b
commit 9e78ec5
Showing
4 changed files
with
44 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,47 @@ | ||
import { describe } from 'manten'; | ||
import { describe, test, expect } from 'manten'; | ||
import { createFixture } from 'fs-fixture'; | ||
import { createTsconfigJson, getTscResolution } from './utils.js'; | ||
import { getTsconfig, createPathsMatcher } from '#get-tsconfig'; | ||
|
||
describe('get-tsconfig', ({ runTestSuite }) => { | ||
await describe('get-tsconfig', ({ runTestSuite }) => { | ||
runTestSuite(import('./specs/get-tsconfig.js')); | ||
runTestSuite(import('./specs/parse-tsconfig/index.js')); | ||
runTestSuite(import('./specs/create-paths-matcher.js')); | ||
runTestSuite(import('./specs/create-files-matcher.js')); | ||
}); | ||
|
||
/** | ||
* This needs to happen in isolation because it changes process.cwd | ||
* | ||
* TODO: either: 1) update code to not rely on cwd, or 2) update manten to handle parallel: false | ||
*/ | ||
test('paths > prefix match > nested directory', async () => { | ||
await using fixture = await createFixture({ | ||
'dir/tsconfig.json': createTsconfigJson({ | ||
compilerOptions: { | ||
paths: { | ||
'@/*': ['./*'], | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
const cwd = process.cwd(); | ||
|
||
try { | ||
process.chdir(fixture.path); | ||
|
||
const tsconfig = getTsconfig('./dir/tsconfig.json'); | ||
expect(tsconfig).not.toBeNull(); | ||
|
||
const matcher = createPathsMatcher(tsconfig!)!; | ||
expect(matcher).not.toBeNull(); | ||
|
||
const resolvedAttempts = await getTscResolution('@/file', fixture.getPath('./dir')); | ||
expect(matcher('@/file')).toStrictEqual([ | ||
resolvedAttempts[0].filePath.slice(0, -3), | ||
]); | ||
} finally { | ||
process.chdir(cwd); | ||
} | ||
}); |
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