fix(mod_output): wrap long base64 file contents and format generated TypeScript output to avoid extremely long lines

This commit is contained in:
2026-01-12 00:57:34 +00:00
parent 41091f1bee
commit 201f8aca38
3 changed files with 32 additions and 3 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@git.zone/tsbundle',
version: '2.7.2',
version: '2.7.3',
description: 'a multi-bundler tool supporting esbuild, rolldown, and rspack for painless bundling of web projects'
}

View File

@@ -79,9 +79,32 @@ export class Base64TsOutput {
* Generate TypeScript file content
*/
public generateTypeScript(): string {
const filesJson = JSON.stringify(this.files, null, 2);
const MAX_LINE_LENGTH = 200;
const formatBase64 = (base64: string): string => {
if (base64.length <= MAX_LINE_LENGTH) {
return `"${base64}"`;
}
const chunks: string[] = [];
for (let i = 0; i < base64.length; i += MAX_LINE_LENGTH) {
chunks.push(base64.slice(i, i + MAX_LINE_LENGTH));
}
return `"" +\n "${chunks.join('" +\n "')}"`;
};
const filesFormatted = this.files.map(file => {
return ` {
"path": "${file.path}",
"contentBase64": ${formatBase64(file.contentBase64)}
}`;
}).join(',\n');
return `// Auto-generated by tsbundle - do not edit
export const files: { path: string; contentBase64: string }[] = ${filesJson};
export const files: { path: string; contentBase64: string }[] = [
${filesFormatted}
];
`;
}