* @param {RawSourceMap} map source map * @param {string} rootContext root context * @returns {RawSourceMap} normalized source map
(map, rootContext)
| 732 | * @returns {RawSourceMap} normalized source map |
| 733 | */ |
| 734 | function normalizeSourceMap(map, rootContext) { |
| 735 | const newMap = map; |
| 736 | |
| 737 | // result.map.file is an optional property that provides the output filename. |
| 738 | // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it. |
| 739 | |
| 740 | if (typeof newMap.file !== "undefined") { |
| 741 | // @ts-expect-error need to fix on webpack side |
| 742 | delete newMap.file; |
| 743 | } |
| 744 | |
| 745 | newMap.sourceRoot = ""; |
| 746 | |
| 747 | // sass returns POSIX paths, that's why we need to transform them back to native paths. |
| 748 | // This fixes an error on windows where the source-map module cannot resolve the source maps. |
| 749 | // @see https://github.com/webpack/sass-loader/issues/366#issuecomment-279460722 |
| 750 | |
| 751 | newMap.sources = newMap.sources.map((/** @type {string} */ source) => { |
| 752 | const sourceType = getURLType(source); |
| 753 | |
| 754 | // Do no touch `scheme-relative`, `path-absolute` and `absolute` types (except `file:`) |
| 755 | if (sourceType === "absolute" && /^file:/i.test(source)) { |
| 756 | return url.fileURLToPath(source); |
| 757 | } else if (sourceType === "path-relative") { |
| 758 | return path.resolve(rootContext, path.normalize(source)); |
| 759 | } |
| 760 | |
| 761 | return source; |
| 762 | }); |
| 763 | |
| 764 | return newMap; |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * @param {Error | SassError} error the original sass error |
no test coverage detected
searching dependent graphs…