From 89e94ba1be2b72db567c4f264c1fe26663967b87 Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:06:42 +0800 Subject: [PATCH 1/2] js: fix cjs build --- js/package-lock.json | 4 ++-- js/package.json | 23 +++++++++++------------ js/rollup.config.mjs | 21 ++++++++++++++++++--- js/tsconfig.json | 4 +++- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/js/package-lock.json b/js/package-lock.json index 0078762..61c9942 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -1,12 +1,12 @@ { "name": "@bonfida/spl-name-service", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@bonfida/spl-name-service", - "version": "3.0.0", + "version": "3.0.1", "license": "MIT", "dependencies": { "@bonfida/sns-records": "0.0.1", diff --git a/js/package.json b/js/package.json index e5a2eaf..de24fe1 100644 --- a/js/package.json +++ b/js/package.json @@ -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": { @@ -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", diff --git a/js/rollup.config.mjs b/js/rollup.config.mjs index 79561bf..11a04d7 100644 --- a/js/rollup.config.mjs +++ b/js/rollup.config.mjs @@ -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: [ @@ -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({ diff --git a/js/tsconfig.json b/js/tsconfig.json index f42a8e7..4283516 100644 --- a/js/tsconfig.json +++ b/js/tsconfig.json @@ -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, From 760a138524ead850f65119ee6ebfc512f09082d9 Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:31:32 +0800 Subject: [PATCH 2/2] js: remove deprecated register fn --- js/tests/registration.test.ts | 42 ++--------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/js/tests/registration.test.ts b/js/tests/registration.test.ts index c915009..f2eb7e8 100644 --- a/js/tests/registration.test.ts +++ b/js/tests/registration.test.ts @@ -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"; @@ -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"); @@ -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,