Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does npm publish perform an npm pack

Considering the Node.js package manager, namely npm - I was curious if the publish command performs the pack command prior to the publish or if it does something different altogether? So if I were to execute:

npm publish <folder>

Does it first perform the following:

npm pack <folder>

I was unable to find anything mentioned in the documentation.


The primary reason I'm curious about this is that our build process is simply doing the npm publish without the explicit npm pack prior, but the package doesn't appear to have the expected contents. i.e.; the contents of the .tgz differ when I perform a local npm pack to that of the contents of the npm publish.
like image 223
David Pine Avatar asked May 13 '16 14:05

David Pine


Video Answer


1 Answers

Having a look at the NPM source you can see that it arrives in the publishFromDirectory function, and calls into the pack module.

https://github.com/npm/npm/blob/b80d650def417645d2525863e9f17af57a917b42/lib/publish.js#L79 and again at https://github.com/npm/npm/blob/b80d650def417645d2525863e9f17af57a917b42/lib/publish.js#L88

If you follow through into the pack module, you can see that the _pack function performs the same 2 steps:

https://github.com/npm/npm/blob/114d518c75732c42acbef3acab36ba1d0fd724e2/lib/pack.js#L67

So, to answer your question, it doesn't do exactly pack <folder> but does call into the same major code paths.

The code there is mostly well written and not difficult to follow, I would encourage you to dig into the source code of these projects for this type of question as your knowledge on the tools you are using will explode if you do.

like image 198
major-mann Avatar answered Oct 06 '22 09:10

major-mann