From 422c340b8033681ef0a7b2f89c2b8387b45e195a Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 14 Apr 2026 17:51:30 +0800 Subject: [PATCH] feat: add and improve package types --- packages/launch-editor-middleware/index.d.ts | 45 +++++++++++++++++++ .../launch-editor-middleware/package.json | 3 +- packages/launch-editor/index.d.ts | 15 ++++++- 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 packages/launch-editor-middleware/index.d.ts diff --git a/packages/launch-editor-middleware/index.d.ts b/packages/launch-editor-middleware/index.d.ts new file mode 100644 index 0000000..365f8e3 --- /dev/null +++ b/packages/launch-editor-middleware/index.d.ts @@ -0,0 +1,45 @@ +import http from 'http' + +type Middleware = (req: http.IncomingMessage, res: http.ServerResponse) => void; +type ErrorCallback = (fileName: string, errorMessage: string | null) => void; + +/** + * A middleware to launch an editor to open a file at a specific line and column. + * The request url should have a `file` query parameter with the file path and + * optional line and column numbers (e.g. "?file=/path/to/file.js:10:2"). + * + * @param onErrorCallback Optional callback for handling errors. + */ +declare function launchEditorMiddleware(onErrorCallback?: ErrorCallback): Middleware; + +/** + * A middleware to launch an editor to open a file at a specific line and column. + * The request url should have a `file` query parameter with the file path and + * optional line and column numbers (e.g. "?file=/path/to/file.js:10:2"). + * + * @param specifiedEditor Optional editor command or path to use. Will be + * parsed using `shell-quote`. + * @param onErrorCallback Optional callback for handling errors. + */ +declare function launchEditorMiddleware( + specifiedEditor?: string, + onErrorCallback?: ErrorCallback +): Middleware; + +/** + * A middleware to launch an editor to open a file at a specific line and column. + * The request url should have a `file` query parameter with the file path and + * optional line and column numbers (e.g. "?file=/path/to/file.js:10:2"). + * + * @param specifiedEditor Optional editor command or path to use. Will be + * parsed using `shell-quote`. + * @param srcRoot Optional source root directory to resolve relative file paths. + * @param onErrorCallback Optional callback for handling errors. + */ +declare function launchEditorMiddleware( + specifiedEditor?: string, + srcRoot?: string, + onErrorCallback?: ErrorCallback +): Middleware; + +export = launchEditorMiddleware diff --git a/packages/launch-editor-middleware/package.json b/packages/launch-editor-middleware/package.json index f21eec4..9715a91 100644 --- a/packages/launch-editor-middleware/package.json +++ b/packages/launch-editor-middleware/package.json @@ -4,7 +4,8 @@ "description": "express middleware for launching editor", "main": "index.js", "files": [ - "index.js" + "index.js", + "index.d.ts" ], "scripts": { "test": "node --test --experimental-test-module-mocks" diff --git a/packages/launch-editor/index.d.ts b/packages/launch-editor/index.d.ts index 405030f..90a4b79 100644 --- a/packages/launch-editor/index.d.ts +++ b/packages/launch-editor/index.d.ts @@ -1,3 +1,14 @@ +type ErrorCallback = (fileName: string, errorMessage: string | null) => void; + +/** + * Launch an editor to open a file at a specific line and column. + * + * @param file File path with optional line and column numbers (e.g. + * "/path/to/file.js:10:2"). + * @param onErrorCallback Optional callback for handling errors. + */ +declare function launchEditor(file: string, onErrorCallback?: ErrorCallback): void; + /** * Launch an editor to open a file at a specific line and column. * @@ -9,8 +20,8 @@ */ declare function launchEditor( file: string, - specifiedEditor?: string | ((fileName: string, errorMessage: string | null) => void), - onErrorCallback?: (fileName: string, errorMessage: string | null) => void + specifiedEditor?: string, + onErrorCallback?: ErrorCallback ): void; export = launchEditor;