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

Feature request: plugin “preprocessor” option #2022

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
46 changes: 30 additions & 16 deletions packages/schema/src/cli/plugin-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ export class PluginRunner {
});
}

const preprocessorPlugins = plugins.filter((p) => p.options.preprocessor);
const otherPlugins = plugins.filter((p) => !p.options.preprocessor);

// calculate all plugins (including core plugins implicitly enabled)
const { corePlugins, userPlugins } = this.calculateAllPlugins(runnerOptions, plugins);
const { corePlugins, userPlugins } = this.calculateAllPlugins(
runnerOptions,
otherPlugins,
);
const allPlugins = [...corePlugins, ...userPlugins];

// check dependencies
Expand Down Expand Up @@ -139,6 +145,28 @@ export class PluginRunner {
let prismaClientDtsPath: string | undefined = undefined;

const project = createProject();

const runUserPlugins = async (plugins: PluginInfo[]) => {
for (const { name, description, run, options: pluginOptions } of plugins) {
const options = { ...pluginOptions, prismaClientPath, prismaClientDtsPath };
const r = await this.runPlugin(
name,
description,
run,
runnerOptions,
options as PluginOptions,
dmmf,
shortNameMap,
project,
false
);
warnings.push(...(r?.warnings ?? [])); // the null-check is for backward compatibility
}
};

// run preprocessor plugins
await runUserPlugins(preprocessorPlugins);

for (const { name, description, run, options: pluginOptions } of corePlugins) {
const options = { ...pluginOptions, prismaClientPath };
const r = await this.runPlugin(
Expand Down Expand Up @@ -175,21 +203,7 @@ export class PluginRunner {
await compileProject(project, runnerOptions);

// run user plugins
for (const { name, description, run, options: pluginOptions } of userPlugins) {
const options = { ...pluginOptions, prismaClientPath, prismaClientDtsPath };
const r = await this.runPlugin(
name,
description,
run,
runnerOptions,
options as PluginOptions,
dmmf,
shortNameMap,
project,
false
);
warnings.push(...(r?.warnings ?? [])); // the null-check is for backward compatibility
}
await runUserPlugins(userPlugins);

console.log(colors.green(colors.bold('\n👻 All plugins completed successfully!')));
warnings.forEach((w) => console.warn(colors.yellow(w)));
Expand Down
Loading