FormidableLabs / inspectpack

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

Not working with pnpm #151

Open vjpr opened 3 years ago

vjpr commented 3 years ago

Reproduction: https://github.com/vjpr/repro-inspectpack-pnpm-test


Possibly related: https://github.com/FormidableLabs/inspectpack/issues/131


Upon compiling I get the following error.

Compiled with warnings.

Missing sources: Expected 4, found 0.
Found map: {}

Notice how Found map: {}.

I've tracked down what is causing the map to be empty to here:

https://github.com/FormidableLabs/inspectpack/blob/917c7c9ba5118ae19b5992ed0afd505dbf6ba460/src/lib/actions/versions.ts#L362-L368

filePath = /Users/Vaughan/dev/inspectpack-pnpm-test/packages/cra/node_modules/react-refresh
modsToFilePath = {
  "/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/react-refresh@0.8.3/node_modules/react-refresh": [
    {
      "baseName": "react-refresh/cjs/react-refresh-runtime.development.js",
      "chunks": [
        0
      ],
      "identifier": "/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/babel-loader@8.1.0_427212bc1158d185e577033f19ca0757/node_modules/babel-loader/lib/index.js??ref--5-oneOf-3!/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/react-refresh@0.8.3/node_modules/react-refresh/cjs/react-refresh-runtime.development.js",
      "isNodeModules": true,
      "isSynthetic": false,
      "size": 23198,
    },
    {
      "baseName": "react-refresh/runtime.js",
      "chunks": [
        0
      ],
      "identifier": "/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/babel-loader@8.1.0_427212bc1158d185e577033f19ca0757/node_modules/babel-loader/lib/index.js??ref--5-oneOf-3!/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/react-refresh@0.8.3/node_modules/react-refresh/runtime.js",
      "isNodeModules": true,
      "isSynthetic": false,
      "size": 221,
      "source": "'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n  module.exports = require('./cjs/react-refresh-runtime.production.min.js');\n} else {\n  module.exports = require('./cjs/react-refresh-runtime.development.js');\n}"
    }
  ],
  "/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/react-refresh@0.9.0/node_modules/react-refresh": [
    {
      "baseName": "react-refresh/cjs/react-refresh-runtime.development.js",
      "chunks": [
        0
      ],
      "identifier": "/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/babel-loader@8.1.0_427212bc1158d185e577033f19ca0757/node_modules/babel-loader/lib/index.js??ref--5-oneOf-3!/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/react-refresh@0.9.0/node_modules/react-refresh/cjs/react-refresh-runtime.development.js",
      "isNodeModules": true,
      "isSynthetic": false,
      "size": 23096,
    },
    {
      "baseName": "react-refresh/runtime.js",
      "chunks": [
        0
      ],
      "identifier": "/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/babel-loader@8.1.0_427212bc1158d185e577033f19ca0757/node_modules/babel-loader/lib/index.js??ref--5-oneOf-3!/Users/Vaughan/dev/inspectpack-pnpm-test/node_modules/.pnpm/react-refresh@0.9.0/node_modules/react-refresh/runtime.js",
      "isNodeModules": true,
      "isSynthetic": false,
      "size": 221,
    }
  ]
}

Notice how modsToFilePath's keys are the "realpath" of the package, whereas filePath is the "logical path".

filePath seems to comes from here:

https://github.com/FormidableLabs/inspectpack/blob/917c7c9ba5118ae19b5992ed0afd505dbf6ba460/src/lib/util/dependencies.ts#L145-L209

However I have reached the point where I don't understand what is going on and maybe a maintainer could quickly point to the right fix?

ryan-roemer commented 3 years ago

Thanks for the test repository. I'm working on the webpack5 upgrade and then with a bit of time will try and take a look here.

My strong intuition is that while the duplicates sub-feature (Duplicates: Found 3 similar files across 4 code sources) is working, the versions sub-feature (Packages: Found 0 packages with 0 resolved, 0 installed, and 0 depended versions.) of the duplicates plugin is unable to correctly infer node_modules roots in the manner that pnpm places them.

I'll see if I can come with an appropriate test fixture that mirrors how pnpm does it and work from there when I get time. (The fixtures application in test land is a bit complicated, but they live here if you're curious: https://github.com/FormidableLabs/inspectpack/tree/master/test/fixtures )