Language - JavaScript - Yarn
Define JavaScript language package.
(use-package emacs
:after (uno-lang-js uno-dev-lsp projectile)
:config
(provide 'uno-lang-js-yarn))
(use-package emacs
:after uno-lang-js-yarn
:init
(defun uno/lang/js/yarn/add-to-local-lsp (name file)
"Add NAME dependency from FILE to local yarn instance."
(when (uno/lang/js/yarn/local-p file)
(lsp-dependency name `(:yarn-local ,file))
t))
(defun uno/lang/js/yarn/check ()
"Set up support with local Yarn instance."
(when (uno/lang/js/yarn/local-p)
(require 'lsp-javascript)
(make-local-variable 'lsp-enabled-clients)
(plist-put lsp-deps-providers
:yarn-local '(:path uno/lang/js/yarn/local-provider))
(setq-local lsp-auto-guess-root t)
(run-hooks 'uno-lang-js-yarn-hook)))
(defun uno/lang/js/yarn/local-p (&optional file)
"Check if Yarn SDK is available locally."
(if file
(file-exists-p (uno/lang/js/yarn/local-provider file))
(file-directory-p (uno/lang/js/yarn/local-provider))))
(defun uno/lang/js/yarn/local-provider (&optional path)
"Provide path for local yarn instance relative to PATH."
(concat (projectile-project-root) ".yarn/sdks/" path)))
(use-package emacs
:after (uno-lang-js-yarn flycheck)
:hook
(uno-lang-js-yarn . uno/lang/js/eslint/add)
:init
(defun uno/lang/js/eslint/add ()
"Add support for ESLint."
(when (uno/lang/js/yarn/local-p "eslint/bin/eslint.js")
(let ((-eslint-full (uno/lang/js/yarn/local-provider "eslint/bin/eslint.js"))
(-node-path (uno/lang/js/yarn/local-provider)))
(setq-local
flycheck-javascript-eslint-executable -eslint-full
lsp-eslint-node-path -node-path
lsp-eslint-package-manager "yarn"))
(push 'eslint lsp-enabled-clients)))
(uno/add-useless-buffer "\\*eslint\\*")
(uno/add-useless-buffer "\\*eslint::.*\\*"))