Use path-exists instead of fs.exists.

fs.exists is being deprecated, see: https://github.com/nodejs/io.js/issues/103.
This commit is contained in:
Mark-Simulacrum 2015-06-25 12:39:39 -06:00
parent 560a044d8f
commit b308602098
10 changed files with 33 additions and 26 deletions

View File

@ -61,6 +61,7 @@
"lodash": "^3.6.0", "lodash": "^3.6.0",
"minimatch": "^2.0.3", "minimatch": "^2.0.3",
"output-file-sync": "^1.1.0", "output-file-sync": "^1.1.0",
"path-exists": "^1.0.0",
"path-is-absolute": "^1.0.0", "path-is-absolute": "^1.0.0",
"private": "^0.1.6", "private": "^0.1.6",
"regenerator": "0.8.31", "regenerator": "0.8.31",

View File

@ -1,5 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
var pathExists = require("path-exists");
var readline = require("readline"); var readline = require("readline");
var child = require("child_process"); var child = require("child_process");
var path = require("path"); var path = require("path");
@ -98,7 +99,7 @@ var cmds = {
write("README.md", template("README.md", templateData)); write("README.md", template("README.md", templateData));
if (!fs.existsSync("src")) { if (!pathExists.sync("src")) {
fs.mkdirSync("src"); fs.mkdirSync("src");
write("src/index.js", template("index.js", templateData)); write("src/index.js", template("index.js", templateData));
} }

View File

@ -1,4 +1,5 @@
var outputFileSync = require("output-file-sync"); var outputFileSync = require("output-file-sync");
var pathExists = require("path-exists");
var chokidar = require("chokidar"); var chokidar = require("chokidar");
var slash = require("slash"); var slash = require("slash");
var path = require("path"); var path = require("path");
@ -41,7 +42,7 @@ module.exports = function (commander, filenames, opts) {
}; };
var handle = function (filename) { var handle = function (filename) {
if (!fs.existsSync(filename)) return; if (!pathExists.sync(filename)) return;
var stat = fs.statSync(filename); var stat = fs.statSync(filename);

View File

@ -100,7 +100,7 @@ module.exports = function (commander, filenames, opts) {
results = []; results = [];
_.each(filenames, function (filename) { _.each(filenames, function (filename) {
if (!fs.existsSync(filename)) return; if (!pathExists.sync(filename)) return;
var stat = fs.statSync(filename); var stat = fs.statSync(filename);
if (stat.isDirectory()) { if (stat.isDirectory()) {

View File

@ -1,6 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
var moduleFormatters = require("babel-core/lib/babel/transformation/modules"); var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
var pathExists = require("path-exists");
var commander = require("commander"); var commander = require("commander");
var transform = require("babel-core").transform; var transform = require("babel-core").transform;
var kebabCase = require("lodash/string/kebabCase"); var kebabCase = require("lodash/string/kebabCase");
@ -88,7 +89,7 @@ var filenames = commander.args.reduce(function (globbed, input) {
filenames = uniq(filenames); filenames = uniq(filenames);
each(filenames, function (filename) { each(filenames, function (filename) {
if (!fs.existsSync(filename)) { if (!pathExists.sync(filename)) {
errors.push(filename + " doesn't exist"); errors.push(filename + " doesn't exist");
} }
}); });

View File

@ -1,6 +1,7 @@
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import homeOrTmp from "home-or-tmp"; import homeOrTmp from "home-or-tmp";
import pathExists from "path-exists";
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json"); const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
var data = {}; var data = {};
@ -15,7 +16,7 @@ export function load() {
process.on("exit", save); process.on("exit", save);
process.nextTick(save); process.nextTick(save);
if (!fs.existsSync(FILENAME)) return; if (!pathExists.sync(FILENAME)) return;
try { try {
data = JSON.parse(fs.readFileSync(FILENAME)); data = JSON.parse(fs.readFileSync(FILENAME));

View File

@ -3,16 +3,15 @@ import { normaliseOptions } from "./index";
import merge from "../../../helpers/merge"; import merge from "../../../helpers/merge";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import pathExists from "path-exists";
var cache = {}; var cache = {};
var jsons = {}; var jsons = {};
function exists(filename) { function exists(filename) {
if (!fs.existsSync) return false;
var cached = cache[filename]; var cached = cache[filename];
if (cached != null) return cached; if (cached != null) return cached;
return cache[filename] = fs.existsSync(filename); return cache[filename] = pathExists.sync(filename);
} }
export default function (loc, opts = {}) { export default function (loc, opts = {}) {

View File

@ -18,6 +18,7 @@ import has from "lodash/object/has";
import fs from "fs"; import fs from "fs";
import * as t from "./types"; import * as t from "./types";
import slash from "slash"; import slash from "slash";
import pathExists from "path-exists";
export { inherits, inspect } from "util"; export { inherits, inspect } from "util";
@ -182,7 +183,7 @@ function loadTemplates() {
var templates = {}; var templates = {};
var templatesLoc = path.join(__dirname, "transformation/templates"); var templatesLoc = path.join(__dirname, "transformation/templates");
if (!fs.existsSync(templatesLoc)) { if (!pathExists.sync(templatesLoc)) {
throw new ReferenceError(messages.get("missingTemplatesDirectory")); throw new ReferenceError(messages.get("missingTemplatesDirectory"));
} }

View File

@ -1,3 +1,4 @@
var pathExists = require("path-exists");
var esvalid = require("esvalid"); var esvalid = require("esvalid");
var util = require("../../lib/babel/util"); var util = require("../../lib/babel/util");
var path = require("path"); var path = require("path");
@ -10,7 +11,7 @@ var humanize = function (val, noext) {
}; };
var readFile = exports.readFile = function (filename) { var readFile = exports.readFile = function (filename) {
if (fs.existsSync(filename)) { if (pathExists.sync(filename)) {
var file = fs.readFileSync(filename, "utf8").trim(); var file = fs.readFileSync(filename, "utf8").trim();
file = file.replace(/\r\n/g, "\n"); file = file.replace(/\r\n/g, "\n");
return file; return file;
@ -31,7 +32,7 @@ exports.esvalid = function (ast, code, loc) {
}; };
exports.assertVendor = function (name) { exports.assertVendor = function (name) {
if (!fs.existsSync(__dirname + "/../../vendor/" + name)) { if (!pathExists.sync(__dirname + "/../../vendor/" + name)) {
console.error("No vendor/" + name + " - run `make bootstrap`"); console.error("No vendor/" + name + " - run `make bootstrap`");
process.exit(1); process.exit(1);
} }
@ -130,13 +131,13 @@ exports.get = function (entryName, entryLoc) {
suite.tests.push(test); suite.tests.push(test);
var sourceMappingsLoc = taskDir + "/source-mappings.json"; var sourceMappingsLoc = taskDir + "/source-mappings.json";
if (fs.existsSync(sourceMappingsLoc)) { if (pathExists.sync(sourceMappingsLoc)) {
test.options.sourceMap = true; test.options.sourceMap = true;
test.sourceMappings = require(sourceMappingsLoc); test.sourceMappings = require(sourceMappingsLoc);
} }
var sourceMap = taskDir + "/source-map.json"; var sourceMap = taskDir + "/source-map.json";
if (fs.existsSync(sourceMap)) { if (pathExists.sync(sourceMap)) {
test.options.sourceMap = true; test.options.sourceMap = true;
test.sourceMap = require(sourceMap); test.sourceMap = require(sourceMap);
} }

View File

@ -9,6 +9,7 @@ var child = require("child_process");
var path = require("path"); var path = require("path");
var chai = require("chai"); var chai = require("chai");
var fs = require("fs"); var fs = require("fs");
var pathExists = require("path-exists");
var _ = require("lodash"); var _ = require("lodash");
var fixtureLoc = __dirname + "/fixtures/bin"; var fixtureLoc = __dirname + "/fixtures/bin";
@ -16,7 +17,7 @@ var tmpLoc = __dirname + "/tmp";
var readDir = function (loc) { var readDir = function (loc) {
var files = {}; var files = {};
if (fs.existsSync(loc)) { if (pathExists.sync(loc)) {
_.each(readdir(loc), function (filename) { _.each(readdir(loc), function (filename) {
var contents = helper.readFile(loc + "/" + filename); var contents = helper.readFile(loc + "/" + filename);
files[filename] = contents; files[filename] = contents;
@ -112,7 +113,7 @@ var buildTest = function (binName, testName, opts) {
var clear = function () { var clear = function () {
process.chdir(__dirname); process.chdir(__dirname);
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc); if (pathExists.sync(tmpLoc)) rimraf.sync(tmpLoc);
fs.mkdirSync(tmpLoc); fs.mkdirSync(tmpLoc);
process.chdir(tmpLoc); process.chdir(tmpLoc);
}; };
@ -132,11 +133,11 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
}; };
var optionsLoc = testLoc + "/options.json" var optionsLoc = testLoc + "/options.json"
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc)); if (pathExists.sync(optionsLoc)) _.merge(opts, require(optionsLoc));
_.each(["stdout", "stdin", "stderr"], function (key) { _.each(["stdout", "stdin", "stderr"], function (key) {
var loc = testLoc + "/" + key + ".txt"; var loc = testLoc + "/" + key + ".txt";
if (fs.existsSync(loc)) { if (pathExists.sync(loc)) {
opts[key] = helper.readFile(loc); opts[key] = helper.readFile(loc);
} else { } else {
opts[key] = opts[key] || ""; opts[key] = opts[key] || "";