mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-30 17:18:41 +08:00
Make flow check async
This commit is contained in:
@@ -59,6 +59,13 @@ function setUpRedBoxConsoleErrorHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
function setupFlowChecker() {
|
||||
if (__DEV__) {
|
||||
var checkFlowAtRuntime = require('checkFlowAtRuntime');
|
||||
checkFlowAtRuntime();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a set of window environment wrappers that ensure that the
|
||||
* BatchedBridge is flushed after each tick. In both the case of the
|
||||
@@ -143,3 +150,4 @@ setUpGeolocation();
|
||||
setUpWebSockets();
|
||||
setupProfile();
|
||||
setUpProcessEnv();
|
||||
setupFlowChecker();
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @providesModule checkFlowAtRuntime
|
||||
*
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function checkFlowAtRuntime() {
|
||||
var url = getPackagerURL();
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
fetch(url + 'flow/')
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (response.silentError) {
|
||||
return;
|
||||
}
|
||||
throw {
|
||||
message: response.message,
|
||||
stack: response.errors.map(err => {
|
||||
return {
|
||||
...err,
|
||||
methodName: err.description,
|
||||
file: err.filename,
|
||||
};
|
||||
}),
|
||||
};
|
||||
},
|
||||
() => {
|
||||
//if fetch fails, silently give up
|
||||
})
|
||||
.done();
|
||||
}
|
||||
|
||||
function getPackagerURL() {
|
||||
var NativeModules = require('NativeModules');
|
||||
var scriptURL = (NativeModules
|
||||
&& NativeModules.SourceCode
|
||||
&& NativeModules.SourceCode.scriptURL)
|
||||
|| '';
|
||||
|
||||
// extract the url of the packager from the whole scriptURL
|
||||
// we match until the first / after http(s)://
|
||||
// i.e. http://www.mypackger.com/debug/my/bundle -> http://www.mypackger.com/
|
||||
return getFirstOrNull(scriptURL.match(/^https?:\/\/[^/]+\//));
|
||||
}
|
||||
|
||||
function getFirstOrNull(ar) {
|
||||
return ar ? ar[0] : null;
|
||||
}
|
||||
|
||||
module.exports = checkFlowAtRuntime;
|
||||
@@ -32,7 +32,7 @@ function parseErrorStack(e, sourceMapInstance) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var stack = stacktraceParser.parse(e.stack);
|
||||
var stack = Array.isArray(e.stack) ? e.stack : stacktraceParser.parse(e.stack);
|
||||
|
||||
var framesToPop = e.framesToPop || 0;
|
||||
while (framesToPop--) {
|
||||
|
||||
Reference in New Issue
Block a user