open-editor
Advanced tools
Comparing version 1.2.0 to 2.0.0
54
index.js
@@ -5,5 +5,5 @@ 'use strict'; | ||
const lineColumnPath = require('line-column-path'); | ||
const opn = require('opn'); | ||
const open = require('open'); | ||
const make = (files, opts) => { | ||
const make = (files, options = {}) => { | ||
if (!Array.isArray(files)) { | ||
@@ -13,9 +13,7 @@ throw new TypeError(`Expected an \`Array\`, got ${typeof files}`); | ||
opts = Object.assign({}, opts); | ||
const editor = options.editor ? envEditor.getEditor(options.editor) : envEditor.defaultEditor(); | ||
const editorArguments = []; | ||
const editor = opts.editor ? envEditor.get(opts.editor) : envEditor.default(); | ||
const args = []; | ||
if (editor.id === 'vscode') { | ||
args.push('--goto'); | ||
editorArguments.push('--goto'); | ||
} | ||
@@ -26,9 +24,9 @@ | ||
if (['sublime', 'atom', 'vscode'].indexOf(editor.id) !== -1) { | ||
args.push(lineColumnPath.stringify(parsed)); | ||
if (['sublime', 'atom', 'vscode'].includes(editor.id)) { | ||
editorArguments.push(lineColumnPath.stringify(parsed)); | ||
continue; | ||
} | ||
if (['webstorm', 'intellij'].indexOf(editor.id) !== -1) { | ||
args.push(lineColumnPath.stringify(parsed, {column: false})); | ||
if (['webstorm', 'intellij'].includes(editor.id)) { | ||
editorArguments.push(lineColumnPath.stringify(parsed, {column: false})); | ||
continue; | ||
@@ -38,3 +36,3 @@ } | ||
if (editor.id === 'textmate') { | ||
args.push('--line', lineColumnPath.stringify(parsed, { | ||
editorArguments.push('--line', lineColumnPath.stringify(parsed, { | ||
file: false | ||
@@ -45,13 +43,13 @@ }), parsed.file); | ||
if (['vim', 'neovim'].indexOf(editor.id) !== -1) { | ||
args.push(`+call cursor(${parsed.line}, ${parsed.column})`, parsed.file); | ||
if (['vim', 'neovim'].includes(editor.id)) { | ||
editorArguments.push(`+call cursor(${parsed.line}, ${parsed.column})`, parsed.file); | ||
continue; | ||
} | ||
args.push(parsed.file); | ||
editorArguments.push(parsed.file); | ||
} | ||
return { | ||
bin: editor.bin, | ||
args, | ||
binary: editor.binary, | ||
arguments: editorArguments, | ||
isTerminalEditor: editor.isTerminalEditor | ||
@@ -61,8 +59,7 @@ }; | ||
module.exports = (files, opts) => { | ||
const result = make(files, opts); | ||
module.exports = (files, options) => { | ||
const result = make(files, options); | ||
const stdio = result.isTerminalEditor ? 'inherit' : 'ignore'; | ||
const cp = childProcess.spawn(result.bin, result.args, { | ||
const subProcess = childProcess.spawn(result.bin, result.arguments, { | ||
detached: true, | ||
@@ -73,7 +70,10 @@ stdio | ||
// Fallback | ||
cp.on('error', () => { | ||
const result = make(files, Object.assign({}, opts, {editor: ''})); | ||
subProcess.on('error', () => { | ||
const result = make(files, { | ||
...options, | ||
editor: '' | ||
}); | ||
for (const file of result.args) { | ||
opn(file, {wait: false}); | ||
for (const file of result.arguments) { | ||
open(file); | ||
} | ||
@@ -83,5 +83,5 @@ }); | ||
if (result.isTerminalEditor) { | ||
cp.on('exit', process.exit); | ||
subProcess.on('exit', process.exit); | ||
} else { | ||
cp.unref(); | ||
subProcess.unref(); | ||
} | ||
@@ -88,0 +88,0 @@ }; |
106
package.json
{ | ||
"name": "open-editor", | ||
"version": "1.2.0", | ||
"description": "Open files in your editor at a specific line and column", | ||
"license": "MIT", | ||
"repository": "sindresorhus/open-editor", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"open", | ||
"editor", | ||
"launch", | ||
"files", | ||
"file", | ||
"line", | ||
"column", | ||
"position", | ||
"path", | ||
"filepath", | ||
"editors", | ||
"start", | ||
"app", | ||
"sublime", | ||
"atom", | ||
"vscode", | ||
"webstorm", | ||
"textmate", | ||
"vim", | ||
"neovim", | ||
"intellij" | ||
], | ||
"dependencies": { | ||
"env-editor": "^0.3.1", | ||
"line-column-path": "^1.0.0", | ||
"opn": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "open-editor", | ||
"version": "2.0.0", | ||
"description": "Open files in your editor at a specific line and column", | ||
"license": "MIT", | ||
"repository": "sindresorhus/open-editor", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"open", | ||
"editor", | ||
"launch", | ||
"files", | ||
"file", | ||
"line", | ||
"column", | ||
"position", | ||
"path", | ||
"filepath", | ||
"editors", | ||
"start", | ||
"app", | ||
"sublime", | ||
"atom", | ||
"vscode", | ||
"webstorm", | ||
"textmate", | ||
"vim", | ||
"neovim", | ||
"intellij", | ||
"emacs", | ||
"nano" | ||
], | ||
"dependencies": { | ||
"env-editor": "^0.4.0", | ||
"line-column-path": "^2.0.0", | ||
"open": "^6.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -22,3 +22,3 @@ # open-editor [![Build Status](https://travis-ci.org/sindresorhus/open-editor.svg?branch=master)](https://travis-ci.org/sindresorhus/open-editor) | ||
``` | ||
$ npm install --save open-editor | ||
$ npm install open-editor | ||
``` | ||
@@ -51,3 +51,3 @@ | ||
Type: `Array<string|Object>` | ||
Type: `Array<string | object>` | ||
@@ -58,3 +58,3 @@ Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`. | ||
Type: `Object` | ||
Type: `object` | ||
@@ -66,5 +66,5 @@ ##### editor | ||
Name, command, or binary path of the editor. Only use this option if you really have to. | ||
Name, command, or binary path of the editor. | ||
Can be useful if you want to force a specific editor or implement your own auto-detection. | ||
**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. | ||
@@ -75,3 +75,3 @@ ### openEditor.make(files, [options]) | ||
Example: `{bin: 'subl', args: ['foo.js:1:5'], isTerminalEditor: false}` | ||
Example: `{binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false}` | ||
@@ -84,3 +84,3 @@ Can be useful if you want to handle opening the files yourself. | ||
- [open-editor-cli](https://github.com/sindresorhus/open-editor-cli) - CLI for this module | ||
- [opn](https://github.com/sindresorhus/opn) - Opens stuff like websites, files, executables | ||
- [open](https://github.com/sindresorhus/open) - Open stuff like URLs, files, executables | ||
@@ -87,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
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
7385
5
123
3
+ Addedopen@^6.2.0
+ Addedenv-editor@0.4.2(transitive)
+ Addedline-column-path@2.0.0(transitive)
+ Addedopen@6.4.0(transitive)
+ Addedtype-fest@0.4.1(transitive)
- Removedopn@^5.0.0
- Removedenv-editor@0.3.1(transitive)
- Removedline-column-path@1.0.0(transitive)
- Removedopn@5.5.0(transitive)
Updatedenv-editor@^0.4.0
Updatedline-column-path@^2.0.0