express-open-in-editor
Advanced tools
Comparing version 1.0.0 to 1.1.0
18
index.js
@@ -11,15 +11,9 @@ var parseUrl = require('parseurl'); | ||
var opener = configure(options, function(err) { | ||
console.warn('open-in-editor configure error: ', err); | ||
console.warn('[open-in-editor] configure error: ', err); | ||
}); | ||
if (!opener) { | ||
return function openInEditorFallback(req, res, next) { | ||
next(); | ||
}; | ||
} | ||
return function openInEditor(req, res, next) { | ||
function fail(code, message) { | ||
res.statusCode = code; | ||
res.end(message); | ||
res.end('[open-in-editor] ' + message); | ||
} | ||
@@ -42,2 +36,8 @@ | ||
if (!opener) { | ||
var msg = 'Request to open file failed, editor is not set up'; | ||
console.warn('[open-in-editor] ', msg); | ||
return fail(400, msg); | ||
} | ||
var filename = querystring.parse(parsedUrl.query).file; | ||
@@ -61,3 +61,3 @@ | ||
function(e) { | ||
fail(500, 'open-in-editor error: ' + e); | ||
fail(500, 'ERROR: ' + e); | ||
} | ||
@@ -64,0 +64,0 @@ ); |
{ | ||
"name": "express-open-in-editor", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Express extension to open file in editor", | ||
@@ -15,5 +15,4 @@ "author": "Roman Dvornov <rdvornov@gmail.com>", | ||
], | ||
"homepage": "https://github.com/lahmatiy/express-open-in-editor#readme", | ||
"dependencies": { | ||
"open-in-editor": "lahmatiy/open-in-editor", | ||
"open-in-editor": "^1.1.0", | ||
"parseurl": "~1.3.0" | ||
@@ -20,0 +19,0 @@ }, |
[![NPM version](https://img.shields.io/npm/v/express-open-in-editor.svg)](https://www.npmjs.com/package/express-open-in-editor) | ||
Express extension to open file in editor. Based on [open-in-editor](https://github.com/lahmatiy/open-in-editor). | ||
Express extension to open any file in an editor. Based on [open-in-editor](https://github.com/lahmatiy/open-in-editor). | ||
@@ -24,5 +24,5 @@ ## Install | ||
After that you can use GET requests like `/open-in-editor?file=foo/bar.ext:2:5` to open `foo/bar.ext` in editor at line 2 column 5. | ||
After that you can use GET requests like `/open-in-editor?file=foo/bar.ext:2:5` to open `foo/bar.ext` in an editor at line 2 column 5. | ||
By default extension uses `process.env.VISUAL` or `process.env.EDITOR` (with this priority) to get command to open file in editor. It could be set globally or with main script: | ||
By default extension uses `process.env.VISUAL` or `process.env.EDITOR` (with this priority) to get the command to open file in an editor. It could be set globally or with main script: | ||
@@ -33,6 +33,19 @@ ``` | ||
Also you can set `process.env.OPEN_FILE`, that has highest priority and could detect editor command to launch by it's short name (i.e. `subl` for `Sublime Text` or `atom` for `Atom Editor`). | ||
Also you can set `process.env.OPEN_FILE` that has highest priority and understands shorthands (i.e. `subl` for `Sublime Text` or `atom` for `Atom Editor`). | ||
More details about editor setup see in [open-in-editor](https://github.com/lahmatiy/open-in-editor). | ||
For more details about editor setup see [open-in-editor](https://github.com/lahmatiy/open-in-editor). | ||
### Using with webpack-dev-server | ||
Although `webpack-dev-server` uses `express` to create server, you can't use `app.use()` to apply extension. Instead you should define it in `setup` method (see [issue](https://github.com/webpack/webpack-dev-server/issues/285) for details). | ||
```js | ||
var server = new WebpackDevServer(webpack(config), { | ||
// ... | ||
setup: function(app) { | ||
app.use(openInEditor()); | ||
} | ||
}); | ||
``` | ||
## API | ||
@@ -52,3 +65,3 @@ | ||
Listen path. | ||
Request to this path triggers middleware. | ||
@@ -63,3 +76,3 @@ #### editor | ||
Allows set editor to open file. Option accepts one of preset value. When some value is set, extension try to detect command to launch editor if possible. | ||
Editor to open files. Option accepts one of preset values. When value is set, extension tries to detect command to launch an editor. | ||
@@ -78,5 +91,5 @@ Supported editors: | ||
Specify command to launch editor. If some value set to option then `editor` is ignoring. | ||
Command to launch an editor. This option overrides whatever is set in `editor` option. | ||
Command could contains some patterns to be replaced by actual values. Supported values: `filename`, `line` and `column`. | ||
Command could contain placeholders that will be replaced with actual values. Supported placeholders: `filename`, `line` and `column`. | ||
@@ -89,3 +102,3 @@ ```js | ||
If no `{filename}` pattern in command found then `{filename}:{line}:{column}` is appending. So, previous example could be simplified: | ||
If no `{filename}` placeholder is present, then `{filename}:{line}:{column}` is appended to the value of this option. That way previous example could be simplified: | ||
@@ -92,0 +105,0 @@ ```js |
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
9933
7
108
0
0
1
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedclap@1.2.3(transitive)
+ Addedes6-promise-polyfill@1.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedopen-in-editor@1.2.1(transitive)
+ Addedos-homedir@1.0.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
Updatedopen-in-editor@^1.1.0