Skip to content
14 changes: 7 additions & 7 deletions packages/core/src/amazonq/commons/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { existsSync } from 'fs'
import * as vscode from 'vscode'
import { featureDevScheme } from '../../amazonqFeatureDev/constants'
import { fs } from '../../shared'

export async function openDiff(leftPath: string, rightPath: string, tabId: string) {
const { left, right } = getFileDiffUris(leftPath, rightPath, tabId)
const { left, right } = await getFileDiffUris(leftPath, rightPath, tabId)
await vscode.commands.executeCommand('vscode.diff', left, right)
}

export async function openDeletedDiff(filePath: string, name: string, tabId: string) {
const fileUri = getOriginalFileUri(filePath, tabId)
const fileUri = await getOriginalFileUri(filePath, tabId)
await vscode.commands.executeCommand('vscode.open', fileUri, {}, `${name} (Deleted)`)
}

export function getOriginalFileUri(fullPath: string, tabId: string) {
return existsSync(fullPath) ? vscode.Uri.file(fullPath) : createAmazonQUri('empty', tabId)
export async function getOriginalFileUri(fullPath: string, tabId: string) {
return (await fs.exists(fullPath)) ? vscode.Uri.file(fullPath) : createAmazonQUri('empty', tabId)
}

export function getFileDiffUris(leftPath: string, rightPath: string, tabId: string) {
const left = getOriginalFileUri(leftPath, tabId)
export async function getFileDiffUris(leftPath: string, rightPath: string, tabId: string) {
const left = await getOriginalFileUri(leftPath, tabId)
const right = createAmazonQUri(rightPath, tabId)

return { left, right }
Expand Down
28 changes: 14 additions & 14 deletions packages/core/src/amazonq/lsp/lspController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from 'vscode'
import * as path from 'path'
import * as fs from 'fs-extra'
import { chmodSync, createWriteStream } from 'fs'
import * as crypto from 'crypto'
import { getLogger } from '../../shared/logger/logger'
import { CurrentWsFolders, collectFilesForIndex } from '../../shared/utilities/workspaceUtils'
Expand All @@ -19,7 +19,7 @@ import { CodeWhispererSettings } from '../../codewhisperer/util/codewhispererSet
import { activate as activateLsp } from './lspClient'
import { telemetry } from '../../shared/telemetry'
import { isCloud9 } from '../../shared/extensionUtilities'
import { globals, ToolkitError } from '../../shared'
import { fs, globals, ToolkitError } from '../../shared'
import { AuthUtil } from '../../codewhisperer'
import { isWeb } from '../../shared/extensionGlobals'
import { getUserAgent } from '../../shared/telemetry/util'
Expand Down Expand Up @@ -105,7 +105,7 @@ export class LspController {
throw new ToolkitError(`Failed to download. Error: ${JSON.stringify(res)}`)
}
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(localFile)
const file = createWriteStream(localFile)
res.body.pipe(file)
res.body.on('error', (err) => {
reject(err)
Expand Down Expand Up @@ -133,16 +133,16 @@ export class LspController {
}

async getFileSha384(filePath: string): Promise<string> {
const fileBuffer = await fs.promises.readFile(filePath)
const fileBuffer = await fs.readFile(filePath)
const hash = crypto.createHash('sha384')
hash.update(fileBuffer)
return hash.digest('hex')
}

isLspInstalled(context: vscode.ExtensionContext) {
async isLspInstalled(context: vscode.ExtensionContext) {
const localQServer = context.asAbsolutePath(path.join('resources', 'qserver'))
const localNodeRuntime = context.asAbsolutePath(path.join('resources', nodeBinName))
return fs.existsSync(localQServer) && fs.existsSync(localNodeRuntime)
return (await fs.exists(localQServer)) && (await fs.exists(localNodeRuntime))
}

getQserverFromManifest(manifest: Manifest): Content | undefined {
Expand Down Expand Up @@ -207,7 +207,7 @@ export class LspController {
getLogger().error(
`LspController: Downloaded file sha ${sha384} does not match manifest ${content.hashes[0]}.`
)
fs.removeSync(filePath)
await fs.delete(filePath)
return false
}
return true
Expand All @@ -225,19 +225,19 @@ export class LspController {
async tryInstallLsp(context: vscode.ExtensionContext): Promise<boolean> {
let tempFolder = undefined
try {
if (this.isLspInstalled(context)) {
if (await this.isLspInstalled(context)) {
getLogger().info(`LspController: LSP already installed`)
return true
}
// clean up previous downloaded LSP
const qserverPath = context.asAbsolutePath(path.join('resources', 'qserver'))
if (fs.existsSync(qserverPath)) {
if (await fs.exists(qserverPath)) {
await tryRemoveFolder(qserverPath)
}
// clean up previous downloaded node runtime
const nodeRuntimePath = context.asAbsolutePath(path.join('resources', nodeBinName))
if (fs.existsSync(nodeRuntimePath)) {
fs.rmSync(nodeRuntimePath)
if (await fs.exists(nodeRuntimePath)) {
await fs.delete(nodeRuntimePath)
}
// fetch download url for qserver and node runtime
const manifest: Manifest = (await this.fetchManifest()) as Manifest
Expand All @@ -258,16 +258,16 @@ export class LspController {
}
const zip = new AdmZip(qserverZipTempPath)
zip.extractAllTo(tempFolder)
fs.moveSync(path.join(tempFolder, 'qserver'), qserverPath)
await fs.rename(path.join(tempFolder, 'qserver'), qserverPath)

// download node runtime to temp folder
const nodeRuntimeTempPath = path.join(tempFolder, nodeBinName)
const downloadNodeOk = await this.downloadAndCheckHash(nodeRuntimeTempPath, nodeRuntimeContent)
if (!downloadNodeOk) {
return false
}
fs.chmodSync(nodeRuntimeTempPath, 0o755)
fs.moveSync(nodeRuntimeTempPath, nodeRuntimePath)
chmodSync(nodeRuntimeTempPath, 0o755)
await fs.rename(nodeRuntimeTempPath, nodeRuntimePath)
return true
} catch (e) {
getLogger().error(`LspController: Failed to setup LSP server ${e}`)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/awsService/iot/commands/createCert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/

import * as vscode from 'vscode'
import * as fs from 'fs-extra'
import * as path from 'path'
import { getLogger } from '../../../shared/logger'
import { localize } from '../../../shared/utilities/vsCodeUtils'
import { showViewLogsMessage } from '../../../shared/utilities/messages'
import { IotCertsFolderNode } from '../explorer/iotCertFolderNode'
import { fileExists } from '../../../shared/filesystemUtilities'
import { Iot } from 'aws-sdk'
import { fs } from '../../../shared'

// eslint-disable-next-line @typescript-eslint/naming-convention
const MODE_RW_R_R = 0o644 //File permission 0644 rw-r--r-- for PEM files.
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/awsService/iot/commands/createPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/

import * as vscode from 'vscode'
import * as fs from 'fs-extra'
import { getLogger } from '../../../shared/logger'
import { localize } from '../../../shared/utilities/vsCodeUtils'
import { showViewLogsMessage } from '../../../shared/utilities/messages'
import { IotPolicyFolderNode } from '../explorer/iotPolicyFolderNode'
import { fs } from '../../../shared'

/**
* Creates a policy from a policy document.
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function createPolicyCommand(node: IotPolicyFolderNode, getPolicyDo
await node.refreshNode()
}

export async function getPolicyDocument(): Promise<Buffer | undefined> {
export async function getPolicyDocument(): Promise<Uint8Array | undefined> {
const fileLocation = await vscode.window.showOpenDialog({
canSelectFolders: false,
canSelectFiles: true,
Expand All @@ -64,7 +64,7 @@ export async function getPolicyDocument(): Promise<Buffer | undefined> {

const policyLocation = fileLocation[0]

let data: Buffer
let data: Uint8Array
try {
data = await fs.readFile(policyLocation.fsPath)
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/codecatalyst/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { DevEnvClient } from '../shared/clients/devenvClient'
import { getLogger } from '../shared/logger'
import { AsyncCollection, toCollection } from '../shared/utilities/asyncCollection'
import { getCodeCatalystSpaceName, getCodeCatalystProjectName, getCodeCatalystDevEnvId } from '../shared/vscode/env'
import { writeFile } from 'fs-extra'
import { sshAgentSocketVariable, startSshAgent, startVscodeRemote } from '../shared/extensions/ssh'
import { ChildProcess } from '../shared/utilities/processUtils'
import { isDevenvVscode } from './utils'
Expand All @@ -31,6 +30,7 @@ import { ToolkitError } from '../shared/errors'
import { Result } from '../shared/utilities/result'
import { VscodeRemoteConnection, ensureDependencies } from '../shared/remoteSession'
import { SshConfig, sshLogFileLocation } from '../shared/sshConfig'
import { fs } from '../shared'

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

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

export function bearerTokenCacheLocation(devenvId: string): string {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/dev/codecatalyst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import { glob } from 'glob'
import * as fs from 'fs-extra'
import * as path from 'path'
import * as vscode from 'vscode'
import * as manifest from '../../package.json'
Expand All @@ -21,6 +20,7 @@ import { startVscodeRemote } from '../shared/extensions/ssh'
import { isValidResponse } from '../shared/wizards/wizard'
import { createQuickPick } from '../shared/ui/pickerPrompter'
import { createCommonButtons } from '../shared/ui/buttons'
import { fs } from '../shared'

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

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

const packageData = await fs.readFile(path.join(resp, 'package.json'), 'utf-8')
const packageData = await fs.readFileAsString(path.join(resp, 'package.json'))
const targetManfiest: typeof manifest = JSON.parse(packageData)
const destName = `${extPath}/${extId}-${targetManfiest.version}`
const source = `${resp}${path.sep}`
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/dynamicResources/awsResourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import { writeFileSync } from 'fs'
import { remove } from 'fs-extra'
import * as path from 'path'
import * as vscode from 'vscode'
import { CloudFormationClient } from '../shared/clients/cloudFormationClient'
Expand All @@ -20,6 +19,7 @@ import { ResourceNode } from './explorer/nodes/resourceNode'
import { ResourceTypeNode } from './explorer/nodes/resourceTypeNode'
import { isCloud9 } from '../shared/extensionUtilities'
import globals from '../shared/extensionGlobals'
import { fs } from '../shared'

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

Expand Down Expand Up @@ -97,7 +97,7 @@ export class AwsResourceManager {
}

if (uri.scheme === 'file') {
await remove(uri.fsPath)
await fs.delete(uri.fsPath)

globals.schemaService.registerMapping({
uri,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lambda/commands/createNewSamApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ import { waitUntil } from '../../shared/utilities/timeoutUtils'
import { debugNewSamAppUrl, launchConfigDocUrl } from '../../shared/constants'
import { getIdeProperties, isCloud9 } from '../../shared/extensionUtilities'
import { execFileSync } from 'child_process'
import { writeFile } from 'fs-extra'
import { checklogs } from '../../shared/localizedText'
import globals from '../../shared/extensionGlobals'
import { telemetry } from '../../shared/telemetry/telemetry'
import { LambdaArchitecture, Result, Runtime } from '../../shared/telemetry/telemetry'
import { getTelemetryReason, getTelemetryResult } from '../../shared/errors'
import { openUrl, replaceVscodeVars } from '../../shared/utilities/vsCodeUtils'
import { fs } from '../../shared'

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

await writeFile(readmeLocation, readme)
await fs.writeFile(readmeLocation, readme)
getLogger().debug(`writeToolkitReadme: wrote file: %O`, readmeLocation)

return true
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lambda/commands/downloadLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import AdmZip from 'adm-zip'
import * as fs from 'fs-extra'
import * as _ from 'lodash'
import * as path from 'path'
import * as vscode from 'vscode'
Expand All @@ -26,6 +25,7 @@ import { Progress } from 'got/dist/source'
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
import { telemetry } from '../../shared/telemetry/telemetry'
import { Result, Runtime } from '../../shared/telemetry/telemetry'
import { fs } from '../../shared'

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

if (await fs.pathExists(downloadLocation)) {
if (await fs.exists(downloadLocation)) {
const isConfirmed = await showConfirmationMessage({
prompt: localize(
'AWS.lambda.download.prompt',
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/lambda/config/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// Use jsonc-parser.parse instead of JSON.parse, as JSONC can handle comments. VS Code uses jsonc-parser
// under the hood to provide symbols for JSON documents, so this will keep us consistent with VS code.
import { access, writeFile, ensureDir } from 'fs-extra'
import * as jsonParser from 'jsonc-parser'
import * as os from 'os'
import * as _path from 'path'
Expand All @@ -17,6 +16,8 @@ import { ReadonlyJsonObject } from '../../shared/sam/debugger/awsSamDebugConfigu
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
import { getNormalizedRelativePath } from '../../shared/utilities/pathUtils'
import { saveDocumentIfDirty } from '../../shared/utilities/textDocumentUtilities'
import { access } from 'fs/promises'
import { fs } from '../../shared'

const localize = nls.loadMessageBundle()

Expand Down Expand Up @@ -197,11 +198,11 @@ export function showTemplatesConfigurationError(
}

export async function ensureTemplatesConfigFileExists(path: string): Promise<void> {
await ensureDir(_path.dirname(path))
await fs.mkdir(_path.dirname(path))
try {
await access(path)
} catch {
await writeFile(path, '{}')
await fs.writeFile(path, '{}')
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lambda/vue/configEditor/samInvokeBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as fs from 'fs-extra'
import * as path from 'path'
import * as vscode from 'vscode'
import * as nls from 'vscode-nls'
Expand Down Expand Up @@ -36,6 +35,7 @@ import globals from '../../../shared/extensionGlobals'
import { VueWebview } from '../../../webviews/main'
import { Commands } from '../../../shared/vscode/commands2'
import { telemetry } from '../../../shared/telemetry/telemetry'
import { fs } from '../../../shared'

const localize = nls.loadMessageBundle()

Expand Down Expand Up @@ -220,7 +220,7 @@ export class SamInvokeWebview extends VueWebview {
* @param config Config to save
*/
public async saveLaunchConfig(config: AwsSamDebuggerConfiguration): Promise<void> {
const uri = getUriFromLaunchConfig(config)
const uri = await getUriFromLaunchConfig(config)
if (!uri) {
// TODO Localize
void vscode.window.showErrorMessage(
Expand Down Expand Up @@ -289,7 +289,7 @@ export class SamInvokeWebview extends VueWebview {
resolveWorkspaceFolderVariable(undefined, config),
'Editor-Created Debug Config'
)
const targetUri = getUriFromLaunchConfig(finalConfig)
const targetUri = await getUriFromLaunchConfig(finalConfig)
const folder = targetUri ? vscode.workspace.getWorkspaceFolder(targetUri) : undefined

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

function getUriFromLaunchConfig(config: AwsSamDebuggerConfiguration): vscode.Uri | undefined {
async function getUriFromLaunchConfig(config: AwsSamDebuggerConfiguration): Promise<vscode.Uri | undefined> {
let targetPath: string
if (isTemplateTargetProperties(config.invokeTarget)) {
targetPath = config.invokeTarget.templatePath
Expand All @@ -342,7 +342,7 @@ function getUriFromLaunchConfig(config: AwsSamDebuggerConfiguration): vscode.Uri
const workspaceFolders = vscode.workspace.workspaceFolders || []
for (const workspaceFolder of workspaceFolders) {
const absolutePath = tryGetAbsolutePath(workspaceFolder, targetPath)
if (fs.pathExistsSync(absolutePath)) {
if (await fs.exists(absolutePath)) {
return vscode.Uri.file(absolutePath)
}
}
Expand Down
Loading
Loading