Skip to content

Commit

Permalink
Bundle & pin Wrangler dependencies (#7737)
Browse files Browse the repository at this point in the history
* bundle chokidar

* Harden up more deps

* Add path-to-regexp
  • Loading branch information
penalosa authored Jan 13, 2025
1 parent 8e9aa40 commit 336cc48
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 52 deletions.
27 changes: 13 additions & 14 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,18 @@
"type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.721.0",
"@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": "^4.0.1",
"date-fns": "^4.1.0",
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
"@esbuild-plugins/node-modules-polyfill": "0.2.2",
"blake3-wasm": "2.1.5",
"esbuild": "0.17.19",
"itty-time": "^1.0.6",
"miniflare": "workspace:*",
"nanoid": "^3.3.3",
"path-to-regexp": "^6.3.0",
"resolve": "^1.22.8",
"selfsigned": "^2.0.1",
"source-map": "^0.6.1",
"path-to-regexp": "6.3.0",
"unenv": "npm:[email protected]",
"workerd": "1.20241230.0",
"xxhash-wasm": "^1.0.1"
"workerd": "1.20241230.0"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.721.0",
"@cloudflare/cli": "workspace:*",
"@cloudflare/eslint-config-worker": "workspace:*",
"@cloudflare/pages-shared": "workspace:^",
Expand Down Expand Up @@ -118,10 +110,12 @@
"@vitest/ui": "catalog:default",
"@webcontainer/env": "^1.1.0",
"chalk": "^5.2.0",
"chokidar": "^4.0.1",
"cli-table3": "^0.6.3",
"cmd-shim": "^4.1.0",
"command-exists": "^1.2.9",
"concurrently": "^8.2.2",
"date-fns": "^4.1.0",
"devtools-protocol": "^0.0.1182435",
"dotenv": "^16.3.1",
"execa": "^6.1.0",
Expand All @@ -131,6 +125,7 @@
"https-proxy-agent": "7.0.2",
"ignore": "^5.2.0",
"is-ci": "^3.0.1",
"itty-time": "^1.0.6",
"javascript-time-ago": "^2.5.4",
"md5-file": "5.0.0",
"mime": "^3.0.0",
Expand All @@ -142,10 +137,13 @@
"patch-console": "^1.0.0",
"pretty-bytes": "^6.0.0",
"prompts": "^2.4.2",
"resolve": "^1.22.8",
"rimraf": "catalog:default",
"selfsigned": "^2.0.1",
"semiver": "^1.1.0",
"shell-quote": "^1.8.1",
"signal-exit": "^3.0.7",
"source-map": "^0.6.1",
"strip-ansi": "^7.1.0",
"supports-color": "^9.2.2",
"timeago.js": "^4.0.2",
Expand All @@ -157,6 +155,7 @@
"vitest-websocket-mock": "^0.4.0",
"ws": "^8.18.0",
"xdg-app-paths": "^8.3.0",
"xxhash-wasm": "^1.0.1",
"yargs": "^17.7.2"
},
"peerDependencies": {
Expand Down
26 changes: 21 additions & 5 deletions packages/wrangler/scripts/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,38 @@ import path from "node:path";
* Dependencies that _are not_ bundled along with wrangler
*/
export const EXTERNAL_DEPENDENCIES = [
"fsevents",
// Wrangler depends on a pinned version of esbuild.
"esbuild",

// This blows up when bundled, and has WASM dependencies. Wrangler depends on a pinned version.
"blake3-wasm",

// Wrangler depends on a pinned version of Miniflare.
"miniflare",
// todo - bundle miniflare too
"selfsigned",
"source-map",

// Pending deletion in v4...
"@esbuild-plugins/node-globals-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
"@cloudflare/workers-types",

// unenv must be external because it contains unenv/runtime code which needs to be resolved
// and read when we are bundling the worker application
"unenv",

// path-to-regexp must be external because it contains runtime code which needs to be resolved
// and read when we are bundling the worker application.
// See `templates/pages-template-workers`
"path-to-regexp",

// @cloudflare/kv-asset-handler must be external because it contains runtime code which needs to be resolved
// and read when we are bundling the worker application
// Pending deletion in v4...
"@cloudflare/kv-asset-handler",

// workerd contains a native binary, so must be external. Wrangler depends on a pinned version.
"workerd",
];

Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/pages/functions/buildWorker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from "node:crypto";
import { access, cp, lstat, rm } from "node:fs/promises";
import { join, resolve } from "node:path";
import { build as esBuild } from "esbuild";
import { nanoid } from "nanoid";
import { bundleWorker } from "../../deployment-bundle/bundle";
import { findAdditionalModules } from "../../deployment-bundle/find-additional-modules";
import {
Expand Down Expand Up @@ -404,7 +404,7 @@ function assetsPlugin(buildOutputDirectory: string | undefined): Plugin {
}

// TODO: Consider hashing the contents rather than using a unique identifier every time?
identifiers.set(directory, nanoid());
identifiers.set(directory, crypto.randomUUID());
if (!buildOutputDirectory) {
console.warn(
"You're attempting to import static assets as part of your Pages Functions, but have not specified a directory in which to put them. You must use 'wrangler pages dev <directory>' rather than 'wrangler pages dev -- <command>' to import static assets in Functions."
Expand Down
59 changes: 28 additions & 31 deletions pnpm-lock.yaml

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

0 comments on commit 336cc48

Please sign in to comment.