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 ae18df136..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'); - return { name, contents }; + return { name, contents: stripXmlPreamble(contents) }; }) ); }