Skip to content

Commit d569529

Browse files
author
Ben Newman
committed
Avoid more uses of fs.exists and fs.existsSync.
Part of meteor#6921.
1 parent b612e39 commit d569529

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

packages/stylus/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
summary: 'Expressive, dynamic, robust CSS',
3-
version: "2.512.0"
3+
version: "2.512.1"
44
});
55

66
Package.registerBuildPlugin({

packages/stylus/plugin/compile-stylus.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ class StylusCompiler extends MultiFileCachingCompiler {
9393
// if it is not a custom syntax path, it could be a lookup in a folder
9494
for (let i = paths.length - 1; i >= 0; i--) {
9595
const joined = path.join(paths[i], importPath);
96-
if (fs.exists(joined))
96+
if (statOrNull(joined)) {
9797
return [joined];
98+
}
9899
}
99100
}
100101

@@ -177,3 +178,11 @@ class StylusCompiler extends MultiFileCachingCompiler {
177178
});
178179
}
179180
}
181+
182+
function statOrNull(path) {
183+
try {
184+
return fs.statSync(path);
185+
} catch (e) {
186+
return null;
187+
}
188+
}

tools/fs/files.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,11 @@ wrapFsFunc("rename", [0, 1]);
14291429

14301430
// The fs.exists method is deprecated in Node v4:
14311431
// https://nodejs.org/api/fs.html#fs_fs_exists_path_callback
1432-
files.exists = function (path) {
1432+
files.exists =
1433+
files.existsSync = function (path, callback) {
1434+
if (typeof callback === "function") {
1435+
throw new Error("Passing a callback to files.exists is no longer supported");
1436+
}
14331437
return !! files.statOrNull(path);
14341438
};
14351439

tools/static-assets/server/boot.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ Fiber(function () {
150150
});
151151
}
152152

153+
function statOrNull(path) {
154+
try {
155+
return fs.statSync(path);
156+
} catch (e) {
157+
return null;
158+
}
159+
}
160+
153161
var Npm = {
154162
/**
155163
* @summary Require a package that was specified using
@@ -171,7 +179,7 @@ Fiber(function () {
171179
name.split("/", 1)[0]
172180
));
173181

174-
if (fs.existsSync(packageBase)) {
182+
if (statOrNull(packageBase)) {
175183
return fullPath = files.convertToOSPath(
176184
files.pathResolve(nodeModuleBase, name)
177185
);

tools/static-assets/server/npm-require.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ var files = require('./mini-files.js');
66
var serverJson = require("./server-json.js");
77
var topLevelIdPattern = /^[^./]/;
88

9+
function statOrNull(path) {
10+
try {
11+
return fs.statSync(path);
12+
} catch (e) {
13+
return null;
14+
}
15+
}
16+
917
function findAppDirHelper(absOSPath) {
1018
if (fs.statSync(absOSPath).isDirectory() &&
11-
fs.existsSync(path.join(absOSPath, ".meteor"))) {
19+
statOrNull(path.join(absOSPath, ".meteor"))) {
1220
return absOSPath;
1321
}
1422

0 commit comments

Comments
 (0)