Comparing version 0.2.0 to 0.2.1
@@ -52,2 +52,8 @@ var path = require( 'path' ), | ||
} | ||
}).then( function () { | ||
if ( !self.isOriginalSource ) { | ||
return self; | ||
} | ||
return null; | ||
}); | ||
@@ -71,3 +77,6 @@ }, | ||
self.sources = self.map.sources.map( function ( source ) { | ||
return new Node( resolveSourcePath( self, source ) )._loadSync(); | ||
var node = new Node( resolveSourcePath( self, source ) ); | ||
node._loadSync(); | ||
return node; | ||
}); | ||
@@ -78,3 +87,3 @@ | ||
return this; | ||
return !this.isOriginalSource ? this : null; | ||
}, | ||
@@ -144,6 +153,6 @@ | ||
sources: sources.map( function ( source ) { | ||
return getRelativePath( self.file, source ); | ||
return getRelativePath( options.base || self.file, source ); | ||
}), | ||
sourcesContent: sources.map( function ( source ) { | ||
return options.includeContent ? self.sourcesContentByPath[ source ] : null; | ||
return includeContent ? self.sourcesContentByPath[ source ] : null; | ||
}), | ||
@@ -199,2 +208,27 @@ names: names, | ||
} | ||
}, | ||
write: function ( dest, options ) { | ||
var map, url, index, content; | ||
options = options || {}; | ||
dest = path.resolve( dest ); | ||
map = this.apply({ | ||
includeContent: options.includeContent, | ||
base: dest | ||
}); | ||
url = options.inline ? map.toUrl() : path.basename( dest ) + '.map'; | ||
index = this.content.lastIndexOf( 'sourceMappingURL=' ) + 17; | ||
content = this.content.substr( 0, index ) + this.content.substring( index ).replace( /^\S+/, url ); | ||
promises = [ sander.writeFile( dest, content ) ]; | ||
if ( !options.inline ) { | ||
promises.push( sander.writeFile( dest + '.map', map.toString() ) ); | ||
} | ||
return sander.Promise.all( promises ); | ||
} | ||
@@ -201,0 +235,0 @@ }; |
@@ -6,2 +6,4 @@ var path = require( 'path' ), | ||
module.exports = function getMapFromUrl ( url, base, sync ) { | ||
var json, map; | ||
if ( /^data/.test( url ) ) { | ||
@@ -15,3 +17,4 @@ match = /base64,(.+)$/.exec( url ); | ||
json = atob( match[1] ); | ||
return JSON.parse( json ); | ||
map = JSON.parse( json ); | ||
return sync ? map : sander.Promise.resolve( map ); | ||
} | ||
@@ -18,0 +21,0 @@ |
@@ -1,6 +0,16 @@ | ||
var pattern = /\/\/#\s*sourceMappingURL=([^\s]+)/; | ||
module.exports = function getSourceMappingUrl ( str ) { | ||
var index, substring, url; | ||
module.exports = function getSourceMappingUrl ( str ) { | ||
var match = pattern.exec( str ); | ||
return match ? match[1] : null; | ||
// assume we want the last occurence | ||
index = str.lastIndexOf( 'sourceMappingURL' ); | ||
if ( index === -1 ) { | ||
return null; | ||
} | ||
substring = str.substring( index + 17 ); | ||
match = /^\S+/.exec( substring ); | ||
url = match ? match[0] : null; | ||
return url; | ||
}; |
{ | ||
"name": "sorcery", | ||
"description": "Resolve a chain of sourcemaps back to the original source", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"author": "Rich Harris", | ||
@@ -21,3 +21,12 @@ "repository": "https://github.com/Rich-Harris/sorcery", | ||
"sorcery": "bin/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"prepublish": "mocha" | ||
}, | ||
"files": [ | ||
"lib/", | ||
"bin/", | ||
"README.md" | ||
] | ||
} |
@@ -37,2 +37,14 @@ # sorcery.js | ||
// write to a new file - this will create `output.js` and | ||
// `output.js.map`, and will preserve relative paths. It | ||
// returns a Promise | ||
chain.write( 'output.js' ); | ||
// write to a new file, but append the flattened sourcemap as a data URI | ||
chain.write( 'output.js', { inline: true }); | ||
// overwrite the existing file | ||
chain.write(); | ||
chain.write({ inline: true }); | ||
// find the origin of line x, column y. Returns an object with | ||
@@ -39,0 +51,0 @@ // `source`, `line`, `column` and (if applicable) `name` properties. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
105
0
18080
17
421