Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active April 19, 2022 20:57
Show Gist options
  • Save isaacs/cf8684d4c4c4ae720f08fca5d073c441 to your computer and use it in GitHub Desktop.
Save isaacs/cf8684d4c4c4ae720f08fca5d073c441 to your computer and use it in GitHub Desktop.
{"name":"hello-world-bespoke-archive-format","version":"1.0.0","main":"lib/index.js"}
console.log('hello, world!')
# hello-world-bespoke-archive-format
An example of a "hello world" program, but instead of being a tarball, it's
shown in the bespoke package format that npm *SHOULD* have used, instead of
tar.
One can be forgiven for not wanting to reinvent the wheel, but let this be a
lesson that, in fact, some wheels _ought_ to be reinvented, when the
alternative does not roll as easily.
{"package.json":[0,86],"lib/index.js":[86,29],"README.md":[115,379]}}
00000000000000000000000000000070
@isaacs
Copy link
Author

isaacs commented Apr 19, 2022

AND AnOThER ThiNG!! If you nest these files within one another, then the parent can re-index the files of the children. So bundleDependencies could have something like:

{"name":"module","version":"1.2.3","bundleDependencies":["dep"],"dependencies":{"dep":"1"}}
require('dep').doSomething() // this is module's index.js
{"name":"dep","version":"1.5.4","main":"index.js"}
exports.doSomething = () => console.log('this is dep')
{"package.json":[0,59],"index.js":[59,100]}
00000000000000000000000000000044
{"package.json":[0,99],"index.js":[99,123],"node_modules/dep.npm":[222,192,{"node_modules/dep/package.json":[222,59],"node_modules/dep/index.js":[281,100]}]}
00000000000000000000000000000159

So any .npm file that shows up in the archive has its entries automatically added to the index. Want to unpack the bundled deps? Easy peasy! They're right there! Want to just do 1 level? Or just 2 levels? Also easy!

Jesus, I might have to sit down and write this some day just to get it out of my system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment