-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update types to handle tmp upgrade, with a test
- Loading branch information
1 parent
0439af3
commit 413069c
Showing
3 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
import { fileSync, dirSync, tmpNameSync, setGracefulCleanup } from 'tmp'; | ||
import { Options, SimpleOptions } from 'tmp'; | ||
import { fileSync, dirSync, tmpNameSync, setGracefulCleanup } from "tmp"; | ||
import { FileOptions, DirOptions, TmpNameOptions } from "tmp"; | ||
|
||
export interface DirectoryResult { | ||
path: string; | ||
cleanup(): void; | ||
path: string; | ||
cleanup(): void; | ||
} | ||
|
||
export interface FileResult extends DirectoryResult { | ||
fd: number; | ||
fd: number; | ||
} | ||
|
||
export function file(options?: Options): Promise<FileResult>; | ||
export function withFile<T>(fn: (result: FileResult) => Promise<T>, options?: Options): Promise<T>; | ||
export function file(options?: FileOptions): Promise<FileResult>; | ||
export function withFile<T>( | ||
fn: (result: FileResult) => Promise<T>, | ||
options?: FileOptions | ||
): Promise<T>; | ||
|
||
export function dir(options?: Options): Promise<DirectoryResult>; | ||
export function withDir<T>(fn: (results: DirectoryResult) => Promise<T>, options?: Options): Promise<T>; | ||
export function dir(options?: DirOptions): Promise<DirectoryResult>; | ||
export function withDir<T>( | ||
fn: (results: DirectoryResult) => Promise<T>, | ||
options?: DirOptions | ||
): Promise<T>; | ||
|
||
export function tmpName(options?: SimpleOptions): Promise<string>; | ||
export function tmpName(options?: TmpNameOptions): Promise<string>; | ||
|
||
export { fileSync, dirSync, tmpNameSync, setGracefulCleanup } | ||
export { fileSync, dirSync, tmpNameSync, setGracefulCleanup }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { file, withFile, dir, withDir, tmpName } from "."; | ||
|
||
async function fileExample() { | ||
const { path, fd, cleanup } = await file({ discardDescriptor: true }); | ||
|
||
await withFile( | ||
async ({ path, fd, cleanup }) => { | ||
console.log(fd); | ||
}, | ||
{ discardDescriptor: true } | ||
); | ||
} | ||
|
||
async function dirExample() { | ||
const { path, cleanup } = await dir({ unsafeCleanup: true }); | ||
|
||
await withDir( | ||
async ({ path, cleanup }) => { | ||
console.log(path); | ||
}, | ||
{ unsafeCleanup: true } | ||
); | ||
} | ||
|
||
async function tmpNameExample() { | ||
const name = await tmpName({ tries: 3 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters