Comparing version 0.1.0 to 0.1.1
@@ -47,3 +47,3 @@ var Minifier | ||
self.mapForFile = function (file) { | ||
if(!self.registry[file]) { | ||
if(!self.fileExists(file)) { | ||
throw new Error('ENOFILE'); | ||
@@ -59,3 +59,3 @@ } | ||
self.codeForFile = function (file) { | ||
if(!self.registry[file]) { | ||
if(!self.fileExists(file)) { | ||
throw new Error('ENOFILE'); | ||
@@ -67,2 +67,6 @@ } | ||
self.fileExists = function (file) { | ||
return (self.registry[file] != null); | ||
} | ||
/* | ||
@@ -171,10 +175,47 @@ * Compresses code before Browserify touches it | ||
return target; | ||
}; | ||
} | ||
, missingSources = {}; | ||
// Figure out where my minified files went in the bundle | ||
bundleMap.eachMapping(function (mapping) { | ||
mapSourceToLine(mapping.source, mapping.generatedLine); | ||
// Is this a known source? | ||
if(self.fileExists(mapping.source)) { | ||
mapSourceToLine(mapping.source, mapping.generatedLine); | ||
} | ||
// Not a known source, pass thru the mapping | ||
else { | ||
generator.addMapping({ | ||
generated: { | ||
line: mapping.generatedLine | ||
, column: mapping.generatedColumn | ||
} | ||
, original: { | ||
line: mapping.originalLine | ||
, column: mapping.originalColumn | ||
} | ||
, source: opts.transformPaths(mapping.source) | ||
, name: mapping.name | ||
}); | ||
missingSources[mapping.source] = true; | ||
} | ||
}); | ||
if(process.env.debug) { | ||
console.log(' [DEBUG] Here is where Browserify put your modules:'); | ||
_.each(bundleToMinMap, function (line, file) { | ||
console.log(' [DEBUG] line ' + line + ' "' + opts.transformPaths(file) + '"'); | ||
}); | ||
} | ||
// Add sourceContent for missing sources | ||
_.each(missingSources, function (v, source) { | ||
generator.setSourceContent(opts.transformPaths(source), bundleMap.sourceContentFor(source)); | ||
}); | ||
// Map from the hi-res sourcemaps to the browserify bundle | ||
if(process.env.debug) { | ||
console.log(' [DEBUG] Here is how I\'m mapping your code:'); | ||
} | ||
self.eachSource(function (file, code) { | ||
@@ -185,4 +226,16 @@ var offset = lineForSource(file) - 1 | ||
if(process.env.debug) { | ||
console.log(' [DEBUG] Now mapping "' + transformedFileName + '"'); | ||
} | ||
fileMap.eachMapping(function (mapping) { | ||
generator.addMapping( self.transformMapping(transformedFileName, mapping, offset) ); | ||
var transformedMapping = self.transformMapping(transformedFileName, mapping, offset); | ||
if(process.env.debug) { | ||
console.log(' [DEBUG] Generated [' + transformedMapping.generated.line | ||
+ ':' + transformedMapping.generated.column + '] > [' | ||
+ mapping.originalLine + ':' + mapping.originalColumn + '] Original'); | ||
} | ||
generator.addMapping( transformedMapping ); | ||
}); | ||
@@ -189,0 +242,0 @@ |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"repository": { | ||
@@ -17,0 +17,0 @@ "type": "git", |
@@ -15,4 +15,52 @@ /** | ||
, SMConsumer = SM.SourceMapConsumer | ||
, testSourcemap | ||
, tests; | ||
testSourcemap = function (fixtureName) { | ||
return function (next) { | ||
var bundle = new browserify() | ||
, bundledFile = fixtures.bundledFile(fixtureName) | ||
, bundledMap = fixtures.bundledMap(fixtureName) | ||
, minifier = new minifyify({ | ||
source: bundledFile | ||
, map: path.basename(bundledMap) | ||
, transformPaths: function (filePath) { | ||
return path.relative(fixtures.dir, filePath); | ||
} | ||
}) | ||
, d = domain.create(); | ||
bundle.add( fixtures.entryScript(fixtureName) ); | ||
bundle.transform(minifier.transformer); | ||
// We don't expect any errors | ||
d.on('error', function (e) { | ||
assert.fail('there should be no errors, but this happened: ' + e); | ||
}); | ||
// Try to consume output, should trigger error inside domain | ||
d.run(function () { | ||
bundle.bundle({debug: true}) | ||
.pipe(minifier.consumer(function (code, map) { | ||
assert.ok('the consumer callback was called'); | ||
var consumer = new SMConsumer(map); | ||
if(process.env.debug) { | ||
var bundledPage = path.join(path.dirname(bundledFile), 'index.html'); | ||
console.log(' [DEBUG] Writing output to fixture directory'); | ||
console.log(' bundle: ' + path.relative(process.cwd(), bundledFile)); | ||
console.log(' map: ' + path.relative(process.cwd(), bundledMap)); | ||
console.log(' open "' + path.relative(process.cwd(), bundledPage) + '" in your browser dev tools'); | ||
fs.writeFileSync(bundledFile, code); | ||
fs.writeFileSync(bundledMap, map); | ||
} | ||
next(); | ||
})); | ||
}); | ||
} | ||
}; | ||
tests = { | ||
@@ -75,48 +123,6 @@ 'fails to consume when not in debug mode': function (next) { | ||
} | ||
, 'transforms sourcemap': function (next) { | ||
var bundle = new browserify() | ||
, bundledFile = fixtures.bundledFile('complex file') | ||
, bundledMap = fixtures.bundledMap('complex file') | ||
, minifier = new minifyify({ | ||
source: bundledFile | ||
, map: path.basename(bundledMap) | ||
, transformPaths: function (filePath) { | ||
return path.relative(fixtures.dir, filePath); | ||
} | ||
}) | ||
, d = domain.create(); | ||
bundle.add( fixtures.entryScript('complex file') ); | ||
bundle.transform(minifier.transformer); | ||
// We don't expect any errors | ||
d.on('error', function (e) { | ||
assert.fail('there should be no errors, but this happened: ' + e); | ||
}); | ||
// Try to consume output, should trigger error inside domain | ||
d.run(function () { | ||
bundle.bundle({debug: true}) | ||
.pipe(minifier.consumer(function (code, map) { | ||
assert.ok('the consumer callback was called'); | ||
var consumer = new SMConsumer(map); | ||
if(process.env.debug) { | ||
var bundledPage = path.join(path.dirname(bundledFile), 'index.html'); | ||
console.log(' [DEBUG] Writing output to fixture directory'); | ||
console.log(' bundle: ' + path.relative(process.cwd(), bundledFile)); | ||
console.log(' map: ' + path.relative(process.cwd(), bundledMap)); | ||
console.log(' open "' + path.relative(process.cwd(), bundledPage) + '" in your browser dev tools'); | ||
fs.writeFileSync(bundledFile, code); | ||
fs.writeFileSync(bundledMap, map); | ||
} | ||
next(); | ||
})); | ||
}); | ||
} | ||
, 'transforms complex sourcemap': testSourcemap('complex file') | ||
, 'transforms sourcemap with native libs': testSourcemap('native libs') | ||
}; | ||
module.exports = tests; |
Sorry, the diff of this file is not supported yet
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
18607
16
501
0
10287
6