common-shakeify
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -7,2 +7,7 @@ # common-shakeify change log | ||
## 0.6.2 | ||
* Fix usage with browserify's `fullPaths: true` option. ([#33](https://github.com/browserify/common-shakeify/pull/33)) | ||
If you use `fullPaths: true`, the bugfix from 0.6.1 does _not_ apply. If you do not use `fullPaths: true`, the bugfix from 0.6.1 _does_ apply. | ||
## 0.6.1 | ||
@@ -9,0 +14,0 @@ * Fix bugs when using `-r` or `b.require('a', { expose: 'b' })`. ([@laduke](https://github.com/laduke) and [@goto-bus-stop](https://github.com/goto-bus-stop) in [#30](https://github.com/browserify/common-shakeify/pull/30)) |
30
index.js
@@ -9,4 +9,2 @@ 'use strict' | ||
const kDuplicates = Symbol('duplicates') | ||
module.exports = function commonShake (b, opts) { | ||
@@ -48,2 +46,3 @@ if (typeof b !== 'object') { | ||
opts.sourceMap = !!b._options.debug | ||
opts.fullPaths = !!b._options.fullPaths | ||
@@ -62,2 +61,3 @@ addHooks() | ||
const strings = new Map() | ||
const duplicates = new Map() | ||
@@ -67,3 +67,3 @@ return through.obj(onfile, onend) | ||
function onfile (row, enc, next) { | ||
const index = row.index | ||
const index = opts.fullPaths ? row.file : row.index | ||
let source = row.source | ||
@@ -96,5 +96,6 @@ | ||
Object.keys(row.indexDeps).forEach((name) => { | ||
if (row.indexDeps[name]) { | ||
analyzer.resolve(index, name, row.indexDeps[name]) | ||
const deps = opts.fullPaths ? row.deps : row.indexDeps | ||
Object.keys(deps).forEach((name) => { | ||
if (deps[name]) { | ||
analyzer.resolve(index, name, deps[name]) | ||
} | ||
@@ -235,12 +236,13 @@ }) | ||
} | ||
} | ||
function addDuplicate (row, dupe) { | ||
if (!row[kDuplicates]) { | ||
row[kDuplicates] = [] | ||
function addDuplicate (row, dupe) { | ||
if (!duplicates.has(row)) { | ||
duplicates.set(row, [dupe]) | ||
} else { | ||
duplicates.get(row).push(dupe) | ||
} | ||
} | ||
row[kDuplicates].push(dupe) | ||
function getDuplicates (row) { | ||
return duplicates.get(row) || [] | ||
} | ||
} | ||
function getDuplicates (row) { | ||
return row[kDuplicates] || [] | ||
} |
{ | ||
"name": "common-shakeify", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "browserify tree shaking plugin using @indutny common-shake", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -164,1 +164,27 @@ var test = require('tape') | ||
}) | ||
// TODO fix this one | ||
test('dash-r node_modules with full paths', { skip: true }, function (t) { | ||
var b = browserify({ | ||
fullPaths: true, | ||
entries: path.join(__dirname, 'dash-r-node-modules/app.js') | ||
}) | ||
b.require('net-browserify-stub', { expose: 'net' }) | ||
b.plugin(commonShake) | ||
var bundle = b.bundle() | ||
bundle.on('error', t.fail) | ||
bundle.pipe(fs.createWriteStream( | ||
path.join(__dirname, 'dash-r-node-modules/actual-fullpaths.js') | ||
)) | ||
bundle.pipe(concat(function (result) { | ||
t.is( | ||
result.toString('utf8'), | ||
fs.readFileSync(path.join(__dirname, 'dash-r-node-modules/expected-fullpaths.js'), 'utf8'), | ||
'dash-r' | ||
) | ||
t.end() | ||
})) | ||
}) |
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
42945
817