1

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.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • `checking the date of node_modules` Be careful with that approach, caught me out when trying create some auto generated build tools, this was due to NPM using back to future dates, https://github.com/npm/npm/issues/20439 Apparently this was for some tarball consistency builds, but of course instead of fixing the issue at source, NPM dev's decided to break NPM logic instead. – Keith Nov 24 '21 at 11:34
  • @Keith which is why, if possible, I'd like to reuse `npm`s logic instead of that. – jjmerelo Nov 24 '21 at 12:06
  • @Keith also, was that an April's fools release? – jjmerelo Nov 24 '21 at 12:08
  • 1
    No, I don't believe it was an April fools.. :) .. But if you want to see how NPM does thing under the hood, you could maybe look at the source -> https://github.com/npm/cli – Keith Nov 24 '21 at 12:14
  • @Keith right, I've tried that... and quitted. Every command has its own file, so that's easy. But then... it gets complicated. Bad comes to worse, I guess that's the only way... – jjmerelo Nov 24 '21 at 15:59

0 Answers0