99import * as path from "@std/path" ;
1010import * as babel from "@babel/core" ;
1111import { httpAbsolute } from "./patches/http_absolute.ts" ;
12- import { JS_REG , JSX_REG } from "../utils.ts" ;
12+ import { JS_REG , JSX_REG , joinViteQuery , splitViteQuery } from "../utils.ts" ;
1313import { builtinModules } from "node:module" ;
1414
1515// @ts -ignore Workaround for https://github.com/denoland/deno/issues/30850
@@ -69,6 +69,8 @@ export function deno(): Plugin {
6969 : browserLoader ;
7070
7171 const original = id ;
72+ let { specifier, query } = splitViteQuery ( id ) ;
73+ id = specifier ;
7274
7375 let isHttp = false ;
7476 if ( id . startsWith ( "deno-http::" ) ) {
@@ -89,7 +91,11 @@ export function deno(): Plugin {
8991 // resolution, with us being in front due to `enforce: "pre"`.
9092 // But we still want to ignore everything `vite:resolve` does
9193 // because we're kinda replacing that plugin here.
92- const tmp = await this . resolve ( id , importer , options ) ;
94+ const tmp = await this . resolve (
95+ joinViteQuery ( id , query ) ,
96+ importer ,
97+ options ,
98+ ) ;
9399 if ( tmp && tmp . resolvedBy !== "vite:resolve" ) {
94100 if ( tmp . external && ! / ^ h t t p s ? : \/ \/ / . test ( tmp . id ) ) {
95101 return tmp ;
@@ -100,7 +106,11 @@ export function deno(): Plugin {
100106 return tmp ;
101107 }
102108
103- id = tmp . id ;
109+ const resolvedTmp = splitViteQuery ( tmp . id ) ;
110+ id = resolvedTmp . specifier ;
111+ if ( resolvedTmp . query ) {
112+ query = resolvedTmp . query ;
113+ }
104114 }
105115
106116 // Plugins may return lower cased drive letters on windows
@@ -134,7 +144,7 @@ export function deno(): Plugin {
134144
135145 if ( resolved . startsWith ( "node:" ) ) {
136146 return {
137- id : resolved ,
147+ id : joinViteQuery ( resolved , query ) ,
138148 external : true ,
139149 } ;
140150 }
@@ -148,15 +158,15 @@ export function deno(): Plugin {
148158 type !== RequestedModuleType . Default ||
149159 / ^ ( h t t p s ? | j s r | n p m ) : / . test ( resolved )
150160 ) {
151- return toDenoSpecifier ( resolved , type ) ;
161+ return joinViteQuery ( toDenoSpecifier ( resolved , type ) , query ) ;
152162 }
153163
154164 if ( resolved . startsWith ( "file://" ) ) {
155165 resolved = path . fromFileUrl ( resolved ) ;
156166 }
157167
158168 return {
159- id : resolved ,
169+ id : joinViteQuery ( resolved , query ) ,
160170 meta : {
161171 deno : {
162172 type,
@@ -202,6 +212,8 @@ export function deno(): Plugin {
202212 id = id . slice ( 1 ) ;
203213 }
204214
215+ const { specifier : loadSpecifier } = splitViteQuery ( id ) ;
216+
205217 const meta = this . getModuleInfo ( id ) ?. meta . deno as
206218 | DenoState
207219 | undefined
@@ -212,12 +224,12 @@ export function deno(): Plugin {
212224 // Skip for non-js files like `.css`
213225 if (
214226 meta . type === RequestedModuleType . Default &&
215- ! JS_REG . test ( id )
227+ ! JS_REG . test ( loadSpecifier )
216228 ) {
217229 return ;
218230 }
219231
220- const url = path . toFileUrl ( id ) ;
232+ const url = path . toFileUrl ( loadSpecifier ) ;
221233
222234 const result = await loader . load ( url . href , meta . type ) ;
223235 if ( result . kind === "external" ) {
0 commit comments