nl_tokens: Fix module resolution in all found javascript files
pl_tokens: function fixFiles ( ) { logger . trace ( "inside fixFiles()" ) ; _ . each ( registry . files , function ( file ) { var fullpath = path . join ( rootpath , file ) ; var basepath = path . posix . dirname ( file ) ; var basefile = path . posix . resolve ( file ) ; var source = fs . readFileSync ( fullpath , 'utf8' ) ; logger . trace ( "fixing file: " + fullpath ) ; var requireRegex = / (require)\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\) / g ; var staticRequireRegex = / (require)(?:\(\s*['"])([^'"]+)(?:['"]\s*\)) / g ; source = <mask> . replace ( requireRegex , function ( $1 , $2 , $3 ) { var requestedModule = $2 ; if ( staticRequireRegex . test ( $1 ) ) { var staticRequireSource = $1 ; staticRequireSource = staticRequireSource . replace ( staticRequireRegex , function ( $1 , $2 , $3 ) { var resolved_path = resolver . resolve ( $3 , basepath ) ; return 'require("' + resolved_path + '")' ; } ) ; return staticRequireSource ; } else { return 'require(Alloy.resolve(' + $3 + ', "' + basepath + '"))' ; } } ) ; fs . writeFileSync ( fullpath , source , { mode : 0o755 } ) ; } ) ; }