Skip to content

Commit b29d360

Browse files
committed
remove more occurences of fs-extra
1 parent 55cc95e commit b29d360

File tree

8 files changed

+34
-24
lines changed

8 files changed

+34
-24
lines changed

packages/core/src/codecatalyst/model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { DevEnvClient } from '../shared/clients/devenvClient'
1818
import { getLogger } from '../shared/logger'
1919
import { AsyncCollection, toCollection } from '../shared/utilities/asyncCollection'
2020
import { getCodeCatalystSpaceName, getCodeCatalystProjectName, getCodeCatalystDevEnvId } from '../shared/vscode/env'
21-
import { writeFile } from 'fs-extra'
2221
import { sshAgentSocketVariable, startSshAgent, startVscodeRemote } from '../shared/extensions/ssh'
2322
import { ChildProcess } from '../shared/utilities/processUtils'
2423
import { isDevenvVscode } from './utils'
@@ -31,6 +30,7 @@ import { ToolkitError } from '../shared/errors'
3130
import { Result } from '../shared/utilities/result'
3231
import { VscodeRemoteConnection, ensureDependencies } from '../shared/remoteSession'
3332
import { SshConfig, sshLogFileLocation } from '../shared/sshConfig'
33+
import { fs } from '../shared'
3434

3535
export type DevEnvironmentId = Pick<DevEnvironment, 'id' | 'org' | 'project'>
3636
export const connectScriptPrefix = 'codecatalyst_connect'
@@ -134,7 +134,7 @@ export function createBoundProcess(envProvider: EnvProvider): typeof ChildProces
134134
}
135135

136136
export async function cacheBearerToken(bearerToken: string, devenvId: string): Promise<void> {
137-
await writeFile(bearerTokenCacheLocation(devenvId), `${bearerToken}`, 'utf8')
137+
await fs.writeFile(bearerTokenCacheLocation(devenvId), `${bearerToken}`, 'utf8')
138138
}
139139

