mirror of https://github.com/status-im/metro.git
Break out defaults, add flow for Config
Summary: In order to make `Config` and defaults available to our new code, I’ve added flow types and put default values into one shared modile Reviewed By: cpojer Differential Revision: D4044600 fbshipit-source-id: 875ed3ade69c5b22bb3c1b177e7bad732834d476
This commit is contained in:
parent
74a5b35802
commit
f6f2c6259b
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"rules": {
|
"rules": {
|
||||||
"extra-arrow-initializer": 0
|
"extra-arrow-initializer": 0,
|
||||||
|
"no-console-disallow": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +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.
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = [
|
|
||||||
'bmp', 'gif', 'jpg', 'jpeg', 'png', 'psd', 'svg', 'webp', // Image formats
|
|
||||||
'm4v', 'mov', 'mp4', 'mpeg', 'mpg', 'webm', // Video formats
|
|
||||||
'aac', 'aiff', 'caf', 'm4a', 'mp3', 'wav', // Audio formats
|
|
||||||
'html', 'pdf', // Document formats
|
|
||||||
];
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
exports.assetExts = [
|
||||||
|
'bmp', 'gif', 'jpg', 'jpeg', 'png', 'psd', 'svg', 'webp', // Image formats
|
||||||
|
'm4v', 'mov', 'mp4', 'mpeg', 'mpg', 'webm', // Video formats
|
||||||
|
'aac', 'aiff', 'caf', 'm4a', 'mp3', 'wav', // Audio formats
|
||||||
|
'html', 'pdf', // Document formats
|
||||||
|
];
|
||||||
|
|
||||||
|
exports.moduleSystem = require.resolve('./react-packager/src/Resolver/polyfills/require.js');
|
||||||
|
|
||||||
|
exports.platforms = ['ios', 'android', 'windows', 'web'];
|
||||||
|
|
||||||
|
exports.polyfills = [
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/polyfills.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/console.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/error-guard.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/Number.es6.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/String.prototype.es6.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/Array.prototype.es6.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/Array.es6.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/Object.es7.js'),
|
||||||
|
require.resolve('./react-packager/src/Resolver/polyfills/babelHelpers.js'),
|
||||||
|
];
|
||||||
|
|
||||||
|
exports.providesModuleNodeModules = [
|
||||||
|
'react-native',
|
||||||
|
'react-native-windows',
|
||||||
|
// Parse requires AsyncStorage. They will
|
||||||
|
// change that to require('react-native') which
|
||||||
|
// should work after this release and we can
|
||||||
|
// remove it from here.
|
||||||
|
'parse',
|
||||||
|
];
|
||||||
|
|
||||||
|
exports.runBeforeMainModule = [
|
||||||
|
// Ensures essential globals are available and are patched correctly.
|
||||||
|
'InitializeCore',
|
||||||
|
];
|
|
@ -9,9 +9,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
jest.unmock('../');
|
jest.unmock('../');
|
||||||
|
jest.unmock('../../../../defaults');
|
||||||
jest.mock('path');
|
jest.mock('path');
|
||||||
|
|
||||||
|
const {join: pathJoin} = require.requireActual('path');
|
||||||
const DependencyGraph = jest.fn();
|
const DependencyGraph = jest.fn();
|
||||||
jest.setMock('../../node-haste', DependencyGraph);
|
jest.setMock('../../node-haste', DependencyGraph);
|
||||||
let Module;
|
let Module;
|
||||||
|
@ -219,7 +220,11 @@ describe('Resolver', function() {
|
||||||
'polyfills/Object.es7.js',
|
'polyfills/Object.es7.js',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
].map(({id, file, dependencies}) => ({
|
||||||
|
id: pathJoin(__dirname, '..', id),
|
||||||
|
file: pathJoin(__dirname, '..', file),
|
||||||
|
dependencies: dependencies.map((d => pathJoin(__dirname, '..', d))),
|
||||||
|
})));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -295,7 +300,7 @@ describe('Resolver', function() {
|
||||||
'polyfills/Array.es6.js',
|
'polyfills/Array.es6.js',
|
||||||
'polyfills/Object.es7.js',
|
'polyfills/Object.es7.js',
|
||||||
'polyfills/babelHelpers.js',
|
'polyfills/babelHelpers.js',
|
||||||
]
|
].map(d => pathJoin(__dirname, '..', d))
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,11 +9,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const Activity = require('../Activity');
|
const Activity = require('../Activity');
|
||||||
const DependencyGraph = require('../node-haste');
|
const DependencyGraph = require('../node-haste');
|
||||||
|
|
||||||
const declareOpts = require('../lib/declareOpts');
|
const declareOpts = require('../lib/declareOpts');
|
||||||
const Promise = require('promise');
|
const defaults = require('../../../defaults');
|
||||||
|
const pathJoin = require('path').join;
|
||||||
|
|
||||||
const validateOpts = declareOpts({
|
const validateOpts = declareOpts({
|
||||||
projectRoots: {
|
projectRoots: {
|
||||||
|
@ -74,7 +75,7 @@ const getDependenciesValidateOpts = declareOpts({
|
||||||
},
|
},
|
||||||
unbundle: {
|
unbundle: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
recursive: {
|
recursive: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
@ -96,16 +97,8 @@ class Resolver {
|
||||||
return filepath.indexOf('__tests__') !== -1 ||
|
return filepath.indexOf('__tests__') !== -1 ||
|
||||||
(opts.blacklistRE && opts.blacklistRE.test(filepath));
|
(opts.blacklistRE && opts.blacklistRE.test(filepath));
|
||||||
},
|
},
|
||||||
providesModuleNodeModules: [
|
providesModuleNodeModules: defaults.providesModuleNodeModules,
|
||||||
'react-native',
|
platforms: defaults.platforms,
|
||||||
'react-native-windows',
|
|
||||||
// Parse requires AsyncStorage. They will
|
|
||||||
// change that to require('react-native') which
|
|
||||||
// should work after this release and we can
|
|
||||||
// remove it from here.
|
|
||||||
'parse',
|
|
||||||
],
|
|
||||||
platforms: ['ios', 'android', 'windows', 'web'],
|
|
||||||
preferNativePlatform: true,
|
preferNativePlatform: true,
|
||||||
fileWatcher: opts.fileWatcher,
|
fileWatcher: opts.fileWatcher,
|
||||||
cache: opts.cache,
|
cache: opts.cache,
|
||||||
|
@ -160,14 +153,14 @@ class Resolver {
|
||||||
const opts = getDependenciesValidateOpts(options);
|
const opts = getDependenciesValidateOpts(options);
|
||||||
|
|
||||||
const prelude = opts.dev
|
const prelude = opts.dev
|
||||||
? path.join(__dirname, 'polyfills/prelude_dev.js')
|
? pathJoin(__dirname, 'polyfills/prelude_dev.js')
|
||||||
: path.join(__dirname, 'polyfills/prelude.js');
|
: pathJoin(__dirname, 'polyfills/prelude.js');
|
||||||
|
|
||||||
const moduleSystem = path.join(__dirname, 'polyfills/require.js');
|
const moduleSystem = defaults.moduleSystem;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
prelude,
|
prelude,
|
||||||
moduleSystem
|
moduleSystem,
|
||||||
].map(moduleName => this._depGraph.createPolyfill({
|
].map(moduleName => this._depGraph.createPolyfill({
|
||||||
file: moduleName,
|
file: moduleName,
|
||||||
id: moduleName,
|
id: moduleName,
|
||||||
|
@ -176,17 +169,7 @@ class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
_getPolyfillDependencies() {
|
_getPolyfillDependencies() {
|
||||||
const polyfillModuleNames = [
|
const polyfillModuleNames = defaults.polyfills.concat(this._polyfillModuleNames);
|
||||||
path.join(__dirname, 'polyfills/polyfills.js'),
|
|
||||||
path.join(__dirname, 'polyfills/console.js'),
|
|
||||||
path.join(__dirname, 'polyfills/error-guard.js'),
|
|
||||||
path.join(__dirname, 'polyfills/Number.es6.js'),
|
|
||||||
path.join(__dirname, 'polyfills/String.prototype.es6.js'),
|
|
||||||
path.join(__dirname, 'polyfills/Array.prototype.es6.js'),
|
|
||||||
path.join(__dirname, 'polyfills/Array.es6.js'),
|
|
||||||
path.join(__dirname, 'polyfills/Object.es7.js'),
|
|
||||||
path.join(__dirname, 'polyfills/babelHelpers.js'),
|
|
||||||
].concat(this._polyfillModuleNames);
|
|
||||||
|
|
||||||
return polyfillModuleNames.map(
|
return polyfillModuleNames.map(
|
||||||
(polyfillModuleName, idx) => this._depGraph.createPolyfill({
|
(polyfillModuleName, idx) => this._depGraph.createPolyfill({
|
||||||
|
@ -242,7 +225,7 @@ class Resolver {
|
||||||
code,
|
code,
|
||||||
meta = {},
|
meta = {},
|
||||||
dev = true,
|
dev = true,
|
||||||
minify = false
|
minify = false,
|
||||||
}) {
|
}) {
|
||||||
if (module.isJSON()) {
|
if (module.isJSON()) {
|
||||||
code = `module.exports = ${code}`;
|
code = `module.exports = ${code}`;
|
||||||
|
|
|
@ -19,7 +19,7 @@ const Promise = require('promise');
|
||||||
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||||
|
|
||||||
const declareOpts = require('../lib/declareOpts');
|
const declareOpts = require('../lib/declareOpts');
|
||||||
const defaultAssetExts = require('../../../defaultAssetExts');
|
const defaults = require('../../../defaults');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
@ -81,7 +81,7 @@ const validateOpts = declareOpts({
|
||||||
},
|
},
|
||||||
assetExts: {
|
assetExts: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
default: defaultAssetExts,
|
default: defaults.assetExts,
|
||||||
},
|
},
|
||||||
transformTimeoutInterval: {
|
transformTimeoutInterval: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -128,10 +128,7 @@ const bundleOpts = declareOpts({
|
||||||
},
|
},
|
||||||
runBeforeMainModule: {
|
runBeforeMainModule: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
default: [
|
default: defaults.runBeforeMainModule,
|
||||||
// Ensures essential globals are available and are patched correctly.
|
|
||||||
'InitializeCore'
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
unbundle: {
|
unbundle: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
@ -147,7 +144,7 @@ const bundleOpts = declareOpts({
|
||||||
},
|
},
|
||||||
isolateModuleIDs: {
|
isolateModuleIDs: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
resolutionResponse: {
|
resolutionResponse: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -487,7 +484,7 @@ class Server {
|
||||||
'Accept-Ranges': 'bytes',
|
'Accept-Ranges': 'bytes',
|
||||||
'Content-Length': chunksize,
|
'Content-Length': chunksize,
|
||||||
'Content-Range': `bytes ${dataStart}-${dataEnd}/${data.length}`,
|
'Content-Range': `bytes ${dataStart}-${dataEnd}/${data.length}`,
|
||||||
'Content-Type': mime.lookup(path.basename(assetPath[1]))
|
'Content-Type': mime.lookup(path.basename(assetPath[1])),
|
||||||
});
|
});
|
||||||
|
|
||||||
return data.slice(dataStart, dataEnd + 1);
|
return data.slice(dataStart, dataEnd + 1);
|
||||||
|
@ -585,7 +582,7 @@ class Server {
|
||||||
...options,
|
...options,
|
||||||
resolutionResponse: response.copy({
|
resolutionResponse: response.copy({
|
||||||
dependencies: changedModules,
|
dependencies: changedModules,
|
||||||
})
|
}),
|
||||||
}).then(updateBundle => {
|
}).then(updateBundle => {
|
||||||
const oldModules = bundle.getModules();
|
const oldModules = bundle.getModules();
|
||||||
const newModules = updateBundle.getModules();
|
const newModules = updateBundle.getModules();
|
||||||
|
|
Loading…
Reference in New Issue