Skip to content

Commit

Permalink
Merge pull request #27 from paulmelnikow/update-types
Browse files Browse the repository at this point in the history
Update types to handle tmp upgrade, with a test
  • Loading branch information
dave-gray101 authored May 7, 2019
2 parents 0439af3 + 413069c commit c37d280
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
28 changes: 17 additions & 11 deletions index.d.ts
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 };
27 changes: 27 additions & 0 deletions index.test-d.ts
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 });
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha"
"mocha": "mocha",
"check-types": "tsd",
"test": "npm run mocha && npm run check-types"
},
"keywords": [
"tmp",
Expand All @@ -25,7 +27,8 @@
"tmp": "0.1.0"
},
"devDependencies": {
"@types/tmp": "0.0.33",
"mocha": "^3.1.2"
"@types/tmp": "0.1.0",
"mocha": "^3.1.2",
"tsd": "^0.7.2"
}
}

0 comments on commit c37d280

Please sign in to comment.