mirror of https://github.com/status-im/metro.git
Moving source map stuff into its own package
Reviewed By: rafeca Differential Revision: D6692262 fbshipit-source-id: 7476ec4c8ea45eaea6c19f410e98650ce7eb0acb
This commit is contained in:
parent
997be549aa
commit
d6feb5a89a
|
@ -17,17 +17,42 @@ const SourceMap = require('source-map');
|
|||
|
||||
import type {SourceMap as MappingsMap} from 'babel-core';
|
||||
import type {RawMapping as BabelRawMapping} from 'babel-generator';
|
||||
import type {RawMapping as CompactRawMapping} from 'source-map';
|
||||
|
||||
export type {SourceMap as MappingsMap} from 'babel-core';
|
||||
export type CompactRawMappings = Array<CompactRawMapping>;
|
||||
export type RawMappings = Array<BabelRawMapping>;
|
||||
|
||||
type RawMappings = Array<BabelRawMapping>;
|
||||
type GeneratedCodeMapping = [number, number];
|
||||
type SourceMapping = [number, number, number, number];
|
||||
type SourceMappingWithName = [number, number, number, number, string];
|
||||
|
||||
type FBExtensions = {
|
||||
x_facebook_offsets: Array<number>,
|
||||
x_metro_module_paths: Array<string>,
|
||||
};
|
||||
|
||||
export type RawMapping =
|
||||
| SourceMappingWithName
|
||||
| SourceMapping
|
||||
| GeneratedCodeMapping;
|
||||
|
||||
export type IndexMapSection = {
|
||||
map: MetroSourceMap,
|
||||
offset: {line: number, column: number},
|
||||
};
|
||||
|
||||
export type IndexMap = {
|
||||
file?: string,
|
||||
mappings?: void, // avoids SourceMap being a disjoint union
|
||||
sections: Array<IndexMapSection>,
|
||||
version: number,
|
||||
};
|
||||
|
||||
export type FBIndexMap = IndexMap & FBExtensions;
|
||||
export type MetroSourceMap = IndexMap | MappingsMap;
|
||||
export type FBSourceMap = FBIndexMap | (MappingsMap & FBExtensions);
|
||||
|
||||
/**
|
||||
* Creates a source map from modules with "raw mappings", i.e. an array of
|
||||
* tuples with either 2, 4, or 5 elements:
|
||||
|
|
|
@ -29,11 +29,14 @@ const {
|
|||
import type {PostProcessModules} from '../DeltaBundler';
|
||||
import type {Options as JSTransformerOptions} from '../JSTransformer/worker';
|
||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||
import type {CompactRawMappings} from '../lib/SourceMap';
|
||||
import type {MappingsMap, SourceMap} from '../lib/SourceMap';
|
||||
import type {TransformCache} from '../lib/TransformCaching';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {HasteImpl} from '../node-haste/Module';
|
||||
import type {
|
||||
CompactRawMappings,
|
||||
MappingsMap,
|
||||
MetroSourceMap as SourceMap,
|
||||
} from 'metro-source-map';
|
||||
|
||||
export type BundlingOptions = {|
|
||||
+preloadedModules: ?{[string]: true} | false,
|
||||
|
|
|
@ -25,11 +25,11 @@ const {EventEmitter} = require('events');
|
|||
|
||||
import type Bundler from '../Bundler';
|
||||
import type {Options as JSTransformerOptions} from '../JSTransformer/worker';
|
||||
import type {CompactRawMappings} from '../lib/SourceMap';
|
||||
import type DependencyGraph from '../node-haste/DependencyGraph';
|
||||
import type Module from '../node-haste/Module';
|
||||
import type {Options as BundleOptions, MainOptions} from './';
|
||||
import type {DependencyEdges} from './traverseDependencies';
|
||||
import type {CompactRawMappings} from 'metro-source-map';
|
||||
|
||||
export type DeltaEntryType =
|
||||
| 'asset'
|
||||
|
|
|
@ -21,7 +21,6 @@ const {createRamBundleGroups} = require('../Bundler/util');
|
|||
const {fromRawMappings} = require('metro-source-map');
|
||||
|
||||
import type {AssetData} from '../Assets';
|
||||
import type {MappingsMap} from '../lib/SourceMap';
|
||||
import type {BundleOptions} from '../shared/types.flow';
|
||||
import type {ModuleTransportLike} from '../shared/types.flow';
|
||||
import type DeltaBundler, {Options as BuildOptions} from './';
|
||||
|
@ -29,6 +28,7 @@ import type DeltaTransformer, {
|
|||
DeltaEntry,
|
||||
DeltaTransformResponse,
|
||||
} from './DeltaTransformer';
|
||||
import type {MappingsMap} from 'metro-source-map';
|
||||
|
||||
export type Options = BundleOptions & {
|
||||
deltaBundleId: ?string,
|
||||
|
|
|
@ -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 {MappingsMap} from '../lib/SourceMap';
|
||||
import type {MappingsMap} from 'metro-source-map';
|
||||
import type {ResultWithMap} from './worker/minify';
|
||||
|
||||
import typeof {minify as Minify, transform as Transform} from './worker';
|
||||
|
|
|
@ -27,7 +27,7 @@ const path = require('path');
|
|||
const {compactMapping} = require('metro-source-map');
|
||||
|
||||
import type {LogEntry} from 'metro-core/src/Logger';
|
||||
import type {CompactRawMappings, MappingsMap} from '../../lib/SourceMap';
|
||||
import type {CompactRawMappings, MappingsMap} from 'metro-source-map';
|
||||
import type {LocalPath} from '../../node-haste/lib/toLocalPath';
|
||||
import type {ResultWithMap} from './minify';
|
||||
import type {Ast, Plugins as BabelPlugins} from 'babel-core';
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
const uglify = require('uglify-es');
|
||||
|
||||
import type {MappingsMap} from '../../lib/SourceMap';
|
||||
import type {MappingsMap} from 'metro-source-map';
|
||||
|
||||
export type ResultWithMap = {
|
||||
code: string,
|
||||
|
|
|
@ -22,8 +22,8 @@ const {
|
|||
} = require('../../shared/output/unbundle/as-indexed-file');
|
||||
const {concat, getModuleCode, partition, toModuleTransport} = require('./util');
|
||||
|
||||
import type {FBIndexMap} from '../../lib/SourceMap.js';
|
||||
import type {OutputFn} from '../types.flow';
|
||||
import type {FBIndexMap} from 'metro-source-map';
|
||||
|
||||
function asIndexedRamBundle({
|
||||
filename,
|
||||
|
|
|
@ -21,7 +21,7 @@ const path = require('path');
|
|||
|
||||
const {concat, getModuleCode, partition, toModuleTransport} = require('./util');
|
||||
|
||||
import type {FBIndexMap} from '../../lib/SourceMap.js';
|
||||
import type {FBIndexMap} from 'metro-source-map';
|
||||
import type {OutputFn} from '../types.flow';
|
||||
|
||||
function asMultipleFilesRamBundle({
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import type {FBSourceMap, IndexMapSection, IndexMap} from '../../lib/SourceMap';
|
||||
import type {FBSourceMap, IndexMap, IndexMapSection} from 'metro-source-map';
|
||||
|
||||
export type {FBSourceMap};
|
||||
|
||||
|
|
|
@ -11,9 +11,14 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
import type {FBSourceMap, MappingsMap, SourceMap} from '../lib/SourceMap';
|
||||
import type {Ast} from 'babel-core';
|
||||
import type {Console} from 'console';
|
||||
import type {
|
||||
FBSourceMap,
|
||||
MappingsMap,
|
||||
MetroSourceMap as SourceMap,
|
||||
} from 'metro-source-map';
|
||||
|
||||
export type {Transformer} from '../JSTransformer/worker';
|
||||
|
||||
export type BuildResult = {|
|
||||
|
|
|
@ -23,7 +23,7 @@ const optimizeDependencies = require('./optimizeDependencies');
|
|||
const sourceMap = require('source-map');
|
||||
|
||||
import type {TransformedSourceFile, TransformResult} from '../types.flow';
|
||||
import type {MappingsMap, SourceMap} from '../../lib/SourceMap';
|
||||
import type {MappingsMap, MetroSourceMap as SourceMap} from 'metro-source-map';
|
||||
import type {PostMinifyProcess} from '../../Bundler/index.js';
|
||||
|
||||
export type OptimizationOptions = {|
|
||||
|
|
|
@ -40,8 +40,9 @@ import type {
|
|||
PostMinifyProcess,
|
||||
PostProcessBundleSourcemap,
|
||||
} from '../Bundler';
|
||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
||||
import type {TransformCache} from '../lib/TransformCaching';
|
||||
import type {SourceMap, Symbolicate} from './symbolicate';
|
||||
import type {Symbolicate} from './symbolicate';
|
||||
import type {AssetData} from '../Assets';
|
||||
import type {RamBundleInfo} from '../DeltaBundler/Serializers';
|
||||
import type {PostProcessModules} from '../DeltaBundler';
|
||||
|
|
|
@ -20,8 +20,7 @@ const xpipe = require('xpipe');
|
|||
const {LazyPromise, LockingPromise} = require('./util');
|
||||
const {fork} = require('child_process');
|
||||
|
||||
export type {SourceMap};
|
||||
import type {SourceMap} from '../../lib/SourceMap';
|
||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
||||
|
||||
export type Stack = Array<{file: string, lineNumber: number, column: number}>;
|
||||
export type Symbolicate = (
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {SourceMap as MappingsMap} from 'babel-core';
|
||||
import type {RawMapping} from 'babel-generator';
|
||||
import type {RawMapping as CompactRawMapping} from 'source-map';
|
||||
|
||||
export type IndexMapSection = {
|
||||
map: SourceMap,
|
||||
offset: {line: number, column: number},
|
||||
};
|
||||
|
||||
export type RawMappings = Array<RawMapping>;
|
||||
|
||||
type FBExtensions = {
|
||||
x_facebook_offsets: Array<number>,
|
||||
x_metro_module_paths: Array<string>,
|
||||
};
|
||||
|
||||
export type {MappingsMap};
|
||||
export type IndexMap = {
|
||||
file?: string,
|
||||
mappings?: void, // avoids SourceMap being a disjoint union
|
||||
sections: Array<IndexMapSection>,
|
||||
version: number,
|
||||
};
|
||||
|
||||
export type FBIndexMap = IndexMap & FBExtensions;
|
||||
export type SourceMap = IndexMap | MappingsMap;
|
||||
export type FBSourceMap = FBIndexMap | (MappingsMap & FBExtensions);
|
||||
|
||||
export type CompactRawMappings = Array<CompactRawMapping>;
|
||||
|
||||
function isMappingsMap(map: SourceMap): %checks {
|
||||
return map.mappings !== undefined;
|
||||
}
|
||||
|
||||
exports.isMappingsMap = isMappingsMap;
|
|
@ -22,9 +22,9 @@ const rimraf = require('rimraf');
|
|||
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||
|
||||
import type {Options as WorkerOptions} from '../JSTransformer/worker';
|
||||
import type {CompactRawMappings} from './SourceMap';
|
||||
import type {Reporter} from './reporting';
|
||||
import type {LocalPath} from '../node-haste/lib/toLocalPath';
|
||||
import type {CompactRawMappings} from 'metro-source-map';
|
||||
|
||||
type CacheFilePaths = {transformedCode: string, metadata: string};
|
||||
export type GetTransformCacheKey = (options: {}) => string;
|
||||
|
|
|
@ -14,15 +14,13 @@
|
|||
|
||||
const path = require('path');
|
||||
|
||||
const {isMappingsMap} = require('./SourceMap');
|
||||
|
||||
import type {SourceMap} from './SourceMap';
|
||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
||||
|
||||
function relativizeSourceMapInternal(
|
||||
sourceMap: SourceMap,
|
||||
sourcesRoot: string,
|
||||
) {
|
||||
if (!isMappingsMap(sourceMap)) {
|
||||
if (sourceMap.mappings === undefined) {
|
||||
for (let i = 0; i < sourceMap.sections.length; i++) {
|
||||
relativizeSourceMapInternal(sourceMap.sections[i].map, sourcesRoot);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import type {
|
|||
Options as WorkerOptions,
|
||||
} from '../JSTransformer/worker';
|
||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||
import type {CompactRawMappings} from '../lib/SourceMap';
|
||||
import type {
|
||||
TransformCache,
|
||||
GetTransformCacheKey,
|
||||
|
@ -36,6 +35,7 @@ import type {Reporter} from '../lib/reporting';
|
|||
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||
import type ModuleCache from './ModuleCache';
|
||||
import type {LocalPath} from './lib/toLocalPath';
|
||||
import type {CompactRawMappings} from 'metro-source-map';
|
||||
|
||||
export type ReadResult = {
|
||||
+code: string,
|
||||
|
|
|
@ -19,8 +19,8 @@ const meta = require('./meta');
|
|||
const relativizeSourceMap = require('../../lib/relativizeSourceMap');
|
||||
const writeFile = require('./writeFile');
|
||||
|
||||
import type {SourceMap} from '../../lib/SourceMap';
|
||||
import type {OutputOptions, RequestOptions} from '../types.flow';
|
||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
||||
|
||||
function buildBundle(
|
||||
packagerClient: Server,
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
const invariant = require('fbjs/lib/invariant');
|
||||
|
||||
import type {RamModule} from '../../../DeltaBundler/Serializers';
|
||||
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
|
||||
import type {
|
||||
FBIndexMap,
|
||||
IndexMap,
|
||||
MappingsMap,
|
||||
SourceMap,
|
||||
} from '../../../lib/SourceMap';
|
||||
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
|
||||
MetroSourceMap as SourceMap,
|
||||
} from 'metro-source-map';
|
||||
|
||||
const newline = /\r\n?|\n|\u2028|\u2029/g;
|
||||
// fastest implementation
|
||||
|
|
|
@ -18,11 +18,10 @@ import type {
|
|||
} from '../Bundler';
|
||||
import type {PostProcessModules} from '../DeltaBundler';
|
||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||
import type {SourceMap} from '../lib/SourceMap';
|
||||
import type {TransformCache} from '../lib/TransformCaching';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {HasteImpl} from '../node-haste/Module';
|
||||
import type {RawMapping} from 'metro-source-map';
|
||||
import type {MetroSourceMap as SourceMap, RawMapping} from 'metro-source-map';
|
||||
|
||||
type BundleType = 'bundle' | 'delta' | 'map' | 'ram' | 'cli' | 'hmr' | 'todo';
|
||||
type SourceMapOrMappings = SourceMap | Array<RawMapping>;
|
||||
|
|
Loading…
Reference in New Issue