Skip to content

Commit 9dac236

Browse files
committed
fix: remove querystring from module id
1 parent 862dbdb commit 9dac236

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { isNil, pickBy } from 'es-toolkit'
66
import { ResolverFactory } from 'oxc-resolver'
77
import { getBundlerConfig } from './bundler'
88
import { normalizeOptions } from './normalizeOptions'
9-
import { hashObject } from './utils'
9+
import { hashObject, removeQuerystring } from './utils'
1010

1111
export * from './bundler/exports'
1212
export * from './typings'
@@ -31,6 +31,8 @@ export function resolve(source: string, file: string, options?: OxcResolverOptio
3131
resolver = cachedResolver
3232
}
3333

34+
source = removeQuerystring(source)
35+
3436
// https://github.com/oxc-project/oxc-resolver/blob/main/npm/README.md#api
3537
const result = resolver.sync(dirname(file), source)
3638

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,11 @@ export async function tryRequireThenImport<T>(module: string): Promise<T> {
8080
}
8181
}
8282
}
83+
84+
export function removeQuerystring(id: string): string {
85+
const querystringIndex = id.lastIndexOf('?')
86+
if (querystringIndex >= 0) {
87+
return id.slice(0, querystringIndex)
88+
}
89+
return id
90+
}

tests/source/resolve.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { resolve } from 'node:path'
2+
import { cwd } from 'node:process'
13
import { run } from './utils'
24

35
run({
@@ -26,6 +28,10 @@ run({
2628
'../../../vitest.config',
2729
'../../../src/index',
2830
'../../../src',
31+
{
32+
source: '../../../package.json?type=1',
33+
path: resolve(cwd(), 'package.json'),
34+
},
2935
],
3036
invalid: [
3137
'../inexistent.ts',
@@ -42,6 +48,10 @@ run({
4248
'vitest.config.ts',
4349
'src/index.ts',
4450
'src/index',
51+
{
52+
source: 'package.json?type=1',
53+
path: resolve(cwd(), 'package.json'),
54+
},
4555
],
4656
invalid: [
4757
'inexistent.ts',

0 commit comments

Comments
 (0)