@@ -6,8 +6,6 @@ const wrapComment = require('wrap-comment')
6
6
const through = require ( 'through2' )
7
7
const convertSourceMap = require ( 'convert-source-map' )
8
8
9
- const kDuplicates = Symbol ( 'duplicates' )
10
-
11
9
module . exports = function commonShake ( b , opts ) {
12
10
if ( typeof b !== 'object' ) {
13
11
throw new Error ( 'common-shakeify: must be used as a plugin, not a transform' )
@@ -44,6 +42,7 @@ module.exports = function commonShake (b, opts) {
44
42
} , opts )
45
43
46
44
opts . sourceMap = ! ! b . _options . debug
45
+ opts . fullPaths = ! ! b . _options . fullPaths
47
46
48
47
addHooks ( )
49
48
b . on ( 'reset' , addHooks )
@@ -57,11 +56,12 @@ function createStream (opts) {
57
56
58
57
const rows = new Map ( )
59
58
const strings = new Map ( )
59
+ const duplicates = new Map ( )
60
60
61
61
return through . obj ( onfile , onend )
62
62
63
63
function onfile ( row , enc , next ) {
64
- const index = row . index
64
+ const index = opts . fullPaths ? row . file : row . index
65
65
let source = row . source
66
66
67
67
if ( row . dedupe ) {
@@ -89,9 +89,10 @@ function createStream (opts) {
89
89
} )
90
90
analyzer . run ( ast , index )
91
91
92
- Object . keys ( row . indexDeps ) . forEach ( ( name ) => {
93
- if ( row . indexDeps [ name ] ) {
94
- analyzer . resolve ( index , name , row . indexDeps [ name ] )
92
+ const deps = opts . fullPaths ? row . deps : row . indexDeps
93
+ Object . keys ( deps ) . forEach ( ( name ) => {
94
+ if ( deps [ name ] ) {
95
+ analyzer . resolve ( index , name , deps [ name ] )
95
96
}
96
97
} )
97
98
@@ -227,14 +228,15 @@ function createStream (opts) {
227
228
function commentify ( str ) {
228
229
return wrapComment ( `common-shake removed: ${ str } ` )
229
230
}
230
- }
231
231
232
- function addDuplicate ( row , dupe ) {
233
- if ( ! row [ kDuplicates ] ) {
234
- row [ kDuplicates ] = [ ]
232
+ function addDuplicate ( row , dupe ) {
233
+ if ( ! duplicates . has ( row ) ) {
234
+ duplicates . set ( row , [ dupe ] )
235
+ } else {
236
+ duplicates . get ( row ) . push ( dupe )
237
+ }
238
+ }
239
+ function getDuplicates ( row ) {
240
+ return duplicates . get ( row ) || [ ]
235
241
}
236
- row [ kDuplicates ] . push ( dupe )
237
- }
238
- function getDuplicates ( row ) {
239
- return row [ kDuplicates ] || [ ]
240
242
}
0 commit comments