(filename, currentDirectory, options, environment, callback)
| 16 | }, |
| 17 | |
| 18 | loadFile(filename, currentDirectory, options, environment, callback) { |
| 19 | let fullFilename; |
| 20 | const isAbsoluteFilename = this.isPathAbsolute(filename); |
| 21 | const filenamesTried = []; |
| 22 | const self = this; |
| 23 | const prefix = filename.slice(0, 1); |
| 24 | const explicit = prefix === '.' || prefix === '/'; |
| 25 | let result = null; |
| 26 | let isNodeModule = false; |
| 27 | const npmPrefix = 'npm://'; |
| 28 | |
| 29 | options = options || {}; |
| 30 | |
| 31 | const paths = isAbsoluteFilename ? [''] : [currentDirectory]; |
| 32 | |
| 33 | if (options.paths) { paths.push.apply(paths, options.paths); } |
| 34 | |
| 35 | if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); } |
| 36 | |
| 37 | const prefixes = options.prefixes || ['']; |
| 38 | const fileParts = this.extractUrlParts(filename); |
| 39 | |
| 40 | if (options.syncImport) { |
| 41 | getFileData(returnData, returnData); |
| 42 | if (callback) { |
| 43 | callback(result.error, result); |
| 44 | } |
| 45 | else { |
| 46 | return result; |
| 47 | } |
| 48 | } |
| 49 | else { |
| 50 | // promise is guaranteed to be asyncronous |
| 51 | // which helps as it allows the file handle |
| 52 | // to be closed before it continues with the next file |
| 53 | return new Promise(getFileData); |
| 54 | } |
| 55 | |
| 56 | function returnData(data) { |
| 57 | if (!data.filename) { |
| 58 | result = { error: data }; |
| 59 | } |
| 60 | else { |
| 61 | result = data; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | function getFileData(fulfill, reject) { |
| 66 | (function tryPathIndex(i) { |
| 67 | function tryWithExtension() { |
| 68 | const extFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename; |
| 69 | |
| 70 | if (extFilename !== fullFilename && !explicit && paths[i] === '.') { |
| 71 | try { |
| 72 | fullFilename = require.resolve(extFilename); |
| 73 | isNodeModule = true; |
| 74 | } |
| 75 | catch (e) { |
no test coverage detected