Why does nodebb check dependencies programmatically?
-
I'm having trouble understanding what the point of this code is:
NodeBB/src/cli/index.js at 16f0affa701fbc1b89745386d709c39179caca24 · NodeBB/NodeBB
Node.js based forum software built for the modern web - NodeBB/src/cli/index.js at 16f0affa701fbc1b89745386d709c39179caca24 · NodeBB/NodeBB
GitHub (github.com)
if (['ENOENT', 'DEP_WRONG_VERSION', 'MODULE_NOT_FOUND'].includes(e.code)) { console.warn('Dependencies outdated or not yet installed.'); console.log('Installing them now...\n'); packageInstall.updatePackageFile(); packageInstall.preserveExtraneousPlugins(); packageInstall.installAll();
It runs even if it's preceded by an
npm install
, so I'm not sure what problem it's finding. It's slowing down docker builds by quite a bit. The other issue is that if you use a faster package manager likepnpm
, it's still piping everything through npm.It would be nice if:
- there was a flag to disable this behavior for environments like Docker
- the package error is output with console.debug so there were some chance to solve the problem. I'm finding nodebb's internals a bit mysterious based on behavior like not surfacing errors, which is making debugging a lot harder.
-
The NodeBB repository does not have a root
package.json
. It hasinstall/package.json
. This is to support installing plugins stored inpackage.json
while still being able to upgrade the dependencies of NodeBB core.But this means that
npm install
does not work out of the box. Instead, our CLI detects the absence ofpackage.json
or the absence of some dependencies and will automatically install them as necessary.This simplifies the install and upgrade process.
It's slowing down docker builds by quite a bit.
I don't see why checking the existence of a few files would slow things down like you say. Have you measured it?
The other issue is that if you use a faster package manager like pnpm, it's still piping everything through npm.
You can set your preferred package manager in config.json
-
@o-o said in Why does nodebb check dependencies programmatically?:
It runs even if it's preceded by an
npm install
, so I'm not sure what problem it's finding.It doesn't if it finds the correct dependencies. You can see in the code above this what the check does - verify that
package.json
of NodeBB dependencies matches the semver ranges specified for a given NodeBB version. Importantly, it does so only for a few deps - I'm not actually sure what criteria they were chosen on, but as long as you install the right versions ofnconf
(required for NodeBB config),async
,chalk
(probably because it's in CLI code?),commander
,lodash
andlru-cache
NodeBB should not try to install anything.The other issue is that if you use a faster package manager like
pnpm
, it's still piping everything through npm.NodeBB can actually use
npm
,cnpm
,pnpm
oryarn
depending on corepack'spackageManager
key inpackage.json
,package_manager
setting inconfig.json
(https://docs.nodebb.org/configuring/config/) or lock files, in that order (so corepack setting takes precedence over the rest).But you need to somehow tell NodeBB you're using something else than npm - since due to being shipped with node it's the obvious default.
-
-