@cloudflare/worker-bundler 0.2.1 → 0.2.3

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
@@ -397,7 +397,7 @@ const result = await createApp({
397
397
  const worker = env.LOADER.get(loaderId, () => ({
398
398
  mainModule: result.mainModule,
399
399
  modules: result.modules,
400
- compatibilityDate: "2026-01-28"
400
+ compatibilityDate: "2026-06-11"
401
401
  }));
402
402
 
403
403
  // Mount as a facet for persistent storage
package/dist/esbuild.wasm CHANGED
Binary file
@@ -11,7 +11,7 @@ interface FileSystem {
11
11
  * @param path The path to the file.
12
12
  * @param content The contents of the file.
13
13
  */
14
- write(path: string, content: string): void;
14
+ write(path: string, content: FileEntry): void;
15
15
  /**
16
16
  * Deletes a file from the file system.
17
17
  * @param path The path to the file.
@@ -128,6 +128,11 @@ declare function createFileSystemSnapshot(
128
128
  | AsyncIterable<readonly [string, string]>
129
129
  | Iterable<readonly [string, string]>
130
130
  ): Promise<InMemoryFileSystem>;
131
+ type FileEntry =
132
+ | string
133
+ | {
134
+ data: Uint8Array<ArrayBuffer>;
135
+ };
131
136
  //#endregion
132
137
  export {
133
138
  createFileSystemSnapshot as a,
@@ -136,4 +141,4 @@ export {
136
141
  FileSystem as r,
137
142
  DurableObjectKVFileSystem as t
138
143
  };
139
- //# sourceMappingURL=file-system-PsI0bi2L.d.ts.map
144
+ //# sourceMappingURL=file-system-ZXKe_fv7.d.ts.map
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  n as DurableObjectRawFileSystem,
5
5
  r as FileSystem,
6
6
  t as DurableObjectKVFileSystem
7
- } from "./file-system-PsI0bi2L.js";
7
+ } from "./file-system-ZXKe_fv7.js";
8
8
 
9
9
  //#region src/types.d.ts
10
10
  /**
@@ -484,17 +484,7 @@ declare function inferContentType(path: string): string | undefined;
484
484
  */
485
485
  declare function isTextContentType(contentType: string): boolean;
486
486
  //#endregion
487
- //#region src/installer.d.ts
488
- interface InstallOptions {
489
- /**
490
- * Include devDependencies (default: false)
491
- */
492
- dev?: boolean;
493
- /**
494
- * Registry URL (default: https://registry.npmjs.org)
495
- */
496
- registry?: string;
497
- }
487
+ //#region src/common.d.ts
498
488
  interface InstallResult {
499
489
  /**
500
490
  * Packages that were freshly installed in this call.
@@ -506,6 +496,18 @@ interface InstallResult {
506
496
  */
507
497
  warnings: string[];
508
498
  }
499
+ //#endregion
500
+ //#region src/installer.d.ts
501
+ interface InstallOptions {
502
+ /**
503
+ * Include devDependencies (default: false)
504
+ */
505
+ dev?: boolean;
506
+ /**
507
+ * Registry URL (default: https://registry.npmjs.org)
508
+ */
509
+ registry?: string;
510
+ }
509
511
  /**
510
512
  * Install npm dependencies into a virtual file system.
511
513
  *
@@ -521,7 +523,7 @@ declare function installDependencies(
521
523
  options?: InstallOptions
522
524
  ): Promise<InstallResult>;
523
525
  /**
524
- * Check if files contain a package.json with dependencies that need installing.
526
+ * Check if files contain a package.json or pyproject.toml with dependencies that need installing.
525
527
  */
526
528
  declare function hasDependencies(files: FileSystem): boolean;
527
529
  //#endregion
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as hasDependencies, r as installDependencies } from "./installer-Ns4ivVf5.js";
1
+ import { n as hasDependencies, r as installDependencies } from "./installer-DDvaMqav.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";
@@ -188,7 +188,7 @@ function parseImports(code) {
188
188
  */
189
189
  function parseImportsRegex(code) {
190
190
  const imports = [];
191
- for (const match of code.matchAll(/import\s+(?:(?:[\w*{}\s,]+)\s+from\s+)?['"]([^'"]+)['"]/g)) {
191
+ for (const match of code.matchAll(/\bimport\b\s+(?:(?:(?!\b(?:import|export)\b)[\w*{},])+(?:\s+(?:(?!\b(?:import|export)\b)[\w*{},])+)*\s+from\s+)?['"]([^'"]+)['"]/g)) {
192
192
  const specifier = match[1];
193
193
  if (specifier) imports.push(specifier);
194
194
  }
@@ -196,7 +196,7 @@ function parseImportsRegex(code) {
196
196
  const specifier = match[1];
197
197
  if (specifier) imports.push(specifier);
198
198
  }
199
- for (const match of code.matchAll(/export\s+(?:[\w*{}\s,]+\s+)?from\s+['"]([^'"]+)['"]/g)) {
199
+ for (const match of code.matchAll(/\bexport\b\s+(?:(?:(?!\b(?:import|export)\b)[\w*{},])+(?:\s+(?:(?!\b(?:import|export)\b)[\w*{},])+)*\s+)?from\s+['"]([^'"]+)['"]/g)) {
200
200
  const specifier = match[1];
201
201
  if (specifier) imports.push(specifier);
202
202
  }
@@ -713,7 +713,7 @@ async function transformAndResolve(files, entryPoint, externals) {
713
713
  * This is necessary because the Worker Loader expects imports to match registered module names.
714
714
  */
715
715
  function rewriteImports(code, importer, files, pathMap, externals) {
716
- const importExportRegex = /(import\s+(?:[\w*{}\s,]+\s+from\s+)?|export\s+(?:[\w*{}\s,]+\s+)?from\s+)(['"])([^'"]+)\2/g;
716
+ const importExportRegex = /(\bimport\b\s+(?:(?:(?!\b(?:import|export)\b)[\w*{},])+(?:\s+(?:(?!\b(?:import|export)\b)[\w*{},])+)*\s+from\s+)?|\bexport\b\s+(?:(?:(?!\b(?:import|export)\b)[\w*{},])+(?:\s+(?:(?!\b(?:import|export)\b)[\w*{},])+)*\s+)?from\s+)(['"])([^'"]+)\2/g;
717
717
  const importerOutputPath = pathMap.get(importer) ?? importer;
718
718
  return code.replace(importExportRegex, (match, prefix, quote, specifier) => {
719
719
  if (externals.includes(specifier) || externals.some((e) => specifier.startsWith(`${e}/`) || specifier.startsWith(e))) return match;
@@ -784,6 +784,7 @@ const DEFAULT_ENTRY_POINTS = [
784
784
  "src/index.mjs",
785
785
  "index.ts",
786
786
  "index.js",
787
+ "index.py",
787
788
  "src/worker.ts",
788
789
  "src/worker.js"
789
790
  ];
@@ -1516,7 +1517,7 @@ async function createApp(options) {
1516
1517
  const nodejsCompat = hasNodejsCompat(wranglerConfig);
1517
1518
  const installWarnings = [];
1518
1519
  if (hasDependencies(fileSystem)) {
1519
- const installResult = await installDependencies(fileSystem, registry ? { registry } : {});
1520
+ const installResult = await installDependencies(fileSystem, { ...registry ? { registry } : {} });
1520
1521
  installWarnings.push(...installResult.warnings);
1521
1522
  }
1522
1523
  const clientEntries = options.client ? Array.isArray(options.client) ? options.client : [options.client] : [];
@@ -1627,12 +1628,29 @@ async function createWorker(options) {
1627
1628
  const nodejsCompat = hasNodejsCompat(wranglerConfig);
1628
1629
  const installWarnings = [];
1629
1630
  if (hasDependencies(fileSystem)) {
1630
- const installResult = await installDependencies(fileSystem, registry ? { registry } : {});
1631
+ const installResult = await installDependencies(fileSystem, { ...registry ? { registry } : {} });
1631
1632
  installWarnings.push(...installResult.warnings);
1632
1633
  }
1633
1634
  const entryPoint = options.entryPoint ?? detectEntryPoint(fileSystem, wranglerConfig);
1634
1635
  if (!entryPoint) throw new Error(`Could not determine entry point for createWorker. Tried (in order): the \`entryPoint\` option, \`main\` in wrangler config, \`exports\`/\`module\`/\`main\` in package.json, and the defaults ${DEFAULT_ENTRY_POINTS.join(", ")}. Pass \`entryPoint\` explicitly or add one of those files.`);
1635
1636
  if (fileSystem.read(entryPoint) === null) throw new Error(`Entry point "${entryPoint}" was not found in \`files\`. Available files: ${formatFileListForError(fileSystem)}.`);
1637
+ if (entryPoint.endsWith(".py")) {
1638
+ const modules = {};
1639
+ for (const path of fileSystem.list()) {
1640
+ if (path === "pyproject.toml") continue;
1641
+ const content = fileSystem.read(path);
1642
+ if (content !== null) modules[path] = content;
1643
+ }
1644
+ return {
1645
+ mainModule: entryPoint,
1646
+ modules,
1647
+ wranglerConfig: {
1648
+ compatibilityDate: wranglerConfig?.compatibilityDate ?? "2026-07-02",
1649
+ compatibilityFlags: wranglerConfig?.compatibilityFlags ?? []
1650
+ },
1651
+ warnings: installWarnings
1652
+ };
1653
+ }
1636
1654
  if (bundle) {
1637
1655
  const result = await bundleWithEsbuild({
1638
1656
  files: fileSystem,