22 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33 * SPDX-License-Identifier: Apache-2.0
44 */
5-
65import path from 'path'
7- import { collectFiles , CollectFilesOptions } from '../../shared/utilities/workspaceUtils'
6+ import { collectFiles , CollectFilesOptions , CollectFilesResultItem } from '../../shared/utilities/workspaceUtils'
87import { CurrentWsFolders } from '../commons/types'
98import { ZipStream } from '../../shared/utilities/zipStream'
109
@@ -19,9 +18,9 @@ interface ZipProjectOptions {
1918}
2019
2120interface ZipProjectCustomizations {
22- isExcluded ?: ( relativePath : string , fileSize : number ) => boolean
23- checkForError ?: ( relativePath : string , fileSize : number ) => void | never
24- computeSideEffects ?: ( filePath : string ) => Promise < void > | void
21+ isExcluded ?: ( file : CollectFilesResultItem ) => boolean
22+ checkForError ?: ( file : CollectFilesResultItem ) => Error | undefined
23+ computeSideEffects ?: ( file : CollectFilesResultItem ) => Promise < void > | void
2524}
2625
2726export async function zipProject (
@@ -41,15 +40,16 @@ export async function zipProject(
4140 }
4241 zippedFiles . add ( file . zipFilePath )
4342
44- if ( customizations ?. isExcluded && customizations . isExcluded ( file . relativeFilePath , file . fileSizeBytes ) ) {
43+ if ( customizations ?. isExcluded && customizations . isExcluded ( file ) ) {
4544 continue
4645 }
47- if ( customizations ?. checkForError ) {
48- customizations . checkForError ( file . relativeFilePath , file . fileSizeBytes )
46+ const errorToThrow = customizations ?. checkForError ? customizations . checkForError ( file ) : undefined
47+ if ( errorToThrow ) {
48+ throw errorToThrow
4949 }
5050
5151 if ( customizations ?. computeSideEffects ) {
52- await customizations . computeSideEffects ( file . fileUri . fsPath )
52+ await customizations . computeSideEffects ( file )
5353 }
5454
5555 totalBytes += file . fileSizeBytes
@@ -58,7 +58,12 @@ export async function zipProject(
5858 const posixPath = file . zipFilePath . split ( path . sep ) . join ( path . posix . sep )
5959
6060 try {
61- zip . writeFile ( file . fileUri . fsPath , posixPath )
61+ // filepath will be out-of-sync for files with unsaved changes.
62+ if ( file . isText ) {
63+ zip . writeString ( file . fileContent , posixPath )
64+ } else {
65+ zip . writeFile ( file . fileUri . fsPath , posixPath )
66+ }
6267 } catch ( error ) {
6368 if ( error instanceof Error && error . message . includes ( 'File not found' ) ) {
6469 // No-op: Skip if file was deleted or does not exist
0 commit comments