Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

common-shakeify

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

common-shakeify - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

test/dedupe/a/index.js

57

index.js

@@ -8,2 +8,4 @@ 'use strict'

const kDuplicates = Symbol('duplicates')
module.exports = function commonShake (b, opts) {

@@ -52,4 +54,21 @@ if (typeof b !== 'object') {

const file = row.id
let source = row.source
if (row.dedupe) {
// For modules that were deduped, attach the duplicates to the original row,
// and pass the original source to the analyzer.
// Later on, we'll merge the used declarations together, so everything still
// works if dependencies of different copies of the deduped module use
// different parts of that module.
const deduped = rows.get(row.dedupe) || rows.get(row.dedupeIndex)
if (deduped) {
addDuplicate(deduped, row)
source = deduped.source
} else {
return next(new Error(`Could not redupe module ${row.file}`))
}
}
let ast
const string = transformAst(row.source, { locations: true }, (node) => {
const string = transformAst(source, { locations: true }, (node) => {
if (node.type === 'Program') ast = node

@@ -87,3 +106,11 @@ })

const row = rows.get(key)
const dupes = getDuplicates(row)
// If this module was a duplicate of another module,
// the original module will have been rewritten already.
if (row.dedupe) {
this.push(row)
return
}
if (module.bailouts) {

@@ -96,3 +123,3 @@ opts.onModuleBailout(module, module.bailouts)

module.getDeclarations().forEach((decl) => {
if (!module.isUsed(decl.name)) {
if (!isUsed(decl.name)) {
opts.onExportDelete(row.sourceFile || row.file, decl.name)

@@ -104,3 +131,19 @@ remove(string, decl.ast)

row.source = string.toString()
this.push(row)
// Check if a name was used in this module, or
// in any of this module's deduped versions.
function isUsed (name) {
if (module.isUsed(name)) {
return true
}
if (dupes.length > 0) {
return dupes.some((dupe) => {
const m = analyzer.modules.get(dupe.file)
return m && m.isUsed(name)
})
}
return false
}
})

@@ -149,1 +192,11 @@

}
function addDuplicate (row, dupe) {
if (!row[kDuplicates]) {
row[kDuplicates] = []
}
row[kDuplicates].push(dupe)
}
function getDuplicates (row) {
return row[kDuplicates] || []
}

2

package.json
{
"name": "common-shakeify",
"version": "0.3.1",
"version": "0.3.2",
"description": "browserify tree shaking plugin using @indutny common-shake",

@@ -5,0 +5,0 @@ "main": "index.js",

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