Skip to content

Commit 24b2c66

Browse files
remove warnings during config validations on experimental_remote fields (#9678)
* remove warnings during config validations on `experimental_remote` fields * fixup! remove warnings during config validations on `experimental_remote` fields update changelog
1 parent bfb791e commit 24b2c66

File tree

11 files changed

+32
-245
lines changed

11 files changed

+32
-245
lines changed

.changeset/new-pants-fail.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
remove warnings during config validations on `experimental_remote` fields
6+
7+
wrangler commands, run without the `--x-remote-bindings` flag, parsing config files containing `experimental_remote` fields currently show warnings stating that the field is not recognized. This is usually more cumbersome than helpful so here we're loosening up this validation and making wrangler always recognize the field even when no `--x-remote-bindings` flag is provided

packages/vite-plugin-cloudflare/src/__tests__/get-worker-config.spec.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ describe("getWorkerConfig", () => {
66
test("should return a simple raw config", () => {
77
const { raw } = getWorkerConfig(
88
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
9-
undefined,
10-
false
9+
undefined
1110
);
1211
expect(typeof raw).toEqual("object");
1312

@@ -35,8 +34,7 @@ describe("getWorkerConfig", () => {
3534
test("should return a simple config without non-applicable fields", () => {
3635
const { config } = getWorkerConfig(
3736
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
38-
undefined,
39-
false
37+
undefined
4038
);
4139
expect(typeof config).toEqual("object");
4240

@@ -46,8 +44,7 @@ describe("getWorkerConfig", () => {
4644
test("should not return any non-applicable config when there isn't any", () => {
4745
const { nonApplicable } = getWorkerConfig(
4846
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
49-
undefined,
50-
false
47+
undefined
5148
);
5249
expect(nonApplicable).toEqual({
5350
replacedByVite: new Set(),
@@ -58,8 +55,7 @@ describe("getWorkerConfig", () => {
5855
test("should read a simple wrangler.toml file", () => {
5956
const { config, nonApplicable } = getWorkerConfig(
6057
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
61-
undefined,
62-
false
58+
undefined
6359
);
6460
expect(typeof config).toEqual("object");
6561

@@ -93,8 +89,7 @@ describe("getWorkerConfig", () => {
9389
import.meta.url
9490
)
9591
),
96-
undefined,
97-
false
92+
undefined
9893
);
9994

10095
expect(typeof config).toEqual("object");
@@ -169,8 +164,7 @@ describe("getWorkerConfig", () => {
169164
import.meta.url
170165
)
171166
),
172-
undefined,
173-
false
167+
undefined
174168
)
175169
).toThrowError(
176170
/The provided Wrangler config main field \(.*?index\.ts\) doesn't point to an existing file/
@@ -186,8 +180,7 @@ describe("getWorkerConfig", () => {
186180
import.meta.url
187181
)
188182
),
189-
undefined,
190-
false
183+
undefined
191184
)
192185
).toThrowError(
193186
/The provided Wrangler config main field \(.*?fixtures\) points to a directory, it needs to point to a file instead/

packages/vite-plugin-cloudflare/src/deploy-config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function getDeployConfigPath(root: string) {
1717
return path.resolve(root, ".wrangler", "deploy", "config.json");
1818
}
1919

20-
export function getWorkerConfigs(root: string, remoteBindingsEnabled: boolean) {
20+
export function getWorkerConfigs(root: string) {
2121
const deployConfigPath = getDeployConfigPath(root);
2222
const deployConfig = JSON.parse(
2323
fs.readFileSync(deployConfigPath, "utf-8")
@@ -31,10 +31,7 @@ export function getWorkerConfigs(root: string, remoteBindingsEnabled: boolean) {
3131
path.dirname(deployConfigPath),
3232
configPath
3333
);
34-
return unstable_readConfig(
35-
{ config: resolvedConfigPath },
36-
{ experimental: { remoteBindingsEnabled } }
37-
);
34+
return unstable_readConfig({ config: resolvedConfigPath });
3835
});
3936
}
4037

packages/vite-plugin-cloudflare/src/plugin-config.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ export function resolvePluginConfig(
115115
return {
116116
...shared,
117117
type: "preview",
118-
workers: getWorkerConfigs(
119-
root,
120-
shared.experimental.remoteBindings ?? false
121-
),
118+
workers: getWorkerConfigs(root),
122119
};
123120
}
124121

@@ -137,7 +134,6 @@ export function resolvePluginConfig(
137134
const entryWorkerResolvedConfig = getWorkerConfig(
138135
entryWorkerConfigPath,
139136
cloudflareEnv,
140-
pluginConfig.experimental?.remoteBindings ?? false,
141137
{
142138
visitedConfigPaths: configPaths,
143139
isEntryWorker: true,
@@ -186,7 +182,6 @@ export function resolvePluginConfig(
186182
const workerResolvedConfig = getWorkerConfig(
187183
workerConfigPath,
188184
cloudflareEnv,
189-
pluginConfig.experimental?.remoteBindings ?? false,
190185
{
191186
visitedConfigPaths: configPaths,
192187
}

packages/vite-plugin-cloudflare/src/workers-configs.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ const nullableNonApplicable = [
112112

113113
function readWorkerConfig(
114114
configPath: string,
115-
env: string | undefined,
116-
remoteBindingsEnabled: boolean
115+
env: string | undefined
117116
): {
118117
raw: RawWorkerConfig;
119118
config: SanitizedWorkerConfig;
@@ -124,10 +123,7 @@ function readWorkerConfig(
124123
notRelevant: new Set(),
125124
};
126125
const config: Optional<RawWorkerConfig, "build" | "define"> =
127-
unstable_readConfig(
128-
{ config: configPath, env },
129-
{ experimental: { remoteBindingsEnabled } }
130-
);
126+
unstable_readConfig({ config: configPath, env });
131127
const raw = structuredClone(config) as RawWorkerConfig;
132128

133129
nullableNonApplicable.forEach((prop) => {
@@ -279,7 +275,6 @@ function missingFieldErrorMessage(
279275
export function getWorkerConfig(
280276
configPath: string,
281277
env: string | undefined,
282-
remoteBindingsEnabled: boolean,
283278
opts?: {
284279
visitedConfigPaths?: Set<string>;
285280
isEntryWorker?: boolean;
@@ -289,11 +284,7 @@ export function getWorkerConfig(
289284
throw new Error(`Duplicate Wrangler config path found: ${configPath}`);
290285
}
291286

292-
const { raw, config, nonApplicable } = readWorkerConfig(
293-
configPath,
294-
env,
295-
remoteBindingsEnabled
296-
);
287+
const { raw, config, nonApplicable } = readWorkerConfig(configPath, env);
297288

298289
opts?.visitedConfigPaths?.add(configPath);
299290

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

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6367,82 +6367,6 @@ describe("normalizeAndValidateConfig()", () => {
63676367
});
63686368
});
63696369
});
6370-
6371-
describe("remote bindings", () => {
6372-
it("should ignore remote configs when specified without REMOTE_BINDINGS enabled", () => {
6373-
const rawConfig: RawConfig = {
6374-
name: "my-worker",
6375-
kv_namespaces: [
6376-
{
6377-
binding: "KV",
6378-
id: "xxxx-xxxx-xxxx-xxxx",
6379-
experimental_remote: true,
6380-
},
6381-
],
6382-
r2_buckets: [
6383-
{
6384-
binding: "R2",
6385-
bucket_name: "my-r2",
6386-
experimental_remote: 5 as unknown as boolean,
6387-
},
6388-
],
6389-
};
6390-
const { diagnostics } = run(
6391-
{
6392-
RESOURCES_PROVISION: false,
6393-
MULTIWORKER: false,
6394-
REMOTE_BINDINGS: false,
6395-
},
6396-
() =>
6397-
normalizeAndValidateConfig(rawConfig, undefined, undefined, {
6398-
env: undefined,
6399-
})
6400-
);
6401-
6402-
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
6403-
"Processing wrangler configuration:
6404-
- Unexpected fields found in kv_namespaces[0] field: \\"experimental_remote\\"
6405-
- Unexpected fields found in r2_buckets[0] field: \\"experimental_remote\\""
6406-
`);
6407-
});
6408-
6409-
it("should error on non boolean remote values", () => {
6410-
const rawConfig: RawConfig = {
6411-
name: "my-worker",
6412-
kv_namespaces: [
6413-
{
6414-
binding: "KV",
6415-
id: "xxxx-xxxx-xxxx-xxxx",
6416-
experimental_remote: "hello" as unknown as boolean,
6417-
},
6418-
],
6419-
r2_buckets: [
6420-
{
6421-
binding: "R2",
6422-
bucket_name: "my-r2",
6423-
experimental_remote: 5 as unknown as boolean,
6424-
},
6425-
],
6426-
};
6427-
const { diagnostics } = run(
6428-
{
6429-
RESOURCES_PROVISION: false,
6430-
MULTIWORKER: false,
6431-
REMOTE_BINDINGS: true,
6432-
},
6433-
() =>
6434-
normalizeAndValidateConfig(rawConfig, undefined, undefined, {
6435-
env: undefined,
6436-
})
6437-
);
6438-
6439-
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
6440-
"Processing wrangler configuration:
6441-
- \\"kv_namespaces[0]\\" should, optionally, have a boolean \\"experimental_remote\\" field but got {\\"binding\\":\\"KV\\",\\"id\\":\\"xxxx-xxxx-xxxx-xxxx\\",\\"experimental_remote\\":\\"hello\\"}.
6442-
- \\"r2_buckets[0]\\" should, optionally, have a boolean \\"experimental_remote\\" field but got {\\"binding\\":\\"R2\\",\\"bucket_name\\":\\"my-r2\\",\\"experimental_remote\\":5}."
6443-
`);
6444-
});
6445-
});
64466370
});
64476371

64486372
describe("experimental_readRawConfig()", () => {

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13068,42 +13068,6 @@ export default{
1306813068
});
1306913069
});
1307013070

13071-
it("should warn about unexpected experimental_remote fields", async () => {
13072-
writeWorkerSource();
13073-
writeWranglerConfig({
13074-
main: "./index.js",
13075-
kv_namespaces: [
13076-
{ binding: "MY_KV", id: "kv-id-xxx", experimental_remote: true },
13077-
],
13078-
});
13079-
mockSubDomainRequest();
13080-
mockUploadWorkerRequest();
13081-
13082-
await runWrangler("deploy");
13083-
13084-
expect(std.warn).toContain(
13085-
'Unexpected fields found in kv_namespaces[0] field: "experimental_remote"'
13086-
);
13087-
});
13088-
13089-
it("should not warn about experimental_remote fields when --x-remote-bindings is provided", async () => {
13090-
writeWorkerSource();
13091-
writeWranglerConfig({
13092-
main: "./index.js",
13093-
kv_namespaces: [
13094-
{ binding: "MY_KV", id: "kv-id-xxx", experimental_remote: true },
13095-
],
13096-
});
13097-
mockSubDomainRequest();
13098-
mockUploadWorkerRequest();
13099-
13100-
await runWrangler("deploy --x-remote-bindings");
13101-
13102-
expect(std.warn).not.toContain(
13103-
'Unexpected fields found in kv_namespaces[0] field: "experimental_remote"'
13104-
);
13105-
});
13106-
1310713071
describe("multi-env warning", () => {
1310813072
it("should warn if the wrangler config contains environments but none was specified in the command", async () => {
1310913073
writeWorkerSource();

packages/wrangler/src/__tests__/dev.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,16 +1735,6 @@ describe.sequential("wrangler dev", () => {
17351735
env.MY_R2 (my-bucket) R2 Bucket local
17361736
env.WorkerA (A) Worker local [not connected]
17371737
1738-
"
1739-
`);
1740-
expect(std.warn).toMatchInlineSnapshot(`
1741-
"▲ [WARNING] Processing wrangler.toml configuration:
1742-
1743-
- Unexpected fields found in kv_namespaces[0] field: \\"experimental_remote\\"
1744-
- Unexpected fields found in queues.producers[0] field: \\"experimental_remote\\"
1745-
- Unexpected fields found in r2_buckets[0] field: \\"experimental_remote\\"
1746-
- Unexpected fields found in d1_databases[0] field: \\"experimental_remote\\"
1747-
17481738
"
17491739
`);
17501740
});

packages/wrangler/src/__tests__/versions/versions.upload.test.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -211,56 +211,6 @@ describe("versions upload", () => {
211211
expect(std.info).toContain("Retrying API call after error...");
212212
});
213213

214-
it("should warn about unexpected experimental_remote fields", async () => {
215-
mockGetScript();
216-
mockUploadVersion(true);
217-
mockGetWorkerSubdomain({ enabled: true, previews_enabled: false });
218-
219-
// Setup
220-
writeWranglerConfig({
221-
name: "test-name",
222-
main: "./index.js",
223-
kv_namespaces: [
224-
{ binding: "MY_KV", id: "kv-id-xxx", experimental_remote: true },
225-
],
226-
});
227-
writeWorkerSource();
228-
setIsTTY(false);
229-
230-
const result = runWrangler("versions upload");
231-
232-
await expect(result).resolves.toBeUndefined();
233-
234-
expect(std.warn).toContain(
235-
'Unexpected fields found in kv_namespaces[0] field: "experimental_remote"'
236-
);
237-
});
238-
239-
it("should not warn about experimental_remote fields when --x-remote-bindings is provided", async () => {
240-
mockGetScript();
241-
mockUploadVersion(true);
242-
mockGetWorkerSubdomain({ enabled: true, previews_enabled: false });
243-
244-
// Setup
245-
writeWranglerConfig({
246-
name: "test-name",
247-
main: "./index.js",
248-
kv_namespaces: [
249-
{ binding: "MY_KV", id: "kv-id-xxx", experimental_remote: true },
250-
],
251-
});
252-
writeWorkerSource();
253-
setIsTTY(false);
254-
255-
const result = runWrangler("versions upload --x-remote-bindings");
256-
257-
await expect(result).resolves.toBeUndefined();
258-
259-
expect(std.warn).not.toContain(
260-
'Unexpected fields found in kv_namespaces[0] field: "experimental_remote"'
261-
);
262-
});
263-
264214
describe("multi-env warning", () => {
265215
it("should warn if the wrangler config contains environments but none was specified in the command", async () => {
266216
mockGetScript();

0 commit comments

Comments
 (0)