I'm trying to get the list of files from a local package that would be published by npm. The best solution I've come by is to use
npm publish --dry-run
through child_processes.spawn(...)
or a related method.
However, this is not very reliable as I need to parse the text output that is not guaranteed to be/stay the same in all environments/future releases.
Of course, I could npm pack
and list the contents of the tarball, but that is rather outside the scope of my project, as for instance I wouldn't want to rely on being able to write to the filesystem.
So, is there a "semantic" way to access the data returned by npm publish
?
CodePudding user response:
To answer my own question:
The specific case I was having trouble with was solved using the
json
option that I was not aware of at the time I posted the question:npm pack --dry-run --json
through
child_processes.spawn
, which at least produces semantic results.To the general question, i.e., whether it was possible to call
npm
functions directly, not through spawning, the answer seems to be NO.I tried installing
npm
as a library:npm install npm
and then in the javascript source
const Pack = require('npm').Pack;
resulted in an enlightening
Error: The programmatic API was removed in npm v8.0.0