Skip to content

Commit eb68f64

Browse files
authored
feat!: remove synchronous interface (#80)
BREAKING CHANGE: this module no longer supports synchronous usage
1 parent 82a2345 commit eb68f64

78 files changed

Lines changed: 62 additions & 470 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/index.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
const packlist = require('../')
23

34
const dirs = []
45
let doSort = false
@@ -15,12 +16,22 @@ process.argv.slice(2).forEach(arg => {
1516

1617
const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list
1718

18-
const packlist = require('../')
19-
if (!dirs.length) {
20-
console.log(sort(packlist.sync({ path: process.cwd() })).join('\n'))
21-
} else {
22-
dirs.forEach(path => {
23-
console.log(`> ${path}`)
24-
console.log(sort(packlist.sync({ path })).join('\n'))
25-
})
19+
const main = async () => {
20+
if (!dirs.length) {
21+
const results = await packlist({ path: process.cwd() })
22+
console.log(sort(results).join('\n'))
23+
} else {
24+
for (const dir of dirs) {
25+
console.group(`> ${dir}`)
26+
const results = await packlist({ path: dir })
27+
console.log(sort(results).join('\n'))
28+
console.groupEnd()
29+
}
30+
}
2631
}
32+
33+
// coverage disabled for catch handler because we don't need to test that
34+
main().catch(/* istanbul ignore next */(err) => {
35+
process.exitCode = 1
36+
console.error(err.stack)
37+
})

lib/index.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
const bundleWalk = require('npm-bundled')
99
const BundleWalker = bundleWalk.BundleWalker
10-
const BundleWalkerSync = bundleWalk.BundleWalkerSync
1110

1211
const ignoreWalk = require('ignore-walk')
1312
const IgnoreWalker = ignoreWalk.Walker
14-
const IgnoreWalkerSync = ignoreWalk.WalkerSync
1513

1614
const rootBuiltinRules = Symbol('root-builtin-rules')
1715
const packageNecessaryRules = Symbol('package-necessary-rules')
@@ -418,26 +416,6 @@ class Walker extends npmWalker(IgnoreWalker) {
418416
}
419417
}
420418

421-
class WalkerSync extends npmWalker(IgnoreWalkerSync) {
422-
globFiles (pattern, cb) {
423-
cb(null, glob.sync(pattern, { dot: true, cwd: this.path, nocase: true }))
424-
}
425-
426-
readPackageJson (entries) {
427-
const p = this.path + '/package.json'
428-
try {
429-
this.onReadPackageJson(entries, null, fs.readFileSync(p))
430-
} catch (er) {
431-
this.onReadPackageJson(entries, er)
432-
}
433-
}
434-
435-
walker (entry, opt, then) {
436-
new WalkerSync(this.walkerOpt(entry, opt)).start()
437-
then()
438-
}
439-
}
440-
441419
const walk = (options, callback) => {
442420
options = options || {}
443421
const p = new Promise((resolve, reject) => {
@@ -452,16 +430,6 @@ const walk = (options, callback) => {
452430
return callback ? p.then(res => callback(null, res), callback) : p
453431
}
454432

455-
const walkSync = options => {
456-
options = options || {}
457-
const bw = new BundleWalkerSync(options).start()
458-
options.bundled = bw.result
459-
options.packageJsonCache = bw.packageJsonCache
460-
const walker = new WalkerSync(options)
461-
walker.start()
462-
return walker.result
463-
}
464-
465433
// optimize for compressibility
466434
// extname, then basename, then locale alphabetically
467435
// https://twitter.com/isntitvacant/status/1131094910923231232
@@ -477,6 +445,4 @@ const sort = (a, b) => {
477445
}
478446

479447
module.exports = walk
480-
walk.sync = walkSync
481448
walk.Walker = Walker
482-
walk.WalkerSync = WalkerSync

map.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = () => ['bin/index.js', 'lib/index.js']

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@
4646
"tap": {
4747
"test-env": [
4848
"LC_ALL=sk"
49-
],
50-
"check-coverage": true,
51-
"nyc-arg": [
52-
"--include=index.js",
53-
"--include=bin/index.js"
5449
]
5550
},
5651
"bin": {
@@ -59,6 +54,9 @@
5954
"engines": {
6055
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
6156
},
57+
"tap": {
58+
"coverage-map": "map.js"
59+
},
6260
"templateOSS": {
6361
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
6462
"version": "3.2.0"

tap-snapshots/test/bin.js.test.cjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ Object {
5959
"stderr": "",
6060
"stdout": String(
6161
> .
62-
lib/cat.js
63-
lib/chai.js
64-
lib/dog.js
65-
index.js
66-
lib/index.js
67-
package.json
68-
README.md
69-
LICENSE.txt
62+
lib/cat.js
63+
lib/chai.js
64+
lib/dog.js
65+
index.js
66+
lib/index.js
67+
package.json
68+
README.md
69+
LICENSE.txt
7070
7171
),
7272
}

tap-snapshots/test/bundled-files.js.test.cjs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ Array [
1414
]
1515
`
1616

17-
exports[`test/bundled-files.js TAP includes bundled dependency using bundleDependencies sync > must match snapshot 1`] = `
18-
Array [
19-
"elf.js",
20-
"node_modules/history/index.js",
21-
"node_modules/history/package.json",
22-
"package.json",
23-
]
24-
`
25-
2617
exports[`test/bundled-files.js TAP includes bundled dependency using bundledDependencies async > must match snapshot 1`] = `
2718
Array [
2819
"elf.js",
@@ -31,12 +22,3 @@ Array [
3122
"package.json",
3223
]
3324
`
34-
35-
exports[`test/bundled-files.js TAP includes bundled dependency using bundledDependencies sync > must match snapshot 1`] = `
36-
Array [
37-
"elf.js",
38-
"node_modules/history/index.js",
39-
"node_modules/history/package.json",
40-
"package.json",
41-
]
42-
`

tap-snapshots/test/bundled-scoped-symlink.js.test.cjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,3 @@ Array [
1313
"package.json",
1414
]
1515
`
16-
17-
exports[`test/bundled-scoped-symlink.js TAP includes bundled dependency sync > must match snapshot 1`] = `
18-
Array [
19-
"elf.js",
20-
"node_modules/@npmwombat/history/index.js",
21-
"node_modules/@npmwombat/history/package.json",
22-
"package.json",
23-
]
24-
`

tap-snapshots/test/bundled-scoped.js.test.cjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,3 @@ Array [
1313
"package.json",
1414
]
1515
`
16-
17-
exports[`test/bundled-scoped.js TAP includes bundled dependency sync > must match snapshot 1`] = `
18-
Array [
19-
"elf.js",
20-
"node_modules/@npmwombat/history/index.js",
21-
"node_modules/@npmwombat/history/package.json",
22-
"package.json",
23-
]
24-
`

tap-snapshots/test/bundled-symlink.js.test.cjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,3 @@ Array [
1313
"package.json",
1414
]
1515
`
16-
17-
exports[`test/bundled-symlink.js TAP includes bundled dependency sync > must match snapshot 1`] = `
18-
Array [
19-
"elf.js",
20-
"node_modules/history/index.js",
21-
"node_modules/history/package.json",
22-
"package.json",
23-
]
24-
`

tap-snapshots/test/bundled.js.test.cjs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ Array [
1414
]
1515
`
1616

17-
exports[`test/bundled.js TAP includes bundled dependency using bundleDependencies sync > must match snapshot 1`] = `
18-
Array [
19-
"elf.js",
20-
"node_modules/history/index.js",
21-
"node_modules/history/package.json",
22-
"package.json",
23-
]
24-
`
25-
2617
exports[`test/bundled.js TAP includes bundled dependency using bundledDependencies async > must match snapshot 1`] = `
2718
Array [
2819
"elf.js",
@@ -31,12 +22,3 @@ Array [
3122
"package.json",
3223
]
3324
`
34-
35-
exports[`test/bundled.js TAP includes bundled dependency using bundledDependencies sync > must match snapshot 1`] = `
36-
Array [
37-
"elf.js",
38-
"node_modules/history/index.js",
39-
"node_modules/history/package.json",
40-
"package.json",
41-
]
42-
`

0 commit comments

Comments
 (0)