Code coverage report for lib/normalize-entry-points.js

Statements: 100% (21 / 21)      Branches: 100% (4 / 4)      Functions: 100% (4 / 4)      Lines: 100% (21 / 21)      Ignored: none     

All files » lib/ » normalize-entry-points.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 661   1   1                                             49   49 13     49     1 13   13   3 1   1       2 2   2     10     1 13     1 22      
module.exports = normalizeEntryPoints
 
var path = require('path')
 
function normalizeEntryPoints(entryPoints) {
  // entryPoint ::= file ":" repr
  //              | ":" repr
  //              | file
  //
  // file ::= relativePath
  //        | absolutePath
  //        | implicitRelativePath
  //
  // relativePath ::= "." path
  //
  // absolutePath ::= <path-sep> path
  //
  // implicitRelativePath ::= path
  //
  // path ::= [^\s]+
  //
  // repr ::= [^\s]+
  // -------------------------
  // output is `{repr: path, ...}`.
  // repr's *always* use `/`.
  // path's *may* use `\`.
 
  var output = {}
 
  for(var i = 0, len = entryPoints.length; i < len; ++i) {
    addEntryPoint(output, entryPoints[i])
  }
 
  return output
}
 
function addEntryPoint(output, entryPoint) {
  var colonIdx = entryPoint.indexOf(':')
 
  if(colonIdx !== -1) {
    // `repr: null` from ":repr"
    if(colonIdx === 0) {
      output[normRepr(entryPoint.slice(1))] = null
 
      return
    }
 
    // `repr: path` from "path:repr"
    entryPoint = entryPoint.split(':')
    output[normRepr(entryPoint[1])] = normPath(entryPoint[0])
 
    return
  }
 
  output[normPath(normRepr(entryPoint))] = normPath(entryPoint)
}
 
function normRepr(repr) {
  return '/' + repr.split(path.sep).join('/')
}
 
function normPath(filepath) {
  return path.resolve(filepath)
}