Skip to content

Commit 900ed38

Browse files
authored
Use commonjs package type for JS client (#36)
After many hours of research, this appears to be the most versatile and interoperable way of publishing dual package libraries.
1 parent 41d47d0 commit 900ed38

File tree

9 files changed

+48
-36
lines changed

9 files changed

+48
-36
lines changed

.changeset/clever-wombats-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-solana-program": patch
3+
---
4+
5+
Use commonjs package type for JS client

template/clients/js/clients/js/_.eslintrc.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module.exports = {
22
extends: ['@solana/eslint-config-solana'],
3+
ignorePatterns: ['.eslintrc.cjs', 'tsup.config.ts', 'env-shim.ts'],
4+
parserOptions: {
5+
project: 'tsconfig.json',
6+
tsconfigRootDir: __dirname,
7+
sourceType: 'module',
8+
},
39
rules: {
410
'@typescript-eslint/ban-types': 'off',
511
'@typescript-eslint/sort-type-constituents': 'off',

template/clients/js/clients/js/package.json.njk

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"version": "0.0.0",
44
"description": "JavaScript client for the {{ programName | titleCase }} program",
55
"sideEffects": false,
6-
"module": "./dist/src/index.js",
7-
"main": "./dist/src/index.cjs",
8-
"types": "./dist/types/src/index.d.ts",
9-
"type": "module",
6+
"module": "./dist/src/index.mjs",
7+
"main": "./dist/src/index.js",
8+
"types": "./dist/types/index.d.ts",
9+
"type": "commonjs",
1010
"exports": {
1111
".": {
12-
"types": "./dist/types/src/index.d.ts",
13-
"import": "./dist/src/index.js",
14-
"require": "./dist/src/index.cjs"
12+
"types": "./dist/types/index.d.ts",
13+
"import": "./dist/src/index.mjs",
14+
"require": "./dist/src/index.js"
1515
}
1616
},
1717
"files": [

template/clients/js/clients/js/test/_setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
setTransactionMessageLifetimeUsingBlockhash,
2424
signTransactionMessageWithSigners,
2525
} from '@solana/web3.js';
26-
import { findCounterPda, getCreateInstructionAsync } from '../src/index.js';
26+
import { findCounterPda, getCreateInstructionAsync } from '../src';
2727

2828
type Client = {
2929
rpc: Rpc<SolanaRpcApi>;

template/clients/js/clients/js/test/create.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import {
88
Counter,
99
fetchCounterFromSeeds,
1010
getCreateInstructionAsync,
11-
} from '../src/index.js';
11+
} from '../src';
1212
import {
1313
createDefaultSolanaClient,
1414
createDefaultTransaction,
1515
generateKeyPairSignerWithSol,
1616
signAndSendTransaction,
17-
} from './_setup.js';
17+
} from './_setup';
1818

1919
test('it creates a new counter account', async (t) => {
2020
// Given an authority key pair with some SOL.

template/clients/js/clients/js/test/increment.test.ts.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import {
1515
findCounterPda,
1616
getIncrementInstruction,
1717
getIncrementInstructionAsync,
18-
} from '../src/index.js';
18+
} from '../src';
1919
import {
2020
createCounterForAuthority,
2121
createDefaultSolanaClient,
2222
createDefaultTransaction,
2323
generateKeyPairSignerWithSol,
2424
getBalance,
2525
signAndSendTransaction,
26-
} from './_setup.js';
26+
} from './_setup';
2727

2828
test('it increments an existing counter by 1 by default', async (t) => {
2929
// Given an authority key pair with an associated counter account of value 0.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"compilerOptions": {
3-
"declaration": true,
4-
"declarationMap": true,
5-
"emitDeclarationOnly": true,
6-
"outDir": "./dist/types",
3+
"declaration": true,
4+
"declarationMap": true,
5+
"emitDeclarationOnly": true,
6+
"outDir": "./dist/types",
77
},
8-
"extends": "./tsconfig.json"
8+
"extends": "./tsconfig.json",
9+
"include": ["src"]
910
}

template/clients/js/clients/js/tsconfig.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
4-
"composite": false,
5-
"declaration": true,
6-
"declarationMap": true,
7-
"esModuleInterop": true,
8-
"forceConsistentCasingInFileNames": true,
9-
"inlineSources": false,
10-
"isolatedModules": true,
11-
"module": "ESNext",
12-
"moduleResolution": "node",
13-
"noFallthroughCasesInSwitch": true,
14-
"noUnusedLocals": true,
15-
"noUnusedParameters": true,
16-
"outDir": "./dist",
17-
"preserveWatchOutput": true,
18-
"skipLibCheck": true,
19-
"strict": true,
20-
"target": "ESNext"
4+
"composite": false,
5+
"declaration": true,
6+
"declarationMap": true,
7+
"esModuleInterop": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"inlineSources": false,
10+
"isolatedModules": true,
11+
"module": "ESNext",
12+
"moduleResolution": "node",
13+
"noFallthroughCasesInSwitch": true,
14+
"noUnusedLocals": true,
15+
"noUnusedParameters": true,
16+
"outDir": "./dist",
17+
"preserveWatchOutput": true,
18+
"skipLibCheck": true,
19+
"strict": true,
20+
"target": "ESNext"
2121
},
2222
"exclude": ["node_modules"],
2323
"include": ["src", "test"]

template/clients/js/clients/js/tsup.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const SHARED_OPTIONS: Options = {
77
entry: ['./src/index.ts'],
88
inject: [path.resolve(__dirname, 'env-shim.ts')],
99
outDir: './dist/src',
10-
outExtension: ({ format }) => ({ js: format === 'cjs' ? '.cjs' : '.js' }),
10+
outExtension: ({ format }) => ({ js: format === 'cjs' ? '.js' : '.mjs' }),
1111
sourcemap: true,
1212
treeshake: true,
1313
};
@@ -22,7 +22,7 @@ export default defineConfig(() => [
2222
...SHARED_OPTIONS,
2323
bundle: false,
2424
entry: ['./test/*.ts'],
25-
format: 'esm',
25+
format: 'cjs',
2626
outDir: './dist/test',
2727
},
2828
]);

0 commit comments

Comments
 (0)