Skip to content

Commit

Permalink
chore: remove experimental_services from configuration (#445)
Browse files Browse the repository at this point in the history
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"
```
  • Loading branch information
threepointone authored Feb 11, 2022
1 parent b72a111 commit d5935e7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 63 deletions.
27 changes: 27 additions & 0 deletions .changeset/long-penguins-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
"wrangler": patch
---

chore: remove `experimental_services` from configuration

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.

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"
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions packages/wrangler/src/api/form_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ export interface WorkerMetadata {
class_name: string;
script_name?: string;
}
| {
type: "service";
name: string;
service: string;
environment: string;
}
)[];
}

Expand Down Expand Up @@ -141,15 +135,6 @@ export function toFormData(worker: CfWorkerInit): FormData {
}
}

bindings.services?.forEach(({ name, service, environment }) => {
metadataBindings.push({
name,
type: "service",
service,
environment,
});
});

if (bindings.unsafe) {
// @ts-expect-error unsafe bindings don't need to match a specific type here
metadataBindings.push(...bindings.unsafe);
Expand Down
10 changes: 0 additions & 10 deletions packages/wrangler/src/api/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ interface CfDurableObject {
script_name?: string;
}

/**
* A Service.
*/
interface CfService {
name: string;
service: string;
environment: string;
}

interface CfUnsafeBinding {
name: string;
type: string;
Expand Down Expand Up @@ -147,7 +138,6 @@ export interface CfWorkerInit {
kv_namespaces?: CfKvNamespace[];
wasm_modules?: CfWasmModuleBindings;
durable_objects?: { bindings: CfDurableObject[] };
services?: CfService[];
unsafe?: CfUnsafeBinding[];
};
migrations: undefined | CfDurableObjectMigrations;
Expand Down
29 changes: 2 additions & 27 deletions packages/wrangler/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export type Config = {
*
* @default `[]`
* @optional
* @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.
* @inherited false
*/
experimental_services?: {
Expand Down Expand Up @@ -569,7 +570,7 @@ export function normaliseAndValidateEnvironmentsConfig(config: Config) {
}

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

// `vars` is just an object
Expand Down Expand Up @@ -644,31 +645,5 @@ export function normaliseAndValidateEnvironmentsConfig(config: Config) {
}
}
}

// `experimental_services` contains an array of namespace bindings
if (config.experimental_services !== undefined) {
if (environment.experimental_services === undefined) {
console.warn(
`In your configuration, "experimental_services" exists at the top level, but not on "env.${envKey}".\n` +
`This is not what you probably want, since "experimental_services" is not inherited by environments.\n` +
`Please add "experimental_services" to "env.${envKey}".`
);
} else {
const envBindingNames = new Set(
environment.experimental_services.map((service) => service.name)
);
for (const bindingName of config.experimental_services.map(
(service) => service.name
)) {
if (!envBindingNames.has(bindingName)) {
console.warn(
`In your configuration, there is a experimental_services with binding name "${bindingName}" at the top level, but not on "env.${envKey}".\n` +
`This is not what you probably want, since "experimental_services" is not inherited by environments.\n` +
`Please add a service for "${bindingName}" to "env.${envKey}.experimental_services".`
);
}
}
}
}
}
}
27 changes: 18 additions & 9 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,25 @@ async function readConfig(configPath?: string): Promise<Config> {

normaliseAndValidateEnvironmentsConfig(config);

// The field "experimental_services" doesn't exist anymore
// in the config, but we still want to error about any older usage.
// TODO: remove this error before GA.
if ("experimental_services" in config) {
console.warn(
"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"
throw new Error(
`The "experimental_services" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
${TOML.stringify({
unsafe: {
bindings: (config.experimental_services || []).map((serviceDefinition) => {
return {
name: serviceDefinition.name,
type: "service",
service: serviceDefinition.service,
environment: serviceDefinition.environment,
};
}),
},
})}`
);
}

Expand Down Expand Up @@ -795,7 +811,6 @@ export async function main(argv: string[]): Promise<void> {
vars: envRootObj.vars,
wasm_modules: config.wasm_modules,
durable_objects: envRootObj.durable_objects,
services: envRootObj.experimental_services,
unsafe: envRootObj.unsafe?.bindings,
}}
/>
Expand Down Expand Up @@ -870,12 +885,6 @@ export async function main(argv: string[]): Promise<void> {
alias: "route",
type: "array",
})
.option("services", {
describe: "experimental support for services",
type: "boolean",
default: "false",
hidden: true,
})
.option("jsx-factory", {
describe: "The function that is called for each JSX element",
type: "string",
Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ export default async function publish(props: Props): Promise<void> {
vars: envRootObj.vars,
wasm_modules: config.wasm_modules,
durable_objects: envRootObj.durable_objects,
services: envRootObj.experimental_services,
unsafe: envRootObj.unsafe?.bindings,
};

Expand Down

0 comments on commit d5935e7

Please sign in to comment.