cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7d5afd114613b471f408a712a8accef23c73eadc

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/utils/make-dist-package-json.cjs

29lines · modecode

1const pkgJson = require(process.env['PKG_JSON_PATH'] || '../../package.json');
2
3function 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}
10processExportMap(pkgJson.exports);
11
12for (const key of ['types', 'main', 'module']) {
13 if (typeof pkgJson[key] === 'string') pkgJson[key] = pkgJson[key].replace(/^(\.\/)?dist\//, './');
14}
15// Fix bin paths if present
16if (pkgJson.bin) {
17 for (const key in pkgJson.bin) {
18 if (typeof pkgJson.bin[key] === 'string') {
19 pkgJson.bin[key] = pkgJson.bin[key].replace(/^(\.\/)?dist\//, './');
20 }
21 }
22}
23
24delete pkgJson.devDependencies;
25delete pkgJson.scripts.prepack;
26delete pkgJson.scripts.prepublishOnly;
27delete pkgJson.scripts.prepare;
28
29console.log(JSON.stringify(pkgJson, null, 2));
30