make-dist-package-json.cjs 654 B

123456789101112131415161718192021
  1. const pkgJson = require(process.env['PKG_JSON_PATH'] || '../../package.json');
  2. function processExportMap(m) {
  3. for (const key in m) {
  4. const value = m[key];
  5. if (typeof value === 'string') m[key] = value.replace(/^\.\/dist\//, './');
  6. else processExportMap(value);
  7. }
  8. }
  9. processExportMap(pkgJson.exports);
  10. for (const key of ['types', 'main', 'module']) {
  11. if (typeof pkgJson[key] === 'string') pkgJson[key] = pkgJson[key].replace(/^(\.\/)?dist\//, './');
  12. }
  13. delete pkgJson.devDependencies;
  14. delete pkgJson.scripts.prepack;
  15. delete pkgJson.scripts.prepublishOnly;
  16. delete pkgJson.scripts.prepare;
  17. console.log(JSON.stringify(pkgJson, null, 2));