Skip to content

Commit 65fac13

Browse files
refactor(fs): rename read functions to be more specific, add docstrings (aws#5713)
## Problem Follow up from: aws#5689 ## Solution - rename 'readFileAsString' to 'readFileText' since this function assumes a text file (utf-8) encoding. - Add missing doc strings to copy and exist within fs wrapper. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Justin M. Keyes <[email protected]>
1 parent 401fc1e commit 65fac13

File tree

38 files changed

+108
-85
lines changed

38 files changed

+108
-85
lines changed

packages/amazonq/test/unit/amazonqGumby/humanInTheLoopManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('HumanInTheLoopManager', async function () {
3636
)
3737
const outputPathResult = path.join(outputDirectoryPath, 'pom.xml')
3838
assertEqualPaths(newPomFilePath.fsPath, outputPathResult)
39-
const newPomFileContents = await fs.readFileAsString(newPomFilePath.path)
39+
const newPomFileContents = await fs.readFileText(newPomFilePath.path)
4040
assert.strictEqual(
4141
stripStringWhitespace(newPomFileContents),
4242
stripStringWhitespace(`<?xml version="1.0" encoding="UTF-8"?>

packages/amazonq/test/unit/validation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('package validations', function () {
2323
*/
2424
it('has synced contributes.icons with core/package.json', async function () {
2525
const corePackageJson = JSON.parse(
26-
await fs.readFileAsString(path.resolve(__dirname, '../../../../core/package.json'))
26+
await fs.readFileText(path.resolve(__dirname, '../../../../core/package.json'))
2727
)
2828
assert.deepStrictEqual(packageJson.contributes.icons, corePackageJson.contributes.icons)
2929
})

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class LspController {
133133
}
134134

135135
async getFileSha384(filePath: string): Promise<string> {
136-
const fileBuffer = await fs.readFile(filePath)
136+
const fileBuffer = await fs.readFileBytes(filePath)
137137
const hash = crypto.createHash('sha384')
138138
hash.update(fileBuffer)
139139
return hash.digest('hex')

packages/core/src/auth/credentials/sharedCredentials.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ async function loadConfigFile(configUri?: vscode.Uri): Promise<ReturnType<typeof
230230
return []
231231
}
232232

233-
return parseIni(await fs.readFileAsString(configUri), configUri)
233+
return parseIni(await fs.readFileText(configUri), configUri)
234234
}
235235

236236
async function loadCredentialsFile(credentialsUri?: vscode.Uri): Promise<ReturnType<typeof parseIni>> {
237237
if (!credentialsUri || !(await fs.exists(credentialsUri))) {
238238
return []
239239
}
240240

241-
return parseIni(await fs.readFileAsString(credentialsUri), credentialsUri)
241+
return parseIni(await fs.readFileText(credentialsUri), credentialsUri)
242242
}
243243

244244
/**

packages/core/src/auth/sso/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class AuthSSOServer {
218218

219219
private async loadResource(res: http.ServerResponse, resourcePath: string) {
220220
try {
221-
const file = await fs.readFile(resourcePath)
221+
const file = await fs.readFileBytes(resourcePath)
222222
res.writeHead(200)
223223
res.end(file)
224224
} catch (e) {

packages/core/src/awsService/cdk/explorer/cdkProject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface CdkAppLocation {
1818
}
1919

2020
export async function getApp(location: CdkAppLocation): Promise<CdkApp> {
21-
const constructTree = JSON.parse(await fs.readFileAsString(location.treeUri)) as ConstructTree
21+
const constructTree = JSON.parse(await fs.readFileText(location.treeUri)) as ConstructTree
2222

2323
return { location, constructTree }
2424
}

packages/core/src/awsService/ec2/sshKeyPair.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class SshKeyPair {
6868
}
6969

7070
public async getPublicKey(): Promise<string> {
71-
const contents = await fs.readFileAsString(this.publicKeyPath)
71+
const contents = await fs.readFileText(this.publicKeyPath)
7272
return contents
7373
}
7474

packages/core/src/awsService/iot/commands/createPolicy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function getPolicyDocument(): Promise<Uint8Array | undefined> {
6666

6767
let data: Uint8Array
6868
try {
69-
data = await fs.readFile(policyLocation.fsPath)
69+
data = await fs.readFileBytes(policyLocation.fsPath)
7070
} catch (e) {
7171
getLogger().error('Failed to read policy document: %s', e)
7272
void showViewLogsMessage(localize('AWS.iot.createPolicy.error', 'Failed to read policy document'))

packages/core/src/codewhisperer/service/transformByQ/humanInTheLoopManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class HumanInTheLoopManager {
6464
}
6565

6666
public getDependencyListXmlOutput = async () =>
67-
await fs.readFileAsString(path.join(this.tmpDependencyListDir, this.localPathToXmlDependencyList))
67+
await fs.readFileText(path.join(this.tmpDependencyListDir, this.localPathToXmlDependencyList))
6868

6969
public createPomFileCopy = async (outputDirectoryPath: string, pomFileVirtualFileReference: vscode.Uri) => {
7070
const newPomCopyRef = await createPomCopy(outputDirectoryPath, pomFileVirtualFileReference, 'pom.xml')

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export async function stopJob(jobId: string) {
177177
}
178178

179179
export async function uploadPayload(payloadFileName: string, uploadContext?: UploadContext) {
180-
const buffer = Buffer.from(await fs.readFile(payloadFileName))
180+
const buffer = Buffer.from(await fs.readFileBytes(payloadFileName))
181181
const sha256 = getSha256(buffer)
182182

183183
throwIfCancelled()

0 commit comments

Comments
 (0)