update-package-json.mjs 700 B

123456789101112131415161718192021
  1. import fs from "fs";
  2. import path from "path";
  3. import { fileURLToPath } from "url";
  4. /**
  5. * This script updates the package.json file in the dist directory after the TypeScript build.
  6. *
  7. * This ensures that the published package correctly references the compiled JavaScript
  8. * instead of the TypeScript source files.
  9. */
  10. const __dirname = path.dirname(fileURLToPath(import.meta.url));
  11. const distPackageJsonPath = path.join(__dirname, "..", "package.json");
  12. const packageJson = JSON.parse(fs.readFileSync(distPackageJsonPath, "utf8"));
  13. packageJson.main = "dist/src/index.js";
  14. packageJson.types = "dist/src/index.d.ts";
  15. fs.writeFileSync(distPackageJsonPath, JSON.stringify(packageJson, null, 2));