Skip to content

Commit

Permalink
feat: change default asset hash type to SOURCE
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
kikuomax committed Mar 8, 2023
1 parent 04f16a3 commit 0ccc8b8
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/bundling.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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`.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0ccc8b8

Please sign in to comment.