@@ -2,12 +2,12 @@ import fs from "node:fs";
22import TOML from "@iarna/toml" ;
33import chalk from "chalk" ;
44import dotenv from "dotenv" ;
5- import { findUpSync } from "find-up" ;
65import { FatalError , UserError } from "../errors" ;
76import { getFlag } from "../experimental-flags" ;
87import { logger } from "../logger" ;
98import { EXIT_CODE_INVALID_PAGES_CONFIG } from "../pages/errors" ;
109import { parseJSONC , parseTOML , readFileSync } from "../parse" ;
10+ import { resolveWranglerConfigPath } from "./config-helpers" ;
1111import { isPagesConfig , normalizeAndValidateConfig } from "./validation" ;
1212import { validatePagesConfig } from "./validation-pages" ;
1313import type { CfWorkerInit } from "../deployment-bundle/worker" ;
@@ -66,25 +66,23 @@ export function formatConfigSnippet(
6666 }
6767}
6868
69- type ReadConfigCommandArgs = NormalizeAndValidateConfigArgs ;
69+ type ReadConfigCommandArgs = NormalizeAndValidateConfigArgs & {
70+ config ?: string ;
71+ script ?: string ;
72+ } ;
7073
7174/**
7275 * Get the Wrangler configuration; read it from the give `configPath` if available.
7376 */
7477export function readConfig (
75- configPath : string | undefined ,
7678 args : ReadConfigCommandArgs ,
7779 options ?: { hideWarnings ?: boolean }
7880) : Config ;
7981export function readConfig (
80- configPath : string | undefined ,
8182 args : ReadConfigCommandArgs ,
8283 { hideWarnings = false } : { hideWarnings ?: boolean } = { }
8384) : Config {
84- if ( ! configPath ) {
85- configPath = findWranglerConfig ( process . cwd ( ) ) ;
86- }
87-
85+ const configPath = resolveWranglerConfigPath ( args ) ;
8886 const rawConfig = readRawConfig ( configPath ) ;
8987
9088 const { config, diagnostics } = normalizeAndValidateConfig (
@@ -104,13 +102,10 @@ export function readConfig(
104102}
105103
106104export function readPagesConfig (
107- configPath : string | undefined ,
108105 args : ReadConfigCommandArgs ,
109106 { hideWarnings = false } : { hideWarnings ?: boolean } = { }
110107) : Omit < Config , "pages_build_output_dir" > & { pages_build_output_dir : string } {
111- if ( ! configPath ) {
112- configPath = findWranglerConfig ( process . cwd ( ) ) ;
113- }
108+ const configPath = resolveWranglerConfigPath ( args ) ;
114109
115110 let rawConfig : RawConfig ;
116111 try {
@@ -173,20 +168,6 @@ export const readRawConfig = (configPath: string | undefined): RawConfig => {
173168 return { } ;
174169} ;
175170
176- /**
177- * Find the wrangler config file by searching up the file-system
178- * from the current working directory.
179- */
180- export function findWranglerConfig (
181- referencePath : string = process . cwd ( )
182- ) : string | undefined {
183- return (
184- findUpSync ( `wrangler.json` , { cwd : referencePath } ) ??
185- findUpSync ( `wrangler.jsonc` , { cwd : referencePath } ) ??
186- findUpSync ( `wrangler.toml` , { cwd : referencePath } )
187- ) ;
188- }
189-
190171function addLocalSuffix (
191172 id : string | symbol | undefined ,
192173 local : boolean = false
@@ -660,12 +641,12 @@ export function printBindings(
660641
661642export function withConfig < T > (
662643 handler : (
663- t : OnlyCamelCase < T & CommonYargsOptions > & { config : Config }
644+ args : OnlyCamelCase < T & CommonYargsOptions > & { config : Config }
664645 ) => Promise < void > ,
665- options ?: Parameters < typeof readConfig > [ 2 ]
646+ options ?: Parameters < typeof readConfig > [ 1 ]
666647) {
667- return ( t : OnlyCamelCase < T & CommonYargsOptions > ) => {
668- return handler ( { ...t , config : readConfig ( t . config , t , options ) } ) ;
648+ return ( args : OnlyCamelCase < T & CommonYargsOptions > ) => {
649+ return handler ( { ...args , config : readConfig ( args , options ) } ) ;
669650 } ;
670651}
671652
0 commit comments