44 */
55
66import path from 'path'
7- import { fs } from '../../shared/fs/fs'
87import { collectFiles , CollectFilesOptions } from '../../shared/utilities/workspaceUtils'
98import { CurrentWsFolders } from '../commons/types'
109import { 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+
2327export 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 )
0 commit comments