Compare commits

...

1 Commits

Author SHA1 Message Date
Jarred Sumner
6ffcdfe3f5 Make tempDirWithFiles a disposable string 2025-07-14 03:39:02 -07:00
2 changed files with 20 additions and 5 deletions

View File

@@ -121,7 +121,7 @@ index c8950c17b265104bcf27f8c345df1a1b13a78950..7ce57ab96400ab0ff4fac7e06f6e02c2
const patchFilename = filepathEscape(`is-even@${version}.patch`);
const patchVersion = patchVersion_ ?? version;
test(version, async () => {
const filedir = tempDirWithFiles("patch1", {
using filedir = tempDirWithFiles("patch1", {
"package.json": JSON.stringify({
"name": "bun-patch-test",
"module": "index.ts",

View File

@@ -236,6 +236,19 @@ export function makeTreeSync(base: string, filesOrAbsolutePathToCopyFolderFrom:
return makeTreeSyncFromDirectoryTree(base, filesOrAbsolutePathToCopyFolderFrom);
}
class DeletablePathString extends String {
constructor(value: string) {
super(value);
}
[Symbol.dispose]() {
rmSync(this.toString(), { recursive: true, force: true });
}
[Symbol.asyncDispose]() {
return rm(this.toString(), { recursive: true, force: true });
}
}
/**
* Recursively create files within a new temporary directory.
*
@@ -256,16 +269,18 @@ export function makeTreeSync(base: string, filesOrAbsolutePathToCopyFolderFrom:
export function tempDirWithFiles(
basename: string,
filesOrAbsolutePathToCopyFolderFrom: DirectoryTree | string,
): string {
): string & { [Symbol.dispose](): void; [Symbol.asyncDispose](): Promise<void> } {
const base = fs.mkdtempSync(join(fs.realpathSync(os.tmpdir()), basename + "_"));
makeTreeSync(base, filesOrAbsolutePathToCopyFolderFrom);
return base;
return new DeletablePathString(base) as any;
}
export function tempDirWithFilesAnon(filesOrAbsolutePathToCopyFolderFrom: DirectoryTree | string): string {
export function tempDirWithFilesAnon(
filesOrAbsolutePathToCopyFolderFrom: DirectoryTree | string,
): string & { [Symbol.dispose](): void; [Symbol.asyncDispose](): Promise<void> } {
const base = tmpdirSync();
makeTreeSync(base, filesOrAbsolutePathToCopyFolderFrom);
return base;
return new DeletablePathString(base) as any;
}
export function bunRun(file: string, env?: Record<string, string> | NodeJS.ProcessEnv) {