Skip to content

Commit e771fe9

Browse files
authoredJan 8, 2025··
include the top level Worker name in the parsed config structure (#7703)
1 parent f5bd6a7 commit e771fe9

File tree

7 files changed

+44
-12
lines changed

7 files changed

+44
-12
lines changed
 

‎.changeset/hungry-llamas-repair.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
include the top level Worker name in the parsed config structure

‎packages/wrangler/src/__tests__/config/configuration.test.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,11 @@ describe("normalizeAndValidateConfig()", () => {
11961196

11971197
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11981198
expect({ ...config, tsconfig: normalizePath(config.tsconfig!) }).toEqual(
1199-
expect.objectContaining({ ...expectedConfig, main: resolvedMain })
1199+
expect.objectContaining({
1200+
...expectedConfig,
1201+
main: resolvedMain,
1202+
topLevelName: expectedConfig.name,
1203+
})
12001204
);
12011205
expect(diagnostics.hasErrors()).toBe(false);
12021206
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
@@ -4152,6 +4156,7 @@ describe("normalizeAndValidateConfig()", () => {
41524156
...rawConfig,
41534157
main: resolvedMain,
41544158
name: "mock-name-dev",
4159+
topLevelName: "mock-name",
41554160
})
41564161
);
41574162
expect(diagnostics.hasErrors()).toBe(false);
@@ -4229,7 +4234,11 @@ describe("normalizeAndValidateConfig()", () => {
42294234
);
42304235

42314236
expect(config).toEqual(
4232-
expect.objectContaining({ ...rawEnv, main: resolvedMain })
4237+
expect.objectContaining({
4238+
...rawEnv,
4239+
main: resolvedMain,
4240+
topLevelName: "mock-name",
4241+
})
42334242
);
42344243
expect(diagnostics.hasErrors()).toBe(false);
42354244
expect(diagnostics.hasWarnings()).toBe(false);
@@ -4251,6 +4260,7 @@ describe("normalizeAndValidateConfig()", () => {
42514260
);
42524261

42534262
expect(config.name).toEqual("mock-name");
4263+
expect(config.topLevelName).toEqual("mock-name");
42544264
expect(diagnostics.hasErrors()).toBe(false);
42554265
expect(diagnostics.hasWarnings()).toBe(true);
42564266
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`

‎packages/wrangler/src/config/config.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,32 @@ import type { CamelCaseKey } from "yargs";
2222
* - `@breaking`: the deprecation/optionality is a breaking change from Wrangler v1.
2323
* - `@todo`: there's more work to be done (with details attached).
2424
*/
25-
export type Config = ConfigFields<DevConfig> & PagesConfigFields & Environment;
25+
export type Config = ComputedFields &
26+
ConfigFields<DevConfig> &
27+
PagesConfigFields &
28+
Environment;
2629

2730
export type RawConfig = Partial<ConfigFields<RawDevConfig>> &
2831
PagesConfigFields &
2932
RawEnvironment &
3033
DeprecatedConfigFields &
3134
EnvironmentMap & { $schema?: string };
3235

33-
export interface ConfigFields<Dev extends RawDevConfig> {
36+
export interface ComputedFields {
3437
/** The path to the Wrangler configuration file (if any, and possibly redirected from the user Wrangler configuration) used to create this configuration. */
3538
configPath: string | undefined;
3639
/** The path to the user's Wrangler configuration file (if any), which may have been redirected to another file that used to create this configuration. */
3740
userConfigPath: string | undefined;
41+
/**
42+
* The original top level name for the Worker in the raw configuration.
43+
*
44+
* When a raw configuration has been flattened to a single environment the worker name may have been replaced or transformed.
45+
* It can be useful to know what the top-level name was before the flattening.
46+
*/
47+
topLevelName: string | undefined;
48+
}
3849

50+
export interface ConfigFields<Dev extends RawDevConfig> {
3951
/**
4052
* A boolean to enable "legacy" style wrangler environments (from Wrangler v1).
4153
* These have been superseded by Services, but there may be projects that won't
@@ -285,6 +297,11 @@ export type OnlyCamelCase<T = Record<string, never>> = {
285297
};
286298

287299
export const defaultWranglerConfig: Config = {
300+
/* COMPUTED_FIELDS */
301+
configPath: undefined,
302+
userConfigPath: undefined,
303+
topLevelName: undefined,
304+
288305
/*====================================================*/
289306
/* Fields supported by both Workers & Pages */
290307
/*====================================================*/
@@ -329,8 +346,6 @@ export const defaultWranglerConfig: Config = {
329346
/* Fields supported by Workers only */
330347
/*====================================================*/
331348
/* TOP-LEVEL ONLY FIELDS */
332-
configPath: undefined,
333-
userConfigPath: undefined,
334349
legacy_env: true,
335350
site: undefined,
336351
legacy_assets: undefined,

‎packages/wrangler/src/config/validation-pages.ts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const supportedPagesConfigFields = [
4040
// normalizeAndValidateConfig() sets these values
4141
"configPath",
4242
"userConfigPath",
43+
"topLevelName",
4344
] as const;
4445

4546
export function validatePagesConfig(

‎packages/wrangler/src/config/validation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export function normalizeAndValidateConfig(
269269
const config: Config = {
270270
configPath,
271271
userConfigPath,
272+
topLevelName: rawConfig.name,
272273
pages_build_output_dir: normalizeAndValidatePagesBuildOutputDir(
273274
configPath,
274275
rawConfig.pages_build_output_dir

‎packages/wrangler/src/d1/execute.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { requireAuth } from "../user";
1919
import * as options from "./options";
2020
import splitSqlQuery from "./splitter";
2121
import { getDatabaseByNameOrBinding, getDatabaseInfoFromConfig } from "./utils";
22-
import type { Config, ConfigFields, DevConfig, Environment } from "../config";
22+
import type { Config } from "../config";
2323
import type {
2424
CommonYargsArgv,
2525
StrictYargsOptionsToInterface,
@@ -197,7 +197,7 @@ export async function executeSql({
197197
}: {
198198
local: boolean | undefined;
199199
remote: boolean | undefined;
200-
config: ConfigFields<DevConfig> & Environment;
200+
config: Config;
201201
name: string;
202202
shouldPrompt: boolean | undefined;
203203
persistTo: string | undefined;

‎packages/wrangler/src/d1/migrations/helpers.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isNonInteractiveOrCI } from "../../is-interactive";
77
import { logger } from "../../logger";
88
import { DEFAULT_MIGRATION_PATH } from "../constants";
99
import { executeSql } from "../execute";
10-
import type { ConfigFields, DevConfig, Environment } from "../../config";
10+
import type { Config } from "../../config";
1111
import type { QueryResult } from "../execute";
1212
import type { Migration } from "../types";
1313

@@ -57,7 +57,7 @@ export async function getUnappliedMigrations({
5757
migrationsPath: string;
5858
local: boolean | undefined;
5959
remote: boolean | undefined;
60-
config: ConfigFields<DevConfig> & Environment;
60+
config: Config;
6161
name: string;
6262
persistTo: string | undefined;
6363
preview: boolean | undefined;
@@ -92,7 +92,7 @@ type ListAppliedMigrationsProps = {
9292
migrationsTableName: string;
9393
local: boolean | undefined;
9494
remote: boolean | undefined;
95-
config: ConfigFields<DevConfig> & Environment;
95+
config: Config;
9696
name: string;
9797
persistTo: string | undefined;
9898
preview: boolean | undefined;
@@ -170,7 +170,7 @@ export const initMigrationsTable = async ({
170170
migrationsTableName: string;
171171
local: boolean | undefined;
172172
remote: boolean | undefined;
173-
config: ConfigFields<DevConfig> & Environment;
173+
config: Config;
174174
name: string;
175175
persistTo: string | undefined;
176176
preview: boolean | undefined;

0 commit comments

Comments
 (0)
Please sign in to comment.