volta-cli/volta

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

Open

#950 aperta il 25 feb 2021

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)Rust (189 fork)batch import
enhancementgood first issue

Metriche repository

Star
 (8309 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor