Files
react-native/packages/react-native/scripts/compose-source-maps.js
Tim Yung e7a9322bdf RN: Flowify packages/react-native-scripts (#51671)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51671

Adds `flow` (or `noflow`) to all files in this directory and ensures that Flow succeeds (by adding type annotations, using minor refactors, or suppressing errors due to intentionally dynamic logic).

This will help improve type safety when making changes both in these files as well as files that these depend on.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D75581879

fbshipit-source-id: 6dcd8cc55d0021973eeae2670c1ebceb6d69fa8f
2025-05-29 07:52:38 -07:00

68 lines
1.8 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
const fs = require('fs');
const {composeSourceMaps} = require('metro-source-map');
const argv = process.argv.slice(2);
let outputPath /*: ?string */;
for (let i = 0; i < argv.length; ) {
if (argv[i] === '-o') {
outputPath = argv[i + 1];
argv.splice(i, 2);
continue;
}
++i;
}
if (!argv.length) {
process.stderr.write(
'Usage: node compose-source-maps.js <packager_sourcemap> <compiler_sourcemap> [-o output_file]\n',
);
process.exitCode = -1;
} else {
const [packagerSourcemapPath, compilerSourcemapPath] = argv.splice(0, 2);
const packagerSourcemap = JSON.parse(
fs.readFileSync(packagerSourcemapPath, 'utf8'),
);
const compilerSourcemap = JSON.parse(
fs.readFileSync(compilerSourcemapPath, 'utf8'),
);
if (
packagerSourcemap.x_facebook_offsets != null ||
compilerSourcemap.x_facebook_offsets != null
) {
throw new Error(
'Random Access Bundle (RAM) format is not supported by this tool; ' +
'it cannot process the `x_facebook_offsets` field provided ' +
'in the base and/or target source map(s)',
);
}
if (compilerSourcemap.x_facebook_segments != null) {
throw new Error(
'This tool cannot process the `x_facebook_segments` field provided ' +
'in the target source map.',
);
}
const composedMapJSON = JSON.stringify(
composeSourceMaps([packagerSourcemap, compilerSourcemap]),
);
if (outputPath != null) {
fs.writeFileSync(outputPath, composedMapJSON, 'utf8');
} else {
process.stdout.write(composedMapJSON);
}
}