Socket
Socket
Sign inDemoInstall

npm-packlist

Package Overview
Dependencies
7
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.1.0

133

index.js
'use strict'
// Do a two-pass walk, first to get the list of packages that need to be
// bundled, then again to get the actual files and folders.
// Keep a cache of node_modules content and package.json data, so that the
// second walk doesn't have to re-do all the same work.
const bundleWalk = require('npm-bundled')
const BundleWalker = bundleWalk.BundleWalker
const BundleWalkerSync = bundleWalk.BundleWalkerSync
const ignoreWalk = require('ignore-walk')

@@ -10,2 +20,23 @@ const IgnoreWalker = ignoreWalk.Walker

const defaultRules = [
'.npmignore',
'.gitignore',
'/node_modules/**',
'/node_modules/.bin/**',
'**/.git/',
'**/.svn/',
'**/.hg/',
'**/CVS/',
'/.lock-wscript',
'/.wafpickle-*',
'/build/config.gypi',
'npm-debug.log',
'**/.npmrc',
'.*.swp',
'.DS_Store',
'._*',
'.*.orig',
'/test{,s}/'
]
// a decorator that applies our custom rules to an ignore walker

@@ -34,25 +65,9 @@ const npmWalker = Class => class Walker extends Class {

this.bundled = opt.bundled || []
const rules = [
'**/.npmignore',
'**/.gitignore',
'/node_modules/',
'/node_modules/.bin',
'**/.git/',
'**/.svn/',
'**/.hg/',
'**/CVS/',
'/.lock-wscript',
'/.wafpickle-*',
'/build/config.gypi',
'npm-debug.log',
'**/.npmrc',
'.*.swp',
'.DS_Store',
'._*',
'.*.orig',
'/test{,s}/'
].concat(this.bundled.map(dep => '!/node_modules/' + dep))
.join('\n') + '\n'
const bundleRules = this.bundled.map(
dep => '!/node_modules/' + dep + '/**')
const rules = defaultRules.concat(bundleRules).join('\n') + '\n'
this.packageJsonCache = opt.packageJsonCache || new Map()
super.onReadIgnoreFile(rootBuiltinRules, rules, _=>_)
}
} else
this.packageJsonCache = this.parent.packageJsonCache
}

@@ -69,28 +84,40 @@

addIgnoreFile (file, then) {
const ig = path.resolve(this.path, file)
if (this.packageJsonCache.has(ig))
this.onPackageJson(ig, this.packageJsonCache.get(ig), then)
else
super.addIgnoreFile(file, then)
}
onPackageJson (ig, pkg, then) {
this.packageJsonCache.set(ig, pkg)
// if there's a browser or main, make sure we don't ignore it
const rules = [
pkg.browser ? '!' + pkg.browser : '',
pkg.main ? '!' + pkg.main : '',
'!package.json',
'!@(readme|license|licence|notice|changes|changelog|history){,.*}'
].filter(f => f).join('\n') + '\n'
super.onReadIgnoreFile(packageNecessaryRules, rules, _=>_)
if (Array.isArray(pkg.files) && pkg.files.length)
super.onReadIgnoreFile('package.json', '*\n' + pkg.files.map(
f => '!' + f + '\n!' + f.replace(/\/+$/, '') + '/**'
).join('\n') + '\n', then)
else
then()
}
onReadIgnoreFile (file, data, then) {
if (file === 'package.json') {
if (file === 'package.json')
try {
const pkg = JSON.parse(data)
// if there's a browser or main, make sure we don't ignore it
const rules = [
pkg.browser ? '!' + pkg.browser : '',
pkg.main ? '!' + pkg.main : '',
'!package.json',
'!@(readme|license|licence|notice|changes|changelog|history){,.*}'
].filter(f => f).join('\n') + '\n'
super.onReadIgnoreFile(packageNecessaryRules, rules, _=>_)
if (!Array.isArray(pkg.files) || !pkg.files.length)
return then()
else
data = '*\n' + pkg.files.map(
f => '!' + f + '\n!' + f.replace(/\/+$/, '') + '/**'
).join('\n') + '\n'
this.onPackageJson(file, JSON.parse(data), then)
} catch (er) {
// ignore package.json files that are not json
return then()
then()
}
}
return super.onReadIgnoreFile(file, data, then)
else
super.onReadIgnoreFile(file, data, then)
}

@@ -116,4 +143,10 @@

const walk = (options, callback) => {
options = options || {}
const p = new Promise((resolve, reject) => {
new Walker(options).on('done', resolve).on('error', reject).start()
const bw = new BundleWalker(options).start()
bw.on('done', bundled => {
options.bundled = bundled
options.packageJsonCache = bw.packageJsonCache
new Walker(options).on('done', resolve).on('error', reject).start()
})
})

@@ -124,3 +157,9 @@ return callback ? p.then(res => callback(null, res), callback) : p

const walkSync = options => {
return new WalkerSync(options).start().result
options = options || {}
const bw = new BundleWalkerSync(options).start()
options.bundled = bw.result
options.packageJsonCache = bw.packageJsonCache
const walker = new WalkerSync(options)
walker.start()
return walker.result
}

@@ -132,4 +171,4 @@

: b === 'package.json' ? 1
: /^node_modules/.test(a) ? 1
: /^node_modules/.test(b) ? -1
: /^node_modules/.test(a) && !/^node_modules/.test(b) ? 1
: /^node_modules/.test(b) && !/^node_modules/.test(a) ? -1
: path.dirname(a) === '.' && path.dirname(b) !== '.' ? -1

@@ -136,0 +175,0 @@ : path.dirname(b) === '.' && path.dirname(a) !== '.' ? 1

{
"name": "npm-packlist",
"version": "1.0.1",
"version": "1.1.0",
"main": "index.js",
"dependencies": {
"ignore-walk": "^2.0.2"
"ignore-walk": "^2.0.2",
"npm-bundled": "^1.0.1"
},

@@ -8,0 +9,0 @@ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",

@@ -9,3 +9,3 @@ # npm-packlist

```js
const pack = require('npm-packlist')
const packlist = require('npm-packlist')
const tar = require('tar')

@@ -15,3 +15,3 @@ const packageDir = '/path/to/package'

pack({ path: packageDir })
packlist({ path: packageDir })
.then(files => tar.create({

@@ -21,10 +21,3 @@ prefix: 'package/',

file: packageTarball,
gzip: true,
bundled: [
'some',
'deps',
'that-are',
'bundled-dependencies-in-node_modules',
'this-is-optional-of-course'
]
gzip: true
}, files))

@@ -51,4 +44,3 @@ .then(_ => {

symbolic link, then the target of the link is included, not the
symlink itself. (The `bundled` option determines which packages
are to be considered bundled deps.)
symlink itself.
4. Unless they're explicitly included (by being in a `files` list, or

@@ -74,3 +66,7 @@ a `!negated` rule in a relevant `.npmignore` or `.gitignore`),

Same API as [ignore-walk](http://npm.im/ignore-walk), just hard-coded
file list and rule sets, and takes the `bundled` list of package names
to include.
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.
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