diff --git a/desktop/pkg-lib/src/index.ts b/desktop/pkg-lib/src/index.ts index 41282807c..6ffd2e0b2 100644 --- a/desktop/pkg-lib/src/index.ts +++ b/desktop/pkg-lib/src/index.ts @@ -10,3 +10,4 @@ export {default as runBuild} from './runBuild'; export {default as getWatchFolders} from './getWatchFolders'; export {default as computePackageChecksum} from './computePackageChecksum'; +export {default as stripSourceMapComment} from './stripSourceMap'; diff --git a/desktop/pkg-lib/src/runBuild.ts b/desktop/pkg-lib/src/runBuild.ts index ff47871ce..53baeaf1d 100644 --- a/desktop/pkg-lib/src/runBuild.ts +++ b/desktop/pkg-lib/src/runBuild.ts @@ -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, diff --git a/desktop/pkg-lib/src/stripSourceMap.ts b/desktop/pkg-lib/src/stripSourceMap.ts new file mode 100644 index 000000000..7ff8d9c2a --- /dev/null +++ b/desktop/pkg-lib/src/stripSourceMap.ts @@ -0,0 +1,23 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import os from 'os'; +import fs from 'fs-extra'; + +// 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. +export default 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)); + } +} diff --git a/desktop/scripts/build-utils.ts b/desktop/scripts/build-utils.ts index 686b0ff1a..28a3fd43e 100644 --- a/desktop/scripts/build-utils.ts +++ b/desktop/scripts/build-utils.ts @@ -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: {