Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

source-map-loader

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-map-loader - npm Package Compare versions

Comparing version 4.0.1 to 4.0.2

1

dist/cjs.js
"use strict";
const loader = require("./index");
module.exports = loader.default;
module.exports.raw = loader.raw;

44

dist/index.js

@@ -7,11 +7,6 @@ "use strict";

exports.default = loader;
var _path = _interopRequireDefault(require("path"));
var _options = _interopRequireDefault(require("./options.json"));
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*

@@ -21,2 +16,3 @@ MIT License http://www.opensource.org/licenses/mit-license.php

*/
async function loader(input, inputMap) {

@@ -29,3 +25,2 @@ const options = this.getOptions(_options.default);

const callback = this.async();
if (!sourceMappingURL) {

@@ -35,5 +30,3 @@ callback(null, input, inputMap);

}
let behaviourSourceMappingUrl;
try {

@@ -44,5 +37,5 @@ behaviourSourceMappingUrl = typeof options.filterSourceMappingUrl !== "undefined" ? options.filterSourceMappingUrl(sourceMappingURL, this.resourcePath) : "consume";

return;
} // eslint-disable-next-line default-case
}
// eslint-disable-next-line default-case
switch (behaviourSourceMappingUrl) {

@@ -52,3 +45,2 @@ case "skip":

return;
case false:

@@ -59,6 +51,4 @@ case "remove":

}
let sourceURL;
let sourceContent;
try {

@@ -74,9 +64,6 @@ ({

}
if (sourceURL) {
this.addDependency(sourceURL);
}
let map;
try {

@@ -89,5 +76,3 @@ map = JSON.parse(sourceContent.replace(/^\)\]\}'/, ""));

}
const context = sourceURL ? _path.default.dirname(sourceURL) : this.context;
if (map.sections) {

@@ -97,15 +82,16 @@ // eslint-disable-next-line no-param-reassign

}
const resolvedSources = await Promise.all(map.sources.map(async (source, i) => {
// eslint-disable-next-line no-shadow
let sourceURL; // eslint-disable-next-line no-shadow
let sourceURL;
// eslint-disable-next-line no-shadow
let sourceContent;
const originalSourceContent = map.sourcesContent && typeof map.sourcesContent[i] !== "undefined" && map.sourcesContent[i] !== null ? map.sourcesContent[i] : // eslint-disable-next-line no-undefined
const originalSourceContent = map.sourcesContent && typeof map.sourcesContent[i] !== "undefined" && map.sourcesContent[i] !== null ? map.sourcesContent[i] :
// eslint-disable-next-line no-undefined
undefined;
const skipReading = typeof originalSourceContent !== "undefined";
let errored = false; // We do not skipReading here, because we need absolute paths in sources.
let errored = false;
// We do not skipReading here, because we need absolute paths in sources.
// This is necessary so that for sourceMaps with the same file structure in sources, name collisions do not occur.
// https://github.com/webpack-contrib/source-map-loader/issues/51
try {

@@ -120,3 +106,2 @@ ({

}
if (skipReading) {

@@ -126,5 +111,5 @@ sourceContent = originalSourceContent;

this.addDependency(sourceURL);
} // Return original value of `source` when error happens
}
// Return original value of `source` when error happens
return {

@@ -135,3 +120,4 @@ sourceURL: errored ? source : sourceURL,

}));
const newMap = { ...map
const newMap = {
...map
};

@@ -151,8 +137,6 @@ newMap.sources = [];

const sourcesContentIsEmpty = newMap.sourcesContent.filter(entry => Boolean(entry)).length === 0;
if (sourcesContentIsEmpty) {
delete newMap.sourcesContent;
}
callback(null, input.replace(replacementString, ""), newMap);
}

@@ -214,3 +214,2 @@ "use strict";

};
var _default = labelToNames;
exports.default = _default;
var _default = exports.default = labelToNames;

@@ -7,37 +7,28 @@ "use strict";

exports.default = parseDataUrl;
var _abab = require("abab");
const removeLeadingAndTrailingHTTPWhitespace = string => string.replace(/^[ \t\n\r]+/, "").replace(/[ \t\n\r]+$/, "");
const removeTrailingHTTPWhitespace = string => string.replace(/[ \t\n\r]+$/, "");
const isHTTPWhitespaceChar = char => char === " " || char === "\t" || char === "\n" || char === "\r";
const solelyContainsHTTPTokenCodePoints = string => /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/.test(string);
const soleyContainsHTTPQuotedStringTokenCodePoints = string => /^[\t\u0020-\u007E\u0080-\u00FF]*$/.test(string);
const asciiLowercase = string => string.replace(/[A-Z]/g, l => l.toLowerCase());
const collectAnHTTPQuotedString = (input, position) => {
let value = ""; // eslint-disable-next-line no-param-reassign
let value = "";
position += 1; // eslint-disable-next-line no-constant-condition
// eslint-disable-next-line no-param-reassign
position += 1;
// eslint-disable-next-line no-constant-condition
while (true) {
while (position < input.length && input[position] !== '"' && input[position] !== "\\") {
value += input[position]; // eslint-disable-next-line no-param-reassign
value += input[position];
// eslint-disable-next-line no-param-reassign
position += 1;
}
if (position >= input.length) {
break;
}
const quoteOrBackslash = input[position];
const quoteOrBackslash = input[position]; // eslint-disable-next-line no-param-reassign
// eslint-disable-next-line no-param-reassign
position += 1;
if (quoteOrBackslash === "\\") {

@@ -48,5 +39,4 @@ if (position >= input.length) {

}
value += input[position]; // eslint-disable-next-line no-param-reassign
value += input[position];
// eslint-disable-next-line no-param-reassign
position += 1;

@@ -57,17 +47,12 @@ } else {

}
return [value, position];
};
function isASCIIHex(c) {
return c >= 0x30 && c <= 0x39 || c >= 0x41 && c <= 0x46 || c >= 0x61 && c <= 0x66;
}
function percentDecodeBytes(input) {
const output = new Uint8Array(input.byteLength);
let outputIndex = 0;
for (let i = 0; i < input.byteLength; ++i) {
const byte = input[i];
if (byte !== 0x25) {

@@ -81,12 +66,117 @@ output[outputIndex] = byte;

}
outputIndex += 1;
}
return output.slice(0, outputIndex);
}
/**
* A lookup table for atob(), which converts an ASCII character to the
* corresponding six-bit number.
*/
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function atobLookup(chr) {
const index = characters.indexOf(chr);
// Throw exception if character is not in the lookup string; should not be hit in tests
// eslint-disable-next-line no-undefined
return index < 0 ? undefined : index;
}
/**
* Implementation of atob() according to the HTML and Infra specs, except that
* instead of throwing INVALID_CHARACTER_ERR we return null.
*/
function atob(input) {
/* eslint-disable no-bitwise */
// Web IDL requires DOMStrings to just be converted using ECMAScript
// ToString, which in our case amounts to using a template literal.
let data = `${input}`;
// "Remove all ASCII whitespace from data."
data = data.replace(/[ \t\n\f\r]/g, "");
// "If data's length divides by 4 leaving no remainder, then: if data ends
// with one or two U+003D (=) code points, then remove them from data."
if (data.length % 4 === 0) {
data = data.replace(/==?$/, "");
}
// "If data's length divides by 4 leaving a remainder of 1, then return
// failure."
//
// "If data contains a code point that is not one of
//
// U+002B (+)
// U+002F (/)
// ASCII alphanumeric
//
// then return failure."
if (data.length % 4 === 1 || /[^+/0-9A-Za-z]/.test(data)) {
return null;
}
// "Let output be an empty byte sequence."
let output = "";
// "Let buffer be an empty buffer that can have bits appended to it."
//
// We append bits via left-shift and or. accumulatedBits is used to track
// when we've gotten to 24 bits.
let buffer = 0;
let accumulatedBits = 0;
// "Let position be a position variable for data, initially pointing at the
// start of data."
//
// "While position does not point past the end of data:"
for (let i = 0; i < data.length; i++) {
// "Find the code point pointed to by position in the second column of
// Table 1: The Base 64 Alphabet of RFC 4648. Let n be the number given in
// the first cell of the same row.
//
// "Append to buffer the six bits corresponding to n, most significant bit
// first."
//
// atobLookup() implements the table from RFC 4648.
// eslint-disable-next-line no-bitwise
buffer <<= 6;
// eslint-disable-next-line no-bitwise
buffer |= atobLookup(data[i]);
accumulatedBits += 6;
// "If buffer has accumulated 24 bits, interpret them as three 8-bit
// big-endian numbers. Append three bytes with values equal to those
// numbers to output, in the same order, and then empty buffer."
if (accumulatedBits === 24) {
output += String.fromCharCode((buffer & 0xff0000) >> 16);
output += String.fromCharCode((buffer & 0xff00) >> 8);
output += String.fromCharCode(buffer & 0xff);
accumulatedBits = 0;
buffer = 0;
}
// "Advance position by 1."
}
// "If buffer is not empty, it contains either 12 or 18 bits. If it contains
// 12 bits, then discard the last four and interpret the remaining eight as
// an 8-bit big-endian number. If it contains 18 bits, then discard the last
// two and interpret the remaining 16 as two 8-bit big-endian numbers. Append
// the one or two bytes with values equal to those one or two numbers to
// output, in the same order."
if (accumulatedBits === 12) {
buffer >>= 4;
output += String.fromCharCode(buffer);
} else if (accumulatedBits === 18) {
buffer >>= 2;
output += String.fromCharCode((buffer & 0xff00) >> 8);
output += String.fromCharCode(buffer & 0xff);
}
/* eslint-enable no-bitwise */
// "Return output."
return output;
}
function parseDataUrl(stringInput) {
let parsedUrl;
try {

@@ -97,13 +187,11 @@ parsedUrl = new URL(stringInput);

}
if (parsedUrl.protocol !== "data:") {
return null;
}
parsedUrl.hash = "";
parsedUrl.hash = ""; // `5` is value of `'data:'.length`
// `5` is value of `'data:'.length`
const input = parsedUrl.toString().substring(5);
let position = 0;
let mediaType = "";
while (position < input.length && input[position] !== ",") {

@@ -113,31 +201,24 @@ mediaType += input[position];

}
mediaType = mediaType.replace(/^[ \t\n\f\r]+/, "").replace(/[ \t\n\f\r]+$/, "");
if (position === input.length) {
return null;
}
position += 1;
const encodedBody = input.substring(position);
let body = Buffer.from(percentDecodeBytes(Buffer.from(encodedBody, "utf-8"))); // Can't use /i regexp flag because it isn't restricted to ASCII.
let body = Buffer.from(percentDecodeBytes(Buffer.from(encodedBody, "utf-8")));
// Can't use /i regexp flag because it isn't restricted to ASCII.
const mimeTypeBase64MatchResult = /(.*); *[Bb][Aa][Ss][Ee]64$/.exec(mediaType);
if (mimeTypeBase64MatchResult) {
const stringBody = body.toString("binary");
const asString = (0, _abab.atob)(stringBody);
const asString = atob(stringBody);
if (asString === null) {
return null;
}
body = Buffer.from(asString, "binary");
[, mediaType] = mimeTypeBase64MatchResult;
}
if (mediaType.startsWith(";")) {
mediaType = `text/plain ${mediaType}`;
}
const result = {

@@ -152,11 +233,8 @@ // eslint-disable-next-line no-undefined

};
if (!mediaType) {
return result;
}
const inputMediaType = removeLeadingAndTrailingHTTPWhitespace(mediaType);
let positionMediaType = 0;
let type = "";
while (positionMediaType < inputMediaType.length && inputMediaType[positionMediaType] !== "/") {

@@ -166,15 +244,12 @@ type += inputMediaType[positionMediaType];

}
if (type.length === 0 || !solelyContainsHTTPTokenCodePoints(type)) {
return result;
}
if (positionMediaType >= inputMediaType.length) {
return result;
} // Skips past "/"
}
// Skips past "/"
positionMediaType += 1;
let subtype = "";
while (positionMediaType < inputMediaType.length && inputMediaType[positionMediaType] !== ";") {

@@ -184,22 +259,15 @@ subtype += inputMediaType[positionMediaType];

}
subtype = removeTrailingHTTPWhitespace(subtype);
if (subtype.length === 0 || !solelyContainsHTTPTokenCodePoints(subtype)) {
return result;
}
result.type = asciiLowercase(type);
result.subtype = asciiLowercase(subtype);
while (positionMediaType < inputMediaType.length) {
// Skip past ";"
positionMediaType += 1;
while (isHTTPWhitespaceChar(inputMediaType[positionMediaType])) {
positionMediaType += 1;
}
let parameterName = "";
while (positionMediaType < inputMediaType.length && inputMediaType[positionMediaType] !== ";" && inputMediaType[positionMediaType] !== "=") {

@@ -209,5 +277,3 @@ parameterName += inputMediaType[positionMediaType];

}
parameterName = asciiLowercase(parameterName);
if (positionMediaType < inputMediaType.length) {

@@ -217,13 +283,10 @@ if (inputMediaType[positionMediaType] === ";") {

continue;
} // Skip past "="
}
// Skip past "="
positionMediaType += 1;
}
let parameterValue = "";
if (inputMediaType[positionMediaType] === '"') {
[parameterValue, positionMediaType] = collectAnHTTPQuotedString(inputMediaType, positionMediaType);
while (positionMediaType < inputMediaType.length && inputMediaType[positionMediaType] !== ";") {

@@ -237,5 +300,3 @@ positionMediaType += 1;

}
parameterValue = removeTrailingHTTPWhitespace(parameterValue);
if (parameterValue === "") {

@@ -246,3 +307,2 @@ // eslint-disable-next-line no-continue

}
if (parameterName.length > 0 && solelyContainsHTTPTokenCodePoints(parameterName) && soleyContainsHTTPQuotedStringTokenCodePoints(parameterValue) && !result.parameters.has(parameterName)) {

@@ -252,4 +312,3 @@ result.parameters.set(parameterName, parameterValue);

}
return result;
}

@@ -10,21 +10,13 @@ "use strict";

exports.isURL = isURL;
var _path = _interopRequireDefault(require("path"));
var _url = _interopRequireDefault(require("url"));
var _sourceMapJs = _interopRequireDefault(require("source-map-js"));
var _iconvLite = require("iconv-lite");
var _parseDataUrl = _interopRequireDefault(require("./parse-data-url"));
var _labelsToNames = _interopRequireDefault(require("./labels-to-names"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Matches only the last occurrence of sourceMappingURL
const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*([^\s'"]*)\s*/;
/* eslint-disable prefer-template */
const sourceMappingURLRegex = RegExp("(?:" + "/\\*" + "(?:\\s*\r?\n(?://)?)?" + "(?:" + innerRegex.source + ")" + "\\s*" + "\\*/" + "|" + "//(?:" + innerRegex.source + ")" + ")" + "\\s*");

@@ -37,3 +29,2 @@ /* eslint-enable prefer-template */

}
async function flattenSourceMap(map) {

@@ -66,3 +57,2 @@ const consumer = await new _sourceMapJs.default.SourceMapConsumer(map);

};
if (source) {

@@ -74,10 +64,7 @@ generatedMap.addMapping(mappings);

}
function getSourceMappingURL(code) {
const lines = code.split(/^/m);
let match;
for (let i = lines.length - 1; i >= 0; i--) {
match = lines[i].match(sourceMappingURLRegex);
if (match) {

@@ -87,3 +74,2 @@ break;

}
const sourceMappingURL = match ? match[1] || match[2] || "" : null;

@@ -95,3 +81,2 @@ return {

}
function getAbsolutePath(context, request, sourceRoot) {

@@ -101,3 +86,2 @@ if (isURL(sourceRoot)) {

}
if (sourceRoot) {

@@ -107,12 +91,8 @@ if (_path.default.isAbsolute(sourceRoot)) {

}
return _path.default.join(context, sourceRoot, request);
}
return _path.default.join(context, request);
}
function fetchFromDataURL(loaderContext, sourceURL) {
const dataURL = (0, _parseDataUrl.default)(sourceURL);
if (dataURL) {

@@ -124,9 +104,6 @@ // https://tools.ietf.org/html/rfc4627

}
throw new Error(`Failed to parse source map from "data" URL: ${sourceURL}`);
}
async function fetchFromFilesystem(loaderContext, sourceURL) {
let buffer;
if (isURL(sourceURL)) {

@@ -137,3 +114,2 @@ return {

}
try {

@@ -145,3 +121,2 @@ buffer = await new Promise((resolve, reject) => {

}
return resolve(data);

@@ -153,3 +128,2 @@ });

}
return {

@@ -160,6 +134,4 @@ path: sourceURL,

}
async function fetchPathsFromFilesystem(loaderContext, possibleRequests, errorsAccumulator = "") {
let result;
try {

@@ -171,3 +143,2 @@ result = await fetchFromFilesystem(loaderContext, possibleRequests[0], errorsAccumulator);

const [, ...tailPossibleRequests] = possibleRequests;
if (tailPossibleRequests.length === 0) {

@@ -177,13 +148,9 @@ error.message = errorsAccumulator;

}
return fetchPathsFromFilesystem(loaderContext, tailPossibleRequests, errorsAccumulator);
}
return result;
}
function isURL(value) {
return /^[a-z][a-z0-9+.-]*:/i.test(value) && !_path.default.win32.isAbsolute(value);
}
async function fetchFromURL(loaderContext, context, url, sourceRoot, skipReading = false) {

@@ -195,3 +162,2 @@ // 1. It's an absolute url and it is not `windows` path like `C:\dir\file`

} = _url.default.parse(url);
if (protocol === "data:") {

@@ -203,3 +169,2 @@ if (skipReading) {

}
const sourceContent = fetchFromDataURL(loaderContext, url);

@@ -211,3 +176,2 @@ return {

}
if (skipReading) {

@@ -218,8 +182,5 @@ return {

}
if (protocol === "file:") {
const pathFromURL = _url.default.fileURLToPath(url);
const sourceURL = _path.default.normalize(pathFromURL);
const {

@@ -233,24 +194,19 @@ data: sourceContent

}
throw new Error(`Failed to parse source map: '${url}' URL is not supported`);
} // 2. It's a scheme-relative
}
// 2. It's a scheme-relative
if (/^\/\//.test(url)) {
throw new Error(`Failed to parse source map: '${url}' URL is not supported`);
} // 3. Absolute path
}
// 3. Absolute path
if (_path.default.isAbsolute(url)) {
let sourceURL = _path.default.normalize(url);
let sourceContent;
if (!skipReading) {
const possibleRequests = [sourceURL];
if (url.startsWith("/")) {
possibleRequests.push(getAbsolutePath(context, sourceURL.slice(1), sourceRoot));
}
const result = await fetchPathsFromFilesystem(loaderContext, possibleRequests);

@@ -260,3 +216,2 @@ sourceURL = result.path;

}
return {

@@ -266,8 +221,7 @@ sourceURL,

};
} // 4. Relative path
}
// 4. Relative path
const sourceURL = getAbsolutePath(context, url, sourceRoot);
let sourceContent;
if (!skipReading) {

@@ -279,3 +233,2 @@ const {

}
return {

@@ -282,0 +235,0 @@ sourceURL,

{
"name": "source-map-loader",
"version": "4.0.1",
"version": "4.0.2",
"description": "extracts inlined source map and offers it to webpack",

@@ -27,3 +27,7 @@ "license": "MIT",

"lint:js": "eslint --cache .",
"lint:spelling": "cspell \"**/*.*\"",
"lint": "npm-run-all -l -p \"lint:**\"",
"fix:js": "npm run lint:js -- --fix",
"fix:prettier": "npm run lint:prettier -- --write",
"fix": "npm-run-all -l fix:js fix:prettier",
"test:only": "cross-env NODE_ENV=test jest",

@@ -44,3 +48,2 @@ "test:watch": "npm run test:only -- --watch",

"dependencies": {
"abab": "^2.0.6",
"iconv-lite": "^0.6.3",

@@ -50,23 +53,24 @@ "source-map-js": "^1.0.2"

"devDependencies": {
"@babel/cli": "^7.19.3",
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@commitlint/cli": "^16.3.0",
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.0",
"@babel/preset-env": "^7.22.20",
"@commitlint/cli": "^17.7.2",
"@commitlint/config-conventional": "^16.2.4",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^29.1.2",
"babel-jest": "^29.7.0",
"cross-env": "^7.0.3",
"cspell": "^6.31.3",
"del": "^6.0.0",
"del-cli": "^4.0.1",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"husky": "^8.0.1",
"jest": "^29.1.2",
"lint-staged": "^12.4.1",
"memfs": "^3.4.7",
"eslint": "^8.50.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.28.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^13.3.0",
"memfs": "^3.5.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"prettier": "^2.8.8",
"standard-version": "^9.5.0",
"webpack": "^5.74.0"
"webpack": "^5.88.2"
},

@@ -73,0 +77,0 @@ "keywords": [

@@ -11,3 +11,3 @@ <div align="center">

[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]
[![discussion][discussion]][discussion-url]
[![size][size]][size-url]

@@ -170,5 +170,5 @@

[cover-url]: https://codecov.io/gh/webpack-contrib/source-map-loader
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
[discussion-url]: https://github.com/webpack/webpack/discussions
[size]: https://packagephobia.now.sh/badge?p=source-map-loader
[size-url]: https://packagephobia.now.sh/result?p=source-map-loader
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc