Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Migrate from path.exists to fs.exists #2411

Merged
merged 2 commits into from

7 participants

@mintplant

Compatibility is kept for path.exists. Versions of node that have made the change will use fs.exists, while older versions will fall back to path.exists. The same goes for path.existsSync.

This patch successfully passes cake build:full.

@mintplant mintplant Migrate from path.exists to fs.exists
Compatibility is kept for path.exists. Versions of node that have
made the change will use fs.exists, while older versions will fall
back to path.exists. The same goes for path.existsSync.
ace4837
@TrevorBurnham
Collaborator

The code in blocks.coffee is broken, so we might as well fix it with this patch. Instead of

raise "Location does not exist" unless fs.exists()

it should be

raise "Location does not exist" unless fs.existsSync(location)

Otherwise, LGTM.

@paulmillr

actually it should be throw new Error "Location does not exist" unless fs.existsSync location because there's no raise

@mintplant

I thought that looked odd. Fixed.

examples/blocks.coffee
@@ -31,7 +31,7 @@ File.open = (path, mode, block) ->
# Write.
write = (location, data) ->
path = new Pathname location
- raise "Location does not exist" unless path.exists()
+ raise "Location does not exist" unless fs.exists()

and here too

Right, revised the commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@michaelficarra
Collaborator

LGTM

@michaelficarra michaelficarra merged commit 2a56f0c into jashkenas:master
@michaelficarra
Collaborator

Merged. Thanks, @mintplant.

@ricardobeat

When is this getting into a release?

@jashkenas
Owner

When we cut the next one -- sorry for the slowness. Feel free to use master for now.

@tizzo

Haven't dug into it much but I'm on master and still receive path.existsSync is now calledfs.existsSyncwhen starting node apps with the syntaxcoffee app.coffee`. I think it appears master is still having this issue.

Running node v0.8.12 on OS X Lion for what it's worth.

@ricardobeat

@tizzo are you sure you updated /usr/local/bin/coffee? This has been fixed since 1.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 2, 2012
  1. @mintplant

    Migrate from path.exists to fs.exists

    mintplant authored
    Compatibility is kept for path.exists. Versions of node that have
    made the change will use fs.exists, while older versions will fall
    back to path.exists. The same goes for path.existsSync.
  2. @mintplant
This page is out of date. Refresh to see the latest.
View
4 examples/blocks.coffee
@@ -8,7 +8,7 @@ get '/hello', ->
# Append.
append = (location, data) ->
path = new Pathname location
- throw new Error("Location does not exist") unless path.exists()
+ throw new Error "Location does not exist" unless fs.existsSync(location)
File.open path, 'a', (file) ->
file.console.log YAML.dump data
@@ -31,7 +31,7 @@ File.open = (path, mode, block) ->
# Write.
write = (location, data) ->
path = new Pathname location
- raise "Location does not exist" unless path.exists()
+ throw new Error "Location does not exist" unless fs.existsSync(location)
File.open path, 'w', (file) ->
return false if Digest.MD5.hexdigest(file.read()) is data.hash()
View
6 lib/coffee-script/cake.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
+ var CoffeeScript, cakefileDirectory, existsSync, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
fs = require('fs');
@@ -12,6 +12,8 @@
CoffeeScript = require('./coffee-script');
+ existsSync = fs.existsSync || path.existsSync;
+
tasks = {};
options = {};
@@ -98,7 +100,7 @@
cakefileDirectory = function(dir) {
var parent;
- if (path.existsSync(path.join(dir, 'Cakefile'))) {
+ if (existsSync(path.join(dir, 'Cakefile'))) {
return dir;
}
parent = path.normalize(path.join(dir, '..'));
View
12 lib/coffee-script/command.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, hidden, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
+ var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
fs = require('fs');
@@ -16,6 +16,8 @@
EventEmitter = require('events').EventEmitter;
+ exists = fs.exists || path.exists;
+
helpers.extend(CoffeeScript, new EventEmitter);
printLine = function(line) {
@@ -372,8 +374,8 @@
sourceCode.splice(index, 1);
if (removeJs && !opts.join) {
jsPath = outputPath(source, base);
- return path.exists(jsPath, function(exists) {
- if (exists) {
+ return exists(jsPath, function(itExists) {
+ if (itExists) {
return fs.unlink(jsPath, function(err) {
if (err && err.code !== 'ENOENT') {
throw err;
@@ -410,8 +412,8 @@
}
});
};
- return path.exists(jsDir, function(exists) {
- if (exists) {
+ return exists(jsDir, function(itExists) {
+ if (itExists) {
return compile();
} else {
return exec("mkdir -p " + jsDir, compile);
View
4 src/cake.coffee
@@ -13,6 +13,8 @@ helpers = require './helpers'
optparse = require './optparse'
CoffeeScript = require './coffee-script'
+existsSync = fs.existsSync or path.existsSync
+
# Keep track of the list of defined tasks, the accepted options, and so on.
tasks = {}
options = {}
@@ -79,7 +81,7 @@ missingTask = (task) -> fatalError "No such task: #{task}"
# When `cake` is invoked, search in the current and all parent directories
# to find the relevant Cakefile.
cakefileDirectory = (dir) ->
- return dir if path.existsSync path.join dir, 'Cakefile'
+ return dir if existsSync path.join dir, 'Cakefile'
parent = path.normalize path.join dir, '..'
return cakefileDirectory parent unless parent is dir
throw new Error "Cakefile not found in #{process.cwd()}"
View
10 src/command.coffee
@@ -13,6 +13,8 @@ CoffeeScript = require './coffee-script'
{spawn, exec} = require 'child_process'
{EventEmitter} = require 'events'
+exists = fs.exists or path.exists
+
# Allow CoffeeScript to emit Node.js events.
helpers.extend CoffeeScript, new EventEmitter
@@ -247,8 +249,8 @@ removeSource = (source, base, removeJs) ->
sourceCode.splice index, 1
if removeJs and not opts.join
jsPath = outputPath source, base
- path.exists jsPath, (exists) ->
- if exists
+ exists jsPath, (itExists) ->
+ if itExists
fs.unlink jsPath, (err) ->
throw err if err and err.code isnt 'ENOENT'
timeLog "removed #{source}"
@@ -274,8 +276,8 @@ writeJs = (source, js, base) ->
printLine err.message
else if opts.compile and opts.watch
timeLog "compiled #{source}"
- path.exists jsDir, (exists) ->
- if exists then compile() else exec "mkdir -p #{jsDir}", compile
+ exists jsDir, (itExists) ->
+ if itExists then compile() else exec "mkdir -p #{jsDir}", compile
# Convenience for cleaner setTimeouts.
wait = (milliseconds, func) -> setTimeout func, milliseconds
Something went wrong with that request. Please try again.