Skip to content

Commit 4e03a2a

Browse files
jamesopstadpenalosa
authored andcommitted
Export config types/utils (#7256)
* Exported RawConfig and RawEnvironment types * Added changeset * Export readConfig * Export Config type * Overload unstable_getMiniflareWorkerOptions function to accept config * Added unstable prefix * Updated changeset
1 parent cb01ebe commit 4e03a2a

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

.changeset/breezy-cats-matter.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Export unstable_readConfig function and UnstableConfig, UnstableRawConfig, UnstableRawEnvironment and UnstableMiniflareWorkerOptions types from Wrangler.
6+
Overload unstable_getMiniflareWorkerOptions function to accept a config that has already been loaded.

packages/wrangler/src/api/integrations/platform/index.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ import { getLegacyAssetPaths, getSiteAssetPaths } from "../../../sites";
1616
import { CacheStorage } from "./caches";
1717
import { ExecutionContext } from "./executionContext";
1818
import { getServiceBindings } from "./services";
19-
import type { Config } from "../../../config";
19+
import type { Config, RawConfig, RawEnvironment } from "../../../config";
2020
import type { IncomingRequestCfProperties } from "@cloudflare/workers-types/experimental";
2121
import type { MiniflareOptions, ModuleRule, WorkerOptions } from "miniflare";
2222

23+
export { readConfig as unstable_readConfig };
24+
export type {
25+
Config as UnstableConfig,
26+
RawConfig as UnstableRawConfig,
27+
RawEnvironment as UnstableRawEnvironment,
28+
};
29+
2330
/**
2431
* Options for the `getPlatformProxy` utility
2532
*/
@@ -237,17 +244,27 @@ export type SourcelessWorkerOptions = Omit<
237244
"script" | "scriptPath" | "modules" | "modulesRoot"
238245
> & { modulesRules?: ModuleRule[] };
239246

240-
export function unstable_getMiniflareWorkerOptions(
241-
configPath: string,
242-
env?: string
243-
): {
247+
export interface UnstableMiniflareWorkerOptions {
244248
workerOptions: SourcelessWorkerOptions;
245249
define: Record<string, string>;
246250
main?: string;
247-
} {
248-
const config = readConfig(configPath, {
249-
env,
250-
});
251+
}
252+
253+
export function unstable_getMiniflareWorkerOptions(
254+
configPath: string,
255+
env?: string
256+
): UnstableMiniflareWorkerOptions;
257+
export function unstable_getMiniflareWorkerOptions(
258+
config: Config
259+
): UnstableMiniflareWorkerOptions;
260+
export function unstable_getMiniflareWorkerOptions(
261+
configOrConfigPath: string | Config,
262+
env?: string
263+
): UnstableMiniflareWorkerOptions {
264+
const config =
265+
typeof configOrConfigPath === "string"
266+
? readConfig(configOrConfigPath, { env })
267+
: configOrConfigPath;
251268

252269
const modulesRules: ModuleRule[] = config.rules
253270
.concat(DEFAULT_MODULE_RULES)

0 commit comments

Comments
 (0)