From d734481abdc92035ef68d7c75ffde3b31dc1d50d Mon Sep 17 00:00:00 2001 From: zodern Date: Mon, 23 Dec 2019 10:31:03 -0600 Subject: [PATCH] Use optimisticRealpath when copying node_modules --- tools/fs/optimistic.ts | 19 +++++++++++++++++++ tools/isobuild/builder.js | 7 ++++--- tools/isobuild/bundler.js | 3 ++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/fs/optimistic.ts b/tools/fs/optimistic.ts index 86eb79ee1f..1fb57e81cd 100644 --- a/tools/fs/optimistic.ts +++ b/tools/fs/optimistic.ts @@ -16,6 +16,7 @@ import { readdir, dependOnPath, findAppDir, + realpath, } from "./files"; // When in doubt, the optimistic caching system can be completely disabled @@ -273,6 +274,24 @@ export const optimisticLStatOrNull = makeCheapPathFunction( }, ); +export const optimisticRealpath = makeOptimistic('realpath', realpath); +export const optimisticRealpathOrNull = makeOptimistic('realpathOrNull', ( + path: string, + options?: Parameters[1], +) => { + try { + return realpath(path, options) + } catch (e) { + if (e.code !== "ENOENT") { + throw e; + } + } + + dependOnParentDirectory(path); + + return null; +}); + export const optimisticReadFile = makeOptimistic("readFile", readFile); export const optimisticReaddir = makeOptimistic("readdir", readdir); export const optimisticHashOrNull = makeOptimistic("hashOrNull", ( diff --git a/tools/isobuild/builder.js b/tools/isobuild/builder.js index 04a23919ec..689645903b 100644 --- a/tools/isobuild/builder.js +++ b/tools/isobuild/builder.js @@ -11,6 +11,7 @@ import { optimisticStatOrNull, optimisticLStatOrNull, optimisticHashOrNull, + optimisticRealpath, } from "../fs/optimistic"; // Builder is in charge of writing "bundles" to disk, which are @@ -540,7 +541,7 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}` // as well as node_modules/meteor and the parent directories of any // scoped npm packages. this._ensureAllNonPackageDirectories( - files.realpath(options.from), + optimisticRealpath(options.from), options.to ); } @@ -637,7 +638,7 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}` }); } - const rootDir = files.realpath(from); + const rootDir = optimisticRealpath(from); const walk = (absFrom, relTo) => { if (symlink && ! (relTo in this.usedAsFile)) { @@ -671,7 +672,7 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}` } try { - var real = files.realpath(thisAbsFrom); + var real = optimisticRealpath(thisAbsFrom); } catch (e) { if (e.code !== "ENOENT" && e.code !== "ELOOP") { diff --git a/tools/isobuild/bundler.js b/tools/isobuild/bundler.js index af7446bf0f..d6d34b0bda 100644 --- a/tools/isobuild/bundler.js +++ b/tools/isobuild/bundler.js @@ -173,6 +173,7 @@ import { loadIsopackage } from '../tool-env/isopackets.js'; import { CORDOVA_PLATFORM_VERSIONS } from '../cordova'; import { gzipSync } from "zlib"; import { PackageRegistry } from "../../packages/meteor/define-package.js"; +import { optimisticRealpathOrNull } from '../fs/optimistic'; const SOURCE_URL_PREFIX = "meteor://\u{1f4bb}app"; @@ -486,7 +487,7 @@ export class NodeModulesDirectory { return true; } - const real = files.realpathOrNull(path); + const real = optimisticRealpathOrNull(path); if (typeof real === "string" && real !== path) { // If node_modules/.bin/command is a symlink, determine the