Просмотр исходного кода

Mark the generated client as an ES Module (#21)

* Mark the generated client as an ES Module

* Create silent-paws-repeat.md

* Build at the highest target possible, and use ESM in tests
Steven Luscher 1 год назад
Родитель
Сommit
a25f252e44

+ 5 - 0
.changeset/silent-paws-repeat.md

@@ -0,0 +1,5 @@
+---
+"create-solana-program": patch
+---
+
+Generated clients can now be imported into ESM projects

+ 1 - 0
template/clients/js/clients/js/package.json.njk

@@ -6,6 +6,7 @@
   "module": "./dist/src/index.mjs",
   "main": "./dist/src/index.js",
   "types": "./dist/types/src/index.d.ts",
+  "type": "module",
   "exports": {
     ".": {
       "types": "./dist/types/src/index.d.ts",

+ 1 - 1
template/clients/js/clients/js/test/_setup.ts

@@ -23,7 +23,7 @@ import {
   setTransactionLifetimeUsingBlockhash,
   signTransactionWithSigners,
 } from '@solana/web3.js';
-import { findCounterPda, getCreateInstructionAsync } from '../src';
+import { findCounterPda, getCreateInstructionAsync } from '../src/index.js';
 
 type Client = {
   rpc: Rpc<SolanaRpcApi>;

+ 2 - 2
template/clients/js/clients/js/test/create.test.ts

@@ -4,13 +4,13 @@ import {
   Counter,
   fetchCounterFromSeeds,
   getCreateInstructionAsync,
-} from '../src';
+} from '../src/index.js';
 import {
   createDefaultSolanaClient,
   createDefaultTransaction,
   generateKeyPairSignerWithSol,
   signAndSendTransaction,
-} from './_setup';
+} from './_setup.js';
 
 test('it creates a new counter account', async (t) => {
   // Given an authority key pair with some SOL.

+ 2 - 2
template/clients/js/clients/js/test/increment.test.ts.njk

@@ -5,7 +5,7 @@ import {
   findCounterPda,
   getIncrementInstruction,
   getIncrementInstructionAsync,
-} from '../src';
+} from '../src/index.js';
 import {
   createCounterForAuthority,
   createDefaultSolanaClient,
@@ -13,7 +13,7 @@ import {
   generateKeyPairSignerWithSol,
   getBalance,
   signAndSendTransaction,
-} from './_setup';
+} from './_setup.js';
 
 test('it increments an existing counter by 1 by default', async (t) => {
   // Given an authority key pair with an associated counter account of value 0.

+ 1 - 1
template/clients/js/clients/js/tsconfig.json

@@ -8,7 +8,7 @@
       "forceConsistentCasingInFileNames": true,
       "inlineSources": false,
       "isolatedModules": true,
-      "module": "commonjs",
+      "module": "ESNext",
       "moduleResolution": "node",
       "noFallthroughCasesInSwitch": true,
       "noUnusedLocals": true,

+ 1 - 1
template/clients/js/clients/js/tsup.config.ts

@@ -21,7 +21,7 @@ export default defineConfig(() => [
     ...SHARED_OPTIONS,
     bundle: false,
     entry: ['./test/*.ts'],
-    format: 'cjs',
+    format: 'esm',
     outDir: './dist/test',
   },
 ]);