MCPcopy Index your code
hub / github.com/webpack/css-loader / normalizeSourceMap

Function normalizeSourceMap

src/utils.js:832–873  ·  view source on GitHub ↗
(map, resourcePath)

Source from the content-addressed store, hash-verified

830}
831
832function normalizeSourceMap(map, resourcePath) {
833 let newMap = map;
834
835 // Some loader emit source map as string
836 // Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
837 if (typeof newMap === "string") {
838 newMap = JSON.parse(newMap);
839 }
840
841 delete newMap.file;
842
843 const { sourceRoot } = newMap;
844
845 delete newMap.sourceRoot;
846
847 if (newMap.sources) {
848 // Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
849 // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
850 newMap.sources = newMap.sources.map((source) => {
851 // Non-standard syntax from `postcss`
852 if (source.indexOf("<") === 0) {
853 return source;
854 }
855
856 const sourceType = getURLType(source);
857
858 // Do no touch `scheme-relative` and `absolute` URLs
859 if (sourceType === "path-relative" || sourceType === "path-absolute") {
860 const absoluteSource =
861 sourceType === "path-relative" && sourceRoot
862 ? path.resolve(sourceRoot, normalizePath(source))
863 : normalizePath(source);
864
865 return path.relative(path.dirname(resourcePath), absoluteSource);
866 }
867
868 return source;
869 });
870 }
871
872 return newMap;
873}
874
875function getPreRequester({ loaders, loaderIndex }) {
876 const cache = Object.create(null);

Callers 1

loaderFunction · 0.90

Calls 2

getURLTypeFunction · 0.85
normalizePathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…