Permalink
Browse files

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.
  • Loading branch information...
1 parent 6417cf4 commit ace4837365447c665c56975ae7080029cbd78d53 Michael Smith committed Jul 2, 2012
Showing with 22 additions and 14 deletions.
  1. +2 −2 examples/blocks.coffee
  2. +4 −2 lib/coffee-script/cake.js
  3. +7 −5 lib/coffee-script/command.js
  4. +3 −1 src/cake.coffee
  5. +6 −4 src/command.coffee
View
@@ -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.exists()
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()
+ raise "Location does not exist" unless fs.exists()
File.open path, 'w', (file) ->
return false if Digest.MD5.hexdigest(file.read()) is data.hash()

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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
@@ -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

0 comments on commit ace4837

Please sign in to comment.