@@ -28,8 +28,7 @@ const debug = require('debug')('Metro:Server');
28
28
const formatBundlingError = require ( './lib/formatBundlingError' ) ;
29
29
const getPrependedScripts = require ( './lib/getPrependedScripts' ) ;
30
30
const mime = require ( 'mime-types' ) ;
31
- const nullthrows = require ( 'nullthrows' ) ;
32
- const parseCustomTransformOptions = require ( './lib/parseCustomTransformOptions' ) ;
31
+ const parseOptionsFromUrl = require ( './lib/parseOptionsFromUrl' ) ;
33
32
const parsePlatformFilePath = require ( './node-haste/lib/parsePlatformFilePath' ) ;
34
33
const path = require ( 'path' ) ;
35
34
const symbolicate = require ( './Server/symbolicate/symbolicate' ) ;
@@ -49,6 +48,7 @@ import type {MetroSourceMap} from 'metro-source-map';
49
48
import type { Symbolicate } from './Server/symbolicate/symbolicate' ;
50
49
import type { AssetData } from './Assets' ;
51
50
import type { TransformInputOptions } from './lib/transformHelpers' ;
51
+ import type { DeltaOptions } from './lib/parseOptionsFromUrl' ;
52
52
53
53
const {
54
54
Logger,
@@ -64,10 +64,6 @@ type GraphInfo = {|
64
64
65
65
export type OutputGraph = Graph < > ;
66
66
67
- type DeltaOptions = BundleOptions & {
68
- deltaBundleId : ?string ,
69
- } ;
70
-
71
67
function debounceAndBatch ( fn , delay ) {
72
68
let timeout ;
73
69
return ( ) => {
@@ -567,12 +563,14 @@ class Server {
567
563
req : IncomingMessage ,
568
564
mres : MultipartResponse ,
569
565
) : { options : DeltaOptions , buildID : string } {
570
- const options = this . _getOptionsFromUrl (
566
+ const options = parseOptionsFromUrl (
571
567
url . format ( {
572
568
...url . parse ( req . url ) ,
573
569
protocol : 'http' ,
574
570
host : req . headers . host ,
575
571
} ) ,
572
+ this . _config . projectRoot ,
573
+ new Set ( this . _config . resolver . platforms ) ,
576
574
) ;
577
575
578
576
const buildID = this . getNewBuildID ( ) ;
@@ -931,7 +929,11 @@ class Server {
931
929
}
932
930
933
931
async _sourceMapForURL ( reqUrl : string ) : Promise < MetroSourceMap > {
934
- const options : DeltaOptions = this . _getOptionsFromUrl ( reqUrl ) ;
932
+ const options : DeltaOptions = parseOptionsFromUrl (
933
+ reqUrl ,
934
+ this . _config . projectRoot ,
935
+ new Set ( this . _config . resolver . platforms ) ,
936
+ ) ;
935
937
936
938
const { graph, prepend} = await this . _getGraphInfo ( options , {
937
939
rebuild : false ,
@@ -967,96 +969,6 @@ class Server {
967
969
} ) ;
968
970
}
969
971
970
- _getOptionsFromUrl ( reqUrl : string ) : DeltaOptions {
971
- // `true` to parse the query param as an object.
972
- const urlObj = nullthrows ( url . parse ( reqUrl , true ) ) ;
973
- const urlQuery = nullthrows ( urlObj . query ) ;
974
-
975
- const pathname = urlObj . pathname ? decodeURIComponent ( urlObj . pathname ) : '' ;
976
-
977
- let isMap = false ;
978
-
979
- // Backwards compatibility. Options used to be as added as '.' to the
980
- // entry module name. We can safely remove these options.
981
- const entryFile =
982
- pathname
983
- . replace ( / ^ \/ / , '' )
984
- . split ( '.' )
985
- . filter ( part => {
986
- if ( part === 'map' ) {
987
- isMap = true ;
988
- return false ;
989
- }
990
- if (
991
- part === 'includeRequire' ||
992
- part === 'runModule' ||
993
- part === 'bundle' ||
994
- part === 'delta' ||
995
- part === 'assets'
996
- ) {
997
- return false ;
998
- }
999
- return true ;
1000
- } )
1001
- . join ( '.' ) + '.js' ;
1002
-
1003
- const absoluteEntryFile = path . resolve ( this . _config . projectRoot , entryFile ) ;
1004
-
1005
- // try to get the platform from the url
1006
- const platform =
1007
- urlQuery . platform ||
1008
- parsePlatformFilePath ( pathname , this . _platforms ) . platform ;
1009
-
1010
- const deltaBundleId = urlQuery . deltaBundleId ;
1011
-
1012
- const dev = this . _getBoolOptionFromQuery ( urlQuery , 'dev' , true ) ;
1013
- const minify = this . _getBoolOptionFromQuery ( urlQuery , 'minify' , false ) ;
1014
- const excludeSource = this . _getBoolOptionFromQuery (
1015
- urlQuery ,
1016
- 'excludeSource' ,
1017
- false ,
1018
- ) ;
1019
- const includeSource = this . _getBoolOptionFromQuery (
1020
- urlQuery ,
1021
- 'inlineSourceMap' ,
1022
- false ,
1023
- ) ;
1024
-
1025
- const customTransformOptions = parseCustomTransformOptions ( urlObj ) ;
1026
-
1027
- return {
1028
- sourceMapUrl : url . format ( {
1029
- ...urlObj ,
1030
- pathname : pathname . replace ( / \. ( b u n d l e | d e l t a ) $ / , '.map' ) ,
1031
- } ) ,
1032
- bundleType : isMap ? 'map ' : deltaBundleId ? 'delta ' : 'bundle ',
1033
- customTransformOptions ,
1034
- entryFile : absoluteEntryFile ,
1035
- deltaBundleId ,
1036
- dev ,
1037
- minify ,
1038
- excludeSource ,
1039
- hot : true ,
1040
- runModule : this . _getBoolOptionFromQuery ( urlObj . query , 'runModule' , true ) ,
1041
- inlineSourceMap : includeSource ,
1042
- platform ,
1043
- onProgress : null ,
1044
- } ;
1045
- }
1046
-
1047
- _getBoolOptionFromQuery (
1048
- query : ?{ } ,
1049
- opt : string ,
1050
- defaultVal : boolean ,
1051
- ) : boolean {
1052
- /* $FlowFixMe: `query` could be empty when it comes from an invalid URL */
1053
- if ( query [ opt ] == null ) {
1054
- return defaultVal ;
1055
- }
1056
-
1057
- return query [ opt ] === 'true' || query [ opt ] === '1' ;
1058
- }
1059
-
1060
972
getGraphs ( ) : Map < string , Promise < GraphInfo >> {
1061
973
return this . _graphs ;
1062
974
}
0 commit comments