@@ -5,8 +5,8 @@ import * as cxapi from '@aws-cdk/cx-api';
55import { Construct } from 'constructs' ;
66import * as fs from 'fs-extra' ;
77import * as minimatch from 'minimatch' ;
8- import { AssetHashType , AssetOptions , FileAssetPackaging } from './assets' ;
9- import { BundlingOptions , BundlingOutput } from './bundling' ;
8+ import { AssetHashType , AssetOptions } from './assets' ;
9+ import { BundlingOptions } from './bundling' ;
1010import { FileSystem , FingerprintOptions } from './fs' ;
1111import { Names } from './names' ;
1212import { Cache } from './private/cache' ;
@@ -17,8 +17,6 @@ import { Stage } from './stage';
1717// eslint-disable-next-line
1818import { Construct as CoreConstruct } from './construct-compat' ;
1919
20- const ARCHIVE_EXTENSIONS = [ '.zip' , '.jar' ] ;
21-
2220/**
2321 * A previously staged asset
2422 */
@@ -140,9 +138,6 @@ export class AssetStaging extends CoreConstruct {
140138
141139 private readonly cacheKey : string ;
142140
143- private _packaging = FileAssetPackaging . ZIP_DIRECTORY ;
144- private _isArchive = true ;
145-
146141 constructor ( scope : Construct , id : string , props : AssetStagingProps ) {
147142 super ( scope , id ) ;
148143
@@ -208,20 +203,6 @@ export class AssetStaging extends CoreConstruct {
208203 return this . assetHash ;
209204 }
210205
211- /**
212- * How this asset should be packaged.
213- */
214- public get packaging ( ) : FileAssetPackaging {
215- return this . _packaging ;
216- }
217-
218- /**
219- * Whether this asset is an archive (zip or jar).
220- */
221- public get isArchive ( ) : boolean {
222- return this . _isArchive ;
223- }
224-
225206 /**
226207 * Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack
227208 *
@@ -300,16 +281,11 @@ export class AssetStaging extends CoreConstruct {
300281 const bundleDir = this . determineBundleDir ( this . assetOutdir , assetHash ) ;
301282 this . bundle ( bundling , bundleDir ) ;
302283
303- // Check bundling output content and determine if we will need to archive
304- const bundlingOutputType = bundling . outputType ?? BundlingOutput . AUTO_DISCOVER ;
305- const bundledAsset = determineBundledAsset ( bundleDir , bundlingOutputType ) ;
306- this . _packaging = bundledAsset . packaging ;
307-
308284 // Calculate assetHash afterwards if we still must
309- assetHash = assetHash ?? this . calculateHash ( this . hashType , bundling , bundledAsset . path ) ;
310- const stagedPath = path . resolve ( this . assetOutdir , renderAssetFilename ( assetHash , bundledAsset . extension ) ) ;
285+ assetHash = assetHash ?? this . calculateHash ( this . hashType , bundling , bundleDir ) ;
286+ const stagedPath = path . resolve ( this . assetOutdir , renderAssetFilename ( assetHash ) ) ;
311287
312- this . stageAsset ( bundledAsset . path , stagedPath , 'move' ) ;
288+ this . stageAsset ( bundleDir , stagedPath , 'move' ) ;
313289 return { assetHash, stagedPath } ;
314290 }
315291
@@ -347,8 +323,6 @@ export class AssetStaging extends CoreConstruct {
347323 const stat = fs . statSync ( sourcePath ) ;
348324 if ( stat . isFile ( ) ) {
349325 fs . copyFileSync ( sourcePath , targetPath ) ;
350- this . _packaging = FileAssetPackaging . FILE ;
351- this . _isArchive = ARCHIVE_EXTENSIONS . includes ( path . extname ( sourcePath ) . toLowerCase ( ) ) ;
352326 } else if ( stat . isDirectory ( ) ) {
353327 fs . mkdirSync ( targetPath ) ;
354328 FileSystem . copyDirectory ( sourcePath , targetPath , this . fingerprintOptions ) ;
@@ -528,57 +502,3 @@ function sortObject(object: { [key: string]: any }): { [key: string]: any } {
528502 }
529503 return ret ;
530504}
531-
532- /**
533- * Returns the single archive file of a directory or undefined
534- */
535- function singleArchiveFile ( directory : string ) : string | undefined {
536- if ( ! fs . existsSync ( directory ) ) {
537- throw new Error ( `Directory ${ directory } does not exist.` ) ;
538- }
539-
540- if ( ! fs . statSync ( directory ) . isDirectory ( ) ) {
541- throw new Error ( `${ directory } is not a directory.` ) ;
542- }
543-
544- const content = fs . readdirSync ( directory ) ;
545- if ( content . length === 1 ) {
546- const file = path . join ( directory , content [ 0 ] ) ;
547- const extension = path . extname ( content [ 0 ] ) . toLowerCase ( ) ;
548- if ( fs . statSync ( file ) . isFile ( ) && ARCHIVE_EXTENSIONS . includes ( extension ) ) {
549- return file ;
550- }
551- }
552-
553- return undefined ;
554- }
555-
556- interface BundledAsset {
557- path : string ,
558- packaging : FileAssetPackaging ,
559- extension ?: string
560- }
561-
562- /**
563- * Returns the bundled asset to use based on the content of the bundle directory
564- * and the type of output.
565- */
566- function determineBundledAsset ( bundleDir : string , outputType : BundlingOutput ) : BundledAsset {
567- const archiveFile = singleArchiveFile ( bundleDir ) ;
568-
569- // auto-discover means that if there is an archive file, we take it as the
570- // bundle, otherwise, we will archive here.
571- if ( outputType === BundlingOutput . AUTO_DISCOVER ) {
572- outputType = archiveFile ? BundlingOutput . ARCHIVED : BundlingOutput . NOT_ARCHIVED ;
573- }
574-
575- switch ( outputType ) {
576- case BundlingOutput . NOT_ARCHIVED :
577- return { path : bundleDir , packaging : FileAssetPackaging . ZIP_DIRECTORY } ;
578- case BundlingOutput . ARCHIVED :
579- if ( ! archiveFile ) {
580- throw new Error ( 'Bundling output directory is expected to include only a single .zip or .jar file when `output` is set to `ARCHIVED`' ) ;
581- }
582- return { path : archiveFile , packaging : FileAssetPackaging . FILE , extension : path . extname ( archiveFile ) } ;
583- }
584- }
0 commit comments