Skip to content

Commit

Permalink
fix: RangeError: Maximum call stack size exceeded
Browse files Browse the repository at this point in the history
Closes #826
  • Loading branch information
develar committed Nov 3, 2016
1 parent c3136ad commit c5627f8
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@ const concurrency = {concurrency: MAX_FILE_REQUESTS}
const NODE_MODULES_PATTERN = path.sep + "node_modules" + path.sep

export async function walk(dirPath: string, consumer?: (file: string, stat: Stats) => void, filter?: Filter, addRootToResult?: boolean): Promise<Array<string>> {
const list = await BluebirdPromise.map(await readdir(dirPath), name => {
const filePath = dirPath + path.sep + name
return lstat(filePath)
.then((stat): any => {
if (filter != null && !filter(filePath, stat)) {
return null
}
const childNames = await readdir(dirPath)
const list = await BluebirdPromise.map(childNames, name => lstat(dirPath + path.sep + name), concurrency)
.then(stats => BluebirdPromise.map(stats, (stat, index): any => {
const filePath = dirPath + path.sep + childNames[index]
if (filter != null && !filter(filePath, stat)) {
return null
}

if (consumer != null) {
consumer(filePath, stat)
}
if (stat.isDirectory()) {
return walk(filePath, consumer, filter, true)
}
return filePath
})
}, concurrency)
if (consumer != null) {
consumer(filePath, stat)
}
if (stat.isDirectory()) {
return walk(filePath, consumer, filter, true)
}
return filePath
}, concurrency))

list.sort((a, b) => {
// files before directories
Expand Down

0 comments on commit c5627f8

Please sign in to comment.