Skip to content

Commit bbd8a5e

Browse files
Minimize the number of the Miniflare package dependencies (#11897)
* Minimize the number of the Miniflare package dependencies * Bundle zod dependency in miniflare and vitest-pool-workers Refine the approach to bundling dependencies: only bundle zod (pure JS library with no native dependencies) while keeping other dependencies external for technical reasons: - sharp: Native binary with platform-specific builds - undici: Dynamically required at runtime in worker threads (fetch-sync.ts) - ws: Has optional native bindings for performance optimization - workerd: Native binary (Cloudflare's JS runtime) - @cspotcode/source-map-support: Uses require.cache manipulation - youch: Dynamically required for lazy loading Also updated deps.ts comments to accurately document why each dependency must remain external. * fix workerd version --------- Co-authored-by: Pete Bacon Darwin <pbacondarwin@cloudflare.com>
1 parent f08ef21 commit bbd8a5e

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed

.changeset/warm-numbers-smell.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"miniflare": patch
3+
"@cloudflare/vitest-pool-workers": patch
4+
---
5+
6+
Bundle the `zod` dependency to reduce supply chain attack surface
7+
8+
In order to prevent possible npm vulnerability attacks, the team's policy is to bundle
9+
dependencies in our packages where possible. This helps ensure that only trusted code
10+
runs on the user's system, even if compromised packages are later published to npm.
11+
12+
This change bundles `zod` (a pure JavaScript validation library with no native dependencies)
13+
into miniflare and @cloudflare/vitest-pool-workers.
14+
15+
Other dependencies remain external for technical reasons:
16+
17+
- `sharp`: Native binary with platform-specific builds
18+
- `undici`: Dynamically required at runtime in worker threads
19+
- `ws`: Has optional native bindings for performance
20+
- `workerd`: Native binary (Cloudflare's JavaScript runtime)
21+
- `@cspotcode/source-map-support`: Uses require.cache manipulation at runtime
22+
- `youch`: Dynamically required for lazy loading

packages/miniflare/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
"undici": "catalog:default",
4949
"workerd": "1.20260123.0",
5050
"ws": "catalog:default",
51-
"youch": "4.1.0-beta.10",
52-
"zod": "^3.25.76"
51+
"youch": "4.1.0-beta.10"
5352
},
5453
"devDependencies": {
5554
"@cloudflare/cli": "workspace:*",
@@ -100,7 +99,8 @@
10099
"typescript": "catalog:default",
101100
"vitest": "catalog:default",
102101
"which": "^2.0.2",
103-
"xdg-app-paths": "^8.3.0"
102+
"xdg-app-paths": "^8.3.0",
103+
"zod": "^3.25.76"
104104
},
105105
"engines": {
106106
"node": ">=18.0.0"

packages/miniflare/scripts/deps.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@ export const EXTERNAL_DEPENDENCIES = [
1212
// Native binary with platform-specific builds - cannot be bundled
1313
"sharp",
1414

15-
// Large HTTP client with optional native dependencies; commonly shared
16-
// with other packages to avoid version conflicts and duplication
15+
// Must be external - dynamically required at runtime in worker threads via
16+
// require("undici") for synchronous fetch operations (see fetch-sync.ts)
1717
"undici",
1818

1919
// Native binary - Cloudflare's JavaScript runtime cannot be bundled
2020
"workerd",
2121

2222
// Has optional native bindings (bufferutil, utf-8-validate) for performance;
23-
// commonly shared with other packages to avoid duplication
23+
// bundling would lose these optimizations and fall back to JS implementations
2424
"ws",
2525

2626
// Must be external - dynamically required at runtime via require("youch")
2727
// for lazy loading of pretty error pages
2828
"youch",
29-
30-
// Large validation library; commonly shared as a dependency
31-
// to avoid version conflicts and bundle size duplication
32-
"zod",
3329
];

packages/vitest-pool-workers/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
"cjs-module-lexer": "^1.2.3",
5757
"esbuild": "catalog:default",
5858
"miniflare": "workspace:*",
59-
"wrangler": "workspace:*",
60-
"zod": "^3.25.76"
59+
"wrangler": "workspace:*"
6160
},
6261
"devDependencies": {
6362
"@cloudflare/eslint-config-shared": "workspace:*",
@@ -78,7 +77,8 @@
7877
"ts-dedent": "^2.2.0",
7978
"typescript": "catalog:default",
8079
"undici": "catalog:default",
81-
"vitest": "catalog:default"
80+
"vitest": "catalog:default",
81+
"zod": "^3.25.76"
8282
},
8383
"peerDependencies": {
8484
"@vitest/runner": "2.0.x - 3.2.x",

packages/vitest-pool-workers/scripts/bundle.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ const commonOptions = {
100100
// External dependencies (see scripts/deps.ts for rationale)
101101
"cjs-module-lexer",
102102
"esbuild",
103-
"zod",
104103
// Workspace dependencies
105104
"miniflare",
106105
"wrangler",

packages/vitest-pool-workers/scripts/deps.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@ export const EXTERNAL_DEPENDENCIES = [
1010

1111
// Native binary - cannot be bundled, used to bundle test files at runtime
1212
"esbuild",
13-
14-
// Large validation library; commonly shared as a dependency
15-
// to avoid version conflicts and bundle size duplication
16-
"zod",
1713
];

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)