Skip to content

Commit

Permalink
refactor: use esbuild-plugins-node-modules-polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Aug 24, 2023
1 parent bced8b3 commit f2c0092
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions packages/create-cloudflare/src/frameworks/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ async function installCFWorker(ctx: PagesGeneratorContext) {
await installPackages(
[
"@cloudflare/workers-types",
"@esbuild-plugins/node-globals-polyfill",
"@esbuild-plugins/node-modules-polyfill",
"@miniflare/tre@next",
"esbuild",
"esbuild-plugins-node-modules-polyfill",
"fast-glob",
"wrangler@beta",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import { worker as workerPath } from "./paths.mjs";
import * as esbuild from "esbuild";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import fg from "fast-glob";

// Process each of the JS files in the `_worker.js` directory
Expand Down Expand Up @@ -31,10 +30,7 @@ async function bundleMain() {
define: {
global: "globalThis",
},
plugins: [
NodeGlobalsPolyfillPlugin({ buffer: true }),
NodeModulesPolyfillPlugin(),
],
plugins: [nodeModulesPolyfillPlugin({ globals: { Buffer: true } })],
});

// Store the original promise (before Angular/Zone.js replaces it) on the global scope.
Expand Down Expand Up @@ -65,7 +61,7 @@ async function bundleLazyModule(filePath) {
define: {
global: "globalThis",
},
plugins: [NodeModulesPolyfillPlugin()],
plugins: [nodeModulesPolyfillPlugin()],
});

let content = result.outputFiles[0].text;
Expand Down
3 changes: 1 addition & 2 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@
},
"dependencies": {
"@cloudflare/kv-asset-handler": "^0.2.0",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"blake3-wasm": "^2.1.5",
"chokidar": "^3.5.3",
"esbuild": "0.16.3",
"esbuild-plugins-node-modules-polyfill": "^1.5.0",
"miniflare": "3.20230814.1",
"nanoid": "^3.3.3",
"path-to-regexp": "^6.2.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/wrangler/scripts/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export const EXTERNAL_DEPENDENCIES = [
// todo - bundle miniflare too
"selfsigned",
"source-map",
"@esbuild-plugins/node-globals-polyfill",
"@esbuild-plugins/node-modules-polyfill",
"esbuild-plugins-node-modules-polyfill",
"chokidar",
];

Expand Down
5 changes: 2 additions & 3 deletions packages/wrangler/src/deployment-bundle/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as fs from "node:fs";
import { builtinModules } from "node:module";
import * as path from "node:path";
import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
import * as esbuild from "esbuild";
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import tmp from "tmp-promise";
import createModuleCollector from "../module-collection";
import { getBasePath } from "../paths";
Expand Down Expand Up @@ -355,7 +354,7 @@ export async function bundleWorker(
plugins: [
moduleCollector.plugin,
...(legacyNodeCompat
? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
? [nodeModulesPolyfillPlugin({ globals: { Buffer: true } })]
: []),
...(nodejsCompat ? [nodejsCompatPlugin] : []),
...[cloudflareInternalPlugin],
Expand Down
2 changes: 1 addition & 1 deletion templates/worker-aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@aws-sdk/client-sqs": "^3.82.0"
},
"devDependencies": {
"@esbuild-plugins/node-modules-polyfill": "0.1.4",
"esbuild-plugins-node-modules-polyfill": "^1.5.0",
"worktop.build": "0.0.5",
"wrangler": "^3.0.0"
}
Expand Down
4 changes: 2 additions & 2 deletions templates/worker-aws/worktop.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { define } from 'worktop.build';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';

// @ts-ignore
export default define({
modify(config) {
config.plugins = config.plugins || [];
config.plugins.push(NodeModulesPolyfillPlugin());
config.plugins.push(nodeModulesPolyfillPlugin());
},
});

0 comments on commit f2c0092

Please sign in to comment.