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

sorcery

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sorcery - npm Package Compare versions

Comparing version 0.6.4 to 0.6.5

4

CHANGELOG.md
# changelog
## 0.6.5
* Use rollup-babel
## 0.6.4

@@ -4,0 +8,0 @@

724

dist/sorcery.js
'use strict';
var path = require('path');
var sander = require('sander');
var path = require('path');
var crc32 = require('buffer-crc32');
crc32 = 'default' in crc32 ? crc32['default'] : crc32;
var _SOURCEMAPPING_URL = 'sourceMa';
_SOURCEMAPPING_URL += 'ppingURL';
var babelHelpers_classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
function sourcemapComment(url, dest) {
var ext = path.extname(dest);
url = encodeURI(url);
var charToInteger = {};
var integerToChar = {};
if (ext === '.css') {
return '\n/*# ' + _SOURCEMAPPING_URL + '=' + url + ' */\n';
}
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split('').forEach(function (char, i) {
charToInteger[char] = i;
integerToChar[i] = char;
});
return '\n//# ' + _SOURCEMAPPING_URL + '=' + url + '\n';
}
function decode(string) {
var result = [],
len = string.length,
i,
hasContinuationBit,
shift = 0,
value = 0,
integer,
shouldNegate;
var SOURCEMAP_COMMENT = new RegExp('\n*(?:' + ('\\/\\/[@#]\\s*' + _SOURCEMAPPING_URL + '=([^\'"]+)|') + ( // js
'\\/\\*#?\\s*' + _SOURCEMAPPING_URL + '=([^\'"]+)\\s\\*\\/)') + // css
'\\s*$', 'g');
for (i = 0; i < len; i += 1) {
integer = charToInteger[string[i]];
function processWriteOptions(dest, chain, options) {
var resolved = path.resolve(dest);
if (integer === undefined) {
throw new Error('Invalid character (' + string[i] + ')');
}
var map = chain.apply({
includeContent: options.includeContent,
base: options.base ? path.resolve(options.base) : path.dirname(resolved)
});
hasContinuationBit = integer & 32;
var url = options.inline ? map.toUrl() : (options.absolutePath ? resolved : path.basename(resolved)) + '.map';
integer &= 31;
value += integer << shift;
// TODO shouldn't url be relative?
var content = chain.node.content.replace(SOURCEMAP_COMMENT, '') + sourcemapComment(url, resolved);
if (hasContinuationBit) {
shift += 5;
} else {
shouldNegate = value & 1;
value >>= 1;
return { resolved: resolved, content: content, map: map };
}
result.push(shouldNegate ? -value : value);
function slash(path) {
return typeof path === 'string' ? path.replace(/\\/g, '/') : path;
}
// reset
value = shift = 0;
}
}
/**
* Encodes a string as base64
* @param {string} str - the string to encode
* @returns {string}
*/
function btoa(str) {
return new Buffer(str).toString('base64');
return result;
}
function __classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function encode(value) {
var result, i;
var SourceMap = (function () {
function SourceMap(properties) {
__classCallCheck(this, SourceMap);
this.version = 3;
this.file = properties.file;
this.sources = properties.sources;
this.sourcesContent = properties.sourcesContent;
this.names = properties.names;
this.mappings = properties.mappings;
if (typeof value === 'number') {
result = encodeInteger(value);
} else {
result = '';
for (i = 0; i < value.length; i += 1) {
result += encodeInteger(value[i]);
}
}
SourceMap.prototype.toString = function toString() {
return JSON.stringify(this);
};
return result;
}
SourceMap.prototype.toUrl = function toUrl() {
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
};
function encodeInteger(num) {
var result = '',
clamped;
return SourceMap;
})();
var integerToChar = {};
var charToInteger = {};
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
charToInteger[ char ] = i;
integerToChar[ i ] = char;
});
function encodeInteger ( num ) {
var result = '', clamped;
if ( num < 0 ) {
num = ( -num << 1 ) | 1;
if (num < 0) {
num = -num << 1 | 1;
} else {

@@ -104,8 +89,8 @@ num <<= 1;

if ( num > 0 ) {
if (num > 0) {
clamped |= 32;
}
result += integerToChar[ clamped ];
} while ( num > 0 );
result += integerToChar[clamped];
} while (num > 0);

@@ -115,270 +100,4 @@ return result;

function encode ( value ) {
var result, i;
if ( typeof value === 'number' ) {
result = encodeInteger( value );
} else {
result = '';
for ( i = 0; i < value.length; i += 1 ) {
result += encodeInteger( value[i] );
}
}
return result;
}
function encodeMappings(decoded) {
var offsets = {
generatedCodeColumn: 0,
sourceFileIndex: 0, // second field
sourceCodeLine: 0, // third field
sourceCodeColumn: 0, // fourth field
nameIndex: 0 // fifth field
};
return decoded.map(function (line) {
offsets.generatedCodeColumn = 0; // first field - reset each time
return line.map(encodeSegment).join(',');
}).join(';');
function encodeSegment(segment) {
if (!segment.length) {
return segment;
}
var result = new Array(segment.length);
result[0] = segment[0] - offsets.generatedCodeColumn;
offsets.generatedCodeColumn = segment[0];
if (segment.length === 1) {
// only one field!
return result;
}
result[1] = segment[1] - offsets.sourceFileIndex;
result[2] = segment[2] - offsets.sourceCodeLine;
result[3] = segment[3] - offsets.sourceCodeColumn;
offsets.sourceFileIndex = segment[1];
offsets.sourceCodeLine = segment[2];
offsets.sourceCodeColumn = segment[3];
if (segment.length === 5) {
result[4] = segment[4] - offsets.nameIndex;
offsets.nameIndex = segment[4];
}
return encode(result);
}
}
function tally(nodes, stat) {
return nodes.reduce(function (total, node) {
return total + node._stats[stat];
}, 0);
}
function ___classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Chain = (function () {
function Chain(node, sourcesContentByPath) {
___classCallCheck(this, Chain);
this.node = node;
this.sourcesContentByPath = sourcesContentByPath;
this._stats = {};
}
Chain.prototype.stat = function stat() {
return {
selfDecodingTime: this._stats.decodingTime / 1e6,
totalDecodingTime: (this._stats.decodingTime + tally(this.node.sources, 'decodingTime')) / 1e6,
encodingTime: this._stats.encodingTime / 1e6,
tracingTime: this._stats.tracingTime / 1e6,
untraceable: this._stats.untraceable
};
};
Chain.prototype.apply = function apply() {
var _this = this;
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var allNames = [];
var allSources = [];
var applySegment = function (segment, result) {
if (segment.length < 4) return;
var traced = _this.node.sources[segment[1]].trace( // source
segment[2], // source code line
segment[3], // source code column
_this.node.map.names[segment[4]]);
if (!traced) {
_this._stats.untraceable += 1;
return;
}
var sourceIndex = allSources.indexOf(traced.source);
if (! ~sourceIndex) {
sourceIndex = allSources.length;
allSources.push(traced.source);
}
var newSegment = [segment[0], // generated code column
sourceIndex, traced.line - 1, traced.column];
if (traced.name) {
var nameIndex = allNames.indexOf(traced.name);
if (! ~nameIndex) {
nameIndex = allNames.length;
allNames.push(traced.name);
}
newSegment[4] = nameIndex;
}
result[result.length] = newSegment;
};
// Trace mappings
var tracingStart = process.hrtime();
var i = this.node.mappings.length;
var resolved = new Array(i);
var j = undefined,
line = undefined,
result = undefined;
while (i--) {
line = this.node.mappings[i];
resolved[i] = result = [];
for (j = 0; j < line.length; j += 1) {
applySegment(line[j], result);
}
}
var tracingTime = process.hrtime(tracingStart);
this._stats.tracingTime = 1e9 * tracingTime[0] + tracingTime[1];
// Encode mappings
var encodingStart = process.hrtime();
var mappings = encodeMappings(resolved);
var encodingTime = process.hrtime(encodingStart);
this._stats.encodingTime = 1e9 * encodingTime[0] + encodingTime[1];
var includeContent = options.includeContent !== false;
return new SourceMap({
file: path.basename(this.node.file),
sources: allSources.map(function (source) {
return slash(path.relative(options.base || path.dirname(_this.node.file), source));
}),
sourcesContent: allSources.map(function (source) {
return includeContent ? _this.sourcesContentByPath[source] : null;
}),
names: allNames,
mappings: mappings
});
};
Chain.prototype.trace = function trace(oneBasedLineIndex, zeroBasedColumnIndex) {
return this.node.trace(oneBasedLineIndex - 1, zeroBasedColumnIndex, null);
};
Chain.prototype.write = function write(dest, options) {
if (typeof dest !== 'string') {
options = dest;
dest = this.node.file;
}
options = options || {};
var _processWriteOptions = processWriteOptions(dest, this, options);
var resolved = _processWriteOptions.resolved;
var content = _processWriteOptions.content;
var map = _processWriteOptions.map;
var promises = [sander.writeFile(resolved, content)];
if (!options.inline) {
promises.push(sander.writeFile(resolved + '.map', map.toString()));
}
return Promise.all(promises);
};
Chain.prototype.writeSync = function writeSync(dest, options) {
if (typeof dest !== 'string') {
options = dest;
dest = this.node.file;
}
options = options || {};
var _processWriteOptions2 = processWriteOptions(dest, this, options);
var resolved = _processWriteOptions2.resolved;
var content = _processWriteOptions2.content;
var map = _processWriteOptions2.map;
sander.writeFileSync(resolved, content);
if (!options.inline) {
sander.writeFileSync(resolved + '.map', map.toString());
}
};
return Chain;
})();
var cache = {};
function decode ( string ) {
var result = [],
len = string.length,
i,
hasContinuationBit,
shift = 0,
value = 0,
integer,
shouldNegate;
for ( i = 0; i < len; i += 1 ) {
integer = charToInteger[ string[i] ];
if ( integer === undefined ) {
throw new Error( 'Invalid character (' + string[i] + ')' );
}
hasContinuationBit = integer & 32;
integer &= 31;
value += integer << shift;
if ( hasContinuationBit ) {
shift += 5;
} else {
shouldNegate = value & 1;
value >>= 1;
result.push( shouldNegate ? -value : value );
// reset
value = shift = 0;
}
}
return result;
}
function decodeSegments(encodedSegments) {

@@ -462,3 +181,2 @@ var i = encodedSegments.length;

/**

@@ -473,8 +191,8 @@ * Decodes a base64 string

// this looks ridiculous, but it prevents sourcemap tooling from mistaking
// this for an actual sourceMappingURL
var SOURCEMAPPING_URL = 'sourceMa';
SOURCEMAPPING_URL += 'ppingURL';
var SOURCEMAPPING_URL$1 = 'sourceMa';
SOURCEMAPPING_URL$1 += 'ppingURL';
var SOURCEMAPPING_URL$2 = SOURCEMAPPING_URL$1;

@@ -497,3 +215,3 @@ /**

if (!match) {
throw new Error(SOURCEMAPPING_URL + ' is not base64-encoded');
throw new Error(SOURCEMAPPING_URL$2 + ' is not base64-encoded');
}

@@ -519,3 +237,3 @@

// assume we want the last occurence
index = str.lastIndexOf(SOURCEMAPPING_URL + '=');
index = str.lastIndexOf(SOURCEMAPPING_URL$2 + '=');

@@ -556,16 +274,2 @@ if (index === -1) {

function getContent(node, sourcesContentByPath) {
if (node.file in sourcesContentByPath) {
node.content = sourcesContentByPath[node.file];
}
if (!node.content) {
return sander.readFile(node.file).then(String);
}
return sander.Promise.resolve(node.content);
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Node = (function () {

@@ -575,5 +279,4 @@ function Node(_ref) {

var content = _ref.content;
babelHelpers_classCallCheck(this, Node);
_classCallCheck(this, Node);
this.file = file ? path.resolve(file) : null;

@@ -747,2 +450,296 @@ this.content = content || null; // sometimes exists in sourcesContent, sometimes doesn't

function getContent(node, sourcesContentByPath) {
if (node.file in sourcesContentByPath) {
node.content = sourcesContentByPath[node.file];
}
if (!node.content) {
return sander.readFile(node.file).then(String);
}
return sander.Promise.resolve(node.content);
}
/**
* Encodes a string as base64
* @param {string} str - the string to encode
* @returns {string}
*/
function btoa(str) {
return new Buffer(str).toString('base64');
}
var SourceMap = (function () {
function SourceMap(properties) {
babelHelpers_classCallCheck(this, SourceMap);
this.version = 3;
this.file = properties.file;
this.sources = properties.sources;
this.sourcesContent = properties.sourcesContent;
this.names = properties.names;
this.mappings = properties.mappings;
}
SourceMap.prototype.toString = function toString() {
return JSON.stringify(this);
};
SourceMap.prototype.toUrl = function toUrl() {
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
};
return SourceMap;
})();
function encodeMappings(decoded) {
var offsets = {
generatedCodeColumn: 0,
sourceFileIndex: 0, // second field
sourceCodeLine: 0, // third field
sourceCodeColumn: 0, // fourth field
nameIndex: 0 // fifth field
};
return decoded.map(function (line) {
offsets.generatedCodeColumn = 0; // first field - reset each time
return line.map(encodeSegment).join(',');
}).join(';');
function encodeSegment(segment) {
if (!segment.length) {
return segment;
}
var result = new Array(segment.length);
result[0] = segment[0] - offsets.generatedCodeColumn;
offsets.generatedCodeColumn = segment[0];
if (segment.length === 1) {
// only one field!
return result;
}
result[1] = segment[1] - offsets.sourceFileIndex;
result[2] = segment[2] - offsets.sourceCodeLine;
result[3] = segment[3] - offsets.sourceCodeColumn;
offsets.sourceFileIndex = segment[1];
offsets.sourceCodeLine = segment[2];
offsets.sourceCodeColumn = segment[3];
if (segment.length === 5) {
result[4] = segment[4] - offsets.nameIndex;
offsets.nameIndex = segment[4];
}
return encode(result);
}
}
function slash(path) {
return typeof path === 'string' ? path.replace(/\\/g, '/') : path;
}
var SOURCEMAPPING_URL = 'sourceMa';
SOURCEMAPPING_URL += 'ppingURL';
var SOURCEMAP_COMMENT = new RegExp('\n*(?:' + ('\\/\\/[@#]\\s*' + SOURCEMAPPING_URL + '=([^\'"]+)|') + ( // js
'\\/\\*#?\\s*' + SOURCEMAPPING_URL + '=([^\'"]+)\\s\\*\\/)') + // css
'\\s*$', 'g');
var Chain = (function () {
function Chain(node, sourcesContentByPath) {
babelHelpers_classCallCheck(this, Chain);
this.node = node;
this.sourcesContentByPath = sourcesContentByPath;
this._stats = {};
}
Chain.prototype.stat = function stat() {
return {
selfDecodingTime: this._stats.decodingTime / 1e6,
totalDecodingTime: (this._stats.decodingTime + tally(this.node.sources, 'decodingTime')) / 1e6,
encodingTime: this._stats.encodingTime / 1e6,
tracingTime: this._stats.tracingTime / 1e6,
untraceable: this._stats.untraceable
};
};
Chain.prototype.apply = function apply() {
var _this = this;
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var allNames = [];
var allSources = [];
var applySegment = function (segment, result) {
if (segment.length < 4) return;
var traced = _this.node.sources[segment[1]].trace( // source
segment[2], // source code line
segment[3], // source code column
_this.node.map.names[segment[4]]);
if (!traced) {
_this._stats.untraceable += 1;
return;
}
var sourceIndex = allSources.indexOf(traced.source);
if (! ~sourceIndex) {
sourceIndex = allSources.length;
allSources.push(traced.source);
}
var newSegment = [segment[0], // generated code column
sourceIndex, traced.line - 1, traced.column];
if (traced.name) {
var nameIndex = allNames.indexOf(traced.name);
if (! ~nameIndex) {
nameIndex = allNames.length;
allNames.push(traced.name);
}
newSegment[4] = nameIndex;
}
result[result.length] = newSegment;
};
// Trace mappings
var tracingStart = process.hrtime();
var i = this.node.mappings.length;
var resolved = new Array(i);
var j = undefined,
line = undefined,
result = undefined;
while (i--) {
line = this.node.mappings[i];
resolved[i] = result = [];
for (j = 0; j < line.length; j += 1) {
applySegment(line[j], result);
}
}
var tracingTime = process.hrtime(tracingStart);
this._stats.tracingTime = 1e9 * tracingTime[0] + tracingTime[1];
// Encode mappings
var encodingStart = process.hrtime();
var mappings = encodeMappings(resolved);
var encodingTime = process.hrtime(encodingStart);
this._stats.encodingTime = 1e9 * encodingTime[0] + encodingTime[1];
var includeContent = options.includeContent !== false;
return new SourceMap({
file: path.basename(this.node.file),
sources: allSources.map(function (source) {
return slash(path.relative(options.base || path.dirname(_this.node.file), source));
}),
sourcesContent: allSources.map(function (source) {
return includeContent ? _this.sourcesContentByPath[source] : null;
}),
names: allNames,
mappings: mappings
});
};
Chain.prototype.trace = function trace(oneBasedLineIndex, zeroBasedColumnIndex) {
return this.node.trace(oneBasedLineIndex - 1, zeroBasedColumnIndex, null);
};
Chain.prototype.write = function write(dest, options) {
if (typeof dest !== 'string') {
options = dest;
dest = this.node.file;
}
options = options || {};
var _processWriteOptions = processWriteOptions(dest, this, options);
var resolved = _processWriteOptions.resolved;
var content = _processWriteOptions.content;
var map = _processWriteOptions.map;
var promises = [sander.writeFile(resolved, content)];
if (!options.inline) {
promises.push(sander.writeFile(resolved + '.map', map.toString()));
}
return Promise.all(promises);
};
Chain.prototype.writeSync = function writeSync(dest, options) {
if (typeof dest !== 'string') {
options = dest;
dest = this.node.file;
}
options = options || {};
var _processWriteOptions2 = processWriteOptions(dest, this, options);
var resolved = _processWriteOptions2.resolved;
var content = _processWriteOptions2.content;
var map = _processWriteOptions2.map;
sander.writeFileSync(resolved, content);
if (!options.inline) {
sander.writeFileSync(resolved + '.map', map.toString());
}
};
return Chain;
})();
function processWriteOptions(dest, chain, options) {
var resolved = path.resolve(dest);
var map = chain.apply({
includeContent: options.includeContent,
base: options.base ? path.resolve(options.base) : path.dirname(resolved)
});
var url = options.inline ? map.toUrl() : (options.absolutePath ? resolved : path.basename(resolved)) + '.map';
// TODO shouldn't url be relative?
var content = chain.node.content.replace(SOURCEMAP_COMMENT, '') + sourcemapComment(url, resolved);
return { resolved: resolved, content: content, map: map };
}
function tally(nodes, stat) {
return nodes.reduce(function (total, node) {
return total + node._stats[stat];
}, 0);
}
function sourcemapComment(url, dest) {
var ext = path.extname(dest);
url = encodeURI(url);
if (ext === '.css') {
return '\n/*# ' + SOURCEMAPPING_URL + '=' + url + ' */\n';
}
return '\n//# ' + SOURCEMAPPING_URL + '=' + url + '\n';
}
function load(file, options) {

@@ -797,3 +794,2 @@ var _init = init(file, options);

exports.load = load;
exports.loadSync = loadSync;
//# sourceMappingURL=sorcery.js.map
exports.loadSync = loadSync;
{
"name": "sorcery",
"description": "Resolve a chain of sourcemaps back to the original source",
"version": "0.6.4",
"version": "0.6.5",
"author": "Rich Harris",

@@ -21,8 +21,7 @@ "repository": "https://github.com/Rich-Harris/sorcery",

"coffee-script": "^1.9.2",
"eslint": "^1.5.1",
"eslint": "^1.6.0",
"esperanto": "^0.7.5",
"gobble": "^0.10.1",
"gobble-babel": "^5.0.0",
"gobble-cli": "^0.5.0",
"gobble-rollup": "^0.10.0",
"gobble-rollup-babel": "^0.5.0",
"istanbul": "^0.3.22",

@@ -29,0 +28,0 @@ "less": "^2.5.0",

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