perf(javascript): replace add-node-modules-path

The add-node-modules-path package calls `npm bin` to locate the
node_modules/.bin, and does so while invoking the user's $SHELL, which
can be very expensive depending on the user's shell configuration,
possibly adding seconds to the startup time of any JS/TS file.

To mitigate this, I replace the package with a much faster, and in-house
heuristic. Folks with more complex needs should be using direnv anyway.

Fix: #6878
This commit is contained in:
Henrik Lissner 2022-10-08 18:07:17 +02:00
parent 4bd4b13158
commit d25ff46d46
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
3 changed files with 10 additions and 2 deletions

View file

@ -31,6 +31,15 @@ ignore the cache."
(assq packages deps))
(t (error "Expected a package symbol or list, got %s" packages))))))
;;;###autoload
(defun +javascript-add-npm-path-h ()
"Add node_modules/.bin to `exec-path'."
(when-let ((node-modules-parent (locate-dominating-file default-directory "node_modules/"))
(node-modules-dir (expand-file-name "node_modules/.bin/" node-modules-parent)))
(make-local-variable 'exec-path)
(add-to-list 'exec-path node-modules-dir)
(doom-log ":lang:javascript: add %s to $PATH" (expand-file-name "node_modules/" node-modules-parent))))
;;
;; Commands

View file

@ -323,7 +323,7 @@ to tide."
typescript-mode
solidity-mode)
:when (locate-dominating-file default-directory "package.json")
:add-hooks '(add-node-modules-path npm-mode))
:add-hooks '(+javascript-add-npm-path-h npm-mode))
(def-project-mode! +javascript-gulp-mode
:when (locate-dominating-file default-directory "gulpfile.js"))

View file

@ -8,7 +8,6 @@
;; Tools
(package! js2-refactor :pin "a0977c4ce1918cc266db9d6cd7a2ab63f3a76b9a")
(package! npm-mode :pin "3ee7c0bad5b7a041d4739ef3aaa06a3dc764e5eb")
(package! add-node-modules-path :pin "63f047fd84b825876152743f66de7ee6f9ed203b")
;; Eval
(package! nodejs-repl :pin "3b841055cad00f442e4a9159b1056f59411b6646")