From 9e53df0c40cc443820352098602a61f7a39e1330 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 4 Jul 2024 12:36:49 +0800 Subject: [PATCH] fix(register): file path with query (#801) --- packages/integrate-module/src/index.ts | 6 ++++++ packages/register/esm.mts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/integrate-module/src/index.ts b/packages/integrate-module/src/index.ts index c0820f6d9..5b7f3729d 100644 --- a/packages/integrate-module/src/index.ts +++ b/packages/integrate-module/src/index.ts @@ -13,6 +13,8 @@ import { baz } from './subdirectory/index.mjs' import { Component } from './component.js' import './js-module.mjs' +const { foo: fooWithQuery } = await import(`./foo.mjs?q=${Date.now()}`) + await test('file-type should work', () => { assert.ok(supportedExtensions.has('jpg')) }) @@ -33,6 +35,10 @@ await test('resolve paths', () => { assert.equal(subBar(), 'bar') }) +await test('resolve with query', () => { + assert.equal(fooWithQuery(), 'foo') +}) + await test('compiled js file with .d.ts', () => { const instance = new CompiledClass() assert.equal(instance.name, 'CompiledClass') diff --git a/packages/register/esm.mts b/packages/register/esm.mts index 74ee87ed7..dbf95da6e 100644 --- a/packages/register/esm.mts +++ b/packages/register/esm.mts @@ -202,10 +202,10 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => { (process.platform === 'win32' && !path.includes('\\node_modules\\'))) ) { debug('resolved: typescript', specifier, path) - + const url = new URL(join('file://', path)) return addShortCircuitSignal({ ...context, - url: pathToFileURL(path).href, + url: url.href, format: 'module', }) }