sindresorhus / meow

🐈 CLI app helper
MIT License
3.54k stars 151 forks source link

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

Closed jimmywarting closed 10 months ago

jimmywarting commented 3 years ago

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

sindresorhus commented 3 years ago

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 commented 10 months ago

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