diff --git a/README.md b/README.md index 9512d8c..49eec85 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,24 @@ These can be handed to [tar](http://npm.im/tar) like so to make an npm package tarball: ```js +const Arborist = require('@npmcli/arborist') 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 +const arborist = new Arborist({ path: packageDir }) +arborist.loadActual().then((tree) => { + packlist({ path: packageDir, tree }) + .then(files => tar.create({ + prefix: 'package/', + cwd: packageDir, + file: packageTarball, + gzip: true + }, files)) + .then(_ => { + // tarball has been created, continue with your day + }) }) ``` @@ -97,7 +101,6 @@ Any specific file matched by an exact filename in the package.json `files` list ## API -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. diff --git a/lib/index.js b/lib/index.js index bcd0a9b..538873f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,5 @@ 'use strict' -const Arborist = require('@npmcli/arborist') const { Walker: IgnoreWalker } = require('ignore-walk') const { lstatSync: lstat, readFileSync: readFile } = require('fs') const { basename, dirname, extname, join, relative, resolve, sep } = require('path') @@ -104,7 +103,7 @@ class PackWalker extends IgnoreWalker { super(options) this.isPackage = options.isPackage this.seen = options.seen || new Set() - this.tree = options.tree // no default, we'll load the tree later if we need to + this.tree = options.tree this.requiredFiles = options.requiredFiles || [] const additionalDefaults = [] @@ -202,22 +201,6 @@ class PackWalker extends IgnoreWalker { return super.stat(opts, callback) } - // 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 // in to a normal child directory (this will never be a bundle). the default method here // copies the root's `ignoreFiles` value, but we don't want to respect package.json for diff --git a/package.json b/package.json index 2f3200a..9c92d42 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ }, "main": "lib/index.js", "dependencies": { - "@npmcli/arborist": "^5.0.4 || ^6.0.0 || ^6.0.0-pre.0", "ignore-walk": "^5.0.1" }, "author": "GitHub Inc.", @@ -17,6 +16,7 @@ "lib/" ], "devDependencies": { + "@npmcli/arborist": "^5.0.4 || ^6.0.0 || ^6.0.0-pre.0", "@npmcli/eslint-config": "^3.0.1", "@npmcli/template-oss": "4.4.2", "mutate-fs": "^2.1.1", @@ -45,10 +45,8 @@ "nyc-arg": [ "--exclude", "tap-snapshots/**" - ] - }, - "bin": { - "npm-packlist": "bin/index.js" + ], + "files": ["test/*.js"] }, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" diff --git a/test/bin.js b/test/bin.js index 25bd991..b085b77 100644 --- a/test/bin.js +++ b/test/bin.js @@ -6,7 +6,7 @@ const t = require('tap') const { spawnSync } = require('child_process') const nodePath = process.execPath -const binPath = require.resolve('../bin/index.js') +const binPath = require.resolve('./utils/bin.js') const cwd = t.testdir({ 'package.json': JSON.stringify({ diff --git a/test/bundle-missing-dep.js b/test/bundle-missing-dep.js index 7cc9e1e..21888cc 100644 --- a/test/bundle-missing-dep.js +++ b/test/bundle-missing-dep.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -24,8 +25,10 @@ t.test('skips bundling deps with missing edges', async (t) => { }, }, }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() - const files = await packlist({ path: pkg }) + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'index.js', 'package.json', diff --git a/test/bundled-cycle.js b/test/bundled-cycle.js index f8eb4a9..dd2ba66 100644 --- a/test/bundled-cycle.js +++ b/test/bundled-cycle.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -41,7 +42,9 @@ t.test('correctly bundles cyclic deps', async (t) => { }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'index.js', 'node_modules/a/index.js', diff --git a/test/bundled-file-in-workspace.js b/test/bundled-file-in-workspace.js index 695eb26..0fde3c4 100644 --- a/test/bundled-file-in-workspace.js +++ b/test/bundled-file-in-workspace.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -29,7 +30,9 @@ t.test('correctly filters files from workspace subdirectory', async (t) => { }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'index.js', 'package.json', @@ -76,7 +79,9 @@ t.test('does not filter based on package.json if subdirectory is not a workspace }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'index.js', 'package.json', diff --git a/test/bundled-files.js b/test/bundled-files.js index 9fb6110..a0fe15c 100644 --- a/test/bundled-files.js +++ b/test/bundled-files.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -36,7 +37,9 @@ t.test('includes bundled dependency using bundleDependencies', async (t) => { }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'node_modules/history/index.js', @@ -73,7 +76,9 @@ t.test('includes bundled dependency using bundledDependencies', async (t) => { }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'node_modules/history/index.js', diff --git a/test/bundled-scoped-symlink.js b/test/bundled-scoped-symlink.js index 55675e5..2d58cb6 100644 --- a/test/bundled-scoped-symlink.js +++ b/test/bundled-scoped-symlink.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('..') @@ -51,7 +52,9 @@ const pkg = t.testdir({ }) + '/pkg' t.test('includes bundled dependency', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'node_modules/@npmwombat/history/index.js', diff --git a/test/bundled-scoped.js b/test/bundled-scoped.js index 7942758..2a02da0 100644 --- a/test/bundled-scoped.js +++ b/test/bundled-scoped.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -37,7 +38,9 @@ const pkg = t.testdir({ }) t.test('includes bundled dependency', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'node_modules/@npmwombat/history/index.js', diff --git a/test/bundled-symlink.js b/test/bundled-symlink.js index fc0cfd4..eb7fcbc 100644 --- a/test/bundled-symlink.js +++ b/test/bundled-symlink.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -49,7 +50,9 @@ const pkg = t.testdir({ }) + '/pkg' t.test('includes bundled dependency', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'node_modules/history/index.js', diff --git a/test/bundled-workspace.js b/test/bundled-workspace.js index bd2cd5a..905f67d 100644 --- a/test/bundled-workspace.js +++ b/test/bundled-workspace.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -42,7 +43,9 @@ t.test('packs workspace dependencies correctly', async (t) => { }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'index.js', 'node_modules/bar/index.js', diff --git a/test/bundled.js b/test/bundled.js index 6c78e35..18c34f8 100644 --- a/test/bundled.js +++ b/test/bundled.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -35,7 +36,9 @@ t.test('includes bundled dependency using bundleDependencies', async (t) => { }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'node_modules/history/index.js', @@ -71,7 +74,9 @@ t.test('includes bundled dependency using bundledDependencies', async (t) => { }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'node_modules/history/index.js', diff --git a/test/callbacks.js b/test/callbacks.js index 558530e..f1fa23d 100644 --- a/test/callbacks.js +++ b/test/callbacks.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -9,15 +10,20 @@ const pkg = t.testdir({ }), }) -t.test('export supports callbacks', (t) => { - packlist({ path: pkg }, (err, files) => { - if (err) { - throw err - } +t.test('export supports callbacks', async (t) => { + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() - t.same(files, [ - 'package.json', - ]) - t.end() + return new Promise((resolve, reject) => { + packlist({ path: pkg, tree }, (err, files) => { + if (err) { + reject(err) + } + + t.same(files, [ + 'package.json', + ]) + resolve(files) + }) }) }) diff --git a/test/cannot-exclude-package-json.js b/test/cannot-exclude-package-json.js index aeadbc6..0955e01 100644 --- a/test/cannot-exclude-package-json.js +++ b/test/cannot-exclude-package-json.js @@ -1,6 +1,7 @@ // cannot exclude package.json in the root 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -12,7 +13,9 @@ const pkg = t.testdir({ }) t.test('try to exclude package.json but cannot', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ '.npmignore', 'package.json', diff --git a/test/cannot-exclude-readme.js b/test/cannot-exclude-readme.js index e752c84..8fef82a 100644 --- a/test/cannot-exclude-readme.js +++ b/test/cannot-exclude-readme.js @@ -1,6 +1,7 @@ // cannot exclude readme.md in the root 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -18,7 +19,9 @@ const pkg = t.testdir({ }) t.test('try to exclude package.json but cannot', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ '.npmignore', 'package.json', diff --git a/test/cannot-exclude-shrinkwrap.js b/test/cannot-exclude-shrinkwrap.js index 3082998..1b3fb13 100644 --- a/test/cannot-exclude-shrinkwrap.js +++ b/test/cannot-exclude-shrinkwrap.js @@ -1,6 +1,7 @@ // cannot exclude npm-shrinkwrap.json in the root 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -13,7 +14,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ '.npmignore', 'npm-shrinkwrap.json', diff --git a/test/cannot-include-non-file-or-directory.js b/test/cannot-include-non-file-or-directory.js index fbfb071..d1c5bcd 100644 --- a/test/cannot-include-non-file-or-directory.js +++ b/test/cannot-include-non-file-or-directory.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const fs = require('fs') const t = require('tap') const { join } = require('path') @@ -54,7 +55,9 @@ t.test('cannot include something that exists but is neither a file nor a directo }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'index.js', 'package.json', diff --git a/test/cannot-include-package-lock.js b/test/cannot-include-package-lock.js index 597732b..0072883 100644 --- a/test/cannot-include-package-lock.js +++ b/test/cannot-include-package-lock.js @@ -1,6 +1,7 @@ // cannot include package-lock.json in the root 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -15,7 +16,9 @@ const pkg = t.testdir({ }) t.test('try to include package-lock.json but cannot', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ '.npmignore', 'package.json', diff --git a/test/constructor.js b/test/constructor.js index 07cdca3..2a94ab7 100644 --- a/test/constructor.js +++ b/test/constructor.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -15,7 +16,9 @@ t.test('Walker constructor allows ommitting options entirely', async (t) => { t.teardown(() => process.cwd = cwd) process.cwd = () => pkg - const walker = new packlist.Walker() + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const walker = new packlist.Walker({ tree }) const files = await new Promise((resolve, reject) => { walker .on('done', resolve) diff --git a/test/cwd.js b/test/cwd.js index ee8f212..7c9f87a 100644 --- a/test/cwd.js +++ b/test/cwd.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -44,7 +45,9 @@ t.test('follows npm package ignoring rules', async (t) => { t.teardown(() => process.chdir(cwd)) process.chdir(pkg) - const files = await packlist() + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ tree }) t.same(files, [ 'deps/foo/config/config.gypi', 'elf.js', diff --git a/test/empty-npmignore.js b/test/empty-npmignore.js index 17cd2ab..a41c92b 100644 --- a/test/empty-npmignore.js +++ b/test/empty-npmignore.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -47,7 +48,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'deps/foo/config/config.gypi', 'elf.js', diff --git a/test/ignore-file-included-by-globstar.js b/test/ignore-file-included-by-globstar.js index 0e12b4c..eac6bf4 100644 --- a/test/ignore-file-included-by-globstar.js +++ b/test/ignore-file-included-by-globstar.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -21,7 +22,9 @@ t.test('include a globstar, then exclude one of them', async (t) => { }), }) - const files = await packlist({ path }) + const arborist = new Arborist({ path }) + const tree = await arborist.loadActual() + const files = await packlist({ path, tree }) t.same(files, [ 'bar.js', 'bar/bar.js', diff --git a/test/ignores.js b/test/ignores.js index 81d4b2a..847b44c 100644 --- a/test/ignores.js +++ b/test/ignores.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -80,7 +81,9 @@ readme.md }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'core', 'deps/foo/config/config.gypi', diff --git a/test/include-gitignore.js b/test/include-gitignore.js index 585bd59..47ccae3 100644 --- a/test/include-gitignore.js +++ b/test/include-gitignore.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -44,7 +45,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'z/.gitignore', 'deps/foo/config/config.gypi', diff --git a/test/nested-lock-and-core.js b/test/nested-lock-and-core.js index ec19d03..90b1240 100644 --- a/test/nested-lock-and-core.js +++ b/test/nested-lock-and-core.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -33,7 +34,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/core', 'lib/package-lock.json', diff --git a/test/package-json-bin-multiple.js b/test/package-json-bin-multiple.js index 82f672b..52d1006 100644 --- a/test/package-json-bin-multiple.js +++ b/test/package-json-bin-multiple.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -34,7 +35,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ '__bin_bar', '__bin_foo', diff --git a/test/package-json-bin-single.js b/test/package-json-bin-single.js index ec0f750..7653a55 100644 --- a/test/package-json-bin-single.js +++ b/test/package-json-bin-single.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -30,7 +31,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ '__bin', 'lib/elf.js', diff --git a/test/package-json-empty.js b/test/package-json-empty.js index 8c5049b..17dd51c 100644 --- a/test/package-json-empty.js +++ b/test/package-json-empty.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -44,7 +45,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'elf.js', 'package.json', diff --git a/test/package-json-filed-dir-nested-npmignore.js b/test/package-json-filed-dir-nested-npmignore.js index 0e1c012..a4a0686 100644 --- a/test/package-json-filed-dir-nested-npmignore.js +++ b/test/package-json-filed-dir-nested-npmignore.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -20,7 +21,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/for.js', 'lib/one.js', diff --git a/test/package-json-files-and-containing-dir.js b/test/package-json-files-and-containing-dir.js index 60ba99e..22e460d 100644 --- a/test/package-json-files-and-containing-dir.js +++ b/test/package-json-files-and-containing-dir.js @@ -2,6 +2,7 @@ // in ways that will have them included from multiple directions 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -27,7 +28,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/for.js', 'lib/one.js', diff --git a/test/package-json-files-dir-and-nested-ignore.js b/test/package-json-files-dir-and-nested-ignore.js index f1a4ebc..fe568c6 100644 --- a/test/package-json-files-dir-and-nested-ignore.js +++ b/test/package-json-files-dir-and-nested-ignore.js @@ -2,6 +2,7 @@ // 'files' array matches a dir, but not any specific files. 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -22,7 +23,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/for.js', 'lib/one.js', diff --git a/test/package-json-files-including-npmignore.js b/test/package-json-files-including-npmignore.js index fc00a67..d058a5d 100644 --- a/test/package-json-files-including-npmignore.js +++ b/test/package-json-files-including-npmignore.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -23,7 +24,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/.npmignore', 'lib/sub/for.js', diff --git a/test/package-json-files-nested-dir-and-nested-ignore.js b/test/package-json-files-nested-dir-and-nested-ignore.js index 357b1e5..98cb899 100644 --- a/test/package-json-files-nested-dir-and-nested-ignore.js +++ b/test/package-json-files-nested-dir-and-nested-ignore.js @@ -2,6 +2,7 @@ // 'files' array matches a dir that passes by it. 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -24,7 +25,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/dir/for.js', 'lib/dir/one.js', diff --git a/test/package-json-files-no-dir-nested-npmignore.js b/test/package-json-files-no-dir-nested-npmignore.js index 2dd50a8..bdb3158 100644 --- a/test/package-json-files-no-dir-nested-npmignore.js +++ b/test/package-json-files-no-dir-nested-npmignore.js @@ -1,3 +1,6 @@ +'use strict' + +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -18,7 +21,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/for.js', 'lib/one.js', diff --git a/test/package-json-files-with-slashes.js b/test/package-json-files-with-slashes.js index 612d953..146eb1d 100644 --- a/test/package-json-files-with-slashes.js +++ b/test/package-json-files-with-slashes.js @@ -4,6 +4,7 @@ // list as a file path, it will be included no matter what. 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -27,7 +28,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/for.js', 'lib/one.js', diff --git a/test/package-json-main.js b/test/package-json-main.js index 4284b6a..674d8d1 100644 --- a/test/package-json-main.js +++ b/test/package-json-main.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -49,7 +50,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'deps/foo/config/config.gypi', '__main.js', diff --git a/test/package-json-negated-files.js b/test/package-json-negated-files.js index 8f7ee4c..578e4da 100644 --- a/test/package-json-negated-files.js +++ b/test/package-json-negated-files.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -21,7 +22,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/for', 'lib/tre', diff --git a/test/package-json-nested-readme-include-npmignore.js b/test/package-json-nested-readme-include-npmignore.js index c06ab85..77b57ff 100644 --- a/test/package-json-nested-readme-include-npmignore.js +++ b/test/package-json-nested-readme-include-npmignore.js @@ -1,6 +1,7 @@ // include readme.* files anywhere in a package 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -51,7 +52,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/a/a.js', 'lib/a/b/b.js', diff --git a/test/package-json-nested-readme.js b/test/package-json-nested-readme.js index ef7499d..0013f10 100644 --- a/test/package-json-nested-readme.js +++ b/test/package-json-nested-readme.js @@ -1,6 +1,7 @@ // include readme.* files anywhere in a package 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -48,7 +49,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'lib/a/a.js', 'lib/a/b/b.js', diff --git a/test/package-json-nested.js b/test/package-json-nested.js index 02bd25d..792b1a2 100644 --- a/test/package-json-nested.js +++ b/test/package-json-nested.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -20,7 +21,9 @@ const pkg = t.testdir({ }) t.test('includes nested package.json file', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'nest/foo.js', 'nest/index.js', diff --git a/test/package-json-roots-and-nests.js b/test/package-json-roots-and-nests.js index c803393..b31b566 100644 --- a/test/package-json-roots-and-nests.js +++ b/test/package-json-roots-and-nests.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -56,7 +57,9 @@ const pkg = t.testdir({ }) t.test('package with negated files', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'node_modules/@foo/bar/.DS_Store', 'inc/foo', diff --git a/test/package-json.js b/test/package-json.js index 9219a1d..abb8b47 100644 --- a/test/package-json.js +++ b/test/package-json.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -45,7 +46,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'deps/foo/config/config.gypi', 'elf.js', diff --git a/test/package-not-json.js b/test/package-not-json.js index 368148e..6154bdd 100644 --- a/test/package-not-json.js +++ b/test/package-not-json.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -36,7 +37,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'deps/foo/config/config.gypi', 'elf.js', diff --git a/test/scoped.js b/test/scoped.js index efce01d..2c105af 100644 --- a/test/scoped.js +++ b/test/scoped.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -39,7 +40,9 @@ const pkg = t.testdir({ }) t.test('includes bundledDependencies', async (t) => { - const files = await packlist({ path: pkg, bundled: ['@npmwombat/scoped'] }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, bundled: ['@npmwombat/scoped'], tree }) t.same(files, [ 'elf.js', 'node_modules/@npmwombat/scoped/index.js', diff --git a/test/star-names.js b/test/star-names.js index 7e38fd6..fe51b53 100644 --- a/test/star-names.js +++ b/test/star-names.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const fs = require('fs') @@ -65,7 +66,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'deps/foo/config/config.gypi', 'elf.js', diff --git a/test/strip-slash-from-package-files-list-entries.js b/test/strip-slash-from-package-files-list-entries.js index cc319b6..849c3f2 100644 --- a/test/strip-slash-from-package-files-list-entries.js +++ b/test/strip-slash-from-package-files-list-entries.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -48,7 +49,9 @@ t.test('should strip / from package.json files array entry results', async (t) = }, }) - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'dist/bar', 'dist/baz/boo', diff --git a/test/symlink.js b/test/symlink.js index 52c320b..e1e42f2 100644 --- a/test/symlink.js +++ b/test/symlink.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const t = require('tap') const packlist = require('../') @@ -64,7 +65,9 @@ const pkg = t.testdir({ }) t.test('follows npm package ignoring rules', async (t) => { - const files = await packlist({ path: pkg }) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const files = await packlist({ path: pkg, tree }) t.same(files, [ 'test/resolver/multirepo/packages/a/README', 'deps/foo/config/config.gypi', diff --git a/bin/index.js b/test/utils/bin.js similarity index 67% rename from bin/index.js rename to test/utils/bin.js index 48a6b87..3474dea 100755 --- a/bin/index.js +++ b/test/utils/bin.js @@ -1,7 +1,8 @@ #!/usr/bin/env node 'use strict' -const packlist = require('../') +const Arborist = require('@npmcli/arborist') +const packlist = require('../../') const dirs = [] let doSort = false @@ -20,12 +21,17 @@ const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : li const main = async () => { if (!dirs.length) { - const results = await packlist({ path: process.cwd() }) + const path = process.cwd() + const arborist = new Arborist({ path }) + const tree = await arborist.loadActual() + const results = await packlist({ path, tree }) console.log(sort(results).join('\n')) } else { for (const dir of dirs) { + const arborist = new Arborist({ path: dir }) + const tree = await arborist.loadActual() console.group(`> ${dir}`) - const results = await packlist({ path: dir }) + const results = await packlist({ path: dir, tree }) console.log(sort(results).join('\n')) console.groupEnd() } diff --git a/test/workspace.js b/test/workspace.js index ed0f449..e92cff0 100644 --- a/test/workspace.js +++ b/test/workspace.js @@ -1,5 +1,6 @@ 'use strict' +const Arborist = require('@npmcli/arborist') const path = require('path') const t = require('tap') @@ -34,11 +35,14 @@ t.test('respects workspace root ignore files', async (t) => { }) const workspacePath = path.join(root, 'workspaces', 'foo') + const arborist = new Arborist({ path: workspacePath }) + const tree = await arborist.loadActual() // this simulates what it looks like when a user does i.e. npm pack -w ./workspaces/foo const files = await packlist({ path: workspacePath, prefix: root, workspaces: [workspacePath], + tree, }) t.same(files, [ 'child.js', @@ -50,6 +54,7 @@ t.test('respects workspace root ignore files', async (t) => { const secondFiles = await packlist({ path: workspacePath, prefix: root, + tree, }) t.same(secondFiles, [ 'ignore-me', @@ -89,10 +94,13 @@ t.test('packing a workspace root does not include children', async (t) => { const workspacePath = path.join(root, 'workspaces', 'foo') // this simulates what it looks like when a user does `npm pack` from a workspace root + const arborist = new Arborist({ path: root }) + const tree = await arborist.loadActual() const files = await packlist({ path: root, prefix: root, workspaces: [workspacePath], + tree, }) t.same(files, [ 'root.js', @@ -103,6 +111,7 @@ t.test('packing a workspace root does not include children', async (t) => { const secondFiles = await packlist({ path: root, prefix: root, + tree, }) t.same(secondFiles, [ 'workspaces/foo/child.js', @@ -149,10 +158,13 @@ t.test('.gitignore is discarded if .npmignore exists outside of tree', async (t) const workspacePath = path.join(root, 'workspaces', 'foo') // this simulates what it looks like when a user does i.e. npm pack -w ./workspaces/foo + const arborist = new Arborist({ path: workspacePath }) + const tree = await arborist.loadActual() const files = await packlist({ path: workspacePath, prefix: root, workspaces: [workspacePath], + tree, }) t.same(files, [ 'dont-ignore-me', @@ -165,6 +177,7 @@ t.test('.gitignore is discarded if .npmignore exists outside of tree', async (t) const secondFiles = await packlist({ path: workspacePath, prefix: root, + tree, }) t.same(secondFiles, [ 'dont-ignore-me',