From c60bb394b6df7fddd33216f2a2ff2ea3da905a72 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 19 Jan 2018 18:57:44 -0500 Subject: [PATCH] Go back to writing .meteor-portable-2.json files asynchronously. This reverts commit 4e4e204ab0891ac5a8f90820955147e35a302d9c. This commit caused a strange regression in reliability of the Windows dynamic-import self-test, which may be an indication of a deeper problem, so it seems safest to revert this change for now. In case empty .meteor-portable-2.json files are written, I've added an additional check that the cached JSON value is a boolean. --- tools/isobuild/meteor-npm.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/isobuild/meteor-npm.js b/tools/isobuild/meteor-npm.js index e0daed192f..a13a477754 100644 --- a/tools/isobuild/meteor-npm.js +++ b/tools/isobuild/meteor-npm.js @@ -496,7 +496,7 @@ const isPortable = Profile("meteorNpm.isPortable", dir => { allowSyntaxError: true }); - if (result) { + if (typeof result === "boolean") { return result; } @@ -528,17 +528,18 @@ const isPortable = Profile("meteorNpm.isPortable", dir => { isPortable(files.pathJoin(dir, itemName))); if (canCache) { - try { - files.writeFile( - portableFile, - JSON.stringify(result) + "\n", - "utf8" - ); - } catch (ignored) { - // Don't worry if the write fails, e.g. because the file system is - // read-only (#6591). Failing to write the file only means more work - // next time. - } + // Write the .meteor-portable file asynchronously, and don't worry + // if it fails, e.g. because the file system is read-only (#6591). + // Failing to write the file only means more work next time. + fs.writeFile( + portableFile, + JSON.stringify(result) + "\n", + error => { + // Once the asynchronous write finishes (successful or not), we no + // longer need to cache the written value in memory. + delete portableCache[portableFile]; + }, + ); // Cache the result immediately in memory so we don't have to wait for // file change notifications to invalidate optimisticReadJsonOrNull.