Make loading of bundled plugins working and robust
Summary: Bundled plugins so far didn't load because the defaultPlugins was not generated yet. Fixed follow up errors that resulted from node modules not being available in the browser, and made the process more robust so that one plugin that fails to initialise doesn't kill all bundled plugins from being loaded. Cleaned up the server scripts, and reused the BUILTINS list that is already maintained in the babel transformer. Report errors during the build process if modules are referred that are stubbed out (later on we could maybe error on that) Reviewed By: aigoncharov Differential Revision: D33020243 fbshipit-source-id: 3ce13b0049664b5fb19c1f45f0b33c1d7fdbea4c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5564251aac
commit
5ce5d897c8
@@ -30,6 +30,7 @@ import {
|
||||
babelTransformationsDir,
|
||||
serverDir,
|
||||
rootDir,
|
||||
browserUiDir,
|
||||
} from './paths';
|
||||
|
||||
const {version} = require('../package.json');
|
||||
@@ -121,11 +122,25 @@ async function generateDefaultPluginEntryPoints(
|
||||
bundledPlugins,
|
||||
);
|
||||
const pluginRequres = bundledPlugins
|
||||
.map((x) => ` '${x.name}': require('${x.name}')`)
|
||||
.map(
|
||||
(x) =>
|
||||
` '${x.name}': tryRequire('${x.name}', () => require('${x.name}'))`,
|
||||
)
|
||||
.join(',\n');
|
||||
const generatedIndex = `
|
||||
/* eslint-disable */
|
||||
// THIS FILE IS AUTO-GENERATED by function "generateDefaultPluginEntryPoints" in "build-utils.ts".
|
||||
|
||||
// This function exists to make sure that if one require fails in its module initialisation, not everything fails
|
||||
function tryRequire(module: string, fn: () => any): any {
|
||||
try {
|
||||
return fn();
|
||||
} catch (e) {
|
||||
console.error(\`Could not require ${module}: \`, e)
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export default {\n${pluginRequres}\n} as any
|
||||
`;
|
||||
await fs.ensureDir(path.join(appDir, 'src', 'defaultPlugins'));
|
||||
@@ -133,6 +148,11 @@ async function generateDefaultPluginEntryPoints(
|
||||
path.join(appDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndex,
|
||||
);
|
||||
await fs.ensureDir(path.join(browserUiDir, 'src', 'defaultPlugins'));
|
||||
await fs.writeFile(
|
||||
path.join(browserUiDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndex,
|
||||
);
|
||||
console.log('✅ Generated bundled plugin entry points.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user