Skip to content

Commit

Permalink
fix(paths): handle ../ in relative path check (#18)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
  • Loading branch information
JounQin and privatenumber authored Jun 24, 2022
1 parent b003f2e commit 96a5c10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/paths/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function parsePaths(
`Substitution '${substitution}' in pattern '${pattern}' can have at most one '*' character.`,
);

if (!substitution.startsWith('./') && !baseUrl) {
if (!baseUrl && !isRelativePathPattern.test(substitution)) {
throw new Error('Non-relative paths are not allowed when \'baseUrl\' is not set. Did you forget a leading \'./\'?');
}

Expand Down
23 changes: 23 additions & 0 deletions tests/specs/paths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ export default testSuite(({ describe }) => {
]);
});

// #17
test('exact match with parent path', async () => {
const fixture = await createFixture({
'tsconfig.json': tsconfigJson({
compilerOptions: {
paths: {
exactMatch: ['../src'],
},
},
}),
});

const tsconfig = getTsconfig(fixture.path);
expect(tsconfig).not.toBeNull();

const matcher = createPathsMatcher(tsconfig!)!;

expect(matcher).not.toBeNull();
expect(matcher('exactMatch')).toStrictEqual([
path.join(fixture.path, '../src'),
]);
});

test('exact match with wildcard', async () => {
const fixture = await createFixture({
'tsconfig.json': tsconfigJson({
Expand Down

0 comments on commit 96a5c10

Please sign in to comment.