* Caches the source map, with the given filename, moduleInstance, sourceURL and sourceMapURL. * This function does not automatically extract the source map from the content. The caller should either * extract the source map from the content via V8 API or use extractSourceURLMagicComment ex
(filename, content, moduleInstance, isGeneratedSource, sourceURL, sourceMapURL)
| 155 | * @param {string | undefined} sourceMapURL - the source map url |
| 156 | */ |
| 157 | function maybeCacheSourceMap(filename, content, moduleInstance, isGeneratedSource, sourceURL, sourceMapURL) { |
| 158 | const support = getSourceMapsSupport(); |
| 159 | if (!(process.env.NODE_V8_COVERAGE || support.enabled)) return; |
| 160 | const { normalizeReferrerURL } = require('internal/modules/helpers'); |
| 161 | filename = normalizeReferrerURL(filename); |
| 162 | if (filename === undefined) { |
| 163 | // This is most likely an invalid filename in sourceURL of [eval]-wrapper. |
| 164 | return; |
| 165 | } |
| 166 | if (!support.nodeModules && isUnderNodeModules(filename)) { |
| 167 | // Skip file under node_modules if not enabled. |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | // Bail out when there is no source map url. |
| 172 | if (typeof sourceMapURL !== 'string') { |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | // Normalize the sourceURL to a file URL if it is a path. |
| 177 | sourceURL = normalizeReferrerURL(sourceURL); |
| 178 | |
| 179 | const data = dataFromUrl(filename, sourceMapURL); |
| 180 | // `data` could be null if the source map is invalid. |
| 181 | // In this case, create a cache entry with null data with source url for test coverage. |
| 182 | |
| 183 | const entry = { |
| 184 | __proto__: null, |
| 185 | lineLengths: lineLengths(content), |
| 186 | data, |
| 187 | // Save the source map url if it is not a data url. |
| 188 | sourceMapURL: data ? null : sourceMapURL, |
| 189 | sourceURL, |
| 190 | }; |
| 191 | |
| 192 | if (isGeneratedSource) { |
| 193 | generatedSourceMapCache.set(filename, entry); |
| 194 | return; |
| 195 | } |
| 196 | // If it is not a generated source, we assume we are in a "cjs/esm" |
| 197 | // context. |
| 198 | const keys = sourceURL ? [filename, sourceURL] : [filename]; |
| 199 | getModuleSourceMapCache().set(keys, entry, moduleInstance); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Caches the source map if it is present in the eval'd source. |
no test coverage detected
searching dependent graphs…