mirror of https://github.com/status-im/metro.git
Simplify `File` type: `map` is nullable, but not optional
Summary: Simplifies the `File` type by making `map` a non-optional, but nullable property. Also adds helper functions for empty/virtual modules Reviewed By: jeanlauliac Differential Revision: D5111580 fbshipit-source-id: 9cab6634a9bdb0522dc36aec2abccaef9cf35339
This commit is contained in:
parent
7b5d91f359
commit
132d71f0a3
|
@ -13,6 +13,7 @@
|
||||||
const emptyFunction = require('fbjs/lib/emptyFunction');
|
const emptyFunction = require('fbjs/lib/emptyFunction');
|
||||||
const invariant = require('fbjs/lib/invariant');
|
const invariant = require('fbjs/lib/invariant');
|
||||||
const memoize = require('async/memoize');
|
const memoize = require('async/memoize');
|
||||||
|
const emptyModule = require('./module').empty;
|
||||||
const nullthrows = require('fbjs/lib/nullthrows');
|
const nullthrows = require('fbjs/lib/nullthrows');
|
||||||
const queue = require('async/queue');
|
const queue = require('async/queue');
|
||||||
const seq = require('async/seq');
|
const seq = require('async/seq');
|
||||||
|
@ -49,9 +50,6 @@ type Async$Queue<T, C> = {
|
||||||
type LoadQueue =
|
type LoadQueue =
|
||||||
Async$Queue<{id: string, parent: ?string}, Callback<File, Array<string>>>;
|
Async$Queue<{id: string, parent: ?string}, Callback<File, Array<string>>>;
|
||||||
|
|
||||||
const createParentModule =
|
|
||||||
() => ({file: {code: '', type: 'script', path: ''}, dependencies: []});
|
|
||||||
|
|
||||||
const NO_OPTIONS = {};
|
const NO_OPTIONS = {};
|
||||||
|
|
||||||
exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn {
|
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) {
|
function createGraphHelpers(loadQueue, skip) {
|
||||||
const modules = new Map([[null, createParentModule()]]);
|
const modules = new Map([[null, emptyModule()]]);
|
||||||
|
|
||||||
function collect(
|
function collect(
|
||||||
path = null,
|
path = null,
|
||||||
|
|
|
@ -14,8 +14,7 @@ const defaults = require('../../defaults');
|
||||||
const nullthrows = require('fbjs/lib/nullthrows');
|
const nullthrows = require('fbjs/lib/nullthrows');
|
||||||
const parallel = require('async/parallel');
|
const parallel = require('async/parallel');
|
||||||
const seq = require('async/seq');
|
const seq = require('async/seq');
|
||||||
|
const virtualModule = require('./module').virtual;
|
||||||
const {virtualModule} = require('./output/util');
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Callback,
|
Callback,
|
||||||
|
|
|
@ -32,6 +32,7 @@ describe('build setup', () => {
|
||||||
file: {
|
file: {
|
||||||
code: 'var __DEV__=true,__BUNDLE_START_TIME__=' +
|
code: 'var __DEV__=true,__BUNDLE_START_TIME__=' +
|
||||||
'this.nativePerformanceNow?nativePerformanceNow():Date.now();',
|
'this.nativePerformanceNow?nativePerformanceNow():Date.now();',
|
||||||
|
map: null,
|
||||||
path: '',
|
path: '',
|
||||||
type: 'script',
|
type: 'script',
|
||||||
},
|
},
|
||||||
|
|
|
@ -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',
|
||||||
|
},
|
||||||
|
});
|
|
@ -10,6 +10,8 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const virtualModule = require('../module').virtual;
|
||||||
|
|
||||||
import type {IdForPathFn, Module} from '../types.flow';
|
import type {IdForPathFn, Module} from '../types.flow';
|
||||||
|
|
||||||
// Transformed modules have the form
|
// Transformed modules have the form
|
||||||
|
@ -77,17 +79,3 @@ exports.requireCallsTo = function* (
|
||||||
yield virtualModule(`require(${idForPath(module.file)});`);
|
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',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ type Dependency = {|
|
||||||
|
|
||||||
export type File = {|
|
export type File = {|
|
||||||
code: string,
|
code: string,
|
||||||
map?: ?MappingsMap,
|
map: ?MappingsMap,
|
||||||
path: string,
|
path: string,
|
||||||
type: CodeFileTypes,
|
type: CodeFileTypes,
|
||||||
|};
|
|};
|
||||||
|
|
Loading…
Reference in New Issue