From 02adfa79e9810ca4ef8e93668229741859673e6e Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Fri, 20 May 2022 04:04:06 -0700 Subject: [PATCH] Add sourcemap support to server build Summary: Provide the same build parameters as for the main build and move the two bundles to a folder where we can pick them up. For consistency, I'm keeping the naming scheme with the main build. Reviewed By: antonk52 Differential Revision: D36521046 fbshipit-source-id: 9ea992d6e5dc299d88083d751ca8e84eadb1430b --- .../scripts/build-flipper-server-release.tsx | 7 +++++ desktop/scripts/build-utils.tsx | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/desktop/scripts/build-flipper-server-release.tsx b/desktop/scripts/build-flipper-server-release.tsx index 046537a4c..42d946157 100644 --- a/desktop/scripts/build-flipper-server-release.tsx +++ b/desktop/scripts/build-flipper-server-release.tsx @@ -17,6 +17,7 @@ import { getVersionNumber, prepareDefaultPlugins, prepareHeadlessPlugins, + moveServerSourceMaps, } from './build-utils'; import {defaultPluginsDir, distDir, serverDir, staticDir} from './paths'; import isFB from './isFB'; @@ -98,6 +99,11 @@ const argv = yargs 'Directory with prepared list of default plugins which will be included into the Flipper distribution as "defaultPlugins" dir', type: 'string', }, + 'source-map-dir': { + describe: + 'Directory to write the main.bundle.map and bundle.map files for the main and render bundle sourcemaps, respectively', + type: 'string', + }, version: { description: 'Unique build identifier to be used as the version patch part for the build', @@ -335,6 +341,7 @@ async function buildServerRelease() { await copyStaticResources(dir, versionNumber); await downloadIcons(path.join(dir, 'static')); await buildBrowserBundle(path.join(dir, 'static'), false); + await moveServerSourceMaps(dir, argv['source-map-dir']); await modifyPackageManifest(dir, versionNumber, hgRevision, argv.channel); const archive = await packNpmArchive(dir, versionNumber); await runPostBuildAction(archive, dir); diff --git a/desktop/scripts/build-utils.tsx b/desktop/scripts/build-utils.tsx index d723f85db..6f0ea6771 100644 --- a/desktop/scripts/build-utils.tsx +++ b/desktop/scripts/build-utils.tsx @@ -351,9 +351,35 @@ export async function moveSourceMaps( } else { // If we don't move them out of the build folders, they'll get included in the ASAR // which we don't want. + console.log(`⏭ Removing source maps.`); await fs.remove(mainBundleMap); await fs.remove(rendererBundleMap); + } +} + +export async function moveServerSourceMaps( + buildFolder: string, + sourceMapFolder: string | undefined, +) { + console.log(`⚙️ Moving server source maps...`); + const mainBundleMap = path.join(buildFolder, 'dist', 'index.map'); + const rendererBundleMap = path.join(buildFolder, 'static', 'bundle.map'); + if (sourceMapFolder) { + await fs.ensureDir(sourceMapFolder); + await fs.move(mainBundleMap, path.join(sourceMapFolder, 'bundle.map'), { + overwrite: true, + }); + await fs.move( + rendererBundleMap, + path.join(sourceMapFolder, 'main.bundle.map'), + {overwrite: true}, + ); + console.log(`✅ Moved to ${sourceMapFolder}.`); + } else { + // Removing so we don't bundle them up as part of the release. console.log(`⏭ Removing source maps.`); + await fs.remove(mainBundleMap); + await fs.remove(rendererBundleMap); } }