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

@@ -9,11 +9,14 @@
import Metro from 'metro';
import tmp from 'tmp';
import os from 'os';
import path from 'path';
import fs from 'fs-extra';
import {spawn} from 'promisify-child-process';
import {getWatchFolders, runBuild} from 'flipper-pkg-lib';
import {
getWatchFolders,
runBuild,
stripSourceMapComment,
} from 'flipper-pkg-lib';
import getAppWatchFolders from './get-app-watch-folders';
import {
getSourcePlugins,
@@ -161,16 +164,6 @@ async function buildDefaultPlugins(defaultPlugins: InstalledPluginDetails[]) {
}
}
// TODO: Share this with the runBuild util in pkg-lib.
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));
}
}
const minifierConfig = {
minifierPath: require.resolve('metro-minify-terser'),
minifierConfig: {