mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Use optimistic functions in meteorNpm.isPortable.
This commit is contained in:
@@ -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 => {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user