mirror of https://github.com/status-im/metro.git
Updates from Wed Feb 18
- [reactnative] s/SpinnerIOS/ActivityIndicatorIOS/ | Dan Witte - [react-packager] Add a non-persistent mode for static builds | Amjad Masad - [React Native] Fix stored file rejection when initializing cache | Alex Akers - [React Native] Consolidate network requests in image downloader | Alex Akers - [React Native] Update RCTCache | Alex Akers - Converted all low-hanging RKBridgeModules in FBReactKit to RCTBridgeModules | Nick Lockwood
This commit is contained in:
parent
6cbd5fb941
commit
6dafafeea1
|
@ -10,10 +10,30 @@ exports.middleware = function(options) {
|
|||
|
||||
exports.buildPackageFromUrl = function(options, reqUrl) {
|
||||
Activity.disable();
|
||||
// Don't start the filewatcher or the cache.
|
||||
if (options.nonPersistent == null) {
|
||||
options.nonPersistent = true;
|
||||
}
|
||||
|
||||
var server = new Server(options);
|
||||
return server.buildPackageFromUrl(reqUrl)
|
||||
.then(function(p) {
|
||||
server.kill();
|
||||
server.end();
|
||||
return p;
|
||||
});
|
||||
};
|
||||
|
||||
exports.getDependencies = function(options, main) {
|
||||
Activity.disable();
|
||||
// Don't start the filewatcher or the cache.
|
||||
if (options.nonPersistent == null) {
|
||||
options.nonPersistent = true;
|
||||
}
|
||||
|
||||
var server = new Server(options);
|
||||
return server.getDependencies(main)
|
||||
.then(function(r) {
|
||||
server.end();
|
||||
return r.dependencies;
|
||||
});
|
||||
};
|
||||
|
|
|
@ -55,6 +55,25 @@ describe('HasteDependencyResolver', function() {
|
|||
isPolyfill: true,
|
||||
dependencies: ['polyfills/prelude.js', 'polyfills/require.js']
|
||||
},
|
||||
{ id: 'polyfills/console.js',
|
||||
isPolyfill: true,
|
||||
path: 'polyfills/console.js',
|
||||
dependencies: [
|
||||
'polyfills/prelude.js',
|
||||
'polyfills/require.js',
|
||||
'polyfills/polyfills.js'
|
||||
],
|
||||
},
|
||||
{ id: 'polyfills/error-guard.js',
|
||||
isPolyfill: true,
|
||||
path: 'polyfills/error-guard.js',
|
||||
dependencies: [
|
||||
'polyfills/prelude.js',
|
||||
'polyfills/require.js',
|
||||
'polyfills/polyfills.js',
|
||||
'polyfills/console.js'
|
||||
],
|
||||
},
|
||||
module
|
||||
]);
|
||||
});
|
||||
|
@ -97,11 +116,35 @@ describe('HasteDependencyResolver', function() {
|
|||
isPolyfill: true,
|
||||
dependencies: ['polyfills/prelude.js', 'polyfills/require.js']
|
||||
},
|
||||
{ id: 'polyfills/console.js',
|
||||
isPolyfill: true,
|
||||
path: 'polyfills/console.js',
|
||||
dependencies: [
|
||||
'polyfills/prelude.js',
|
||||
'polyfills/require.js',
|
||||
'polyfills/polyfills.js'
|
||||
],
|
||||
},
|
||||
{ id: 'polyfills/error-guard.js',
|
||||
isPolyfill: true,
|
||||
path: 'polyfills/error-guard.js',
|
||||
dependencies: [
|
||||
'polyfills/prelude.js',
|
||||
'polyfills/require.js',
|
||||
'polyfills/polyfills.js',
|
||||
'polyfills/console.js'
|
||||
],
|
||||
},
|
||||
{ path: 'some module',
|
||||
id: 'some module',
|
||||
isPolyfill: true,
|
||||
dependencies: [ 'polyfills/prelude.js', 'polyfills/require.js',
|
||||
'polyfills/polyfills.js']
|
||||
dependencies: [
|
||||
'polyfills/prelude.js',
|
||||
'polyfills/require.js',
|
||||
'polyfills/polyfills.js',
|
||||
'polyfills/console.js',
|
||||
'polyfills/error-guard.js',
|
||||
]
|
||||
},
|
||||
module
|
||||
]);
|
||||
|
|
|
@ -19,7 +19,10 @@ var DEFINE_MODULE_REPLACE_RE = /_moduleName_|_code_|_deps_/g;
|
|||
var REL_REQUIRE_STMT = /require\(['"]([\.\/0-9A-Z_$\-]*)['"]\)/gi;
|
||||
|
||||
function HasteDependencyResolver(config) {
|
||||
this._fileWatcher = new FileWatcher(config.projectRoots);
|
||||
this._fileWatcher = config.nonPersistent
|
||||
? FileWatcher.createDummyWatcher()
|
||||
: new FileWatcher(config.projectRoots);
|
||||
|
||||
this._depGraph = new DependencyGraph({
|
||||
roots: config.projectRoots,
|
||||
ignoreFilePath: function(filepath) {
|
||||
|
@ -97,7 +100,6 @@ HasteDependencyResolver.prototype.wrapModule = function(module, code) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
var relativizedCode =
|
||||
code.replace(REL_REQUIRE_STMT, function(codeMatch, depName) {
|
||||
var dep = resolvedDeps[depName];
|
||||
|
@ -117,7 +119,6 @@ HasteDependencyResolver.prototype.wrapModule = function(module, code) {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
HasteDependencyResolver.prototype.end = function() {
|
||||
return this._fileWatcher.end();
|
||||
};
|
||||
|
|
|
@ -76,3 +76,11 @@ function createWatcher(root) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
FileWatcher.createDummyWatcher = function() {
|
||||
var ev = new EventEmitter();
|
||||
ev.end = function() {
|
||||
return q();
|
||||
};
|
||||
return ev;
|
||||
};
|
||||
|
|
|
@ -6,6 +6,10 @@ jest
|
|||
.dontMock('os')
|
||||
.dontMock('../index');
|
||||
|
||||
var OPTIONS = {
|
||||
transformModulePath: '/foo/bar'
|
||||
};
|
||||
|
||||
describe('Transformer', function() {
|
||||
var Transformer;
|
||||
var workers;
|
||||
|
@ -32,7 +36,7 @@ describe('Transformer', function() {
|
|||
callback(null, 'content');
|
||||
});
|
||||
|
||||
return new Transformer({}).loadFileAndTransform([], 'file', {})
|
||||
return new Transformer(OPTIONS).loadFileAndTransform([], 'file', {})
|
||||
.then(function(data) {
|
||||
expect(data).toEqual({
|
||||
code: 'transformed',
|
||||
|
@ -55,7 +59,7 @@ describe('Transformer', function() {
|
|||
callback(null, {error: esprimaError});
|
||||
});
|
||||
|
||||
return new Transformer({}).loadFileAndTransform([], 'foo-file.js', {})
|
||||
return new Transformer(OPTIONS).loadFileAndTransform([], 'foo-file.js', {})
|
||||
.catch(function(error) {
|
||||
expect(error.type).toEqual('TransformError');
|
||||
expect(error.snippet).toEqual([
|
||||
|
|
|
@ -14,15 +14,21 @@ module.exports = Transformer;
|
|||
Transformer.TransformError = TransformError;
|
||||
|
||||
function Transformer(projectConfig) {
|
||||
this._cache = new Cache(projectConfig);
|
||||
this._workers = workerFarm(
|
||||
{autoStart: true},
|
||||
projectConfig.transformModulePath
|
||||
);
|
||||
this._cache = projectConfig.nonPersistent
|
||||
? new DummyCache() : new Cache(projectConfig);
|
||||
|
||||
if (projectConfig.transformModulePath == null) {
|
||||
this._failedToStart = q.Promise.reject(new Error('No transfrom module'));
|
||||
} else {
|
||||
this._workers = workerFarm(
|
||||
{autoStart: true},
|
||||
projectConfig.transformModulePath
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Transformer.prototype.kill = function() {
|
||||
workerFarm.end(this._workers);
|
||||
this._workers && workerFarm.end(this._workers);
|
||||
return this._cache.end();
|
||||
};
|
||||
|
||||
|
@ -37,6 +43,10 @@ Transformer.prototype.loadFileAndTransform = function(
|
|||
filePath,
|
||||
options
|
||||
) {
|
||||
if (this._failedToStart) {
|
||||
return this._failedToStart;
|
||||
}
|
||||
|
||||
var workers = this._workers;
|
||||
return this._cache.get(filePath, function() {
|
||||
return readFile(filePath)
|
||||
|
@ -93,3 +103,10 @@ function formatEsprimaError(err, filename, source) {
|
|||
error.description = err.description;
|
||||
return error;
|
||||
}
|
||||
|
||||
function DummyCache() {}
|
||||
DummyCache.prototype.get = function(filePath, loaderCb) {
|
||||
return loaderCb();
|
||||
};
|
||||
DummyCache.prototype.end =
|
||||
DummyCache.prototype.invalidate = function(){};
|
||||
|
|
|
@ -34,15 +34,7 @@ var DEFAULT_CONFIG = {
|
|||
*/
|
||||
polyfillModuleNames: [],
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
*
|
||||
* A string of code to be appended to the top of a package.
|
||||
*
|
||||
* TODO: THIS RUINS SOURCE MAPS. THIS OPTION SHOULD BE REMOVED ONCE WE GET
|
||||
* config.polyfillModuleNames WORKING!
|
||||
*/
|
||||
runtimeCode: ''
|
||||
nonPersistent: false,
|
||||
};
|
||||
|
||||
function Packager(projectConfig) {
|
||||
|
@ -72,7 +64,7 @@ Packager.prototype.package = function(main, runModule, sourceMapUrl) {
|
|||
var findEventId = Activity.startEvent('find dependencies');
|
||||
var transformEventId;
|
||||
|
||||
return this._resolver.getDependencies(main)
|
||||
return this.getDependencies(main)
|
||||
.then(function(result) {
|
||||
Activity.endEvent(findEventId);
|
||||
transformEventId = Activity.startEvent('transform');
|
||||
|
@ -98,10 +90,14 @@ Packager.prototype.package = function(main, runModule, sourceMapUrl) {
|
|||
});
|
||||
};
|
||||
|
||||
Packager.prototype.invalidateFile = function(filePath){
|
||||
Packager.prototype.invalidateFile = function(filePath) {
|
||||
this._transformer.invalidateFile(filePath);
|
||||
}
|
||||
|
||||
Packager.prototype.getDependencies = function(main) {
|
||||
return this._resolver.getDependencies(main);
|
||||
};
|
||||
|
||||
Packager.prototype._transformModule = function(module) {
|
||||
var resolver = this._resolver;
|
||||
return this._transformer.loadFileAndTransform(
|
||||
|
|
|
@ -18,10 +18,13 @@ function Server(options) {
|
|||
cacheVersion: options.cacheVersion,
|
||||
resetCache: options.resetCache,
|
||||
dev: options.dev,
|
||||
transformModulePath: options.transformModulePath
|
||||
transformModulePath: options.transformModulePath,
|
||||
nonPersistent: options.nonPersistent,
|
||||
});
|
||||
|
||||
this._fileWatcher = new FileWatcher(options.projectRoots);
|
||||
this._fileWatcher = options.nonPersistent
|
||||
? FileWatcher.createDummyWatcher()
|
||||
: new FileWatcher(options.projectRoots);
|
||||
|
||||
var onFileChange = this._onFileChange.bind(this);
|
||||
this._fileWatcher.on('all', onFileChange);
|
||||
|
@ -48,7 +51,7 @@ Server.prototype._rebuildPackages = function(filepath) {
|
|||
});
|
||||
};
|
||||
|
||||
Server.prototype.kill = function() {
|
||||
Server.prototype.end = function() {
|
||||
q.all([
|
||||
this._fileWatcher.end(),
|
||||
this._packager.kill(),
|
||||
|
@ -68,6 +71,10 @@ Server.prototype.buildPackageFromUrl = function(reqUrl) {
|
|||
return this._buildPackage(options);
|
||||
};
|
||||
|
||||
Server.prototype.getDependencies = function(main) {
|
||||
return this._packager.getDependencies(main);
|
||||
};
|
||||
|
||||
Server.prototype._processDebugRequest = function(reqUrl, res) {
|
||||
var ret = '<!doctype html>';
|
||||
var pathname = url.parse(reqUrl).pathname;
|
||||
|
|
Loading…
Reference in New Issue