@@ -19,7 +19,10 @@ import type { BundlingOptions, ICommandHooks } from './types';
1919
2020export const HASHABLE_DEPENDENCIES_EXCLUDE = [
2121 '*.pyc' ,
22+ 'cdk.out/**' ,
23+ '**/cdk.out/**' ,
2224 'cdk/**' ,
25+ '**/cdk/**' ,
2326 '.git/**' ,
2427 '.venv/**' ,
2528] ;
@@ -28,8 +31,10 @@ export const DEFAULT_ASSET_EXCLUDES = [
2831 '.venv/' ,
2932 'node_modules/' ,
3033 'cdk.out/' ,
34+ '**/cdk.out/**' ,
35+ 'cdk/' ,
36+ '**/cdk/**' ,
3137 '.git/' ,
32- 'cdk' ,
3338] ;
3439
3540export const DEFAULT_UV_VERSION = '0.5.27' ;
@@ -87,29 +92,48 @@ export class Bundling {
8792
8893 public static bundle ( options : BundlingProps ) : AssetCode {
8994 const {
90- hashableAssetExclude = HASHABLE_DEPENDENCIES_EXCLUDE ,
95+ hashableAssetExclude,
9196 assetHashType = AssetHashType . SOURCE ,
9297 assetHash,
9398 ...bundlingOptions
9499 } = options ;
100+ const mergedHashableAssetExclude = dedupePatterns ( [
101+ ...HASHABLE_DEPENDENCIES_EXCLUDE ,
102+ ...( hashableAssetExclude ?? [ ] ) ,
103+ ] ) ;
95104
96105 const bundling = new Bundling ( bundlingOptions ) ;
97106 const cdkOutDir = getCdkOutDir ( ) ;
98107 const hostFunctionOutputDir = bundling . getHostFunctionOutputDir ( cdkOutDir ) ;
108+ const hostFunctionWorkspaceDir =
109+ bundling . getHostFunctionWorkspaceDir ( cdkOutDir ) ;
110+ const hostFunctionArchivePath =
111+ bundling . getHostFunctionArchivePath ( cdkOutDir ) ;
112+
113+ if ( bundling . skip ) {
114+ mkdirSync ( hostFunctionOutputDir , { recursive : true } ) ;
115+ return Code . fromCustomCommand (
116+ hostFunctionOutputDir ,
117+ bundling . createBundlingCommand ( ) ,
118+ {
119+ assetHash,
120+ assetHashType,
121+ exclude : mergedHashableAssetExclude ,
122+ } ,
123+ ) ;
124+ }
99125
100- mkdirSync ( hostFunctionOutputDir , { recursive : true } ) ;
126+ mkdirSync ( hostFunctionWorkspaceDir , { recursive : true } ) ;
101127
102- if ( ! bundling . skip ) {
103- bundling . ensureBuilderReady ( cdkOutDir ) ;
104- }
128+ bundling . ensureBuilderReady ( cdkOutDir ) ;
105129
106130 return Code . fromCustomCommand (
107- hostFunctionOutputDir ,
131+ hostFunctionArchivePath ,
108132 bundling . createBundlingCommand ( ) ,
109133 {
110134 assetHash,
111135 assetHashType,
112- exclude : hashableAssetExclude ,
136+ exclude : mergedHashableAssetExclude ,
113137 } ,
114138 ) ;
115139 }
@@ -147,7 +171,10 @@ export class Bundling {
147171 this . securityOpt = props . securityOpt ;
148172 this . network = props . network ;
149173 this . bundlingFileAccess = props . bundlingFileAccess ;
150- this . assetExcludes = props . assetExcludes ?? DEFAULT_ASSET_EXCLUDES ;
174+ this . assetExcludes = dedupePatterns ( [
175+ ...DEFAULT_ASSET_EXCLUDES ,
176+ ...( props . assetExcludes ?? [ ] ) ,
177+ ] ) ;
151178 this . commandHooks = props . commandHooks ;
152179 this . outputPathSuffix = props . outputPathSuffix ;
153180 this . skip = ! ! props . skip ;
@@ -249,6 +276,7 @@ export class Bundling {
249276 }
250277
251278 const containerOutputDir = this . getContainerFunctionOutputDir ( ) ;
279+ const containerArchivePath = this . getContainerFunctionArchivePath ( ) ;
252280 const command = [ 'docker' , 'exec' ] ;
253281 const builderUser = getDockerUserArg ( ) ;
254282
@@ -265,6 +293,8 @@ export class Bundling {
265293 `${ BUILDER_TOOL_DIR } /export.sh` ,
266294 '--output' ,
267295 containerOutputDir ,
296+ '--output-zip' ,
297+ containerArchivePath ,
268298 ) ;
269299
270300 if ( this . props . workspacePackage ) {
@@ -315,16 +345,39 @@ export class Bundling {
315345
316346 private getContainerFunctionOutputDir ( ) {
317347 return toPosixPath (
318- path . join ( '/uvbuild' , this . functionOutDir , this . outputPathSuffix ?? '' ) ,
348+ path . join (
349+ '/uvbuild' ,
350+ this . functionOutDir ,
351+ 'bundle' ,
352+ this . outputPathSuffix ?? '' ,
353+ ) ,
319354 ) ;
320355 }
321356
322357 private getHostFunctionOutputDir ( cdkOutDir : string ) {
358+ return path . join (
359+ this . getHostFunctionWorkspaceDir ( cdkOutDir ) ,
360+ 'bundle' ,
361+ this . outputPathSuffix ?? '' ,
362+ ) ;
363+ }
364+
365+ private getContainerFunctionArchivePath ( ) {
366+ return toPosixPath ( path . join ( '/uvbuild' , this . functionOutDir , 'asset.zip' ) ) ;
367+ }
368+
369+ private getHostFunctionWorkspaceDir ( cdkOutDir : string ) {
323370 return path . join (
324371 cdkOutDir ,
325372 this . containerBuilderKey ,
326373 this . functionOutDir ,
327- this . outputPathSuffix ?? '' ,
374+ ) ;
375+ }
376+
377+ private getHostFunctionArchivePath ( cdkOutDir : string ) {
378+ return path . join (
379+ this . getHostFunctionWorkspaceDir ( cdkOutDir ) ,
380+ 'asset.zip' ,
328381 ) ;
329382 }
330383
@@ -365,6 +418,10 @@ function toPosixPath(value: string) {
365418 return value . split ( path . sep ) . join ( path . posix . sep ) ;
366419}
367420
421+ function dedupePatterns ( patterns : string [ ] ) {
422+ return [ ...new Set ( patterns ) ] ;
423+ }
424+
368425function getBuilderEnvironment (
369426 environment ?: Record < string , string > ,
370427) : Record < string , string > {
0 commit comments