* Returns whether the source map should be used to resolve a local path, * following the `resolveSourceMapPaths`
({ sourceMapUrl, compiledPath }: ISourceMapMetadata)
| 100 | * following the `resolveSourceMapPaths` |
| 101 | */ |
| 102 | public shouldResolveSourceMap({ sourceMapUrl, compiledPath }: ISourceMapMetadata) { |
| 103 | // Node 15 started including some source-mapped internals (acorn), but |
| 104 | // they don't ship source maps in the build. Never try to resolve those. |
| 105 | if (compiledPath.startsWith(node15InternalsPrefix)) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if (!this.resolvePatterns || this.resolvePatterns.length === 0) { |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | const sourcePath = |
| 114 | // If the source map refers to an absolute path, that's what we're after |
| 115 | fileUrlToAbsolutePath(sourceMapUrl) |
| 116 | // If it's a data URI, use the compiled path as a stand-in. It should |
| 117 | // be quite rare that ignored files (i.e. node_modules) reference |
| 118 | // source modules and vise versa. |
| 119 | || (isDataUri(sourceMapUrl) && compiledPath) |
| 120 | // Fall back to the raw URL if those fail. |
| 121 | || sourceMapUrl; |
| 122 | |
| 123 | // Where the compiled path is webpack-internal, just resolve it. We have |
| 124 | // no way to know where it's coming from, but this is necessary sometimes. |
| 125 | // See https://github.com/microsoft/vscode-js-debug/issues/854#issuecomment-741958453 |
| 126 | if (sourcePath.startsWith('webpack-internal:///')) { |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | // Be case insensitive for things that might be remote uris--we have no way |
| 131 | // to know whether the server is case sensitive or not. |
| 132 | const caseSensitive = isWindowsPath(sourceMapUrl) ? false : getCaseSensitivePaths(); |
| 133 | const rebased = this.rebaseRemoteToLocal(sourcePath); |
| 134 | const testLocations = rebased !== sourcePath ? [sourcePath, rebased] : [sourcePath]; |
| 135 | |
| 136 | const l = match(testLocations.map(forceForwardSlashes), this.resolvePatterns, { |
| 137 | dot: true, |
| 138 | nocase: !caseSensitive, |
| 139 | }); |
| 140 | |
| 141 | return l.length > 0; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Rebases a remote path to a local one using the remote and local roots. |
nothing calls this directly
no test coverage detected