@@ -3,6 +3,7 @@ import path from "node:path";
33import {
44 configFileName ,
55 experimental_readRawConfig ,
6+ experimental_readRawConfigAsync ,
67 FatalError ,
78 isPagesConfig ,
89 normalizeAndValidateConfig ,
@@ -16,6 +17,7 @@ import type {
1617 Config ,
1718 NormalizeAndValidateConfigArgs ,
1819 RawConfig ,
20+ ReadRawConfigResult ,
1921 ResolveConfigPathOptions ,
2022} from "@cloudflare/workers-utils" ;
2123
@@ -60,7 +62,7 @@ function convertRawConfigToConfig(
6062 userConfigPath,
6163 deployConfigPath,
6264 redirected,
63- } : Awaited < ReturnType < typeof experimental_readRawConfig > >
65+ } : ReturnType < typeof experimental_readRawConfig >
6466) : Config {
6567 if ( redirected ) {
6668 assert ( configPath , "Redirected config found without a configPath" ) ;
@@ -95,36 +97,47 @@ function convertRawConfigToConfig(
9597}
9698
9799/**
98- * Get the Wrangler configuration; read it from the give `configPath` if available.
100+ * Synchronously get the Wrangler configuration from a data file (toml, json, jsonc).
101+ *
102+ * This function only supports data file formats. For code-based config files,
103+ * use `unstable_readConfigAsync` instead.
99104 */
100105export function readConfig (
101106 args : ReadConfigCommandArgs ,
102107 options : ReadConfigOptions = { }
103- ) : Config | Promise < Config > {
104- const configOrPromise = experimental_readRawConfig ( args , options ) ;
105- if ( "then" in configOrPromise ) {
106- return configOrPromise . then ( ( raw ) =>
107- convertRawConfigToConfig ( args , options , raw )
108- ) ;
109- } else {
110- return convertRawConfigToConfig ( args , options , configOrPromise ) ;
111- }
108+ ) : Config {
109+ const raw = experimental_readRawConfig ( args , options ) ;
110+ return convertRawConfigToConfig ( args , options , raw ) ;
111+ }
112+
113+ /**
114+ * Asynchronously get the Wrangler configuration.
115+ *
116+ * This function supports both data file formats (toml, json, jsonc) and
117+ * will support code-based config files (ts, js, mjs) in the future.
118+ *
119+ * In Wrangler v5, this will become the default `readConfig`.
120+ */
121+ export async function readConfigAsync (
122+ args : ReadConfigCommandArgs ,
123+ options : ReadConfigOptions = { }
124+ ) : Promise < Config > {
125+ const raw = await experimental_readRawConfigAsync ( args , options ) ;
126+ return convertRawConfigToConfig ( args , options , raw ) ;
112127}
113128
114- export async function readPagesConfig (
129+ export function readPagesConfig (
115130 args : ReadConfigCommandArgs ,
116131 options : ReadConfigOptions = { }
117- ) : Promise <
118- Omit < Config , "pages_build_output_dir" > & { pages_build_output_dir : string }
119- > {
132+ ) : Omit < Config , "pages_build_output_dir" > & { pages_build_output_dir : string } {
120133 let rawConfig : RawConfig ;
121134 let configPath : string | undefined ;
122135 let userConfigPath : string | undefined ;
123136 let redirected : boolean ;
124137 let deployConfigPath : string | undefined ;
125138 try {
126139 ( { rawConfig, configPath, userConfigPath, deployConfigPath, redirected } =
127- await experimental_readRawConfig ( args , options ) ) ;
140+ experimental_readRawConfig ( args , options ) ) ;
128141 if ( redirected ) {
129142 assert ( configPath , "Redirected config found without a configPath" ) ;
130143 assert (
0 commit comments