11/* eslint-disable node-core/require-common-first, node-core/required-modules */
22'use strict' ;
33
4- const { execSync } = require ( 'child_process' ) ;
54const fs = require ( 'fs' ) ;
65const path = require ( 'path' ) ;
7- const { debuglog } = require ( 'util' ) ;
86const { isMainThread } = require ( 'worker_threads' ) ;
97
10- const debug = debuglog ( 'test/tmpdir' ) ;
11-
12- function rimrafSync ( pathname , { spawn = true } = { } ) {
13- const st = ( ( ) => {
14- try {
15- return fs . lstatSync ( pathname ) ;
16- } catch ( e ) {
17- if ( fs . existsSync ( pathname ) )
18- throw new Error ( `Something wonky happened rimrafing ${ pathname } ` ) ;
19- debug ( e ) ;
20- }
21- } ) ( ) ;
22-
23- // If (!st) then nothing to do.
24- if ( ! st ) {
25- return ;
26- }
27-
28- // On Windows first try to delegate rmdir to a shell.
29- if ( spawn && process . platform === 'win32' && st . isDirectory ( ) ) {
30- try {
31- // Try `rmdir` first.
32- execSync ( `rmdir /q /s ${ pathname } ` , { timeout : 1000 } ) ;
33- } catch ( e ) {
34- // Attempt failed. Log and carry on.
35- debug ( e ) ;
36- }
37- }
38-
39- fs . rmdirSync ( pathname , { recursive : true , maxRetries : 5 } ) ;
40-
41- if ( fs . existsSync ( pathname ) )
42- throw new Error ( `Unable to rimraf ${ pathname } ` ) ;
8+ function rimrafSync ( pathname ) {
9+ fs . rmdirSync ( pathname , { maxRetries : 3 , recursive : true } ) ;
4310}
4411
4512const testRoot = process . env . NODE_TEST_DIR ?
@@ -52,8 +19,8 @@ const tmpdirName = '.tmp.' +
5219const tmpPath = path . join ( testRoot , tmpdirName ) ;
5320
5421let firstRefresh = true ;
55- function refresh ( opts = { } ) {
56- rimrafSync ( this . path , opts ) ;
22+ function refresh ( ) {
23+ rimrafSync ( this . path ) ;
5724 fs . mkdirSync ( this . path ) ;
5825
5926 if ( firstRefresh ) {
@@ -70,7 +37,7 @@ function onexit() {
7037 process . chdir ( testRoot ) ;
7138
7239 try {
73- rimrafSync ( tmpPath , { spawn : false } ) ;
40+ rimrafSync ( tmpPath ) ;
7441 } catch ( e ) {
7542 console . error ( 'Can\'t clean tmpdir:' , tmpPath ) ;
7643
0 commit comments