Skip to content

Commit

Permalink
fix(esm): resolve absolute paths (#544)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
  • Loading branch information
fardjad and privatenumber committed May 6, 2024
1 parent b407435 commit 3a0ea18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/esm/hook/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const resolve: resolve = async (

const isPath = (
specifier.startsWith(fileProtocol)
|| path.isAbsolute(specifier)
|| isRelativePathPattern.test(specifier)
);

Expand Down
12 changes: 12 additions & 0 deletions tests/specs/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
import './js/index.js?query=123';
import './js/index';
import './js/';
import { FIXTURE_PATH };
// No double .default.default in Dynamic Import
import('./js/index.js').then(m => {
Expand Down Expand Up @@ -638,6 +639,17 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
// Comment at EOF: could be a sourcemap declaration. Edge case for inserting functions here
`.trim(),
});

const importFromTs = await fixture.readFile('import-from-ts.ts', 'utf8');
const importFromTsWithAbsolutePath = importFromTs.toString().replace(
'{ FIXTURE_PATH }',
JSON.stringify(
packageType === 'module'
? new URL('js/index.js', pathToFileURL(`${fixture.path}/`)).toString()
: path.resolve(fixture.path, 'js/index.js'),
),
);
await fixture.writeFile('import-from-ts.ts', importFromTsWithAbsolutePath);
onFinish(async () => await fixture.rm());

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

0 comments on commit 3a0ea18

Please sign in to comment.