Let's say we want to replicate part of the functionality npm has, namely, we want to know if node_modules is synced with the current state of package.json and package-lock.json, so that, if it's not, launch npm ci (if possible also programatically). Essentially we don't want to incur into the penalty of running npm ci (which can take several seconds) but do something a bit less simplistic than checking the date of node_modules against package.json.
I have checked out the dependencies of npm, and there does not seem to be one that carries that logic. arborist is more related to dependencies and its storage, pacote deals with packages. So it must be something in npm itself. Also, according to this answer we shouldn't really try and run npm from outside the CLI so I wonder if that kind of logic (which is probably used elsewhere, like yarn or grunt) is available from some other package.
At the end of the day, I want a logic similar to the one used by make: update stuff if downstream dependencies have changed somehow. node_modules vs. package.json is an example... But there could be use cases where we would also need it. At the end of the day, what I'm looking for are off-the-shelf node.js modules that would help me create a make-like tool in JavaScript.