Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit b3c1df4

Browse files
committed
Rename experimental_services to services`, closes #280
1 parent 92f7faa commit b3c1df4

File tree

6 files changed

+47
-19
lines changed

6 files changed

+47
-19
lines changed

packages/core/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ function splitWranglerConfig<Plugins extends PluginSignatures>(
153153
plugins: PluginEntries<Plugins>,
154154
overrides: PluginOptions<Plugins>,
155155
config: WranglerConfig,
156-
configDir: string
156+
configDir: string,
157+
log: Log
157158
): PluginOptions<Plugins> {
158159
// Create a new options object so we don't override overrides with undefined,
159160
// causing future reloads to unset config defined in Wrangler
@@ -168,7 +169,11 @@ function splitWranglerConfig<Plugins extends PluginSignatures>(
168169
if (key in pluginOverrides) {
169170
(pluginResult as any)[key] = pluginOverrides[key];
170171
} else {
171-
(pluginResult as any)[key] = meta.fromWrangler?.(config, configDir);
172+
(pluginResult as any)[key] = meta.fromWrangler?.(
173+
config,
174+
configDir,
175+
log
176+
);
172177
}
173178
}
174179
result[name] = pluginResult;
@@ -351,7 +356,8 @@ export class MiniflareCore<
351356
this.#plugins,
352357
this.#overrides,
353358
config,
354-
configDir
359+
configDir,
360+
this.#ctx.log
355361
);
356362
} catch (e: any) {
357363
// Ignore ENOENT (file not found) errors for default path

packages/core/src/plugins/bindings.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
PluginContext,
1212
RequestContext,
1313
SetupResult,
14+
WranglerServiceConfig,
1415
getRequestContext,
1516
viewToBuffer,
1617
} from "@miniflare/shared";
@@ -208,14 +209,21 @@ export class BindingsPlugin
208209
}
209210
})
210211
),
211-
fromWrangler: ({ experimental_services }) =>
212-
experimental_services?.reduce(
213-
(services, { name, service, environment }) => {
214-
services[name] = { service, environment };
215-
return services;
216-
},
217-
{} as ServiceBindingsOptions
218-
),
212+
fromWrangler: ({ services, experimental_services }, configDir, log) => {
213+
if (experimental_services) {
214+
log.warn(
215+
"Using `experimental_services` in `wrangler.toml` is deprecated. " +
216+
"This key should be renamed to `services`."
217+
);
218+
}
219+
const allServices: WranglerServiceConfig[] = [];
220+
if (services) allServices.push(...services);
221+
if (experimental_services) allServices.push(...experimental_services);
222+
return allServices?.reduce((services, { name, service, environment }) => {
223+
services[name] = { service, environment };
224+
return services;
225+
}, {} as ServiceBindingsOptions);
226+
},
219227
})
220228
serviceBindings?: ServiceBindingsOptions;
221229

packages/core/test/plugins/bindings.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ test("BindingsPlugin: parses options from wrangler config", async (t) => {
121121
DATA1: "data-blob-1.bin",
122122
DATA2: "data-blob-2.bin",
123123
},
124-
experimental_services: [
124+
services: [
125125
{ name: "SERVICE1", service: "service1", environment: "development" },
126126
{ name: "SERVICE2", service: "service2", environment: "production" },
127127
],
128+
experimental_services: [
129+
{ name: "SERVICE3", service: "service3", environment: "staging" },
130+
],
128131
miniflare: {
129132
globals: { KEY5: "value5", KEY6: false, KEY7: 10 },
130133
env_path: ".env.test",
@@ -139,6 +142,7 @@ test("BindingsPlugin: parses options from wrangler config", async (t) => {
139142
serviceBindings: {
140143
SERVICE1: { service: "service1", environment: "development" },
141144
SERVICE2: { service: "service2", environment: "production" },
145+
SERVICE3: { service: "service3", environment: "staging" },
142146
},
143147
});
144148

packages/shared-test/src/plugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Context,
55
ExtractOptions,
66
Mount,
7+
NoOpLog,
78
Option,
89
OptionType,
910
Plugin,
@@ -30,7 +31,11 @@ export function parsePluginWranglerConfig<Plugin extends PluginSignature>(
3031
): ExtractOptions<InstanceType<Plugin>> {
3132
const result = {} as ExtractOptions<InstanceType<Plugin>>;
3233
for (const [key, meta] of plugin.prototype.opts?.entries() ?? []) {
33-
(result as any)[key] = meta.fromWrangler?.(config, configDir);
34+
(result as any)[key] = meta.fromWrangler?.(
35+
config,
36+
configDir,
37+
new NoOpLog()
38+
);
3439
}
3540
return result;
3641
}

packages/shared/src/plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export interface OptionMetadataType<Type extends OptionType, Value> {
4242
: undefined;
4343
fromWrangler?: (
4444
config: WranglerConfig,
45-
configDir: string
45+
configDir: string,
46+
log: Log
4647
) => Value | undefined;
4748
}
4849

packages/shared/src/wrangler.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { ModuleRuleType } from "./runner";
33

44
// See https://developers.cloudflare.com/workers/cli-wrangler/configuration#keys
55

6+
export interface WranglerServiceConfig {
7+
name: string;
8+
service: string;
9+
environment: string;
10+
}
11+
612
export interface WranglerEnvironmentConfig {
713
name?: string; // inherited
814
zone_id?: string; // inherited
@@ -37,11 +43,9 @@ export interface WranglerEnvironmentConfig {
3743
wasm_modules?: Record<string, string>; // inherited
3844
text_blobs?: Record<string, string>; // inherited
3945
data_blobs?: Record<string, string>; // inherited
40-
experimental_services?: {
41-
name: string;
42-
service: string;
43-
environment: string;
44-
}[]; // (probably) NOT inherited
46+
services?: WranglerServiceConfig[]; // (probably) NOT inherited
47+
/** @deprecated Use `services` instead */
48+
experimental_services?: WranglerServiceConfig[]; // (probably) NOT inherited
4549
miniflare?: {
4650
globals?: Record<string, any>;
4751
upstream?: string;

0 commit comments

Comments
 (0)