From 9f9090fc668440eae162ccb7aac8e128cb188f28 Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:01:47 +0800 Subject: [PATCH] js: fix cjs build --- js/package-lock.json | 4 ++-- js/package.json | 24 +++++++++++------------- js/rollup.config.mjs | 21 ++++++++++++++++++--- js/tsconfig.json | 4 +++- 4 files changed, 34 insertions(+), 19 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..5f6c1d8 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,13 @@ "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" + "pretty:fix": "prettier --write 'src/*.[jt]s'" }, "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,