Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup workers-shared types #7304

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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: 0 additions & 5 deletions fixtures/asset-config/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions fixtures/asset-config/env.d.ts

This file was deleted.

24 changes: 0 additions & 24 deletions fixtures/asset-config/package.json

This file was deleted.

15 changes: 0 additions & 15 deletions fixtures/asset-config/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/workers-shared/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
root: true,
extends: ["@cloudflare/eslint-config-worker"],
ignorePatterns: ["dist"],
ignorePatterns: ["dist", "scripts"],
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { handleRequest } from "../src/handler";
import type { AssetConfig } from "../../utils/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
import { SELF } from "cloudflare:test";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { applyConfigurationDefaults } from "../../packages/workers-shared/asset-worker/src/configuration";
import Worker from "../../packages/workers-shared/asset-worker/src/index";
import { getAssetWithMetadataFromKV } from "../../packages/workers-shared/asset-worker/src/utils/kv";
import { applyConfigurationDefaults } from "../src/configuration";
import Worker from "../src/index";
import { getAssetWithMetadataFromKV } from "../src/utils/kv";
import { encodingTestCases } from "./test-cases/encoding-test-cases";
import { htmlHandlingTestCases } from "./test-cases/html-handling-test-cases";
import type { AssetMetadata } from "../../packages/workers-shared/asset-worker/src/utils/kv";
import type { AssetMetadata } from "../src/utils/kv";

const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;

vi.mock("../../packages/workers-shared/asset-worker/src/utils/kv.ts");
vi.mock("../../packages/workers-shared/asset-worker/src/configuration");
vi.mock("../src/utils/kv.ts");
vi.mock("../src/configuration");
const existsMock = (fileList: Set<string>) => {
vi.spyOn(Worker.prototype, "unstable_exists").mockImplementation(
async (pathname: string) => {
if (fileList.has(pathname)) {
return pathname;
}
return null;
}
);
};
const BASE_URL = "http://example.com";

export type TestCase = {
title: string;
files: string[];
requestPath: string;
matchedFile?: string;
finalPath?: string;
};

