1- import { join } from 'path' ;
1+ import { resolve } from 'path' ;
22import { statSync } from 'fs' ;
33
4+ // @ts -ignore
5+ import normalizePath from 'normalize-path' ;
46// @ts -ignore
57import arrify from 'arrify' ;
68
@@ -11,18 +13,10 @@ import arrify from 'arrify';
1113 */
1214export function parseFiles ( files , context ) {
1315 return arrify ( files ) . map ( ( /** @type {string } */ file ) =>
14- replaceBackslashes ( join ( context , file ) )
16+ normalizePath ( resolve ( context , file ) )
1517 ) ;
1618}
1719
18- /**
19- * @param {string } str
20- * @returns {string }
21- */
22- export function replaceBackslashes ( str ) {
23- return str . replace ( / \\ / g, '/' ) ;
24- }
25-
2620/**
2721 * @param {string|string[] } patterns
2822 * @param {string|string[] } extensions
@@ -35,26 +29,24 @@ export function parseFoldersToGlobs(patterns, extensions = []) {
3529 . map ( ( /** @type {string } */ extension ) => extension . replace ( / ^ \. / u, '' ) )
3630 . join ( ',' ) ;
3731
38- return arrify ( patterns )
39- . map ( ( /** @type {string } */ pattern ) => replaceBackslashes ( pattern ) )
40- . map ( ( /** @type {string } */ pattern ) => {
41- try {
42- // The patterns are absolute because they are prepended with the context.
43- const stats = statSync ( pattern ) ;
44- /* istanbul ignore else */
45- if ( stats . isDirectory ( ) ) {
46- return pattern . replace (
47- / [ / \\ ] * ?$ / u,
48- `/**${
49- extensionsGlob ? `/*.${ prefix + extensionsGlob + postfix } ` : ''
50- } `
51- ) ;
52- }
53- } catch ( _ ) {
54- // Return the pattern as is on error.
32+ return arrify ( patterns ) . map ( ( /** @type {string } */ pattern ) => {
33+ try {
34+ // The patterns are absolute because they are prepended with the context.
35+ const stats = statSync ( pattern ) ;
36+ /* istanbul ignore else */
37+ if ( stats . isDirectory ( ) ) {
38+ return pattern . replace (
39+ / [ / \\ ] * ?$ / u,
40+ `/**${
41+ extensionsGlob ? `/*.${ prefix + extensionsGlob + postfix } ` : ''
42+ } `
43+ ) ;
5544 }
56- return pattern ;
57- } ) ;
45+ } catch ( _ ) {
46+ // Return the pattern as is on error.
47+ }
48+ return pattern ;
49+ } ) ;
5850}
5951
6052/**
0 commit comments