Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js: fix cjs build #79

Merged
merged 2 commits into from
Aug 7, 2024
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
4 changes: 2 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "@bonfida/spl-name-service",
"version": "3.0.0",
"version": "3.0.1",
"license": "MIT",
"files": [
"dist"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"main": "./dist/cjs/index.cjs",
"module": "./dist/esm/index.mjs",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.cjs",
"types": "./dist/types/index.d.ts"
}
},
"repository": {
Expand All @@ -23,15 +23,14 @@
"homepage": "https://sns.guide",
"scripts": {
"dev": "tsc && node --trace-warnings dist/test.js",
"build": "rm -rf dist && rollup -c",
"prepublish": "rm -rf dist && rollup -c",
"prepack": "rm -rf dist && rollup -c",
"build": "rm -rf dist && rollup -c && tsc --emitDeclarationOnly --outDir dist/types",
"prepublish": "rm -rf dist && rollup -c && tsc --emitDeclarationOnly --outDir dist/types",
"prepack": "rm -rf dist && rollup -c && tsc --emitDeclarationOnly --outDir dist/types",
"lint": "yarn pretty && eslint .",
"lint:fix": "yarn pretty:fix && eslint . --fix",
"pretty": "prettier --check 'src/*.[jt]s'",
"pretty:fix": "prettier --write 'src/*.[jt]s'",
"test": "jest ./tests",
"doc": "yarn typedoc src/index.ts"
"test": "jest ./tests"
},
"devDependencies": {
"@bonfida/prettier-config": "^1.0.0",
Expand Down
21 changes: 18 additions & 3 deletions js/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ export default {
],
output: [
{
dir: "dist/",
dir: "dist/esm",
format: "esm",
sourcemap: true,
entryFileNames: "[name].mjs",
exports: "named",
preserveModules: true,
preserveModulesRoot: "src",
},
{
dir: "dist/cjs",
format: "cjs",
sourcemap: true,
entryFileNames: "[name].cjs",
exports: "named",
preserveModules: true,
preserveModulesRoot: "src",
},
{ dir: "dist/", format: "cjs", sourcemap: true },
],
external: ["@solana/web3.js"],
plugins: [
Expand All @@ -42,7 +52,12 @@ export default {
dedupe: ["borsh", "@solana/spl-token", "bn.js", "buffer"],
}),
commonjs(),
typescript(),
typescript({
tsconfig: "./tsconfig.json",
declaration: false,
outDir: null,
declarationDir: null,
}),
babel({ babelHelpers: "bundled" }),
json(),
replace({
Expand Down
42 changes: 2 additions & 40 deletions js/tests/registration.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require("dotenv").config();
import { test, jest } from "@jest/globals";
import { Connection, PublicKey, Transaction } from "@solana/web3.js";
import { registerDomainName } from "../src/bindings/registerDomainName";
import { registerDomainNameV2 } from "../src/bindings/registerDomainNameV2";
import { registerWithNft } from "../src/bindings/registerWithNft";
import { randomBytes } from "crypto";
import { REFERRERS, USDC_MINT } from "../src/constants";
import { REFERRERS } from "../src/constants";
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
import { getDomainKeySync } from "../src/utils/getDomainKeySync";
import { getReverseKeySync } from "../src/utils/getReverseKeySync";
Expand All @@ -21,43 +20,6 @@ const VAULT_OWNER = new PublicKey(
"5D2zKog251d6KPCyFyLMt3KroWwXXPWSgTPyhV22K2gR",
);

test("Registration", async () => {
const tx = new Transaction();
const ix = await registerDomainName(
connection,
randomBytes(10).toString("hex"),
1_000,
VAULT_OWNER,
getAssociatedTokenAddressSync(USDC_MINT, VAULT_OWNER, true),
USDC_MINT,
);
tx.add(...ix);
const { blockhash } = await connection.getLatestBlockhash();
tx.recentBlockhash = blockhash;
tx.feePayer = VAULT_OWNER;
const res = await connection.simulateTransaction(tx);
expect(res.value.err).toBe(null);
});

test("Registration with ref", async () => {
const tx = new Transaction();
const ix = await registerDomainName(
connection,
randomBytes(10).toString("hex"),
1_000,
VAULT_OWNER,
getAssociatedTokenAddressSync(FIDA_MINT, VAULT_OWNER, true),
FIDA_MINT,
REFERRERS[1],
);
tx.add(...ix);
const { blockhash } = await connection.getLatestBlockhash();
tx.recentBlockhash = blockhash;
tx.feePayer = VAULT_OWNER;
const res = await connection.simulateTransaction(tx);
expect(res.value.err).toBe(null);
});

test("Register with NFT", async () => {
const tx = new Transaction();
const domain = randomBytes(10).toString("hex");
Expand Down Expand Up @@ -93,7 +55,7 @@ test("Register with NFT", async () => {
test("Indempotent ATA creation ref", async () => {
const tx = new Transaction();
for (let i = 0; i < 3; i++) {
const ix = await registerDomainName(
const ix = await registerDomainNameV2(
connection,
randomBytes(10).toString("hex"),
1_000,
Expand Down
4 changes: 3 additions & 1 deletion js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es2019",
"outDir": "dist",
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"declarationDir": "dist/types",
"emitDeclarationOnly": true,
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
Expand Down
Loading