Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(esm): resolve absolute paths #544

Merged
Merged
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
Loading