2.6.1 • Published 7 months ago

launch-editor-middleware v2.6.1

Weekly downloads
1,037,436
License
MIT
Repository
github
Last release
7 months ago

launch-editor

Open file with line numbers in editor from Node.js.

The main functionality is extracted from react-dev-utils with slight modifications so that it can be used as a standalone package. The original source code is licensed under MIT.

Also added column number support.

Why

There are also a few other existing packages with the same purpose:

However, both expects env variables like EDITOR to be set in order to open files. This package infers the editor to open by checking current running processes before falling back to env variables.

On the other hand,react-dev-utils includes many other utilities and dependencies and is thus not suitable for standalone usage.

Usage

const launch = require('launch-editor')

launch(
  // filename:line:column
  // both line and column are optional
  'foo.js:12:34',
  // try specific editor bin first (optional)
  'code',
  // callback if failed to launch (optional)
  (fileName, errorMsg) => {
    // log error if any
  }
)

Middleware

An express/connect/webpack-dev-server compatible middleware is also available:

const launchMiddleware = require('launch-editor-middleware')

app.use('/__open-in-editor', launchMiddleware())

The middleware factory function accepts the following arguments (all optional, the callback can be in any position as long as it's the last argument):

  1. A specific editor bin to try first. Defaults to inferring from running processes, then fallback to env variables like EDITOR and VISUAL.
  2. The root directory of source files, in case the file path is relative. Defaults to process.cwd().
  3. a callback when it fails to launch the editor.

To launch files, send requests to the server like the following:

/__open-in-editor?file=src/main.js:13:24

Supported editors

ValueEditorLinuxWindowsOSX
appcodeAppCode
atomAtom
atom-betaAtom Beta
bracketsBrackets
clionClion
codeVisual Studio Code
code-insidersVisual Studio Code Insiders
emacsEmacs
ideaIDEA
notepad++Notepad++
pycharmPyCharm
phpstormPhpStorm
rubymineRubyMine
sublimeSublime Text
vimVim
visualstudioVisual Studio
webstormWebStorm
@ishopee/cli-servicevuedragdropuploadimagesmio-cli-servicemylicensepg-cli-service@guomio/cli-servicefx-webpack-ttk@kzx/citic-cli-servicenuxt-compactnuxt2bb-chat@startdt/cli-service@startdt/next-service@gentean/vue-cli-serviceworklio-cli@everything-registry/sub-chunk-2047vue-cli-service-wc-native-slotsecho_222_module2easy-nuxtmfv-cli-servicemeng-vue-cli-servicephenix-cli-plugin-startphenix-corenuxt-set-clnuxtjs-node6poipigsspigsnuxt-edge-startnuxt-fixmyquasarv1appmylicense1zy-vue-cli-serviceflowable-bpmn-modelergiant-cli-servicefx-webpackfx-webpack-betahot-zone-vuel-lazykolibri-toolslily-vue-uilitepie-datepicker-gabejesusdemomulti-prod-env-vue-cli-servicenewdemo1@best-shot/dev-server@bmy/cli-service@borealisgroup/cli-service@dovca/nuxt-server@bazumax/quasar-appqzx-nuxtqzx-nuxt-startrcli-vue3@fromage/cli-service@fuc/cli-service@fzo/fzo-service@nuxt/server@nuxt/server-edge@phaser-r/cli-service@phenixs/cli-servicersbuild-plugin-console-debugrsbuild-plugin-react-inspectorrsbuild-plugin-svelte-inspectorrsbuild-plugin-vue-inspectorrui-rkitbrowser-vite@gtarsia-vue/cli-servicesource-inspector@dtwo/server@dtwo/server-edgecango-app@etsx/server@evlos/cli-servicecli-multi-servicecli-service-rely-oncli-service-ttncli-service-ttn1@linaj/lazycssesc-wbg@kocdigital/sf-cliservice@mixup/mixupteld-nuxtteld-runtime-nuxt@mpxjs/vue-cli-plugin-mpx@hsdata/web-helperchange-vue-cli-service@elux/cli-webpacksm-webpack-configseabo-cli-service@darwishdev/dash-dev@giantx/cli-service@giantx/giant-cli-service@lumavate/nuxt-edge@nkduy/cli-service@nkduy/ion@micro-app/plugin-webpackcustom-wjp-cli-service@joelwat/quasar-appsummerseatestl@junvary/quasar-ui-qcascader
2.6.1

7 months ago

2.5.0

2 years ago

2.4.0

2 years ago

2.6.0

2 years ago

2.3.0

2 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago