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

smart-source-map-loader

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-source-map-loader - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

20

lib/comment.js

@@ -8,5 +8,3 @@ "use strict";

exports.pathsFromURL = pathsFromURL;
var _util = require("./util");
const rDirective = '([@#][ \\t]+sourceMappingURL=([^\r\n]*[^\\s]+))';

@@ -18,2 +16,3 @@ const rCommentLine = `(\\/\\/${rDirective}[ \\t]*)`;

const rCommentEndMatch = new RegExp(rCommentEnd);
/**

@@ -25,13 +24,11 @@ * Parse code for source map comment.

*/
function parse(code) {
const m = code.match(rCommentEndMatch);
if (!m) {
return null;
} // eslint-disable-next-line prefer-destructuring
}
const footer = m[0]; // eslint-disable-next-line prefer-destructuring
// eslint-disable-next-line prefer-destructuring
const footer = m[0];
// eslint-disable-next-line prefer-destructuring
const comment = m[2];

@@ -49,2 +46,3 @@ const directive = m[4] || m[7];

}
/**

@@ -56,13 +54,9 @@ * Get possible paths from URL, decoded and not if different.

*/
function pathsFromURL(url) {
const decoded = (0, _util.decodeURISafe)(url);
if (decoded && decoded !== url) {
return [url, decoded];
}
return [url];
}
//# sourceMappingURL=comment.js.map
//# sourceMappingURL=comment.js.map

@@ -7,5 +7,3 @@ "use strict";