const testSuites = [
{
title: "htmlHanding options",
Expand All @@ -41,7 +34,7 @@ const testSuites = [
},
];

describe.each(testSuites)("$title", ({ title, suite }) => {
describe.each(testSuites)("$title", ({ suite }) => {
beforeEach(() => {
vi.mocked(getAssetWithMetadataFromKV).mockImplementation(
() =>
Expand Down Expand Up @@ -72,7 +65,7 @@ describe.each(testSuites)("$title", ({ title, suite }) => {
async ({ files, requestPath, matchedFile, finalPath }) => {
existsMock(new Set(files));
const request = new IncomingRequest(BASE_URL + requestPath);
let response = await SELF.fetch(request);
const response = await SELF.fetch(request);
if (matchedFile && finalPath) {
expect(getAssetWithMetadataFromKV).toBeCalledTimes(1);
expect(getAssetWithMetadataFromKV).toBeCalledWith(
Expand Down
1 change: 1 addition & 0 deletions packages/workers-shared/asset-worker/tests/kv.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { getAssetWithMetadataFromKV } from "../src/utils/kv";
import type { AssetMetadata } from "../src/utils/kv";
import type { MockInstance } from "vitest";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestCase } from "../html-handling.test";
import type { TestCase } from "./test-case";

export const encodingTestCases: {
html_handling:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestCase } from "../html-handling.test";
import type { TestCase } from "./test-case";

export const htmlHandlingTestCases: {
html_handling:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type TestCase = {
title: string;
files: string[];
requestPath: string;
matchedFile?: string;
finalPath?: string;
};
7 changes: 5 additions & 2 deletions packages/workers-shared/asset-worker/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "@cloudflare/workers-tsconfig/tsconfig.json",
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["@cloudflare/workers-types/experimental", "vitest/globals"]
"types": [
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
]
},
"include": ["**/*.ts"]
}
7 changes: 4 additions & 3 deletions packages/workers-shared/asset-worker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"module": "es2022",
"moduleResolution": "Bundler",
"types": ["@cloudflare/workers-types/experimental"],
"noEmit": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
},
"include": ["src/**/*.ts"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config";

class FilteredPushArray<T> extends Array<T> {
constructor(private readonly predicate: (item: T) => boolean) {
Expand All @@ -10,16 +10,13 @@ class FilteredPushArray<T> extends Array<T> {
}
}

export default defineWorkersConfig({
export default defineWorkersProject({
test: {
chaiConfig: {
truncateThreshold: 80,
},
poolOptions: {
workers: {
singleWorker: true,
wrangler: {
configPath:
"../../packages/workers-shared/asset-worker/wrangler.toml",
configPath: "./wrangler.toml",
},
},
},
Expand Down
11 changes: 7 additions & 4 deletions packages/workers-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@
"bundle:router-worker": "esbuild router-worker/src/index.ts --format=esm --bundle --outfile=dist/router-worker.mjs --sourcemap=external",
"bundle:router-worker:prod": "pnpm run bundle:router-worker --minify",
"check:lint": "eslint . --max-warnings=0",
"check:type": "pnpm run check:type:tests && tsc",
"check:type:tests": "tsc -p ./asset-worker/tests/tsconfig.json",
"check:type": "pnpm run check:type:package && pnpm run check:type:asset-worker && pnpm run check:type:router-worker",
"check:type:asset-worker": "tsc -p ./asset-worker/tsconfig.json && tsc -p ./asset-worker/tests/tsconfig.json",
"check:type:package": "tsc -p ./tsconfig.json && tsc -p ./tsconfig.node.json",
"check:type:router-worker": "tsc -p ./router-worker/tsconfig.json",
"clean": "rimraf dist",
"deploy": "pnpm run deploy:router-worker && pnpm run deploy:asset-worker",
"deploy:asset-worker": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler versions upload --experimental-versions -c asset-worker/wrangler.toml",
"deploy:router-worker": "CLOUDFLARE_API_TOKEN=$WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN pnpx wrangler versions upload --experimental-versions -c router-worker/wrangler.toml",
"dev": "pnpm run clean && concurrently -n bundle:asset-worker,bundle:router-worker -c blue,magenta \"pnpm run bundle:asset-worker --watch\" \"pnpm run bundle:router-worker --watch\"",
"test": "vitest",
"test:ci": "vitest run",
"test": "vitest -c asset-worker/vitest.config.mts",
"test:ci": "vitest run -c asset-worker/vitest.config.mts",
"types:emit": "tsc index.ts --declaration --emitDeclarationOnly --declarationDir ./dist"
},
"dependencies": {
Expand All @@ -46,6 +48,7 @@
},
"devDependencies": {
"@cloudflare/eslint-config-worker": "workspace:*",
"@cloudflare/vitest-pool-workers": "^0.5.29",
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20241106.0",
"@types/mime": "^3.0.4",
Expand Down
7 changes: 4 additions & 3 deletions packages/workers-shared/router-worker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"module": "es2022",
"moduleResolution": "Bundler",
"types": ["@cloudflare/workers-types/experimental"],
"noEmit": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
},
"include": ["src/**/*.ts"]
}
19 changes: 12 additions & 7 deletions packages/workers-shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"extends": "@cloudflare/workers-tsconfig/tsconfig.json",
"compilerOptions": {
"module": "esnext",
"sourceMap": true,
"target": "es2021",
"lib": ["es2021"],
"module": "es2022",
"moduleResolution": "Bundler",
"types": ["@cloudflare/workers-types/experimental", "@types/node"],
"noEmit": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"useUnknownInCatchVariables": false,
"types": ["@cloudflare/workers-types/experimental"]
"strict": true,
"skipLibCheck": true
},
"include": ["**/*.ts", "vitest.config.mts"],
"exclude": ["node_modules", "dist", "**/tests", "**/*.test.ts"]
"include": ["utils/*.ts", "index.ts"],
"exclude": ["scripts/**"]
}
13 changes: 13 additions & 0 deletions packages/workers-shared/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"lib": ["ES2021"],
"noEmit": true
},
"include": ["./**/vitest.config.mts", "./scripts/**/*.ts"]
}
15 changes: 0 additions & 15 deletions packages/workers-shared/utils/tsconfig.json

This file was deleted.

12 changes: 0 additions & 12 deletions packages/workers-shared/vitest.config.mts

This file was deleted.

Loading
Loading