diff --git a/packages/metro-bundler/src/JSTransformer/index.js b/packages/metro-bundler/src/JSTransformer/index.js index 5d5a83da..6f44ed48 100644 --- a/packages/metro-bundler/src/JSTransformer/index.js +++ b/packages/metro-bundler/src/JSTransformer/index.js @@ -19,7 +19,7 @@ const Worker = require('jest-worker').default; import type {Options, TransformedCode} from './worker'; import type {LocalPath} from '../node-haste/lib/toLocalPath'; -import type {RawMappings} from '../lib/SourceMap'; +import type {MappingsMap} from '../lib/SourceMap'; import type {ResultWithMap} from './worker/minify'; import typeof { @@ -78,7 +78,7 @@ module.exports = class Transformer { async minify( filename: string, code: string, - sourceMap: RawMappings, + sourceMap: MappingsMap, ): Promise { return await this._worker.minify(filename, code, sourceMap); } diff --git a/packages/metro-bundler/src/JSTransformer/worker/index.js b/packages/metro-bundler/src/JSTransformer/worker/index.js index caf97e8e..0bebcce7 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/index.js +++ b/packages/metro-bundler/src/JSTransformer/worker/index.js @@ -12,7 +12,6 @@ 'use strict'; -const asyncify = require('async/asyncify'); const constantFolding = require('./constant-folding'); const extractDependencies = require('./extract-dependencies'); const inline = require('./inline'); @@ -34,7 +33,7 @@ export type TransformedCode = { code: string, dependencies: Array, dependencyOffsets: Array, - map?: ?CompactRawMappings, + map: CompactRawMappings, }; export type TransformArgs = {| @@ -134,7 +133,7 @@ function transformCode( : transformed.map; // Convert the sourcemaps to Compact Raw source maps. - const map = rawMappings ? rawMappings.map(compactMapping) : null; + const map = rawMappings ? rawMappings.map(compactMapping) : []; let code = transformed.code; if (isJson) { @@ -168,7 +167,7 @@ function transformCode( exports.minify = async function( filename: string, code: string, - sourceMap: RawMappings, + sourceMap: MappingsMap, ): Promise { try { return minify.withSourceMap(code, sourceMap, filename); diff --git a/packages/metro-bundler/src/JSTransformer/worker/minify.js b/packages/metro-bundler/src/JSTransformer/worker/minify.js index 736dc2f6..41b5b436 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/minify.js +++ b/packages/metro-bundler/src/JSTransformer/worker/minify.js @@ -14,17 +14,7 @@ const uglify = require('uglify-es'); -const { - compactMapping, - fromRawMappings, - toRawMappings, -} = require('../../Bundler/source-map'); - -import type { - CompactRawMappings, - MappingsMap, - RawMappings, -} from '../../lib/SourceMap'; +import type {MappingsMap} from '../../lib/SourceMap'; export type ResultWithMap = { code: string, @@ -37,15 +27,9 @@ function noSourceMap(code: string): string { function withSourceMap( code: string, - sourceMap: ?MappingsMap | RawMappings, + sourceMap: ?MappingsMap, filename: string, ): ResultWithMap { - if (sourceMap && Array.isArray(sourceMap)) { - sourceMap = fromRawMappings([ - {code, source: code, map: sourceMap, path: filename}, - ]).toMap(undefined, {}); - } - const result = minify(code, sourceMap); const map: MappingsMap = JSON.parse(result.map); @@ -53,19 +37,6 @@ function withSourceMap( return {code: result.code, map}; } -function withRawMappings( - code: string, - map: RawMappings, - filename: string, -): {code: string, map: CompactRawMappings} { - const result = withSourceMap(code, map, filename); - - return { - code: result.code, - map: toRawMappings(result.map).map(compactMapping), - }; -} - function minify(inputCode: string, inputMap: ?MappingsMap) { const result = uglify.minify(inputCode, { mangle: {toplevel: true}, @@ -93,6 +64,5 @@ function minify(inputCode: string, inputMap: ?MappingsMap) { module.exports = { noSourceMap, - withRawMappings, withSourceMap, }; diff --git a/packages/metro-bundler/src/Resolver/index.js b/packages/metro-bundler/src/Resolver/index.js index 5b1edd69..755fc1e1 100644 --- a/packages/metro-bundler/src/Resolver/index.js +++ b/packages/metro-bundler/src/Resolver/index.js @@ -35,11 +35,7 @@ import type { } from '../lib/TransformCaching'; import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; -type MinifyCode = ( - filePath: string, - code: string, - map: ?MappingsMap, -) => Promise<{code: string, map: ?MappingsMap}>; +import typeof {minify as MinifyCode} from '../JSTransformer/worker'; type ContainsTransformerOptions = {+transformer: JSTransformerOptions}; @@ -273,7 +269,7 @@ class Resolver { ); const minified = await this._minifyCode(path, code, sourceMap); - const result = await this._postMinifyProcess(minified); + const result = await this._postMinifyProcess({...minified}); return { code: result.code, diff --git a/packages/metro-bundler/src/lib/TransformCaching.js b/packages/metro-bundler/src/lib/TransformCaching.js index 533cd90a..bddf743f 100644 --- a/packages/metro-bundler/src/lib/TransformCaching.js +++ b/packages/metro-bundler/src/lib/TransformCaching.js @@ -35,7 +35,7 @@ export type CachedResult = { code: string, dependencies: Array, dependencyOffsets: Array, - map?: ?CompactRawMappings, + map: CompactRawMappings, }; export type TransformCacheResult = {| @@ -336,7 +336,7 @@ function readMetadataFileSync( cachedSourceHash: string, dependencies: Array, dependencyOffsets: Array, - sourceMap: ?CompactRawMappings, + sourceMap: CompactRawMappings, } { const metadataStr = fs.readFileSync(metadataFilePath, 'utf8'); const metadata = tryParseJSON(metadataStr); diff --git a/packages/metro-bundler/src/node-haste/Module.js b/packages/metro-bundler/src/node-haste/Module.js index 21f7909f..54032547 100644 --- a/packages/metro-bundler/src/node-haste/Module.js +++ b/packages/metro-bundler/src/node-haste/Module.js @@ -27,7 +27,7 @@ import type { Options as WorkerOptions, } from '../JSTransformer/worker'; import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; -import type {MappingsMap} from '../lib/SourceMap'; +import type {CompactRawMappings} from '../lib/SourceMap'; import type { TransformCache, GetTransformCacheKey, @@ -42,7 +42,7 @@ export type ReadResult = { +code: string, +dependencies: Array, +dependencyOffsets?: ?Array, - +map?: ?(MappingsMap | Array), + +map: CompactRawMappings, +source: string, };