public File findExecutable ( String binary ) throws IOException , ParseException { File npmDirectory = getNPMDirectory ( ) ; File packageFile = new File ( npmDirectory , PACKAGE_JSON ) ; if ( ! packageFile . isFile ( ) ) { throw new IllegalStateException ( "Invalid NPM " + npmName + " - " + packageFile . getAbsolutePath ( ) + " does not" + " exist" ) ; } FileReader reader = null ; try { reader = new FileReader ( packageFile ) ; JSONObject json = ( JSONObject ) JSONValue . parseWithException ( reader ) ; JSONObject bin = ( JSONObject ) json . get ( "bin" ) ; if ( bin == null ) { log . error ( "No `bin` object in " + packageFile . getAbsolutePath ( ) ) ; return null ; } else { String exec = ( String ) bin . get ( binary ) ; if ( exec == null ) { log . error ( "No `" + binary + "` object in the `bin` object from " + packageFile . getAbsolutePath ( ) ) ; return null ; } File file = new File ( npmDirectory , exec ) ; if ( ! file . isFile ( ) ) { log . error ( "To execute " + npmName + ", an entry was found for " + binary + " in 'package.json', " + "but the specified file does not exist - " + file . getAbsolutePath ( ) ) ; return null ; } return file ; } } finally { IOUtils . closeQuietly ( reader ) ; } }
Tries to find the main JS file . This search is based on the package . json file and it s bin entry . If there is an entry in the bin object matching binary it uses this javascript file . If the search failed null is returned