patch-package icon indicating copy to clipboard operation
patch-package copied to clipboard

[Proposal] Reduce `patch-package` installation size

Open SukkaW opened this issue 2 years ago • 3 comments

The installation size of the patch-package is reaching 2.33 MiB:

image

(https://packagephobia.com/result?p=patch-package)

And here is the current npm dependency graph of the patch-package:

https://npmgraph.js.org/?q=patch-package#zoom=w

image

I am wondering if we can reduce the installation size. And here is what I propose:

  • Replace [email protected] with picocolors
    • The picocolors is "14 times smaller and 2 times faster than chalk", and is used by popular libraries like postcss, autoprefixer, and stylelint.
    • We can reduce the installation size by 94 KiB: https://packagephobia.com/result?p=chalk%404.1.2, https://packagephobia.com/result?p=picocolors
  • Replace [email protected] with the Node.js built-in fs API
    • The Node.js built-in fs API has been improving and evolving, And patch-package@8 is targeting Node.js 14+ already.
    • We can reduce the installation size by 185 KiB: https://packagephobia.com/result?p=fs-extra%409.1.0
  • Replace [email protected] with the Node.js built-in fs.rm API
    • Node.js has introduced the rm -rf-like fs.rm API, and it has been available since Node.js 14.14.0
    • We can reduce the installation size by 166 KiB: https://packagephobia.com/[email protected]
  • Replace json-stable-stringify with fast-json-stable-stringify
    • The json-stable-stringify is shipped with a JSON polyfill (jsonify). But we don't need the JSON polyfill since patch-package@8 is targeting Node.js 14+.
    • We can reduce the installation size by 25 KiB: https://packagephobia.com/result?p=json-stable-stringify, https://packagephobia.com/result?p=fast-json-stable-stringify

Together we can reduce the installation size of the patch-package by 470 KiB.

@ds300 What do you think?

SukkaW avatar Oct 31 '23 06:10 SukkaW

I thought picocolors was a joke in response to nanocolors drama, but apparently it's now used by the author of nanocolors in his projects (yes, all 3 projects you mentioned above have the same author, so it's just a personal preference, not a statistic). Anyway, why not colorette? (the project from which nanocolors was originally copied)

sesm avatar Nov 03 '23 21:11 sesm

Anyway, why not colorette? (the project from which nanocolors was originally copied)

The installation size of the colorette (17 KiB) is 3x of picocolors (5.66 KiB) while only 7% faster (https://www.npmjs.com/package/colorette?activeTab=readme#benchmarks). So I'd still prefer picocolors.

SukkaW avatar Nov 04 '23 09:11 SukkaW

Replace [email protected] with picocolors

Relevant: https://github.com/chalk/chalk#why-not-switch-to-a-smaller-coloring-package

sindresorhus avatar Aug 13 '24 21:08 sindresorhus