npm-packlist
Advanced tools
Comparing version 6.0.1 to 7.0.0-pre.0
'use strict' | ||
const Arborist = require('@npmcli/arborist') | ||
const { Walker: IgnoreWalker } = require('ignore-walk') | ||
@@ -84,3 +83,3 @@ const { lstatSync: lstat, readFileSync: readFile } = require('fs') | ||
class PackWalker extends IgnoreWalker { | ||
constructor (opts) { | ||
constructor (tree, opts) { | ||
const options = { | ||
@@ -90,9 +89,5 @@ ...opts, | ||
follow: false, | ||
} | ||
// we path.resolve() here because ignore-walk doesn't do it and we want full paths | ||
options.path = resolve(options.path || process.cwd()).replace(/\\/g, '/') | ||
if (!options.ignoreFiles) { | ||
options.ignoreFiles = [ | ||
// we path.resolve() here because ignore-walk doesn't do it and we want full paths | ||
path: resolve(opts?.path || tree.path).replace(/\\/g, '/'), | ||
ignoreFiles: opts?.ignoreFiles || [ | ||
defaultRules, | ||
@@ -103,3 +98,3 @@ 'package.json', | ||
strictRules, | ||
] | ||
], | ||
} | ||
@@ -110,3 +105,3 @@ | ||
this.seen = options.seen || new Set() | ||
this.tree = options.tree // no default, we'll load the tree later if we need to | ||
this.tree = tree | ||
this.requiredFiles = options.requiredFiles || [] | ||
@@ -209,18 +204,2 @@ | ||
// overridden method: we need to load the arborist tree before we actually start running | ||
start () { | ||
if (this.isPackage && !this.tree) { | ||
const arborist = new Arborist({ path: this.path }) | ||
// loading the tree is async while the start function depends on being sync | ||
// eslint-disable-next-line promise/catch-or-return, promise/always-return | ||
arborist.loadActual().then((tree) => { | ||
this.tree = tree | ||
super.start() | ||
}) | ||
return this | ||
} | ||
return super.start() | ||
} | ||
// overridden method: this is called to create options for a child walker when we step | ||
@@ -231,12 +210,7 @@ // in to a normal child directory (this will never be a bundle). the default method here | ||
walkerOpt (entry, opts) { | ||
let ignoreFiles = [ | ||
defaultRules, | ||
'.npmignore', | ||
'.gitignore', | ||
strictRules, | ||
] | ||
let ignoreFiles = null | ||
// however, if we have a tree, and we have workspaces, and the directory we're about | ||
// to step into is a workspace, then we _do_ want to respect its package.json | ||
if (this.tree && this.tree.workspaces) { | ||
if (this.tree.workspaces) { | ||
const workspaceDirs = [...this.tree.workspaces.values()] | ||
@@ -255,2 +229,9 @@ .map((dir) => dir.replace(/\\/g, '/')) | ||
} | ||
} else { | ||
ignoreFiles = [ | ||
defaultRules, | ||
'.npmignore', | ||
'.gitignore', | ||
strictRules, | ||
] | ||
} | ||
@@ -275,3 +256,3 @@ | ||
walker (entry, opts, callback) { | ||
new PackWalker(this.walkerOpt(entry, opts)).on('done', callback).start() | ||
new PackWalker(this.tree, this.walkerOpt(entry, opts)).on('done', callback).start() | ||
} | ||
@@ -379,3 +360,3 @@ | ||
async gatherBundles () { | ||
if (this.tree && this.seen.has(this.tree)) { | ||
if (this.seen.has(this.tree)) { | ||
return | ||
@@ -409,10 +390,12 @@ } | ||
const node = this.tree.edgesOut.get(dep).to | ||
// we use node.path for the path because we want the location the node was linked to, | ||
// not where it actually lives on disk | ||
const path = node.path | ||
// but link nodes don't have edgesOut, so we need to pass in the target of the node | ||
// in order to make sure we correctly traverse its dependencies | ||
const tree = node.target | ||
// and start building options to be passed to the walker for this package | ||
const walkerOpts = { | ||
// we use node.path for the path because we want the location the node was linked to, | ||
// not where it actually lives on disk | ||
path: node.path, | ||
// but link nodes don't have edgesOut, so we need to pass in the target of the node | ||
// in order to make sure we correctly traverse its dependencies | ||
tree: node.target, | ||
path, | ||
isPackage: true, | ||
@@ -443,3 +426,3 @@ ignoreFiles: [], | ||
// create a walker for this dependency and gather its results | ||
const walker = new PackWalker(walkerOpts) | ||
const walker = new PackWalker(tree, walkerOpts) | ||
const bundled = await new Promise((pResolve, pReject) => { | ||
@@ -461,6 +444,10 @@ walker.on('error', pReject) | ||
const walk = (options, callback) => { | ||
options = { ...options, isPackage: true } | ||
const walk = (tree, options, callback) => { | ||
if (typeof options === 'function') { | ||
callback = options | ||
options = {} | ||
} | ||
const p = new Promise((pResolve, pReject) => { | ||
new PackWalker(options).on('done', pResolve).on('error', pReject).start() | ||
new PackWalker(tree, { ...options, isPackage: true }) | ||
.on('done', pResolve).on('error', pReject).start() | ||
}) | ||
@@ -467,0 +454,0 @@ return callback ? p.then(res => callback(null, res), callback) : p |
{ | ||
"name": "npm-packlist", | ||
"version": "6.0.1", | ||
"version": "7.0.0-pre.0", | ||
"description": "Get a list of the files to add from a folder into an npm package", | ||
@@ -10,3 +10,2 @@ "directories": { | ||
"dependencies": { | ||
"@npmcli/arborist": "^5.0.4 || ^6.0.0 || ^6.0.0-pre.0", | ||
"ignore-walk": "^5.0.1" | ||
@@ -21,2 +20,3 @@ }, | ||
"devDependencies": { | ||
"@npmcli/arborist": "^6.0.0 || ^6.0.0-pre.0", | ||
"@npmcli/eslint-config": "^3.0.1", | ||
@@ -50,7 +50,7 @@ "@npmcli/template-oss": "4.4.2", | ||
"tap-snapshots/**" | ||
], | ||
"files": [ | ||
"test/*.js" | ||
] | ||
}, | ||
"bin": { | ||
"npm-packlist": "bin/index.js" | ||
}, | ||
"engines": { | ||
@@ -57,0 +57,0 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" |
@@ -9,2 +9,3 @@ # npm-packlist | ||
```js | ||
const Arborist = require('@npmcli/arborist') | ||
const packlist = require('npm-packlist') | ||
@@ -15,11 +16,14 @@ const tar = require('tar') | ||
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 | ||
const arborist = new Arborist({ path: packageDir }) | ||
arborist.loadActual().then((tree) => { | ||
packlist(tree) | ||
.then(files => tar.create({ | ||
prefix: 'package/', | ||
cwd: packageDir, | ||
file: packageTarball, | ||
gzip: true | ||
}, files)) | ||
.then(_ => { | ||
// tarball has been created, continue with your day | ||
}) | ||
}) | ||
@@ -102,5 +106,4 @@ ``` | ||
Same API as [ignore-walk](http://npm.im/ignore-walk), just hard-coded | ||
file list and rule sets. | ||
Same API as [ignore-walk](http://npm.im/ignore-walk), except providing a `tree` is required and there are hard-coded file list and rule sets. | ||
The `Walker` class will load an [arborist](https://github.com/npm/cli/tree/latest/workspaces/arborist) tree, and if any bundled dependencies are found will include them as well as their own dependencies in the resulting file set. | ||
The `Walker` class requires an [arborist](https://github.com/npm/cli/tree/latest/workspaces/arborist) tree, and if any bundled dependencies are found will include them as well as their own dependencies in the resulting file set. |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
107
21754
5
4
390
1
- Removed@gar/promisify@1.1.3(transitive)
- Removed@isaacs/cliui@8.0.2(transitive)
- Removed@isaacs/string-locale-compare@1.1.0(transitive)
- Removed@npmcli/arborist@6.5.1(transitive)
- Removed@npmcli/fs@2.1.23.1.0(transitive)
- Removed@npmcli/git@4.1.0(transitive)
- Removed@npmcli/installed-package-contents@2.1.0(transitive)
- Removed@npmcli/map-workspaces@3.0.6(transitive)
- Removed@npmcli/metavuln-calculator@5.0.1(transitive)
- Removed@npmcli/move-file@2.0.1(transitive)
- Removed@npmcli/name-from-folder@2.0.0(transitive)
- Removed@npmcli/node-gyp@3.0.0(transitive)
- Removed@npmcli/package-json@4.0.1(transitive)
- Removed@npmcli/promise-spawn@6.0.2(transitive)
- Removed@npmcli/query@3.1.0(transitive)
- Removed@npmcli/run-script@6.0.2(transitive)
- Removed@pkgjs/parseargs@0.11.0(transitive)
- Removed@sigstore/bundle@1.1.0(transitive)
- Removed@sigstore/protobuf-specs@0.2.1(transitive)
- Removed@sigstore/sign@1.0.0(transitive)
- Removed@sigstore/tuf@1.0.3(transitive)
- Removed@tootallnate/once@2.0.0(transitive)
- Removed@tufjs/canonical-json@1.0.0(transitive)
- Removed@tufjs/models@1.0.4(transitive)
- Removedabbrev@1.1.12.0.0(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedagentkeepalive@4.5.0(transitive)
- Removedaggregate-error@3.1.0(transitive)
- Removedansi-regex@5.0.16.0.1(transitive)
- Removedansi-styles@4.3.06.2.1(transitive)
- Removedaproba@2.0.0(transitive)
- Removedare-we-there-yet@3.0.14.0.2(transitive)
- Removedbin-links@4.0.3(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuiltins@5.1.0(transitive)
- Removedcacache@16.1.317.1.4(transitive)
- Removedchownr@2.0.0(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedcmd-shim@6.0.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcommon-ancestor-path@1.0.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removedcssesc@3.0.0(transitive)
- Removeddebug@4.3.4(transitive)
- Removeddelegates@1.0.0(transitive)
- Removedeastasianwidth@0.2.0(transitive)
- Removedemoji-regex@8.0.09.2.2(transitive)
- Removedencoding@0.1.13(transitive)
- Removedenv-paths@2.2.1(transitive)
- Removederr-code@2.0.3(transitive)
- Removedexponential-backoff@3.1.1(transitive)
- Removedforeground-child@3.1.1(transitive)
- Removedfs-minipass@2.1.03.0.3(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgauge@4.0.45.0.1(transitive)
- Removedglob@10.3.127.2.38.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@6.1.1(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedhttp-proxy-agent@5.0.0(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removedhumanize-ms@1.2.1(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedignore-walk@6.0.4(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedinfer-owner@1.0.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedip-address@9.0.5(transitive)
- Removedis-core-module@2.13.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-lambda@1.0.1(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjackspeak@2.3.6(transitive)
- Removedjsbn@1.1.0(transitive)
- Removedjson-parse-even-better-errors@3.0.1(transitive)
- Removedjson-stringify-nice@1.1.4(transitive)
- Removedjsonparse@1.3.1(transitive)
- Removedjust-diff@6.0.2(transitive)
- Removedjust-diff-apply@5.5.0(transitive)
- Removedlru-cache@10.2.26.0.07.18.3(transitive)
- Removedmake-fetch-happen@10.2.111.1.1(transitive)
- Removedminimatch@3.1.29.0.4(transitive)
- Removedminipass@3.3.65.0.07.0.4(transitive)
- Removedminipass-collect@1.0.2(transitive)
- Removedminipass-fetch@2.1.23.0.4(transitive)
- Removedminipass-flush@1.0.5(transitive)
- Removedminipass-json-stream@1.0.1(transitive)
- Removedminipass-pipeline@1.2.4(transitive)
- Removedminipass-sized@1.0.3(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedms@2.1.2(transitive)
- Removednegotiator@0.6.3(transitive)
- Removednode-gyp@9.4.1(transitive)
- Removednopt@6.0.07.2.0(transitive)
- Removednormalize-package-data@5.0.0(transitive)
- Removednpm-bundled@3.0.0(transitive)
- Removednpm-install-checks@6.3.0(transitive)
- Removednpm-normalize-package-bin@3.0.1(transitive)
- Removednpm-package-arg@10.1.0(transitive)
- Removednpm-packlist@7.0.4(transitive)
- Removednpm-pick-manifest@8.0.2(transitive)
- Removednpm-registry-fetch@14.0.5(transitive)
- Removednpmlog@6.0.27.0.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-map@4.0.0(transitive)
- Removedpacote@15.2.0(transitive)
- Removedparse-conflict-json@3.0.1(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-scurry@1.10.2(transitive)
- Removedpostcss-selector-parser@6.0.16(transitive)
- Removedproc-log@3.0.0(transitive)
- Removedpromise-all-reject-late@1.0.1(transitive)
- Removedpromise-call-limit@1.0.2(transitive)
- Removedpromise-inflight@1.0.1(transitive)
- Removedpromise-retry@2.0.1(transitive)
- Removedread-cmd-shim@4.0.0(transitive)
- Removedread-package-json@6.0.4(transitive)
- Removedread-package-json-fast@3.0.2(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedretry@0.12.0(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsemver@7.6.0(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.74.1.0(transitive)
- Removedsigstore@1.9.0(transitive)
- Removedsmart-buffer@4.2.0(transitive)
- Removedsocks@2.8.3(transitive)
- Removedsocks-proxy-agent@7.0.0(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.17(transitive)
- Removedsprintf-js@1.1.3(transitive)
- Removedssri@10.0.59.0.1(transitive)
- Removedstring-width@4.2.35.1.2(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-ansi@6.0.17.1.0(transitive)
- Removedtar@6.2.1(transitive)
- Removedtreeverse@3.0.0(transitive)
- Removedtuf-js@1.1.7(transitive)
- Removedunique-filename@2.0.13.0.0(transitive)
- Removedunique-slug@3.0.04.0.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedvalidate-npm-package-name@5.0.0(transitive)
- Removedwalk-up-path@3.0.1(transitive)
- Removedwhich@2.0.23.0.1(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedwrap-ansi@7.0.08.1.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedwrite-file-atomic@5.0.1(transitive)
- Removedyallist@4.0.0(transitive)