3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
import * as vscode from 'vscode'
6
- import * as fs from 'fs'
6
+ import * as nodefs from 'fs'
7
7
import * as path from 'path'
8
8
import * as os from 'os'
9
9
import * as codeWhisperer from '../../client/codewhisperer'
@@ -44,7 +44,7 @@ import { AuthUtil } from '../../util/authUtil'
44
44
import { createCodeWhispererChatStreamingClient } from '../../../shared/clients/codewhispererChatClient'
45
45
import { downloadExportResultArchive } from '../../../shared/utilities/download'
46
46
import { ExportIntent , TransformationDownloadArtifactType } from '@amzn/codewhisperer-streaming'
47
- import fs2 from '../../../shared/fs/fs'
47
+ import fs from '../../../shared/fs/fs'
48
48
import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSession'
49
49
import { convertToTimeString , encodeHTML } from '../../../shared/utilities/textUtilities'
50
50
@@ -109,7 +109,7 @@ export async function uploadArtifactToS3(
109
109
) {
110
110
throwIfCancelled ( )
111
111
try {
112
- const uploadFileByteSize = ( await fs . promises . stat ( fileName ) ) . size
112
+ const uploadFileByteSize = ( await nodefs . promises . stat ( fileName ) ) . size
113
113
getLogger ( ) . info (
114
114
`Uploading project artifact at %s with checksum %s using uploadId: %s and size %s kB` ,
115
115
fileName ,
@@ -177,7 +177,7 @@ export async function stopJob(jobId: string) {
177
177
}
178
178
179
179
export async function uploadPayload ( payloadFileName : string , uploadContext ?: UploadContext ) {
180
- const buffer = fs . readFileSync ( payloadFileName )
180
+ const buffer = Buffer . from ( await fs . readFile ( payloadFileName ) )
181
181
const sha256 = getSha256 ( buffer )
182
182
183
183
throwIfCancelled ( )
@@ -249,7 +249,7 @@ function isExcludedDependencyFile(path: string): boolean {
249
249
* getFilesRecursively on the source code folder.
250
250
*/
251
251
function getFilesRecursively ( dir : string , isDependenciesFolder : boolean ) : string [ ] {
252
- const entries = fs . readdirSync ( dir , { withFileTypes : true } )
252
+ const entries = nodefs . readdirSync ( dir , { withFileTypes : true } )
253
253
const files = entries . flatMap ( ( entry ) => {
254
254
const res = path . resolve ( dir , entry . name )
255
255
// 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
301
301
const sourceFiles = getFilesRecursively ( modulePath , false )
302
302
let sourceFilesSize = 0
303
303
for ( const file of sourceFiles ) {
304
- if ( fs . statSync ( file ) . isDirectory ( ) ) {
304
+ if ( nodefs . statSync ( file ) . isDirectory ( ) ) {
305
305
getLogger ( ) . info ( 'CodeTransformation: Skipping directory, likely a symlink' )
306
306
continue
307
307
}
308
308
const relativePath = path . relative ( modulePath , file )
309
309
const paddedPath = path . join ( 'sources' , relativePath )
310
310
zip . addLocalFile ( file , path . dirname ( paddedPath ) )
311
- sourceFilesSize += ( await fs . promises . stat ( file ) ) . size
311
+ sourceFilesSize += ( await nodefs . promises . stat ( file ) ) . size
312
312
}
313
313
getLogger ( ) . info ( `CodeTransformation: source code files size = ${ sourceFilesSize } ` )
314
314
}
315
315
316
316
throwIfCancelled ( )
317
317
318
318
let dependencyFiles : string [ ] = [ ]
319
- if ( fs . existsSync ( dependenciesFolder . path ) ) {
319
+ if ( await fs . exists ( dependenciesFolder . path ) ) {
320
320
dependencyFiles = getFilesRecursively ( dependenciesFolder . path , true )
321
321
}
322
322
@@ -330,7 +330,7 @@ export async function zipCode({ dependenciesFolder, humanInTheLoopFlag, modulePa
330
330
// const paddedPath = path.join(`dependencies/${dependenciesFolder.name}`, relativePath)
331
331
const paddedPath = path . join ( `dependencies/` , relativePath )
332
332
zip . addLocalFile ( file , path . dirname ( paddedPath ) )
333
- dependencyFilesSize += ( await fs . promises . stat ( file ) ) . size
333
+ dependencyFilesSize += ( await nodefs . promises . stat ( file ) ) . size
334
334
}
335
335
getLogger ( ) . info ( `CodeTransformation: dependency files size = ${ dependencyFilesSize } ` )
336
336
dependenciesCopied = true
@@ -353,19 +353,19 @@ export async function zipCode({ dependenciesFolder, humanInTheLoopFlag, modulePa
353
353
}
354
354
355
355
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 } )
359
359
}
360
360
} catch ( e : any ) {
361
361
throw Error ( 'Failed to zip project' )
362
362
} finally {
363
363
if ( logFilePath ) {
364
- fs . rmSync ( logFilePath )
364
+ await fs . delete ( logFilePath )
365
365
}
366
366
}
367
367
368
- const zipSize = ( await fs . promises . stat ( tempFilePath ) ) . size
368
+ const zipSize = ( await nodefs . promises . stat ( tempFilePath ) ) . size
369
369
370
370
const exceedsLimit = zipSize > CodeWhispererConstants . uploadZipSizeLimitInBytes
371
371
@@ -409,7 +409,7 @@ export async function startJob(uploadId: string) {
409
409
}
410
410
411
411
export function getImageAsBase64 ( filePath : string ) {
412
- const fileContents = fs . readFileSync ( filePath , { encoding : 'base64' } )
412
+ const fileContents = nodefs . readFileSync ( filePath , { encoding : 'base64' } )
413
413
return `data:image/svg+xml;base64,${ fileContents } `
414
414
}
415
415
@@ -725,9 +725,9 @@ export async function downloadAndExtractResultArchive(
725
725
pathToArchiveDir : string ,
726
726
downloadArtifactType : TransformationDownloadArtifactType
727
727
) {
728
- const archivePathExists = await fs2 . existsDir ( pathToArchiveDir )
728
+ const archivePathExists = await fs . existsDir ( pathToArchiveDir )
729
729
if ( ! archivePathExists ) {
730
- await fs2 . mkdir ( pathToArchiveDir )
730
+ await fs . mkdir ( pathToArchiveDir )
731
731
}
732
732
733
733
const pathToArchive = path . join ( pathToArchiveDir , 'ExportResultsArchive.zip' )
0 commit comments