Skip to content

v2.0.0

Compare
Choose a tag to compare
@github-actions github-actions released this 11 Dec 07:46
· 4 commits to main since this release

Buy me a coffee

Documentation v2.0.0: https://raw.githack.com/jaywcjlove/auto-config-loader/790defe/index.html

v1.7.8...v2.0.0

  1. test: update test case. @jaywcjlove
  2. fix: ensure consistent handling of default exports across platforms. @jaywcjlove
  3. fix: ensure consistent handling of default exports across platforms. @jaywcjlove
  4. 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

  1. Loader Functions Support Async

    • LoaderFunc<T> now supports returning T or Promise<T>.
    • Update custom loaders to handle asynchronous operations if needed.

    Example:

    export type LoaderFunc<T> = (
      filepath: string,
      content: string,
      jsOption?: LoadConfOption
    ) => T | Promise<T>;
  2. autoConf Returns a Promise

    • The autoConf function now returns a Promise 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>;

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);
});