Support searching node_modules/.bin
Adds a package that allows Emacs to searching through a projects node_modules executables when resolving a binary like eslint, prettier etc. This was being hacked together before by relying on explicit paths to executables. This is a more durable solution. Also includes some packages related to LSP for Javascript, which I haven't been able to get working yet.
This commit is contained in:
parent
3dadd97ef3
commit
6ebd90a946
2 changed files with 44 additions and 48 deletions
|
@ -103,17 +103,6 @@
|
||||||
(evil-window-vsplit)
|
(evil-window-vsplit)
|
||||||
(find-file "~/.emacs.d/init.el"))
|
(find-file "~/.emacs.d/init.el"))
|
||||||
|
|
||||||
(defun wpc/set-flow-executable ()
|
|
||||||
(interactive)
|
|
||||||
(let* ((root (locate-dominating-file buffer-file-name "node_modules/flow-bin"))
|
|
||||||
(executable (car (file-expand-wildcards
|
|
||||||
(concat root "node_modules/flow-bin/*osx*/flow")))))
|
|
||||||
(setq-local company-flow-executable executable)
|
|
||||||
;; These are not necessary for this package, but a good idea if you use
|
|
||||||
;; these other packages
|
|
||||||
(setq-local flow-minor-default-binary executable)
|
|
||||||
(setq-local flycheck-javascript-flow-executable executable)))
|
|
||||||
|
|
||||||
(defun wpc/jump-to-parent-file ()
|
(defun wpc/jump-to-parent-file ()
|
||||||
"Jumps to a React store or component's parent file. Useful for store or index file."
|
"Jumps to a React store or component's parent file. Useful for store or index file."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
;;; javascript.el --- My Javascript preferences -*- lexical-binding: t -*-
|
;;; wpc-javascript.el --- My Javascript preferences -*- lexical-binding: t -*-
|
||||||
;; Author: William Carroll <wpcarro@gmail.com>
|
;; Author: William Carroll <wpcarro@gmail.com>
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
@ -6,11 +6,17 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
;; Helper functions
|
;; Constants
|
||||||
(defun wpc/indium-setup (url)
|
(defconst wpc/js-hooks
|
||||||
"Setup the indium environment using URL."
|
'(js-mode-hook js2-mode-hook rjsx-mode)
|
||||||
(indium-eval (format "window.dispatchEvent(new CustomEvent('patch', {detail: {url: %s}}" url)))
|
"All of the commonly used hooks for Javascript buffers.")
|
||||||
|
|
||||||
|
(defconst wpc/frontend-hooks
|
||||||
|
(-insert-at 0 'css-mode-hook wpc/js-hooks)
|
||||||
|
"All of the commonly user hooks for frontend development.")
|
||||||
|
|
||||||
|
|
||||||
|
;; Helper functions
|
||||||
(defun wpc/insert-flow-annotation ()
|
(defun wpc/insert-flow-annotation ()
|
||||||
"Insert a flow type annotation to the beginning of a buffer."
|
"Insert a flow type annotation to the beginning of a buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
@ -18,15 +24,15 @@
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(insert "// @flow\n")))
|
(insert "// @flow\n")))
|
||||||
|
|
||||||
|
;; frontend indentation settings
|
||||||
|
(setq js-indent-level 2
|
||||||
|
css-indent-offset 2)
|
||||||
|
|
||||||
;; ;; javascript
|
;; ;; javascript
|
||||||
;; (evil-leader/set-key-for-mode 'rjsx-mode "t" #'wpc/toggle-between-js-test-and-module)
|
;; (evil-leader/set-key-for-mode 'rjsx-mode "t" #'wpc/toggle-between-js-test-and-module)
|
||||||
;; (evil-leader/set-key-for-mode 'rjsx-mode "x" #'wpc/toggle-between-js-component-and-store)
|
;; (evil-leader/set-key-for-mode 'rjsx-mode "x" #'wpc/toggle-between-js-component-and-store)
|
||||||
;; (evil-leader/set-key-for-mode 'rjsx-mode "u" #'wpc/jump-to-parent-file)
|
;; (evil-leader/set-key-for-mode 'rjsx-mode "u" #'wpc/jump-to-parent-file)
|
||||||
|
|
||||||
;; javascript setup
|
|
||||||
(use-package indium
|
|
||||||
:hook (indium-update-script-source . wpc/indium-setup))
|
|
||||||
|
|
||||||
;; javascript text objects
|
;; javascript text objects
|
||||||
(quelpa '(evil-text-objects-javascript
|
(quelpa '(evil-text-objects-javascript
|
||||||
:fetcher github
|
:fetcher github
|
||||||
|
@ -40,35 +46,21 @@
|
||||||
:config
|
:config
|
||||||
(evil-leader/set-key-for-mode 'rjsx-mode "F" #'wpc/insert-flow-annotation))
|
(evil-leader/set-key-for-mode 'rjsx-mode "F" #'wpc/insert-flow-annotation))
|
||||||
|
|
||||||
(use-package company-flow
|
;; Shouldn't need this once LSP is setup properly
|
||||||
:after (company)
|
;; (use-package company-flow
|
||||||
:hook (rjsx-mode . wpc/set-flow-executable)
|
;; :after (company)
|
||||||
:config
|
;; :config
|
||||||
(add-to-list 'company-flow-modes 'rjsx-mode)
|
;; (add-to-list 'company-flow-modes 'rjsx-mode)
|
||||||
(add-to-list 'company-backends 'company-flow))
|
;; (add-to-list 'company-backends 'company-flow))
|
||||||
|
|
||||||
(use-package flycheck-flow
|
;; Shouldn't need this once LSP is setup properly
|
||||||
:after (flycheck)
|
;; (use-package flycheck-flow
|
||||||
:config
|
;; :after (flycheck)
|
||||||
(flycheck-add-mode 'javascript-flow 'rjsx-mode)
|
;; :config
|
||||||
(flycheck-add-mode 'javascript-flow 'flow-minor-mode)
|
;; (flycheck-add-mode 'javascript-flow 'rjsx-mode)
|
||||||
(flycheck-add-mode 'javascript-eslint 'flow-minor-mode)
|
;; (flycheck-add-mode 'javascript-flow 'flow-minor-mode)
|
||||||
(flycheck-add-next-checker 'javascript-flow 'javascript-eslint))
|
;; (flycheck-add-mode 'javascript-eslint 'flow-minor-mode)
|
||||||
|
;; (flycheck-add-next-checker 'javascript-flow 'javascript-eslint))
|
||||||
;; front-end indentation
|
|
||||||
(setq js-indent-level 2
|
|
||||||
css-indent-offset 2)
|
|
||||||
|
|
||||||
;; eslint integration with flycheck
|
|
||||||
(setq flycheck-javascript-eslint-executable "~/urbint/grid-front-end/node_modules/.bin/eslint")
|
|
||||||
|
|
||||||
;; JS autoformatting
|
|
||||||
(use-package prettier-js
|
|
||||||
:after (rjsx-mode)
|
|
||||||
:ghook ('(rjsx-mode-hook
|
|
||||||
js2-mode-hook
|
|
||||||
json-mode-hook
|
|
||||||
css-mode-hook)))
|
|
||||||
|
|
||||||
;; JSX highlighting
|
;; JSX highlighting
|
||||||
(use-package rjsx-mode
|
(use-package rjsx-mode
|
||||||
|
@ -83,5 +75,20 @@
|
||||||
(setq js2-mode-show-parse-errors nil
|
(setq js2-mode-show-parse-errors nil
|
||||||
js2-mode-show-strict-warnings nil))
|
js2-mode-show-strict-warnings nil))
|
||||||
|
|
||||||
|
;; JS autoformatting
|
||||||
|
(use-package prettier-js
|
||||||
|
:after (rjsx-mode)
|
||||||
|
:config
|
||||||
|
(general-add-hook wpc/frontend-hooks #'prettier-js-mode))
|
||||||
|
|
||||||
|
(use-package add-node-modules-path
|
||||||
|
:config
|
||||||
|
(general-add-hook wpc/js-hooks #'add-node-modules-path))
|
||||||
|
|
||||||
|
;; LSP support
|
||||||
|
(use-package lsp-javascript-flow
|
||||||
|
:config
|
||||||
|
(general-add-hook wpc/js-hooks #'lsp-javascript-flow-enable))
|
||||||
|
|
||||||
(provide 'wpc-javascript)
|
(provide 'wpc-javascript)
|
||||||
;;; wpc-javascript.el ends here
|
;;; wpc-javascript.el ends here
|
||||||
|
|
Loading…
Reference in a new issue