cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
scripts/make-dist-package-json.cjs
21lines · modeblame
2d51afdcstainless-app[bot]2 years ago | 1 | const pkgJson = require(process.env['PKG_JSON_PATH'] || '../package.json'); |
| 2 | | |
| 3 | function processExportMap(m) { | |
| 4 | for (const key in m) { | |
| 5 | const value = m[key]; | |
| 6 | if (typeof value === 'string') m[key] = value.replace(/^\.\/dist\//, './'); | |
| 7 | else processExportMap(value); | |
| 8 | } | |
| 9 | } | |
| 10 | processExportMap(pkgJson.exports); | |
| 11 | | |
| 12 | for (const key of ['types', 'main', 'module']) { | |
| 13 | if (typeof pkgJson[key] === 'string') pkgJson[key] = pkgJson[key].replace(/^(\.\/)?dist\//, './'); | |
| 14 | } | |
| 15 | | |
| 16 | delete pkgJson.devDependencies; | |
| 17 | delete pkgJson.scripts.prepack; | |
| 18 | delete pkgJson.scripts.prepublishOnly; | |
| 19 | delete pkgJson.scripts.prepare; | |
| 20 | | |
| 21 | console.log(JSON.stringify(pkgJson, null, 2)); |