Skip to content
Closed
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
8 changes: 8 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12605,6 +12605,11 @@ export default{
"# Python vendor module 2\nprint('hello')"
);

await fs.promises.writeFile(
"python_modules/test.pyc",
"this shouldn't be deployed"
);

// Create a regular Python module
await fs.promises.writeFile(
"src/helper.py",
Expand All @@ -12614,12 +12619,15 @@ export default{
const expectedModules = {
"index.py": mainPython,
"helper.py": "# Helper module\ndef helper(): pass",
"python_modules/module1.so": "binary content for module 1",
"python_modules/module2.py": "# Python vendor module 2\nprint('hello')",
};

mockSubDomainRequest();
mockUploadWorkerRequest({
expectedMainModule: "index.py",
expectedModules,
excludedModules: ["python_modules/test.pyc"],
});

await runWrangler("deploy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function mockUploadWorkerRequest(
expectedType?: "esm" | "sw" | "none";
expectedBindings?: unknown;
expectedModules?: Record<string, string | null>;
excludedModules?: string[];
expectedCompatibilityDate?: string;
expectedCompatibilityFlags?: string[];
expectedMigrations?: CfWorkerInit["migrations"];
Expand Down Expand Up @@ -135,6 +136,9 @@ export function mockUploadWorkerRequest(
for (const [name, content] of Object.entries(expectedModules)) {
expect(await serialize(formBody.get(name))).toEqual(content);
}
for (const name of excludedModules) {
expect(formBody.get(name)).toBeNull();
}

if (useOldUploadApi) {
return HttpResponse.json(
Expand Down Expand Up @@ -173,6 +177,7 @@ export function mockUploadWorkerRequest(
expectedType = "esm",
expectedBindings,
expectedModules = {},
excludedModules = [],
expectedCompatibilityDate,
expectedCompatibilityFlags,
env = undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,30 @@ export async function findAdditionalModules(
pythonModulesDir,
parseRules(vendoredRules)
)
).map((m) => {
const prefixedPath = path.join("python_modules", m.name);
return {
...m,
name: prefixedPath,
};
});
)
.filter(
// Exclude certain file extensions to avoid bundling files that aren't
// necessary and which increase the size of the bundle considerably.
(m) =>
!m.name.endsWith(".pyc") &&
// Translation files
!m.name.endsWith(".po") &&
// Static files shouldn't be included
!m.name.endsWith(".svg") &&
!m.name.endsWith(".png") &&
!m.name.endsWith(".jpg") &&
!m.name.endsWith(".css") &&
!m.name.endsWith(".gz") &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any way to customize these? because django needs to load this specific .gz common-passwords.txt.gz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I included it because it was in your screenshot

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad sorry

!m.name.endsWith(".txt") &&
!m.name.endsWith(".js")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excluding .js files is going to break urllib3 again. It also seems to me that it is impossible to override these filters from wrangler.jsonc file? What if someone explicitly wants to include one of these file types?

)
.map((m) => {
const prefixedPath = path.join("python_modules", m.name);
return {
...m,
name: prefixedPath,
};
});

modules.push(...vendoredModules);
} else {
Expand Down
Loading