Skip to content

Commit bea6558

Browse files
refactor: remove missed redundant computation of projectRoot (#7421)
* refactor: remove missed redundant computation of `projectRoot` * test: do not watch test files in workflow fixture test jobs
1 parent bb70e87 commit bea6558

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

fixtures/workflow-multiple/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"deploy": "wrangler deploy",
66
"start": "wrangler dev",
7-
"test:ci": "vitest"
7+
"test:ci": "vitest run"
88
},
99
"devDependencies": {
1010
"@cloudflare/workers-types": "^4.20241106.0",

fixtures/workflow/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"deploy": "wrangler deploy",
66
"start": "wrangler dev",
7-
"test:ci": "vitest"
7+
"test:ci": "vitest run"
88
},
99
"devDependencies": {
1010
"@cloudflare/workers-types": "^4.20241106.0",

packages/wrangler/src/__tests__/get-entry.test.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import path from "path";
22
import dedent from "ts-dedent";
3-
import { defaultWranglerConfig } from "../config/config";
3+
import { normalizeAndValidateConfig } from "../config/validation";
44
import { getEntry } from "../deployment-bundle/entry";
55
import { mockConsoleMethods } from "./helpers/mock-console";
66
import { runInTempDir } from "./helpers/run-in-tmp";
77
import { seed } from "./helpers/seed";
8-
import type { Config } from "../config/config";
8+
import type { Config, RawConfig } from "../config";
99
import type { Entry } from "../deployment-bundle/entry";
1010

11-
function getConfig(): Config {
12-
return {
13-
...defaultWranglerConfig,
14-
projectRoot: process.cwd(),
15-
};
11+
function getConfig(raw: RawConfig = {}, configPath?: string): Config {
12+
return normalizeAndValidateConfig(raw, configPath, {}).config;
1613
}
1714

1815
function normalize(entry: Entry): Entry {
@@ -83,11 +80,7 @@ describe("getEntry()", () => {
8380
}
8481
`,
8582
});
86-
const entry = await getEntry(
87-
{},
88-
{ ...getConfig(), main: "index.ts" },
89-
"deploy"
90-
);
83+
const entry = await getEntry({}, getConfig({ main: "index.ts" }), "deploy");
9184
expect(normalize(entry)).toMatchObject({
9285
file: "/tmp/dir/index.ts",
9386
moduleRoot: "/tmp/dir",
@@ -106,7 +99,7 @@ describe("getEntry()", () => {
10699
});
107100
const entry = await getEntry(
108101
{},
109-
{ ...getConfig(), main: "src/index.ts" },
102+
getConfig({ main: "src/index.ts" }),
110103
"deploy"
111104
);
112105
expect(normalize(entry)).toMatchObject({
@@ -127,12 +120,12 @@ describe("getEntry()", () => {
127120
});
128121
const entry = await getEntry(
129122
{},
130-
{
131-
...getConfig(),
132-
main: "src/index.ts",
133-
configPath: "other-worker/wrangler.toml",
134-
projectRoot: "other-worker",
135-
},
123+
getConfig(
124+
{
125+
main: "src/index.ts",
126+
},
127+
"other-worker/wrangler.toml"
128+
),
136129
"deploy"
137130
);
138131
expect(normalize(entry)).toMatchObject({

packages/wrangler/src/config/config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ export type RawConfig = Partial<ConfigFields<RawDevConfig>> &
3434
EnvironmentMap & { $schema?: string };
3535

3636
export interface ComputedConfigFields {
37-
/** Path to the configuration file (e.g. wrangler.toml/json), if one was provided. */
37+
/**
38+
* Path (relative to current working directory) of the configuration file (e.g. wrangler.toml/json), if one was provided.
39+
*/
3840
configPath: string | undefined;
3941

40-
/** A worker's directory. Usually where the Wrangler configuration file is located */
42+
/**
43+
* Absolute path to the Worker's directory.
44+
*
45+
* Will be the directory containing the Wrangler configuration file,
46+
* or the current working directory otherwise.
47+
*/
4148
projectRoot: string;
4249
}
4350
export interface ConfigFields<Dev extends RawDevConfig> {

packages/wrangler/src/deployment-bundle/entry.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ export async function getEntry(
5151
): Promise<Entry> {
5252
const entryPoint = config.site?.["entry-point"];
5353

54-
let paths:
55-
| { absolutePath: string; relativePath: string; projectRoot?: string }
56-
| undefined;
54+
let paths: { absolutePath: string; relativePath: string } | undefined;
5755

5856
if (args.script) {
5957
paths = resolveEntryWithScript(args.script);
@@ -86,10 +84,9 @@ export async function getEntry(
8684
config.configPath
8785
);
8886

89-
const projectRoot = paths.projectRoot ?? process.cwd();
9087
const { format, exports } = await guessWorkerFormat(
9188
paths.absolutePath,
92-
projectRoot,
89+
config.projectRoot,
9390
args.format ?? config.build?.upload?.format,
9491
config.tsconfig
9592
);

0 commit comments

Comments
 (0)