mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 13:44:04 +00:00
Disable Flow on Packager
Reviewed By: frantic Differential Revision: D2870105 fb-gh-sync-id: c95db83e40b3558c53614b08240a5361c14e0e6c
This commit is contained in:
parent
f2438b440d
commit
c56f280af2
@ -96,13 +96,6 @@ function setUpErrorHandler() {
|
||||
ErrorUtils.setGlobalHandler(handleError);
|
||||
}
|
||||
|
||||
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
|
||||
@ -219,7 +212,6 @@ setUpMapAndSet();
|
||||
setUpProduct();
|
||||
setUpWebSockets();
|
||||
setUpProfile();
|
||||
setUpFlowChecker();
|
||||
setUpNumber();
|
||||
setUpDevTools();
|
||||
|
||||
|
@ -1,59 +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.
|
||||
*
|
||||
* @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;
|
@ -1,150 +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';
|
||||
|
||||
var chalk = require('chalk');
|
||||
var exec = require('child_process').exec;
|
||||
var url = require('url');
|
||||
var Activity = require('../../../packager/react-packager').Activity;
|
||||
|
||||
var hasWarned = {};
|
||||
|
||||
function getFlowTypeCheckMiddleware(options) {
|
||||
return function(req, res, next) {
|
||||
var reqObj = url.parse(req.url);
|
||||
var isFlowCheck = (reqObj.path.match(/^\/flow\//));
|
||||
|
||||
if (!isFlowCheck) {
|
||||
return next();
|
||||
}
|
||||
if (options.skipflow) {
|
||||
_endSkipFlow(res);
|
||||
return;
|
||||
}
|
||||
if (options.flowroot || options.projectRoots.length === 1) {
|
||||
var flowroot = options.flowroot || options.projectRoots[0];
|
||||
} else {
|
||||
if (!hasWarned.noRoot) {
|
||||
hasWarned.noRoot = true;
|
||||
console.warn('flow: No suitable root');
|
||||
}
|
||||
_endFlowBad(res);
|
||||
return;
|
||||
}
|
||||
exec('command -v flow >/dev/null 2>&1', function(error, stdout) {
|
||||
if (error) {
|
||||
if (!hasWarned.noFlow) {
|
||||
hasWarned.noFlow = true;
|
||||
console.warn(chalk.yellow('flow: Skipping because not installed. Install with ' +
|
||||
'`brew install flow`.'));
|
||||
}
|
||||
_endFlowBad(res);
|
||||
return;
|
||||
} else {
|
||||
return doFlowTypecheck(res, flowroot, next);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function doFlowTypecheck(res, flowroot, next) {
|
||||
var flowCmd = 'cd "' + flowroot + '" && flow --json --timeout 20';
|
||||
var eventId = Activity.startEvent('flow static typechecks');
|
||||
exec(flowCmd, function(flowError, stdout, stderr) {
|
||||
Activity.endEvent(eventId);
|
||||
if (!flowError) {
|
||||
_endFlowOk(res);
|
||||
return;
|
||||
} 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 error = {
|
||||
status: 200,
|
||||
message: 'Flow found type errors. If you think these are wrong, ' +
|
||||
'make sure your flow bin and .flowconfig are up to date, or ' +
|
||||
'disable with --skipflow.',
|
||||
type: 'FlowError',
|
||||
errors: errors,
|
||||
};
|
||||
res.writeHead(error.status, {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
});
|
||||
res.end(JSON.stringify(error));
|
||||
} catch (e) {
|
||||
if (stderr.match(/Could not find a \.flowconfig/)) {
|
||||
if (!hasWarned.noConfig) {
|
||||
hasWarned.noConfig = true;
|
||||
console.warn(chalk.yellow('flow: ' + stderr));
|
||||
}
|
||||
_endFlowBad(res);
|
||||
} else if (flowError.code === 3) {
|
||||
if (!hasWarned.timeout) {
|
||||
hasWarned.timeout = true;
|
||||
console.warn(chalk.yellow('flow: ' + stdout));
|
||||
}
|
||||
_endSkipFlow(res);
|
||||
} else {
|
||||
if (!hasWarned.brokenFlow) {
|
||||
hasWarned.brokenFlow = true;
|
||||
console.warn(chalk.yellow(
|
||||
'Flow failed to provide parseable output:\n\n`' + stdout +
|
||||
'`.\n' + 'stderr: `' + stderr + '`'
|
||||
));
|
||||
}
|
||||
_endFlowBad(res);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _endRes(res, message, code, silentError) {
|
||||
res.writeHead(code, {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
});
|
||||
res.end(JSON.stringify({
|
||||
message: message,
|
||||
errors: [],
|
||||
silentError: silentError,
|
||||
}));
|
||||
}
|
||||
|
||||
function _endFlowOk(res) {
|
||||
_endRes(res, 'No Flow Error', '200', true);
|
||||
}
|
||||
|
||||
function _endFlowBad(res) {
|
||||
// we want to show that flow failed
|
||||
// status 200 is need for the fetch to not be rejected
|
||||
_endRes(res, 'Flow failed to run! Please look at the console for more details.', '200', false);
|
||||
}
|
||||
|
||||
function _endSkipFlow(res) {
|
||||
_endRes(res, 'Flow was skipped, check the server options', '200', true);
|
||||
}
|
||||
|
||||
module.exports = getFlowTypeCheckMiddleware;
|
@ -33,8 +33,6 @@ function runServer(args, config, readyCallback) {
|
||||
.use(statusPageMiddleware)
|
||||
.use(systraceProfileMiddleware)
|
||||
.use(cpuProfilerMiddleware)
|
||||
// Temporarily disable flow check until it's more stable
|
||||
//.use(getFlowTypeCheckMiddleware(args))
|
||||
.use(packagerServer.processRequest.bind(packagerServer));
|
||||
|
||||
args.projectRoots.forEach(root => app.use(connect.static(root)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user