@cloudflare/worker-bundler 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,7 @@ Bundle and serve full-stack applications on Cloudflare's [Worker Loader binding]
8
8
 
9
9
  This package only runs **inside the Cloudflare Workers runtime (`workerd`)** — both in production and in `wrangler dev`. It bundles via an `esbuild-wasm` `WebAssembly.Module` import that only the Workers module loader can resolve.
10
10
 
11
- It will **not** work under plain Node.js. In particular, importing it from a Vitest/Jest test that uses the default Node pool will surface an error pointing you here. To test code that depends on `@cloudflare/worker-bundler`, run your tests with [`@cloudflare/vitest-pool-workers`](https://developers.cloudflare.com/workers/testing/vitest-integration/) so the test body executes inside `workerd`. See `packages/worker-bundler/src/tests/vitest.config.ts` in this repo for an example setup.
11
+ It will **not** work under plain Node.js. In particular, importing it from a Vitest/Jest test that uses the default Node pool will surface an error pointing you here. To test code that depends on `@cloudflare/worker-bundler`, run your tests with [`@cloudflare/vitest-plugin`](https://developers.cloudflare.com/workers/testing/vitest-integration/) so the test body executes inside `workerd`. See `packages/worker-bundler/src/tests/vitest.config.ts` in this repo for an example setup.
12
12
 
13
13
  ## Installation
14
14
 
@@ -272,12 +272,16 @@ function createR2Storage(bucket: R2Bucket, prefix = "assets"): AssetStorage {
272
272
  ### Custom: Workspace Storage
273
273
 
274
274
  ```ts
275
- import type { Workspace } from "@cloudflare/shell";
275
+ import type { Workspace } from "@cloudflare/computer";
276
276
 
277
277
  function createWorkspaceStorage(workspace: Workspace): AssetStorage {
278
278
  return {
279
279
  async get(pathname) {
280
- return workspace.readFile(pathname);
280
+ try {
281
+ return await workspace.fs.readFile(`/workspace/assets${pathname}`);
282
+ } catch {
283
+ return null;
284
+ }
281
285
  }
282
286
  };
283
287
  }
@@ -489,9 +493,7 @@ Skip bundling to preserve the module structure:
489
493
 
490
494
  ```ts
491
495
  const { mainModule, modules } = await createWorker({
492
- files: {
493
- /* ... */
494
- },
496
+ files: {/* ... */},
495
497
  bundle: false
496
498
  });
497
499
  ```
@@ -711,16 +713,17 @@ const fs = new DurableObjectRawFileSystem(this.ctx.storage);
711
713
 
712
714
  ### Snapshotting from async sources
713
715
 
714
- The `FileSystem` interface is synchronous because esbuild and TypeScript require synchronous file access. To bridge from an async storage backend (like `Workspace` from `@cloudflare/shell`), use `createFileSystemSnapshot`:
716
+ The `FileSystem` interface is synchronous because esbuild and TypeScript require synchronous file access. To bridge from an async storage backend (like a `Workspace` from `@cloudflare/computer`), use `createFileSystemSnapshot`:
715
717
 
716
718
  ```ts
717
719
  import { createFileSystemSnapshot } from "@cloudflare/worker-bundler";
718
720
 
719
721
  // Accepts any sync or async iterable of [path, content] pairs
720
722
  async function* workspaceFiles(workspace) {
721
- for (const entry of workspace.glob("**/*.{ts,tsx,json}")) {
722
- const content = await workspace.readFile(entry.path);
723
- if (content !== null) yield [entry.path, content];
723
+ for (const entry of await workspace.fs.find("/workspace", "**")) {
724
+ if (entry.type !== "file" || !/\.(tsx?|json)$/.test(entry.path)) continue;
725
+ const content = await workspace.fs.readFile(entry.path, "utf8");
726
+ yield [entry.path.slice("/workspace/".length), content];
724
727
  }
725
728
  }
726
729
 
@@ -837,7 +840,7 @@ const diagnostics = languageService.getSemanticDiagnostics("src/index.ts");
837
840
 
838
841
  ### Integrating with Workspace
839
842
 
840
- When using `Workspace` from `@cloudflare/shell` as durable storage, snapshot source files into an `InMemoryFileSystem` for type checking:
843
+ When using a `Workspace` from `@cloudflare/computer` as durable storage, snapshot source files into an `InMemoryFileSystem` for type checking:
841
844
 
842
845
  ```ts
843
846
  import { createFileSystemSnapshot } from "@cloudflare/worker-bundler";
@@ -845,9 +848,10 @@ import { createTypescriptLanguageService } from "@cloudflare/worker-bundler/type
845
848
 
846
849
  // 1. Snapshot source files from Workspace (async reads)
847
850
  async function* sourceFiles(workspace) {
848
- for (const entry of workspace.glob("**/*.{ts,tsx,json}")) {
849
- const content = await workspace.readFile(entry.path);
850
- if (content !== null) yield [entry.path, content];
851
+ for (const entry of await workspace.fs.find("/workspace", "**")) {
852
+ if (entry.type !== "file" || !/\.(tsx?|json)$/.test(entry.path)) continue;
853
+ const content = await workspace.fs.readFile(entry.path, "utf8");
854
+ yield [entry.path.slice("/workspace/".length), content];
851
855
  }
852
856
  }
853
857
 
@@ -863,7 +867,7 @@ const errors = languageService.getSemanticDiagnostics("src/index.ts");
863
867
 
864
868
  // 4. On edits, update both the TS environment and durable storage
865
869
  fileSystem.write("src/index.ts", newContent);
866
- await workspace.writeFile("src/index.ts", newContent);
870
+ await workspace.fs.writeFile("/workspace/src/index.ts", newContent);
867
871
  ```
868
872
 
869
873
  ## Known Limitations
package/dist/index.d.ts CHANGED
@@ -497,6 +497,13 @@ interface InstallResult {
497
497
  warnings: string[];
498
498
  }
499
499
  //#endregion
500
+ //#region src/installer-python.d.ts
501
+ /** The compatibility settings a Python Worker runs with. */
502
+ interface PythonRuntime {
503
+ compatibilityDate: string;
504
+ compatibilityFlags: readonly string[];
505
+ }
506
+ //#endregion
500
507
  //#region src/installer.d.ts
501
508
  interface InstallOptions {
502
509
  /**
@@ -507,6 +514,11 @@ interface InstallOptions {
507
514
  * Registry URL (default: https://registry.npmjs.org)
508
515
  */
509
516
  registry?: string;
517
+ /**
518
+ * The compatibility settings a Python Worker runs with, which pick the
519
+ * Python its wheels must match.
520
+ */
521
+ python?: PythonRuntime;
510
522
  }
511
523
  /**
512
524
  * Install npm dependencies into a virtual file system.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as hasDependencies, r as installDependencies } from "./installer-Dzd--DQ7.js";
1
+ import { n as hasDependencies, r as installDependencies } from "./installer-DGE0yDdf.js";
2
2
  import * as esbuild from "esbuild-wasm/lib/browser.js";
3
3
  import { parse } from "es-module-lexer/js";
4
4
  import * as resolveExports from "resolve.exports";
@@ -79,13 +79,17 @@ function resolvePackage(specifier, files, conditions, extensions) {
79
79
  }
80
80
  } catch {}
81
81
  const legacyEntry = resolveExports.legacy(pkg, { fields: ["module", "main"] });
82
- if (legacyEntry && typeof legacyEntry === "string") {
82
+ if (!subpath && legacyEntry && typeof legacyEntry === "string") {
83
83
  const fullPath = `node_modules/${packageName}/${normalizeRelativePath(legacyEntry)}`;
84
84
  if (files.read(fullPath) !== null) return {
85
85
  path: fullPath,
86
86
  external: false
87
87
  };
88
88
  }
89
+ if (subpath && pkg.exports !== void 0) return {
90
+ path: specifier,
91
+ external: true
92
+ };
89
93
  const indexPath = resolveWithExtensions(`node_modules/${packageName}${subpath ? `/${subpath}` : ""}`, files, extensions);
90
94
  if (indexPath) return {
91
95
  path: indexPath,
@@ -405,7 +409,7 @@ function isCloudflareWorkersRuntime() {
405
409
  * the Workers runtime. Exported so tests can match against it without
406
410
  * duplicating the wording.
407
411
  */
408
- const NOT_IN_WORKERS_ERROR = "@cloudflare/worker-bundler is only supported inside the Cloudflare Workers runtime (workerd). It cannot run in plain Node.js — including Vitest, Jest or other Node-based test runners — because it bundles via a `WebAssembly.Module` import that only the Workers module loader can resolve. To test code that uses this package, run your tests with @cloudflare/vitest-pool-workers so they execute inside workerd. See https://developers.cloudflare.com/workers/testing/vitest-integration/ for setup.";
412
+ const NOT_IN_WORKERS_ERROR = "@cloudflare/worker-bundler is only supported inside the Cloudflare Workers runtime (workerd). It cannot run in plain Node.js — including Vitest, Jest or other Node-based test runners — because it bundles via a `WebAssembly.Module` import that only the Workers module loader can resolve. To test code that uses this package, run your tests with @cloudflare/vitest-plugin so they execute inside workerd. See https://developers.cloudflare.com/workers/testing/vitest-integration/ for setup.";
409
413
  /**
410
414
  * Pre-started promise for the esbuild WASM module load.
411
415
  *
@@ -1628,7 +1632,13 @@ async function createWorker(options) {
1628
1632
  const nodejsCompat = hasNodejsCompat(wranglerConfig);
1629
1633
  const installWarnings = [];
1630
1634
  if (hasDependencies(fileSystem)) {
1631
- const installResult = await installDependencies(fileSystem, { ...registry ? { registry } : {} });
1635
+ const installResult = await installDependencies(fileSystem, {
1636
+ ...registry ? { registry } : {},
1637
+ python: {
1638
+ compatibilityDate: wranglerConfig?.compatibilityDate ?? "2026-07-02",
1639
+ compatibilityFlags: wranglerConfig?.compatibilityFlags ?? []
1640
+ }
1641
+ });
1632
1642
  installWarnings.push(...installResult.warnings);
1633
1643
  }
1634
1644
  const entryPoint = options.entryPoint ?? detectEntryPoint(fileSystem, wranglerConfig);
@@ -1637,7 +1647,7 @@ async function createWorker(options) {
1637
1647
  if (entryPoint.endsWith(".py")) {
1638
1648
  const modules = {};
1639
1649
  for (const path of fileSystem.list()) {
1640
- if (path === "pyproject.toml") continue;
1650
+ if (path === "pyproject.toml" || path === "wrangler.toml" || path === "wrangler.json" || path === "wrangler.jsonc") continue;
1641
1651
  const content = fileSystem.read(path);
1642
1652
  if (content !== null) modules[path] = content;
1643
1653
  }