FormidableLabs / inspectpack

An inspection tool for Webpack frontend JavaScript bundles.
MIT License
592 stars 20 forks source link

BUG: Multiple package roots incorrectly collapse / don't prefix. #90

Closed ryan-roemer closed 5 years ago

ryan-roemer commented 5 years ago

We have an existing multiple-roots test scenario that is wrong in the new plugin:

Plugin

Notice the two foo/index.js (I, 54) for 1.1.1. There should be a separate package2 root, that we need to handle differently

## bundle.js
foo (Found 2 resolved, 2 installed. Latest version 1.1.1.)
  3.3.3
    ~/different-foo/~/foo
      * Dependency graph
        multiple-roots@1.2.3 -> different-foo@^1.0.1 -> foo@^3.0.1
      * Duplicated files in bundle.js
        foo/index.js (S, 64)

  1.1.1
    ~/foo
      * Dependency graph
        package2@2.2.2 -> foo@^1.0.0
      * Duplicated files in bundle.js
        foo/index.js (I, 54)
        foo/index.js (I, 54)

CLI

Versions:

$ node bin/inspectpack.js \
  --action=versions \
  --stats=test/fixtures/multiple-roots/dist-development-4/stats.json \
  -f text

inspectpack --action=versions
=============================

## Summary
* Packages w/ Skews:        1
* Total skewed versions:    2
* Total installed packages: 2
* Total depended packages:  2
* Total bundled files:      4

## `bundle.js`
* foo
  * 1.1.1
    * ~/foo
      * Num deps: 1, files: 2
      * package2@2.2.2 -> foo@^1.0.0
  * 3.3.3
    * ~/different-foo/~/foo
      * Num deps: 1, files: 2
      * multiple-roots@1.2.3 -> different-foo@^1.0.1 -> foo@^3.0.1

Duplicates:

$ node bin/inspectpack.js \
  --action=duplicates \
  --stats=test/fixtures/multiple-roots/dist-development-4/stats.json \
  -f text

inspectpack --action=duplicates
===============================

## Summary
* Extra Files (unique):         2
* Extra Sources (non-unique):   3
* Extra Bytes (non-unique):     172

## `bundle.js`
* foo/index.js
  * Meta: Files 2, Sources 3, Bytes 172
  0. (Files 1, Sources 1, Bytes 64)
    (64) /Users/rye/scm/fmd/inspectpack/test/fixtures/multiple-roots/node_modules/different-foo/node_modules/foo/index.js
  1. (Files 1, Sources 2, Bytes 108)
    (54) /Users/rye/scm/fmd/inspectpack/test/fixtures/multiple-roots/packages/package1/node_modules/foo/index.js
    (54) /Users/rye/scm/fmd/inspectpack/test/fixtures/multiple-roots/packages/package2/node_modules/foo/index.js

Task

Deal with this scenario:

in the following way: