Skip to content

Commit 9f79ef3

Browse files
committed
fix: add option to include project name
1 parent acb7361 commit 9f79ef3

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ZippedWorkspaceResult {
1414
}
1515

1616
interface ZipProjectOptions {
17-
zip?: ZipStream
17+
includeProjectName?: boolean
1818
}
1919

2020
interface ZipProjectCustomizations {
@@ -28,7 +28,8 @@ export async function addToZip(
2828
workspaceFolders: CurrentWsFolders,
2929
collectFilesOptions: CollectFilesOptions,
3030
zip: ZipStream,
31-
customizations?: ZipProjectCustomizations
31+
customizations?: ZipProjectCustomizations,
32+
options?: ZipProjectOptions
3233
) {
3334
const files = await collectFiles(repoRootPaths, workspaceFolders, collectFilesOptions)
3435
const zippedFiles = new Set()
@@ -47,21 +48,20 @@ export async function addToZip(
4748
throw errorToThrow
4849
}
4950

50-
if (customizations?.computeSideEffects) {
51-
await customizations.computeSideEffects(file)
52-
}
53-
5451
totalBytes += file.fileSizeBytes
5552
// Paths in zip should be POSIX compliant regardless of OS
5653
// Reference: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
57-
const posixPath = file.zipFilePath.split(path.sep).join(path.posix.sep)
54+
const zipFilePath = options?.includeProjectName
55+
? path.join(path.basename(file.workspaceFolder.uri.fsPath), file.zipFilePath)
56+
: file.zipFilePath
57+
const posixPath = zipFilePath.split(path.sep).join(path.posix.sep)
5858

5959
try {
6060
// filepath will be out-of-sync for files with unsaved changes.
6161
if (file.isText) {
6262
zip.writeString(file.fileContent, posixPath)
6363
} else {
64-
zip.writeFile(file.fileUri.fsPath, posixPath)
64+
zip.writeFile(file.fileUri.fsPath, path.dirname(posixPath))
6565
}
6666
} catch (error) {
6767
if (error instanceof Error && error.message.includes('File not found')) {
@@ -71,6 +71,10 @@ export async function addToZip(
7171
}
7272
throw error
7373
}
74+
75+
if (customizations?.computeSideEffects) {
76+
await customizations.computeSideEffects(file)
77+
}
7478
}
7579

7680
return { zip, totalBytesAdded: totalBytes }
@@ -81,14 +85,15 @@ export async function zipProject(
8185
workspaceFolders: CurrentWsFolders,
8286
collectFilesOptions: CollectFilesOptions,
8387
customizations?: ZipProjectCustomizations,
84-
options?: ZipProjectOptions
88+
options?: ZipProjectOptions & { zip?: ZipStream }
8589
): Promise<ZippedWorkspaceResult> {
8690
const { zip, totalBytesAdded } = await addToZip(
8791
repoRootPaths,
8892
workspaceFolders,
8993
collectFilesOptions,
9094
options?.zip ?? new ZipStream(),
91-
customizations
95+
customizations,
96+
options
9297
)
9398
const zipResult = await zip.finalize()
9499
const zipFileBuffer = zipResult.streamBuffer.getContents() || Buffer.from('')

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,18 @@ export class ZipUtil {
453453
this._totalSize += file.fileSizeBytes
454454
}
455455

456-
await addToZip(projectPaths, workspaceFolders, collectFilesOptions, zip, {
457-
isExcluded,
458-
checkForError,
459-
computeSideEffects,
460-
})
456+
await addToZip(
457+
projectPaths,
458+
workspaceFolders,
459+
collectFilesOptions,
460+
zip,
461+
{
462+
isExcluded,
463+
checkForError,
464+
computeSideEffects,
465+
},
466+
{ includeProjectName: true }
467+
)
461468
}
462469

463470
protected processOtherFiles(zip: ZipStream, languageCount: Map<CodewhispererLanguage, number>) {

0 commit comments

Comments
 (0)