Ensure that 'nvm use' is applied properly across various directories and commands. `npm run watch` and `npm run setup` are now deterministic and reliable. #32
This PR should fix issues folks have been having with running npm run setup and getting errors like:
nvm is not compatible with the "PREFIX" environment variable
Run unset PREFIX to unset it.
Summary of changes
Fixes scripts/watch so that it properly does 'nvm use' to ensure correct Node version
Improves scripts/watch to be more readable/maintainable
Adds a scripts/install script to ensure that 'npm install' occurs via
correct NodeJS version by respecting the .nvmrc file.
Removes extraneous debug message from scripts/add
Background
The solid/solidos build system uses Lerna to cross-link the node_modules/ directories for the various sub-repos in workspaces/.
These sub-repos (e.g., node-solid-server, solid-ui, mashlib, etc) each have their own .nvmrc file to indicate the NodeJS version that they support. Currently, the versions in .nvmrc files are:
12.19.1 solidos/.nvmrc
v12.7.0 solidos/workspaces/mashlib/.nvmrc
13.14.0 solidos/workspaces/node-solid-server/.nvmrc
v12.19.1 solidos/workspaces/rdflib/.nvmrc
v12.7.0 solidos/workspaces/solid-panes/.nvmrc
v12.7.0 solidos/workspaces/solid-ui/.nvmrc
Unfortunately, not all of the sub-repos use the same NodeJS version, so it is necessary to ensure that nvm use is invoked when building a particular repo.
But nvm use is very sensitive to the bash environment having either PREFIX or npm_config_prefix defined. If either is defined, the above nvm is not compatible with the "PREFIX" environment variable or nvm is not compatible with the "npm_config_prefix" environment variable error message will be displayed and nvm will fail.
However, when a package.json script is invoked via npm run (e.g., npm run setup), then the invoked script will have both PREFIX and npm_config_prefix defined. So these must be explicitly unset before invoking nvm use.
It is also necessary, in some cases, to add nvm to the bash environment by invoking $HOME/.nvm/nvm.sh, which then invokes nvm use. If either PREFIX ornpm_config_prefix are defined, then this will fail.
If you invoke something like scripts/reset without using npm run reset, then nvm will usually work properly, because PREFIX and npm_config_prefix will usually not be defined. This is what made debugging this tricksy.
The nvm use command has a --delete-prefix option, which basically unsets PREFIX and npm_config_prefix and continues without failure. However, when $HOME/.nvm/nvm.sh is sourced, there is no provision for passing this argument. That is why it is necessary to unset PREFIX npm_config_prefix prior to sourcing nvm.sh.
This PR should fix issues folks have been having with running
npm run setup
and getting errors like:Summary of changes
.nvmrc
file.Background
.nvmrc
file to indicate the NodeJS version that they support. Currently, the versions in.nvmrc
files are: 12.19.1 solidos/.nvmrc v12.7.0 solidos/workspaces/mashlib/.nvmrc 13.14.0 solidos/workspaces/node-solid-server/.nvmrc v12.19.1 solidos/workspaces/rdflib/.nvmrc v12.7.0 solidos/workspaces/solid-panes/.nvmrc v12.7.0 solidos/workspaces/solid-ui/.nvmrcnvm use
is invoked when building a particular repo.nvm use
is very sensitive to the bash environment having eitherPREFIX
ornpm_config_prefix
defined. If either is defined, the abovenvm is not compatible with the "PREFIX" environment variable
ornvm is not compatible with the "npm_config_prefix" environment variable
error message will be displayed andnvm
will fail.package.json
script is invoked vianpm run
(e.g.,npm run setup
), then the invoked script will have bothPREFIX
andnpm_config_prefix
defined. So these must be explicitly unset before invokingnvm use
.nvm
to the bash environment by invoking$HOME/.nvm/nvm.sh
, which then invokesnvm use
. If eitherPREFIX
ornpm_config_prefix
are defined, then this will fail.scripts/reset
without usingnpm run reset
, then nvm will usually work properly, becausePREFIX
andnpm_config_prefix
will usually not be defined. This is what made debugging this tricksy.nvm use
command has a--delete-prefix
option, which basically unsetsPREFIX
andnpm_config_prefix
and continues without failure. However, when$HOME/.nvm/nvm.sh
is sourced, there is no provision for passing this argument. That is why it is necessary tounset PREFIX npm_config_prefix
prior to sourcingnvm.sh
.