Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

DeepeshKalura
Copy link

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.

Copy link

changeset-bot bot commented Apr 27, 2024

⚠️ No Changeset found

Latest commit: c68f21f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ErKeLost
Copy link
Member

ErKeLost commented Apr 28, 2024

@DeepeshKalura Thanks, Thank you for your contribution, but should not update pnpm.lock should use the correct version,my pnpm version is 8.7.x or your higher version we will consider upgrading the pnpm version in the future

@ErKeLost
Copy link
Member

Because the code of core has been modified, you need to execute npx changeset in the root directory to update the package of the first version of patch.

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) {
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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[]> {
Copy link
Member

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') {
Copy link
Member

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

Copy link
Author

@DeepeshKalura DeepeshKalura Apr 28, 2024

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} 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) {
Copy link
Member

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.

@DeepeshKalura
Copy link
Author

@ErKeLost Thanks for letting me know, I will revert changes in the pnpm version and execute npx changeset. update this PR.

@DeepeshKalura
Copy link
Author

@shulandmimi Closing this PR and I later will recreate this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants