### module name resolution When resolving module names to file paths, ScriptCraft uses the following rules... 1. if the module does not begin with './' or '/' then ... 1.1 Look in the 'scriptcraft/lib' directory. If it's not there then... 1.2 Look in the 'scriptcraft/modules' directory.
(moduleName, parentDir)
| 155 | |
| 156 | ***/ |
| 157 | function resolveModuleToFile(moduleName, parentDir) { |
| 158 | var file = new File(moduleName), |
| 159 | i = 0, |
| 160 | resolvedFile; |
| 161 | if (file.exists()) { |
| 162 | return fileExists(file); |
| 163 | } |
| 164 | if (moduleName.match(/^[^\.\/]/)) { |
| 165 | // it's a module named like so ... 'events' , 'net/http' |
| 166 | // |
| 167 | for (; i < modulePaths.length; i++) { |
| 168 | resolvedFile = new File(modulePaths[i] + moduleName); |
| 169 | if (resolvedFile.exists()) { |
| 170 | return fileExists(resolvedFile); |
| 171 | } else { |
| 172 | // try appending a .js to the end |
| 173 | resolvedFile = new File(modulePaths[i] + moduleName + '.js'); |
| 174 | if (resolvedFile.exists()) { |
| 175 | return resolvedFile; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } else { |
| 180 | if ((file = new File(parentDir, moduleName)).exists()) { |
| 181 | return fileExists(file); |
| 182 | } else if ((file = new File(parentDir, moduleName + '.js')).exists()) { |
| 183 | // try .js extension |
| 184 | return file; |
| 185 | } else if ((file = new File(parentDir, moduleName + '.json')).exists()) { |
| 186 | // try .json extension |
| 187 | return file; |
| 188 | } |
| 189 | } |
| 190 | return null; |
| 191 | } |
| 192 | /* |
| 193 | require() function implementation |
| 194 | */ |
no test coverage detected