33 * SPDX-License-Identifier: Apache-2.0
44 */
55import * as vscode from 'vscode'
6- import * as fs from 'fs'
6+ import * as nodefs from 'fs'
77import * as path from 'path'
88import * as os from 'os'
99import * as codeWhisperer from '../../client/codewhisperer'
@@ -44,7 +44,7 @@ import { AuthUtil } from '../../util/authUtil'
4444import { createCodeWhispererChatStreamingClient } from '../../../shared/clients/codewhispererChatClient'
4545import { downloadExportResultArchive } from '../../../shared/utilities/download'
4646import { ExportIntent , TransformationDownloadArtifactType } from '@amzn/codewhisperer-streaming'
47- import fs2 from '../../../shared/fs/fs'
47+ import fs from '../../../shared/fs/fs'
4848import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSession'
4949import { convertToTimeString , encodeHTML } from '../../../shared/utilities/textUtilities'
5050
@@ -109,7 +109,7 @@ export async function uploadArtifactToS3(
109109) {
110110 throwIfCancelled ( )
111111 try {
112- const uploadFileByteSize = ( await fs . promises . stat ( fileName ) ) . size
112+ const uploadFileByteSize = ( await nodefs . promises . stat ( fileName ) ) . size
113113 getLogger ( ) . info (
114114 `Uploading project artifact at %s with checksum %s using uploadId: %s and size %s kB` ,
115115 fileName ,
@@ -177,7 +177,7 @@ export async function stopJob(jobId: string) {
177177}
178178
179179export async function uploadPayload ( payloadFileName : string , uploadContext ?: UploadContext ) {
180- const buffer = fs . readFileSync ( payloadFileName )
180+ const buffer = Buffer . from ( await fs . readFile ( payloadFileName ) )
181181 const sha256 = getSha256 ( buffer )
182182
183183 throwIfCancelled ( )
@@ -249,7 +249,7 @@ function isExcludedDependencyFile(path: string): boolean {
249249 * getFilesRecursively on the source code folder.
250250 */
251251function getFilesRecursively ( dir : string , isDependenciesFolder : boolean ) : string [ ] {
252- const entries = fs . readdirSync ( dir , { withFileTypes : true } )
252+ const entries = nodefs . readdirSync ( dir , { withFileTypes : true } )
253253 const files = entries . flatMap ( ( entry ) => {
254254 const res = path . resolve ( dir , entry . name )
255255 // exclude 'target' directory from ZIP (except if zipping dependencies) due to issues in backend
@@ -301,22 +301,22 @@ export async function zipCode({ dependenciesFolder, humanInTheLoopFlag, modulePa
301301 const sourceFiles = getFilesRecursively ( modulePath , false )
302302 let sourceFilesSize = 0
303303 for ( const file of sourceFiles ) {
304- if ( fs . statSync ( file ) . isDirectory ( ) ) {
304+ if ( nodefs . statSync ( file ) . isDirectory ( ) ) {
305305 getLogger ( ) . info ( 'CodeTransformation: Skipping directory, likely a symlink' )
306306 continue
307307 }
308308 const relativePath = path . relative ( modulePath , file )
309309 const paddedPath = path . join ( 'sources' , relativePath )
310310 zip . addLocalFile ( file , path . dirname ( paddedPath ) )
311- sourceFilesSize += ( await fs . promises . stat ( file ) ) . size
311+ sourceFilesSize += ( await nodefs . promises . stat ( file ) ) . size
312312 }
313313 getLogger ( ) . info ( `CodeTransformation: source code files size = ${ sourceFilesSize } ` )
314314 }
315315
316316 throwIfCancelled ( )
317317
318318 let dependencyFiles : string [ ] = [ ]
319- if ( fs . existsSync ( dependenciesFolder . path ) ) {
319+ if ( await fs . exists ( dependenciesFolder . path ) ) {
320320 dependencyFiles = getFilesRecursively ( dependenciesFolder . path , true )
321321 }
322322
@@ -330,7 +330,7 @@ export async function zipCode({ dependenciesFolder, humanInTheLoopFlag, modulePa
330330 // const paddedPath = path.join(`dependencies/${dependenciesFolder.name}`, relativePath)
331331 const paddedPath = path . join ( `dependencies/` , relativePath )
332332 zip . addLocalFile ( file , path . dirname ( paddedPath ) )
333- dependencyFilesSize += ( await fs . promises . stat ( file ) ) . size
333+ dependencyFilesSize += ( await nodefs . promises . stat ( file ) ) . size
334334 }
335335 getLogger ( ) . info ( `CodeTransformation: dependency files size = ${ dependencyFilesSize } ` )
336336 dependenciesCopied = true
@@ -353,19 +353,19 @@ export async function zipCode({ dependenciesFolder, humanInTheLoopFlag, modulePa
353353 }
354354
355355 tempFilePath = path . join ( os . tmpdir ( ) , 'zipped-code.zip' )
356- fs . writeFileSync ( tempFilePath , zip . toBuffer ( ) )
357- if ( fs . existsSync ( dependenciesFolder . path ) ) {
358- fs . rmSync ( dependenciesFolder . path , { recursive : true , force : true } )
356+ await fs . writeFile ( tempFilePath , zip . toBuffer ( ) )
357+ if ( await fs . exists ( dependenciesFolder . path ) ) {
358+ await fs . delete ( dependenciesFolder . path , { recursive : true , force : true } )
359359 }
360360 } catch ( e : any ) {
361361 throw Error ( 'Failed to zip project' )
362362 } finally {
363363 if ( logFilePath ) {
364- fs . rmSync ( logFilePath )
364+ await fs . delete ( logFilePath )
365365 }
366366 }
367367
368- const zipSize = ( await fs . promises . stat ( tempFilePath ) ) . size
368+ const zipSize = ( await nodefs . promises . stat ( tempFilePath ) ) . size
369369
370370 const exceedsLimit = zipSize > CodeWhispererConstants . uploadZipSizeLimitInBytes
371371
@@ -409,7 +409,7 @@ export async function startJob(uploadId: string) {
409409}
410410
411411export function getImageAsBase64 ( filePath : string ) {
412- const fileContents = fs . readFileSync ( filePath , { encoding : 'base64' } )
412+ const fileContents = nodefs . readFileSync ( filePath , { encoding : 'base64' } )
413413 return `data:image/svg+xml;base64,${ fileContents } `
414414}
415415
@@ -725,9 +725,9 @@ export async function downloadAndExtractResultArchive(
725725 pathToArchiveDir : string ,
726726 downloadArtifactType : TransformationDownloadArtifactType
727727) {
728- const archivePathExists = await fs2 . existsDir ( pathToArchiveDir )
728+ const archivePathExists = await fs . existsDir ( pathToArchiveDir )
729729 if ( ! archivePathExists ) {
730- await fs2 . mkdir ( pathToArchiveDir )
730+ await fs . mkdir ( pathToArchiveDir )
731731 }
732732
733733 const pathToArchive = path . join ( pathToArchiveDir , 'ExportResultsArchive.zip' )
0 commit comments