-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a function to combine resolveFarmPlugin and resolveAsyncPlugins in index.ts #1255
Conversation
… resolveAsyncPlugin in index.ts
|
@DeepeshKalura Thanks, Thank you for your contribution, but should not update pnpm.lock should use the correct version,my |
Because the code of core has been modified, you need to execute |
import type { JsPlugin } from './type.js'; | ||
import { ResolvedUserConfig, type UserConfig } from '../config/index.js'; | ||
import merge from '../utils/merge.js'; | ||
|
||
export * from './js/index.js'; | ||
export * from './rust/index.js'; | ||
|
||
export async function resolveFarmPlugins(config: UserConfig) { | ||
// combing resolveFarmPlugin and resolveAsyncPlugin | ||
export async function resolveFarmPluginsAndAsyncPlugins(config: UserConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/core/src/config/index.ts:13
references it but does not sync the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate the what you mean by references it?
My understanding, you call the function it has synchronized issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You changed its name but did not change it synchronously in packages/core/src/config/index.ts
where it is used.
}; | ||
} | ||
|
||
// resolve promise plugins | ||
export async function resolveAsyncPlugins<T>(arr: T[]): Promise<T[]> { | ||
async function resolveAsyncPlugins<T>(arr: T[]): Promise<T[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, packages/core/src/config/index.ts:13
references it.
) { | ||
rustPlugins.push( | ||
await rustPluginResolver(plugin as string, config.root ?? process.cwd()) | ||
); | ||
} else if (isObject(plugin)) { | ||
} else if (typeof plugin === 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof is not accurate, for example, a null is received
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shulandmimi you are correct that typeof
in js can be misleading, especially when dealing with null values, as typeof
null returns 'object'. Can you suggest me what to do when null
received. I was thinking to raise an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (typeof plugin === 'object') { | |
} else if (isObject(plugin)) { |
@@ -20,7 +19,6 @@ export async function resolveFarmPlugins(config: UserConfig) { | |||
} | |||
|
|||
const rustPlugins = []; | |||
|
|||
const jsPlugins: JsPlugin[] = []; | |||
|
|||
for (const plugin of plugins) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should support async plugin, that is, the plugin may be a promise, so we should judge here whether it is a promise received, wait for it to resolve, and then judge whether it is a rust plugin or a js plugin.
But the above implementation alone does not support nesting, so it would be better if you could help implement nesting.
@ErKeLost Thanks for letting me know, I will revert changes in the |
@shulandmimi Closing this PR and I later will recreate this PR. |
Source
from Issue #1224, "support receive Promise plugin"
Understand
Combine two function
Description of changes:
The
resolveFarmPlugins
function was originally responsible for processing an array of plugins from a configuration object. It would separate these plugins into two categories: Rust plugins and JavaScript plugins. The function would then return an object containing these two arrays.The
resolveAsyncPlugins
function was responsible for resolving an array of asynchronous plugins. It would return a new array where all asynchronous plugins have been resolved.In the combined function resolveFarmPluginsAndAsyncPlugins, we first process the plugins as we did in the resolveFarmPlugins function. However, instead of immediately returning the Rust and JavaScript plugins, we pass each array to the resolveAsyncPlugins function. This ensures that all plugins are resolved before they are returned.
The main difference between the original resolveFarmPlugins function and the combined resolveFarmPluginsAndAsyncPlugins function is that the latter ensures all plugins are resolved before they are returned. This is important if any of the plugins are asynchronous and need to be awaited before they can be used.
This combined function provides a more complete solution for processing and resolving plugins, as it handles both the separation of plugin types and the resolution of asynchronous plugins.