diff --git a/packages/cli/src/media-use/lib/adopt.mjs b/packages/cli/src/media-use/lib/adopt.mjs index ee4ad75a4e..26b73b296f 100644 --- a/packages/cli/src/media-use/lib/adopt.mjs +++ b/packages/cli/src/media-use/lib/adopt.mjs @@ -4,6 +4,7 @@ import { readManifest, appendRecord, nextId } from "./manifest.mjs"; import { regenerateIndex } from "./index-gen.mjs"; import { probe } from "./probe.mjs"; import { matchTokens } from "./match.mjs"; +import { terminalText } from "./terminal-text.mjs"; const AUDIO_EXT = new Set([".mp3", ".wav", ".ogg", ".m4a", ".aac"]); const IMAGE_EXT = new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg", ".ico"]); @@ -59,7 +60,7 @@ export function scanExistingAssets(projectDir) { if (stat.size === 0) { // A 0-byte asset would register clean but fail at render — skip it loudly // rather than adopt a broken file. - console.error(`media-use: skipping 0-byte asset assets/${rel}`); + console.error(terminalText(`media-use: skipping 0-byte asset assets/${rel}`)); continue; } const meta = probe(fullPath); diff --git a/packages/cli/src/media-use/lib/adopt.test.mjs b/packages/cli/src/media-use/lib/adopt.test.mjs index 0f1a7575f1..13b4f18c90 100644 --- a/packages/cli/src/media-use/lib/adopt.test.mjs +++ b/packages/cli/src/media-use/lib/adopt.test.mjs @@ -2,7 +2,7 @@ import { strict as assert } from "node:assert"; import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { tmpdir } from "node:os"; -import { findExistingAsset, adoptExistingAssets } from "./adopt.mjs"; +import { findExistingAsset, adoptExistingAssets, scanExistingAssets } from "./adopt.mjs"; let tmp; function setup() { @@ -122,6 +122,25 @@ function runTests() { cleanup(); }); + test("prints a skipped file name from the project with control characters escaped", () => { + setup(); + const name = "bad\x1b]0;owned\x07\r\nok.mp3"; + mkdirSync(join(tmp, "assets", "dir\x1b[2J"), { recursive: true }); + writeFileSync(join(tmp, "assets", "dir\x1b[2J", name), ""); + const lines = []; + const original = console.error; + console.error = (line) => lines.push(String(line)); + try { + assert.deepEqual(scanExistingAssets(tmp), []); + } finally { + console.error = original; + } + assert.deepEqual(lines, [ + "media-use: skipping 0-byte asset assets/dir\\x1b[2J/bad\\x1b]0;owned\\x07\\x0d\\x0aok.mp3", + ]); + cleanup(); + }); + let passed = 0; let failed = 0; for (const { name, fn } of tests) {