Refactor out strip source map fn

Summary: Remove the duplicate function and centralise it as nikoant suggested.

Reviewed By: fabiomassimo

Differential Revision: D29548480

fbshipit-source-id: 3e931cc88198415017c557c6b7c81cb35c3f22c9
This commit is contained in:
Pascal Hartig
2021-07-05 06:36:20 -07:00
committed by Facebook GitHub Bot
parent 04616ad647
commit 0e1f8e45ec
4 changed files with 30 additions and 24 deletions

View File

@@ -13,6 +13,7 @@ import path from 'path';
import fs from 'fs-extra';
import {getInstalledPluginDetails} from 'flipper-plugin-lib';
import {FileStore} from 'metro-cache';
import stripSourceMapComment from './stripSourceMap';
import os from 'os';
let metroDir: string | undefined;
@@ -37,18 +38,6 @@ type Options = {
sourceMapPath?: string | undefined;
};
// Metro erroneously adds source map comments to the bottom of the file
// which break checksums on CI environments where paths change and are generally
// undesired. We manually strip the comment here and write the file back.
async function stripSourceMapComment(out: string) {
const lines = (await fs.readFile(out, 'utf-8')).split(os.EOL);
const lastLine = lines[lines.length - 1];
if (lastLine.startsWith('//# sourceMappingURL=')) {
console.log(`Updating ${out} to remove sourceMapURL= comment.`);
await fs.writeFile(out, lines.slice(0, lines.length - 1).join(os.EOL));
}
}
export default async function bundlePlugin(
pluginDir: string,
dev: boolean,