Skip to content

Commit 3a0ea18

Browse files
fardjadprivatenumber
andauthoredMay 6, 2024··
fix(esm): resolve absolute paths (#544)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
1 parent b407435 commit 3a0ea18

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎src/esm/hook/resolve.ts

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const resolve: resolve = async (
123123

124124
const isPath = (
125125
specifier.startsWith(fileProtocol)
126+
|| path.isAbsolute(specifier)
126127
|| isRelativePathPattern.test(specifier)
127128
);
128129

‎tests/specs/smoke.ts

+12
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
502502
import './js/index.js?query=123';
503503
import './js/index';
504504
import './js/';
505+
import { FIXTURE_PATH };
505506
506507
// No double .default.default in Dynamic Import
507508
import('./js/index.js').then(m => {
@@ -638,6 +639,17 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
638639
// Comment at EOF: could be a sourcemap declaration. Edge case for inserting functions here
639640
`.trim(),
640641
});
642+
643+
const importFromTs = await fixture.readFile('import-from-ts.ts', 'utf8');
644+
const importFromTsWithAbsolutePath = importFromTs.toString().replace(
645+
'{ FIXTURE_PATH }',
646+
JSON.stringify(
647+
packageType === 'module'
648+
? new URL('js/index.js', pathToFileURL(`${fixture.path}/`)).toString()
649+
: path.resolve(fixture.path, 'js/index.js'),
650+
),
651+
);
652+
await fixture.writeFile('import-from-ts.ts', importFromTsWithAbsolutePath);
641653
onFinish(async () => await fixture.rm());
642654

643655
test('import all', async ({ onTestFail }) => {

0 commit comments

Comments
 (0)
Please sign in to comment.