-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(wrangler): Explicitely pick node compat plugins for each mode (
#7387) * refactor: cleanup & simplify * refactor(wrangler): Explicitely pick node compat plugins for each mode * Update packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts Co-authored-by: Pete Bacon Darwin <[email protected]> * fixup! renamed vars (review feedback) * fixup! format --------- Co-authored-by: Pete Bacon Darwin <[email protected]>
- Loading branch information
1 parent
4aed2d6
commit ff8f5ae
Showing
4 changed files
with
66 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/wrangler/src/deployment-bundle/esbuild-plugins/nodejs-plugins.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill"; | ||
import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill"; | ||
import { asyncLocalStoragePlugin } from "./als-external"; | ||
import { nodejsHybridPlugin } from "./hybrid-nodejs-compat"; | ||
import { nodejsCompatPlugin } from "./nodejs-compat"; | ||
import { standardURLPlugin } from "./standard-url"; | ||
import type { Plugin } from "esbuild"; | ||
import type { NodeJSCompatMode } from "miniflare"; | ||
|
||
/** | ||
* Returns the list of ESBuild plugins to use for a given compat mode. | ||
*/ | ||
export function getNodeJSCompatPlugins(mode: NodeJSCompatMode): Plugin[] { | ||
switch (mode) { | ||
case "als": | ||
return [asyncLocalStoragePlugin, nodejsCompatPlugin(mode)]; | ||
case "legacy": | ||
return [ | ||
NodeGlobalsPolyfills({ buffer: true }), | ||
standardURLPlugin(), | ||
NodeModulesPolyfills(), | ||
nodejsCompatPlugin(mode), | ||
]; | ||
case "v1": | ||
return [nodejsCompatPlugin(mode)]; | ||
case "v2": | ||
return [nodejsHybridPlugin()]; | ||
case null: | ||
return [nodejsCompatPlugin(mode)]; | ||
} | ||
} |