fs.directory matches commonjs spec

This commit is contained in:
Corey Johnson 2012-05-01 09:59:14 -07:00
parent 28f39cbdab
commit ee51a72721
2 changed files with 6 additions and 9 deletions

View File

@ -8,8 +8,8 @@ describe "fs", ->
describe "when called with a directory path", ->
it "return the path it was given", ->
expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures/dir')
expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures/dir')
expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures')
expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures')
describe ".join(paths...)", ->
it "concatenates the given paths with the directory seperator", ->

View File

@ -14,17 +14,14 @@ module.exports =
# any leading directory components removed. If specified, also
# remove a trailing extension.
base: (path, ext) ->
path =
base = path.replace(/\/$/, '').split("/").pop()
if ext then base.replace(RegEx(ext + "$"), "") else base
# Return the dirname of the given path. That is the path with any trailing
# non-directory component removed.
# Returns the path of a file's containing directory, albeit the
# parent directory if the file is a directory. A terminal directory
# separator is ignored.
directory: (path) ->
if @isDirectory(path)
path.replace(/\/?$/, '')
else
path.replace(new RegExp("/#{@base(path)}$"), '')
path.replace(new RegExp("/#{@base(path)}\/?$"), '')
# Returns true if the file specified by path exists
exists: (path) ->