Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/esm/hook/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
tsExtensionsPattern,
isDirectoryPattern,
isRelativePath,
isFilePath,
} from '../../utils/path-utils.js';
import type { TsxRequest } from '../types.js';
import { logEsm as log, debugEnabled } from '../../utils/debug.js';
Expand Down Expand Up @@ -252,8 +253,9 @@ const resolveTsPaths: ResolveHook = async (
fromNodeModules: context.parentURL?.includes('/node_modules/'),
});
if (
// Bare specifier
!requestAcceptsQuery(specifier)
// Bare specifier or TS path alias (e.g. `ns:foo`) - not a file path or file:// URL
!isFilePath(specifier)
&& !specifier.startsWith(fileUrlPrefix)
// TS path alias
&& tsconfigPathsMatcher
&& !context.parentURL?.includes('/node_modules/')
Expand Down
27 changes: 27 additions & 0 deletions tests/specs/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,33 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
expect(pTsconfig.stderr).toBe('');
expect(pTsconfig.stdout).toBe('');
});

test('tsconfig paths with colon in alias name', async ({ onTestFail }) => {
await using fixture = await createFixture({
'package.json': createPackageJson(packageType ? { type: packageType } : {}),
'tsconfig.json': createTsconfig({
compilerOptions: {
baseUrl: '.',
paths: {
'ns:*': ['./src/*'],
},
},
}),
'src/utils.ts': `export const value = 'success'`,
'index.ts': `
import { value } from 'ns:utils';
console.log(value);
`,
});

const result = await tsx(['index.ts'], fixture.path);
onTestFail((error) => {
console.error(error);
console.log(result);
});
expect(result.failed).toBe(false);
expect(result.stdout).toBe('success');
});
});

describe('custom tsconfig', ({ test }) => {
Expand Down
Loading