Sha256: d85eac214ceb3fb4a047015fade5e481ba9acf4c8cb8714a62b8477caeab8a00

Contents?: true

Size: 1.38 KB

Versions: 32

Compression:

Stored size: 1.38 KB

Contents

'use strict'

var glob = require('glob')
var path = require('path')

function trueCasePathSync(fsPath) {

  // Normalize the path so as to resolve . and .. components.
  // !! As of Node v4.1.1, a path starting with ../ is NOT resolved relative
  // !! to the current dir, and glob.sync() below then fails.
  // !! When in doubt, resolve with fs.realPathSync() *beforehand*.
  var fsPathNormalized = path.normalize(fsPath)

  // OSX: HFS+ stores filenames in NFD (decomposed normal form) Unicode format,
  // so we must ensure that the input path is in that format first.
  if (process.platform === 'darwin') fsPathNormalized = fsPathNormalized.normalize('NFD')

  // !! Windows: Curiously, the drive component mustn't be part of a glob,
  // !! otherwise glob.sync() will invariably match nothing.
  // !! Thus, we remove the drive component and instead pass it in as the 'cwd'
  // !! (working dir.) property below.
  var pathRoot = path.parse(fsPathNormalized).root
  var noDrivePath = fsPathNormalized.slice(Math.max(pathRoot.length - 1, 0))

  // Perform case-insensitive globbing (on Windows, relative to the drive /
  // network share) and return the 1st match, if any.
  // Fortunately, glob() with nocase case-corrects the input even if it is
  // a *literal* path.
  return glob.sync(noDrivePath, { nocase: true, cwd: pathRoot })[0]
}

module.exports = trueCasePathSync

Version data entries

32 entries across 31 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/true-case-path/index.js
disco_app-0.18.0 test/dummy/node_modules/true-case-path/index.js
disco_app-0.18.2 test/dummy/node_modules/true-case-path/index.js
tang-0.2.1 spec/tang_app/node_modules/true-case-path/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/true-case-path/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/true-case-path/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/true-case-path/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/true-case-path/index.js
tang-0.2.0 spec/tang_app/node_modules/true-case-path/index.js
tang-0.1.0 spec/tang_app/node_modules/true-case-path/index.js
tang-0.0.9 spec/tang_app/node_modules/true-case-path/index.js
enju_library-0.3.8 spec/dummy/node_modules/true-case-path/index.js
ilog-0.4.1 node_modules/true-case-path/index.js
ilog-0.4.0 node_modules/true-case-path/index.js
ilog-0.3.3 node_modules/true-case-path/index.js
jester-data-8.0.0 node_modules/true-case-path/index.js
ezii-os-5.2.1 node_modules/true-case-path/index.js
ezii-os-2.0.1 node_modules/true-case-path/index.js
ezii-os-1.1.0 node_modules/true-case-path/index.js
ezii-os-1.0.0 node_modules/true-case-path/index.js