Skip to content

Commit 4a65f39

Browse files
sarahdayanclaude
andcommitted
fix(changelog): handle frozen commit objects from conventional-changelog-writer
The conventional-changelog-writer library freezes commit objects, but presets like angular expect to mutate them. This causes a "Cannot modify immutable object" error when the transform function tries to change commit.type. Add a wrapTransform helper that deep clones commits before passing them to the original transform function, allowing mutation while preserving the original frozen objects. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b91c297 commit 4a65f39

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

packages/shipjs/src/step/prepare/updateChangelog.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ export async function prepareParams({
152152
return { args, gitRawCommitsOpts, templateContext };
153153
}
154154

155+
// Wraps a transform function to clone commits before modification.
156+
// This is needed because conventional-changelog-writer freezes commit objects,
157+
// but presets like angular expect to mutate them.
158+
function wrapTransform(originalTransform) {
159+
if (!originalTransform) {
160+
return undefined;
161+
}
162+
163+
return (commit, context) => {
164+
const mutableCommit = JSON.parse(JSON.stringify(commit));
165+
166+
return originalTransform(mutableCommit, context);
167+
};
168+
}
169+
155170
function runConventionalChangelog({
156171
args,
157172
templateContext,
@@ -165,12 +180,15 @@ function runConventionalChangelog({
165180
}
166181

167182
const { parserOpts, writerOpts } = args.config || {};
183+
const wrappedWriterOpts = writerOpts
184+
? { ...writerOpts, transform: wrapTransform(writerOpts.transform) }
185+
: undefined;
168186
const changelogStream = conventionalChangelogCore(
169187
args,
170188
templateContext,
171189
{ ...gitRawCommitsOpts, path: dir },
172190
parserOpts ? { ...parserOpts } : undefined,
173-
writerOpts ? { ...writerOpts } : undefined,
191+
wrappedWriterOpts,
174192
{ path: dir, cwd: dir }
175193
).on('error', reject);
176194

0 commit comments

Comments
 (0)