[skip ci] plugin guard
This commit is contained in:
1 parent
c0dce836cf
commit
35b38c7cd8
17 files changed
+97
-15
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { CompilerPlugin, ProgramBuilder } from 'brighterscript';
|
||||
|
||||
// A plugin that fails to load (e.g. a TypeScript error in its file) is only logged
|
||||
// by bsc and the build continues without it, exiting 0 (rokucommunity/brighterscript#1675).
|
||||
// Listed last in the plugins array, this guard fails the command when any configured
|
||||
// plugin is missing from the loaded set. It deliberately imports nothing from the
|
||||
// other plugin files, so it still loads when one of them is broken.
|
||||
const exitOnError = !!process.env.npm_lifecycle_event && !process.argv.includes('--lsp');
|
||||
|
||||
export class CriticalExitGuardPlugin implements CompilerPlugin {
|
||||
public name = 'CriticalExitGuardPlugin';
|
||||
|
||||
beforeProgramCreate(builder: ProgramBuilder) {
|
||||
if (!exitOnError) {
|
||||
return;
|
||||
}
|
||||
const configured = (builder as any)?.options?.plugins?.length ?? 0;
|
||||
const loaded = (builder as any)?.plugins?.plugins?.length ?? 0;
|
||||
if (loaded < configured) {
|
||||
console.error(`${configured - loaded} of ${configured} configured plugins failed to load (see "Error when loading plugin" above)`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
return new CriticalExitGuardPlugin();
|
||||
};
|
||||
Reference in new issue
Block a user