How can package files (these to be published) be listed to debug records in .npmignore
?
I'm looking for something like equivalent of git ls-files
for .gitignore
.
The only way I have found so far is to pack the package and then list the archive which I find a bit clumsy:
npm pack
tar -tzf <package-id>.tgz
As Mike 'Pomax' Kamermans mentioned in comment the fact that .npmignore
and .gitignore
use the same syntax can be leveraged:
git ls-files -co --exclude-per-directory=.npmignore
The command above lists exactly files that are not npm-ignored according to .npmignore
file. (On top of that npm automatically ignores some other entries like node_modules
.)
Git ls-files
command generally lists combinations of files in working directory and index.
-c
option says show cached files-o
show 'other', i.e. untracked files--exclude-per-directory=.npmignore
use .npmignore
as name of files of ignore entriesEDIT:
Since the approach above has bunch of exceptions - files that will never or always included regardless of content of the .npmignore
- I find it unreliable. Following command is heavyweight but reliable:
file_name=$(npm pack) && tar -ztf $file_name && rm $file_name
It packages the project, lists package files and at the end removes created package.
npm pack --dry-run
prints out what will be included
logger ❯ npm pack --dry-run
npm notice
npm notice 📦 @supercollider.js/[email protected]
npm notice === Tarball Contents ===
npm notice 817B package.json
npm notice 199B README.md
npm notice 1.7kB lib/index.d.ts
npm notice 693B lib/index.d.ts.map
npm notice 3.9kB lib/index.js
npm notice 2.9kB lib/index.js.map
npm notice === Tarball Details ===
npm notice name: @supercollider.js/logger
npm notice version: 1.0.0
npm notice filename: supercollider.js-logger-1.0.0.tgz
npm notice package size: 3.0 kB
npm notice unpacked size: 10.2 kB
npm notice shasum: 6c60400e1d61723ce3d7705bb3a8a9a907b7d83b
npm notice integrity: sha512-+1tQZMPQr3cAp[...]zPu6R/BqYdIJQ==
npm notice total files: 6
npm notice
supercollider.js-logger-1.0.0.tgz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With