Reproduction: https://github.com/vjpr/repro-inspectpack-pnpm-test
Possibly related: #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:
|
const modules = (modsToFilePath[filePath] || []).map((mod) => ({ |
|
baseName: mod.baseName, |
|
fileName: mod.identifier, |
|
size: { |
|
full: mod.size, |
|
}, |
|
})); |
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:
|
export const _findPackage = ({ |
|
filePath, |
|
name, |
|
pkgMap, |
|
}: { |
|
filePath: string, |
|
name: string, |
|
pkgMap: INpmPackageMap, |
|
}): { |
|
isFlattened: boolean, |
|
pkgPath: string | null; |
|
pkgObj: INpmPackage | null; |
|
} => { |
|
// We now check the existing package map which, if iterating in correct |
|
// directory order, should already have higher up roots that may contain |
|
// `node_modules` **within** the `require` resolution rules that would |
|
// naturally be the "selected" module. |
|
// |
|
// Fixes https://github.com/FormidableLabs/inspectpack/issues/10 |
|
const cachedRoots = Object.keys(pkgMap) |
|
// Get directories. |
|
.map((k) => dirname(k)) |
|
// Limit to those that are a higher up directory from our root, which |
|
// is fair game by Node.js `require` resolution rules, and not the current |
|
// root because that already failed. |
|
.filter((p) => p !== filePath && filePath.indexOf(p) === 0); |
|
|
|
const roots = [filePath].concat(cachedRoots); |
|
|
|
// Iterate down potential paths. |
|
// If we find it as _first_ result, then it hasn't been flattened. |
|
let isFlattened = false; |
|
|
|
for (const curRoot of roots) { |
|
// Reset to full path. This _will_ end up in some duplicate checks, but |
|
// shouldn't be too expensive. |
|
let curFilePath = filePath; |
|
|
|
while (curRoot.length <= curFilePath.length) { |
|
// Check at this level. |
|
const pkgPath = join(curFilePath, "node_modules", name); |
|
const pkgJsonPath = join(pkgPath, "package.json"); |
|
const pkgObj = pkgMap[pkgJsonPath]; |
|
|
|
// Found a match. |
|
if (pkgObj) { |
|
// Validation: These should all be **real** npm packages, so we should |
|
// **never** fail here. But, can't hurt to check. |
|
if (!pkgObj.name) { |
|
throw new Error(`Found package without name: ${JSON.stringify(pkgObj)}`); |
|
} else if (!pkgObj.version) { |
|
throw new Error(`Found package without version: ${JSON.stringify(pkgObj)}`); |
|
} |
|
|
|
return { isFlattened, pkgPath, pkgObj }; |
|
} |
|
|
|
// Decrement path. If we find it now, it's flattened. |
|
curFilePath = dirname(curFilePath); |
|
isFlattened = true; |
|
} |
|
} |
|
|
|
return { isFlattened: false, pkgPath: null, pkgObj: null }; |
|
}; |
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?
Reproduction: https://github.com/vjpr/repro-inspectpack-pnpm-test
Possibly related: #131
Upon compiling I get the following error.
Notice how
Found map: {}.I've tracked down what is causing the map to be empty to here:
inspectpack/src/lib/actions/versions.ts
Lines 362 to 368 in 917c7c9
Notice how
modsToFilePath's keys are the "realpath" of the package, whereasfilePathis the "logical path".filePathseems to comes from here:inspectpack/src/lib/util/dependencies.ts
Lines 145 to 209 in 917c7c9
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?