Handle broken symlinks when walking

This commit is contained in:
Kevin Sawicki
2015-02-11 15:19:29 -08:00
parent 5310b7dd32
commit c52d3593ff

View File

@@ -1,3 +1,4 @@
fs = require 'fs'
path = require 'path'
module.exports = (grunt) ->
@@ -19,7 +20,7 @@ module.exports = (grunt) ->
getOtherTotal = ->
Object.keys(otherModules).length
grunt.file.recurse nodeModulesDir, (absolutePath, rootPath, relativePath, fileName) ->
recurseHandler = (absolutePath, rootPath, relativePath, fileName) ->
return if fileName isnt 'package.json'
{name, version, repository} = grunt.file.readJSON(absolutePath)
@@ -36,6 +37,22 @@ module.exports = (grunt) ->
modules[name].count++
modules[name].versions[version] = true
walkNodeModuleDir = ->
grunt.file.recurse(nodeModulesDir, recurseHandler)
# Handle broken symlinks that grunt.file.recurse fails to handle
loop
try
walkNodeModuleDir()
break
catch error
if error.code is 'ENOENT'
fs.unlinkSync(error.path)
otherModules = {}
atomModules = {}
else
break
if getAtomTotal() > 0
console.log "Atom Modules: #{getAtomTotal()}"
sortModuleNames(atomModules).forEach (name) ->