From b37c9c14226cf45fc129b9b82ddd72e5ecf6064a Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 30 Aug 2018 03:22:17 -0700 Subject: [PATCH] End metro server gracefully when there are some edge errors Summary: This diff fixes a couple of edge cases that caused Metro to keep the process running when there were some specific errors (specially around the `dependencies` command and the transformer path). Reviewed By: jrwats Differential Revision: D9551834 fbshipit-source-id: 959cefcec9e2687dff89c94a871ae74c50d2dd77 --- dependencies/dependencies.js | 41 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/dependencies/dependencies.js b/dependencies/dependencies.js index c604c345d..aba54ec13 100644 --- a/dependencies/dependencies.js +++ b/dependencies/dependencies.js @@ -44,29 +44,26 @@ async function dependencies(argv, configPromise, args, packagerInstance) { ? fs.createWriteStream(args.output) : process.stdout; - return Promise.resolve( - (packagerInstance - ? packagerInstance.getOrderedDependencyPaths(options) - : Metro.getOrderedDependencyPaths(config, options) - ).then(deps => { - deps.forEach(modulePath => { - // Temporary hack to disable listing dependencies not under this directory. - // Long term, we need either - // (a) JS code to not depend on anything outside this directory, or - // (b) Come up with a way to declare this dependency in Buck. - const isInsideProjectRoots = - config.watchFolders.filter(root => modulePath.startsWith(root)) - .length > 0; + const deps = packagerInstance + ? await packagerInstance.getOrderedDependencyPaths(options) + : await Metro.getOrderedDependencyPaths(config, options); - if (isInsideProjectRoots) { - outStream.write(modulePath + '\n'); - } - }); - return writeToFile - ? denodeify(outStream.end).bind(outStream)() - : Promise.resolve(); - }), - ); + deps.forEach(modulePath => { + // Temporary hack to disable listing dependencies not under this directory. + // Long term, we need either + // (a) JS code to not depend on anything outside this directory, or + // (b) Come up with a way to declare this dependency in Buck. + const isInsideProjectRoots = + config.watchFolders.filter(root => modulePath.startsWith(root)).length > + 0; + + if (isInsideProjectRoots) { + outStream.write(modulePath + '\n'); + } + }); + return writeToFile + ? denodeify(outStream.end).bind(outStream)() + : Promise.resolve(); } module.exports = {