terminal-png 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +12 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,22 +15,29 @@ export async function renderTerminalPng(ansiText, options = {}) {
|
|
|
15
15
|
const png = renderPng(svg);
|
|
16
16
|
if (options.output) {
|
|
17
17
|
const temporaryPath = `${options.output}.${randomUUID()}.tmp`;
|
|
18
|
+
let temporaryCreated = false;
|
|
18
19
|
try {
|
|
19
20
|
await writeFile(temporaryPath, png, { flag: "wx" });
|
|
21
|
+
temporaryCreated = true;
|
|
20
22
|
await rename(temporaryPath, options.output);
|
|
21
23
|
}
|
|
22
24
|
catch (error) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (temporaryCreated || !isAlreadyExistsError(error)) {
|
|
26
|
+
try {
|
|
27
|
+
await rm(temporaryPath, { force: true });
|
|
28
|
+
}
|
|
29
|
+
catch (cleanupError) {
|
|
30
|
+
void cleanupError;
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
throw error;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
return png;
|
|
33
37
|
}
|
|
38
|
+
function isAlreadyExistsError(error) {
|
|
39
|
+
return error instanceof Error && "code" in error && error.code === "EEXIST";
|
|
40
|
+
}
|
|
34
41
|
export * from "./ansi-parser.js";
|
|
35
42
|
export * from "./font.js";
|
|
36
43
|
export * from "./png-renderer.js";
|