Skip to content

Commit d5935e7

Browse files
chore: remove experimental_services from configuration (#445)
Now that we have `[[unsafe.bindings]]` (as of #411), we should use that for experimental features. This removes support for `[experimental_services]`, and adds a helpful message for how to rewrite their configuration. This error is temporary, until the internal teams that were using this rewrite their configs. We'll remove it before GA. What the error looks like - ``` Error: The "experimental_services" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml: [[unsafe.bindings]] name = "SomeService" type = "service" service = "some-service" environment = "staging" [[unsafe.bindings]] name = "SomeOtherService" type = "service" service = "some-other-service" environment = "qa" ```
1 parent b72a111 commit d5935e7

File tree

7 files changed

+48
-63
lines changed

7 files changed

+48
-63
lines changed

.changeset/long-penguins-guess.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
chore: remove `experimental_services` from configuration
6+
7+
Now that we have `[[unsafe.bindings]]` (as of https://github.com/cloudflare/wrangler2/pull/411), we should use that for experimental features. This removes support for `[experimental_services]`, and adds a helpful message for how to rewrite their configuration.
8+
9+
This error is temporary, until the internal teams that were using this rewrite their configs. We'll remove it before GA.
10+
11+
What the error looks like -
12+
13+
```
14+
Error: The "experimental_services" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
15+
16+
[[unsafe.bindings]]
17+
name = "SomeService"
18+
type = "service"
19+
service = "some-service"
20+
environment = "staging"
21+
22+
[[unsafe.bindings]]
23+
name = "SomeOtherService"
24+
type = "service"
25+
service = "some-other-service"
26+
environment = "qa"
27+
```

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wrangler/src/api/form_data.ts

-15
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ export interface WorkerMetadata {
4343
class_name: string;
4444
script_name?: string;
4545
}
46-
| {
47-
type: "service";
48-
name: string;
49-
service: string;
50-
environment: string;
51-
}
5246
)[];
5347
}
5448

@@ -141,15 +135,6 @@ export function toFormData(worker: CfWorkerInit): FormData {
141135
}
142136
}
143137

144-
bindings.services?.forEach(({ name, service, environment }) => {
145-
metadataBindings.push({
146-
name,
147-
type: "service",
148-
service,
149-
environment,
150-
});
151-
});
152-
153138
if (bindings.unsafe) {
154139
// @ts-expect-error unsafe bindings don't need to match a specific type here
155140
metadataBindings.push(...bindings.unsafe);

packages/wrangler/src/api/worker.ts

-10
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ interface CfDurableObject {
9999
script_name?: string;
100100
}
101101

102-
/**
103-
* A Service.
104-
*/
105-
interface CfService {
106-
name: string;
107-
service: string;
108-
environment: string;
109-
}
110-
111102
interface CfUnsafeBinding {
112103
name: string;
113104
type: string;
@@ -147,7 +138,6 @@ export interface CfWorkerInit {
147138
kv_namespaces?: CfKvNamespace[];
148139
wasm_modules?: CfWasmModuleBindings;
149140
durable_objects?: { bindings: CfDurableObject[] };
150-
services?: CfService[];
151141
unsafe?: CfUnsafeBinding[];
152142
};
153143
migrations: undefined | CfDurableObjectMigrations;

packages/wrangler/src/config.ts

+2-27
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export type Config = {
209209
*
210210
* @default `[]`
211211
* @optional
212+
* @deprecated DO NOT USE. We'd added this to test the new service binding system, but the proper way to test experimental features is to use `unsafe.bindings` configuration.
212213
* @inherited false
213214
*/
214215
experimental_services?: {
@@ -569,7 +570,7 @@ export function normaliseAndValidateEnvironmentsConfig(config: Config) {
569570
}
570571

571572
// Warn if there is a "required" field in the top level config that has not been specified specified in the environment.
572-
// These required fields are `vars`, `durable_objects`, `kv_namespaces` and `experimental_services`.
573+
// These required fields are `vars`, `durable_objects`, and `kv_namespaces`.
573574
// Each of them has different characteristics that need to be checked.
574575

575576
// `vars` is just an object
@@ -644,31 +645,5 @@ export function normaliseAndValidateEnvironmentsConfig(config: Config) {
644645
}
645646
}
646647
}
647-
648-
// `experimental_services` contains an array of namespace bindings
649-
if (config.experimental_services !== undefined) {
650-
if (environment.experimental_services === undefined) {
651-
console.warn(
652-
`In your configuration, "experimental_services" exists at the top level, but not on "env.${envKey}".\n` +
653-
`This is not what you probably want, since "experimental_services" is not inherited by environments.\n` +
654-
`Please add "experimental_services" to "env.${envKey}".`
655-
);
656-
} else {
657-
const envBindingNames = new Set(
658-
environment.experimental_services.map((service) => service.name)
659-
);
660-
for (const bindingName of config.experimental_services.map(
661-
(service) => service.name
662-
)) {
663-
if (!envBindingNames.has(bindingName)) {
664-
console.warn(
665-
`In your configuration, there is a experimental_services with binding name "${bindingName}" at the top level, but not on "env.${envKey}".\n` +
666-
`This is not what you probably want, since "experimental_services" is not inherited by environments.\n` +
667-
`Please add a service for "${bindingName}" to "env.${envKey}.experimental_services".`
668-
);
669-
}
670-
}
671-
}
672-
}
673648
}
674649
}

packages/wrangler/src/index.tsx

+18-9
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,25 @@ async function readConfig(configPath?: string): Promise<Config> {
7272

7373
normaliseAndValidateEnvironmentsConfig(config);
7474

75+
// The field "experimental_services" doesn't exist anymore
76+
// in the config, but we still want to error about any older usage.
77+
// TODO: remove this error before GA.
7578
if ("experimental_services" in config) {
76-
console.warn(
77-
"The experimental_services field is only for cloudflare internal usage right now, and is subject to change. Please do not use this on production projects"
79+
throw new Error(
80+
`The "experimental_services" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
81+
82+
${TOML.stringify({
83+
unsafe: {
84+
bindings: (config.experimental_services || []).map((serviceDefinition) => {
85+
return {
86+
name: serviceDefinition.name,
87+
type: "service",
88+
service: serviceDefinition.service,
89+
environment: serviceDefinition.environment,
90+
};
91+
}),
92+
},
93+
})}`
7894
);
7995
}
8096

@@ -795,7 +811,6 @@ export async function main(argv: string[]): Promise<void> {
795811
vars: envRootObj.vars,
796812
wasm_modules: config.wasm_modules,
797813
durable_objects: envRootObj.durable_objects,
798-
services: envRootObj.experimental_services,
799814
unsafe: envRootObj.unsafe?.bindings,
800815
}}
801816
/>
@@ -870,12 +885,6 @@ export async function main(argv: string[]): Promise<void> {
870885
alias: "route",
871886
type: "array",
872887
})
873-
.option("services", {
874-
describe: "experimental support for services",
875-
type: "boolean",
876-
default: "false",
877-
hidden: true,
878-
})
879888
.option("jsx-factory", {
880889
describe: "The function that is called for each JSX element",
881890
type: "string",

packages/wrangler/src/publish.ts

-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ export default async function publish(props: Props): Promise<void> {
254254
vars: envRootObj.vars,
255255
wasm_modules: config.wasm_modules,
256256
durable_objects: envRootObj.durable_objects,
257-
services: envRootObj.experimental_services,
258257
unsafe: envRootObj.unsafe?.bindings,
259258
};
260259

0 commit comments

Comments
 (0)