Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: readDir implementation
Browse files Browse the repository at this point in the history
scolladon committed Jan 10, 2023

Unverified

This user has not yet uploaded their public signing key.
1 parent c6a8c51 commit fa144a2
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/lib/service/inResourceHandler.test.js
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ describe('InResourceHandler', () => {
readDir.mockImplementation(() =>
Promise.resolve([
'other.resource-meta.xml',
'other',
'other/',
'image.resource-meta.xml',
])
)
2 changes: 1 addition & 1 deletion __tests__/unit/lib/utils/fsHelper.test.js
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ describe('readDir', () => {
const dirContent = await readDir(dir, work)

// Assert
expect(dirContent).toEqual(expect.arrayContaining([`${dir}${file}`]))
expect(dirContent).toEqual(expect.arrayContaining([`${file}`]))
expect(getStreamContent).toHaveBeenCalled()
})
})
5 changes: 4 additions & 1 deletion src/service/inResourceHandler.js
Original file line number Diff line number Diff line change
@@ -78,7 +78,10 @@ class ResourceHandler extends StandardHandler {
async _buildElementMap(srcPath) {
if (!elementSrc.has(srcPath)) {
const dirContent = await readDir(srcPath, this.config)
elementSrc.set(srcPath, dirContent)
elementSrc.set(
srcPath,
dirContent.map(f => f.replace(/\/$/, ''))
)
}
}
}
9 changes: 4 additions & 5 deletions src/utils/fsHelper.js
Original file line number Diff line number Diff line change
@@ -57,9 +57,7 @@ const readDir = async (dir, config) => {
const dirContent = []
if (data.startsWith(FOLDER)) {
const [, , ...files] = data.split(EOLRegex)
for (const file of files) {
dirContent.push(join(dir, file))
}
dirContent.push(...files)
}
return dirContent
}
@@ -74,10 +72,11 @@ const readFile = async path => {
async function* scan(dir, config) {
const entries = await readDir(dir, config)
for (const file of entries) {
const filePath = join(dir, file)
if (file.endsWith('/')) {
yield* scan(file, config)
yield* scan(filePath, config)
} else {
yield file
yield filePath
}
}
}

0 comments on commit fa144a2

Please sign in to comment.