Skip to content

Commit

Permalink
Fix/filter server plugins (#5858)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Jun 21, 2024
1 parent 29aeb3c commit f8ba62c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/hungry-squids-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/plugin-testing': patch
'@modern-js/app-tools': patch
---

fix: filter server plugin by metaName
fix: 用 metaName 来过滤 server plugin
7 changes: 6 additions & 1 deletion packages/runtime/plugin-testing/src/cli/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ const test = async (
plugins: [],
})) || {};

// filter plugins by metaName
const filtedPlugins = plugins?.filter((plugin: any) =>
plugin.name.includes(appContext.metaName || 'modern-js'),
);

api.setAppContext({
...api.useAppContext(),
serverPlugins: plugins,
serverPlugins: filtedPlugins,
});

userConfig.testing = userConfig.testing || {};
Expand Down
2 changes: 1 addition & 1 deletion packages/solutions/app-tools/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const build = async (
const hookRunners = api.useHookRunners();

// we need load server plugin to appContext for ssg & deploy commands.
await loadServerPlugins(api, appContext.appDirectory);
await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);

await registerCompiler(
appContext.appDirectory,
Expand Down
2 changes: 1 addition & 1 deletion packages/solutions/app-tools/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const dev = async (

await generateRoutes(appContext);

const pluginInstances = await loadServerPlugins(api, appDirectory);
const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);

const serverOptions = {
metaName,
Expand Down
2 changes: 1 addition & 1 deletion packages/solutions/app-tools/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const start = async (api: PluginAPI<AppTools<'shared'>>) => {
`${meta}.server`,
);

const pluginInstances = await loadServerPlugins(api, appDirectory);
const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);

const app = await createProdServer({
metaName,
Expand Down
13 changes: 10 additions & 3 deletions packages/solutions/app-tools/src/utils/loadPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@ import { AppTools, PluginAPI } from '../types';

export async function getServerPlugins(
api: PluginAPI<AppTools<'shared'>>,
metaName = 'modern-js',
): Promise<ServerPlugin[]> {
const runner = api.useHookRunners();
const { plugins } = await runner._internalServerPlugins({ plugins: [] });

// filter plugins by metaName
const filtedPlugins = plugins.filter(plugin =>
plugin.name.includes(metaName),
);

api.setAppContext({
...api.useAppContext(),
serverPlugins: plugins,
serverPlugins: filtedPlugins,
});

return plugins;
return filtedPlugins;
}

export async function loadServerPlugins(
api: PluginAPI<AppTools<'shared'>>,
appDirectory: string,
metaName: string,
): Promise<ServerPluginInstance[]> {
const plugins = await getServerPlugins(api);
const plugins = await getServerPlugins(api, metaName);

const instances = loadServerPluginInstances(plugins, appDirectory);

Expand Down

0 comments on commit f8ba62c

Please sign in to comment.