@@ -26,10 +26,11 @@ let path = require("path");
2626let url = require ( "url" ) ;
2727let fdir = require ( "fdir" ) ;
2828let picomatch = require ( "picomatch" ) ;
29- picomatch = __toESM ( picomatch ) ;
29+ picomatch = __toESM ( picomatch , 1 ) ;
3030//#region src/utils.ts
3131const isReadonlyArray = Array . isArray ;
3232const BACKSLASHES = / \\ / g;
33+ const DRIVE_RELATIVE_PATH = / ^ [ A - Z a - z ] : $ / ;
3334const isWin = process . platform === "win32" ;
3435const ONLY_PARENT_DIRECTORIES = / ^ ( \/ ? \. \. ) + $ / ;
3536function getPartialMatcher ( patterns , options = { } ) {
@@ -96,18 +97,21 @@ function buildRelative(cwd, root) {
9697 return p [ p . length - 1 ] === "/" && result !== "" ? `${ result } /` : result || "." ;
9798 } ;
9899}
100+ function ensureNonDriveRelativePath ( path$1 ) {
101+ return path$1 . replace ( DRIVE_RELATIVE_PATH , ( match ) => `${ match } /` ) ;
102+ }
99103const splitPatternOptions = { parts : true } ;
100- function splitPattern ( path$1 ) {
104+ function splitPattern ( path$2 ) {
101105 var _result$parts ;
102- const result = picomatch . default . scan ( path$1 , splitPatternOptions ) ;
103- return ( ( _result$parts = result . parts ) === null || _result$parts === void 0 ? void 0 : _result$parts . length ) ? result . parts : [ path$1 ] ;
106+ const result = picomatch . default . scan ( path$2 , splitPatternOptions ) ;
107+ return ( ( _result$parts = result . parts ) === null || _result$parts === void 0 ? void 0 : _result$parts . length ) ? result . parts : [ path$2 ] ;
104108}
105109const ESCAPED_WIN32_BACKSLASHES = / \\ (? ! [ ( ) [ \] { } ! + @ ] ) / g;
106- function convertPosixPathToPattern ( path$2 ) {
107- return escapePosixPath ( path$2 ) ;
110+ function convertPosixPathToPattern ( path$3 ) {
111+ return escapePosixPath ( path$3 ) ;
108112}
109- function convertWin32PathToPattern ( path$3 ) {
110- return escapeWin32Path ( path$3 ) . replace ( ESCAPED_WIN32_BACKSLASHES , "/" ) ;
113+ function convertWin32PathToPattern ( path$4 ) {
114+ return escapeWin32Path ( path$4 ) . replace ( ESCAPED_WIN32_BACKSLASHES , "/" ) ;
111115}
112116/**
113117* Converts a path to a pattern depending on the platform.
@@ -118,8 +122,8 @@ function convertWin32PathToPattern(path$3) {
118122const convertPathToPattern = isWin ? convertWin32PathToPattern : convertPosixPathToPattern ;
119123const POSIX_UNESCAPED_GLOB_SYMBOLS = / (?< ! \\ ) ( [ ( ) [ \] { } * ? | ] | ^ ! | [ ! + @ ] (? = \( ) | \\ (? ! [ ( ) [ \] { } ! * + ? @ | ] ) ) / g;
120124const WIN32_UNESCAPED_GLOB_SYMBOLS = / (?< ! \\ ) ( [ ( ) [ \] { } ] | ^ ! | [ ! + @ ] (? = \( ) ) / g;
121- const escapePosixPath = ( path$4 ) => path$4 . replace ( POSIX_UNESCAPED_GLOB_SYMBOLS , "\\$&" ) ;
122- const escapeWin32Path = ( path$5 ) => path$5 . replace ( WIN32_UNESCAPED_GLOB_SYMBOLS , "\\$&" ) ;
125+ const escapePosixPath = ( path$5 ) => path$5 . replace ( POSIX_UNESCAPED_GLOB_SYMBOLS , "\\$&" ) ;
126+ const escapeWin32Path = ( path$6 ) => path$6 . replace ( WIN32_UNESCAPED_GLOB_SYMBOLS , "\\$&" ) ;
123127/**
124128* Escapes a path's special characters depending on the platform.
125129* @see {@link https://superchupu.dev/tinyglobby/documentation#escapePath }
@@ -173,7 +177,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
173177 }
174178 const potentialRoot = path . posix . join ( cwd , parentDir . slice ( i * 3 ) ) ;
175179 if ( potentialRoot [ 0 ] !== "." && props . root . length > potentialRoot . length ) {
176- props . root = potentialRoot ;
180+ props . root = ensureNonDriveRelativePath ( potentialRoot ) ;
177181 props . depthOffset = - n + i ;
178182 }
179183 }
@@ -193,7 +197,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
193197 }
194198 props . depthOffset = newCommonPath . length ;
195199 props . commonPath = newCommonPath ;
196- props . root = newCommonPath . length > 0 ? path . posix . join ( cwd , ...newCommonPath ) : cwd ;
200+ props . root = ensureNonDriveRelativePath ( newCommonPath . length > 0 ? path . posix . join ( cwd , ...newCommonPath ) : cwd ) ;
197201 }
198202 return result ;
199203}
@@ -286,18 +290,15 @@ function formatPaths(paths, mapper) {
286290}
287291const defaultOptions = {
288292 caseSensitiveMatch : true ,
289- cwd : process . cwd ( ) ,
290293 debug : ! ! process . env . TINYGLOBBY_DEBUG ,
291294 expandDirectories : true ,
292295 followSymbolicLinks : true ,
293296 onlyFiles : true
294297} ;
295298function getOptions ( options ) {
296- const opts = {
297- ...defaultOptions ,
298- ...options
299- } ;
300- opts . cwd = ( opts . cwd instanceof URL ? ( 0 , url . fileURLToPath ) ( opts . cwd ) : ( 0 , path . resolve ) ( opts . cwd ) ) . replace ( BACKSLASHES , "/" ) ;
299+ const opts = Object . assign ( { } , options ) ;
300+ for ( const key in defaultOptions ) if ( opts [ key ] === void 0 ) Object . assign ( opts , { [ key ] : defaultOptions [ key ] } ) ;
301+ opts . cwd = ( opts . cwd instanceof URL ? ( 0 , url . fileURLToPath ) ( opts . cwd ) : ( 0 , path . resolve ) ( opts . cwd || process . cwd ( ) ) ) . replace ( BACKSLASHES , "/" ) ;
301302 opts . ignore = ensureStringArray ( opts . ignore ) ;
302303 opts . fs && ( opts . fs = {
303304 readdir : opts . fs . readdir || fs . readdir ,
0 commit comments