* @todo think about replacing sequential fetch function calls with requires calls * @param {string} _to * @param {string} from * @return {object}
(_to, from)
| 82 | * @return {object} |
| 83 | */ |
| 84 | function fetch(_to, from) { |
| 85 | // getting absolute path to the processing file |
| 86 | const filename = /[^\\/?%*:|"<>.]/i.test(_to[0]) |
| 87 | ? require.resolve(_to) |
| 88 | : resolve(dirname(from), _to); |
| 89 | |
| 90 | // checking cache |
| 91 | let tokens = tokensByFile[filename]; |
| 92 | if (tokens) { |
| 93 | debugFetch(`${filename} → cache`); |
| 94 | debugFetch(tokens); |
| 95 | return tokens; |
| 96 | } |
| 97 | |
| 98 | const source = preprocessCss(readFileSync(filename, 'utf8'), filename); |
| 99 | // https://github.com/postcss/postcss/blob/master/docs/api.md#processorprocesscss-opts |
| 100 | const lazyResult = runner.process(source, assign({}, processorOpts, {from: filename})); |
| 101 | |
| 102 | // https://github.com/postcss/postcss/blob/master/docs/api.md#lazywarnings |
| 103 | lazyResult.warnings().forEach(message => console.warn(message.text)); |
| 104 | |
| 105 | tokens = lazyResult.root.exports || {}; |
| 106 | |
| 107 | if (!debugMode) |
| 108 | // updating cache |
| 109 | tokensByFile[filename] = tokens; |
| 110 | else |
| 111 | // clearing cache in development mode |
| 112 | delete require.cache[filename]; |
| 113 | |
| 114 | if (processCss) |
| 115 | processCss(lazyResult.css, filename); |
| 116 | |
| 117 | debugFetch(`${filename} → fs`); |
| 118 | debugFetch(tokens); |
| 119 | |
| 120 | return tokens; |
| 121 | } |
| 122 | |
| 123 | const isException = buildExceptionChecker(ignore); |
| 124 |
no outgoing calls
no test coverage detected
searching dependent graphs…