Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/short-symbols-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/workers-shared": patch
---

Update mime dependency to 4.X so that javascript files will have content types of `text/javascript` instead of `application/javascript`. This will affect the content-types computed by Asset Worker within Workers Static Assets.
3 changes: 1 addition & 2 deletions packages/workers-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "catalog:default",
"@sentry/cli": "^2.37.0",
"@types/mime": "^3.0.4",
"concurrently": "^8.2.2",
"esbuild": "catalog:default",
"ignore": "^5.2.0",
"mime": "^3.0.0",
"mime": "^4.0.7",
"rimraf": "catalog:default",
"toucan-js": "4.0.0",
"typescript": "catalog:default",
Expand Down
4 changes: 2 additions & 2 deletions packages/workers-shared/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from "node:fs";
import { isAbsolute, resolve, sep } from "node:path";
import ignore from "ignore";
import { getType } from "mime";
import mime from "mime";
import {
CF_ASSETS_IGNORE_FILENAME,
HEADERS_FILENAME,
Expand All @@ -18,7 +18,7 @@ export const normalizeFilePath = (relativeFilepath: string) => {
};

export const getContentType = (absFilePath: string) => {
let contentType = getType(absFilePath);
let contentType = mime.getType(absFilePath);
if (
contentType &&
contentType.startsWith("text/") &&
Expand Down
9 changes: 8 additions & 1 deletion packages/workers-shared/utils/tests/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createAssetsIgnoreFunction } from "../helpers";
import { createAssetsIgnoreFunction, getContentType } from "../helpers";

describe("assets", () => {
const tmpDir = mkdtempSync(join(tmpdir(), "wrangler-tests"));
Expand Down Expand Up @@ -54,3 +54,10 @@ describe("assets", () => {
});
});
});

describe("getContentType", () => {
it("should return 'text/javascript", () => {
const contentType = getContentType("/_astro/sponsors.CIiPz7eJ.js");
expect(contentType).toBe("text/javascript; charset=utf-8");
});
});
14 changes: 9 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading