Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
mdjermanovic committed Oct 23, 2024
commit 26a4c88011573bb8a4d5163c113aaeacd16e35d5
28 changes: 12 additions & 16 deletions lib/config/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,20 +565,14 @@ class LegacyConfigLoader extends ConfigLoader {
* The cached config file path for this instance.
* @type {Promise<{configFilePath:string,basePath:string}|undefined>}
*/
#configFilePathPromise;
#configFilePath;

/**
* The cached config array for this instance.
* @type {FlatConfigArray}
* @type {FlatConfigArray|Promise<FlatConfigArray>}
*/
#configArray;

/**
* The cached config array for this instance.
* @type {Promise<FlatConfigArray>}
*/
#configArrayPromise;

/**
* Creates a new instance.
* @param {ConfigLoaderOptions} options The options to use when loading configuration files.
Expand All @@ -597,15 +591,15 @@ class LegacyConfigLoader extends ConfigLoader {
* the config file.
*/
#locateConfigFileToUse() {
if (!this.#configFilePathPromise) {
this.#configFilePathPromise = locateConfigFileToUse({
if (!this.#configFilePath) {
this.#configFilePath = locateConfigFileToUse({
useConfigFile: this.#options.configFile,
cwd: this.#options.cwd,
allowTS: this.#options.allowTS
});
}

return this.#configFilePathPromise;
return this.#configFilePath;
}

/**
Expand All @@ -622,12 +616,10 @@ class LegacyConfigLoader extends ConfigLoader {
}

// ensure `calculateConfigArray` is called only once
if (!this.#configArrayPromise) {
this.#configArrayPromise = calculateConfigArray(configFilePath, basePath, this.#options);
}
this.#configArray = calculateConfigArray(configFilePath, basePath, this.#options);

// Cache the config array for this instance. This is primarely needed for the sync `getCachedConfigArrayForPath` method.
this.#configArray = await this.#configArrayPromise;
// Unwrap the promise. This is primarely for the sync `getCachedConfigArrayForPath` method.
this.#configArray = await this.#configArray;

return this.#configArray;
}
Expand Down Expand Up @@ -692,6 +684,10 @@ class LegacyConfigLoader extends ConfigLoader {
throw new Error(`Could not find config file for ${dirPath}`);
}

if (typeof this.#configArray.then === "function") {
throw new Error(`Config array for ${dirPath} has not yet been calculated`);
}

return this.#configArray;
}
}
Expand Down