MCPcopy
hub / github.com/webpack/sass-loader / normalizeSourceMap

Function normalizeSourceMap

src/utils.js:734–765  ·  view source on GitHub ↗

* @param {RawSourceMap} map source map * @param {string} rootContext root context * @returns {RawSourceMap} normalized source map

(map, rootContext)

Source from the content-addressed store, hash-verified

732 * @returns {RawSourceMap} normalized source map
733 */
734function 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

Callers 1

loaderFunction · 0.90

Calls 1

getURLTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…