Socket
Socket
Sign inDemoInstall

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.5.5 to 0.6.0

4

CHANGELOG.md
# changelog
## 0.6.0
* Use [rollup](https://github.com/rich-harris/rollup) for building, instead of esperanto
## 0.5.5

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

598

dist/sorcery.js
'use strict';
var sander = require('sander');
var path = require('path');
var path__default = ('default' in path ? path['default'] : path);
var sander = require('sander');
var sander__default = ('default' in sander ? sander['default'] : sander);
var buffer_crc32 = require('buffer-crc32');
var vlq = require('vlq');
var crc32 = require('buffer-crc32');
var SOURCEMAPPING_URL = 'sourceMa';
SOURCEMAPPING_URL += 'ppingURL';
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';
}
var SOURCEMAP_COMMENT = new RegExp('\n*(?:' + ('\\/\\/[@#]\\s*' + SOURCEMAPPING_URL + '=([^\'"]+)|') + ( // js
'\\/\\*#?\\s*' + SOURCEMAPPING_URL + '=([^\'"]+)\\s\\*\\/)') + // css
'\\s*$', 'g'); // js
function btoa(str) {
return new Buffer(str).toString('base64');
}var __classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
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;
}
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 vlq.encode(result);
}
}
function tally(nodes, stat) {
return nodes.reduce(function (total, node) {
return total + node._stats[stat];
}, 0);
}
var ___classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };// css
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 / 1000000,
totalDecodingTime: (this._stats.decodingTime + tally(this.node.sources, 'decodingTime')) / 1000000,
encodingTime: this._stats.encodingTime / 1000000,
tracingTime: this._stats.tracingTime / 1000000,
untraceable: this._stats.untraceable
};
};
Chain.prototype.apply = function apply() {
var _this = this;
var options = arguments[0] === undefined ? {} : arguments[0];
var allNames = [];
var allSources = [];
var applySegment = function (segment, result) {
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 = 1000000000 * tracingTime[0] + tracingTime[1];
// Encode mappings
var encodingStart = process.hrtime();
var mappings = encodeMappings(resolved);
var encodingTime = process.hrtime(encodingStart);
this._stats.encodingTime = 1000000000 * encodingTime[0] + encodingTime[1];
var includeContent = options.includeContent !== false;
return new SourceMap({
file: path.basename(this.node.file),
sources: allSources.map(function (source) {
return 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 || {};
dest = path.resolve(dest);
var map = this.apply({
includeContent: options.includeContent,
base: options.base ? path.resolve(options.base) : path.dirname(dest)
});
var url = options.inline ? map.toUrl() : (options.absolutePath ? dest : path.basename(dest)) + '.map';
var content = this.node.content.replace(SOURCEMAP_COMMENT, '') + sourcemapComment(url, dest);
var promises = [sander.writeFile(dest, content)];
if (!options.inline) {
promises.push(sander.writeFile(dest + '.map', map.toString()));
}
return Promise.all(promises);
};
return Chain;
})(); // source
function resolveSourcePath(node, sourceRoot, source) {
return path.resolve(path.dirname(node.file), sourceRoot || '', source);
}
var cache = {};

@@ -23,3 +265,3 @@

function decodeMappings(mappings) {
var checksum = buffer_crc32(mappings);
var checksum = crc32(mappings);

@@ -91,24 +333,5 @@ if (!cache[checksum]) {

/**
* Decodes a base64 string
* @param {string} base64 - the string to decode
* @returns {string}
*/
function atob(base64) {
return new Buffer(base64, 'base64').toString('utf8');
}
/**
* Turns a sourceMappingURL into a sourcemap
* @param {string} url - the URL (i.e. sourceMappingURL=url). Can
be a base64-encoded data URI
* @param {string} base - the URL against which relative URLS
should be resolved
* @param {boolean} sync - if `true`, return a promise, otherwise
return the sourcemap
* @returns {object} - a version 3 sourcemap
*/
function getMapFromUrl(url, base, sync) {

@@ -124,11 +347,11 @@ if (/^data/.test(url)) {

var map = JSON.parse(json);
return sync ? map : sander__default.Promise.resolve(map);
return sync ? map : sander.Promise.resolve(map);
}
url = path__default.resolve(path__default.dirname(base), decodeURI(url));
url = path.resolve(path.dirname(base), decodeURI(url));
if (sync) {
return JSON.parse(sander__default.readFileSync(url).toString());
return JSON.parse(sander.readFileSync(url).toString());
} else {
return sander__default.readFile(url).then(String).then(JSON.parse);
return sander.readFile(url).then(String).then(JSON.parse);
}

@@ -160,3 +383,2 @@ }

}
function getMap(node, sourceMapByPath, sync) {

@@ -178,6 +400,16 @@ if (node.file in sourceMapByPath) {

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

@@ -188,5 +420,5 @@ function Node(_ref) {

Node___classCallCheck(this, Node);
_classCallCheck(this, Node);
this.file = file ? path__default.resolve(file) : null;
this.file = file ? path.resolve(file) : null;
this.content = content || null; // sometimes exists in sourcesContent, sometimes doesn't

@@ -241,3 +473,3 @@

});
return Node__Promise.all(promises);
return sander.Promise.all(promises);
});

@@ -251,3 +483,3 @@ });

if (!this.content) {
this.content = sourcesContentByPath[this.file] = sander__default.readFileSync(this.file).toString();
this.content = sourcesContentByPath[this.file] = sander.readFileSync(this.file).toString();
}

@@ -347,273 +579,30 @@

return Node;
})();
})(); // 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__default.readFile(node.file).then(String);
}
return Node__Promise.resolve(node.content);
}
function init(file) {
var options = arguments[1] === undefined ? {} : arguments[1];
function resolveSourcePath(node, sourceRoot, source) {
return path__default.resolve(path__default.dirname(node.file), sourceRoot || '', source);
}
var node = new Node({ file: file });
/**
* Encodes a string as base64
* @param {string} str - the string to encode
* @returns {string}
*/
var sourcesContentByPath = {};
var sourceMapByPath = {};
function btoa(str) {
return new Buffer(str).toString('base64');
}
var SourceMap___classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
var SourceMap = (function () {
function SourceMap(properties) {
SourceMap___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 (options.content) {
Object.keys(options.content).forEach(function (key) {
sourcesContentByPath[path.resolve(key)] = options.content[key];
});
}
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 vlq.encode(result);
}
}
var Chain___classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
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) {
Chain___classCallCheck(this, Chain);
this.node = node;
this.sourcesContentByPath = sourcesContentByPath;
this._stats = {};
}
Chain.prototype.stat = function stat() {
return {
selfDecodingTime: this._stats.decodingTime / 1000000,
totalDecodingTime: (this._stats.decodingTime + tally(this.node.sources, 'decodingTime')) / 1000000,
encodingTime: this._stats.encodingTime / 1000000,
tracingTime: this._stats.tracingTime / 1000000,
untraceable: this._stats.untraceable
};
};
Chain.prototype.apply = function apply() {
var _this = this;
var options = arguments[0] === undefined ? {} : arguments[0];
var allNames = [];
var allSources = [];
var applySegment = function (segment, result) {
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 = 1000000000 * tracingTime[0] + tracingTime[1];
// Encode mappings
var encodingStart = process.hrtime();
var mappings = encodeMappings(resolved);
var encodingTime = process.hrtime(encodingStart);
this._stats.encodingTime = 1000000000 * encodingTime[0] + encodingTime[1];
var includeContent = options.includeContent !== false;
return new SourceMap({
file: path.basename(this.node.file),
sources: allSources.map(function (source) {
return 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
if (options.sourcemaps) {
Object.keys(options.sourcemaps).forEach(function (key) {
sourceMapByPath[path.resolve(key)] = options.sourcemaps[key];
});
};
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 || {};
dest = path.resolve(dest);
var map = this.apply({
includeContent: options.includeContent,
base: options.base ? path.resolve(options.base) : path.dirname(dest)
});
var url = options.inline ? map.toUrl() : (options.absolutePath ? dest : path.basename(dest)) + '.map';
var content = this.node.content.replace(SOURCEMAP_COMMENT, '') + sourcemapComment(url, dest);
var promises = [sander__default.writeFile(dest, content)];
if (!options.inline) {
promises.push(sander__default.writeFile(dest + '.map', map.toString()));
}
return Promise.all(promises);
};
return Chain;
})();
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';
return { node: node, sourcesContentByPath: sourcesContentByPath, sourceMapByPath: sourceMapByPath };
}
function load(file, options) {

@@ -644,27 +633,4 @@ var _init = init(file, options);

function init(file) {
var options = arguments[1] === undefined ? {} : arguments[1];
var node = new Node({ file: file });
var sourcesContentByPath = {};
var sourceMapByPath = {};
if (options.content) {
Object.keys(options.content).forEach(function (key) {
sourcesContentByPath[path.resolve(key)] = options.content[key];
});
}
if (options.sourcemaps) {
Object.keys(options.sourcemaps).forEach(function (key) {
sourceMapByPath[path.resolve(key)] = options.sourcemaps[key];
});
}
return { node: node, sourcesContentByPath: sourcesContentByPath, sourceMapByPath: sourceMapByPath };
}
exports.load = load;
exports.loadSync = loadSync;
//# sourceMappingURL=/www/sorcery/.gobble-build/02-esperantoBundle/1/sorcery.js.map
//# sourceMappingURL=sorcery.js.map
{
"name": "sorcery",
"description": "Resolve a chain of sourcemaps back to the original source",
"version": "0.5.5",
"version": "0.6.0",
"author": "Rich Harris",

@@ -24,3 +24,3 @@ "repository": "https://github.com/Rich-Harris/sorcery",

"gobble-cli": "^0.4.2",
"gobble-esperanto-bundle": "^0.1.7",
"gobble-rollup": "^0.1.1",
"less": "^2.5.0",

@@ -39,4 +39,5 @@ "mocha": "^2.1.0",

"pretest": "npm run build",
"prepare-tests": "node test/samples/prepare-tests.js",
"test": "mocha",
"prepublish": "npm run build"
"prepublish": "npm test"
},

@@ -43,0 +44,0 @@ "files": [

import { basename, dirname, extname, relative, resolve } from 'path';
import sander from 'sander';
import { writeFile } from 'sander';
import SourceMap from './SourceMap';

@@ -135,6 +135,6 @@ import encodeMappings from './utils/encodeMappings';

let promises = [ sander.writeFile( dest, content ) ];
let promises = [ writeFile( dest, content ) ];
if ( !options.inline ) {
promises.push( sander.writeFile( dest + '.map', map.toString() ) );
promises.push( writeFile( dest + '.map', map.toString() ) );
}

@@ -141,0 +141,0 @@

@@ -1,11 +0,9 @@

import path from 'path';
import sander from 'sander';
import { dirname, resolve } from 'path';
import { readFile, readFileSync, Promise } from 'sander';
import decodeMappings from './utils/decodeMappings';
import getMap from './utils/getMap';
const Promise = sander.Promise;
export default class Node {
constructor ({ file, content }) {
this.file = file ? path.resolve( file ) : null;
this.file = file ? resolve( file ) : null;
this.content = content || null; // sometimes exists in sourcesContent, sometimes doesn't

@@ -63,3 +61,3 @@

if ( !this.content ) {
this.content = sourcesContentByPath[ this.file ] = sander.readFileSync( this.file ).toString();
this.content = sourcesContentByPath[ this.file ] = readFileSync( this.file ).toString();
}

@@ -164,3 +162,3 @@

if ( !node.content ) {
return sander.readFile( node.file ).then( String );
return readFile( node.file ).then( String );
}

@@ -172,3 +170,3 @@

function resolveSourcePath ( node, sourceRoot, source ) {
return path.resolve( path.dirname( node.file ), sourceRoot || '', source );
return resolve( dirname( node.file ), sourceRoot || '', source );
}

@@ -1,3 +0,3 @@

import path from 'path';
import sander from 'sander';
import { dirname, resolve } from 'path';
import { readFile, readFileSync, Promise } from 'sander';
import atob from './atob';

@@ -25,12 +25,12 @@

const map = JSON.parse( json );
return sync ? map : sander.Promise.resolve( map );
return sync ? map : Promise.resolve( map );
}
url = path.resolve( path.dirname( base ), decodeURI( url ) );
url = resolve( dirname( base ), decodeURI( url ) );
if ( sync ) {
return JSON.parse( sander.readFileSync( url ).toString() );
return JSON.parse( readFileSync( url ).toString() );
} else {
return sander.readFile( url ).then( String ).then( JSON.parse );
return readFile( url ).then( String ).then( JSON.parse );
}
}

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