This Neovim plugin allows users to detect and configure JavaScript runtimes (node, deno, or bun) for their projects. It finds the project root directory based on package.json or deno.json and provides functions to retrieve the correct root directory for each runtime.
Use your preferred package manager to install the plugin. For example, with lazy.nvim:
return { "Yuki-bun/nvim_js_runtime_config" }
-- or dependency of other plugins (eg: lspconfig)
return {
"neovim/nvim-lspconfig",
dependencies = { "Yuki-bun/nvim_js_runtime_config" },
config = function()
-- ...
-- ...
Or with packer.nvim:
use { "Yuki-bun/nvim_js_runtime_config" }Note: This plugin does not provide any standalone functionality. It needs to be integrated with another plugin (such as lspconfig) or Neovim APIs to have any meaningful effect.
Note: This plugin requires a package.json or deno.json file in the project root. Single-file projects without these files are not supported.
- Detects the nearest root directory based on
package.jsonordeno.json. - Provides functions to retrieve the root directory for
node,deno, orbunbased on configuration. - Command to configure runtime for a project
:SetJsRuntimeWhen you run this command, you will be prompted to select a runtime (node, deno, or bun). The selected runtime will be stored in .nvim/js_runtime.lock within the project root. This ensures that the correct runtime is used when configuring LSP servers, linters, and formatters.
This plugin exports functions that allow you to retrieve the correct root directory for specified runtime if there is one.
Example usage in Neovim LSP configuration:
local lspconfig = require("lspconfig")
lspconfig.ts_ls.setup({
root_dir = require("js-runtime").node_root_dir,
single_file_support = false,
})
lspconfig.denols.setup({
root_dir = require("js-runtime").deno_root_dir,
single_file_suppor = false,
})By configuring LSP this way, only the matching language server (ts_ls for Node.js projects and denols for Deno projects) will attach, ensuring the correct environment is used.
Returns the root directory if the project is configured for Node.js.
Returns the root directory if the project is configured for Deno.
Returns the root directory if the project is configured for Bun.
Pull requests and issues are welcome! Feel free to suggest improvements or report bugs.
MIT License