Moshe Katz Moshe Katz - 3 months ago 11
Git Question

Make my NPM package available in source and dist versions

I am working on a private NPM package that I make available to developers who use our API. For various reasons (decided by management), the package on our NPM repository (Sonatype Nexus) has the following folder structure:

+- build
| |- browser.min.js
| \- node.min.js
|- docs
| \ ...
|- package.json
\- README.md


The JS files in the
build
directory are compiled from the actual code of the package.

Also included in the built package are specific versions of dependencies that the package relies on (such as a modified version of
WildEmitter
).

To allow for easy publishing, the
package.json
has the following in it:

...
"main": "build/node.min.js",
"browser": "build/browser.min.js",
"files": [
"build/*.js",
"docs/*",
"README.md"
],
...


However, for internal use of the package, we want to use an uncompiled version, specifically to reduce the overhead of included our dependencies that were included above.

(Aside, I know that this isn't necessarily the best way to package stuff, but we can't change that so easily at this point unless we have no other option.)

I assumed that I would be able to pull the package from our private Git repository, which would give me the whole code of the package.

However, NPM still reads the
files
section of
package.json
when it loads from Git, so it does the
git clone
and then deletes any files that are not present in the
files
array, leaving me with a directory that contains only
docs/*
,
package.json
, and
README.md
.

Is there a way to get the entire code of the package checked out of Git and kept?

Answer

In the end, I decided to modify my build process to make this easier.

Instead of building just the scipts into the build directory and packaging starting from the repository root directory, I have modified my build script to also copy README.md, package.json, and docs/* into the build directory, then to cd into that directory to do the npm publish.

That way, package.json can just say to include all files in the directory.