Skip to content

Commit

Permalink
fix: missing file name when only single path passed to filesFromPaths (
Browse files Browse the repository at this point in the history
…#31)

The common path for the first file was set to the entire `path`, not
`dirname(path)`. For multiple files the common path ends up as
`dirname(path)` but when there's only 1 it stays as `path`, so we end up
stripping out the entire path 🤦‍♂️.

Co-authored-by: Oli Evans <oli@protocol.ai>
  • Loading branch information
Alan Shaw and olizilla authored Dec 14, 2022
1 parent 1878bac commit fc3b5a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ export async function filesFromPaths (paths, options) {
for (const p of paths) {
for await (const file of filesFromPath(p, options)) {
files.push(file)
const nameParts = file.name.split('/')
const nameParts = file.name.split(path.sep)
if (commonParts == null) {
commonParts = nameParts
commonParts = nameParts.slice(0, -1)
continue
}
for (let i = 0; i < commonParts.length; i++) {
Expand Down
6 changes: 6 additions & 0 deletions test/lib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ test('filesFromPaths removes common path prefix', async (t) => {
t.false(file.name.startsWith('test/'))
}
})

test('filesFromPaths single file has name', async (t) => {
const files = await filesFromPaths(['test/fixtures/empty.car'])
t.is(files.length, 1)
t.is(files[0].name, 'empty.car')
})

0 comments on commit fc3b5a0

Please sign in to comment.