mirror of https://github.com/status-im/metro.git
Stop using `as SourceMap` and just use `MetroSourceMap` instead
Reviewed By: rafeca Differential Revision: D6702882 fbshipit-source-id: ef4a58569719bd8aeb8f1869943929c255f89595
This commit is contained in:
parent
4697ecf120
commit
a05eb11cab
|
@ -35,7 +35,7 @@ import type {HasteImpl} from '../node-haste/Module';
|
||||||
import type {BabelSourceMap} from 'babel-core';
|
import type {BabelSourceMap} from 'babel-core';
|
||||||
import type {
|
import type {
|
||||||
MetroSourceMapSegmentTuple,
|
MetroSourceMapSegmentTuple,
|
||||||
MetroSourceMap as SourceMap,
|
MetroSourceMap,
|
||||||
} from 'metro-source-map';
|
} from 'metro-source-map';
|
||||||
|
|
||||||
export type BundlingOptions = {|
|
export type BundlingOptions = {|
|
||||||
|
@ -73,9 +73,9 @@ export type PostMinifyProcess = ({
|
||||||
|
|
||||||
export type PostProcessBundleSourcemap = ({
|
export type PostProcessBundleSourcemap = ({
|
||||||
code: Buffer | string,
|
code: Buffer | string,
|
||||||
map: SourceMap,
|
map: MetroSourceMap,
|
||||||
outFileName: string,
|
outFileName: string,
|
||||||
}) => {code: Buffer | string, map: SourceMap | string};
|
}) => {code: Buffer | string, map: MetroSourceMap | string};
|
||||||
|
|
||||||
export type Options = {|
|
export type Options = {|
|
||||||
+assetExts: Array<string>,
|
+assetExts: Array<string>,
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
import type {Ast} from 'babel-core';
|
import type {Ast} from 'babel-core';
|
||||||
import type {BabelSourceMap} from 'babel-core';
|
import type {BabelSourceMap} from 'babel-core';
|
||||||
import type {Console} from 'console';
|
import type {Console} from 'console';
|
||||||
import type {FBSourceMap, MetroSourceMap as SourceMap} from 'metro-source-map';
|
import type {FBSourceMap, MetroSourceMap} from 'metro-source-map';
|
||||||
|
|
||||||
export type {Transformer} from '../JSTransformer/worker';
|
export type {Transformer} from '../JSTransformer/worker';
|
||||||
|
|
||||||
|
@ -106,7 +106,9 @@ export type PostProcessModules = (
|
||||||
entryPoints: Array<string>,
|
entryPoints: Array<string>,
|
||||||
) => Iterable<Module>;
|
) => Iterable<Module>;
|
||||||
|
|
||||||
export type OutputFn<M: FBSourceMap | SourceMap = FBSourceMap | SourceMap> = ({|
|
export type OutputFn<
|
||||||
|
M: FBSourceMap | MetroSourceMap = FBSourceMap | MetroSourceMap,
|
||||||
|
> = ({|
|
||||||
filename: string,
|
filename: string,
|
||||||
idsForPath: IdsForPathFn,
|
idsForPath: IdsForPathFn,
|
||||||
modules: Iterable<Module>,
|
modules: Iterable<Module>,
|
||||||
|
@ -114,7 +116,7 @@ export type OutputFn<M: FBSourceMap | SourceMap = FBSourceMap | SourceMap> = ({|
|
||||||
sourceMapPath?: ?string,
|
sourceMapPath?: ?string,
|
||||||
|}) => OutputResult<M>;
|
|}) => OutputResult<M>;
|
||||||
|
|
||||||
type OutputResult<M: FBSourceMap | SourceMap> = {|
|
type OutputResult<M: FBSourceMap | MetroSourceMap> = {|
|
||||||
code: string | Buffer,
|
code: string | Buffer,
|
||||||
extraFiles?: Iterable<[string, string | Buffer]>,
|
extraFiles?: Iterable<[string, string | Buffer]>,
|
||||||
map: M,
|
map: M,
|
||||||
|
|
|
@ -24,7 +24,7 @@ const sourceMap = require('source-map');
|
||||||
|
|
||||||
import type {TransformedSourceFile, TransformResult} from '../types.flow';
|
import type {TransformedSourceFile, TransformResult} from '../types.flow';
|
||||||
import type {BabelSourceMap} from 'babel-core';
|
import type {BabelSourceMap} from 'babel-core';
|
||||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
import type {MetroSourceMap} from 'metro-source-map';
|
||||||
import type {PostMinifyProcess} from '../../Bundler/index.js';
|
import type {PostMinifyProcess} from '../../Bundler/index.js';
|
||||||
|
|
||||||
export type OptimizationOptions = {|
|
export type OptimizationOptions = {|
|
||||||
|
@ -111,8 +111,8 @@ function optimizeCode(code, map, filename, inliningOptions) {
|
||||||
|
|
||||||
function mergeSourceMaps(
|
function mergeSourceMaps(
|
||||||
file: string,
|
file: string,
|
||||||
originalMap: SourceMap,
|
originalMap: MetroSourceMap,
|
||||||
secondMap: SourceMap,
|
secondMap: MetroSourceMap,
|
||||||
): BabelSourceMap {
|
): BabelSourceMap {
|
||||||
const merged = new sourceMap.SourceMapGenerator();
|
const merged = new sourceMap.SourceMapGenerator();
|
||||||
const inputMap = new sourceMap.SourceMapConsumer(originalMap);
|
const inputMap = new sourceMap.SourceMapConsumer(originalMap);
|
||||||
|
|
|
@ -40,7 +40,7 @@ import type {
|
||||||
PostMinifyProcess,
|
PostMinifyProcess,
|
||||||
PostProcessBundleSourcemap,
|
PostProcessBundleSourcemap,
|
||||||
} from '../Bundler';
|
} from '../Bundler';
|
||||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
import type {MetroSourceMap} from 'metro-source-map';
|
||||||
import type {TransformCache} from '../lib/TransformCaching';
|
import type {TransformCache} from '../lib/TransformCaching';
|
||||||
import type {Symbolicate} from './symbolicate';
|
import type {Symbolicate} from './symbolicate';
|
||||||
import type {AssetData} from '../Assets';
|
import type {AssetData} from '../Assets';
|
||||||
|
@ -731,7 +731,7 @@ class Server {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _sourceMapForURL(reqUrl: string): Promise<SourceMap> {
|
async _sourceMapForURL(reqUrl: string): Promise<MetroSourceMap> {
|
||||||
const options: DeltaBundlerOptions = this._getOptionsFromUrl(reqUrl);
|
const options: DeltaBundlerOptions = this._getOptionsFromUrl(reqUrl);
|
||||||
|
|
||||||
return await Serializers.fullSourceMapObject(this._deltaBundler, {
|
return await Serializers.fullSourceMapObject(this._deltaBundler, {
|
||||||
|
|
|
@ -20,12 +20,12 @@ const xpipe = require('xpipe');
|
||||||
const {LazyPromise, LockingPromise} = require('./util');
|
const {LazyPromise, LockingPromise} = require('./util');
|
||||||
const {fork} = require('child_process');
|
const {fork} = require('child_process');
|
||||||
|
|
||||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
import type {MetroSourceMap} from 'metro-source-map';
|
||||||
|
|
||||||
export type Stack = Array<{file: string, lineNumber: number, column: number}>;
|
export type Stack = Array<{file: string, lineNumber: number, column: number}>;
|
||||||
export type Symbolicate = (
|
export type Symbolicate = (
|
||||||
Stack,
|
Stack,
|
||||||
Iterable<[string, SourceMap]>,
|
Iterable<[string, MetroSourceMap]>,
|
||||||
) => Promise<Stack>;
|
) => Promise<Stack>;
|
||||||
|
|
||||||
const affixes = {prefix: 'metro-symbolicate', suffix: '.sock'};
|
const affixes = {prefix: 'metro-symbolicate', suffix: '.sock'};
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
import type {MetroSourceMap} from 'metro-source-map';
|
||||||
|
|
||||||
function relativizeSourceMapInternal(
|
function relativizeSourceMapInternal(
|
||||||
sourceMap: SourceMap,
|
sourceMap: MetroSourceMap,
|
||||||
sourcesRoot: string,
|
sourcesRoot: string,
|
||||||
) {
|
) {
|
||||||
if (sourceMap.mappings === undefined) {
|
if (sourceMap.mappings === undefined) {
|
||||||
|
@ -32,9 +32,9 @@ function relativizeSourceMapInternal(
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativizeSourceMap(
|
function relativizeSourceMap(
|
||||||
sourceMap: SourceMap,
|
sourceMap: MetroSourceMap,
|
||||||
sourcesRoot?: string,
|
sourcesRoot?: string,
|
||||||
): SourceMap {
|
): MetroSourceMap {
|
||||||
if (!sourcesRoot) {
|
if (!sourcesRoot) {
|
||||||
return sourceMap;
|
return sourceMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ const relativizeSourceMap = require('../../lib/relativizeSourceMap');
|
||||||
const writeFile = require('./writeFile');
|
const writeFile = require('./writeFile');
|
||||||
|
|
||||||
import type {OutputOptions, RequestOptions} from '../types.flow';
|
import type {OutputOptions, RequestOptions} from '../types.flow';
|
||||||
import type {MetroSourceMap as SourceMap} from 'metro-source-map';
|
import type {MetroSourceMap} from 'metro-source-map';
|
||||||
|
|
||||||
function buildBundle(
|
function buildBundle(
|
||||||
packagerClient: Server,
|
packagerClient: Server,
|
||||||
|
@ -38,10 +38,10 @@ function createCodeWithMap(
|
||||||
bundle: {code: string, map: string},
|
bundle: {code: string, map: string},
|
||||||
dev: boolean,
|
dev: boolean,
|
||||||
sourceMapSourcesRoot?: string,
|
sourceMapSourcesRoot?: string,
|
||||||
): {code: string, map: SourceMap} {
|
): {code: string, map: MetroSourceMap} {
|
||||||
const map = bundle.map;
|
const map = bundle.map;
|
||||||
const sourceMap = relativizeSourceMap(
|
const sourceMap = relativizeSourceMap(
|
||||||
(JSON.parse(map): SourceMap),
|
(JSON.parse(map): MetroSourceMap),
|
||||||
sourceMapSourcesRoot,
|
sourceMapSourcesRoot,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -16,11 +16,7 @@ const invariant = require('fbjs/lib/invariant');
|
||||||
import type {RamModule} from '../../../DeltaBundler/Serializers';
|
import type {RamModule} from '../../../DeltaBundler/Serializers';
|
||||||
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
|
import type {ModuleGroups, ModuleTransportLike} from '../../types.flow';
|
||||||
import type {BabelSourceMap} from 'babel-core';
|
import type {BabelSourceMap} from 'babel-core';
|
||||||
import type {
|
import type {FBIndexMap, IndexMap, MetroSourceMap} from 'metro-source-map';
|
||||||
FBIndexMap,
|
|
||||||
IndexMap,
|
|
||||||
MetroSourceMap as SourceMap,
|
|
||||||
} from 'metro-source-map';
|
|
||||||
|
|
||||||
const newline = /\r\n?|\n|\u2028|\u2029/g;
|
const newline = /\r\n?|\n|\u2028|\u2029/g;
|
||||||
// fastest implementation
|
// fastest implementation
|
||||||
|
@ -48,7 +44,7 @@ function lineToLineSourceMap(
|
||||||
|
|
||||||
const wrapperEnd = wrappedCode => wrappedCode.indexOf('{') + 1;
|
const wrapperEnd = wrappedCode => wrappedCode.indexOf('{') + 1;
|
||||||
|
|
||||||
const Section = (line: number, column: number, map: SourceMap) => ({
|
const Section = (line: number, column: number, map: MetroSourceMap) => ({
|
||||||
map,
|
map,
|
||||||
offset: {line, column},
|
offset: {line, column},
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,12 +22,12 @@ import type {TransformCache} from '../lib/TransformCaching';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
import type {HasteImpl} from '../node-haste/Module';
|
import type {HasteImpl} from '../node-haste/Module';
|
||||||
import type {
|
import type {
|
||||||
MetroSourceMap as SourceMap,
|
MetroSourceMap,
|
||||||
MetroSourceMapSegmentTuple,
|
MetroSourceMapSegmentTuple,
|
||||||
} from 'metro-source-map';
|
} from 'metro-source-map';
|
||||||
|
|
||||||
type BundleType = 'bundle' | 'delta' | 'map' | 'ram' | 'cli' | 'hmr' | 'todo';
|
type BundleType = 'bundle' | 'delta' | 'map' | 'ram' | 'cli' | 'hmr' | 'todo';
|
||||||
type SourceMapOrMappings = SourceMap | Array<MetroSourceMapSegmentTuple>;
|
type SourceMapOrMappings = MetroSourceMap | Array<MetroSourceMapSegmentTuple>;
|
||||||
|
|
||||||
export type BundleOptions = {
|
export type BundleOptions = {
|
||||||
+assetPlugins: Array<string>,
|
+assetPlugins: Array<string>,
|
||||||
|
|
Loading…
Reference in New Issue