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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (!stat.isDirectory()) {
|
||||
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);
|
||||
await fs.ensureDir(path.dirname(out));
|
||||
|
||||
const sourceMapUrl = null; // inline source map
|
||||
const baseConfig = await Metro.loadConfig();
|
||||
const config = Object.assign({}, baseConfig, {
|
||||
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, {
|
||||
dev,
|
||||
minify: !dev,
|
||||
resetCache: false,
|
||||
sourceMap: dev,
|
||||
sourceMap: dev || !!options?.sourceMapPath,
|
||||
sourceMapUrl,
|
||||
minify: !dev,
|
||||
inlineSourceMap: dev,
|
||||
resetCache: false,
|
||||
entry,
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user