File tree Expand file tree Collapse file tree 3 files changed +22
-26
lines changed
packages/vite-plugin-cloudflare/src Expand file tree Collapse file tree 3 files changed +22
-26
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @cloudflare/vite-plugin " : patch
3+ ---
4+
5+ Fix Vite 7.2 compatibility.
Original file line number Diff line number Diff line change 11import assert from "node:assert" ;
22import * as util from "node:util" ;
33import * as vite from "vite" ;
4+ import { additionalModuleRE } from "./plugins/additional-modules" ;
45import { VIRTUAL_WORKER_ENTRY } from "./plugins/virtual-modules" ;
56import {
67 INIT_PATH ,
@@ -17,6 +18,7 @@ import type {
1718 ReplaceWorkersTypes ,
1819 WebSocket ,
1920} from "miniflare" ;
21+ import type { FetchFunctionOptions } from "vite/module-runner" ;
2022
2123export const MAIN_ENTRY_NAME = "index" ;
2224
@@ -121,6 +123,21 @@ export class CloudflareDevEnvironment extends vite.DevEnvironment {
121123 webSocket . accept ( ) ;
122124 this . #webSocketContainer. webSocket = webSocket ;
123125 }
126+
127+ override async fetchModule (
128+ id : string ,
129+ importer ?: string ,
130+ options ?: FetchFunctionOptions
131+ ) : Promise < vite . FetchResult > {
132+ // Additional modules (CompiledWasm, Data, Text)
133+ if ( additionalModuleRE . test ( id ) ) {
134+ return {
135+ externalize : id ,
136+ type : "module" ,
137+ } ;
138+ }
139+ return super . fetchModule ( id , importer , options ) ;
140+ }
124141}
125142
126143export const cloudflareBuiltInModules = [
Original file line number Diff line number Diff line change @@ -46,7 +46,6 @@ import type {
4646 WorkerdStructuredLog ,
4747 WorkerOptions ,
4848} from "miniflare" ;
49- import type { FetchFunctionOptions } from "vite/module-runner" ;
5049import type {
5150 Binding ,
5251 RemoteProxySession ,
@@ -506,36 +505,11 @@ export async function getDevMiniflareOptions(config: {
506505 __VITE_INVOKE_MODULE__ : async ( request ) => {
507506 const payload =
508507 ( await request . json ( ) ) as vite . CustomPayload ;
509- const invokePayloadData = payload . data as {
510- id : string ;
511- name : string ;
512- data : [ string , string , FetchFunctionOptions ] ;
513- } ;
514-
515- assert (
516- invokePayloadData . name === "fetchModule" ,
517- `Invalid invoke event: ${ invokePayloadData . name } `
518- ) ;
519-
520- const [ moduleId ] = invokePayloadData . data ;
521-
522- // Additional modules (CompiledWasm, Data, Text)
523- if ( additionalModuleRE . test ( moduleId ) ) {
524- const result = {
525- externalize : moduleId ,
526- type : "module" ,
527- } satisfies vite . FetchResult ;
528-
529- return MiniflareResponse . json ( { result } ) ;
530- }
531-
532508 const devEnvironment = viteDevServer . environments [
533509 environmentName
534510 ] as CloudflareDevEnvironment ;
535-
536511 const result =
537512 await devEnvironment . hot . handleInvoke ( payload ) ;
538-
539513 return MiniflareResponse . json ( result ) ;
540514 } ,
541515 } ,
You can’t perform that action at this time.
0 commit comments