Generate source maps for releases
Summary: Allows for optional generation of source maps while building plugins. Caveat: This will leave a broken `//# sourceMappingURL` comment at the bottom. If you set it to `null`, as the documentation suggests, you will instead get an inlined source map in addition to the written one. Reviewed By: nikoant Differential Revision: D29265385 fbshipit-source-id: 1e21e49d2516ecc5909b086e7797736b298b86ab
This commit is contained in:
committed by
Facebook GitHub Bot
parent
640e06f130
commit
8df81d2dc0
@@ -33,7 +33,15 @@ async function getMetroDir() {
|
|||||||
return __dirname;
|
return __dirname;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function bundlePlugin(pluginDir: string, dev: boolean) {
|
type Options = {
|
||||||
|
sourceMapPath?: string | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function bundlePlugin(
|
||||||
|
pluginDir: string,
|
||||||
|
dev: boolean,
|
||||||
|
options?: Options,
|
||||||
|
) {
|
||||||
const stat = await fs.lstat(pluginDir);
|
const stat = await fs.lstat(pluginDir);
|
||||||
if (!stat.isDirectory()) {
|
if (!stat.isDirectory()) {
|
||||||
throw new Error(`Plugin source ${pluginDir} is not a directory.`);
|
throw new Error(`Plugin source ${pluginDir} is not a directory.`);
|
||||||
@@ -49,7 +57,6 @@ export default async function bundlePlugin(pluginDir: string, dev: boolean) {
|
|||||||
const out = path.resolve(pluginDir, plugin.main);
|
const out = path.resolve(pluginDir, plugin.main);
|
||||||
await fs.ensureDir(path.dirname(out));
|
await fs.ensureDir(path.dirname(out));
|
||||||
|
|
||||||
const sourceMapUrl = null; // inline source map
|
|
||||||
const baseConfig = await Metro.loadConfig();
|
const baseConfig = await Metro.loadConfig();
|
||||||
const config = Object.assign({}, baseConfig, {
|
const config = Object.assign({}, baseConfig, {
|
||||||
reporter: {update: () => {}},
|
reporter: {update: () => {}},
|
||||||
@@ -89,13 +96,23 @@ export default async function bundlePlugin(pluginDir: string, dev: boolean) {
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
const sourceMapUrl = out.replace(/\.js$/, '.map');
|
||||||
await Metro.runBuild(config, {
|
await Metro.runBuild(config, {
|
||||||
dev,
|
dev,
|
||||||
minify: !dev,
|
sourceMap: dev || !!options?.sourceMapPath,
|
||||||
resetCache: false,
|
|
||||||
sourceMap: dev,
|
|
||||||
sourceMapUrl,
|
sourceMapUrl,
|
||||||
|
minify: !dev,
|
||||||
|
inlineSourceMap: dev,
|
||||||
|
resetCache: false,
|
||||||
entry,
|
entry,
|
||||||
out,
|
out,
|
||||||
});
|
});
|
||||||
|
if (
|
||||||
|
options?.sourceMapPath &&
|
||||||
|
path.resolve(options.sourceMapPath) !== path.resolve(sourceMapUrl)
|
||||||
|
) {
|
||||||
|
console.log(`Moving plugin sourcemap to ${options.sourceMapPath}`);
|
||||||
|
await fs.ensureDir(path.dirname(options.sourceMapPath));
|
||||||
|
await fs.move(sourceMapUrl, options.sourceMapPath, {overwrite: true});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ const argv = yargs
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
alias: 'ou',
|
alias: 'ou',
|
||||||
},
|
},
|
||||||
|
'output-sourcemap': {
|
||||||
|
description: 'File path for the sourcemap to be written. Optional.',
|
||||||
|
type: 'string',
|
||||||
|
alias: 'os',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.help()
|
.help()
|
||||||
.strict()
|
.strict()
|
||||||
@@ -65,9 +70,10 @@ async function buildPlugin() {
|
|||||||
const outputFileArg = argv.output;
|
const outputFileArg = argv.output;
|
||||||
const outputUnpackedArg = argv['output-unpacked'];
|
const outputUnpackedArg = argv['output-unpacked'];
|
||||||
const minFlipperVersion = argv['min-flipper-version'];
|
const minFlipperVersion = argv['min-flipper-version'];
|
||||||
|
const outputSourcemapArg = argv['output-sourcemap'];
|
||||||
const packageJsonPath = path.join(pluginDir, 'package.json');
|
const packageJsonPath = path.join(pluginDir, 'package.json');
|
||||||
const packageJsonOverridePath = path.join(pluginDir, 'fb', 'package.json');
|
const packageJsonOverridePath = path.join(pluginDir, 'fb', 'package.json');
|
||||||
await runBuild(pluginDir, false);
|
await runBuild(pluginDir, false, {sourceMapPath: outputSourcemapArg});
|
||||||
const checksum = await computePackageChecksum(pluginDir);
|
const checksum = await computePackageChecksum(pluginDir);
|
||||||
if (previousChecksum !== checksum && argv.version) {
|
if (previousChecksum !== checksum && argv.version) {
|
||||||
console.log(`Plugin changed. Packaging new version ${argv.version}...`);
|
console.log(`Plugin changed. Packaging new version ${argv.version}...`);
|
||||||
|
|||||||
Reference in New Issue
Block a user