Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/worker-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@typescript/vfs": "^1.6.4",
"es-module-lexer": "^2.2.0",
"esbuild-wasm": "0.28.1",
"fflate": "^0.8.2",
"resolve.exports": "^2.0.3",
"semver": "^7.8.5",
"smol-toml": "^1.7.0",
Expand Down
28 changes: 25 additions & 3 deletions packages/worker-bundler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { bundleWithEsbuild, bundlerOnlyOptionsWarning } from "./bundler";
import { hasNodejsCompat, parseWranglerConfig } from "./config";
import { hasDependencies, installDependencies } from "./installer";
import { transformAndResolve } from "./transformer";
import type { CreateWorkerOptions, CreateWorkerResult } from "./types";
import type { CreateWorkerOptions, CreateWorkerResult, Modules } from "./types";
import {
DEFAULT_ENTRY_POINTS,
detectEntryPoint,
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function createWorker(
const wranglerConfig = parseWranglerConfig(fileSystem);
const nodejsCompat = hasNodejsCompat(wranglerConfig);

// Auto-install dependencies if package.json has dependencies
// Auto-install dependencies if package.json or pyproject.toml has dependencies
const installWarnings: string[] = [];
if (hasDependencies(fileSystem)) {
const installResult = await installDependencies(
Expand All @@ -143,6 +143,29 @@ export async function createWorker(
);
}

if (entryPoint.endsWith(".py")) {
const modules: Modules = {};
for (const path of fileSystem.list()) {
if (path === "pyproject.toml") {
continue;
}
const content = fileSystem.read(path);
if (content !== null) {
modules[path] = content;
}
}

return {
mainModule: entryPoint,
modules,
wranglerConfig: {
compatibilityDate: wranglerConfig?.compatibilityDate ?? "2026-07-02",
compatibilityFlags: wranglerConfig?.compatibilityFlags ?? []
},
warnings: installWarnings
};
}

if (bundle) {
// Try bundling with esbuild-wasm
const result = await bundleWithEsbuild({
Expand Down Expand Up @@ -171,7 +194,6 @@ export async function createWorker(
if (installWarnings.length > 0) {
result.warnings = [...(result.warnings ?? []), ...installWarnings];
}

return result;
} else {
// No bundling - transform files and resolve dependencies.
Expand Down
Loading
Loading