Skip to content

Commit 9732e0b

Browse files
committed
remove instances of fs-extra
1 parent b29d360 commit 9732e0b

File tree

13 files changed

+55
-50
lines changed

13 files changed

+55
-50
lines changed

packages/core/src/lambda/config/templates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import * as _path from 'path'
1111
import * as vscode from 'vscode'
1212
import * as nls from 'vscode-nls'
1313
import * as fsUtils from '../../shared/filesystemUtilities'
14-
import * as fsExtra from 'fs-extra'
1514
import { getLogger, Logger } from '../../shared/logger'
1615
import { ReadonlyJsonObject } from '../../shared/sam/debugger/awsSamDebugConfiguration'
1716
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
1817
import { getNormalizedRelativePath } from '../../shared/utilities/pathUtils'
1918
import { saveDocumentIfDirty } from '../../shared/utilities/textDocumentUtilities'
19+
import { access } from 'fs/promises'
2020
import { fs } from '../../shared'
2121

2222
const localize = nls.loadMessageBundle()
@@ -200,7 +200,7 @@ export function showTemplatesConfigurationError(
200200
export async function ensureTemplatesConfigFileExists(path: string): Promise<void> {
201201
await fs.mkdir(_path.dirname(path))
202202
try {
203-
await fsExtra.access(path)
203+
await access(path)
204204
} catch {
205205
await fs.writeFile(path, '{}')
206206
}

packages/core/src/shared/extensions/yaml.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import { readFileSync } from 'fs-extra'
87
import { VSCODE_EXTENSION_ID } from '../extensions'
98
import { getLogger } from '../logger/logger'
109
import { getIdeProperties } from '../extensionUtilities'
1110
import { activateExtension } from '../utilities/vsCodeUtils'
1211
import { AWS_SCHEME } from '../constants'
12+
import * as fs2 from 'fs'
1313

1414
// sourced from https://github.com/redhat-developer/vscode-yaml/blob/3d82d61ea63d3e3a9848fe6b432f8f1f452c1bec/src/schema-extension-api.ts
1515
// removed everything that is not currently being used
@@ -52,7 +52,8 @@ export async function activateYamlExtension(): Promise<YamlExtension | undefined
5252
try {
5353
// SLOW: This request happens on every keystroke! (5MB+ read from filesystem).
5454
// This is a design flaw in this registerContributor() API.
55-
return readFileSync(vscode.Uri.parse(uri).fsPath).toString()
55+
// TODO: this function is non-async preventing us from using our fs module.
56+
return fs2.readFileSync(vscode.Uri.parse(uri).fsPath).toString()
5657
} catch (e) {
5758
getLogger().error(`YAML Extension: failed to read schema URI "${uri}": ${e}`)
5859
throw new Error(`${getIdeProperties().company} Toolkit could not parse JSON schema URI: ${uri}`)

packages/core/src/shared/sam/debugger/awsSamDebugger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as semver from 'semver'
77
import * as vscode from 'vscode'
8-
import * as fs from 'fs-extra'
98
import * as nls from 'vscode-nls'
109
import {
1110
getCodeRoot,
@@ -67,6 +66,7 @@ import { Logging } from '../../logger/commands'
6766
import { credentialHelpUrl, samTroubleshootingUrl } from '../../constants'
6867
import { Auth } from '../../../auth/auth'
6968
import { openUrl } from '../../utilities/vsCodeUtils'
69+
import fs from '../../fs/fs'
7070

7171
const localize = nls.loadMessageBundle()
7272

@@ -460,7 +460,7 @@ export class SamDebugConfigProvider implements vscode.DebugConfigurationProvider
460460
const handlerName = await getHandlerName(folder, config)
461461

462462
config.baseBuildDir = resolve(folder.uri.fsPath, config.sam?.buildDir ?? (await makeTemporaryToolkitFolder()))
463-
await fs.ensureDir(config.baseBuildDir)
463+
await fs.mkdir(config.baseBuildDir)
464464

465465
if (templateInvoke?.templatePath) {
466466
// Normalize to absolute path.

packages/core/src/shared/sam/debugger/csharpSamDebug.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { chmod, ensureDir, writeFile } from 'fs-extra'
76
import * as os from 'os'
87
import * as path from 'path'
98
import {
@@ -24,6 +23,8 @@ import { getLogger } from '../../logger'
2423
import * as vscode from 'vscode'
2524
import * as nls from 'vscode-nls'
2625
import globals from '../../extensionGlobals'
26+
import fs from '../../fs/fs'
27+
import { chmod } from 'fs/promises'
2728
const localize = nls.loadMessageBundle()
2829

2930
/**
@@ -109,7 +110,7 @@ function getDebuggerPath(parentFolder: string): string {
109110
}
110111

111112
async function _installDebugger({ debuggerPath }: InstallDebuggerArgs): Promise<void> {
112-
await ensureDir(debuggerPath)
113+
await fs.mkdir(debuggerPath)
113114

114115
try {
115116
getLogger().info(
@@ -202,7 +203,7 @@ async function downloadInstallScript(debuggerPath: string): Promise<string> {
202203
throw Error(`Failed to download ${installScriptUrl}`)
203204
}
204205

205-
await writeFile(installScriptPath, installScript, 'utf8')
206+
await fs.writeFile(installScriptPath, installScript, 'utf8')
206207
await chmod(installScriptPath, 0o700)
207208

208209
return installScriptPath
@@ -224,7 +225,7 @@ export async function makeDotnetDebugConfiguration(
224225
}
225226
const pipeArgs = ['-c', `docker exec -i $(docker ps -q -f publish=${config.debugPort}) \${debuggerCommand}`]
226227
config.debuggerPath = pathutil.normalize(getDebuggerPath(codeUri))
227-
await ensureDir(config.debuggerPath)
228+
await fs.mkdir(config.debuggerPath)
228229

229230
const isImageLambda = await isImageLambdaConfig(config)
230231

packages/core/src/shared/sam/debugger/goSamDebug.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { DefaultSamLocalInvokeCommand, waitForDebuggerMessages } from '../cli/sa
1515
import { runLambdaFunction } from '../localLambdaRunner'
1616
import { SamLaunchRequestArgs } from './awsSamDebugger'
1717
import { getLogger } from '../../logger'
18-
import * as fs from 'fs-extra'
19-
import fs2 from '../../fs/fs'
18+
import fs from '../../fs/fs'
19+
import { chmod, unlink } from 'fs/promises'
2020
import { ChildProcess } from '../../utilities/processUtils'
2121
import { Timeout } from '../../utilities/timeoutUtils'
2222
import { execFileSync, SpawnOptions } from 'child_process'
@@ -212,7 +212,7 @@ async function makeInstallScript(debuggerPath: string, isWindows: boolean): Prom
212212

213213
delveVersion = delveVersion.replace('v', '-')
214214
const installScriptPath: string = path.join(debuggerPath, `install${delveVersion}.${scriptExt}`)
215-
const alreadyInstalled = await fs2.exists(installScriptPath)
215+
const alreadyInstalled = await fs.exists(installScriptPath)
216216

217217
if (alreadyInstalled && delveVersion !== '') {
218218
return undefined
@@ -224,7 +224,7 @@ async function makeInstallScript(debuggerPath: string, isWindows: boolean): Prom
224224
script += `go build -o "${delvePath}" "${delveRepo}/cmd/dlv"\n`
225225

226226
await fs.writeFile(installScriptPath, script, 'utf8')
227-
await fs.chmod(installScriptPath, 0o755)
227+
await chmod(installScriptPath, 0o755)
228228

229229
return { path: installScriptPath, options: installOptions }
230230
}
@@ -236,7 +236,7 @@ async function makeInstallScript(debuggerPath: string, isWindows: boolean): Prom
236236
* @returns False when installation fails
237237
*/
238238
async function installDebugger(debuggerPath: string): Promise<boolean> {
239-
await fs.ensureDir(debuggerPath)
239+
await fs.mkdir(debuggerPath)
240240
const isWindows: boolean = os.platform() === 'win32'
241241
let installScript: InstallScript | undefined
242242

@@ -254,16 +254,16 @@ async function installDebugger(debuggerPath: string): Promise<boolean> {
254254
})
255255

256256
const code = install.exitCode
257-
if (!fs.existsSync(path.join(debuggerPath, 'dlv'))) {
257+
if (!(await fs.exists(path.join(debuggerPath, 'dlv')))) {
258258
throw new Error(`Install script did not generate the Delve binary: exit code ${code}`)
259259
} else if (code) {
260260
getLogger().warn(`Install script did not sucessfully run, using old Delve binary...`)
261261
} else {
262262
getLogger().info(`Installed Delve debugger in ${debuggerPath}`)
263263
}
264264
} catch (e) {
265-
if (installScript && (await fs2.exists(installScript.path))) {
266-
fs.unlinkSync(installScript.path) // Removes the install script since it failed
265+
if (installScript && (await fs.exists(installScript.path))) {
266+
await unlink(installScript.path) // Removes the install script since it failed
267267
}
268268
getLogger().error('Failed to cross-compile Delve debugger: %O', e as Error)
269269
return false

packages/core/src/shared/sam/debugger/pythonSamDebug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { Runtime } from 'aws-sdk/clients/lambda'
7-
import { writeFile } from 'fs-extra'
87
import * as os from 'os'
98
import * as path from 'path'
109
import {
@@ -26,6 +25,7 @@ import { getWorkspaceRelativePath } from '../../utilities/workspaceUtils'
2625
import { DefaultSamLocalInvokeCommand, waitForDebuggerMessages } from '../cli/samCliLocalInvoke'
2726
import { runLambdaFunction } from '../localLambdaRunner'
2827
import { SamLaunchRequestArgs } from './awsSamDebugger'
28+
import fs from '../../fs/fs'
2929

3030
/** SAM will mount the --debugger-path to /tmp/lambci_debug_files */
3131
const debugpyWrapperPath = '/tmp/lambci_debug_files/py_debug_wrapper.py'
@@ -56,14 +56,14 @@ async function makePythonDebugManifest(params: {
5656
if (params.useIkpdb) {
5757
manifestText = manifestText.replace(/[ \t]*ikp3db\b[^\r\n]*/, '')
5858
manifestText += `${os.EOL}ikp3db`
59-
await writeFile(debugManifestPath, manifestText)
59+
await fs.writeFile(debugManifestPath, manifestText)
6060
return debugManifestPath
6161
}
6262

6363
// TODO: If another module name includes the string "debugpy", this will be skipped...
6464
if (!params.useIkpdb && !manifestText.includes('debugpy')) {
6565
manifestText += `${os.EOL}debugpy>=1.0,<2`
66-
await writeFile(debugManifestPath, manifestText)
66+
await fs.writeFile(debugManifestPath, manifestText)
6767

6868
return debugManifestPath
6969
}

packages/core/src/shared/sam/debugger/typescriptSamDebug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { existsSync, PathLike, readFileSync } from 'fs'
7-
import { writeFileSync } from 'fs-extra'
87
import * as path from 'path'
98
import * as vscode from 'vscode'
109
import { isImageLambdaConfig, NodejsDebugConfiguration } from '../../../lambda/local/debugConfiguration'
@@ -18,6 +17,7 @@ import { DefaultSamLocalInvokeCommand, waitForDebuggerMessages } from '../cli/sa
1817
import { runLambdaFunction, waitForPort } from '../localLambdaRunner'
1918
import { SamLaunchRequestArgs } from './awsSamDebugger'
2019
import { findTypescriptCompiler } from '../../utilities/pathFind'
20+
import fs from '../../fs/fs'
2121

2222
const tsConfigFile = 'aws-toolkit-tsconfig.json'
2323

@@ -202,7 +202,7 @@ async function compileTypeScript(config: SamLaunchRequestArgs): Promise<void> {
202202
types.push('node')
203203
compilerOptions.types = [...new Set(types)]
204204

205-
writeFileSync(tsConfigPath, JSON.stringify(tsConfig, undefined, 4))
205+
await fs.writeFile(tsConfigPath, JSON.stringify(tsConfig, undefined, 4))
206206

207207
// resolve ts lambda handler to point into build directory relative to codeRoot
208208
const tsLambdaHandler = path.relative(config.codeRoot, path.join(tsBuildDir, config.invokeTarget.lambdaHandler))

packages/core/src/shared/sam/localLambdaRunner.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as vscode from 'vscode'
99
import * as nls from 'vscode-nls'
1010
import * as pathutil from '../utilities/pathUtils'
1111
import got, { OptionsOfTextResponseBody, RequestError } from 'got'
12-
import { copyFile, readFile, remove, writeFile } from 'fs-extra'
1312
import { isImageLambdaConfig } from '../../lambda/local/debugConfiguration'
1413
import { getFamily, RuntimeFamily } from '../../lambda/models/samLambdaRuntime'
1514
import { ExtContext } from '../extensions'
@@ -31,6 +30,7 @@ import { sleep } from '../utilities/timeoutUtils'
3130
import { showMessageWithCancel } from '../utilities/messages'
3231
import { ToolkitError, UnknownError } from '../errors'
3332
import { SamCliError } from './cli/samCliInvokerUtils'
33+
import fs from '../fs/fs'
3434

3535
const localize = nls.loadMessageBundle()
3636

@@ -259,7 +259,7 @@ async function invokeLambdaHandler(
259259
throw ToolkitError.chain(err, msg)
260260
} finally {
261261
if (config.sam?.buildDir === undefined) {
262-
await remove(config.templatePath)
262+
await fs.delete(config.templatePath)
263263
}
264264
}
265265
}
@@ -307,7 +307,7 @@ export async function runLambdaFunction(
307307
const payload =
308308
config.eventPayloadFile === undefined
309309
? undefined
310-
: JSON.parse(await readFile(config.eventPayloadFile, { encoding: 'utf-8' }))
310+
: JSON.parse(await fs.readFileAsString(config.eventPayloadFile))
311311

312312
apiRequest = requestLocalApi(timer, config.api!, config.apiPort!, payload)
313313
}
@@ -571,14 +571,14 @@ export async function makeJsonFiles(config: SamLaunchRequestArgs): Promise<void>
571571
if (Object.keys(configEnv).length !== 0) {
572572
const env = JSON.stringify(getEnvironmentVariables(makeResourceName(config), configEnv))
573573
config.envFile = path.join(config.baseBuildDir!, 'env-vars.json')
574-
await writeFile(config.envFile, env)
574+
await fs.writeFile(config.envFile, env)
575575
}
576576

577577
// container-env-vars.json
578578
if (config.containerEnvVars) {
579579
config.containerEnvFile = path.join(config.baseBuildDir!, 'container-env-vars.json')
580580
const containerEnv = JSON.stringify(config.containerEnvVars)
581-
await writeFile(config.containerEnvFile, containerEnv)
581+
await fs.writeFile(config.containerEnvFile, containerEnv)
582582
}
583583

584584
// event.json
@@ -594,12 +594,12 @@ export async function makeJsonFiles(config: SamLaunchRequestArgs): Promise<void>
594594
if (payloadPath) {
595595
const fullpath = tryGetAbsolutePath(config.workspaceFolder, payloadPath)
596596
try {
597-
JSON.parse(await readFile(fullpath, { encoding: 'utf-8' }))
597+
JSON.parse(await fs.readFileAsString(fullpath))
598598
} catch (e) {
599599
throw Error(`Invalid JSON in payload file: ${payloadPath}`)
600600
}
601-
await copyFile(fullpath, config.eventPayloadFile)
601+
await fs.copy(fullpath, config.eventPayloadFile)
602602
} else {
603-
await writeFile(config.eventPayloadFile, JSON.stringify(payloadObj || {}))
603+
await fs.writeFile(config.eventPayloadFile, JSON.stringify(payloadObj || {}))
604604
}
605605
}

packages/core/src/shared/templates/sam/samTemplateGenerator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { mkdirp, writeFile } from 'fs-extra'
76
import * as yaml from 'js-yaml'
87
import * as path from 'path'
98
import { Architecture } from '../../../lambda/models/samLambdaRuntime'
109
import * as filesystemUtilities from '../../../shared/filesystemUtilities'
1110
import * as CloudFormation from '../../cloudformation/cloudformation'
1211
import ZipResourceProperties = CloudFormation.ZipResourceProperties
12+
import fs from '../../fs/fs'
1313

1414
export class SamTemplateGenerator {
1515
private resourceName?: string
@@ -128,8 +128,8 @@ export class SamTemplateGenerator {
128128

129129
const parentDirectory: string = path.dirname(filename)
130130
if (!(await filesystemUtilities.fileExists(parentDirectory))) {
131-
await mkdirp(parentDirectory)
131+
await fs.mkdir(parentDirectory)
132132
}
133-
await writeFile(filename, templateAsYaml, 'utf8')
133+
await fs.writeFile(filename, templateAsYaml, 'utf8')
134134
}
135135
}

packages/core/src/shared/ui/common/variablesPrompter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import * as fs from 'fs-extra'
87
import { showViewLogsMessage } from '../../utilities/messages'
98
import { WIZARD_RETRY } from '../../wizards/wizard'
109
import { createQuickPick, DataQuickPickItem, QuickPickPrompter } from '../pickerPrompter'
1110
import * as nls from 'vscode-nls'
1211
import { PrompterButtons } from '../buttons'
1312
import { promisifyThenable } from '../../utilities/vsCodeUtils'
13+
import fs from '../../fs/fs'
1414

1515
const localize = nls.loadMessageBundle()
1616

@@ -72,7 +72,7 @@ export function createVariablesPrompter(
7272
throw new Error('Closed dialog')
7373
}
7474
const path = resp[0].fsPath
75-
const contents = await fs.promises.readFile(path)
75+
const contents = await fs.readFile(path)
7676
return parseEnvFile(contents.toString())
7777
} catch (err) {
7878
if ((err as Error).message !== 'Closed dialog') {

0 commit comments

Comments
 (0)