open-editor
Advanced tools
Comparing version 3.0.0 to 4.0.0
113
index.d.ts
import {PathLike} from 'line-column-path'; | ||
declare namespace openEditor { | ||
interface Options { | ||
/** | ||
Name, command, or binary path of the editor. | ||
export interface Options { | ||
/** | ||
The name, command, or binary path of the editor. | ||
Default: [Auto-detected](https://github.com/sindresorhus/env-editor). | ||
Default: [Auto-detected](https://github.com/sindresorhus/env-editor). | ||
__Only use this option if you really have to.__ Can be useful if you want to force a specific editor or implement your own auto-detection. | ||
*/ | ||
readonly editor?: string; | ||
} | ||
__Only use this option if you really have to.__ Can be useful if you want to force a specific editor or implement your own auto-detection. | ||
*/ | ||
readonly editor?: string; | ||
} | ||
interface EditorRunConfig { | ||
/** | ||
Editor binary name. | ||
*/ | ||
binary: string; | ||
export interface EditorInfo { | ||
/** | ||
THe editor binary name. | ||
*/ | ||
readonly binary: string; | ||
/** | ||
Arguments provided to the editor binary. | ||
*/ | ||
arguments: string[]; | ||
/** | ||
The arguments provided to the editor binary. | ||
*/ | ||
readonly arguments: string[]; | ||
/** | ||
A flag indicating whether the editor runs in the terminal. | ||
*/ | ||
isTerminalEditor: boolean; | ||
} | ||
/** | ||
A flag indicating whether the editor runs in the terminal. | ||
*/ | ||
readonly isTerminalEditor: boolean; | ||
} | ||
declare const openEditor: { | ||
/** | ||
Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit. | ||
/** | ||
Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit. | ||
@param files - Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`. | ||
@param files - Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`. | ||
@example | ||
``` | ||
import openEditor = require('open-editor'); | ||
@example | ||
``` | ||
import openEditor from 'open-editor'; | ||
openEditor([ | ||
'unicorn.js:5:3', | ||
{ | ||
file: 'readme.md', | ||
line: 10, | ||
column: 2 | ||
} | ||
]); | ||
``` | ||
*/ | ||
(files: readonly PathLike[], options?: openEditor.Options): void; | ||
openEditor([ | ||
{ | ||
file: 'readme.md', | ||
line: 10, | ||
column: 2, | ||
} | ||
]); | ||
/** | ||
Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal. | ||
openEditor([ | ||
'unicorn.js:5:3', | ||
]); | ||
``` | ||
*/ | ||
export default function openEditor(files: readonly PathLike[], options?: Options): void; | ||
Can be useful if you want to handle opening the files yourself. | ||
/** | ||
Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal. | ||
@example | ||
``` | ||
{binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false} | ||
``` | ||
*/ | ||
make( | ||
files: readonly PathLike[], | ||
options?: openEditor.Options | ||
): openEditor.EditorRunConfig; | ||
}; | ||
Can be useful if you want to handle opening the files yourself. | ||
export = openEditor; | ||
@example | ||
``` | ||
import {getEditorInfo} from 'open-editor'; | ||
getEditorInfo([ | ||
{ | ||
file: 'foo.js', | ||
line: 1, | ||
column: 5, | ||
} | ||
]); | ||
//=> {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false} | ||
``` | ||
*/ | ||
export function getEditorInfo(files: readonly PathLike[], options?: Options): EditorInfo; |
42
index.js
@@ -1,8 +0,8 @@ | ||
'use strict'; | ||
const execa = require('execa'); | ||
const envEditor = require('env-editor'); | ||
const lineColumnPath = require('line-column-path'); | ||
const open = require('open'); | ||
import process from 'node:process'; | ||
import execa from 'execa'; | ||
import {getEditor, defaultEditor} from 'env-editor'; | ||
import {parseLineColumnPath, stringifyLineColumnPath} from 'line-column-path'; | ||
import open from 'open'; | ||
const make = (files, options = {}) => { | ||
export function getEditorInfo(files, options = {}) { | ||
if (!Array.isArray(files)) { | ||
@@ -12,3 +12,3 @@ throw new TypeError(`Expected an \`Array\`, got ${typeof files}`); | ||
const editor = options.editor ? envEditor.getEditor(options.editor) : envEditor.defaultEditor(); | ||
const editor = options.editor ? getEditor(options.editor) : defaultEditor(); | ||
const editorArguments = []; | ||
@@ -21,6 +21,6 @@ | ||
for (const file of files) { | ||
const parsed = lineColumnPath.parse(file); | ||
const parsed = parseLineColumnPath(file); | ||
if (['sublime', 'atom', 'vscode'].includes(editor.id)) { | ||
editorArguments.push(lineColumnPath.stringify(parsed)); | ||
editorArguments.push(stringifyLineColumnPath(parsed)); | ||
continue; | ||
@@ -30,3 +30,3 @@ } | ||
if (['webstorm', 'intellij'].includes(editor.id)) { | ||
editorArguments.push(lineColumnPath.stringify(parsed, {column: false})); | ||
editorArguments.push(stringifyLineColumnPath(parsed, {column: false})); | ||
continue; | ||
@@ -36,4 +36,4 @@ } | ||
if (editor.id === 'textmate') { | ||
editorArguments.push('--line', lineColumnPath.stringify(parsed, { | ||
file: false | ||
editorArguments.push('--line', stringifyLineColumnPath(parsed, { | ||
file: false, | ||
}), parsed.file); | ||
@@ -54,8 +54,8 @@ continue; | ||
arguments: editorArguments, | ||
isTerminalEditor: editor.isTerminalEditor | ||
isTerminalEditor: editor.isTerminalEditor, | ||
}; | ||
}; | ||
} | ||
module.exports = (files, options) => { | ||
const result = make(files, options); | ||
export default function openEditor(files, options) { | ||
const result = getEditorInfo(files, options); | ||
const stdio = result.isTerminalEditor ? 'inherit' : 'ignore'; | ||
@@ -65,3 +65,3 @@ | ||
detached: true, | ||
stdio | ||
stdio, | ||
}); | ||
@@ -71,5 +71,5 @@ | ||
subprocess.on('error', () => { | ||
const result = make(files, { | ||
const result = getEditorInfo(files, { | ||
...options, | ||
editor: '' | ||
editor: '', | ||
}); | ||
@@ -87,4 +87,2 @@ | ||
} | ||
}; | ||
module.exports.make = make; | ||
} |
{ | ||
"name": "open-editor", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Open files in your editor at a specific line and column", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -50,12 +52,12 @@ "scripts": { | ||
"dependencies": { | ||
"env-editor": "^0.4.1", | ||
"execa": "^5.0.0", | ||
"line-column-path": "^2.0.0", | ||
"open": "^7.3.0" | ||
"env-editor": "^1.0.0", | ||
"execa": "^5.1.1", | ||
"line-column-path": "^3.0.0", | ||
"open": "^8.4.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.36.1" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.18.0", | ||
"xo": "^0.45.0" | ||
} | ||
} |
@@ -20,5 +20,5 @@ # open-editor | ||
```sh | ||
npm install open-editor | ||
``` | ||
$ npm install open-editor | ||
``` | ||
@@ -28,12 +28,15 @@ ## Usage | ||
```js | ||
const openEditor = require('open-editor'); | ||
import openEditor from 'open-editor'; | ||
openEditor([ | ||
'unicorn.js:5:3', | ||
{ | ||
file: 'readme.md', | ||
line: 10, | ||
column: 2 | ||
column: 2, | ||
} | ||
]); | ||
openEditor([ | ||
'unicorn.js:5:3', | ||
]); | ||
``` | ||
@@ -62,7 +65,7 @@ | ||
Name, command, or binary path of the editor. | ||
The name, command, or binary path of the editor. | ||
**Only use this option if you really have to.** Can be useful if you want to force a specific editor or implement your own auto-detection. | ||
### openEditor.make(files, options?) | ||
### getEditorRunConfig(files, options?) | ||
@@ -75,2 +78,15 @@ Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal. | ||
```js | ||
import {getEditorInfo} from 'open-editor'; | ||
getEditorInfo([ | ||
{ | ||
file: 'foo.js', | ||
line: 1, | ||
column: 5, | ||
} | ||
]); | ||
//=> {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false} | ||
``` | ||
## Related | ||
@@ -77,0 +93,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7646
124
92
Yes
+ Addeddefine-lazy-prop@2.0.0(transitive)
+ Addedenv-editor@1.1.0(transitive)
+ Addedline-column-path@3.0.0(transitive)
+ Addedopen@8.4.2(transitive)
+ Addedtype-fest@2.19.0(transitive)
- Removedenv-editor@0.4.2(transitive)
- Removedline-column-path@2.0.0(transitive)
- Removedopen@7.4.2(transitive)
- Removedtype-fest@0.4.1(transitive)
Updatedenv-editor@^1.0.0
Updatedexeca@^5.1.1
Updatedline-column-path@^3.0.0
Updatedopen@^8.4.0