44 */
55
66import assert from 'assert'
7- import * as nodeFsSync from 'fs'
87import * as path from 'path'
98import * as vscode from 'vscode'
109import * as FakeTimers from '@sinonjs/fake-timers'
@@ -14,10 +13,9 @@ import globals from '../shared/extensionGlobals'
1413import { waitUntil } from '../shared/utilities/timeoutUtils'
1514import { MetricName , MetricShapes } from '../shared/telemetry/telemetry'
1615import { keys , selectFrom } from '../shared/utilities/tsUtils'
17- import fs2 from '../shared/fs/fs'
16+ import fs from '../shared/fs/fs'
1817import { DeclaredCommand } from '../shared/vscode/commands2'
1918import { mkdirSync , existsSync } from 'fs'
20- import * as nodefs from 'fs/promises'
2119import { randomBytes } from 'crypto'
2220import request from '../shared/request'
2321import { stub } from 'sinon'
@@ -33,15 +31,15 @@ export async function toFile(o: any, filepath: string | vscode.Uri) {
3331 const file = typeof filepath === 'string' ? filepath : filepath . fsPath
3432 const text = o === undefined ? '' : o . toString ( )
3533 const dir = path . dirname ( file )
36- await fs2 . mkdir ( dir )
37- await fs2 . writeFile ( file , text )
34+ await fs . mkdir ( dir )
35+ await fs . writeFile ( file , text )
3836}
3937
4038/**
4139 * Gets the contents of `filepath` as UTF-8 encoded string.
4240 */
4341export async function fromFile ( filepath : string ) : Promise < string > {
44- return fs2 . readFileAsString ( filepath )
42+ return fs . readFileAsString ( filepath )
4543}
4644
4745/** Gets the full path to the Toolkit source root on this machine. */
@@ -97,7 +95,7 @@ export class TestFolder {
9795 await toFile ( content ?? '' , filePath )
9896
9997 if ( options ?. mode !== undefined ) {
100- await nodefs . chmod ( filePath , options . mode )
98+ await fs . chmod ( filePath , options . mode )
10199 }
102100
103101 return filePath
@@ -144,7 +142,7 @@ export async function createTestWorkspaceFolder(name?: string, subDir?: string):
144142 testTempDirs . push ( tempFolder )
145143 const finalWsFolder = subDir === undefined ? tempFolder : path . join ( tempFolder , subDir )
146144 if ( subDir !== undefined && subDir . length > 0 ) {
147- await nodefs . mkdir ( finalWsFolder , { recursive : true } )
145+ await fs . mkdir ( finalWsFolder )
148146 }
149147 return {
150148 uri : vscode . Uri . file ( finalWsFolder ) ,
@@ -157,7 +155,7 @@ export async function createTestFile(fileName: string): Promise<vscode.Uri> {
157155 const tempFolder = await makeTemporaryToolkitFolder ( )
158156 testTempDirs . push ( tempFolder ) // ensures this is deleted at the end
159157 const tempFilePath = path . join ( tempFolder , fileName )
160- await fs2 . writeFile ( tempFilePath , '' )
158+ await fs . writeFile ( tempFilePath , '' )
161159 return vscode . Uri . file ( tempFilePath )
162160}
163161
@@ -205,7 +203,7 @@ export async function createTestWorkspace(
205203
206204 do {
207205 const tempFilePath = path . join ( workspace . uri . fsPath , `${ fileNamePrefix } ${ n } ${ fileNameSuffix } ` )
208- await fs2 . writeFile ( tempFilePath , fileContent )
206+ await fs . writeFile ( tempFilePath , fileContent )
209207 } while ( -- n > 0 )
210208
211209 return workspace
@@ -236,7 +234,7 @@ export function assertEqualPaths(actual: string, expected: string, message?: str
236234 * Asserts that UTF-8 contents of `file` are equal to `expected`.
237235 */
238236export async function assertFileText ( file : string , expected : string , message ?: string | Error ) {
239- const actualContents = await fs2 . readFileAsString ( file )
237+ const actualContents = await fs . readFileAsString ( file )
240238 assert . strictEqual ( actualContents , expected , message )
241239}
242240
@@ -250,12 +248,12 @@ export async function tickPromise<T>(promise: Promise<T>, clock: FakeTimers.Inst
250248 * Creates an executable file (including any parent directories) with the given contents.
251249 */
252250export async function createExecutableFile ( filepath : string , contents : string ) : Promise < void > {
253- await fs2 . mkdir ( path . dirname ( filepath ) )
251+ await fs . mkdir ( path . dirname ( filepath ) )
254252 if ( process . platform === 'win32' ) {
255- await fs2 . writeFile ( filepath , `@echo OFF$\r\n${ contents } \r\n` )
253+ await fs . writeFile ( filepath , `@echo OFF$\r\n${ contents } \r\n` )
256254 } else {
257- await fs2 . writeFile ( filepath , `#!/bin/sh\n${ contents } ` )
258- nodeFsSync . chmodSync ( filepath , 0o744 )
255+ await fs . writeFile ( filepath , `#!/bin/sh\n${ contents } ` )
256+ await fs . chmod ( filepath , 0o744 )
259257 }
260258}
261259
0 commit comments