Skip to content

Commit 6b83fb3

Browse files
committed
temp
1 parent eb29e81 commit 6b83fb3

File tree

3 files changed

+36
-39
lines changed

3 files changed

+36
-39
lines changed

packages/core/src/amazonq/util/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export async function prepareRepoData(
144144
excludePatterns: excludePatterns,
145145
filterFn: filterFn,
146146
},
147-
isExcluded,
147+
{ isExcluded },
148148
{ zip: options?.zip ?? new ZipStream() }
149149
)
150150

packages/core/src/amazonq/util/zipProjectUtil.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
*/
55

66
import path from 'path'
7-
import { fs } from '../../shared/fs/fs'
87
import { collectFiles, CollectFilesOptions } from '../../shared/utilities/workspaceUtils'
98
import { CurrentWsFolders } from '../commons/types'
109
import { ZipStream } from '../../shared/utilities/zipStream'
11-
import { hasCode } from '../../shared/errors'
1210

13-
export interface ZippedResult {
11+
export interface ZippedWorkspaceResult {
1412
zipFileBuffer: Buffer
1513
zipFileChecksum: string
1614
totalFileBytes: number
@@ -20,13 +18,19 @@ interface ZipProjectOptions {
2018
zip?: ZipStream
2119
}
2220

21+
interface ZipProjectCustomizations {
22+
isExcluded?: (relativePath: string, fileSize: number) => boolean
23+
checkForError?: (relativePath: string, fileSize: number) => void | never
24+
computeSideEffects?: (filePath: string) => Promise<void> | void
25+
}
26+
2327
export async function zipProject(
2428
repoRootPaths: string[],
2529
workspaceFolders: CurrentWsFolders,
2630
collectFilesOptions: CollectFilesOptions,
27-
isExcluded: (relativePath: string, fileSize: number) => boolean,
31+
customizations?: ZipProjectCustomizations,
2832
options?: ZipProjectOptions
29-
): Promise<ZippedResult> {
33+
): Promise<ZippedWorkspaceResult> {
3034
const zip = options?.zip ?? new ZipStream()
3135
const files = await collectFiles(repoRootPaths, workspaceFolders, collectFilesOptions)
3236
const zippedFiles = new Set()
@@ -37,25 +41,18 @@ export async function zipProject(
3741
}
3842
zippedFiles.add(file.zipFilePath)
3943

40-
const fileSize = await fs
41-
.stat(file.fileUri.fsPath)
42-
.then((r) => r.size)
43-
.catch((e) => {
44-
if (hasCode(e) && e.code === 'ENOENT') {
45-
// No-op: Skip if file does not exist
46-
return
47-
}
48-
throw e
49-
})
50-
if (!fileSize) {
44+
if (customizations?.isExcluded && customizations.isExcluded(file.relativeFilePath, file.fileSizeBytes)) {
5145
continue
5246
}
47+
if (customizations?.checkForError) {
48+
customizations.checkForError(file.relativeFilePath, file.fileSizeBytes)
49+
}
5350

54-
if (isExcluded(file.relativeFilePath, fileSize)) {
55-
continue
51+
if (customizations?.computeSideEffects) {
52+
await customizations.computeSideEffects(file.fileUri.fsPath)
5653
}
5754

58-
totalBytes += fileSize
55+
totalBytes += file.fileSizeBytes
5956
// Paths in zip should be POSIX compliant regardless of OS
6057
// Reference: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
6158
const posixPath = file.zipFilePath.split(path.sep).join(path.posix.sep)

packages/core/src/codewhisperer/util/zipUtil.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,8 @@ export class ZipUtil {
208208

209209
protected async zipProject(useCase: FeatureUseCase, projectPath?: string, metadataDir?: string) {
210210
const zip = new admZip()
211-
let projectPaths = []
212-
if (useCase === FeatureUseCase.TEST_GENERATION && projectPath) {
213-
projectPaths.push(projectPath)
214-
} else {
215-
projectPaths = this.getProjectPaths()
216-
}
211+
const projectPaths =
212+
useCase === FeatureUseCase.TEST_GENERATION && projectPath ? [projectPath] : this.getProjectPaths()
217213
if (useCase === FeatureUseCase.CODE_SCAN) {
218214
await this.processCombinedGitDiff(zip, projectPaths, '', CodeWhispererConstants.CodeAnalysisScope.PROJECT)
219215
}
@@ -412,26 +408,30 @@ export class ZipUtil {
412408
return
413409
}
414410

415-
const sourceFiles = await collectFiles(
416-
projectPaths,
417-
(useCase === FeatureUseCase.TEST_GENERATION
411+
const workspaceFolders = (
412+
useCase === FeatureUseCase.TEST_GENERATION
418413
? [...(vscode.workspace.workspaceFolders ?? [])].sort(
419414
(a, b) => b.uri.fsPath.length - a.uri.fsPath.length
420415
)
421-
: vscode.workspace.workspaceFolders) as CurrentWsFolders,
422-
{
423-
maxTotalSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(),
424-
excludePatterns:
425-
useCase === FeatureUseCase.TEST_GENERATION
426-
? [...CodeWhispererConstants.testGenExcludePatterns, ...defaultExcludePatterns]
427-
: defaultExcludePatterns,
428-
}
429-
)
416+
: vscode.workspace.workspaceFolders
417+
) as CurrentWsFolders
418+
419+
const collectFilesOptions = {
420+
maxTotalSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(),
421+
excludePatterns:
422+
useCase === FeatureUseCase.TEST_GENERATION
423+
? [...CodeWhispererConstants.testGenExcludePatterns, ...defaultExcludePatterns]
424+
: defaultExcludePatterns,
425+
}
426+
427+
const sourceFiles = await collectFiles(projectPaths, workspaceFolders, collectFilesOptions)
428+
430429
for (const file of sourceFiles) {
431430
const projectName = path.basename(file.workspaceFolder.uri.fsPath)
432431
const zipEntryPath = this.getZipEntryPath(projectName, file.relativeFilePath)
432+
const fileExtension = path.extname(file.fileUri.fsPath)
433433

434-
if (ZipConstants.knownBinaryFileExts.includes(path.extname(file.fileUri.fsPath))) {
434+
if (ZipConstants.knownBinaryFileExts.includes(fileExtension)) {
435435
if (useCase === FeatureUseCase.TEST_GENERATION) {
436436
continue
437437
}

0 commit comments

Comments
 (0)