diff --git a/.changeset/fair-buttons-peel.md b/.changeset/fair-buttons-peel.md new file mode 100644 index 000000000..b62aa9b57 --- /dev/null +++ b/.changeset/fair-buttons-peel.md @@ -0,0 +1,5 @@ +--- +'@farmfe/core': minor +--- + +New Function resolvePlugin created which combine the functionality of resolveFarmPlugin and resloveAsyncPlugins. diff --git a/.changeset/sixty-actors-play.md b/.changeset/sixty-actors-play.md new file mode 100644 index 000000000..ed5aa1ea8 --- /dev/null +++ b/.changeset/sixty-actors-play.md @@ -0,0 +1,16 @@ +--- +'@farmfe/core': major +--- + +Description: + +This PR introduces a new function, resolvePlugins, which combines the functionality of resolveFarmPlugins and resolveAsyncPlugins. This new function first resolves any promises and flattens the array of plugins, and then processes the resulting plugins as in resolveFarmPlugins. This allows the use of async and nested plugins in the configuration. + +Changes: + +Added a new function resolvePlugins in src/plugin/index.ts that handles async and nested plugins. +Replaced calls to resolveFarmPlugins with resolvePlugins in the codebase. + +BREAKING CHANGE: + +This change should not introduce any breaking changes. The new function resolvePlugins is backwards compatible with resolveFarmPlugins. diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts index 2f99f2e50..2a58b7115 100644 --- a/packages/core/src/config/index.ts +++ b/packages/core/src/config/index.ts @@ -10,7 +10,7 @@ import { resolveAsyncPlugins, resolveConfigHook, resolveConfigResolvedHook, - resolveFarmPlugins + resolvePlugins } from '../plugin/index.js'; import { bindingPath, @@ -158,7 +158,7 @@ export async function resolveConfig( config: rawConfig }; - const { jsPlugins, rustPlugins } = await resolveFarmPlugins(userConfig); + const { jsPlugins, rustPlugins } = await resolvePlugins(userConfig); const rawJsPlugins = (await resolveAsyncPlugins(jsPlugins || [])).filter( Boolean diff --git a/packages/core/src/plugin/index.ts b/packages/core/src/plugin/index.ts index 6595bba17..ca001b111 100644 --- a/packages/core/src/plugin/index.ts +++ b/packages/core/src/plugin/index.ts @@ -9,8 +9,8 @@ import merge from '../utils/merge.js'; export * from './js/index.js'; export * from './rust/index.js'; -export async function resolveFarmPlugins(config: UserConfig) { - const plugins = config.plugins ?? []; +export async function resolvePlugins(config: UserConfig) { + let plugins = config.plugins ?? []; if (!plugins.length) { return { @@ -18,9 +18,10 @@ export async function resolveFarmPlugins(config: UserConfig) { jsPlugins: [] }; } + // First, resolve any promises and flatten the array + plugins = await resolveAsyncPlugins(plugins); const rustPlugins = []; - const jsPlugins: JsPlugin[] = []; for (const plugin of plugins) { @@ -56,7 +57,6 @@ export async function resolveFarmPlugins(config: UserConfig) { }; } -// resolve promise plugins export async function resolveAsyncPlugins(arr: T[]): Promise { return arr.reduce>(async (acc, current) => { const flattenedAcc = await acc;