diff --git a/packages/metro-config/src/defaults/index.js b/packages/metro-config/src/defaults/index.js index 8ee4308daf..f234ae03a7 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,7 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({ unstable_disableNormalizePseudoGlobals: false, unstable_renameRequire: true, unstable_compactOutput: false, - unstable_compactSourceMaps: false, + unstable_compactSourceMaps: true, 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/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};