@@ -14,7 +14,7 @@ export interface ZippedWorkspaceResult {
1414}
1515
1616interface ZipProjectOptions {
17- zip ?: ZipStream
17+ includeProjectName ?: boolean
1818}
1919
2020interface 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 ( '' )
0 commit comments