volta-cli/volta

Improve detection of "root" project when inside `node_modules`

Open

#950 aberto em 25 de fev. de 2021

Ver no GitHub
 (6 comments) (0 reactions) (0 assignees)Rust (189 forks)batch import
enhancementgood first issue

Métricas do repositório

Stars
 (8.309 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

When running a shim, Volta will walk up the directory tree to find the closest available package.json file to use as the project, with one exception: When the immediate parent of the directory that contains package.json is node_modules, then we ignore that file. This means when we are inside of our dependencies, if we run a command, we still correctly detect the actual Project root (as opposed to the root of the dependency we are looking at).

Unfortunately, when we are looking at scoped packages (e.g. @babel/core), then the immediate parent is the scope directory, so we think that the root of our project is /project/node_modules/@babel/core, instead of /project. We should also handle the case where the parent is a scoped directory and look one level higher for node_modules.

This may take some design work to make sure that we don't add too much speculative I/O to the project detection process, because it is on the hot path for all commands.

Guia do colaborador