1- import { importJsConfig } from "@oxapps/shared" ;
1+ import { importJsConfig , loadViteConfigField } from "@oxapps/shared" ;
22import { getErrorMessage } from "./utils/utils.ts" ;
33import { DateNow , JSONStringify } from "./utils/globals.ts" ;
44
@@ -94,34 +94,14 @@ async function resolveJsConfig(path: string, cacheKey: number): Promise<JsConfig
9494 return { path, config } ;
9595}
9696
97- const VITE_OXLINT_CONFIG_FIELD = "lint" ;
98-
9997/**
10098 * Resolve a single Vite+ config path to a `JsConfigResult`.
101- * Extracts the `.lint` field. Returns `null` config when missing (signals "skip").
99+ * Extracts the `.lint` field via `vite-plus` . Returns `null` config when missing (signals "skip").
102100 */
103- async function resolveVitePlusConfig ( path : string , cacheKey : number ) : Promise < JsConfigResult > {
104- const config = await importJsConfig ( path , cacheKey ) ;
105-
106- // NOTE: Vite configs may export a function via `defineConfig(() => ({ ... }))`,
107- // but we don't know the arguments to call the function.
108- // Treat non-object exports as "no config" and skip.
109- if ( ! isObject ( config ) ) {
110- return { path, config : null } ;
111- }
112-
113- const lintConfig = ( config as Record < string , unknown > ) [ VITE_OXLINT_CONFIG_FIELD ] ;
114- // NOTE: return `null` if `.lint` is missing which signals "skip" this
115- if ( lintConfig === undefined ) {
116- return { path, config : null } ;
117- }
118-
119- if ( ! isObject ( lintConfig ) ) {
120- throw new Error (
121- `The \`${ VITE_OXLINT_CONFIG_FIELD } \` field in the default export must be an object.` ,
122- ) ;
123- }
124- validateConfigExtends ( lintConfig as object ) ;
101+ async function resolveVitePlusConfig ( path : string ) : Promise < JsConfigResult > {
102+ const lintConfig = await loadViteConfigField ( path , "lint" ) ;
103+ if ( lintConfig === null ) return { path, config : null } ;
104+ validateConfigExtends ( lintConfig ) ;
125105 return { path, config : lintConfig } ;
126106}
127107
@@ -130,11 +110,10 @@ async function resolveVitePlusConfig(path: string, cacheKey: number): Promise<Js
130110 */
131111async function loadConfigs (
132112 paths : string [ ] ,
133- resolver : ( path : string , cacheKey : number ) => Promise < JsConfigResult > ,
113+ resolver : ( path : string ) => Promise < JsConfigResult > ,
134114) : Promise < string > {
135115 try {
136- const cacheKey = DateNow ( ) ;
137- const results = await Promise . allSettled ( paths . map ( ( path ) => resolver ( path , cacheKey ) ) ) ;
116+ const results = await Promise . allSettled ( paths . map ( resolver ) ) ;
138117
139118 const successes : JsConfigResult [ ] = [ ] ;
140119 const errors : { path : string ; error : string } [ ] = [ ] ;
@@ -168,7 +147,12 @@ export type ConfigLoader = (paths: string[]) => Promise<string>;
168147/**
169148 * Load standard oxlint JS/TS config files in parallel.
170149 */
171- export const loadJsConfigs : ConfigLoader = ( paths ) => loadConfigs ( paths , resolveJsConfig ) ;
150+ export const loadJsConfigs : ConfigLoader = ( paths ) => {
151+ // Share one cache-busting key across the batch so that `?cache=<key>` is identical
152+ // for every path resolved in this call (consistent reload semantics for LSP).
153+ const cacheKey = DateNow ( ) ;
154+ return loadConfigs ( paths , ( path ) => resolveJsConfig ( path , cacheKey ) ) ;
155+ } ;
172156
173157/**
174158 * Load Vite+ config files in parallel, extracting the `.lint` field from each.
0 commit comments