@@ -178,191 +178,6 @@ export class PluginManager {
178178 ) ;
179179 }
180180 }
181-
182- /*for (const pluginInfo of this._plugins) {
183- let pluginModule: PluginModule;
184- try {
185- pluginModule = require(pluginModulePath);
186- } catch (err) {
187- ConsoleLogger.error(
188- `Unable to load plugin module ${pluginProvider}: ${pluginModulePath}, ${err}`
189- );
190- throw new ProcessingError(
191- `Unable to load plugin module ${pluginProvider}`
192- );
193- }
194-
195- if (!pluginModule) {
196- ConsoleLogger.error(`Plugin provider ${pluginProvider} is missing`);
197- throw new ProcessingError(
198- `Plugin provider ${pluginProvider} is missing`
199- );
200- }
201- if (!pluginModule.generator) {
202- ConsoleLogger.error(
203- `Plugin provider ${pluginProvider} is missing a "generator" export`
204- );
205- throw new ProcessingError(
206- `Plugin provider ${pluginProvider} is missing a "generator" export`
207- );
208- }
209- if (!pluginModule.runner) {
210- ConsoleLogger.error(
211- `Plugin provider ${pluginProvider} is missing a "runner" export`
212- );
213- throw new ProcessingError(
214- `Plugin provider ${pluginProvider} is missing a "runner" export`
215- );
216- }
217-
218- const dependencies = this.getPluginDependencies(pluginModule);
219- const pluginName = this.getPluginName(pluginModule, pluginProvider);
220- const options: PluginOptions = {
221- schemaPath: context.schemaPath,
222- name: pluginName
223- };
224-
225- ConsoleLogger.debug(
226- `Preparing to load plugin:
227- ${JSON.stringify(options)}`
228- );
229-
230- pluginDecl.fields.forEach(f => {
231- const value = getLiteral(f.value) ?? getLiteralArray(f.value);
232- if (value === undefined) {
233- throw new ProcessingError(
234- `${pluginName} Plugin: Invalid option value for ${f.name}`
235- );
236- }
237- options[f.name] = value;
238- });
239-
240- const plugin = {
241- name: pluginName,
242- provider: pluginProvider,
243- dependencies,
244- options,
245- run: pluginModule.default as PluginFunction,
246- module: pluginModule
247- };
248-
249- ConsoleLogger.debug(
250- `Loading plugin:
251- ${JSON.stringify(plugin)}`
252- );
253-
254- plugins.push(plugin);
255-
256- if (
257- pluginProvider === "@core/prisma" &&
258- typeof options.output === "string"
259- ) {
260- // record custom prisma output path
261- prismaOutput = resolvePath(options.output, options);
262- }
263- }
264-
265- // make sure prerequisites are included
266- const corePlugins: Array<{
267- provider: string;
268- options?: Record<string, unknown>;
269- }> = [
270- { provider: "@core/prisma" },
271- { provider: "@core/model-meta" },
272- { provider: "@core/access-policy" }
273- ];
274-
275- if (
276- getDataModels(context.schema).some(model =>
277- hasValidationAttributes(model)
278- )
279- ) {
280- // '@core /zod' plugin is auto-enabled if there're validation rules
281- corePlugins.push({
282- provider: "@plugins /zod",
283- options: { modelOnly: true }
284- });
285- }
286-
287- // core plugins introduced by dependencies
288- plugins
289- .flatMap(p => p.dependencies)
290- .forEach(dep => {
291- if (dep.startsWith("@core /")) {
292- const existing = corePlugins.find(p => p.provider === dep);
293- if (existing) {
294- // reset options to default
295- existing.options = undefined;
296- } else {
297- // add core dependency
298- corePlugins.push({ provider: dep });
299- }
300- }
301- });
302-
303- for (const corePlugin of corePlugins.reverse()) {
304- const existingIdx = plugins.findIndex(
305- p => p.provider === corePlugin.provider
306- );
307- if (existingIdx >= 0) {
308- // shift the plugin to the front
309- const existing = plugins[existingIdx];
310- plugins.splice(existingIdx, 1);
311- plugins.unshift(existing);
312- } else {
313- // synthesize a plugin and insert front
314- const pluginModule = require(this.getPluginModulePath(
315- corePlugin.provider
316- ));
317- const pluginName = this.getPluginName(
318- pluginModule,
319- corePlugin.provider
320- );
321- plugins.unshift({
322- name: pluginName,
323- provider: corePlugin.provider,
324- dependencies: [],
325- options: {
326- schemaPath: context.schemaPath,
327- name: pluginName,
328- ...corePlugin.options
329- },
330- run: pluginModule.default,
331- module: pluginModule
332- });
333- }
334- }
335-
336- // check dependencies
337- for (const plugin of plugins) {
338- for (const dep of plugin.dependencies) {
339- if (!plugins.find(p => p.provider === dep)) {
340- ConsoleLogger.error(
341- `Plugin ${plugin.provider} depends on "${dep}" but it's not declared`
342- );
343- throw new ProcessingError(
344- `Plugin ${plugin.name}: ${plugin.provider} depends on "${dep}" but it's not declared`
345- );
346- }
347- }
348- }
349-
350- let dmmf: DMMF.Document | undefined = undefined;
351- for (const { name, provider, run, options } of plugins) {
352- const start = Date.now();
353- await this.runPlugin(name, run, context, options, dmmf, warnings);
354- ConsoleLogger.log(
355- `✅ Plugin ${chalk.bold(name)} (${provider}) completed in ${
356- Date.now() - start
357- }ms`
358- );
359- if (provider === "@core/prisma") {
360- // load prisma DMMF
361- dmmf = await getDMMF({
362- datamodel: fs.readFileSync(prismaOutput, { encoding: "utf-8" })
363- });
364- }
365- }*/
366181 } else {
367182 ConsoleLogger . warn (
368183 "No plugins specified for this model. No processing will be performed (please ensure this is expected)."
@@ -400,31 +215,6 @@ ${JSON.stringify(plugin)}`
400215 return getLiteral < string > ( providerField ?. value ) ;
401216 }
402217
403- /*private async runPlugin(
404- name: string,
405- run: PluginFunction,
406- context: Context,
407- options: PluginOptions,
408- dmmf: DMMF.Document | undefined,
409- warnings: string[]
410- ) {
411- ConsoleLogger.info(`Executing plugin ${chalk.bold.cyan(name)}`);
412-
413- try {
414- const result = Promise.resolve(run(context.model, options, dmmf, config));
415- if (Array.isArray(result)) {
416- warnings.push(...result);
417- }
418-
419- ConsoleLogger.success("Plugin completed successfully");
420- } catch (err) {
421- ConsoleLogger.error("Plugin failed to complete");
422- ConsoleLogger.error(err);
423-
424- throw err;
425- }
426- }*/
427-
428218 private getPluginModulePath ( provider : string ) {
429219 let pluginModulePath = provider ;
430220 if ( pluginModulePath . startsWith ( "@stormstack/" ) ) {
@@ -437,19 +227,6 @@ ${JSON.stringify(plugin)}`
437227 ) } `;
438228 }
439229
440- /*if (pluginModulePath.startsWith("@core/")) {
441- pluginModulePath = pluginModulePath.replace(
442- /^@core \//,
443- path.join(__dirname, "../../../forecast/plugins/")
444- );
445- }*/
446- /*if (pluginModulePath.startsWith("@plugins/")) {
447- pluginModulePath = pluginModulePath.replace(
448- /^@plugins \//,
449- path.join(__dirname, "../../../forecast/plugins/")
450- );
451- }*/
452-
453230 return pluginModulePath ;
454231 }
455232
@@ -495,8 +272,10 @@ ${JSON.stringify(plugin)}`
495272 }
496273
497274 if ( ! pluginModule ) {
498- ConsoleLogger . error ( `Plugin provider ${ pluginProvider } is missing` ) ;
499- throw new ProcessingError ( `Plugin provider ${ pluginProvider } is missing` ) ;
275+ ConsoleLogger . error ( `Plugin provider ${ pluginProvider } cannot be found` ) ;
276+ throw new ProcessingError (
277+ `Plugin provider ${ pluginProvider } cannot be found`
278+ ) ;
500279 }
501280
502281 if ( ! pluginModule . name ) {
0 commit comments