Skip to content

Commit 9fe98b6

Browse files
[js-legacy-client] Update tsconfig to export for cjs and esm (#33)
1 parent 4332824 commit 9fe98b6

10 files changed

+182
-26
lines changed

clients/js-legacy/package.json

+20-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,32 @@
1010
"node": ">=16"
1111
},
1212
"files": [
13-
"src"
13+
"lib",
14+
"src",
15+
"LICENSE",
16+
"README.md"
1417
],
18+
"publishConfig": {
19+
"access": "public"
20+
},
21+
"main": "./lib/cjs/index.js",
22+
"module": "./lib/esm/index.js",
23+
"types": "./lib/types/index.d.ts",
24+
"exports": {
25+
"types": "./lib/types/index.d.ts",
26+
"require": "./lib/cjs/index.js",
27+
"import": "./lib/esm/index.js"
28+
},
1529
"scripts": {
1630
"prepublishOnly": "pnpm build",
17-
"build": "tsc --build --verbose",
31+
"build": "tsc --build --verbose tsconfig.all.json",
32+
"postbuild": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
1833
"lint": "eslint --max-warnings 0 .",
1934
"lint:fix": "eslint --fix .",
2035
"format": "prettier --check src test",
2136
"format:fix": "prettier --write src test",
22-
"test": "mocha test/*"
37+
"test": "mocha test/* && pnpm test:exports",
38+
"test:exports": "node ./test/exports/module.mjs && node ./test/exports/commonjs.cjs"
2339
},
2440
"peerDependencies": {
2541
"@solana/web3.js": "^1.95.5"
@@ -40,6 +56,7 @@
4056
"eslint-plugin-require-extensions": "^0.1.1",
4157
"mocha": "^11.0.1",
4258
"prettier": "^3.4.2",
59+
"shx": "^0.3.4",
4360
"typescript": "^5.7.2",
4461
"start-server-and-test": "^2.0.8",
4562
"ts-node": "^10.9.2",

clients/js-legacy/pnpm-lock.yaml

+81
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { Keypair } = require('@solana/web3.js');
2+
const { createInitializeInstruction } = require('../../lib/cjs/index.js');
3+
4+
const record = Keypair.generate().publicKey;
5+
const authority = Keypair.generate().publicKey;
6+
7+
createInitializeInstruction(record, authority);
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This ensures that we do not rely on `__dirname` in ES modules even when it is polyfilled.
2+
globalThis.__dirname = 'DO_NOT_USE';
3+
4+
import { Keypair } from '@solana/web3.js';
5+
import { createInitializeInstruction } from '../../lib/esm/index.js';
6+
7+
const record = Keypair.generate().publicKey;
8+
const authority = Keypair.generate().publicKey;
9+
10+
createInitializeInstruction(record, authority);

clients/js-legacy/tsconfig.all.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig.root.json",
3+
"references": [
4+
{
5+
"path": "./tsconfig.cjs.json"
6+
},
7+
{
8+
"path": "./tsconfig.esm.json"
9+
}
10+
]
11+
}

clients/js-legacy/tsconfig.base.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"include": [],
3+
"compilerOptions": {
4+
"target": "ESNext",
5+
"module": "ESNext",
6+
"moduleResolution": "Node",
7+
"esModuleInterop": true,
8+
"isolatedModules": true,
9+
"noEmitOnError": true,
10+
"resolveJsonModule": true,
11+
"strict": true,
12+
"stripInternal": true
13+
}
14+
}

clients/js-legacy/tsconfig.cjs.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": [
4+
"src"
5+
],
6+
"compilerOptions": {
7+
"outDir": "lib/cjs",
8+
"target": "ES2016",
9+
"module": "CommonJS",
10+
"sourceMap": true
11+
}
12+
}

clients/js-legacy/tsconfig.esm.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": [
4+
"src"
5+
],
6+
"compilerOptions": {
7+
"outDir": "lib/esm",
8+
"declarationDir": "lib/types",
9+
"target": "ES2020",
10+
"module": "ES2020",
11+
"sourceMap": true,
12+
"declaration": true,
13+
"declarationMap": true
14+
}
15+
}

clients/js-legacy/tsconfig.json

+6-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
{
2-
"compilerOptions": {
3-
"composite": false,
4-
"declaration": true,
5-
"declarationMap": true,
6-
"esModuleInterop": true,
7-
"forceConsistentCasingInFileNames": true,
8-
"inlineSources": false,
9-
"isolatedModules": true,
10-
"module": "ESNext",
11-
"moduleResolution": "node",
12-
"noFallthroughCasesInSwitch": true,
13-
"noUnusedLocals": true,
14-
"noUnusedParameters": true,
15-
"outDir": "./dist",
16-
"preserveWatchOutput": true,
17-
"skipLibCheck": true,
18-
"strict": true,
19-
"target": "ESNext"
20-
},
21-
"exclude": [
22-
"node_modules"
23-
],
2+
"extends": "./tsconfig.all.json",
243
"include": [
254
"src",
265
"test"
27-
]
6+
],
7+
"compilerOptions": {
8+
"noEmit": true,
9+
"skipLibCheck": true
10+
}
2811
}

clients/js-legacy/tsconfig.root.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"composite": true
5+
}
6+
}

0 commit comments

Comments
 (0)