Skip to content

Commit

Permalink
tools: Add dot option to ls
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Jun 17, 2024
1 parent b819fc2 commit 0513eb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function ls() {
, out = []
, paths = {}
, reEscRe = /[*.+^=:${}()|\/\\]/g
, opts = { dir: true, file: true, stat: false }
, opts = { dir: true, dot: false, file: true, stat: false }
for (; i > 0; ) {
key = arr[--i]
if (isObj(key)) Object.assign(opts, key)
Expand Down Expand Up @@ -129,7 +129,7 @@ function ls() {
return s.indexOf("/") > -1 && path.dirname(s)
}
function esc(s) {
return (s.charAt(0) === "." ? "" : "(?!\\.)") +
return (opts.dot || s.charAt(0) === "." ? "" : "(?!\\.)") +
s
.replace(reEscRe, "\\$&")
.replace(/\?/g, "[^\/]")
Expand Down
10 changes: 4 additions & 6 deletions test/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ describe("tools", function() {
assert.end()
})

it ("should list files with options", [
[ "*", { dir: false }, "README.md bench.js browser.js cli.js index.js opts.js package.json snapshot.js test.js v8.js watch.js" ],
], function(glob, opts, expected, assert) {
assert.equal(cli.ls(glob, opts).join(" "), expected).end()
})

it ("should list .dot files", function(assert) {
cli.mkdirp(".github/.dot")
cli.cp("package.json", ".github/.dot/p.json")
Expand All @@ -62,6 +56,10 @@ describe("tools", function() {
cli.ls(".*/.d*", null, ".github").join(" "),
child.execSync("bash -c 'shopt -s globstar;echo .github .*/.d*'").toString("utf8").trim()
)
// Assert options
assert.equal(cli.ls(".github/*", { dir: false }).join(" "), ".github/jshint.json .github/litejs.json")
assert.equal(cli.ls(".github/*", { file: false }).join(" "), ".github/workflows")
assert.equal(cli.ls(".github/*", { dot: true }).join(" "), ".github/.dot .github/.dot2 .github/jshint.json .github/litejs.json .github/workflows")
cli.rmrf(".github/.dot")
cli.rmrf(".github/.dot2")
assert.end()
Expand Down

0 comments on commit 0513eb3

Please sign in to comment.