22
33const isNode = require ( 'detect-node' )
44const flatmap = require ( 'flatmap' )
5- const escape = require ( 'glob-escape' )
6-
7- function strip ( name , base ) {
8- const smallBase = base
9- . split ( '/' )
10- . slice ( 0 , - 1 )
11- . join ( '/' ) + '/'
12- return name . replace ( smallBase , '' )
13- }
145
156function loadPaths ( opts , file ) {
167 const path = require ( 'path' )
@@ -29,41 +20,43 @@ function loadPaths (opts, file) {
2920 if ( stats . isDirectory ( ) && opts . recursive ) {
3021 // glob requires a POSIX filename
3122 file = file . split ( path . sep ) . join ( '/' )
32- const globEscapedDir = escape ( file ) + ( file . endsWith ( '/' ) ? '' : '/' )
33- const mg = new glob . sync . GlobSync ( `${ globEscapedDir } ` + '**/*' , {
23+ const fullDir = file + ( file . endsWith ( '/' ) ? '' : '/' )
24+ let dirName = fullDir . split ( '/' )
25+ dirName = dirName [ dirName . length - 2 ] + '/'
26+ const mg = new glob . sync . GlobSync ( '**/*' , {
27+ cwd : file ,
3428 follow : followSymlinks ,
3529 dot : opts . hidden ,
36- ignore : ( opts . ignore || [ ] ) . map ( ( ignoreGlob ) => {
37- return globEscapedDir + ignoreGlob
38- } )
30+ ignore : opts . ignore
3931 } )
4032
4133 return mg . found
4234 . map ( ( name ) => {
35+ const fqn = fullDir + name
4336 // symlinks
44- if ( mg . symlinks [ name ] === true ) {
37+ if ( mg . symlinks [ fqn ] === true ) {
4538 return {
46- path : strip ( name , file ) ,
39+ path : dirName + name ,
4740 symlink : true ,
4841 dir : false ,
49- content : fs . readlinkSync ( name )
42+ content : fs . readlinkSync ( fqn )
5043 }
5144 }
5245
5346 // files
54- if ( mg . cache [ name ] === 'FILE' ) {
47+ if ( mg . cache [ fqn ] === 'FILE' ) {
5548 return {
56- path : strip ( name , file ) ,
49+ path : dirName + name ,
5750 symlink : false ,
5851 dir : false ,
59- content : fs . createReadStream ( name )
52+ content : fs . createReadStream ( fqn )
6053 }
6154 }
6255
6356 // directories
64- if ( mg . cache [ name ] === 'DIR' || mg . cache [ name ] instanceof Array ) {
57+ if ( mg . cache [ fqn ] === 'DIR' || mg . cache [ fqn ] instanceof Array ) {
6558 return {
66- path : strip ( name , file ) ,
59+ path : dirName + name ,
6760 symlink : false ,
6861 dir : true
6962 }
@@ -86,7 +79,7 @@ function prepareFile (file, opts) {
8679 return flatmap ( files , ( file ) => {
8780 if ( typeof file === 'string' ) {
8881 if ( ! isNode ) {
89- throw new Error ( 'Can not add paths in node' )
82+ throw new Error ( 'Can only add file paths in node' )
9083 }
9184
9285 return loadPaths ( opts , file )
0 commit comments