From 0711617c63efe15e4a4078e6ee13693899dadf87 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Wed, 1 Apr 2020 03:05:39 -0700 Subject: [PATCH] Fixed error with 3rd plugin compilation in dev mode Summary: Fixed error "SHA-1 for file is not computed" on 3rd party plugin compilation in dev mode. The error started to appear after moving to yarn workspaces. Changelog: Fixed error "SHA-1 for file is not computed" on 3rd party plugin compilation in dev mode (yarn start). Reviewed By: mweststrate Differential Revision: D20789712 fbshipit-source-id: bbc2fcca197955da50ebf2b51a1fd9cb62f79727 --- desktop/static/compilePlugins.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/desktop/static/compilePlugins.ts b/desktop/static/compilePlugins.ts index 16ed90c05..75d7082c1 100644 --- a/desktop/static/compilePlugins.ts +++ b/desktop/static/compilePlugins.ts @@ -21,6 +21,9 @@ import getWatchFolders from './get-watch-folders'; const HOME_DIR = homedir(); +let metroDir: string | undefined; +const metroDirPromise = getMetroDir().then((dir) => (metroDir = dir)); + const DEFAULT_COMPILE_OPTIONS: CompileOptions = { force: false, failSilently: true, @@ -236,6 +239,19 @@ async function mostRecentlyChanged(dir: string) { .map((f) => fs.lstatSync(f).ctime) .reduce((a, b) => (a > b ? a : b), new Date(0)); } +async function getMetroDir() { + let dir = __dirname; + while (true) { + const dirToCheck = path.join(dir, 'node_modules', 'metro'); + if (await fs.pathExists(dirToCheck)) return dirToCheck; + const nextDir = path.dirname(dir); + if (!nextDir || nextDir === '' || nextDir === dir) { + break; + } + dir = nextDir; + } + return __dirname; +} async function compilePlugin( pluginInfo: PluginInfo, pluginCache: string, @@ -273,7 +289,9 @@ async function compilePlugin( { reporter: {update: () => {}}, projectRoot: rootDir, - watchFolders: [__dirname].concat(await getWatchFolders(rootDir)), + watchFolders: [metroDir || (await metroDirPromise)].concat( + await getWatchFolders(rootDir), + ), serializer: { getRunModuleStatement: (moduleID: string) => `module.exports = global.__r(${moduleID}).default;`,