From 3fc2f0d35ae11b6701ac84b259bdf5e8c957f8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 27 Jan 2025 18:33:18 +0100 Subject: [PATCH] fix: add --no-border-checks flag to recover from source-map-explorer errors --- README.md | 35 ++++++++++++++------------- src/react-native-bundle-visualizer.js | 10 ++++---- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 992562d..413c805 100644 --- a/README.md +++ b/README.md @@ -38,29 +38,30 @@ npm install --save-dev react-native-bundle-visualizer ./node_modules/.bin/react- All command-line arguments are optional. By default a production build will be created for the `ios` platform. -| Option | Description | Example | -| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- | -| `platform` | Platform to build (default is **ios**) | `--platform ios` | -| `dev` | Dev or production build (default is **false**) | `--dev false` | -| `entry-file` | Entry-file (when omitted tries to auto-resolve it) | `--entry-file ./index.ios.js` | -| `bundle-output` | Output bundle-file (default is **tmp**) | `--bundle-output ./myapp.bundle` | -| `format` | Output format **html**, **json** or **tsv** (default is **html**) (see [source-map-explorer options][smeo]) | `--format json` | -| `only-mapped` | Exclude "unmapped" bytes from the output (default is **false**). This will result in total counts less than the file size. | `--only-mapped` | -| `verbose` | Dumps additional output to the console (default is **false**) | `--verbose` | -| `reset-cache` | Removes cached react-native files (default is **false**) | `--reset-cache` | -| `--expo` | Set this to true/ false based on whether using expo or not. For eg, set `--expo true` when using expo. Not required to pass this for react-native cli. (default is **false**) | `--expo false` | +| Option | Description | Example | +| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | +| `platform` | Platform to build (default is **ios**) | `--platform ios` | +| `dev` | Dev or production build (default is **false**) | `--dev false` | +| `entry-file` | Entry-file (when omitted tries to auto-resolve it) | `--entry-file ./index.ios.js` | +| `bundle-output` | Output bundle-file (default is **tmp**) | `--bundle-output ./myapp.bundle` | +| `format` | Output format **html**, **json** or **tsv** (default is **html**) (see [source-map-explorer options][smeo]) | `--format json` | +| `only-mapped` | Exclude "unmapped" bytes from the output (default is **false**). This will result in total counts less than the file size. | `--only-mapped` | +| `verbose` | Dumps additional output to the console (default is **false**) | `--verbose` | +| `reset-cache` | Removes cached react-native files (default is **false**) | `--reset-cache` | +| `--expo` | Set this to true/ false based on whether using expo or not. For eg, set `--expo true` when using expo. Not required to pass this for react-native cli. (default is **false**) | `--expo false` | +| `--no-border-checks` | Pass the same flag to the underlying `source-map-explorer` to disable invalid mapping column/line checks. | `--no-border-checks` | [smeo]: https://github.com/danvk/source-map-explorer#options ->Use [react-native-bundle-visualizer@2](https://github.com/IjzerenHein/react-native-bundle-visualizer/tree/v2) when targetting Expo SDK 40 or lower. +> Use [react-native-bundle-visualizer@2](https://github.com/IjzerenHein/react-native-bundle-visualizer/tree/v2) when targetting Expo SDK 40 or lower. ## Version compatibility -| Version | Comments | -| ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 3.x | Compatible with React-Native CLI bootstrapped projects and Expo SDK 41 or higher. | -| [2.x](https://github.com/IjzerenHein/react-native-bundle-visualizer/tree/v2) | Compatible with React-Native CLI bootstrapped projects and Expo SDK 40 or earlier. | -| [1.x](https://github.com/IjzerenHein/react-native-bundle-visualizer/tree/v1) | Uses the [Haul bundler](https://github.com/callstack/haul) instead instead of the Metro output. | +| Version | Comments | +| ---------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | +| 3.x | Compatible with React-Native CLI bootstrapped projects and Expo SDK 41 or higher. | +| [2.x](https://github.com/IjzerenHein/react-native-bundle-visualizer/tree/v2) | Compatible with React-Native CLI bootstrapped projects and Expo SDK 40 or earlier. | +| [1.x](https://github.com/IjzerenHein/react-native-bundle-visualizer/tree/v1) | Uses the [Haul bundler](https://github.com/callstack/haul) instead instead of the Metro output. | ## License diff --git a/src/react-native-bundle-visualizer.js b/src/react-native-bundle-visualizer.js index 1309bf6..7fcb99b 100755 --- a/src/react-native-bundle-visualizer.js +++ b/src/react-native-bundle-visualizer.js @@ -69,6 +69,7 @@ const bundleOutputSourceMap = bundleOutput + '.map'; const format = argv.format || 'html'; const bundleOutputExplorerFile = path.join(outDir, 'explorer.' + format); const onlyMapped = !!argv['only-mapped'] || false; +const borderChecks = argv['border-checks'] || false; // Make sure the temp dir exists fs.ensureDirSync(baseDir); @@ -96,7 +97,7 @@ const commands = [ '--sourcemap-output', bundleOutputSourceMap, '--minify', - isExpo + isExpo, ]; if (resetCache) { commands.push('--reset-cache'); @@ -147,6 +148,7 @@ bundlePromise }, { onlyMapped, + noBorderChecks: borderChecks === false, output: { format, filename: bundleOutputExplorerFile, @@ -181,7 +183,5 @@ bundlePromise // Open output file return open(bundleOutputExplorerFile); - }).catch(error => console.log( - chalk.red('=== error ==='), - error - )); + }) + .catch((error) => console.log(chalk.red('=== error ==='), error));