Add source map copying for plugins
Reviewed By: nikoant Differential Revision: D39576201 fbshipit-source-id: cd6b11bdb0a4c89e2f84d1c4772f08acc4b86418
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9fc9d6f9b5
commit
7c66a83328
@@ -18,9 +18,17 @@ interface RunBuildConfig {
|
||||
out: string;
|
||||
dev: boolean;
|
||||
node?: boolean;
|
||||
sourceMapPath?: string;
|
||||
}
|
||||
|
||||
async function runBuild({pluginDir, entry, out, dev, node}: RunBuildConfig) {
|
||||
async function runBuild({
|
||||
pluginDir,
|
||||
entry,
|
||||
out,
|
||||
dev,
|
||||
node,
|
||||
sourceMapPath,
|
||||
}: RunBuildConfig) {
|
||||
await build({
|
||||
entryPoints: [path.join(pluginDir, entry)],
|
||||
bundle: true,
|
||||
@@ -45,9 +53,28 @@ async function runBuild({pluginDir, entry, out, dev, node}: RunBuildConfig) {
|
||||
sourcemap: 'external',
|
||||
minify: !dev,
|
||||
});
|
||||
|
||||
const sourceMapUrl = `${out}.map`;
|
||||
if (
|
||||
sourceMapPath &&
|
||||
path.resolve(sourceMapPath) !== path.resolve(sourceMapUrl)
|
||||
) {
|
||||
console.info(`Moving plugin sourcemap to ${sourceMapPath}`);
|
||||
await fs.ensureDir(path.dirname(sourceMapPath));
|
||||
await fs.move(sourceMapUrl, sourceMapPath, {overwrite: true});
|
||||
}
|
||||
}
|
||||
|
||||
export default async function bundlePlugin(pluginDir: string, dev: boolean) {
|
||||
type Options = {
|
||||
sourceMapPath?: string;
|
||||
sourceMapPathServerAddOn?: string;
|
||||
};
|
||||
|
||||
export default async function bundlePlugin(
|
||||
pluginDir: string,
|
||||
dev: boolean,
|
||||
options?: Options,
|
||||
) {
|
||||
const stat = await fs.lstat(pluginDir);
|
||||
if (!stat.isDirectory()) {
|
||||
throw new Error(`Plugin source ${pluginDir} is not a directory.`);
|
||||
@@ -75,6 +102,7 @@ export default async function bundlePlugin(pluginDir: string, dev: boolean) {
|
||||
entry: plugin.source,
|
||||
out: plugin.entry,
|
||||
dev,
|
||||
sourceMapPath: options?.sourceMapPath,
|
||||
});
|
||||
|
||||
if (
|
||||
@@ -89,6 +117,7 @@ export default async function bundlePlugin(pluginDir: string, dev: boolean) {
|
||||
out: plugin.serverAddOnEntry,
|
||||
dev,
|
||||
node: true,
|
||||
sourceMapPath: options?.sourceMapPathServerAddOn,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,17 @@ const argv = yargs
|
||||
type: 'string',
|
||||
alias: 'ou',
|
||||
},
|
||||
'output-sourcemap': {
|
||||
description: 'File path for the sourcemap to be written. Optional.',
|
||||
type: 'string',
|
||||
alias: 'os',
|
||||
},
|
||||
'output-sourcemap-server-addon': {
|
||||
description:
|
||||
'File path for the server add-on sourcemap to be written. Optional.',
|
||||
type: 'string',
|
||||
alias: 'os',
|
||||
},
|
||||
})
|
||||
.help()
|
||||
.parse(process.argv.slice(1));
|
||||
@@ -65,9 +76,14 @@ async function buildPlugin() {
|
||||
const outputFileArg = argv.output;
|
||||
const outputUnpackedArg = argv['output-unpacked'];
|
||||
const minFlipperVersion = argv['min-flipper-version'];
|
||||
const outputSourcemapArg = argv['output-sourcemap'];
|
||||
const outputSourcemapServerAddOnArg = argv['output-sourcemap-server-addon'];
|
||||
const packageJsonPath = path.join(pluginDir, 'package.json');
|
||||
const packageJsonOverridePath = path.join(pluginDir, 'fb', 'package.json');
|
||||
await runBuild(pluginDir, false);
|
||||
await runBuild(pluginDir, false, {
|
||||
sourceMapPath: outputSourcemapArg,
|
||||
sourceMapPathServerAddOn: outputSourcemapServerAddOnArg,
|
||||
});
|
||||
const checksum = await computePackageChecksum(pluginDir);
|
||||
if (previousChecksum !== checksum && argv.version) {
|
||||
console.log(`Plugin changed. Packaging new version ${argv.version}...`);
|
||||
|
||||
Reference in New Issue
Block a user