1.0.2 • Published 9 months ago
paketo v1.0.2
Paketo
A tiny library for importing your package.json, with proper types!
Why?
- You could do like
JSON.parse ( fs.readFileSync ( 'package.json', 'utf8' ) ), but the output will be of typeany, not the type that you want. Also that's annoying to write. - You could do
import Package from './package.json' assert { type: 'json' }, but that's kinda weird, it's not supported everywhere yet, and the path to write will change depending on where you are importing it from, which is inconvenient.
How?
- After reading the
package.jsonfile this library rewrites its own types with the content of that file.
Limitations
- After the first run, and after you edit your
package.jsonfile, you might have to restart TS' LSP before you can see the updated types. - If your dependencies are not installed in a local
node_modulesfolder this library may not work properly.
Install
npm install paketoUsage
import Package from 'paketo';
// Let's read something from our package.json, with proper types
console.log ( Package.name ); // => paketoLicense
MIT © Fabio Spampinato