thinpm
Static download and packaging of types from popular npm packages
Usage
- Run
node dist/main.js <packages...>
- Put the generated JSON file from
generated/output.json
somewhere you can consume it.
Consumption
- Load output.json
- Loop over files in output.packages["YOUR-PACKAGE"]
- For each file, write it to the place you'd normally expect node_modules to be:
for (const f of output.packages["YOUR-PACKAGE"]) {
console.log(dirname(f))
fs.mkdirSync('project/node_modules/' + dirname(f), { recursive: true })
fs.writeFileSync(project/node_modules/' + f, output.files[f])
}
See src/demo.js for a full example.
Implementation
- Run
npm install
for all requested packages and the@types/
equivalent. - For all
.ts
files in node_modules, map path to file contents. - For each directory in node_modules, follow entries in
dependencies
, adding files from each package along the way.
(3) is incomplete and buggy but enough to create a demo; there are probably ways to make (2) save a smaller set of files.