From 392f2699d0aee7ef7da3227614e641600c1e1af1 Mon Sep 17 00:00:00 2001 From: Maxime LUCE Date: Sun, 25 Oct 2015 01:01:01 +0200 Subject: [PATCH] Update opn typings for version 3.0.2 --- opn/opn-tests.ts | 18 ++++++++--- opn/opn.d.ts | 84 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 91 insertions(+), 11 deletions(-) diff --git a/opn/opn-tests.ts b/opn/opn-tests.ts index 361725970..2b39f1950 100644 --- a/opn/opn-tests.ts +++ b/opn/opn-tests.ts @@ -1,10 +1,18 @@ /// -import opn = require('opn'); +import * as opn from "opn"; var errorCallback: (err: Error) => void; -opn('foo'); -opn('foo', 'bar'); -opn('foo', errorCallback); -opn('foo', 'bar', errorCallback); +opn("foo"); +opn("foo", errorCallback); + +opn("foo", { app: "bar" }); +opn("foo", { app: ["bar", "--arg"] }); +opn("foo", { app: "bar", wait: false }); +opn("foo", { app: ["bar", "--arg"] , wait: false}); + +opn("foo", { app: "bar" }, errorCallback); +opn("foo", { app: ["bar", "--arg"] }, errorCallback); +opn("foo", { app: "bar", wait: false }, errorCallback); +opn("foo", { app: ["bar", "--arg"], wait: false }, errorCallback); diff --git a/opn/opn.d.ts b/opn/opn.d.ts index 10a34ce60..6e6a5a178 100644 --- a/opn/opn.d.ts +++ b/opn/opn.d.ts @@ -1,10 +1,82 @@ -// Type definitions for opn 1.0.0 +// Type definitions for opn 3.0.2 // Project: https://github.com/sindresorhus/opn -// Definitions by: Shinnosuke Watanabe +// Definitions by: Shinnosuke Watanabe , +// Maxime LUCE // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module 'opn' { - function opn(target: string, callback?: (err: Error) => void): void; - function opn(target: string, app: string, callback?: (err: Error) => void): void; - export = opn; +/// + +declare namespace Opn { + export interface Options { + /** + * Wait for the opened app to exit before calling the `callback`. + * If `false` it's called immediately when opening the app. + * On Windows you have to explicitly specify an app for it to be able to wait. + */ + wait?: boolean; + + /** + * Specify the app to open the target with, or an array with the app and app arguments. + * The app name is platform dependent. Don't hard code it in reusable modules. + * Eg. Chrome is `google chrome` on OS X, `google-chrome` on Linux and `chrome` on Windows. + */ + app?: string | string[]; + } +} + +declare module "opn" { + import * as cp from "child_process"; + + interface DefaultFunction { + /** + * Uses the command open on OS X, start on Windows and xdg-open on other platforms. + * + * Returns the spawned child process. + * You'd normally not need to use this for anything, but it can be useful if you'd like + * to attach custom event listeners or perform other operations directly on the spawned process. + * + * @param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. Eg. URLs opens in your default browser. + */ + (target: string): cp.ChildProcess; + + /** + * Uses the command open on OS X, start on Windows and xdg-open on other platforms. + * + * Returns the spawned child process. + * You'd normally not need to use this for anything, but it can be useful if you'd like + * to attach custom event listeners or perform other operations directly on the spawned process. + * + * @param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. Eg. URLs opens in your default browser. + * @param callback- Called when the opened app exits, or if `wait: false`, immediately when opening. + */ + (target: string, callback: (err: Error) => void): cp.ChildProcess; + + /** + * Uses the command open on OS X, start on Windows and xdg-open on other platforms. + * + * Returns the spawned child process. + * You'd normally not need to use this for anything, but it can be useful if you'd like + * to attach custom event listeners or perform other operations directly on the spawned process. + * + * @param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. Eg. URLs opens in your default browser. + * @param options - Options to be passed to opn. + */ + (target: string, options: Opn.Options): cp.ChildProcess; + + /** + * Uses the command open on OS X, start on Windows and xdg-open on other platforms. + * + * Returns the spawned child process. + * You'd normally not need to use this for anything, but it can be useful if you'd like + * to attach custom event listeners or perform other operations directly on the spawned process. + * + * @param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. Eg. URLs opens in your default browser. + * @param options - Options to be passed to opn. + * @param callback- Called when the opened app exits, or if `wait: false`, immediately when opening. + */ + (target: string, options: Opn.Options, callback: (err: Error) => void): cp.ChildProcess; + } + + const opn: DefaultFunction; + export = opn; }