Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions packages/launch-editor-middleware/index.d.ts
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion packages/launch-editor-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 13 additions & 2 deletions packages/launch-editor/index.d.ts
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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;