chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
export function ensureAbsolutePath(cwd, maybePath) {
|
||||
return path.isAbsolute(maybePath) ? maybePath : path.resolve(cwd, maybePath);
|
||||
}
|
||||
|
||||
export function createTempDir(prefix = "codex-plugin-") {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||
}
|
||||
|
||||
export function readJsonFile(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
export function writeJsonFile(filePath, value) {
|
||||
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
export function safeReadFile(filePath) {
|
||||
return fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : "";
|
||||
}
|
||||
|
||||
export function isProbablyText(buffer) {
|
||||
const sample = buffer.subarray(0, Math.min(buffer.length, 4096));
|
||||
for (const value of sample) {
|
||||
if (value === 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function readStdinIfPiped() {
|
||||
if (process.stdin.isTTY) {
|
||||
return "";
|
||||
}
|
||||
return fs.readFileSync(0, "utf8");
|
||||
}
|
||||
Reference in New Issue
Block a user