exports.Exception = void 0;
var _meta = require("./meta");
/**

@@ -23,6 +21,4 @@ * Exception class.

}
}
exports.Exception = Exception;
//# sourceMappingURL=exception.js.map
//# sourceMappingURL=exception.js.map

@@ -8,5 +8,3 @@ "use strict";

exports.default = _default;
var _meta = require("./meta");
Object.keys(_meta).forEach(function (key) {

@@ -23,21 +21,11 @@ if (key === "default" || key === "__esModule") return;

});
var _path = require("path");
var _loaderUtils = _interopRequireDefault(require("loader-utils"));
var _util = require("./util");
var _uri = require("./uri");
var _exception = require("./exception");
var _comment = require("./comment");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
/**

@@ -59,3 +47,2 @@ * Create resolver.

}
resolve(result);

@@ -66,3 +53,2 @@ });

});
return function (_x, _x2) {

@@ -73,2 +59,3 @@ return _ref.apply(this, arguments);

}
/**

@@ -80,4 +67,2 @@ * Create resolver multiple from a resolver.

*/
function createResolverMulti(resolver) {

@@ -90,9 +75,8 @@ return /*#__PURE__*/function () {

return yield resolver(context, request);
} catch (err) {// Do nothing.
} catch (err) {
// Do nothing.
}
}
return null;
});
return function (_x3, _x4) {

@@ -102,9 +86,8 @@ return _ref2.apply(this, arguments);

}();
} // eslint-disable-next-line import/no-default-export, jsdoc/require-jsdoc, no-unused-vars
}
// eslint-disable-next-line import/no-default-export, jsdoc/require-jsdoc, no-unused-vars
function _default(_x5, _x6, _x7) {
return _ref3.apply(this, arguments);
}
function _ref3() {

@@ -125,18 +108,17 @@ _ref3 = _asyncToGenerator(function* (source, map, meta) {

const resolver = createResolver(resolve);
const resolverMulti = createResolverMulti(resolver); // If passed a buffer then convert to a string or emit warning and skip.
const resolverMulti = createResolverMulti(resolver);
// If passed a buffer then convert to a string or emit warning and skip.
let sourceString = null;
try {
sourceString = (0, _util.stringOrBufferCast)(source, 'utf8');
} catch (err) {
emitWarning(new _exception.Exception(`Failed to cast source to string: ${err}`)); // eslint-disable-next-line prefer-rest-params
emitWarning(new _exception.Exception(`Failed to cast source to string: ${err}`));
// eslint-disable-next-line prefer-rest-params
callback(null, ...arguments);
return;
} // Parse source map comment or pass the arguments straight through.
}
// Parse source map comment or pass the arguments straight through.
const parsed = (0, _comment.parse)(sourceString);
if (!parsed) {

@@ -146,5 +128,5 @@ // eslint-disable-next-line prefer-rest-params

return;
} // If no source map requested, just output code without comment.
}
// If no source map requested, just output code without comment.
if (!sourceMap) {

@@ -154,12 +136,12 @@ callback(null, parsed.body);

}
let mapFile = null;
let mapInfo = null;
let mapCode = null; // Check if data URI.
let mapCode = null;
// Check if data URI.
if ((0, _util.isDataURI)(parsed.url)) {
mapInfo = (0, _util.stringAbbrev)(parsed.url, 64, '...'); // Attempt to parse URL as a data URI.
mapInfo = (0, _util.stringAbbrev)(parsed.url, 64, '...');
// Attempt to parse URL as a data URI.
const dataURI = (0, _uri.data)(parsed.url);
if (!dataURI) {

@@ -169,5 +151,5 @@ emitWarning(new _exception.Exception(`Failed to parse data URI: ${mapInfo}`));

return;
} // Attempt to decode source map content.
}
// Attempt to decode source map content.
try {

@@ -179,18 +161,23 @@ mapCode = dataURI.body().toString(dataURI.charset);

return;
} // Remember which file the source map came from.
}
// Remember which file the source map came from.
mapFile = resourcePath;
} else {
mapInfo = parsed.url; // Remove file protocol from the URL if present.
mapInfo = parsed.url;
const mapPath = parsed.url.replace(/^file:\/\//i, ''); // Create list of possible file paths.
// Remove file protocol from the URL if present.
const mapPath = parsed.url.replace(/^file:\/\//i, '');
// Create list of possible file paths.
// Compensates for comments that may not be encoded to spec.
const mapPaths = (0, _comment.pathsFromURL)(mapPath);
const mapPaths = (0, _comment.pathsFromURL)(mapPath); // Convert those paths to resolvable paths.
// Convert those paths to resolvable paths.
const mapPathsRequest = mapPaths.map(p => _loaderUtils.default.urlToRequest(p));
const mapPathsRequest = mapPaths.map(p => _loaderUtils.default.urlToRequest(p)); // Resolve the first one that exists or null.
// Resolve the first one that exists or null.
const resolved = yield resolverMulti(context, mapPathsRequest);
const resolved = yield resolverMulti(context, mapPathsRequest); // If file not resolved emit warning and skip.
// If file not resolved emit warning and skip.
if (!resolved) {

@@ -200,7 +187,8 @@ emitWarning(new _exception.Exception(`Failed to resolve source map: ${mapInfo}`));

return;
} // Add the file as a dependency.
}
// Add the file as a dependency.
addDependency(resolved);
addDependency(resolved); // Read the file or emit warning and skip.
// Read the file or emit warning and skip.
try {

@@ -212,13 +200,13 @@ mapCode = yield (0, _util.readFileAsync)(resolved, 'utf-8');

return;
} // Remember which file the source map came from.
}
// Remember which file the source map came from.
mapFile = resolved;
} // Get context of the file that has the source map.
}
// Get context of the file that has the source map.
const mapFileContext = (0, _path.dirname)(mapFile);
const mapFileContext = (0, _path.dirname)(mapFile); // Try to parse the map data.
// Try to parse the map data.
let mapData = null;
try {

@@ -230,7 +218,6 @@ mapData = JSON.parse(mapCode);

return;
} // Loop over the sections to ensure source content.
}
// Loop over the sections to ensure source content.
const mapMappings = (0, _util.sourceMapMappings)(mapData);
for (const mapping of mapMappings) {

@@ -240,28 +227,28 @@ const {

} = mapping;
if (!sources) {
continue;
}
const sourceRoot = mapping.sourceRoot || '.';
const sourceRoot = mapping.sourceRoot || '.'; // Get list of sources or create empty list.
// Get list of sources or create empty list.
const sourcesContent = mapping.sourcesContent = mapping.sourcesContent || [];
const sourcesContent = mapping.sourcesContent = mapping.sourcesContent || []; // Loop over the sources looking for missing content.
// Loop over the sources looking for missing content.
for (let i = 0; i < sources.length; i++) {
const source = sources[i];
const sourceContent = sourcesContent[i]; // If has content or source is a data URI, nothing to read.
const sourceContent = sourcesContent[i];
if ( // eslint-disable-next-line no-undefined
// If has content or source is a data URI, nothing to read.
if (
// eslint-disable-next-line no-undefined
sourceContent !== null && sourceContent !== undefined || (0, _util.isDataURI)(source)) {
continue;
} // Locate the source file.
}
// Locate the source file.
const sourcePath = `${sourceRoot}/${source}`;
const sourceRequest = _loaderUtils.default.urlToRequest(sourcePath);
const sourceRequest = _loaderUtils.default.urlToRequest(sourcePath); // Resolve source file or emit warning and skip.
// Resolve source file or emit warning and skip.
let resolved = null;
try {

@@ -275,9 +262,9 @@ // eslint-disable-next-line no-await-in-loop

return;
} // Add the file as a dependency.
}
// Add the file as a dependency.
addDependency(resolved);
addDependency(resolved); // Read the file or emit warning and skip.
// Read the file or emit warning and skip.
let sourceCode = null;
try {

@@ -291,15 +278,17 @@ // eslint-disable-next-line no-await-in-loop

return;
} // Add source content to the list.
}
// Add source content to the list.
sourcesContent[i] = sourceCode;
}
} // Get the path to the source map, relative if possible.
}
// Get the path to the source map, relative if possible.
const mapFilePath = (0, _util.pathRelativeIfSub)(rootContext, mapFile);
const mapFilePath = (0, _util.pathRelativeIfSub)(rootContext, mapFile); // Rebase the source map base to the source map file.
// Rebase the source map base to the source map file.
// This way webpack will have the real path to the source file.
(0, _util.sourceMapRebase)(mapData, mapFilePath.replace(/\\/g, '/'));
(0, _util.sourceMapRebase)(mapData, mapFilePath.replace(/\\/g, '/')); // All good, pass the body and parsed source map out.
// All good, pass the body and parsed source map out.
callback(null, parsed.body, mapData);

