From 0ccc8b893f919e5363b8f8554912781cb6646633 Mon Sep 17 00:00:00 2001 From: Kikuo Emoto Date: Wed, 8 Mar 2023 13:29:06 +0900 Subject: [PATCH] feat: change default asset hash type to SOURCE - Changes the default asset hash type to `SOURCE` to prevent the costly Rust compiler from running when there is no change in the source files. `BundlingProps` includes additional properties `assetHashType` and `assetHash` to allow a user to change the asset hash type and value, but `RustFunction` does not support it yet. - This change may be a workaround for the issue #10. --- lib/bundling.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/bundling.ts b/lib/bundling.ts index 89d72c7..ac282f1 100644 --- a/lib/bundling.ts +++ b/lib/bundling.ts @@ -1,5 +1,5 @@ import * as cdk from 'aws-cdk-lib'; -import { DockerRunOptions } from 'aws-cdk-lib'; +import { AssetHashType, DockerRunOptions } from 'aws-cdk-lib'; import { Architecture, AssetCode, @@ -14,6 +14,31 @@ import { build } from './build'; * Options for bundling */ export interface BundlingProps extends DockerRunOptions { + /** + * Determines how the asset hash is calculated. + * + * @remarks + * + * This property is set to `AssetHashType.SOURCE` to prevent the costly Rust + * compiler from running when there is no change in the source files. + * + * If your asset depends on files outside `entity`, you have to specify + * a type other than `AssetHashType.SOURCE`. + * + * @default - {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetHashType.html#source | AssetHashType.SOURCE} + */ + readonly assetHashType?: AssetHashType; + + /** + * Custom asset hash. + * + * @remarks + * + * This property is meaningful if and only if `assetHashType` is + * `AssetHashType.CUSTOM`. + */ + readonly assetHash?: string; + /** * Path to the directory that contains the project to be built; i.e., the * directory containing `Cargo.toml`. @@ -49,7 +74,8 @@ export class Bundling implements cdk.BundlingOptions { const bundling = new Bundling(options); return Code.fromAsset(options.entry, { - assetHashType: cdk.AssetHashType.OUTPUT, + assetHashType: options.assetHashType ?? cdk.AssetHashType.SOURCE, + assetHash: options.assetHash, bundling: { image: bundling.image, local: bundling.local,