mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-07 22:42:13 +08:00
- [React Native] Fix RCTText crashes | Alex Akers
- Ensure that NSLocationWhenInUseUsageDescription is set, throw error if not | Alex Kotliarskyi
- [ReactNative] fix exception handler method name | Spencer Ahrens
- [ReactNative] Re-configure horizontal swipe animations | Eric Vicenti
- [ReactNative] <Text>: apply the fontWeight correctly if fontFamily style is also present | Kevin Gozali
- [MAdMan] Dimensions.get('window') considered harmful | Philipp von Weitershausen
- Navigator: Changed transitioner background color to 'transparent' | Eric Vicenti
- [react-native] Listen on all IPv6 interfaces | Ben Alpert
- [react-packager] Don't depend on error.stack being available | Amjad Masad
- [ReactNative] fixup AnimationExperimental a bit | Spencer Ahrens
- [react-packager] Implement new style asset packaging (with dimensions) | Amjad Masad
- [React Native] RCT_EXPORT lvl.2 | Alex Akers
- [react_native] Implement TextInput end editing | Andrei Coman
- [react_native] Make TextInput focus, blur, dismiss and show keyboard work | Andrei Coman
- Added non-class-scanning-based approach fror registering js methods | Nick Lockwood
- [ReactNative] Update package.json | Christopher Chedeau
- [ReactNative] Do flow check when running packager | Spencer Ahrens
- [ReactNative] Fix typo/bug in Navigator._completeTransition | Eric Vicenti
- [ReactNative] Fix Navigator exception when touching during transition | Eric Vicenti
- [ReactNative] Remove bridge retaining cycles | Tadeu Zagallo
- [ReactNative] Fix and re-add WebView executor | Tadeu Zagallo
87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
/**
|
|
* 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';
|
|
|
|
var exec = require('child_process').exec;
|
|
|
|
function getFlowTypeCheckMiddleware(options) {
|
|
return function(req, res, next) {
|
|
if (options.skipflow) {
|
|
return next();
|
|
}
|
|
if (options.flowroot || options.projectRoots.length === 1) {
|
|
var flowroot = options.flowroot || options.projectRoots[0];
|
|
} else {
|
|
console.warn('flow: No suitable root');
|
|
return next();
|
|
}
|
|
exec('command -v flow >/dev/null 2>&1', function(error, stdout) {
|
|
if (error) {
|
|
console.warn('flow: Skipping because not installed. Install with ' +
|
|
'`brew install flow`.');
|
|
return next();
|
|
} else {
|
|
return doFlowTypecheck(res, flowroot, next);
|
|
}
|
|
});
|
|
};
|
|
}
|
|
|
|
function doFlowTypecheck(res, flowroot, next) {
|
|
var flowCmd = 'cd "' + flowroot + '" && flow --json --timeout 20';
|
|
var start = Date.now();
|
|
console.log('flow: Running static typechecks.');
|
|
exec(flowCmd, function(flowError, stdout) {
|
|
if (!flowError) {
|
|
console.log('flow: Typechecks passed (' + (Date.now() - start) + 'ms).');
|
|
return next();
|
|
} else {
|
|
try {
|
|
var flowResponse = JSON.parse(stdout);
|
|
var errors = [];
|
|
var errorNum = 1;
|
|
flowResponse.errors.forEach(function(err) {
|
|
// flow errors are paired across callsites, so we indent and prefix to
|
|
// group them
|
|
var indent = '';
|
|
err.message.forEach(function(msg) {
|
|
errors.push({
|
|
description: indent + 'E' + errorNum + ': ' + msg.descr,
|
|
filename: msg.path,
|
|
lineNumber: msg.line,
|
|
column: msg.start,
|
|
});
|
|
indent = ' ';
|
|
});
|
|
errorNum++;
|
|
});
|
|
var message = 'Flow found type errors. If you think these are wrong, ' +
|
|
'make sure flow is up to date, or disable with --skipflow.';
|
|
} catch (e) {
|
|
var message =
|
|
'Flow failed to provide parseable output:\n\n`' + stdout + '`';
|
|
console.error(message, '\nException: `', e, '`\n\n');
|
|
}
|
|
var error = {
|
|
status: 500,
|
|
message: message,
|
|
type: 'FlowError',
|
|
errors: errors,
|
|
};
|
|
console.error('flow: Error running command `' + flowCmd + '`:\n', error);
|
|
res.writeHead(error.status, {
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
});
|
|
res.end(JSON.stringify(error));
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = getFlowTypeCheckMiddleware;
|