Permalink
Browse files

Source maps should be working

  • Loading branch information...
1 parent d0bafe7 commit a432e2e4167a83785544a56e93bbd87171f47f59 @download13 committed May 14, 2012
Showing with 38 additions and 38 deletions.
  1. +23 −23 lib/minify-closure.js
  2. +2 −1 lib/source-package-util.js
  3. +12 −13 lib/source-package.js
  4. +1 −1 lib/sourcemap.js
View
@@ -1,30 +1,30 @@
-var path = require('path');
-var fs = require('fs');
-var child_process = require('child_process');
+var path = require('path')
+var fs = require('fs')
+var child_process = require('child_process')
-var supportpath = path.resolve(__dirname, '../support/');
-var jarpath = path.join(supportpath, 'closure.jar');
-var mappath = '_tmp_map'; // Should probably make use of that generateTempFile function
-var cmd = 'java -jar "' + jarpath + '" --compilation_level SIMPLE_OPTIMIZATIONS --create_source_map ' + mappath;
+var supportpath = path.resolve(__dirname, '../support/')
+var jarpath = path.join(supportpath, 'closure.jar')
+var mappath = '_tmp_map' // Should probably make use of that generateTempFile function
+var cmd = 'java -jar "' + jarpath + '" --compilation_level SIMPLE_OPTIMIZATIONS --create_source_map ' + mappath + ' --source_map_format V3'
// This needs some error handling and general cleanup
function minify(source, cb) {
- var child = child_process.exec(cmd);
- var minified = '';
-
- child.stdout.setEncoding('utf8');
- child.stdout.on('data', function(data) {
- minified += data;
- });
-
- child.on('exit', function() {
- fs.readFile(mappath, 'utf8', function(err, mapdata) {
- fs.unlinkSync(mappath);
- cb(null, minified, mapdata);
- });
- });
-
- child.stdin.end(source);
+ var child = child_process.exec(cmd), minified = ''
+
+ child.stdout.setEncoding('utf8')
+ child.stdout.on('data', function(data) {
+ minified += data
+ })
+
+ child.on('exit', function() {
+ fs.readFile(mappath, 'utf8', function(err, mapdata) {
+ fs.unlink(mappath, function () {
+ cb(null, minified, mapdata)
+ })
+ })
+ })
+
+ child.stdin.end(source);
}
exports.minify = minify;
@@ -54,9 +54,10 @@ var fs = require('fs')
}
// utility to read multiple files in order and append them
- , loadFiles = function (root, files, callback) {
+ , loadFiles = function (files, callback) {
if (!Array.isArray(files)) files = [ files ]
if (!files.length || (files.length == 1 && files[0] == 'noop')) return callback()
+ var root = this.rootPath
collectFiles(root, files, function (err, files) {
// read each source file in parallel and assemble them together
View
@@ -95,7 +95,7 @@ var fs = require('fs')
this.isRoot = isRoot
this.packageName = packageName
this.packageJSON = packageJSON
- this.rootPath = packageUtil.getPackageRoot(this.parents, this.packageName)
+ this.rootPath = packageUtil.getPackageRoot(this.parents, this.packageName) // Moved to init since it gets used more than once
// custom hasher function for async.memoize so we have a single key, default will use
// first arg (callback) as hash key which won't work
@@ -113,9 +113,7 @@ var fs = require('fs')
// note that "main" and "ender" are processed in the same way so they can both be just
// a string pointing to a source file or an array of source files that are concatenated
// or be left unspecified
- var packageName = this.packageJSON.name
- var root = packageUtil.getPackageRoot(this.parents, this.packageName)
- , mainSources = this.packageJSON.main || []
+ var mainSources = this.packageJSON.main || []
, enderBridgeSources = this.packageJSON.ender || []
, handleSourceData = function (err, sources) {
@@ -136,27 +134,28 @@ var fs = require('fs')
}.bind(this)
, sourceLoaders = {
- main: sourcePackageUtil.loadFiles.bind(this, root, mainSources)
- , ender: sourcePackageUtil.loadFiles.bind(this, root, enderBridgeSources)
+ main: sourcePackageUtil.loadFiles.bind(this, mainSources)
+ , ender: sourcePackageUtil.loadFiles.bind(this, enderBridgeSources)
}
async.parallel(sourceLoaders, handleSourceData)
}
, sources: function (callback) {
async.parallel({
- main: this.loadFiles.bind(this, this.packageJSON.main || [])
- , ender: this.loadFiles.bind(this, this.packageJSON.ender || [])
+ main: sourcePackageUtil.loadFiles.bind(this, this.packageJSON.main || [])
+ , ender: sourcePackageUtil.loadFiles.bind(this, this.packageJSON.ender || [])
}, function (err, sources) {
if (err) return callback(err)
var map = {}
- if (sources.main) {
- map[path.relative('.', sources.main[0].file)] = sources.main[0].content // HACK: Why would there be more than one? If there's a good reason I'll add an iterator
- }
- if (sources.ender) {
- map[path.relative('.', sources.ender[0].file)] = sources.ender[0].content
+ function toMap(source) {
+ map[path.relative('.', source.file)] = source.contents
}
+
+ sources.main && sources.main.forEach(toMap)
+ sources.ender && sources.ender.forEach(toMap)
+
callback(err, map)
}.bind(this))
}
View
@@ -67,7 +67,7 @@ SourceMap.prototype = {
}
var tmp = segment.field3 - offsetTop;
if(tmp >= 0 && tmp < lines) {
- console.log(sourceName, offsetTop, lines, tmp + ' <- ' + segment.field3, segment.field4 - offsetLeft + ' <- ' + segment.field4, (self.names[segment.field5] || segment.field5));
+ //console.log(sourceName, offsetTop, lines, tmp + ' <- ' + segment.field3, segment.field4 - offsetLeft + ' <- ' + segment.field4, (self.names[segment.field5] || segment.field5));
segment.field3 = tmp;
segment.field2 = sourceIndex;
segment.field4 -= offsetLeft;

0 comments on commit a432e2e

Please sign in to comment.