Skip to content

Commit 0ccc8b8

Browse files
committed
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 rnag#10.
1 parent 04f16a3 commit 0ccc8b8

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

lib/bundling.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as cdk from 'aws-cdk-lib';
2-
import { DockerRunOptions } from 'aws-cdk-lib';
2+
import { AssetHashType, DockerRunOptions } from 'aws-cdk-lib';
33
import {
44
Architecture,
55
AssetCode,
@@ -14,6 +14,31 @@ import { build } from './build';
1414
* Options for bundling
1515
*/
1616
export interface BundlingProps extends DockerRunOptions {
17+
/**
18+
* Determines how the asset hash is calculated.
19+
*
20+
* @remarks
21+
*
22+
* This property is set to `AssetHashType.SOURCE` to prevent the costly Rust
23+
* compiler from running when there is no change in the source files.
24+
*
25+
* If your asset depends on files outside `entity`, you have to specify
26+
* a type other than `AssetHashType.SOURCE`.
27+
*
28+
* @default - {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetHashType.html#source | AssetHashType.SOURCE}
29+
*/
30+
readonly assetHashType?: AssetHashType;
31+
32+
/**
33+
* Custom asset hash.
34+
*
35+
* @remarks
36+
*
37+
* This property is meaningful if and only if `assetHashType` is
38+
* `AssetHashType.CUSTOM`.
39+
*/
40+
readonly assetHash?: string;
41+
1742
/**
1843
* Path to the directory that contains the project to be built; i.e., the
1944
* directory containing `Cargo.toml`.
@@ -49,7 +74,8 @@ export class Bundling implements cdk.BundlingOptions {
4974
const bundling = new Bundling(options);
5075

5176
return Code.fromAsset(options.entry, {
52-
assetHashType: cdk.AssetHashType.OUTPUT,
77+
assetHashType: options.assetHashType ?? cdk.AssetHashType.SOURCE,
78+
assetHash: options.assetHash,
5379
bundling: {
5480
image: bundling.image,
5581
local: bundling.local,

0 commit comments

Comments
 (0)