asyncapi / asyncapi/generator

Build step (npm run build) mutates template source files and causes data loss

Closed
#1,897 8 comments 0 reactions 0 assignees View on GitHub
stale
Dominant language
JavaScript
Stars
1.1k
Forks
397
Avg merge
1d 18h
Merged PRs (30d)
26

Description

### Describe the bug
Running `npm run build` in the AsyncAPI Generator repository **silently rewrites source-controlled template files** under `packages/templates/*`.

The build script (`scripts/build-templates.js`) overwrites:
- `.ageneratorrc` (replaces the entire `metadata` object)
- `package.json` (forces the template `name`)

This happens **without warning, confirmation, or opt-in flag**. Any manual changes made by contributors to template metadata or package identity are **lost permanently** after running the build. Since the build also runs as part of tests and CI, this behavior is highly surprising and dangerous.

A build step is expected to be **read-only with respect to source files**, but currently it mutates them.

---

### Steps to reproduce

1. Go to the generator repository root:
```bash
cd generators/generator
2. Pick an existing baked-in template, for example:
```
packages/templates/clients/websocket/javascript
```

3. Edit .ageneratorrc and add a custom field:
```
metadata:
type: client
protocol: websocket
target: javascript
customField: SHOULD_SURVIVE_BUILD
```
4. Edit package.json and change the name:
```
{
"name": "my-custom-ws-js-template"
}
```
5. Verify changes exist:
```
git diff
```
6. Run the build:
```
npm run build
```
7. Check the diff again:
```
git diff
```
## Current behavior
- `.ageneratorrc` is rewritten and `customField` is removed
- package.json.name is reset to the auto-generated value
- No warning or prompt is shown
- Git diff is clean, hiding that changes were overwritten

## Expected behavior
- npm run build should not modify template source files
- Template normalization (if needed) should be:
- opt-in (e.g. --fix, --write)
- or handled by a separate maintenance script
- Existing metadata should be validated or merged, not overwritten
- package.json.name should never be rewritten silently

### I am willing to submit a PR that

Contributor guide

Open the contributing guide

Research direction

Read scripts/build-templates.js first, then reproduce the issue from the repository root with npm run build and inspect git diff. Focus on packages/templates/*, especially .ageneratorrc and package.json; done means the build leaves source files unchanged and preserves custom metadata and the template package name.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.