@@ -2337,6 +2337,25 @@ exports.checkBypass = checkBypass;
2337
2337
2338
2338
"use strict" ;
2339
2339
2340
+ var __createBinding = ( this && this . __createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
2341
+ if ( k2 === undefined ) k2 = k ;
2342
+ Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
2343
+ } ) : ( function ( o , m , k , k2 ) {
2344
+ if ( k2 === undefined ) k2 = k ;
2345
+ o [ k2 ] = m [ k ] ;
2346
+ } ) ) ;
2347
+ var __setModuleDefault = ( this && this . __setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
2348
+ Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
2349
+ } ) : function ( o , v ) {
2350
+ o [ "default" ] = v ;
2351
+ } ) ;
2352
+ var __importStar = ( this && this . __importStar ) || function ( mod ) {
2353
+ if ( mod && mod . __esModule ) return mod ;
2354
+ var result = { } ;
2355
+ if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . hasOwnProperty . call ( mod , k ) ) __createBinding ( result , mod , k ) ;
2356
+ __setModuleDefault ( result , mod ) ;
2357
+ return result ;
2358
+ } ;
2340
2359
var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
2341
2360
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
2342
2361
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
@@ -2348,9 +2367,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2348
2367
} ;
2349
2368
var _a ;
2350
2369
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
2351
- const assert_1 = __nccwpck_require__ ( 9491 ) ;
2352
- const fs = __nccwpck_require__ ( 7147 ) ;
2353
- const path = __nccwpck_require__ ( 1017 ) ;
2370
+ exports . getCmdPath = exports . tryGetExecutablePath = exports . isRooted = exports . isDirectory = exports . exists = exports . IS_WINDOWS = exports . unlink = exports . symlink = exports . stat = exports . rmdir = exports . rename = exports . readlink = exports . readdir = exports . mkdir = exports . lstat = exports . copyFile = exports . chmod = void 0 ;
2371
+ const fs = __importStar ( __nccwpck_require__ ( 7147 ) ) ;
2372
+ const path = __importStar ( __nccwpck_require__ ( 1017 ) ) ;
2354
2373
_a = fs . promises , exports . chmod = _a . chmod , exports . copyFile = _a . copyFile , exports . lstat = _a . lstat , exports . mkdir = _a . mkdir , exports . readdir = _a . readdir , exports . readlink = _a . readlink , exports . rename = _a . rename , exports . rmdir = _a . rmdir , exports . stat = _a . stat , exports . symlink = _a . symlink , exports . unlink = _a . unlink ;
2355
2374
exports . IS_WINDOWS = process . platform === 'win32' ;
2356
2375
function exists ( fsPath ) {
@@ -2391,49 +2410,6 @@ function isRooted(p) {
2391
2410
return p . startsWith ( '/' ) ;
2392
2411
}
2393
2412
exports . isRooted = isRooted ;
2394
- /**
2395
- * Recursively create a directory at `fsPath`.
2396
- *
2397
- * This implementation is optimistic, meaning it attempts to create the full
2398
- * path first, and backs up the path stack from there.
2399
- *
2400
- * @param fsPath The path to create
2401
- * @param maxDepth The maximum recursion depth
2402
- * @param depth The current recursion depth
2403
- */
2404
- function mkdirP ( fsPath , maxDepth = 1000 , depth = 1 ) {
2405
- return __awaiter ( this , void 0 , void 0 , function * ( ) {
2406
- assert_1 . ok ( fsPath , 'a path argument must be provided' ) ;
2407
- fsPath = path . resolve ( fsPath ) ;
2408
- if ( depth >= maxDepth )
2409
- return exports . mkdir ( fsPath ) ;
2410
- try {
2411
- yield exports . mkdir ( fsPath ) ;
2412
- return ;
2413
- }
2414
- catch ( err ) {
2415
- switch ( err . code ) {
2416
- case 'ENOENT' : {
2417
- yield mkdirP ( path . dirname ( fsPath ) , maxDepth , depth + 1 ) ;
2418
- yield exports . mkdir ( fsPath ) ;
2419
- return ;
2420
- }
2421
- default : {
2422
- let stats ;
2423
- try {
2424
- stats = yield exports . stat ( fsPath ) ;
2425
- }
2426
- catch ( err2 ) {
2427
- throw err ;
2428
- }
2429
- if ( ! stats . isDirectory ( ) )
2430
- throw err ;
2431
- }
2432
- }
2433
- }
2434
- } ) ;
2435
- }
2436
- exports . mkdirP = mkdirP ;
2437
2413
/**
2438
2414
* Best effort attempt to determine whether a file exists and is executable.
2439
2415
* @param filePath file path to check
@@ -2530,6 +2506,12 @@ function isUnixExecutable(stats) {
2530
2506
( ( stats . mode & 8 ) > 0 && stats . gid === process . getgid ( ) ) ||
2531
2507
( ( stats . mode & 64 ) > 0 && stats . uid === process . getuid ( ) ) ) ;
2532
2508
}
2509
+ // Get the path of cmd.exe in windows
2510
+ function getCmdPath ( ) {
2511
+ var _a ;
2512
+ return ( _a = process . env [ 'COMSPEC' ] ) !== null && _a !== void 0 ? _a : `cmd.exe` ;
2513
+ }
2514
+ exports . getCmdPath = getCmdPath ;
2533
2515
//# sourceMappingURL=io-util.js.map
2534
2516
2535
2517
/***/ } ) ,
@@ -2539,6 +2521,25 @@ function isUnixExecutable(stats) {
2539
2521
2540
2522
"use strict" ;
2541
2523
2524
+ var __createBinding = ( this && this . __createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
2525
+ if ( k2 === undefined ) k2 = k ;
2526
+ Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
2527
+ } ) : ( function ( o , m , k , k2 ) {
2528
+ if ( k2 === undefined ) k2 = k ;
2529
+ o [ k2 ] = m [ k ] ;
2530
+ } ) ) ;
2531
+ var __setModuleDefault = ( this && this . __setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
2532
+ Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
2533
+ } ) : function ( o , v ) {
2534
+ o [ "default" ] = v ;
2535
+ } ) ;
2536
+ var __importStar = ( this && this . __importStar ) || function ( mod ) {
2537
+ if ( mod && mod . __esModule ) return mod ;
2538
+ var result = { } ;
2539
+ if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . hasOwnProperty . call ( mod , k ) ) __createBinding ( result , mod , k ) ;
2540
+ __setModuleDefault ( result , mod ) ;
2541
+ return result ;
2542
+ } ;
2542
2543
var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
2543
2544
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
2544
2545
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
@@ -2549,11 +2550,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2549
2550
} ) ;
2550
2551
} ;
2551
2552
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
2552
- const childProcess = __nccwpck_require__ ( 2081 ) ;
2553
- const path = __nccwpck_require__ ( 1017 ) ;
2553
+ exports . findInPath = exports . which = exports . mkdirP = exports . rmRF = exports . mv = exports . cp = void 0 ;
2554
+ const assert_1 = __nccwpck_require__ ( 9491 ) ;
2555
+ const childProcess = __importStar ( __nccwpck_require__ ( 2081 ) ) ;
2556
+ const path = __importStar ( __nccwpck_require__ ( 1017 ) ) ;
2554
2557
const util_1 = __nccwpck_require__ ( 3837 ) ;
2555
- const ioUtil = __nccwpck_require__ ( 1962 ) ;
2558
+ const ioUtil = __importStar ( __nccwpck_require__ ( 1962 ) ) ;
2556
2559
const exec = util_1 . promisify ( childProcess . exec ) ;
2560
+ const execFile = util_1 . promisify ( childProcess . execFile ) ;
2557
2561
/**
2558
2562
* Copies a file or folder.
2559
2563
* Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js
@@ -2564,14 +2568,14 @@ const exec = util_1.promisify(childProcess.exec);
2564
2568
*/
2565
2569
function cp ( source , dest , options = { } ) {
2566
2570
return __awaiter ( this , void 0 , void 0 , function * ( ) {
2567
- const { force, recursive } = readCopyOptions ( options ) ;
2571
+ const { force, recursive, copySourceDirectory } = readCopyOptions ( options ) ;
2568
2572
const destStat = ( yield ioUtil . exists ( dest ) ) ? yield ioUtil . stat ( dest ) : null ;
2569
2573
// Dest is an existing file, but not forcing
2570
2574
if ( destStat && destStat . isFile ( ) && ! force ) {
2571
2575
return ;
2572
2576
}
2573
2577
// If dest is an existing directory, should copy inside.
2574
- const newDest = destStat && destStat . isDirectory ( )
2578
+ const newDest = destStat && destStat . isDirectory ( ) && copySourceDirectory
2575
2579
? path . join ( dest , path . basename ( source ) )
2576
2580
: dest ;
2577
2581
if ( ! ( yield ioUtil . exists ( source ) ) ) {
@@ -2636,12 +2640,22 @@ function rmRF(inputPath) {
2636
2640
if ( ioUtil . IS_WINDOWS ) {
2637
2641
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
2638
2642
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
2643
+ // Check for invalid characters
2644
+ // https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
2645
+ if ( / [ * " < > | ] / . test ( inputPath ) ) {
2646
+ throw new Error ( 'File path must not contain `*`, `"`, `<`, `>` or `|` on Windows' ) ;
2647
+ }
2639
2648
try {
2649
+ const cmdPath = ioUtil . getCmdPath ( ) ;
2640
2650
if ( yield ioUtil . isDirectory ( inputPath , true ) ) {
2641
- yield exec ( `rd /s /q "${ inputPath } "` ) ;
2651
+ yield exec ( `${ cmdPath } /s /c "rd /s /q "%inputPath%""` , {
2652
+ env : { inputPath }
2653
+ } ) ;
2642
2654
}
2643
2655
else {
2644
- yield exec ( `del /f /a "${ inputPath } "` ) ;
2656
+ yield exec ( `${ cmdPath } /s /c "del /f /a "%inputPath%""` , {
2657
+ env : { inputPath }
2658
+ } ) ;
2645
2659
}
2646
2660
}
2647
2661
catch ( err ) {
@@ -2674,7 +2688,7 @@ function rmRF(inputPath) {
2674
2688
return ;
2675
2689
}
2676
2690
if ( isDir ) {
2677
- yield exec ( `rm -rf " ${ inputPath } "` ) ;
2691
+ yield execFile ( `rm` , [ ` -rf` , ` ${ inputPath } ` ] ) ;
2678
2692
}
2679
2693
else {
2680
2694
yield ioUtil . unlink ( inputPath ) ;
@@ -2692,7 +2706,8 @@ exports.rmRF = rmRF;
2692
2706
*/
2693
2707
function mkdirP ( fsPath ) {
2694
2708
return __awaiter ( this , void 0 , void 0 , function * ( ) {
2695
- yield ioUtil . mkdirP ( fsPath ) ;
2709
+ assert_1 . ok ( fsPath , 'a path argument must be provided' ) ;
2710
+ yield ioUtil . mkdir ( fsPath , { recursive : true } ) ;
2696
2711
} ) ;
2697
2712
}
2698
2713
exports . mkdirP = mkdirP ;
@@ -2720,62 +2735,80 @@ function which(tool, check) {
2720
2735
throw new Error ( `Unable to locate executable file: ${ tool } . Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.` ) ;
2721
2736
}
2722
2737
}
2738
+ return result ;
2723
2739
}
2724
- try {
2725
- // build the list of extensions to try
2726
- const extensions = [ ] ;
2727
- if ( ioUtil . IS_WINDOWS && process . env . PATHEXT ) {
2728
- for ( const extension of process . env . PATHEXT . split ( path . delimiter ) ) {
2729
- if ( extension ) {
2730
- extensions . push ( extension ) ;
2731
- }
2740
+ const matches = yield findInPath ( tool ) ;
2741
+ if ( matches && matches . length > 0 ) {
2742
+ return matches [ 0 ] ;
2743
+ }
2744
+ return '' ;
2745
+ } ) ;
2746
+ }
2747
+ exports . which = which ;
2748
+ /**
2749
+ * Returns a list of all occurrences of the given tool on the system path.
2750
+ *
2751
+ * @returns Promise<string[]> the paths of the tool
2752
+ */
2753
+ function findInPath ( tool ) {
2754
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
2755
+ if ( ! tool ) {
2756
+ throw new Error ( "parameter 'tool' is required" ) ;
2757
+ }
2758
+ // build the list of extensions to try
2759
+ const extensions = [ ] ;
2760
+ if ( ioUtil . IS_WINDOWS && process . env [ 'PATHEXT' ] ) {
2761
+ for ( const extension of process . env [ 'PATHEXT' ] . split ( path . delimiter ) ) {
2762
+ if ( extension ) {
2763
+ extensions . push ( extension ) ;
2732
2764
}
2733
2765
}
2734
- // if it's rooted, return it if exists. otherwise return empty.
2735
- if ( ioUtil . isRooted ( tool ) ) {
2736
- const filePath = yield ioUtil . tryGetExecutablePath ( tool , extensions ) ;
2737
- if ( filePath ) {
2738
- return filePath ;
2739
- }
2740
- return '' ;
2741
- }
2742
- // if any path separators, return empty
2743
- if ( tool . includes ( '/' ) || ( ioUtil . IS_WINDOWS && tool . includes ( '\\' ) ) ) {
2744
- return '' ;
2745
- }
2746
- // build the list of directories
2747
- //
2748
- // Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
2749
- // it feels like we should not do this. Checking the current directory seems like more of a use
2750
- // case of a shell, and the which() function exposed by the toolkit should strive for consistency
2751
- // across platforms.
2752
- const directories = [ ] ;
2753
- if ( process . env . PATH ) {
2754
- for ( const p of process . env . PATH . split ( path . delimiter ) ) {
2755
- if ( p ) {
2756
- directories . push ( p ) ;
2757
- }
2758
- }
2766
+ }
2767
+ // if it's rooted, return it if exists. otherwise return empty.
2768
+ if ( ioUtil . isRooted ( tool ) ) {
2769
+ const filePath = yield ioUtil . tryGetExecutablePath ( tool , extensions ) ;
2770
+ if ( filePath ) {
2771
+ return [ filePath ] ;
2759
2772
}
2760
- // return the first match
2761
- for ( const directory of directories ) {
2762
- const filePath = yield ioUtil . tryGetExecutablePath ( directory + path . sep + tool , extensions ) ;
2763
- if ( filePath ) {
2764
- return filePath ;
2773
+ return [ ] ;
2774
+ }
2775
+ // if any path separators, return empty
2776
+ if ( tool . includes ( path . sep ) ) {
2777
+ return [ ] ;
2778
+ }
2779
+ // build the list of directories
2780
+ //
2781
+ // Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
2782
+ // it feels like we should not do this. Checking the current directory seems like more of a use
2783
+ // case of a shell, and the which() function exposed by the toolkit should strive for consistency
2784
+ // across platforms.
2785
+ const directories = [ ] ;
2786
+ if ( process . env . PATH ) {
2787
+ for ( const p of process . env . PATH . split ( path . delimiter ) ) {
2788
+ if ( p ) {
2789
+ directories . push ( p ) ;
2765
2790
}
2766
2791
}
2767
- return '' ;
2768
2792
}
2769
- catch ( err ) {
2770
- throw new Error ( `which failed with message ${ err . message } ` ) ;
2793
+ // find all matches
2794
+ const matches = [ ] ;
2795
+ for ( const directory of directories ) {
2796
+ const filePath = yield ioUtil . tryGetExecutablePath ( path . join ( directory , tool ) , extensions ) ;
2797
+ if ( filePath ) {
2798
+ matches . push ( filePath ) ;
2799
+ }
2771
2800
}
2801
+ return matches ;
2772
2802
} ) ;
2773
2803
}
2774
- exports . which = which ;
2804
+ exports . findInPath = findInPath ;
2775
2805
function readCopyOptions ( options ) {
2776
2806
const force = options . force == null ? true : options . force ;
2777
2807
const recursive = Boolean ( options . recursive ) ;
2778
- return { force, recursive } ;
2808
+ const copySourceDirectory = options . copySourceDirectory == null
2809
+ ? true
2810
+ : Boolean ( options . copySourceDirectory ) ;
2811
+ return { force, recursive, copySourceDirectory } ;
2779
2812
}
2780
2813
function cpDirRecursive ( sourceDir , destDir , currentDepth , force ) {
2781
2814
return __awaiter ( this , void 0 , void 0 , function * ( ) {
0 commit comments