Skip to content

Commit 868a7bc

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 868a7bc

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ 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) return undefined;
160+
return (commit, context) => {
161+
// Deep clone the commit to make it mutable
162+
const mutableCommit = JSON.parse(JSON.stringify(commit));
163+
return originalTransform(mutableCommit, context);
164+
};
165+
}
166+
155167
function runConventionalChangelog({
156168
args,
157169
templateContext,
@@ -165,12 +177,16 @@ function runConventionalChangelog({
165177
}
166178

167179
const { parserOpts, writerOpts } = args.config || {};
180+
// Wrap the transform function to handle frozen commit objects
181+
const wrappedWriterOpts = writerOpts
182+
? { ...writerOpts, transform: wrapTransform(writerOpts.transform) }
183+
: undefined;
168184
const changelogStream = conventionalChangelogCore(
169185
args,
170186
templateContext,
171187
{ ...gitRawCommitsOpts, path: dir },
172188
parserOpts ? { ...parserOpts } : undefined,
173-
writerOpts ? { ...writerOpts } : undefined,
189+
wrappedWriterOpts,
174190
{ path: dir, cwd: dir }
175191
).on('error', reject);
176192

0 commit comments

Comments
 (0)