Use optimistic functions in meteorNpm.isPortable.

This commit is contained in:
Ben Newman
2016-09-26 17:35:51 -04:00
parent d954415752
commit 978df6e043
2 changed files with 15 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import {
pathSep,
pathIsAbsolute,
statOrNull,
lstat,
readFile,
readdir,
} from "./files.js";
@@ -123,6 +124,7 @@ function makeCacheKey(args) {
}
export const optimisticStatOrNull = makeOptimistic("statOrNull", statOrNull);
export const optimisticLStat = makeOptimistic("lstat", lstat);
export const optimisticReadFile = makeOptimistic("readFile", readFile);
export const optimisticReaddir = makeOptimistic("readdir", readdir);
export const optimisticHashOrNull = makeOptimistic("hashOrNull", path => {

View File

@@ -22,6 +22,13 @@ import {
convert as convertColonsInPath
} from "../utils/colon-converter.js";
import {
optimisticLStat,
optimisticStatOrNull,
optimisticReadFile,
optimisticReaddir,
} from "../fs/optimistic.js";
var meteorNpm = exports;
// if a user exits meteor while we're trying to create a .npm
@@ -429,14 +436,14 @@ function copyNpmPackageWithSymlinkedNodeModules(fromPkgDir, toPkgDir) {
});
}
function isPortable(dir) {
const lstat = files.lstat(dir);
const isPortable = Profile("meteorNpm.isPortable", dir => {
const lstat = optimisticLStat(dir);
if (! lstat.isDirectory()) {
// Non-directory files are portable unless they end with .node.
return ! dir.endsWith(".node");
}
const pkgJsonStat = files.statOrNull(files.pathJoin(dir, "package.json"));
const pkgJsonStat = optimisticStatOrNull(files.pathJoin(dir, "package.json"));
const canCache = pkgJsonStat && pkgJsonStat.isFile();
const portableFile = files.pathJoin(dir, ".meteor-portable");
@@ -448,7 +455,7 @@ function isPortable(dir) {
// directories, so that they will get cleared away the next time those
// packages are (re)installed.
try {
return JSON.parse(files.readFile(portableFile));
return JSON.parse(optimisticReadFile(portableFile));
} catch (e) {
if (! (e instanceof SyntaxError ||
e.code === "ENOENT")) {
@@ -461,7 +468,7 @@ function isPortable(dir) {
fs.unlink(portableFile, error => {});
}
const result = files.readdir(dir).every(
const result = optimisticReaddir(dir).every(
// Ignore files that start with a ".", such as .bin directories.
itemName => itemName.startsWith(".") ||
isPortable(files.pathJoin(dir, itemName)));
@@ -478,7 +485,7 @@ function isPortable(dir) {
}
return result;
}
});
// Return true if all of a package's npm dependencies are portable
// (that is, if the node_modules can be copied anywhere and we'd