(parentFile, path, options)
| 193 | require() function implementation |
| 194 | */ |
| 195 | function _require(parentFile, path, options) { |
| 196 | var file, |
| 197 | canonizedFilename, |
| 198 | moduleInfo, |
| 199 | buffered, |
| 200 | code = '', |
| 201 | line = null; |
| 202 | |
| 203 | if (typeof options == 'undefined') { |
| 204 | options = { cache: true }; |
| 205 | } else { |
| 206 | if (typeof options.cache == 'undefined') { |
| 207 | options.cache = true; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | file = resolveModuleToFile(path, parentFile); |
| 212 | if (!file) { |
| 213 | var errMsg = |
| 214 | '' + |
| 215 | _format( |
| 216 | "require() failed to find matching file for module '%s' " + |
| 217 | "in working directory '%s' ", |
| 218 | [path, parentFile.canonicalPath] |
| 219 | ); |
| 220 | if (!('' + path).match(/^\./)) { |
| 221 | errMsg = |
| 222 | errMsg + ' and not found in paths ' + JSON.stringify(modulePaths); |
| 223 | } |
| 224 | var find = _require(parentFile, 'find').exports; |
| 225 | var allJS = []; |
| 226 | for (var i = 0; i < modulePaths.length; i++) { |
| 227 | var js = find(modulePaths[i]); |
| 228 | for (var j = 0; j < js.length; j++) { |
| 229 | if (js[j].match(/\.js$/)) { |
| 230 | allJS.push(js[j].replace(modulePaths[i], '')); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | var pathL = path.toLowerCase(); |
| 235 | var candidates = []; |
| 236 | for (i = 0; i < allJS.length; i++) { |
| 237 | var filenameparts = allJS[i]; |
| 238 | var candidate = filenameparts.replace(/\.js/, ''); |
| 239 | var lastpart = candidate.toLowerCase(); |
| 240 | if (pathL.indexOf(lastpart) > -1 || lastpart.indexOf(pathL) > -1) { |
| 241 | candidates.push(candidate); |
| 242 | } |
| 243 | } |
| 244 | if (candidates.length > 0) { |
| 245 | errMsg += |
| 246 | '\nBut found module/s named: ' + |
| 247 | candidates.join(',') + |
| 248 | ' - is this what you meant?'; |
| 249 | } |
| 250 | throw new Error(errMsg); |
| 251 | } |
| 252 | canonizedFilename = _canonize(file); |
no test coverage detected