diff --git a/packages/metro-bundler/src/ModuleGraph/Graph.js b/packages/metro-bundler/src/ModuleGraph/Graph.js index 4e5236a0..7da3baf0 100644 --- a/packages/metro-bundler/src/ModuleGraph/Graph.js +++ b/packages/metro-bundler/src/ModuleGraph/Graph.js @@ -13,6 +13,7 @@ const emptyFunction = require('fbjs/lib/emptyFunction'); const invariant = require('fbjs/lib/invariant'); const memoize = require('async/memoize'); +const emptyModule = require('./module').empty; const nullthrows = require('fbjs/lib/nullthrows'); const queue = require('async/queue'); const seq = require('async/seq'); @@ -49,9 +50,6 @@ type Async$Queue = { type LoadQueue = Async$Queue<{id: string, parent: ?string}, Callback>>; -const createParentModule = - () => ({file: {code: '', type: 'script', path: ''}, dependencies: []}); - const NO_OPTIONS = {}; exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn { @@ -101,7 +99,7 @@ exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn { }; function createGraphHelpers(loadQueue, skip) { - const modules = new Map([[null, createParentModule()]]); + const modules = new Map([[null, emptyModule()]]); function collect( path = null, diff --git a/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js b/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js index e0018609..9b29505d 100644 --- a/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js +++ b/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js @@ -14,8 +14,7 @@ const defaults = require('../../defaults'); const nullthrows = require('fbjs/lib/nullthrows'); const parallel = require('async/parallel'); const seq = require('async/seq'); - -const {virtualModule} = require('./output/util'); +const virtualModule = require('./module').virtual; import type { Callback, diff --git a/packages/metro-bundler/src/ModuleGraph/__tests__/ModuleGraph-test.js b/packages/metro-bundler/src/ModuleGraph/__tests__/ModuleGraph-test.js index 334ea931..f51566b6 100644 --- a/packages/metro-bundler/src/ModuleGraph/__tests__/ModuleGraph-test.js +++ b/packages/metro-bundler/src/ModuleGraph/__tests__/ModuleGraph-test.js @@ -32,6 +32,7 @@ describe('build setup', () => { file: { code: 'var __DEV__=true,__BUNDLE_START_TIME__=' + 'this.nativePerformanceNow?nativePerformanceNow():Date.now();', + map: null, path: '', type: 'script', }, diff --git a/packages/metro-bundler/src/ModuleGraph/module.js b/packages/metro-bundler/src/ModuleGraph/module.js new file mode 100644 index 00000000..05f8e72f --- /dev/null +++ b/packages/metro-bundler/src/ModuleGraph/module.js @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2016-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 + */ +'use strict'; + + +import type {Module} from './types.flow'; + +exports.empty = (): Module => virtual(''); + +// creates a virtual module (i.e. not corresponding to a file on disk) +// with the given source code. +const virtual = exports.virtual = (code: string): Module => ({ + dependencies: [], + file: { + code, + map: null, + path: '', + type: 'script', + }, +}); diff --git a/packages/metro-bundler/src/ModuleGraph/output/util.js b/packages/metro-bundler/src/ModuleGraph/output/util.js index eb84ed88..f9a652a7 100644 --- a/packages/metro-bundler/src/ModuleGraph/output/util.js +++ b/packages/metro-bundler/src/ModuleGraph/output/util.js @@ -10,6 +10,8 @@ */ 'use strict'; +const virtualModule = require('../module').virtual; + import type {IdForPathFn, Module} from '../types.flow'; // Transformed modules have the form @@ -77,17 +79,3 @@ exports.requireCallsTo = function* ( yield virtualModule(`require(${idForPath(module.file)});`); } }; - -// creates a virtual module (i.e. not corresponding to a file on disk) -// with the given source code. -exports.virtualModule = virtualModule; -function virtualModule(code: string) { - return { - dependencies: [], - file: { - code, - path: '', - type: 'script', - }, - }; -} diff --git a/packages/metro-bundler/src/ModuleGraph/types.flow.js b/packages/metro-bundler/src/ModuleGraph/types.flow.js index 5820ddaf..4f66d303 100644 --- a/packages/metro-bundler/src/ModuleGraph/types.flow.js +++ b/packages/metro-bundler/src/ModuleGraph/types.flow.js @@ -26,7 +26,7 @@ type Dependency = {| export type File = {| code: string, - map?: ?MappingsMap, + map: ?MappingsMap, path: string, type: CodeFileTypes, |};