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
This commit is contained in:
Pascal Hartig
2022-05-20 04:04:06 -07:00
committed by Facebook GitHub Bot
parent 3dbd3f43e1
commit 02adfa79e9
2 changed files with 33 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ import {
getVersionNumber, getVersionNumber,
prepareDefaultPlugins, prepareDefaultPlugins,
prepareHeadlessPlugins, prepareHeadlessPlugins,
moveServerSourceMaps,
} from './build-utils'; } from './build-utils';
import {defaultPluginsDir, distDir, serverDir, staticDir} from './paths'; import {defaultPluginsDir, distDir, serverDir, staticDir} from './paths';
import isFB from './isFB'; 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', 'Directory with prepared list of default plugins which will be included into the Flipper distribution as "defaultPlugins" dir',
type: 'string', 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: { version: {
description: description:
'Unique build identifier to be used as the version patch part for the build', '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 copyStaticResources(dir, versionNumber);
await downloadIcons(path.join(dir, 'static')); await downloadIcons(path.join(dir, 'static'));
await buildBrowserBundle(path.join(dir, 'static'), false); await buildBrowserBundle(path.join(dir, 'static'), false);
await moveServerSourceMaps(dir, argv['source-map-dir']);
await modifyPackageManifest(dir, versionNumber, hgRevision, argv.channel); await modifyPackageManifest(dir, versionNumber, hgRevision, argv.channel);
const archive = await packNpmArchive(dir, versionNumber); const archive = await packNpmArchive(dir, versionNumber);
await runPostBuildAction(archive, dir); await runPostBuildAction(archive, dir);

View File

@@ -351,9 +351,35 @@ export async function moveSourceMaps(
} else { } else {
// If we don't move them out of the build folders, they'll get included in the ASAR // If we don't move them out of the build folders, they'll get included in the ASAR
// which we don't want. // which we don't want.
console.log(`⏭ Removing source maps.`);
await fs.remove(mainBundleMap); await fs.remove(mainBundleMap);
await fs.remove(rendererBundleMap); 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.`); console.log(`⏭ Removing source maps.`);
await fs.remove(mainBundleMap);
await fs.remove(rendererBundleMap);
} }
} }