v2.0.0
Documentation v2.0.0: https://raw.githack.com/jaywcjlove/auto-config-loader/790defe/index.html
npm i [email protected]
- test: update test case. @jaywcjlove
- fix: ensure consistent handling of default exports across platforms. @jaywcjlove
- fix: ensure consistent handling of default exports across platforms. @jaywcjlove
- fix(deps): update dependency jiti to v2 #13 @jaywcjlove
V1 To V2 Migration
This guide provides the steps to migrate to the latest version of the configuration loader API.
Key Changes
-
Loader Functions Support Async
LoaderFunc<T>
now supports returningT
orPromise<T>
.- Update custom loaders to handle asynchronous operations if needed.
Example:
export type LoaderFunc<T> = ( filepath: string, content: string, jsOption?: LoadConfOption ) => T | Promise<T>;
-
autoConf
Returns a Promise- The
autoConf
function now returns aPromise
instead of a synchronous result. - Update your code to handle asynchronous calls.
Example:
export declare function autoConf<T>( namespace?: string, option?: AutoConfOption<T> ): Promise<{} & T>;
- The
Migration Steps
1. Update Custom Loader Functions
If you have custom loaders, update their return types to support asynchronous operations:
Example:
const jsonLoader: LoaderFunc<MyConfig> = async (
filepath, content
) => JSON.parse(content);
2. Handle Asynchronous autoConf
Calls
Update all calls to autoConf
to use await
or .then
to handle Promises:
Example Using await
:
const config = await autoConf('myNamespace', options);
console.log(config);
Example Using .then
:
autoConf('myNamespace', options).then(config => {
console.log(config);
});