assets: custom watch/hotswap implementation for asset bundling
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
An API for asset bundling to hook into the watch/hotswap feature to create an incremental build of the asset.
### Use Case
Asset bundling can be expensive. While some providers (e.g. Docker) already use an internal cache to build increments, not all do and it is the responsibility of the provider to store state.
A concrete would be bundling a lambda function with esbuild. This could use esbuild's native watch feature to update assets instead of always doing a full build. Or it could rely on CDKs file watcher, but trigger a [rebuild](https://esbuild.github.io/api/#rebuild) when one of its files changed.
### Proposed Solution
Maybe two variations
```ts
// Uses a custom file watcher implementation and does an incremental update
// will callback to the CDK watch context when an update has occurred
interface WatchingAsset {
startWatching(context) {
// watch files & update when needed
// then inform the CDK watch context
context.updated(/* data */);
}
```
```ts
// Has a well known method that can register interests with the global CDK watcher
interface IncrementalAsset {
gatherInterest(context) {
watchProvider.registerInterest('handler/**/*.ts');
}
// this is called when ever a rebuild is needed
rebuild(changeDetails) {
// do the incremental rebuild here
}
}
```
### Other Information
_No response_
### Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
n/a
### Environment details (OS name and version, etc.)
n/a
Contributor guide
Research direction
No files or tests are named. Start by reading the CDK watch context and the proposed WatchingAsset and IncrementalAsset interfaces, then review esbuild's rebuild/watch behavior; done requires an agreed API and a demonstrated incremental asset update path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100