Fix fb-stubs replacement for plugin bundling
Reviewed By: nikoant Differential Revision: D39765543 fbshipit-source-id: 14cbf8a9bdf35031e636bbbde3dbc955faedb66b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
61a8fe09e9
commit
dd7ba2d6fc
@@ -18,6 +18,7 @@ const defaultPluginsDir = path.join(__dirname, '../../static/defaultPlugins');
|
||||
export async function buildDefaultPlugins(
|
||||
defaultPlugins: InstalledPluginDetails[],
|
||||
dev: boolean,
|
||||
intern: boolean,
|
||||
) {
|
||||
if (process.env.FLIPPER_NO_REBUILD_PLUGINS) {
|
||||
console.log(
|
||||
@@ -36,7 +37,7 @@ export async function buildDefaultPlugins(
|
||||
console.log(
|
||||
`⚙️ Building plugin ${plugin.id} to include it into the default plugins list...`,
|
||||
);
|
||||
await runBuild(plugin.dir, dev);
|
||||
await runBuild(plugin.dir, dev, intern);
|
||||
}
|
||||
await fs.ensureSymlink(
|
||||
plugin.dir,
|
||||
|
||||
@@ -10,7 +10,21 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {getInstalledPluginDetails} from 'flipper-plugin-lib';
|
||||
import {build} from 'esbuild';
|
||||
import {build, Plugin} from 'esbuild';
|
||||
|
||||
// https://github.com/evanw/esbuild/issues/1979#issuecomment-1026988439
|
||||
const resolveFbStubsToFbPlugin: Plugin = {
|
||||
name: 'resolve-fb-stubs-to-fb',
|
||||
setup({onResolve}) {
|
||||
onResolve({filter: /fb-stubs/}, (args) => {
|
||||
return {
|
||||
path: require.resolve(args.path.replace('fb-stubs', 'fb'), {
|
||||
paths: [args.resolveDir],
|
||||
}),
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
interface RunBuildConfig {
|
||||
pluginDir: string;
|
||||
@@ -19,6 +33,7 @@ interface RunBuildConfig {
|
||||
dev: boolean;
|
||||
node?: boolean;
|
||||
sourceMapPath?: string;
|
||||
intern: boolean;
|
||||
}
|
||||
|
||||
async function runBuild({
|
||||
@@ -28,6 +43,7 @@ async function runBuild({
|
||||
dev,
|
||||
node,
|
||||
sourceMapPath,
|
||||
intern,
|
||||
}: RunBuildConfig) {
|
||||
await build({
|
||||
entryPoints: [path.join(pluginDir, entry)],
|
||||
@@ -52,6 +68,7 @@ async function runBuild({
|
||||
],
|
||||
sourcemap: 'external',
|
||||
minify: !dev,
|
||||
plugins: intern ? [resolveFbStubsToFbPlugin] : undefined,
|
||||
});
|
||||
|
||||
const sourceMapUrl = `${out}.map`;
|
||||
@@ -73,6 +90,7 @@ type Options = {
|
||||
export default async function bundlePlugin(
|
||||
pluginDir: string,
|
||||
dev: boolean,
|
||||
intern: boolean,
|
||||
options?: Options,
|
||||
) {
|
||||
const stat = await fs.lstat(pluginDir);
|
||||
@@ -103,6 +121,7 @@ export default async function bundlePlugin(
|
||||
out: plugin.entry,
|
||||
dev,
|
||||
sourceMapPath: options?.sourceMapPath,
|
||||
intern,
|
||||
});
|
||||
|
||||
if (
|
||||
@@ -118,6 +137,7 @@ export default async function bundlePlugin(
|
||||
dev,
|
||||
node: true,
|
||||
sourceMapPath: options?.sourceMapPathServerAddOn,
|
||||
intern,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ import {InstalledPluginDetails} from 'flipper-common';
|
||||
import {getDefaultPlugins} from './getDefaultPlugins';
|
||||
import {buildDefaultPlugins} from './buildDefaultPlugins';
|
||||
|
||||
async function rebuildPlugin(pluginPath: string) {
|
||||
async function rebuildPlugin(pluginPath: string, intern: boolean) {
|
||||
try {
|
||||
await runBuild(pluginPath, true);
|
||||
await runBuild(pluginPath, true, intern);
|
||||
console.info(chalk.green('Rebuilt plugin'), pluginPath);
|
||||
} catch (e) {
|
||||
console.error(
|
||||
@@ -36,6 +36,7 @@ async function rebuildPlugin(pluginPath: string) {
|
||||
|
||||
export default async function startWatchPlugins(
|
||||
isInsidersBuild: boolean,
|
||||
intern: boolean,
|
||||
onChanged?: (
|
||||
changedPlugins: InstalledPluginDetails[],
|
||||
) => void | Promise<void>,
|
||||
@@ -74,7 +75,7 @@ export default async function startWatchPlugins(
|
||||
}
|
||||
dirPath = path.resolve(dirPath, '..');
|
||||
}
|
||||
await rebuildPlugin(dirPath);
|
||||
await rebuildPlugin(dirPath, intern);
|
||||
return dirPath;
|
||||
}),
|
||||
);
|
||||
@@ -85,7 +86,7 @@ export default async function startWatchPlugins(
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.message === 'REBUILD_ALL') {
|
||||
const defaultPlugins = await getDefaultPlugins(isInsidersBuild);
|
||||
await buildDefaultPlugins(defaultPlugins, true);
|
||||
await buildDefaultPlugins(defaultPlugins, true, intern);
|
||||
onChanged?.(defaultPlugins);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user