140140
export function bearerTokenCacheLocation(devenvId: string): string {

packages/core/src/dev/codecatalyst.ts

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

66
import { glob } from 'glob'
7-
import * as fs from 'fs-extra'
87
import * as path from 'path'
98
import * as vscode from 'vscode'
109
import * as manifest from '../../package.json'
@@ -21,6 +20,7 @@ import { startVscodeRemote } from '../shared/extensions/ssh'
2120
import { isValidResponse } from '../shared/wizards/wizard'
2221
import { createQuickPick } from '../shared/ui/pickerPrompter'
2322
import { createCommonButtons } from '../shared/ui/buttons'
23+
import { fs } from '../shared'
2424

2525
type LazyProgress<T> = vscode.Progress<T> & vscode.Disposable & { getToken(): Timeout }
2626

@@ -217,7 +217,7 @@ async function installVsix(
217217
if (path.extname(resp) !== '.vsix') {
218218
progress.report({ message: 'Copying extension...' })
219219

220-
const packageData = await fs.readFile(path.join(resp, 'package.json'), 'utf-8')
220+
const packageData = await fs.readFileAsString(path.join(resp, 'package.json'))
221221
const targetManfiest: typeof manifest = JSON.parse(packageData)
222222
const destName = `${extPath}/${extId}-${targetManfiest.version}`
223223
const source = `${resp}${path.sep}`

packages/core/src/dynamicResources/awsResourceManager.ts

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

66
import { writeFileSync } from 'fs'
7-
import { remove } from 'fs-extra'
87
import * as path from 'path'
98
import * as vscode from 'vscode'
109
import { CloudFormationClient } from '../shared/clients/cloudFormationClient'
@@ -20,6 +19,7 @@ import { ResourceNode } from './explorer/nodes/resourceNode'
2019
import { ResourceTypeNode } from './explorer/nodes/resourceTypeNode'
2120
import { isCloud9 } from '../shared/extensionUtilities'
2221
import globals from '../shared/extensionGlobals'
22+
import { fs } from '../shared'
2323

2424
export const resourceFileGlobPattern = '**/*.awsResource.json'
2525

@@ -97,7 +97,7 @@ export class AwsResourceManager {
9797
}
9898

9999
if (uri.scheme === 'file') {
100-
await remove(uri.fsPath)
100+
await fs.delete(uri.fsPath)
101101

102102
globals.schemaService.registerMapping({
103103
uri,

packages/core/src/lambda/commands/createNewSamApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ import { waitUntil } from '../../shared/utilities/timeoutUtils'
4242
import { debugNewSamAppUrl, launchConfigDocUrl } from '../../shared/constants'
4343
import { getIdeProperties, isCloud9 } from '../../shared/extensionUtilities'
4444
import { execFileSync } from 'child_process'
45-
import { writeFile } from 'fs-extra'
4645
import { checklogs } from '../../shared/localizedText'
4746
import globals from '../../shared/extensionGlobals'
4847
import { telemetry } from '../../shared/telemetry/telemetry'
4948
import { LambdaArchitecture, Result, Runtime } from '../../shared/telemetry/telemetry'
5049
import { getTelemetryReason, getTelemetryResult } from '../../shared/errors'
5150
import { openUrl, replaceVscodeVars } from '../../shared/utilities/vsCodeUtils'
51+
import { fs } from '../../shared'
5252

5353
export const samInitTemplateFiles: string[] = ['template.yaml', 'template.yml']
5454
export const samInitReadmeFile: string = 'README.TOOLKIT.md'
@@ -472,7 +472,7 @@ export async function writeToolkitReadme(
472472
: 'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps.html'
473473
)
474474

475-
await writeFile(readmeLocation, readme)
475+
await fs.writeFile(readmeLocation, readme)
476476
getLogger().debug(`writeToolkitReadme: wrote file: %O`, readmeLocation)
477477

478478
return true

packages/core/src/lambda/commands/downloadLambda.ts

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

66
import AdmZip from 'adm-zip'
7-
import * as fs from 'fs-extra'
87
import * as _ from 'lodash'
98
import * as path from 'path'
109
import * as vscode from 'vscode'
@@ -26,6 +25,7 @@ import { Progress } from 'got/dist/source'
2625
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
2726
import { telemetry } from '../../shared/telemetry/telemetry'
2827
import { Result, Runtime } from '../../shared/telemetry/telemetry'
28+
import { fs } from '../../shared'
2929

3030
export async function downloadLambdaCommand(functionNode: LambdaFunctionNode) {
3131
const result = await runDownloadLambda(functionNode)
@@ -57,7 +57,7 @@ async function runDownloadLambda(functionNode: LambdaFunctionNode): Promise<Resu
5757
const downloadLocation = path.join(selectedUri.fsPath, functionName, path.sep)
5858
const downloadLocationName = vscode.workspace.asRelativePath(downloadLocation, true)
5959

60-
if (await fs.pathExists(downloadLocation)) {
60+
if (await fs.exists(downloadLocation)) {
6161
const isConfirmed = await showConfirmationMessage({
6262
prompt: localize(
6363
'AWS.lambda.download.prompt',

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55

66
// Use jsonc-parser.parse instead of JSON.parse, as JSONC can handle comments. VS Code uses jsonc-parser
77
// under the hood to provide symbols for JSON documents, so this will keep us consistent with VS code.
8-
import { access, writeFile, ensureDir } from 'fs-extra'
98
import * as jsonParser from 'jsonc-parser'
109
import * as os from 'os'
1110
import * as _path from 'path'
1211
import * as vscode from 'vscode'
1312
import * as nls from 'vscode-nls'
1413
import * as fsUtils from '../../shared/filesystemUtilities'
14+
import * as fsExtra from 'fs-extra'
1515
import { getLogger, Logger } from '../../shared/logger'
1616
import { ReadonlyJsonObject } from '../../shared/sam/debugger/awsSamDebugConfiguration'
1717
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
1818
import { getNormalizedRelativePath } from '../../shared/utilities/pathUtils'
1919
import { saveDocumentIfDirty } from '../../shared/utilities/textDocumentUtilities'
20+
import { fs } from '../../shared'
2021

2122
const localize = nls.loadMessageBundle()
2223

@@ -197,11 +198,11 @@ export function showTemplatesConfigurationError(
197198
}
198199

199200
export async function ensureTemplatesConfigFileExists(path: string): Promise<void> {
200-
await ensureDir(_path.dirname(path))
201+
await fs.mkdir(_path.dirname(path))
201202
try {
202-
await access(path)
203+
await fsExtra.access(path)
203204
} catch {
204-
await writeFile(path, '{}')
205+
await fs.writeFile(path, '{}')
205206
}
206207
}
207208

packages/core/src/lambda/vue/configEditor/samInvokeBackend.ts

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

6-
import * as fs from 'fs-extra'
76
import * as path from 'path'
87
import * as vscode from 'vscode'
98
import * as nls from 'vscode-nls'
@@ -36,6 +35,7 @@ import globals from '../../../shared/extensionGlobals'
3635
import { VueWebview } from '../../../webviews/main'
3736
import { Commands } from '../../../shared/vscode/commands2'
3837
import { telemetry } from '../../../shared/telemetry/telemetry'
38+
import { fs } from '../../../shared'
3939

4040
const localize = nls.loadMessageBundle()
4141

@@ -220,7 +220,7 @@ export class SamInvokeWebview extends VueWebview {
220220
* @param config Config to save
221221
*/
222222
public async saveLaunchConfig(config: AwsSamDebuggerConfiguration): Promise<void> {
223-
const uri = getUriFromLaunchConfig(config)
223+
const uri = await getUriFromLaunchConfig(config)
224224
if (!uri) {
225225
// TODO Localize
226226
void vscode.window.showErrorMessage(
@@ -289,7 +289,7 @@ export class SamInvokeWebview extends VueWebview {
289289
resolveWorkspaceFolderVariable(undefined, config),
290290
'Editor-Created Debug Config'
291291
)
292-
const targetUri = getUriFromLaunchConfig(finalConfig)
292+
const targetUri = await getUriFromLaunchConfig(finalConfig)
293293
const folder = targetUri ? vscode.workspace.getWorkspaceFolder(targetUri) : undefined
294294

295295
// Cloud9 currently can't resolve the `aws-sam` debug config provider.
@@ -321,7 +321,7 @@ export function registerSamInvokeVueCommand(context: ExtContext): vscode.Disposa
321321
})
322322
}
323323

324-
function getUriFromLaunchConfig(config: AwsSamDebuggerConfiguration): vscode.Uri | undefined {
324+
async function getUriFromLaunchConfig(config: AwsSamDebuggerConfiguration): Promise<vscode.Uri | undefined> {
325325
let targetPath: string
326326
if (isTemplateTargetProperties(config.invokeTarget)) {
327327
targetPath = config.invokeTarget.templatePath
@@ -342,7 +342,7 @@ function getUriFromLaunchConfig(config: AwsSamDebuggerConfiguration): vscode.Uri
342342
const workspaceFolders = vscode.workspace.workspaceFolders || []
343343
for (const workspaceFolder of workspaceFolders) {
344344
const absolutePath = tryGetAbsolutePath(workspaceFolder, targetPath)
345-
if (fs.pathExistsSync(absolutePath)) {
345+
if (await fs.exists(absolutePath)) {
346346
return vscode.Uri.file(absolutePath)
347347
}
348348
}

packages/core/src/shared/sshConfig.ts

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

66
import * as vscode from 'vscode'
77
import * as path from 'path'
8-
import * as fs from 'fs-extra'
98
import * as nls from 'vscode-nls'
109
import { getLogger } from './logger'
1110
import { ChildProcess, ChildProcessResult } from './utilities/processUtils'
@@ -17,6 +16,8 @@ import { CancellationError } from './utilities/timeoutUtils'
1716
import { getSshConfigPath } from './extensions/ssh'
1817
import globals from './extensionGlobals'
1918
import { fileExists, readFileAsString } from './filesystemUtilities'
19+
import { chmodSync } from 'fs'
20+
import fs from './fs/fs'
2021

2122
const localize = nls.loadMessageBundle()
2223

@@ -109,9 +110,17 @@ export class SshConfig {
109110
const sshConfigPath = getSshConfigPath()
110111
const section = this.createSSHConfigSection(proxyCommand)
111112
try {
112-
await fs.ensureDir(path.dirname(path.dirname(sshConfigPath)), { mode: 0o755 })
113-
await fs.ensureDir(path.dirname(sshConfigPath), 0o700)
114-
await fs.appendFile(sshConfigPath, section, { mode: 0o600 })
113+
const parentsDir = path.dirname(sshConfigPath)
114+
const grandParentsDir = path.dirname(parentsDir)
115+
// TODO: replace w/ fs.chmod once stub is merged.
116+
await fs.mkdir(grandParentsDir)
117+
chmodSync(grandParentsDir, 0o755)
118+
119+
await fs.mkdir(parentsDir)
120+
chmodSync(parentsDir, 0o700)
121+
122+
await fs.appendFile(sshConfigPath, section)
123+
chmodSync(sshConfigPath, 0o600)
115124
} catch (e) {
116125
const message = localize(
117126
'AWS.sshConfig.error.writeFail',
@@ -218,7 +227,7 @@ export async function ensureConnectScript(
218227
const isOutdated = contents1 !== contents2
219228

220229
if (isOutdated) {
221-
await fs.copyFile(versionedScript.fsPath, connectScript.fsPath)
230+
await fs.copy(versionedScript.fsPath, connectScript.fsPath)
222231
getLogger().info('ssh: updated connect script')
223232
}
224233

0 commit comments

Comments
 (0)