From 7bc89e0f84ab54f95ca5b63d0bd1607c4bf24124 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Wed, 18 Mar 2026 12:36:57 -0700 Subject: [PATCH 1/2] fix: strip XML preamble in devvit create icons Fixes #128 Co-Authored-By: Claude Opus 4.6 --- packages/cli/src/commands/create/icons.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/commands/create/icons.ts b/packages/cli/src/commands/create/icons.ts index ae18df136..907fbf5c8 100644 --- a/packages/cli/src/commands/create/icons.ts +++ b/packages/cli/src/commands/create/icons.ts @@ -58,7 +58,9 @@ export default class Icons extends DevvitCommand { assets.map(async (asset) => { const name = path.relative(assetsPath, asset); const contents = await fsp.readFile(asset, 'utf-8'); - return { name, contents }; + // Strip XML preamble (, , comments) before tag. + const stripped = contents.replace(/^[\s\S]*?( Date: Wed, 18 Mar 2026 18:08:32 -0700 Subject: [PATCH 2/2] fix: extract stripXmlPreamble and add unit tests Co-Authored-By: Claude Opus 4.6 (1M context) --- .../cli/src/commands/create/icons.test.ts | 41 +++++++++++++++++++ packages/cli/src/commands/create/icons.ts | 9 ++-- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/commands/create/icons.test.ts diff --git a/packages/cli/src/commands/create/icons.test.ts b/packages/cli/src/commands/create/icons.test.ts new file mode 100644 index 000000000..09525ba7f --- /dev/null +++ b/packages/cli/src/commands/create/icons.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, it } from 'vitest'; + +import { stripXmlPreamble } from './icons.js'; + +describe('stripXmlPreamble', () => { + it('strips declaration', () => { + const input = '\n'; + expect(stripXmlPreamble(input)).toBe(''); + }); + + it('strips declaration', () => { + const input = + '\n'; + expect(stripXmlPreamble(input)).toBe(''); + }); + + it('strips XML comments before ', () => { + const input = '\n'; + expect(stripXmlPreamble(input)).toBe(''); + }); + + it('strips combined preamble ( + + comment)', () => { + const input = [ + '', + '', + '', + '', + ].join('\n'); + expect(stripXmlPreamble(input)).toBe(''); + }); + + it('returns input unchanged when no preamble exists', () => { + const input = ''; + expect(stripXmlPreamble(input)).toBe(input); + }); + + it('handles leading whitespace before ', () => { + const input = ' \n '; + expect(stripXmlPreamble(input)).toBe(''); + }); +}); diff --git a/packages/cli/src/commands/create/icons.ts b/packages/cli/src/commands/create/icons.ts index 907fbf5c8..77ac19b26 100644 --- a/packages/cli/src/commands/create/icons.ts +++ b/packages/cli/src/commands/create/icons.ts @@ -9,6 +9,11 @@ import { dirExists } from '../../util/files.js'; type SvgAsset = { name: string; contents: string }; +/** Strip XML preamble (, , comments) before the tag. */ +export function stripXmlPreamble(contents: string): string { + return contents.replace(/^[\s\S]*?( { const name = path.relative(assetsPath, asset); const contents = await fsp.readFile(asset, 'utf-8'); - // Strip XML preamble (, , comments) before tag. - const stripped = contents.replace(/^[\s\S]*?(