11'use strict' ;
22
33const Y = require ( 'yuidocjs' ) ;
4+ const nodePath = require ( 'path' ) ;
45
56const YUIDoc = Y . YUIDoc ;
67const DIGESTERS = Y . DocParser . DIGESTERS ;
@@ -49,10 +50,15 @@ DIGESTERS.yield = function(tagname, value, target, block) {
4950}
5051
5152function normalizePaths ( document , inputPaths ) {
52- let inputPath = new RegExp ( inputPaths . map ( i => `${ i } /` ) . join ( '|' ) ) ;
53+ let regexStrs = inputPaths
54+ . map ( ( str ) => nodePath . join ( str , '/' ) )
55+ . map ( ( str ) => str . replace ( / \\ / g, '\\\\' ) ) // Ensure Windows-style paths are correctly escaped for the regex
56+ . map ( ( str ) => str . replace ( / \. / g, '\\.' ) ) ; // Ensure eventual dots in path are correctly escaped for the regex
57+
58+ let inputPath = new RegExp ( regexStrs . map ( ( str ) => `(${ str } )` ) . join ( '|' ) ) ;
5359
5460 for ( let path in document . files ) {
55- let normalizedPath = path . replace ( inputPath , '' ) . replace ( / ( \/ i n d e x ) ? \. j s / , '' ) ;
61+ let normalizedPath = normalizePath ( path , inputPath ) ;
5662 let file = document . files [ path ] ;
5763
5864 file . name = normalizedPath ;
@@ -62,27 +68,34 @@ function normalizePaths(document, inputPaths) {
6268 }
6369
6470 for ( let id in document . classes ) {
65- let normalizedId = id . replace ( inputPath , '' ) . replace ( / ( \/ i n d e x ) ? \. j s / , '' ) ;
71+ let normalizedId = normalizePath ( id , inputPath ) ;
6672 let klass = document . classes [ id ] ;
6773
6874 klass . name = normalizedId ;
6975 klass . shortname = normalizedId ;
70- klass . file = klass . file . replace ( inputPath , '' ) . replace ( / ( \/ i n d e x ) ? \. j s / , '' ) ;
76+ klass . file = normalizePath ( klass . file , inputPath ) ;
7177
7278 document . classes [ normalizedId ] = klass ;
7379 delete document . classes [ id ] ;
7480 }
7581
7682 for ( let item of document . classitems ) {
77- item . file = item . file . replace ( inputPath , '' ) . replace ( / ( \/ i n d e x ) ? \. j s / , '' ) ;
78- item . class = item . class . replace ( inputPath , '' ) . replace ( / ( \/ i n d e x ) ? \. j s / , '' ) ;
83+ item . file = normalizePath ( item . file , inputPath ) ;
84+ item . class = normalizePath ( item . class , inputPath ) ;
7985 }
8086
8187 for ( let warning of document . warnings ) {
82- warning . line = warning . line . replace ( inputPath , '' ) ;
88+ warning . line = normalizePath ( warning . line , inputPath ) ;
8389 }
8490}
8591
92+ function normalizePath ( filePath , inputPath ) {
93+ return filePath
94+ . replace ( inputPath , '' ) // Remove root of path
95+ . replace ( / \\ / g, '/' ) // Convert windows-style slashes
96+ . replace ( / ( \/ i n d e x ) ? \. j s / , '' ) ; // Remove index.js / .js
97+ }
98+
8699function isAcceptableWarning ( warning ) {
87100 return warning . message . match ( / ^ u n k n o w n t a g : / ) ;
88101}
0 commit comments