File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
packages/wrangler/src/deployment-bundle Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { getEntryPointFromMetafile } from "./entry-point-from-metafile";
1515import { cloudflareInternalPlugin } from "./esbuild-plugins/cloudflare-internal" ;
1616import { configProviderPlugin } from "./esbuild-plugins/config-provider" ;
1717import { nodejsCompatPlugin } from "./esbuild-plugins/nodejs-compat" ;
18+ import { standardURLPlugin } from "./esbuild-plugins/standard-url" ;
1819import { writeAdditionalModules } from "./find-additional-modules" ;
1920import { noopModuleCollector } from "./module-collection" ;
2021import type { Config } from "../config" ;
@@ -342,7 +343,11 @@ export async function bundleWorker(
342343 plugins : [
343344 moduleCollector . plugin ,
344345 ...( legacyNodeCompat
345- ? [ NodeGlobalsPolyfills ( { buffer : true } ) , NodeModulesPolyfills ( ) ]
346+ ? [
347+ NodeGlobalsPolyfills ( { buffer : true } ) ,
348+ standardURLPlugin ( ) ,
349+ NodeModulesPolyfills ( ) ,
350+ ]
346351 : [ ] ) ,
347352 nodejsCompatPlugin ( ! ! nodejsCompat ) ,
348353 cloudflareInternalPlugin ,
Original file line number Diff line number Diff line change 1+ import type { Plugin } from "esbuild" ;
2+
3+ /**
4+ * An esbuild plugin that will export URL from the url polyfill
5+ */
6+ export const standardURLPlugin : ( ) => Plugin = ( ) => ( {
7+ name : "standard URL plugin" ,
8+ setup ( pluginBuild ) {
9+ pluginBuild . onResolve ( { filter : / ^ u r l $ / } , ( { importer } ) => {
10+ if ( importer === "standard-url-plugin" ) return ;
11+ return {
12+ path : "wrangler-url-polyfill" ,
13+ namespace : "wrangler-url" ,
14+ } ;
15+ } ) ;
16+ pluginBuild . onResolve (
17+ { filter : / ^ w r a n g l e r : u r l $ / } ,
18+ async ( { kind, resolveDir } ) => {
19+ const result = await pluginBuild . resolve ( "url" , {
20+ kind,
21+ resolveDir,
22+ importer : "standard-url-plugin" ,
23+ } ) ;
24+
25+ return result ;
26+ }
27+ ) ;
28+ pluginBuild . onLoad (
29+ { filter : / ^ w r a n g l e r - u r l - p o l y f i l l $ / , namespace : "wrangler-url" } ,
30+ ( ) => {
31+ return {
32+ loader : "js" ,
33+ contents : `export * from "wrangler:url"; export const URL = globalThis.URL` ,
34+ } ;
35+ }
36+ ) ;
37+ } ,
38+ } ) ;
You can’t perform that action at this time.
0 commit comments