diff --git a/packages/buck-worker-tool/package.json b/packages/buck-worker-tool/package.json index 1e30f8aa3f..a7108108b0 100644 --- a/packages/buck-worker-tool/package.json +++ b/packages/buck-worker-tool/package.json @@ -1,6 +1,6 @@ { "name": "buck-worker-tool", - "version": "0.85.0", + "version": "0.86.0", "description": "Implementation of the Buck worker protocol for Node.js.", "license": "MIT", "repository": { diff --git a/packages/metro-babel-register/package.json b/packages/metro-babel-register/package.json index 6173f37e4f..67d97ecafe 100644 --- a/packages/metro-babel-register/package.json +++ b/packages/metro-babel-register/package.json @@ -1,6 +1,6 @@ { "name": "metro-babel-register", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 babel/register configuration for Metro.", "main": "src/babel-register.js", "exports": { diff --git a/packages/metro-babel-transformer/package.json b/packages/metro-babel-transformer/package.json index d4c52cd91a..fffbf5c592 100644 --- a/packages/metro-babel-transformer/package.json +++ b/packages/metro-babel-transformer/package.json @@ -1,6 +1,6 @@ { "name": "metro-babel-transformer", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Base Babel transformer for Metro.", "main": "src/index.js", "exports": { @@ -26,7 +26,7 @@ "@babel/core": "^7.25.2", "flow-enums-runtime": "^0.0.6", "hermes-parser": "0.36.1", - "metro-cache-key": "0.85.0", + "metro-cache-key": "0.86.0", "nullthrows": "^1.1.1" }, "engines": { diff --git a/packages/metro-cache-key/package.json b/packages/metro-cache-key/package.json index 092dcd1c07..4a417bd35f 100644 --- a/packages/metro-cache-key/package.json +++ b/packages/metro-cache-key/package.json @@ -1,6 +1,6 @@ { "name": "metro-cache-key", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Cache key utility.", "main": "src/index.js", "exports": { diff --git a/packages/metro-cache/package.json b/packages/metro-cache/package.json index e40a20af59..da91f88904 100644 --- a/packages/metro-cache/package.json +++ b/packages/metro-cache/package.json @@ -1,6 +1,6 @@ { "name": "metro-cache", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Cache layers for Metro.", "main": "src/index.js", "exports": { @@ -21,7 +21,7 @@ "exponential-backoff": "^3.1.1", "flow-enums-runtime": "^0.0.6", "https-proxy-agent": "^7.0.5", - "metro-core": "0.85.0" + "metro-core": "0.86.0" }, "devDependencies": { "memfs": "^4.38.2" diff --git a/packages/metro-config/package.json b/packages/metro-config/package.json index 551d89e3ef..8050593f86 100644 --- a/packages/metro-config/package.json +++ b/packages/metro-config/package.json @@ -1,6 +1,6 @@ { "name": "metro-config", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Config parser for Metro.", "main": "src/index.js", "exports": { @@ -22,14 +22,14 @@ "connect": "^3.6.5", "flow-enums-runtime": "^0.0.6", "jest-validate": "^29.7.0", - "metro": "0.85.0", - "metro-cache": "0.85.0", - "metro-core": "0.85.0", - "metro-runtime": "0.85.0" + "metro": "0.86.0", + "metro-cache": "0.86.0", + "metro-core": "0.86.0", + "metro-runtime": "0.86.0" }, "devDependencies": { "@types/connect": "^3.4.35", - "metro-babel-register": "0.85.0", + "metro-babel-register": "0.86.0", "pretty-format": "^29.7.0" }, "engines": { diff --git a/packages/metro-config/src/defaults/index.js b/packages/metro-config/src/defaults/index.js index 8ee4308daf..2d7df87df2 100644 --- a/packages/metro-config/src/defaults/index.js +++ b/packages/metro-config/src/defaults/index.js @@ -70,7 +70,6 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({ customSerializer: null, isThirdPartyModule: module => /(?:^|[/\\])node_modules[/\\]/.test(module.path), - unstable_allowIndexMap: false, }, server: { @@ -136,7 +135,6 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({ unstable_disableNormalizePseudoGlobals: false, unstable_renameRequire: true, unstable_compactOutput: false, - unstable_compactSourceMaps: false, unstable_memoizeInlineRequires: false, unstable_workerThreads: false, }, diff --git a/packages/metro-config/src/types.js b/packages/metro-config/src/types.js index 0d1a3c9475..88733bc474 100644 --- a/packages/metro-config/src/types.js +++ b/packages/metro-config/src/types.js @@ -146,13 +146,6 @@ type SerializerConfigT = { polyfillModuleNames: ReadonlyArray, processModuleFilter: (modules: Module<>) => boolean, isThirdPartyModule: (module: Readonly<{path: string, ...}>) => boolean, - // When source maps are stored compactly as VLQ (see - // `transformer.unstable_compactSourceMaps`), allow the whole-bundle map to be - // emitted as an index map (sectioned) that passes the VLQ through verbatim, - // instead of decoding + re-encoding into a flat map. Cheaper to serialize, but - // requires consumers that understand index source maps. No-op unless compact - // VLQ maps are actually present, and ignored when a `customSerializer` is set. - unstable_allowIndexMap: boolean, }; type TransformerConfigT = { diff --git a/packages/metro-config/types/types.d.ts b/packages/metro-config/types/types.d.ts index cbdf1bfda6..c8aed9b7a9 100644 --- a/packages/metro-config/types/types.d.ts +++ b/packages/metro-config/types/types.d.ts @@ -6,7 +6,7 @@ * * @noformat * @oncall react_native - * @generated SignedSource<> + * @generated SignedSource<> * * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js * Original file: packages/metro-config/src/types.js @@ -139,7 +139,6 @@ type SerializerConfigT = { polyfillModuleNames: ReadonlyArray; processModuleFilter: (modules: Module) => boolean; isThirdPartyModule: (module: Readonly<{path: string}>) => boolean; - unstable_allowIndexMap: boolean; }; type TransformerConfigT = Omit< JsTransformerConfig, diff --git a/packages/metro-core/package.json b/packages/metro-core/package.json index df4b784747..8831af7d1d 100644 --- a/packages/metro-core/package.json +++ b/packages/metro-core/package.json @@ -1,6 +1,6 @@ { "name": "metro-core", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Metro's core package.", "main": "src/index.js", "exports": { @@ -20,7 +20,7 @@ "dependencies": { "flow-enums-runtime": "^0.0.6", "lodash.throttle": "^4.1.1", - "metro-resolver": "0.85.0" + "metro-resolver": "0.86.0" }, "license": "MIT", "engines": { diff --git a/packages/metro-file-map/package.json b/packages/metro-file-map/package.json index 452d830ae7..d8da491ab6 100644 --- a/packages/metro-file-map/package.json +++ b/packages/metro-file-map/package.json @@ -1,6 +1,6 @@ { "name": "metro-file-map", - "version": "0.85.0", + "version": "0.86.0", "description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro", "main": "src/index.js", "exports": { diff --git a/packages/metro-minify-terser/package.json b/packages/metro-minify-terser/package.json index da05be6846..40fdfd1b4d 100644 --- a/packages/metro-minify-terser/package.json +++ b/packages/metro-minify-terser/package.json @@ -1,6 +1,6 @@ { "name": "metro-minify-terser", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Minifier for Metro based on Terser.", "main": "src/index.js", "exports": { diff --git a/packages/metro-resolver/package.json b/packages/metro-resolver/package.json index 57cd772ff6..362c8297d5 100644 --- a/packages/metro-resolver/package.json +++ b/packages/metro-resolver/package.json @@ -1,6 +1,6 @@ { "name": "metro-resolver", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Implementation of Metro's resolution logic.", "main": "src/index.js", "exports": { @@ -22,7 +22,7 @@ "node": "^22.13.0 || ^24.3.0 || >= 26.0.0" }, "devDependencies": { - "metro": "0.85.0" + "metro": "0.86.0" }, "dependencies": { "flow-enums-runtime": "^0.0.6" diff --git a/packages/metro-runtime/package.json b/packages/metro-runtime/package.json index da140b80da..76b913d014 100644 --- a/packages/metro-runtime/package.json +++ b/packages/metro-runtime/package.json @@ -1,6 +1,6 @@ { "name": "metro-runtime", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Module required for evaluating Metro bundles.", "exports": { "./package.json": "./package.json", diff --git a/packages/metro-source-map/package.json b/packages/metro-source-map/package.json index 5a4c394344..887acef91b 100644 --- a/packages/metro-source-map/package.json +++ b/packages/metro-source-map/package.json @@ -1,6 +1,6 @@ { "name": "metro-source-map", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Source map generator for Metro.", "main": "src/source-map.js", "exports": { @@ -22,9 +22,9 @@ "@babel/types": "^7.29.0", "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", - "metro-symbolicate": "0.85.0", + "metro-symbolicate": "0.86.0", "nullthrows": "^1.1.1", - "ob1": "0.85.0", + "ob1": "0.86.0", "source-map": "^0.5.6", "vlq": "^1.0.0" }, diff --git a/packages/metro-symbolicate/package.json b/packages/metro-symbolicate/package.json index 9dcdc578cc..e64a33f7d5 100644 --- a/packages/metro-symbolicate/package.json +++ b/packages/metro-symbolicate/package.json @@ -1,6 +1,6 @@ { "name": "metro-symbolicate", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 A tool to find the source location from JS bundles and stack traces.", "license": "MIT", "main": "./src/index.js", @@ -25,7 +25,7 @@ "dependencies": { "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", - "metro-source-map": "0.85.0", + "metro-source-map": "0.86.0", "nullthrows": "^1.1.1", "source-map": "^0.5.6", "vlq": "^1.0.0" diff --git a/packages/metro-transform-plugins/package.json b/packages/metro-transform-plugins/package.json index 1ae3015dd0..1fea8a8dcb 100644 --- a/packages/metro-transform-plugins/package.json +++ b/packages/metro-transform-plugins/package.json @@ -1,6 +1,6 @@ { "name": "metro-transform-plugins", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Transform plugins for Metro.", "main": "src/index.js", "exports": { @@ -33,7 +33,7 @@ "@babel/plugin-transform-modules-commonjs": "^7.24.8", "@babel/types": "^7.29.0", "babel-plugin-tester": "^6.0.1", - "metro": "0.85.0" + "metro": "0.86.0" }, "engines": { "node": "^22.13.0 || ^24.3.0 || >= 26.0.0" diff --git a/packages/metro-transform-worker/package.json b/packages/metro-transform-worker/package.json index f131829836..806eca4598 100644 --- a/packages/metro-transform-worker/package.json +++ b/packages/metro-transform-worker/package.json @@ -1,6 +1,6 @@ { "name": "metro-transform-worker", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 Transform worker for Metro.", "main": "src/index.js", "exports": { @@ -24,13 +24,13 @@ "@babel/parser": "^7.29.0", "@babel/types": "^7.29.0", "flow-enums-runtime": "^0.0.6", - "metro": "0.85.0", - "metro-babel-transformer": "0.85.0", - "metro-cache": "0.85.0", - "metro-cache-key": "0.85.0", - "metro-minify-terser": "0.85.0", - "metro-source-map": "0.85.0", - "metro-transform-plugins": "0.85.0", + "metro": "0.86.0", + "metro-babel-transformer": "0.86.0", + "metro-cache": "0.86.0", + "metro-cache-key": "0.86.0", + "metro-minify-terser": "0.86.0", + "metro-source-map": "0.86.0", + "metro-transform-plugins": "0.86.0", "nullthrows": "^1.1.1" }, "devDependencies": { diff --git a/packages/metro-transform-worker/src/__tests__/__snapshots__/index-test.js.snap b/packages/metro-transform-worker/src/__tests__/__snapshots__/index-test.js.snap index 1560d318fb..6d2836c92e 100644 --- a/packages/metro-transform-worker/src/__tests__/__snapshots__/index-test.js.snap +++ b/packages/metro-transform-worker/src/__tests__/__snapshots__/index-test.js.snap @@ -3,260 +3,19 @@ exports[`reports filename when encountering unsupported dynamic dependency 1`] = `"local/file.js:Invalid call at line 3: require(a)"`; exports[`transforms a module with dependencies 1`] = ` -Array [ - Array [ - 2, - 2, - 1, - 0, - ], - Array [ - 2, - 14, - 1, - 12, - ], - Array [ - 4, - 2, - 1, - 13, - ], - Array [ - 4, - 6, - 1, - 13, +Object { + "mappings": ";EAAA,YAAY;;EAAC,IAAAA,sBAAA,GAAAC,WAAA,CAAAC,cAAA;EAIb,IAAAC,EAAA,GAAAH,sBAAA,CAAAC,WAAA,CAAAC,cAAA;EAHAE,WAAO,CAAAF,cAAA,UAAM,CAAC;EACdG,SAAS,CAACC,IAAI,CAAC;EACf,IAAMC,CAAC,GAAGH,WAAO,CAAAF,cAAA,QAAI,CAAC;AAAC,G", + "names": Array [ "_interopRequireDefault", - ], - Array [ - 4, - 28, - 1, - 13, - ], - Array [ - 4, - 31, - 1, - 13, "_$$_REQUIRE", - ], - Array [ - 4, - 42, - 1, - 13, - ], - Array [ - 4, - 43, - 1, - 13, "_dependencyMap", - ], - Array [ - 4, - 57, - 1, - 13, - ], - Array [ - 5, - 2, - 5, - 0, - ], - Array [ - 5, - 6, - 5, - 0, "_c", - ], - Array [ - 5, - 8, - 5, - 0, - ], - Array [ - 5, - 11, - 5, - 0, - "_interopRequireDefault", - ], - Array [ - 5, - 33, - 5, - 0, - ], - Array [ - 5, - 34, - 5, - 0, - "_$$_REQUIRE", - ], - Array [ - 5, - 45, - 5, - 0, - ], - Array [ - 5, - 46, - 5, - 0, - "_dependencyMap", - ], - Array [ - 5, - 60, - 5, - 0, - ], - Array [ - 6, - 2, - 2, - 0, "require", - ], - Array [ - 6, - 13, - 2, - 7, - ], - Array [ - 6, - 14, - 2, - 7, - "_dependencyMap", - ], - Array [ - 6, - 28, - 2, - 7, - ], - Array [ - 6, - 38, - 2, - 13, - ], - Array [ - 6, - 39, - 2, - 14, - ], - Array [ - 7, - 2, - 3, - 0, "arbitrary", - ], - Array [ - 7, - 11, - 3, - 9, - ], - Array [ - 7, - 12, - 3, - 10, "code", - ], - Array [ - 7, - 16, - 3, - 14, - ], - Array [ - 7, - 17, - 3, - 15, - ], - Array [ - 8, - 2, - 4, - 0, - ], - Array [ - 8, - 6, - 4, - 6, "b", ], - Array [ - 8, - 7, - 4, - 7, - ], - Array [ - 8, - 10, - 4, - 10, - "require", - ], - Array [ - 8, - 21, - 4, - 17, - ], - Array [ - 8, - 22, - 4, - 17, - "_dependencyMap", - ], - Array [ - 8, - 36, - 4, - 17, - ], - Array [ - 8, - 44, - 4, - 21, - ], - Array [ - 8, - 45, - 4, - 22, - ], - Array [ - 9, - 0, - 4, - 23, - ], - Array [ - 9, - 3, - ], -] +} `; exports[`transforms a module with dependencies 2`] = ` @@ -269,50 +28,13 @@ Object { `; exports[`transforms a simple module 1`] = ` -Array [ - Array [ - 2, - 2, - 1, - 0, +Object { + "mappings": ";EAAAA,SAAS,CAACC,IAAI,CAAC;AAAA,G", + "names": Array [ "arbitrary", - ], - Array [ - 2, - 11, - 1, - 9, - ], - Array [ - 2, - 12, - 1, - 10, "code", ], - Array [ - 2, - 16, - 1, - 14, - ], - Array [ - 2, - 17, - 1, - 15, - ], - Array [ - 3, - 0, - 1, - 15, - ], - Array [ - 3, - 3, - ], -] +} `; exports[`transforms a simple module 2`] = ` @@ -325,128 +47,16 @@ Object { `; exports[`transforms a simple script 1`] = ` -Array [ - Array [ - 2, - 2, - 1, - 0, +Object { + "mappings": ";EAAAA,mBAAmB,CAACC,IAAI,CAAC;AAAA,UAAAC,UAAA,mBAAAA,UAAA,UAAAC,MAAA,mBAAAA,MAAA,UAAAC,MAAA,mBAAAA,MAAA,S", + "names": Array [ "someReallyArbitrary", - ], - Array [ - 2, - 21, - 1, - 19, - ], - Array [ - 2, - 22, - 1, - 20, "code", - ], - Array [ - 2, - 26, - 1, - 24, - ], - Array [ - 2, - 27, - 1, - 25, - ], - Array [ - 3, - 0, - 1, - 25, - ], - Array [ - 3, - 10, - 1, - 25, "globalThis", - ], - Array [ - 3, - 20, - 1, - 25, - ], - Array [ - 3, - 39, - 1, - 25, - "globalThis", - ], - Array [ - 3, - 49, - 1, - 25, - ], - Array [ - 3, - 59, - 1, - 25, - "global", - ], - Array [ - 3, - 65, - 1, - 25, - ], - Array [ - 3, - 84, - 1, - 25, "global", - ], - Array [ - 3, - 90, - 1, - 25, - ], - Array [ - 3, - 100, - 1, - 25, "window", ], - Array [ - 3, - 106, - 1, - 25, - ], - Array [ - 3, - 125, - 1, - 25, - "window", - ], - Array [ - 3, - 131, - 1, - 25, - ], - Array [ - 3, - 140, - ], -] +} `; exports[`transforms a simple script 2`] = ` @@ -508,63 +118,14 @@ exports[`transforms async generators 1`] = ` `; exports[`transforms import/export syntax when experimental flag is on 1`] = ` -Array [ - Array [ - 4, - 2, - 1, - 0, - ], - Array [ - 4, - 6, - 1, - 7, +Object { + "mappings": ";;;EAAA,IAAOA,CAAC,GAAAC,kBAAA,CAAAC,cAAA;AAAY,G", + "names": Array [ "c", - ], - Array [ - 4, - 7, - 1, - 8, - ], - Array [ - 4, - 10, - 1, - 8, "_$$_IMPORT_DEFAULT", - ], - Array [ - 4, - 28, - 1, - 8, - ], - Array [ - 4, - 29, - 1, - 8, "_dependencyMap", ], - Array [ - 4, - 43, - 1, - 8, - ], - Array [ - 5, - 0, - 1, - 20, - ], - Array [ - 5, - 3, - ], -] +} `; exports[`transforms import/export syntax when experimental flag is on 2`] = ` diff --git a/packages/metro-transform-worker/src/__tests__/index-test.js b/packages/metro-transform-worker/src/__tests__/index-test.js index b55466d83c..9c1c53c45f 100644 --- a/packages/metro-transform-worker/src/__tests__/index-test.js +++ b/packages/metro-transform-worker/src/__tests__/index-test.js @@ -32,8 +32,6 @@ import type {JsTransformerConfig, JsTransformOptions} from '../index'; import typeof * as TransformerType from '../index'; import typeof FSType from 'fs'; -import {vlqMapFromTuples} from 'metro-source-map'; - const {Buffer} = require('buffer'); const path = require('path'); @@ -193,7 +191,9 @@ test('transforms an es module with asyncToGenerator', async () => { expect(result.output[0].type).toBe('js/module'); expect(result.output[0].data.code).toMatchSnapshot(); - expect(result.output[0].data.map).toHaveLength(34); + const map = result.output[0].data.map; + expect(typeof map.mappings).toBe('string'); + expect(map.mappings.length).toBeGreaterThan(0); expect(result.output[0].data.functionMap).toMatchSnapshot(); expect(result.dependencies).toEqual([ { @@ -411,7 +411,7 @@ test('uses a reserved dependency map name and prevents it from being minified', `); }); -test('unstable_compactSourceMaps emits a VlqMap byte-identical to the tuple path', async () => { +test('emits a compact VlqMap for both the non-minified and minified paths', async () => { const source = Buffer.from( [ 'function foo(aaa, bbb) {', @@ -426,39 +426,34 @@ test('unstable_compactSourceMaps emits a VlqMap byte-identical to the tuple path 'utf8', ); - // Default path stores decoded tuples (line-counted + terminated). - const tupleResult = await Transformer.transform( - {...baseConfig, unstable_compactSourceMaps: false}, + // Non-minified path encodes VLQ straight from Babel's decoded map. + const devResult = await Transformer.transform( + baseConfig, '/root', 'local/file.js', source, {...baseTransformOptions, experimentalImportSupport: true}, ); - // Compact path encodes VLQ straight from Babel's decoded map (no tuples). - const vlqResult = await Transformer.transform( - {...baseConfig, unstable_compactSourceMaps: true}, + // Minified path re-encodes the minifier's tuple output to VLQ. + const minifiedResult = await Transformer.transform( + baseConfig, '/root', 'local/file.js', source, - {...baseTransformOptions, experimentalImportSupport: true}, - ); - - const tupleMap = tupleResult.output[0].data.map; - const vlqMap = vlqResult.output[0].data.map; - - // Generated code and line count are unaffected by map storage. - expect(vlqResult.output[0].data.code).toBe(tupleResult.output[0].data.code); - expect(vlqResult.output[0].data.lineCount).toBe( - tupleResult.output[0].data.lineCount, + { + ...baseTransformOptions, + dev: false, + minify: true, + experimentalImportSupport: true, + }, ); - if (Array.isArray(vlqMap) || !Array.isArray(tupleMap)) { - throw new Error('Expected a VlqMap (compact) and a tuple array (default)'); + for (const result of [devResult, minifiedResult]) { + const map = result.output[0].data.map; + expect(typeof map.mappings).toBe('string'); + expect(map.mappings.length).toBeGreaterThan(0); + expect(Array.isArray(map.names)).toBe(true); } - // The compact fast path is byte-identical to re-encoding the tuple output. - expect(vlqMap).toEqual(vlqMapFromTuples(tupleMap)); - expect(typeof vlqMap.mappings).toBe('string'); - expect(vlqMap.mappings.length).toBeGreaterThan(0); }); test('throws if the reserved dependency map name appears in the input', async () => { diff --git a/packages/metro-transform-worker/src/index.js b/packages/metro-transform-worker/src/index.js index 4f3e4b260a..e10e3faab9 100644 --- a/packages/metro-transform-worker/src/index.js +++ b/packages/metro-transform-worker/src/index.js @@ -114,8 +114,6 @@ export type JsTransformerConfig = Readonly<{ unstable_nonMemoizedInlineRequires?: ReadonlyArray, /** Whether to rename scoped `require` functions to `_$$_REQUIRE`, usually an extraneous operation when serializing to iife (default). */ unstable_renameRequire?: boolean, - /** Store source maps as compact VLQ-encoded strings (`VlqMap`) instead of decoded tuple arrays. Reduces source-map memory ~51% on the heap. Opt-in; changes `JsOutput.data.map` for consumers. */ - unstable_compactSourceMaps?: boolean, }>; export type {CustomTransformOptions} from 'metro-babel-transformer'; @@ -174,7 +172,7 @@ export type JsOutput = Readonly<{ data: Readonly<{ code: string, lineCount: number, - map: Array | VlqMap, + map: VlqMap, functionMap: ?FBSourceFunctionMap, }>, type: JSFileType, @@ -478,46 +476,39 @@ async function transformJS( ); let code = result.code; - let map: Array | VlqMap; + let map: VlqMap; let lineCount: number; - if (config.unstable_compactSourceMaps === true && !minify) { + if (minify) { + // The minifier returns its own map (not Babel's `decodedMap`), so we derive + // tuples from Babel's eagerly-computed decoded map, hand them to the + // minifier, then re-encode the resulting tuples to a compact VLQ map. + let tuples = result.decodedMap + ? tuplesFromBabelDecodedMap(result.decodedMap) + : []; + + ({map: tuples, code} = await minifyCode( + config, + projectRoot, + file.filename, + result.code, + file.code, + tuples, + reserved, + )); + + ({lineCount, map: tuples} = countLinesAndTerminateMap(code, tuples)); + map = vlqMapFromTuples(tuples); + } else { // Dominant path (e.g. Hermes, which doesn't minify): encode the compact VLQ // map straight from Babel's eagerly-computed decoded map, never - // materialising tuples. Byte-identical to the tuple path below. + // materialising tuples. const {lineCount: lines, lastLineColumn} = countLines(code); lineCount = lines; map = vlqMapFromBabelDecodedMap( result.decodedMap ?? {mappings: [], names: []}, [lines, lastLineColumn], ); - } else { - // Derive tuples from Babel's eagerly-computed decoded map rather than - // `result.rawMappings`, which would trigger a second, more expensive decode - // (`allMappings`). Byte-identical to `result.rawMappings.map(toSegmentTuple)`. - let tuples = result.decodedMap - ? tuplesFromBabelDecodedMap(result.decodedMap) - : []; - - if (minify) { - // The minifier returns its own map (not Babel's `decodedMap`), so the - // fast path above can't apply; re-encode the resulting tuples if compact. - ({map: tuples, code} = await minifyCode( - config, - projectRoot, - file.filename, - result.code, - file.code, - tuples, - reserved, - )); - } - - ({lineCount, map: tuples} = countLinesAndTerminateMap(code, tuples)); - map = - config.unstable_compactSourceMaps === true - ? vlqMapFromTuples(tuples) - : tuples; } const output: Array = [ @@ -647,10 +638,9 @@ async function transformJSON( let lineCount; ({lineCount, map} = countLinesAndTerminateMap(code, map)); - // The JSON path builds tuples directly (no Babel `decodedMap`), so when - // compact we re-encode the finished tuples to VLQ. - const outputMap = - config.unstable_compactSourceMaps === true ? vlqMapFromTuples(map) : map; + // The JSON path builds tuples directly (no Babel `decodedMap`), so re-encode + // the finished tuples to a compact VLQ map. + const outputMap = vlqMapFromTuples(map); const output: Array = [ { data: {code, functionMap: null, lineCount, map: outputMap}, diff --git a/packages/metro-transform-worker/types/index.d.ts b/packages/metro-transform-worker/types/index.d.ts index 5fbb1de856..ea027fd5cf 100644 --- a/packages/metro-transform-worker/types/index.d.ts +++ b/packages/metro-transform-worker/types/index.d.ts @@ -6,7 +6,7 @@ * * @noformat * @oncall react_native - * @generated SignedSource<<42a021f72552951fbd1a0bdc2c2bb138>> + * @generated SignedSource<<28342f12ccdb6543eff2ef94ebd19bbc>> * * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js * Original file: packages/metro-transform-worker/src/index.js @@ -22,7 +22,6 @@ import type { import type { BasicSourceMap, FBSourceFunctionMap, - MetroSourceMapSegmentTuple, VlqMap, } from 'metro-source-map'; import type {TransformResultDependency} from 'metro/private/DeltaBundler'; @@ -69,8 +68,6 @@ export type JsTransformerConfig = Readonly<{ unstable_nonMemoizedInlineRequires?: ReadonlyArray; /** Whether to rename scoped `require` functions to `_$$_REQUIRE`, usually an extraneous operation when serializing to iife (default). */ unstable_renameRequire?: boolean; - /** Store source maps as compact VLQ-encoded strings (`VlqMap`) instead of decoded tuple arrays. Reduces source-map memory ~51% on the heap. Opt-in; changes `JsOutput.data.map` for consumers. */ - unstable_compactSourceMaps?: boolean; }>; export type {CustomTransformOptions} from 'metro-babel-transformer'; export type JsTransformOptions = Readonly<{ @@ -93,7 +90,7 @@ export type JsOutput = Readonly<{ data: Readonly<{ code: string; lineCount: number; - map: Array | VlqMap; + map: VlqMap; functionMap: null | undefined | FBSourceFunctionMap; }>; type: JSFileType; diff --git a/packages/metro/package.json b/packages/metro/package.json index 13e696a56b..b78568e6d0 100644 --- a/packages/metro/package.json +++ b/packages/metro/package.json @@ -1,6 +1,6 @@ { "name": "metro", - "version": "0.85.0", + "version": "0.86.0", "description": "🚇 The JavaScript bundler for React Native.", "main": "src/index.js", "bin": "src/cli.js", @@ -39,18 +39,18 @@ "jest-worker": "^29.7.0", "jsc-safe-url": "^0.2.2", "lodash.throttle": "^4.1.1", - "metro-babel-transformer": "0.85.0", - "metro-cache": "0.85.0", - "metro-cache-key": "0.85.0", - "metro-config": "0.85.0", - "metro-core": "0.85.0", - "metro-file-map": "0.85.0", - "metro-resolver": "0.85.0", - "metro-runtime": "0.85.0", - "metro-source-map": "0.85.0", - "metro-symbolicate": "0.85.0", - "metro-transform-plugins": "0.85.0", - "metro-transform-worker": "0.85.0", + "metro-babel-transformer": "0.86.0", + "metro-cache": "0.86.0", + "metro-cache-key": "0.86.0", + "metro-config": "0.86.0", + "metro-core": "0.86.0", + "metro-file-map": "0.86.0", + "metro-resolver": "0.86.0", + "metro-runtime": "0.86.0", + "metro-source-map": "0.86.0", + "metro-symbolicate": "0.86.0", + "metro-transform-plugins": "0.86.0", + "metro-transform-worker": "0.86.0", "mime-types": "^3.0.1", "nullthrows": "^1.1.1", "serialize-error": "^2.1.0", @@ -71,7 +71,7 @@ "dedent": "^0.7.0", "jest-snapshot": "^29.7.0", "jest-snapshot-serializer-raw": "^1.2.0", - "metro-babel-register": "0.85.0", + "metro-babel-register": "0.86.0", "metro-memory-fs": "*", "mock-req": "^0.2.0", "mock-res": "^0.6.0", diff --git a/packages/metro/src/DeltaBundler/Serializers/__tests__/__snapshots__/getRamBundleInfo-test.js.snap b/packages/metro/src/DeltaBundler/Serializers/__tests__/__snapshots__/getRamBundleInfo-test.js.snap index dfa22082c0..03fdfc2d87 100644 --- a/packages/metro/src/DeltaBundler/Serializers/__tests__/__snapshots__/getRamBundleInfo-test.js.snap +++ b/packages/metro/src/DeltaBundler/Serializers/__tests__/__snapshots__/getRamBundleInfo-test.js.snap @@ -9,19 +9,30 @@ Object { "code": "__d(function() {entry()},\\"/root/entry.js\\",[\\"/root/foo.js\\",\\"/root/entry2.js\\"],\\"entry.js\\");", "id": "/root/entry.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/entry.js", - ], - "sourcesContent": Array [ - "source of entry", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/entry.js", + ], + "sourcesContent": Array [ + "source of entry", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "entry.js", "source": "source of entry", @@ -32,19 +43,30 @@ Object { "code": "__d(function() {entry2()},\\"/root/entry2.js\\",[\\"/root/foo2.js\\"],\\"entry2.js\\");", "id": "/root/entry2.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/entry2.js", - ], - "sourcesContent": Array [ - "source of entry2", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/entry2.js", + ], + "sourcesContent": Array [ + "source of entry2", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "entry2.js", "source": "source of entry2", @@ -55,19 +77,30 @@ Object { "code": "__d(function() {foo2()},\\"/root/foo2.js\\",[],\\"foo2.js\\");", "id": "/root/foo2.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/foo2.js", - ], - "sourcesContent": Array [ - "source of foo2", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/foo2.js", + ], + "sourcesContent": Array [ + "source of foo2", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "foo2.js", "source": "source of foo2", @@ -78,19 +111,30 @@ Object { "code": "__d(function() {foo()},\\"/root/foo.js\\",[\\"/root/bar.js\\",\\"/root/baz.js\\",\\"/root/qux.js\\"],\\"foo.js\\");", "id": "/root/foo.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/foo.js", - ], - "sourcesContent": Array [ - "source of foo", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/foo.js", + ], + "sourcesContent": Array [ + "source of foo", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "foo.js", "source": "source of foo", @@ -101,19 +145,30 @@ Object { "code": "__d(function() {baz()},\\"/root/baz.js\\",[],\\"baz.js\\");", "id": "/root/baz.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/baz.js", - ], - "sourcesContent": Array [ - "", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/baz.js", + ], + "sourcesContent": Array [ + "", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "baz.js", "source": "source of baz", @@ -124,19 +179,30 @@ Object { "code": "__d(function() {bar()},\\"/root/bar.js\\",[],\\"bar.js\\");", "id": "/root/bar.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/bar.js", - ], - "sourcesContent": Array [ - "source of bar", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/bar.js", + ], + "sourcesContent": Array [ + "source of bar", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "bar.js", "source": "source of bar", @@ -147,19 +213,30 @@ Object { "code": "__d(function() {qux()},\\"/root/qux.js\\",[],\\"qux.js\\");", "id": "/root/qux.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/qux.js", - ], - "sourcesContent": Array [ - "source of qux", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/qux.js", + ], + "sourcesContent": Array [ + "source of qux", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "qux.js", "source": "source of qux", @@ -172,19 +249,30 @@ Object { "code": "__d(function() {pre()});", "id": "/root/pre.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/pre.js", - ], - "sourcesContent": Array [ - "source of pre", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/pre.js", + ], + "sourcesContent": Array [ + "source of pre", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "pre.js", "source": "source of pre", @@ -195,19 +283,30 @@ Object { "code": "require(\\"/root/entry.js\\");", "id": "require-/root/entry.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "require-/root/entry.js", - ], - "sourcesContent": Array [ - "", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "require-/root/entry.js", + ], + "sourcesContent": Array [ + "", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "entry.js", "source": "", @@ -218,19 +317,30 @@ Object { "code": "//# sourceMappingURL=http://localhost/bundle.map", "id": "source-map", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "source-map", - ], - "sourcesContent": Array [ - "", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "source-map", + ], + "sourcesContent": Array [ + "", + ], + "version": 3, + "x_google_ignoreList": Array [ + 0, + ], + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, - "x_google_ignoreList": Array [ - 0, - ], }, "name": "source-map", "source": "", @@ -250,14 +360,25 @@ Object { "code": "__d(function() {entry()},\\"/root/entry.js\\",[\\"/root/foo.js\\",\\"/root/entry2.js\\"],\\"entry.js\\");", "id": "/root/entry.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/entry.js", - ], - "sourcesContent": Array [ - "source of entry", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/entry.js", + ], + "sourcesContent": Array [ + "source of entry", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -270,14 +391,25 @@ Object { "code": "__d(function() {entry2()},\\"/root/entry2.js\\",[\\"/root/foo2.js\\"],\\"entry2.js\\");", "id": "/root/entry2.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/entry2.js", - ], - "sourcesContent": Array [ - "source of entry2", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/entry2.js", + ], + "sourcesContent": Array [ + "source of entry2", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -290,14 +422,25 @@ Object { "code": "__d(function() {foo2()},\\"/root/foo2.js\\",[],\\"foo2.js\\");", "id": "/root/foo2.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/foo2.js", - ], - "sourcesContent": Array [ - "source of foo2", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/foo2.js", + ], + "sourcesContent": Array [ + "source of foo2", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -310,14 +453,25 @@ Object { "code": "__d(function() {foo()},\\"/root/foo.js\\",[\\"/root/bar.js\\",\\"/root/baz.js\\",\\"/root/qux.js\\"],\\"foo.js\\");", "id": "/root/foo.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/foo.js", - ], - "sourcesContent": Array [ - "source of foo", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/foo.js", + ], + "sourcesContent": Array [ + "source of foo", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -330,14 +484,25 @@ Object { "code": "__d(function() {baz()},\\"/root/baz.js\\",[],\\"baz.js\\");", "id": "/root/baz.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/baz.js", - ], - "sourcesContent": Array [ - "", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/baz.js", + ], + "sourcesContent": Array [ + "", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -350,14 +515,25 @@ Object { "code": "__d(function() {bar()},\\"/root/bar.js\\",[],\\"bar.js\\");", "id": "/root/bar.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/bar.js", - ], - "sourcesContent": Array [ - "source of bar", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/bar.js", + ], + "sourcesContent": Array [ + "source of bar", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -370,14 +546,25 @@ Object { "code": "__d(function() {qux()},\\"/root/qux.js\\",[],\\"qux.js\\");", "id": "/root/qux.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/qux.js", - ], - "sourcesContent": Array [ - "source of qux", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/qux.js", + ], + "sourcesContent": Array [ + "source of qux", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -392,14 +579,25 @@ Object { "code": "__d(function() {pre()});", "id": "/root/pre.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "/root/pre.js", - ], - "sourcesContent": Array [ - "source of pre", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "/root/pre.js", + ], + "sourcesContent": Array [ + "source of pre", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -412,14 +610,25 @@ Object { "code": "require(\\"/root/entry.js\\");", "id": "require-/root/entry.js", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "require-/root/entry.js", - ], - "sourcesContent": Array [ - "", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "require-/root/entry.js", + ], + "sourcesContent": Array [ + "", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, @@ -432,14 +641,25 @@ Object { "code": "//# sourceMappingURL=http://localhost/bundle.map", "id": "source-map", "map": Object { - "file": undefined, - "mappings": "", - "names": Array [], - "sources": Array [ - "source-map", - ], - "sourcesContent": Array [ - "", + "sections": Array [ + Object { + "map": Object { + "file": undefined, + "mappings": "", + "names": Array [], + "sources": Array [ + "source-map", + ], + "sourcesContent": Array [ + "", + ], + "version": 3, + }, + "offset": Object { + "column": 0, + "line": 0, + }, + }, ], "version": 3, }, diff --git a/packages/metro/src/DeltaBundler/Serializers/__tests__/baseJSBundle-test.js b/packages/metro/src/DeltaBundler/Serializers/__tests__/baseJSBundle-test.js index a40064c737..d1cd66dcbc 100644 --- a/packages/metro/src/DeltaBundler/Serializers/__tests__/baseJSBundle-test.js +++ b/packages/metro/src/DeltaBundler/Serializers/__tests__/baseJSBundle-test.js @@ -398,11 +398,29 @@ test('should add an inline source map to a very simple bundle', () => { ).toString(), ), ).toEqual({ - mappings: '', - names: [], - sources: ['/root/foo', '/root/bar'], - sourcesContent: ['foo-source', 'bar-source'], version: 3, + sections: [ + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/foo'], + sourcesContent: ['foo-source'], + names: [], + mappings: '', + }, + }, + { + offset: {line: 2, column: 0}, + map: { + version: 3, + sources: ['/root/bar'], + sourcesContent: ['bar-source'], + names: [], + mappings: '', + }, + }, + ], }); }); @@ -451,8 +469,30 @@ test('emits x_google_ignoreList based on shouldAddToIgnoreList', () => { ), ).toEqual( objectContaining({ - sources: ['/root/foo', '/root/bar'], - x_google_ignoreList: [0, 1], + sections: [ + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/foo'], + sourcesContent: ['foo-source'], + names: [], + mappings: '', + x_google_ignoreList: [0], + }, + }, + { + offset: {line: 2, column: 0}, + map: { + version: 3, + sources: ['/root/bar'], + sourcesContent: ['bar-source'], + names: [], + mappings: '', + x_google_ignoreList: [0], + }, + }, + ], }), ); }); diff --git a/packages/metro/src/DeltaBundler/Serializers/__tests__/sourceMapString-test.js b/packages/metro/src/DeltaBundler/Serializers/__tests__/sourceMapString-test.js index c7cd9194b7..c84110e199 100644 --- a/packages/metro/src/DeltaBundler/Serializers/__tests__/sourceMapString-test.js +++ b/packages/metro/src/DeltaBundler/Serializers/__tests__/sourceMapString-test.js @@ -98,15 +98,39 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( ), ).toEqual({ version: 3, - sources: ['/root/pre.js', '/root/foo.js', '/root/bar.js'], - sourcesContent: ['source pre', 'source foo', 'source bar'], - x_facebook_sources: [ - null, - [{names: [''], mappings: 'AAA'}], - null, + sections: [ + { + offset: {line: 0, column: 0}, + map: { + version: 3, + sources: ['/root/pre.js'], + sourcesContent: ['source pre'], + names: [], + mappings: '', + }, + }, + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/foo.js'], + sourcesContent: ['source foo'], + names: [], + mappings: '', + x_facebook_sources: [[{names: [''], mappings: 'AAA'}]], + }, + }, + { + offset: {line: 2, column: 0}, + map: { + version: 3, + sources: ['/root/bar.js'], + sourcesContent: ['source bar'], + names: [], + mappings: '', + }, + }, ], - names: [], - mappings: '', }); }); @@ -122,15 +146,39 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( ), ).toEqual({ version: 3, - sources: ['/root/pre.js', '/root/bar.js', '/root/foo.js'], - sourcesContent: ['source pre', 'source bar', 'source foo'], - x_facebook_sources: [ - null, - null, - [{names: [''], mappings: 'AAA'}], + sections: [ + { + offset: {line: 0, column: 0}, + map: { + version: 3, + sources: ['/root/pre.js'], + sourcesContent: ['source pre'], + names: [], + mappings: '', + }, + }, + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/bar.js'], + sourcesContent: ['source bar'], + names: [], + mappings: '', + }, + }, + { + offset: {line: 2, column: 0}, + map: { + version: 3, + sources: ['/root/foo.js'], + sourcesContent: ['source foo'], + names: [], + mappings: '', + x_facebook_sources: [[{names: [''], mappings: 'AAA'}]], + }, + }, ], - names: [], - mappings: '', }); }); @@ -165,11 +213,29 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( ), ).toEqual({ version: 3, - sources: ['/root/foo.js', '/root/asset.jpg'], - sourcesContent: ['source foo', ''], - x_facebook_sources: [[{names: [''], mappings: 'AAA'}], null], - names: [], - mappings: '', + sections: [ + { + offset: {line: 0, column: 0}, + map: { + version: 3, + sources: ['/root/foo.js'], + sourcesContent: ['source foo'], + names: [], + mappings: '', + x_facebook_sources: [[{names: [''], mappings: 'AAA'}]], + }, + }, + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/asset.jpg'], + sourcesContent: [''], + names: [], + mappings: '', + }, + }, + ], }); }); @@ -185,23 +251,49 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( ), ).toEqual({ version: 3, - sources: ['/root/pre.js', '/root/foo.js', '/root/bar.js'], - sourcesContent: ['source pre', 'source foo', 'source bar'], - x_facebook_sources: [ - null, - [{names: [''], mappings: 'AAA'}], - null, + sections: [ + { + offset: {line: 0, column: 0}, + map: { + version: 3, + sources: ['/root/pre.js'], + sourcesContent: ['source pre'], + names: [], + mappings: '', + x_google_ignoreList: [0], + }, + }, + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/foo.js'], + sourcesContent: ['source foo'], + names: [], + mappings: '', + x_facebook_sources: [[{names: [''], mappings: 'AAA'}]], + x_google_ignoreList: [0], + }, + }, + { + offset: {line: 2, column: 0}, + map: { + version: 3, + sources: ['/root/bar.js'], + sourcesContent: ['source bar'], + names: [], + mappings: '', + x_google_ignoreList: [0], + }, + }, ], - names: [], - mappings: '', - x_google_ignoreList: [0, 1, 2], }); }); }, ); describe.each([sourceMapString, sourceMapStringNonBlocking])( - 'allowIndexMap (%p)', + 'index source map sections (%p)', sourceMapStringImpl => { const vlqModule: Module<> = { path: '/root/vlq.js', @@ -229,12 +321,9 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( getSourceUrl: null, }; - test('emits an indexed map passing VLQ through verbatim when enabled', async () => { + test('passes a VLQ-stored map through verbatim as a section', async () => { const parsed = JSON.parse( - await sourceMapStringImpl([fooModule, vlqModule], { - ...options, - allowIndexMap: true, - }), + await sourceMapStringImpl([fooModule, vlqModule], options), ); expect(parsed.version).toBe(3); expect(parsed.sections).toHaveLength(2); @@ -248,27 +337,15 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( ]); }); - test('falls back to a flat map when no VLQ maps are present', async () => { + test('re-encodes a tuple-stored map into its section', async () => { const parsed = JSON.parse( - await sourceMapStringImpl([fooModule, barModule], { - ...options, - allowIndexMap: true, - }), + await sourceMapStringImpl([fooModule, barModule], options), ); - // No VLQ → indexed emit is pointless, so we stay flat. - expect(parsed.sections).toBeUndefined(); - expect(typeof parsed.mappings).toBe('string'); - }); - - test('emits a flat map for VLQ input when disabled', async () => { - const parsed = JSON.parse( - await sourceMapStringImpl([fooModule, vlqModule], { - ...options, - allowIndexMap: false, - }), - ); - expect(parsed.sections).toBeUndefined(); - expect(typeof parsed.mappings).toBe('string'); + expect(parsed.version).toBe(3); + expect(parsed.sections).toHaveLength(2); + expect(parsed.sections[1].offset).toEqual({line: 1, column: 0}); + expect(parsed.sections[1].map.sources).toEqual(['/root/bar.js']); + expect(typeof parsed.sections[1].map.mappings).toBe('string'); }); test('omits per-section sourcesContent when excludeSource is set', async () => { @@ -276,7 +353,6 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( await sourceMapStringImpl([vlqModule], { ...options, excludeSource: true, - allowIndexMap: true, }), ); expect(parsed.sections).toHaveLength(1); @@ -289,7 +365,6 @@ describe.each([sourceMapString, sourceMapStringNonBlocking])( await sourceMapStringImpl([vlqModule], { ...options, shouldAddToIgnoreList: (module: Module<>) => true, - allowIndexMap: true, }), ); expect(parsed.sections).toHaveLength(1); diff --git a/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js b/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js index d075660c7d..34d4fc9c85 100644 --- a/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js +++ b/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js @@ -13,22 +13,13 @@ import type {Module} from '../types'; import getSourceMapInfo from './helpers/getSourceMapInfo'; import {isJsModule} from './helpers/js'; -import { - fromRawMappings, - fromRawMappingsIndexed, - fromRawMappingsNonBlocking, - isVlqMap, -} from 'metro-source-map'; +import {fromRawMappingsIndexed} from 'metro-source-map'; export type SourceMapGeneratorOptions = Readonly<{ excludeSource: boolean, processModuleFilter: (module: Module<>) => boolean, shouldAddToIgnoreList: (module: Module<>) => boolean, getSourceUrl: ?(module: Module<>) => string, - // Allow an index map (sectioned) that passes VLQ-stored maps through - // verbatim, instead of decoding + re-encoding into a flat map. No-op unless - // VLQ maps are actually present. - allowIndexMap?: boolean, }>; function getSourceMapInfosImpl( @@ -87,9 +78,7 @@ function getSourceMapInfosImpl( function sourceMapGenerator( modules: ReadonlyArray>, options: SourceMapGeneratorOptions, -): - | ReturnType - | ReturnType { +): ReturnType { let sourceMapInfos; getSourceMapInfosImpl( true, @@ -104,41 +93,21 @@ function sourceMapGenerator( 'Expected getSourceMapInfosImpl() to finish synchronously.', ); } - if (shouldEmitIndexedMap(options, sourceMapInfos)) { - return fromRawMappingsIndexed(sourceMapInfos); - } - return fromRawMappings(sourceMapInfos); + return fromRawMappingsIndexed(sourceMapInfos); } async function sourceMapGeneratorNonBlocking( modules: ReadonlyArray>, options: SourceMapGeneratorOptions, -): Promise< - | ReturnType - | ReturnType, -> { +): Promise> { const sourceMapInfos = await new Promise< ReadonlyArray>, >(resolve => { getSourceMapInfosImpl(false, resolve, modules, options); }); - if (shouldEmitIndexedMap(options, sourceMapInfos)) { - // The indexed path is a cheap synchronous passthrough — no need to yield. - return fromRawMappingsIndexed(sourceMapInfos); - } - return fromRawMappingsNonBlocking(sourceMapInfos); -} - -// An index map only helps (and only avoids decode) when maps are actually stored -// as VLQ, so gate on both the option and the presence of a VLQ map. -function shouldEmitIndexedMap( - options: SourceMapGeneratorOptions, - sourceMapInfos: ReadonlyArray>, -): boolean { - return ( - options.allowIndexMap === true && - sourceMapInfos.some(info => isVlqMap(info.map)) - ); + // Building an index map is a cheap synchronous passthrough (VLQ maps carry + // over verbatim); only gathering the per-module info above needs to yield. + return fromRawMappingsIndexed(sourceMapInfos); } export {sourceMapGenerator, sourceMapGeneratorNonBlocking}; diff --git a/packages/metro/src/Server.js b/packages/metro/src/Server.js index cece20a2cf..cedba41833 100644 --- a/packages/metro/src/Server.js +++ b/packages/metro/src/Server.js @@ -296,7 +296,6 @@ export default class Server { shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList, getSourceUrl: (module: Module<>) => this._getModuleSourceUrl(module, serializerOptions.sourcePaths), - allowIndexMap: this._config.serializer.unstable_allowIndexMap, }, ); } @@ -1310,7 +1309,6 @@ export default class Server { this._shouldAddModuleToIgnoreList(module), getSourceUrl: (module: Module<>) => this._getModuleSourceUrl(module, serializerOptions.sourcePaths), - allowIndexMap: this._config.serializer.unstable_allowIndexMap, }, ); }, diff --git a/packages/metro/src/Server/__tests__/Server-test.js b/packages/metro/src/Server/__tests__/Server-test.js index 47d7e6f954..17dd41b143 100644 --- a/packages/metro/src/Server/__tests__/Server-test.js +++ b/packages/metro/src/Server/__tests__/Server-test.js @@ -594,21 +594,40 @@ describe('processRequest', () => { expect(response._getJSON()).toEqual({ version: 3, - sources: ['require-js', '/root/mybundle.js', '/root/foo.js'], - sourcesContent: ['code-require', 'code-mybundle', 'code-foo'], - names: [], - mappings: ';gBCAA;gBCAA', - x_facebook_sources: [ - null, - null, - [ - { - mappings: 'AAA', - names: [''], + sections: [ + { + offset: {line: 0, column: 0}, + map: { + version: 3, + sources: ['require-js'], + sourcesContent: ['code-require'], + names: [], + mappings: '', }, - ], + }, + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/mybundle.js'], + sourcesContent: ['code-mybundle'], + names: [], + mappings: 'gBAAA', + }, + }, + { + offset: {line: 2, column: 0}, + map: { + version: 3, + sources: ['/root/foo.js'], + sourcesContent: ['code-foo'], + names: [], + mappings: 'gBAAA', + x_facebook_sources: [[{mappings: 'AAA', names: ['']}]], + x_google_ignoreList: [0], + }, + }, ], - x_google_ignoreList: [2], }); }); @@ -617,20 +636,30 @@ describe('processRequest', () => { expect(response._getJSON()).toEqual({ version: 3, - sources: ['/root/mybundle.js', '/root/foo.js'], - sourcesContent: ['code-mybundle', 'code-foo'], - names: [], - mappings: 'gBAAA;gBCAA', - x_facebook_sources: [ - null, - [ - { - mappings: 'AAA', - names: [''], + sections: [ + { + offset: {line: 0, column: 0}, + map: { + version: 3, + sources: ['/root/mybundle.js'], + sourcesContent: ['code-mybundle'], + names: [], + mappings: 'gBAAA', + }, + }, + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/root/foo.js'], + sourcesContent: ['code-foo'], + names: [], + mappings: 'gBAAA', + x_facebook_sources: [[{mappings: 'AAA', names: ['']}]], + x_google_ignoreList: [0], }, - ], + }, ], - x_google_ignoreList: [1], }); }); @@ -718,25 +747,40 @@ describe('processRequest', () => { expect(response._getJSON()).toEqual({ version: 3, - sources: [ - '/require-js', - '/[metro-project]/mybundle.js', - '/[metro-project]/foo.js', - ], - sourcesContent: ['code-require', 'code-mybundle', 'code-foo'], - names: [], - mappings: ';gBCAA;gBCAA', - x_facebook_sources: [ - null, - null, - [ - { - mappings: 'AAA', - names: [''], + sections: [ + { + offset: {line: 0, column: 0}, + map: { + version: 3, + sources: ['/require-js'], + sourcesContent: ['code-require'], + names: [], + mappings: '', }, - ], + }, + { + offset: {line: 1, column: 0}, + map: { + version: 3, + sources: ['/[metro-project]/mybundle.js'], + sourcesContent: ['code-mybundle'], + names: [], + mappings: 'gBAAA', + }, + }, + { + offset: {line: 2, column: 0}, + map: { + version: 3, + sources: ['/[metro-project]/foo.js'], + sourcesContent: ['code-foo'], + names: [], + mappings: 'gBAAA', + x_facebook_sources: [[{mappings: 'AAA', names: ['']}]], + x_google_ignoreList: [0], + }, + }, ], - x_google_ignoreList: [2], }); }); diff --git a/packages/metro/src/integration_tests/__tests__/__snapshots__/buildGraph-test.js.snap b/packages/metro/src/integration_tests/__tests__/__snapshots__/buildGraph-test.js.snap index 3be10525a9..52456009a1 100644 --- a/packages/metro/src/integration_tests/__tests__/__snapshots__/buildGraph-test.js.snap +++ b/packages/metro/src/integration_tests/__tests__/__snapshots__/buildGraph-test.js.snap @@ -24,394 +24,21 @@ Array [ ], }, "lineCount": 13, - "map": Array [ - Array [ - 2, - 2, - 11, - 0, - ], - Array [ - 2, - 14, - 11, - 12, - ], - Array [ - 4, - 2, - 13, - 0, - ], - Array [ - 4, - 6, - 13, - 6, + "map": Object { + "mappings": ";EAUA,YAAY;;EAEZ,IAAMA,GAAG,GAAGC,WAAO,CAAAC,cAAA,GAAQ,CAAC;EAC5B,IAAMC,GAAG,GAAGF,WAAO,CAAAC,cAAA,GAAQ,CAAC;EAG5B,IAAME,UAAU,GAAGH,WAAO,CAAAC,cAAA,GAAe,CAAC;EAE1CG,MAAM,CAACC,IAAI,CAAAD,MAAA,CAAAE,MAAA,KAAKP,GAAG,CAAC,CAAC;EAErBQ,MAAM,CAACC,OAAO,GAAG;IAACN,GAAG,EAAHA,GAAG;IAAEH,GAAG,EAAHA,GAAG;IAAEI,UAAU,EAAVA;EAAU,CAAC;AAAC,G", + "names": Array [ "Bar", - ], - Array [ - 4, - 9, - 13, - 9, - ], - Array [ - 4, - 12, - 13, - 12, "require", - ], - Array [ - 4, - 23, - 13, - 19, - ], - Array [ - 4, - 24, - 13, - 19, "_dependencyMap", - ], - Array [ - 4, - 38, - 13, - 19, - ], - Array [ - 4, - 41, - 13, - 27, - ], - Array [ - 4, - 42, - 13, - 28, - ], - Array [ - 5, - 2, - 14, - 0, - ], - Array [ - 5, - 6, - 14, - 6, "Foo", - ], - Array [ - 5, - 9, - 14, - 9, - ], - Array [ - 5, - 12, - 14, - 12, - "require", - ], - Array [ - 5, - 23, - 14, - 19, - ], - Array [ - 5, - 24, - 14, - 19, - "_dependencyMap", - ], - Array [ - 5, - 38, - 14, - 19, - ], - Array [ - 5, - 41, - 14, - 27, - ], - Array [ - 5, - 42, - 14, - 28, - ], - Array [ - 6, - 2, - 17, - 0, - ], - Array [ - 6, - 6, - 17, - 6, "TypeScript", - ], - Array [ - 6, - 16, - 17, - 16, - ], - Array [ - 6, - 19, - 17, - 19, - "require", - ], - Array [ - 6, - 30, - 17, - 26, - ], - Array [ - 6, - 31, - 17, - 26, - "_dependencyMap", - ], - Array [ - 6, - 45, - 17, - 26, - ], - Array [ - 6, - 48, - 17, - 41, - ], - Array [ - 6, - 49, - 17, - 42, - ], - Array [ - 7, - 2, - 19, - 0, "Object", - ], - Array [ - 7, - 8, - 19, - 6, - ], - Array [ - 7, - 9, - 19, - 7, "keys", - ], - Array [ - 7, - 13, - 19, - 11, - ], - Array [ - 7, - 14, - 19, - 11, - "Object", - ], - Array [ - 7, - 20, - 19, - 11, - ], - Array [ - 7, - 21, - 19, - 11, "assign", - ], - Array [ - 7, - 27, - 19, - 11, - ], - Array [ - 7, - 32, - 19, - 16, - "Bar", - ], - Array [ - 7, - 35, - 19, - 19, - ], - Array [ - 7, - 36, - 19, - 20, - ], - Array [ - 7, - 37, - 19, - 21, - ], - Array [ - 8, - 2, - 21, - 0, "module", - ], - Array [ - 8, - 8, - 21, - 6, - ], - Array [ - 8, - 9, - 21, - 7, "exports", ], - Array [ - 8, - 16, - 21, - 14, - ], - Array [ - 8, - 19, - 21, - 17, - ], - Array [ - 9, - 4, - 21, - 18, - "Foo", - ], - Array [ - 9, - 7, - 21, - 21, - ], - Array [ - 9, - 9, - 21, - 18, - "Foo", - ], - Array [ - 9, - 12, - 21, - 21, - ], - Array [ - 10, - 4, - 21, - 23, - "Bar", - ], - Array [ - 10, - 7, - 21, - 26, - ], - Array [ - 10, - 9, - 21, - 23, - "Bar", - ], - Array [ - 10, - 12, - 21, - 26, - ], - Array [ - 11, - 4, - 21, - 28, - "TypeScript", - ], - Array [ - 11, - 14, - 21, - 38, - ], - Array [ - 11, - 16, - 21, - 28, - "TypeScript", - ], - Array [ - 12, - 2, - 21, - 38, - ], - Array [ - 12, - 3, - 21, - 39, - ], - Array [ - 13, - 0, - 21, - 40, - ], - Array [ - 13, - 3, - ], - ], + }, }, "type": "js/module", }, diff --git a/packages/metro/types/DeltaBundler/Serializers/sourceMapGenerator.d.ts b/packages/metro/types/DeltaBundler/Serializers/sourceMapGenerator.d.ts index 76f696874f..3bbd2dcc42 100644 --- a/packages/metro/types/DeltaBundler/Serializers/sourceMapGenerator.d.ts +++ b/packages/metro/types/DeltaBundler/Serializers/sourceMapGenerator.d.ts @@ -6,7 +6,7 @@ * * @noformat * @oncall react_native - * @generated SignedSource<<35bb62d836afac725c73389319206389>> + * @generated SignedSource<<6c7d6cff28e917c03235af1d0c98db4e>> * * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js * Original file: packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js @@ -17,25 +17,20 @@ import type {Module} from '../types'; -import {fromRawMappings, fromRawMappingsIndexed} from 'metro-source-map'; +import {fromRawMappingsIndexed} from 'metro-source-map'; export type SourceMapGeneratorOptions = Readonly<{ excludeSource: boolean; processModuleFilter: (module: Module) => boolean; shouldAddToIgnoreList: (module: Module) => boolean; getSourceUrl: null | undefined | ((module: Module) => string); - allowIndexMap?: boolean; }>; declare function sourceMapGenerator( modules: ReadonlyArray, options: SourceMapGeneratorOptions, -): - | ReturnType - | ReturnType; +): ReturnType; declare function sourceMapGeneratorNonBlocking( modules: ReadonlyArray, options: SourceMapGeneratorOptions, -): Promise< - ReturnType | ReturnType ->; +): Promise>; export {sourceMapGenerator, sourceMapGeneratorNonBlocking}; diff --git a/packages/ob1/package.json b/packages/ob1/package.json index b1c6155bca..01862d6c2c 100644 --- a/packages/ob1/package.json +++ b/packages/ob1/package.json @@ -1,6 +1,6 @@ { "name": "ob1", - "version": "0.85.0", + "version": "0.86.0", "description": "A small library for working with 0- and 1-based offsets in a type-checked way.", "main": "src/ob1.js", "exports": {