@@ -309,2 +298,2 @@ });

}
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map

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

// This file contains compile-time defined variables.
const NAME = '@NAME@';
const NAME = "smart-source-map-loader";
exports.NAME = NAME;
const VERSION = '@VERSION@';
const VERSION = "1.3.2";
exports.VERSION = VERSION;
//# sourceMappingURL=meta.js.map
//# sourceMappingURL=meta.js.map

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

exports.decodePercents = decodePercents;
/**

@@ -19,7 +18,8 @@ * Decode percents in string.

return decodeURIComponent(s);
} catch (err) {// Do nothing.
} catch (err) {
// Do nothing.
}
return null;
}
/**

@@ -31,11 +31,7 @@ * Parse a data URI.

*/
function data(uri) {
const m1 = uri.match(/^data:([^,]*),([\s\S]*)$/iu);
if (!m1) {
return null;
}
const [, mediaInfo, data] = m1;

@@ -53,3 +49,2 @@ const base64 = /;base64$/iu.test(mediaInfo);

data,
/**

@@ -63,5 +58,4 @@ * Get body.

}
};
}
//# sourceMappingURL=uri.js.map
//# sourceMappingURL=uri.js.map

@@ -17,10 +17,8 @@ "use strict";

exports.stringOrBufferCast = stringOrBufferCast;
var _path = require("path");
var _fs = require("fs");
const rURL = /^([a-z][a-z0-9.-]*:\/?\/?[^/]*|\/\/[^/]*|)([^?#]*)(.*)$/i;
const rProto = /^[a-z][a-z0-9-.]*:/i;
const rDataURI = /^data:/i;
/**

@@ -32,6 +30,6 @@ * Check if absolute URL.

*/
function isAbsoluteURL(uri) {
return uri[0] === '/' || rProto.test(uri);
}
/**

@@ -43,7 +41,6 @@ * Check if data URI.

*/
function isDataURI(uri) {
return rDataURI.test(uri);
}
/**

@@ -55,28 +52,23 @@ * Clean a URL path of extra dot notation.

*/
function pathResolve(path) {
let p = path; // Multiple slashes to slash.
p = p.replace(/\/\/+/g, '/'); // Dot slash.
p = p.replace(/^(\.\/)+/, ''); // Trailing slash dot to slash.
p = p.replace(/\/\.$/, '/'); // Dot slash path components.
let p = path;
// Multiple slashes to slash.
p = p.replace(/\/\/+/g, '/');
// Dot slash.
p = p.replace(/^(\.\/)+/, '');
// Trailing slash dot to slash.
p = p.replace(/\/\.$/, '/');
// Dot slash path components.
p = p.replace(/\/(\.\/)+/g, '/');
for (;;) {
// Leading, middle, and trailing, dot dot slash resolving.
const v = p.replace(/(^|\/)(?!\.\.)[^/]+\/\.\.(\/|$)/g, '$1');
if (v === p) {
break;
}
p = v;
}
return p === '.' ? '' : p;
}
/**

@@ -89,4 +81,2 @@ * Rebase a URL path.

*/
function rebaseURL(from, to) {

@@ -96,3 +86,2 @@ if (isAbsoluteURL(to) || isDataURI(to)) {

}
const [, fb, fp] = from.match(rURL);

@@ -103,2 +92,3 @@ const [,, tp, te] = to.match(rURL);

}
/**

@@ -110,4 +100,2 @@ * Get source mappings maps.

*/
function sourceMapMappings(map) {

@@ -119,2 +107,3 @@ const {

}
/**

@@ -126,4 +115,2 @@ * Rebase source mappings sourceRoot.

*/
function sourceMapRebase(map, base) {

@@ -134,2 +121,3 @@ for (const mapping of sourceMapMappings(map)) {

}
/**

@@ -142,4 +130,2 @@ * Get relative path if a subpath, else unchaged.

*/
function pathRelativeIfSub(from, to) {

@@ -149,10 +135,9 @@ if (from === to) {

}
if (!from) {
return to;
}
const pre = (0, _path.join)(from, '_').replace(/_$/, '');
return to.substring(0, pre.length) === pre ? to.substring(pre.length) : to;
}
/**

@@ -163,10 +148,9 @@ * Abbreviate a string if too long.

* @param {number} max String max length.
* @param {string} [suffix=''] Suffix to use if too long.
* @param {string} suffix Suffix to use if too long.
* @returns {string} Abbreviated or original string.
*/
function stringAbbrev(str, max, suffix = '') {
return str.length > max ? str.substring(0, max - suffix.length) + suffix : str;
}
/**

@@ -178,12 +162,11 @@ * Decode URL returning null on error.

*/
function decodeURISafe(str) {
try {
return decodeURI(str);
} catch (err) {// Do nothing.
} catch (err) {
// Do nothing.
}
return null;
}
/**

@@ -196,4 +179,2 @@ * Convert string or Buffer to string.

*/
function stringOrBufferCast(data, ...args) {

@@ -203,5 +184,5 @@ if (typeof data === 'string') {

}
return data.toString(...args);
}
/**

@@ -214,4 +195,2 @@ * Read a file asyncronousely.

*/
function readFileAsync(path, options) {

@@ -224,3 +203,2 @@ const r = new Promise((resolve, reject) => {

}
resolve(data);

@@ -231,2 +209,2 @@ });

}
//# sourceMappingURL=util.js.map
//# sourceMappingURL=util.js.map
{
"name": "smart-source-map-loader",
"description": "A Smart Source Map Loader for Webpack",
"version": "1.3.1",
"version": "1.3.2",
"keywords": [

@@ -19,3 +19,3 @@ "source-map",

"author": "Alexander O'Mara",
"copyright": "Copyright (c) 2018-2022 Alexander O'Mara",
"copyright": "Copyright (c) 2018-2023 Alexander O'Mara",
"license": "MPL-2.0",

@@ -29,11 +29,10 @@ "main": "lib/index",

"scripts": {
"clean": "gulp clean",
"lint": "gulp lint",
"format": "gulp format",
"formatted": "gulp formatted",
"build": "gulp build",
"test": "gulp test",
"all": "gulp all",
"watch": "gulp watch",
"prepack": "gulp prepack"
"clean": "rimraf *.log* lib",
"lint": "eslint . --ext js,mjs",
"format": "prettier -w .",
"formatted": "prettier -c .",
"build": "babel src --out-dir lib --source-maps true",
"test": "node spec/runner.js lib",
"all": "npm run clean && npm run build && npm run test && npm run lint && npm run formatted",
"prepack": "npm run clean && npm run build"
},

@@ -44,35 +43,19 @@ "peerDependencies": {

"dependencies": {
"loader-utils": "^3.2.0"
"loader-utils": "^3.2.1"
},
"devDependencies": {
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/register": "^7.18.6",
"babel-loader": "^8.2.5",
"del": "^6.1.1",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.3",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-filter": "^7.0.0",
"gulp-insert": "^0.5.0",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.1.3",
"gulp-sourcemaps": "^3.0.0",
"jasmine": "3.6.1",
"jasmine-core": "^3.7.1",
"jasmine-spec-reporter": "^7.0.0",
"@babel/cli": "^7.22.10",
"@babel/core": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"babel-plugin-search-and-replace": "^1.1.1",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsdoc": "^46.4.6",
"memory-fs": "^0.5.0",
"node-require-function": "^1.2.0",
"prettier": "^2.7.1",
"promise.prototype.finally": "^3.1.3",
"pump": "^3.0.0",
"source-map-support": "^0.5.21",
"webpack": "^5.73.0",
"webpack-4-0-0": "npm:webpack@4.0.0",
"webpack-4-46-0": "npm:webpack@4.46.0",
"webpack-5-0-0": "npm:webpack@5.0.0"
"prettier": "^3.0.1",
"rimraf": "^5.0.1",
"source-map-support": "^0.5.21"
}
}

@@ -72,3 +72,3 @@ # Smart Source Map Loader

Copyright (c) 2018-2022 Alexander O'Mara
Copyright (c) 2018-2023 Alexander O'Mara

@@ -75,0 +75,0 @@ Licensed under the Mozilla Public License, v. 2.0.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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