Open anomiex opened 3 weeks ago
Please, provide a solution suggestion
Looks like it was broken by #345, using require.resolve
with paths
was avoiding this problem.
One possibility would be to partially undo that, but instead of require.resolve(i, { paths: [process.cwd()] })
try doing like import.meta.resolve( i, pathToFileURL( process.cwd() + '/package.json' ).toString() )
instead. That seems to work with my test cases above anyway.
Since the parent
parameter to import.meta.resolve
is still experimental, you'll probably want to use something like https://www.npmjs.com/package/import-meta-resolve to polyfill it.
cc @JounQin
Since the parent parameter to import.meta.resolve is still experimental
If it is just a warning, it is OK. Does it work in ^18.0.0 || >=20.0.0
?
The way plugins and presets are loaded works with npm's hoisting, and even works in a non-monorepo (or where size-limit and its plugins are installed in the monorepo root), but does not work when size-limit is installed in a workspace with yarn pnp or pnpm with hoisting disabled.
Reproduction
With yarn:
Create a temporary directory and cd into it.
Create the following files:
package.json
```json { "private": true, "workspaces": [ "a" ] } ```a/index.js
Contents don't matter, even an empty file is ok.a/package.json
```json { "name": "a", "devDependencies": { "@size-limit/file": "^11.1.4", "size-limit": "^11.1.4" }, "size-limit": [ { "path": "index.js" } ], "scripts": { "size": "size-limit" } } ```Run
yarn set version stable && yarn install
Run
yarn workspace a size
With pnpm:
Create a temporary directory and cd into it.
Create the following files:
package.json
```json { } ```.npmrc
``` hoist-pattern=[] ```pnpm-workspace.yaml
```yaml packages: - 'a' ```a/index.js
Contents don't matter, even an empty file is ok.a/package.json
```json { "name": "a", "devDependencies": { "@size-limit/file": "^11.1.4", "size-limit": "^11.1.4" }, "size-limit": [ { "path": "index.js" } ], "scripts": { "size": "size-limit" } } ```Run
pnpm install
.Run `pnpm
Expected behavior
size-limit
runs successfully.Actual behavior
With yarn:
With pnpm: