meow icon indicating copy to clipboard operation
meow copied to clipboard

read read-pkg-up feels very bloated...

Open jimmywarting opened this issue 2 years ago • 1 comments

Regarding this function and read-pkg-up

https://github.com/sindresorhus/meow/blob/e1f0e24840634ae58664a70ee9e19ab80166b3f3/index.js#L112-L115

It felt very unnecessary to install 39 packages and 674 KB of data for just trying to read the closest package.json file

Tried to come up with a pure js solution...

import fs from 'node:fs'

let path = import.meta.url.slice(7) // remove `file://`
let pkg
while (!pkg && path) {
  path = path.substr(0, path.lastIndexOf('/')) // get parent dir
  try {
    pkg = JSON.parse(fs.readFileSync(path + '/package.json'))
  } catch (_) {}
}
console.log(pkg)

This is all the sub dependencies it have to install https://npmgraph.js.org/?q=read-pkg-up image

jimmywarting avatar Aug 19 '21 11:08 jimmywarting

I'm willing to switch it to https://github.com/sindresorhus/find-up, but I think the best solution is just bundling dependencies and treeshaking (there's another issue for that).

sindresorhus avatar Aug 19 '21 11:08 sindresorhus

Bundling was done and the read-package-up dependency is now much smaller.

sindresorhus avatar Dec 22 '23 20:12 sindresorhus