Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions governance/pyth_staking_sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"exports": {
".": "./src/index.ts"
},
"private": true,
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc",
"build": "tsc && node scripts/update-package-json.js",
"test": "pnpm run test:format && pnpm run test:lint && pnpm run test:integration && pnpm run test:types",
"fix": "pnpm fix:lint && pnpm fix:format",
"fix:format": "prettier --write .",
Expand Down
22 changes: 22 additions & 0 deletions governance/pyth_staking_sdk/scripts/update-package-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

/**
* This script updates the package.json file in the dist directory after the TypeScript build.
*
* This ensures that the published package correctly references the compiled JavaScript
* instead of the TypeScript source files.
*/

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const distPackageJsonPath = path.join(__dirname, "..", "dist", "package.json");

const packageJson = JSON.parse(fs.readFileSync(distPackageJsonPath, "utf8"));

packageJson.exports = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there must be a better way to deal with this 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see what @cprussin says

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually have a package for doing this: https://www.npmjs.com/package/@cprussin/transform-package-json

You essentially have to do some transformation like this to the package.json to dual export packages or to use nextjs's transpileModules on a package that gets published, so I think it's fine however you want to do this, and what you have here is perfectly ok

".": "./src/index.js",
};

fs.writeFileSync(distPackageJsonPath, JSON.stringify(packageJson, null, 2));
Loading