HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/rest/node_modules/browserify-transform-tools/src/parentDir.coffee
path    = require 'path'
fs      = require 'fs'

# Temporarily don't use this while waiting for fix for https://github.com/thlorenz/find-parent-dir/issues/1
# exports.parentDir = require 'find-parent-dir'

# Find the first parent direcotry of 'dir' which contains a file named 'fileToFind'.
exports.parentDir = (dir, fileToFind, done) ->
    exists = fs.exists ? path.exists
    exists path.join(dir, fileToFind), (fileExists) ->
        if fileExists
            done null, dir
        else
            parent = path.resolve dir, ".."
            if parent == dir
                # Hit the root directory
                done null, null
            else
                # Recursive call to walk up the tree.
                exports.parentDir parent, fileToFind, done


# Find the first parent directory of `dir` which contains a file named `fileToFind`.
exports.parentDirSync = (dir, fileToFind) ->
    existsSync = fs.existsSync ? path.existsSync

    dirToCheck = path.resolve dir

    answer = null
    while true
        if existsSync path.join(dirToCheck, fileToFind)
            answer = dirToCheck
            break

        oldDirToCheck = dirToCheck
        dirToCheck = path.resolve dirToCheck, ".."
        if oldDirToCheck == dirToCheck
            # We've hit '/'.  We're done
            break

    return answer