Socket
Socket
Sign inDemoInstall

npm-packlist

Package Overview
Dependencies
7
Maintainers
2
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    npm-packlist

Get a list of the files to add from a folder into an npm package


Version published
Maintainers
2
Install size
221 kB
Created

Package description

What is npm-packlist?

The npm-packlist package is used to generate a list of files that would be included in an npm package publish. This includes filtering out files that are not meant to be published, such as those specified in `.npmignore` or the `.gitignore` files, and including those specified in the `files` array in `package.json`. It's useful for package authors to understand and control what gets included in their published npm package.

What are npm-packlist's main functionalities?

Generate packlist

This feature allows you to generate a list of files that would be included if you were to publish the current package. The code sample demonstrates how to use npm-packlist to get an array of file paths that are included in the package's publish list.

const packlist = require('npm-packlist');
packlist().then(files => {
  console.log(files)
});

Customize packlist with package.json

While not a direct feature of npm-packlist, the package respects the `files` field in `package.json`. This allows users to explicitly specify which files or directories should be included in the publish. The code sample shows how to specify a list of files and directories in `package.json` that should be included in the npm package.

{
  "files": [
    "lib/**/*",
    "bin/*",
    "README.md"
  ]
}

Other packages similar to npm-packlist

Readme

Source

npm-packlist

Build Status

Get a list of the files to add from a folder into an npm package

These can be handed to tar like so to make an npm package tarball:

const packlist = require('npm-packlist')
const tar = require('tar')
const packageDir = '/path/to/package'
const packageTarball = '/path/to/package.tgz'

packlist({ path: packageDir })
  .then(files => tar.create({
    prefix: 'package/',
    cwd: packageDir,
    file: packageTarball,
    gzip: true
  }, files))
  .then(_ => {
    // tarball has been created, continue with your day
  })

This uses the following rules:

  1. If a package.json file is found, and it has a files list, then ignore everything that isn't in files. Always include the readme, license, notice, changes, changelog, and history files, if they exist, and the package.json file itself.

  2. If there's no package.json file (or it has no files list), and there is a .npmignore file, then ignore all the files in the .npmignore file.

  3. If there's no package.json with a files list, and there's no .npmignore file, but there is a .gitignore file, then ignore all the files in the .gitignore file.

  4. Everything in the root node_modules is ignored, unless it's a bundled dependency. If it IS a bundled dependency, and it's a symbolic link, then the target of the link is included, not the symlink itself.

  5. Unless they're explicitly included (by being in a files list, or a !negated rule in a relevant .npmignore or .gitignore), always ignore certain common cruft files:

    1. .npmignore and .gitignore files (their effect is in the package already, there's no need to include them in the package)
    2. editor junk like .*.swp, ._* and .*.orig files
    3. .npmrc files (these may contain private configs)
    4. The node_modules/.bin folder
    5. Waf and gyp cruft like /build/config.gypi and .lock-wscript
    6. Darwin's .DS_Store files because wtf are those even
    7. npm-debug.log files at the root of a project

    You can explicitly re-include any of these with a files list in package.json or a negated ignore file rule.

API

Same API as ignore-walk, just hard-coded file list and rule sets.

The Walker and WalkerSync classes take a bundled argument, which is a list of package names to include from node_modules. When calling the top-level packlist() and packlist.sync() functions, this module calls into npm-bundled directly.

FAQs

Last updated on 08 Sep 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc