Skip to content

Commit 6960b20

Browse files
committed
feat: use node:os to get the tmp directory name
1 parent 66104f3 commit 6960b20

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/test-env-server/lib/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { randomBytes } from "node:crypto";
2+
import { tmpdir } from "node:os";
23
import { resolve } from "node:path";
34

45
function getDataDir() {
5-
return resolve(`/tmp/keybr-tests-${randomBytes(6).toString("hex")}`);
6+
return resolve(tmpdir(), `keybr-tests-${randomBytes(6).toString("hex")}`);
67
}
78

89
function getPublicDir() {

packages/tsl/transpile.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createHash } from "node:crypto";
22
import { mkdir, open, readFile, rename } from "node:fs/promises";
3-
import { dirname } from "node:path";
3+
import { tmpdir } from "node:os";
4+
import { dirname, join } from "node:path";
45
import ts from "typescript";
56

67
/**
@@ -26,14 +27,14 @@ export function isTsx(fileName) {
2627
*/
2728
export async function transpile(source, fileName) {
2829
const options = getTranspileOptions(fileName);
29-
const slug = fileName.substring(1).replace(/[./]/g, "_");
30+
const slug = fileName.replace(/[./\\:]/g, "_");
3031
const hash = createHash("md5")
3132
.update(fileName)
3233
.update(source)
3334
.update(JSON.stringify(options))
3435
.update(ts.version)
3536
.digest("hex");
36-
const cachedFilename = `/tmp/tsl/${slug}_${hash}.js`;
37+
const cachedFilename = join(tmpdir(), `tsl`, `${slug}_${hash}.js`);
3738
try {
3839
return await readFile(cachedFilename, "utf-8");
3940
} catch (err) {

0 commit comments

Comments
 (0)