Skip to content

Commit

Permalink
Replace path-exists with fs.existsSync (babel#4731)
Browse files Browse the repository at this point in the history
It's not deprecated anymore, see nodejs/node#8364
  • Loading branch information
SimenB authored and chrisprice committed Oct 18, 2016
1 parent 3142039 commit e4eca7c
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 24 deletions.
1 change: 0 additions & 1 deletion packages/babel-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"glob": "^5.0.5",
"lodash": "^4.2.0",
"output-file-sync": "^1.1.0",
"path-exists": "^1.0.0",
"path-is-absolute": "^1.0.0",
"slash": "^1.0.0",
"source-map": "^0.5.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-cli/src/babel/dir.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let outputFileSync = require("output-file-sync");
let pathExists = require("path-exists");
let slash = require("slash");
let path = require("path");
let util = require("./util");
Expand Down Expand Up @@ -45,7 +44,7 @@ module.exports = function (commander, filenames) {
}

function handle(filename) {
if (!pathExists.sync(filename)) return;
if (!fs.existsSync(filename)) return;

let stat = fs.statSync(filename);

Expand Down
3 changes: 1 addition & 2 deletions packages/babel-cli/src/babel/file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let convertSourceMap = require("convert-source-map");
let pathExists = require("path-exists");
let sourceMap = require("source-map");
let slash = require("slash");
let path = require("path");
Expand Down Expand Up @@ -109,7 +108,7 @@ module.exports = function (commander, filenames, opts) {
results = [];

_.each(filenames, function (filename) {
if (!pathExists.sync(filename)) return;
if (!fs.existsSync(filename)) return;

let stat = fs.statSync(filename);
if (stat.isDirectory()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-cli/src/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require("babel-core");

let pathExists = require("path-exists");
let fs = require("fs");
let commander = require("commander");
let kebabCase = require("lodash/kebabCase");
let options = require("babel-core").options;
Expand Down Expand Up @@ -70,7 +70,7 @@ let filenames = commander.args.reduce(function (globbed, input) {
filenames = uniq(filenames);

each(filenames, function (filename) {
if (!pathExists.sync(filename)) {
if (!fs.existsSync(filename)) {
errors.push(filename + " doesn't exist");
}
});
Expand Down
11 changes: 5 additions & 6 deletions packages/babel-cli/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let child = require("child_process");
let path = require("path");
let chai = require("chai");
let fs = require("fs");
let pathExists = require("path-exists");
let _ = require("lodash");

let fixtureLoc = path.join(__dirname, "fixtures");
Expand All @@ -25,7 +24,7 @@ let pluginLocs = [

let readDir = function (loc) {
let files = {};
if (pathExists.sync(loc)) {
if (fs.existsSync(loc)) {
_.each(readdir(loc), function (filename) {
files[filename] = helper.readFile(path.join(loc, filename));
});
Expand Down Expand Up @@ -130,7 +129,7 @@ let buildTest = function (binName, testName, opts) {

let clear = function () {
process.chdir(__dirname);
if (pathExists.sync(tmpLoc)) rimraf.sync(tmpLoc);
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
fs.mkdirSync(tmpLoc);
process.chdir(tmpLoc);
};
Expand All @@ -150,11 +149,11 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
};

let optionsLoc = path.join(testLoc, "options.json");
if (pathExists.sync(optionsLoc)) _.merge(opts, require(optionsLoc));
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));

_.each(["stdout", "stdin", "stderr"], function (key) {
let loc = path.join(testLoc, key + ".txt");
if (pathExists.sync(loc)) {
if (fs.existsSync(loc)) {
opts[key] = helper.readFile(loc);
} else {
opts[key] = opts[key] || "";
Expand All @@ -165,7 +164,7 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
opts.inFiles = readDir(path.join(testLoc, "in-files"));

let babelrcLoc = path.join(testLoc, ".babelrc");
if (pathExists.sync(babelrcLoc)) {
if (fs.existsSync(babelrcLoc)) {
// copy .babelrc file to tmp directory
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
}
Expand Down
1 change: 0 additions & 1 deletion packages/babel-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"json5": "^0.5.0",
"lodash": "^4.2.0",
"minimatch": "^3.0.2",
"path-exists": "^1.0.0",
"path-is-absolute": "^1.0.0",
"private": "^0.1.6",
"slash": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type Logger from "../logger";
import resolve from "../../../helpers/resolve";
import json5 from "json5";
import isAbsolute from "path-is-absolute";
import pathExists from "path-exists";
import path from "path";
import fs from "fs";

Expand All @@ -17,7 +16,7 @@ const PACKAGE_FILENAME = "package.json";
function exists(filename) {
let cached = existsCache[filename];
if (cached == null) {
return existsCache[filename] = pathExists.sync(filename);
return existsCache[filename] = fs.existsSync(filename);
} else {
return cached;
}
Expand Down
1 change: 0 additions & 1 deletion packages/babel-helper-fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"dependencies": {
"babel-runtime": "^6.9.0",
"lodash": "^4.2.0",
"path-exists": "^1.0.0",
"try-resolve": "^1.0.0"
}
}
7 changes: 3 additions & 4 deletions packages/babel-helper-fixtures/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pathExists from "path-exists";
import resolve from "try-resolve";
import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -132,12 +131,12 @@ export default function get(entryLoc): Array<Suite> {
suite.tests.push(test);

let sourceMappingsLoc = taskDir + "/source-mappings.json";
if (pathExists.sync(sourceMappingsLoc)) {
if (fs.existsSync(sourceMappingsLoc)) {
test.sourceMappings = JSON.parse(readFile(sourceMappingsLoc));
}

let sourceMapLoc = taskDir + "/source-map.json";
if (pathExists.sync(sourceMapLoc)) {
if (fs.existsSync(sourceMapLoc)) {
test.sourceMap = JSON.parse(readFile(sourceMapLoc));
}
}
Expand All @@ -162,7 +161,7 @@ export function multiple(entryLoc, ignore?: Array<string>) {
}

export function readFile(filename) {
if (pathExists.sync(filename)) {
if (fs.existsSync(filename)) {
let file = _.trimEnd(fs.readFileSync(filename, "utf8"));
file = file.replace(/\r\n/g, "\n");
return file;
Expand Down
1 change: 0 additions & 1 deletion packages/babel-register/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"home-or-tmp": "^2.0.0",
"lodash": "^4.2.0",
"mkdirp": "^0.5.1",
"path-exists": "^1.0.0",
"source-map-support": "^0.4.2"
}
}
3 changes: 1 addition & 2 deletions packages/babel-register/src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from "path";
import fs from "fs";
import { sync as mkdirpSync } from "mkdirp";
import homeOrTmp from "home-or-tmp";
import pathExists from "path-exists";

const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
let data = {};
Expand Down Expand Up @@ -37,7 +36,7 @@ export function load() {
process.on("exit", save);
process.nextTick(save);

if (!pathExists.sync(FILENAME)) return;
if (!fs.existsSync(FILENAME)) return;

try {
data = JSON.parse(fs.readFileSync(FILENAME));
Expand Down

0 comments on commit e4eca7c

Please sign in to comment.