1616 * 
1717*/ 
1818
19- const  assert  =  require ( 'assert' ) ; 
20- const  fs  =  require ( 'fs' ) ; 
21- const  file  =  require ( '../../lib/utils/file' ) ; 
19+ const  {  existsSync,  readdirSync,  rmSync,  symlinkSync,  unlinkSync,  writeFileSync }  =  require ( 'fs' ) ; 
2220const  {  assertFileMode,  testRequiresWindowsElevation,  ensureDirs }  =  require ( './helpers' ) ; 
2321const  {  suite,  setup,  test }  =  require ( 'mocha' ) ; 
22+ const  assert  =  require ( 'assert' ) ; 
23+ const  file  =  require ( '../../lib/utils/file' ) ; 
24+ 
25+ // Shim to support older node versions 
26+ const  rmF  =  rmSync 
27+   ? ( path )  =>  rmSync ( path ,  {  force : true  } ) 
28+   : ( path )  =>  file . rmRf ( path ,  { } ) ; 
2429
2530suite ( 'fileUtils' ,  function  ( )  { 
2631
@@ -33,13 +38,13 @@ suite('fileUtils', function () {
3338
3439    test ( 'with dir' ,  function  ( )  { 
3540      file . mkdirP ( 'foo' ) ; 
36-       assert . ok ( fs . existsSync ( 'foo' ) ) ; 
41+       assert . ok ( existsSync ( 'foo' ) ) ; 
3742      ensureDirs ( false ,  'foo' ) ; 
3843    } ) ; 
3944
4045    test ( 'with subdir' ,  function  ( )  { 
4146      file . mkdirP ( 'foo/bar/baz/qux' ) ; 
42-       assert . ok ( fs . existsSync ( 'foo/bar/baz/qux' ) ) ; 
47+       assert . ok ( existsSync ( 'foo/bar/baz/qux' ) ) ; 
4348      ensureDirs ( false ,  'foo' ) ; 
4449    } ) ; 
4550
@@ -50,48 +55,48 @@ suite('fileUtils', function () {
5055    test ( 'with subdir' ,  function  ( )  { 
5156      ensureDirs ( 'foo/bar/baz/qux' ) ; 
5257      file . rmRf ( 'foo/bar' ) ; 
53-       assert . deepStrictEqual ( fs . readdirSync ( 'foo' ) ,  [ ] ) ; 
54-       assert . strictEqual ( fs . existsSync ( 'foo/bar' ) ,  false ) ; 
58+       assert . deepStrictEqual ( readdirSync ( 'foo' ) ,  [ ] ) ; 
59+       assert . strictEqual ( existsSync ( 'foo/bar' ) ,  false ) ; 
5560      ensureDirs ( false ,  'foo' ) ; 
5661    } ) ; 
5762
5863    test ( 'with symlink subdir' ,  function  ( )  { 
5964      testRequiresWindowsElevation ( this ) ; 
6065
6166      ensureDirs ( 'foo' ,  'bar' ) ; 
62-       fs . writeFileSync ( 'foo/hello.txt' ,  'hello, it\'s me' ) ; 
63-       fs . symlinkSync ( '../foo' ,  'bar/foo' ) ; 
67+       writeFileSync ( 'foo/hello.txt' ,  'hello, it\'s me' ) ; 
68+       symlinkSync ( '../foo' ,  'bar/foo' ) ; 
6469
6570      file . rmRf ( 'bar' ) ; 
6671
6772      // Make sure the bar directory was successfully deleted 
68-       assert . strictEqual ( fs . existsSync ( 'bar' ) ,  false ) ; 
73+       assert . strictEqual ( existsSync ( 'bar' ) ,  false ) ; 
6974
7075      // Make sure that the file inside the linked folder wasn't deleted 
71-       assert . strictEqual ( fs . existsSync ( 'foo/hello.txt' ) ,  true ) ; 
76+       assert . strictEqual ( existsSync ( 'foo/hello.txt' ) ,  true ) ; 
7277
7378      // Cleanup 
74-       fs . unlinkSync ( 'foo/hello.txt' ) ; 
79+       unlinkSync ( 'foo/hello.txt' ) ; 
7580      ensureDirs ( false ,  'foo' ,  'bar' ) ; 
7681    } ) ; 
7782
7883    test ( 'with symlinked dir' ,  function  ( )  { 
7984      testRequiresWindowsElevation ( this ) ; 
8085
8186      ensureDirs ( 'foo' ) ; 
82-       fs . writeFileSync ( 'foo/hello.txt' ,  'hello!' ) ; 
83-       fs . symlinkSync ( 'foo' ,  'bar' ) ; 
87+       writeFileSync ( 'foo/hello.txt' ,  'hello!' ) ; 
88+       symlinkSync ( 'foo' ,  'bar' ) ; 
8489
8590      file . rmRf ( 'bar' ) ; 
8691
8792      // Make sure the bar directory was successfully deleted 
88-       assert . strictEqual ( fs . existsSync ( 'bar' ) ,  false ) ; 
93+       assert . strictEqual ( existsSync ( 'bar' ) ,  false ) ; 
8994
9095      // Make sure that the file inside the linked folder wasn't deleted 
91-       assert . strictEqual ( fs . existsSync ( 'foo/hello.txt' ) ,  true ) ; 
96+       assert . strictEqual ( existsSync ( 'foo/hello.txt' ) ,  true ) ; 
9297
9398      // Cleanup 
94-       fs . unlinkSync ( 'foo/hello.txt' ) ; 
99+       unlinkSync ( 'foo/hello.txt' ) ; 
95100      ensureDirs ( false ,  'foo' ,  'bar' ) ; 
96101    } ) ; 
97102
@@ -101,10 +106,10 @@ suite('fileUtils', function () {
101106
102107    test ( 'with same name and different directory' ,  function  ( )  { 
103108      ensureDirs ( 'foo' ,  false ,  'bar' ) ; 
104-       fs . writeFileSync ( 'foo/bar.txt' ,  'w00t' ) ; 
109+       writeFileSync ( 'foo/bar.txt' ,  'w00t' ) ; 
105110
106111      file . cpR ( 'foo' ,  'bar' ) ; 
107-       assert . ok ( fs . existsSync ( 'bar/bar.txt' ) ) ; 
112+       assert . ok ( existsSync ( 'bar/bar.txt' ) ) ; 
108113
109114      ensureDirs ( false ,  'foo' ,  'bar' ) ; 
110115    } ) ; 
@@ -117,61 +122,61 @@ suite('fileUtils', function () {
117122
118123    test ( 'rename via copy in directory' ,  function  ( )  { 
119124      ensureDirs ( 'foo' ) ; 
120-       fs . writeFileSync ( 'foo/bar.txt' ,  'w00t' ) ; 
125+       writeFileSync ( 'foo/bar.txt' ,  'w00t' ) ; 
121126
122127      file . cpR ( 'foo/bar.txt' ,  'foo/baz.txt' ) ; 
123-       assert . ok ( fs . existsSync ( 'foo/baz.txt' ) ) ; 
128+       assert . ok ( existsSync ( 'foo/baz.txt' ) ) ; 
124129
125130      ensureDirs ( false ,  'foo' ) ; 
126131    } ) ; 
127132
128133    test ( 'rename via copy in base' ,  function  ( )  { 
129-       fs . writeFileSync ( 'bar.txt' ,  'w00t' ) ; 
134+       writeFileSync ( 'bar.txt' ,  'w00t' ) ; 
130135
131136      file . cpR ( 'bar.txt' ,  'baz.txt' ) ; 
132-       assert . ok ( fs . existsSync ( 'baz.txt' ) ) ; 
137+       assert . ok ( existsSync ( 'baz.txt' ) ) ; 
133138
134-       fs . rmSync ( 'bar.txt' ) ; 
135-       fs . rmSync ( 'baz.txt' ) ; 
139+       rmF ( 'bar.txt' ) ; 
140+       rmF ( 'baz.txt' ) ; 
136141    } ) ; 
137142
138143    test ( 'keeps file mode' ,  function  ( )  { 
139144      [  0o750 ,  0o744  ] . forEach ( ( mode )  =>  { 
140-         fs . writeFileSync ( 'bar.txt' ,  'w00t' ,  {  mode : mode  } ) ; 
145+         writeFileSync ( 'bar.txt' ,  'w00t' ,  {  mode : mode  } ) ; 
141146
142147        file . cpR ( 'bar.txt' ,  'baz.txt' ) ; 
143148        assertFileMode ( 'baz.txt' ,  mode ) ; 
144149
145-         fs . rmSync ( 'bar.txt' ) ; 
146-         fs . rmSync ( 'baz.txt' ) ; 
150+         rmF ( 'bar.txt' ) ; 
151+         rmF ( 'baz.txt' ) ; 
147152      } ) ; 
148153    } ) ; 
149154
150155    test ( 'keeps file mode when overwriting with preserveMode' ,  function  ( )  { 
151-       fs . writeFileSync ( 'bar.txt' ,  'w00t' ,  { mode : 0o755 } ) ; 
152-       fs . writeFileSync ( 'baz.txt' ,  'w00t!' ,  { mode : 0o744 } ) ; 
156+       writeFileSync ( 'bar.txt' ,  'w00t' ,  { mode : 0o755 } ) ; 
157+       writeFileSync ( 'baz.txt' ,  'w00t!' ,  { mode : 0o744 } ) ; 
153158
154159      file . cpR ( 'bar.txt' ,  'baz.txt' ,  { silent : true ,  preserveMode : true } ) ; 
155160      assertFileMode ( 'baz.txt' ,  0o755 ) ; 
156161
157-       fs . rmSync ( 'bar.txt' ) ; 
158-       fs . rmSync ( 'baz.txt' ) ; 
162+       rmF ( 'bar.txt' ) ; 
163+       rmF ( 'baz.txt' ) ; 
159164    } ) ; 
160165
161166    test ( 'does not keep file mode when overwriting' ,  function  ( )  { 
162-       fs . writeFileSync ( 'bar.txt' ,  'w00t' ,  { mode : 0o766 } ) ; 
163-       fs . writeFileSync ( 'baz.txt' ,  'w00t!' ,  { mode : 0o744 } ) ; 
167+       writeFileSync ( 'bar.txt' ,  'w00t' ,  { mode : 0o766 } ) ; 
168+       writeFileSync ( 'baz.txt' ,  'w00t!' ,  { mode : 0o744 } ) ; 
164169
165170      file . cpR ( 'bar.txt' ,  'baz.txt' ) ; 
166171      assertFileMode ( 'baz.txt' ,  0o744 ) ; 
167172
168-       fs . rmSync ( 'bar.txt' ) ; 
169-       fs . rmSync ( 'baz.txt' ) ; 
173+       rmF ( 'bar.txt' ) ; 
174+       rmF ( 'baz.txt' ) ; 
170175    } ) ; 
171176
172177    test ( 'copies file mode recursively' ,  function  ( )  { 
173178      ensureDirs ( 'foo' ,  false ,  'baz' ) ; 
174-       fs . writeFileSync ( 'foo/bar.txt' ,  'w00t' ,  { mode : 0o740 } ) ; 
179+       writeFileSync ( 'foo/bar.txt' ,  'w00t' ,  { mode : 0o740 } ) ; 
175180
176181      file . cpR ( 'foo' ,  'baz' ) ; 
177182      assertFileMode ( 'baz/bar.txt' ,  0o740 ) ; 
@@ -181,8 +186,8 @@ suite('fileUtils', function () {
181186
182187    test ( 'keeps file mode recursively' ,  function  ( )  { 
183188      ensureDirs ( 'foo' ,  'baz/foo' ) ; 
184-       fs . writeFileSync ( 'foo/bar.txt' ,  'w00t' ,  { mode : 0o740 } ) ; 
185-       fs . writeFileSync ( 'baz/foo/bar.txt' ,  'w00t!' ,  { mode : 0o755 } ) ; 
189+       writeFileSync ( 'foo/bar.txt' ,  'w00t' ,  { mode : 0o740 } ) ; 
190+       writeFileSync ( 'baz/foo/bar.txt' ,  'w00t!' ,  { mode : 0o755 } ) ; 
186191
187192      file . cpR ( 'foo' ,  'baz' ,  { silent : true ,  preserveMode : true } ) ; 
188193      assertFileMode ( 'baz/foo/bar.txt' ,  0o740 ) ; 
0 commit comments