| 99 | } |
| 100 | |
| 101 | function readModuleFromDirectory(dir) { |
| 102 | // look for a package.json file |
| 103 | var pkgJsonFile = new File(dir, './package.json'); |
| 104 | if (pkgJsonFile.exists()) { |
| 105 | var pkg = scload(pkgJsonFile); |
| 106 | var mainFile = new File(dir, pkg.main); |
| 107 | if (mainFile.exists()) { |
| 108 | return mainFile; |
| 109 | } else { |
| 110 | return null; |
| 111 | } |
| 112 | } else { |
| 113 | // look for an index.js file |
| 114 | var indexJsFile = new File(dir, './index.js'); |
| 115 | if (indexJsFile.exists()) { |
| 116 | return indexJsFile; |
| 117 | } else { |
| 118 | return null; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /********************************************************************** |
| 124 | ### module name resolution |