Skip to content

Commit

Permalink
refactor: use esbuild-plugins-node-modules-polyfill
Browse files Browse the repository at this point in the history
Replaces `@esbuild-plugins/node-globals-polyfill` & `@esbuild-plugins/node-modules-polyfill` with the up-to-date & maintained `esbuild-plugins-node-modules-polyfill`

The `esbuild-plugins` repository actually points towards using `esbuild-plugin-polyfill-node` instead
https://github.com/remorses/esbuild-plugins/blob/373b44902ad3e669f7359c857de09a930ce1ce90/README.md?plain=1#L15-L16

But the Remix repo (see remix-run/remix#5274) tried this and found some regressions.
So they chose to go for @imranbarbhuiya's  `esbuild-plugins-node-modules-polyfill` instead (see remix-run/remix#6562), which is an up-to-date and well maintained alternative.

Users should no longer see the following deprecation warnings when installing Wrangler:

```sh
npm WARN deprecated rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
```

Resolves #1232
  • Loading branch information
MichaelDeBoey authored and petebacondarwin committed Mar 8, 2024
1 parent 27fb22b commit 5370d39
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 71 deletions.
22 changes: 22 additions & 0 deletions .changeset/hungry-ladybugs-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"wrangler": major
---

refactor: use `esbuild-plugins-node-modules-polyfill`

Replaces `@esbuild-plugins/node-globals-polyfill` & `@esbuild-plugins/node-modules-polyfill` with the up-to-date & maintained `esbuild-plugins-node-modules-polyfill`

The `esbuild-plugins` repository actually points towards using `esbuild-plugin-polyfill-node` instead
https://github.com/remorses/esbuild-plugins/blob/373b44902ad3e669f7359c857de09a930ce1ce90/README.md?plain=1#L15-L16

But the Remix repo (see https://github.com/remix-run/remix/pull/5274) tried this and found some regressions.
So they chose to go for @imranbarbhuiya's `esbuild-plugins-node-modules-polyfill` instead (see https://github.com/remix-run/remix/pull/6562), which is an up-to-date and well maintained alternative.

Users should no longer see the following deprecation warnings when installing Wrangler:

```sh
npm WARN deprecated rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
```

Resolves https://github.com/cloudflare/workers-sdk/issues/1232
3 changes: 1 addition & 2 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@
},
"dependencies": {
"@cloudflare/kv-asset-handler": "workspace:*",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"blake3-wasm": "^2.1.5",
"chokidar": "^3.5.3",
"esbuild": "0.17.19",
"esbuild-plugins-node-modules-polyfill": "^1.5.0",
"miniflare": "workspace:*",
"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 @@ -12,8 +12,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",
// @cloudflare/workers-types is an optional peer dependency of wrangler, so users can
// get the types by installing the package (to what version they prefer) themselves
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,8 +1,7 @@
import * as fs from "node:fs";
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 { UserError } from "../errors";
import { getBasePath, getWranglerTmpDir } from "../paths";
import { applyMiddlewareLoaderFacade } from "./apply-middleware";
Expand Down Expand Up @@ -342,7 +341,7 @@ export async function bundleWorker(
plugins: [
moduleCollector.plugin,
...(legacyNodeCompat
? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
? [nodeModulesPolyfillPlugin({ globals: { Buffer: true } })]
: []),
nodejsCompatPlugin(!!nodejsCompat),
cloudflareInternalPlugin,
Expand Down
76 changes: 15 additions & 61 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 5370d39

Please sign in to comment.