From f9fd0d2aa5ea8b8da558ab680e6eecc397e47fe8 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Tue, 3 Dec 2024 11:05:39 +0000 Subject: [PATCH 1/2] refactor: remove missed redundant computation of `projectRoot` --- .../wrangler/src/__tests__/get-entry.test.ts | 31 +++++++------------ packages/wrangler/src/config/config.ts | 11 +++++-- .../wrangler/src/deployment-bundle/entry.ts | 7 ++--- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/packages/wrangler/src/__tests__/get-entry.test.ts b/packages/wrangler/src/__tests__/get-entry.test.ts index d2f67af500..ae2541712e 100644 --- a/packages/wrangler/src/__tests__/get-entry.test.ts +++ b/packages/wrangler/src/__tests__/get-entry.test.ts @@ -1,18 +1,15 @@ import path from "path"; import dedent from "ts-dedent"; -import { defaultWranglerConfig } from "../config/config"; +import { normalizeAndValidateConfig } from "../config/validation"; import { getEntry } from "../deployment-bundle/entry"; import { mockConsoleMethods } from "./helpers/mock-console"; import { runInTempDir } from "./helpers/run-in-tmp"; import { seed } from "./helpers/seed"; -import type { Config } from "../config/config"; +import type { Config, RawConfig } from "../config"; import type { Entry } from "../deployment-bundle/entry"; -function getConfig(): Config { - return { - ...defaultWranglerConfig, - projectRoot: process.cwd(), - }; +function getConfig(raw: RawConfig = {}, configPath?: string): Config { + return normalizeAndValidateConfig(raw, configPath, {}).config; } function normalize(entry: Entry): Entry { @@ -83,11 +80,7 @@ describe("getEntry()", () => { } `, }); - const entry = await getEntry( - {}, - { ...getConfig(), main: "index.ts" }, - "deploy" - ); + const entry = await getEntry({}, getConfig({ main: "index.ts" }), "deploy"); expect(normalize(entry)).toMatchObject({ file: "/tmp/dir/index.ts", moduleRoot: "/tmp/dir", @@ -106,7 +99,7 @@ describe("getEntry()", () => { }); const entry = await getEntry( {}, - { ...getConfig(), main: "src/index.ts" }, + getConfig({ main: "src/index.ts" }), "deploy" ); expect(normalize(entry)).toMatchObject({ @@ -127,12 +120,12 @@ describe("getEntry()", () => { }); const entry = await getEntry( {}, - { - ...getConfig(), - main: "src/index.ts", - configPath: "other-worker/wrangler.toml", - projectRoot: "other-worker", - }, + getConfig( + { + main: "src/index.ts", + }, + "other-worker/wrangler.toml" + ), "deploy" ); expect(normalize(entry)).toMatchObject({ diff --git a/packages/wrangler/src/config/config.ts b/packages/wrangler/src/config/config.ts index 5efd39b48c..55f825c028 100644 --- a/packages/wrangler/src/config/config.ts +++ b/packages/wrangler/src/config/config.ts @@ -34,10 +34,17 @@ export type RawConfig = Partial> & EnvironmentMap & { $schema?: string }; export interface ComputedConfigFields { - /** Path to the configuration file (e.g. wrangler.toml/json), if one was provided. */ + /** + * Path (relative to current working directory) of the configuration file (e.g. wrangler.toml/json), if one was provided. + */ configPath: string | undefined; - /** A worker's directory. Usually where the Wrangler configuration file is located */ + /** + * Absolute path to the Worker's directory. + * + * Will be the directory containing the Wrangler configuration file, + * or the current working directory otherwise. + */ projectRoot: string; } export interface ConfigFields { diff --git a/packages/wrangler/src/deployment-bundle/entry.ts b/packages/wrangler/src/deployment-bundle/entry.ts index 4a11e2bf7f..ab3ad5d668 100644 --- a/packages/wrangler/src/deployment-bundle/entry.ts +++ b/packages/wrangler/src/deployment-bundle/entry.ts @@ -51,9 +51,7 @@ export async function getEntry( ): Promise { const entryPoint = config.site?.["entry-point"]; - let paths: - | { absolutePath: string; relativePath: string; projectRoot?: string } - | undefined; + let paths: { absolutePath: string; relativePath: string } | undefined; if (args.script) { paths = resolveEntryWithScript(args.script); @@ -86,10 +84,9 @@ export async function getEntry( config.configPath ); - const projectRoot = paths.projectRoot ?? process.cwd(); const { format, exports } = await guessWorkerFormat( paths.absolutePath, - projectRoot, + config.projectRoot, args.format ?? config.build?.upload?.format, config.tsconfig ); From ebc0a26b0fdf500d34a4f538e2094eefe91bec94 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Tue, 3 Dec 2024 13:59:41 +0000 Subject: [PATCH 2/2] test: do not watch test files in workflow fixture test jobs --- fixtures/workflow-multiple/package.json | 2 +- fixtures/workflow/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fixtures/workflow-multiple/package.json b/fixtures/workflow-multiple/package.json index ca7184f54c..b048c58969 100644 --- a/fixtures/workflow-multiple/package.json +++ b/fixtures/workflow-multiple/package.json @@ -4,7 +4,7 @@ "scripts": { "deploy": "wrangler deploy", "start": "wrangler dev", - "test:ci": "vitest" + "test:ci": "vitest run" }, "devDependencies": { "@cloudflare/workers-types": "^4.20241106.0", diff --git a/fixtures/workflow/package.json b/fixtures/workflow/package.json index 0c8fc04bef..aee92d0389 100644 --- a/fixtures/workflow/package.json +++ b/fixtures/workflow/package.json @@ -4,7 +4,7 @@ "scripts": { "deploy": "wrangler deploy", "start": "wrangler dev", - "test:ci": "vitest" + "test:ci": "vitest run" }, "devDependencies": { "@cloudflare/workers-types": "^4.20241106.0",