Skip to content

Commit

Permalink
Export config types/utils (#7256)
Browse files Browse the repository at this point in the history
* Exported RawConfig and RawEnvironment types

* Added changeset

* Export readConfig

* Export Config type

* Overload unstable_getMiniflareWorkerOptions function to accept config

* Added unstable prefix

* Updated changeset
  • Loading branch information
jamesopstad authored Dec 4, 2024
1 parent 8f25ebe commit 415e5b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/breezy-cats-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"wrangler": patch
---

Export unstable_readConfig function and UnstableConfig, UnstableRawConfig, UnstableRawEnvironment and UnstableMiniflareWorkerOptions types from Wrangler.
Overload unstable_getMiniflareWorkerOptions function to accept a config that has already been loaded.
35 changes: 26 additions & 9 deletions packages/wrangler/src/api/integrations/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ import { getLegacyAssetPaths, getSiteAssetPaths } from "../../../sites";
import { CacheStorage } from "./caches";
import { ExecutionContext } from "./executionContext";
import { getServiceBindings } from "./services";
import type { Config } from "../../../config";
import type { Config, RawConfig, RawEnvironment } from "../../../config";
import type { IncomingRequestCfProperties } from "@cloudflare/workers-types/experimental";
import type { MiniflareOptions, ModuleRule, WorkerOptions } from "miniflare";

export { readConfig as unstable_readConfig };
export type {
Config as UnstableConfig,
RawConfig as UnstableRawConfig,
RawEnvironment as UnstableRawEnvironment,
};

/**
* Options for the `getPlatformProxy` utility
*/
Expand Down Expand Up @@ -237,17 +244,27 @@ export type SourcelessWorkerOptions = Omit<
"script" | "scriptPath" | "modules" | "modulesRoot"
> & { modulesRules?: ModuleRule[] };

export function unstable_getMiniflareWorkerOptions(
configPath: string,
env?: string
): {
export interface UnstableMiniflareWorkerOptions {
workerOptions: SourcelessWorkerOptions;
define: Record<string, string>;
main?: string;
} {
const config = readConfig(configPath, {
env,
});
}

export function unstable_getMiniflareWorkerOptions(
configPath: string,
env?: string
): UnstableMiniflareWorkerOptions;
export function unstable_getMiniflareWorkerOptions(
config: Config
): UnstableMiniflareWorkerOptions;
export function unstable_getMiniflareWorkerOptions(
configOrConfigPath: string | Config,
env?: string
): UnstableMiniflareWorkerOptions {
const config =
typeof configOrConfigPath === "string"
? readConfig(configOrConfigPath, { env })
: configOrConfigPath;

const modulesRules: ModuleRule[] = config.rules
.concat(DEFAULT_MODULE_RULES)
Expand Down

0 comments on commit 415e5b5

Please sign in to comment.