Эх сурвалжийг харах

Use commonjs package type for JS client

After many hours of research, this appears to be the most versatile and interoperable way of publishing dual package libraries.
Loris Leiva 1 жил өмнө
parent
commit
7c30349f0f

+ 1 - 1
clients/js/.eslintrc.cjs

@@ -1,6 +1,6 @@
 module.exports = {
 module.exports = {
   extends: ['@solana/eslint-config-solana'],
   extends: ['@solana/eslint-config-solana'],
-  ignorePatterns: ['.eslintrc.cjs'],
+  ignorePatterns: ['.eslintrc.cjs', 'tsup.config.ts', 'env-shim.ts'],
   parserOptions: {
   parserOptions: {
     project: 'tsconfig.json',
     project: 'tsconfig.json',
     tsconfigRootDir: __dirname,
     tsconfigRootDir: __dirname,

+ 8 - 8
clients/js/package.json

@@ -1,17 +1,17 @@
 {
 {
   "name": "@solana-program/system",
   "name": "@solana-program/system",
-  "version": "0.3.1",
+  "version": "0.3.2",
   "description": "JavaScript client for the System program",
   "description": "JavaScript client for the System program",
   "sideEffects": false,
   "sideEffects": false,
-  "module": "./dist/src/index.js",
-  "main": "./dist/src/index.cjs",
-  "types": "./dist/types/src/index.d.ts",
-  "type": "module",
+  "module": "./dist/src/index.mjs",
+  "main": "./dist/src/index.js",
+  "types": "./dist/types/index.d.ts",
+  "type": "commonjs",
   "exports": {
   "exports": {
     ".": {
     ".": {
-      "types": "./dist/types/src/index.d.ts",
-      "import": "./dist/src/index.js",
-      "require": "./dist/src/index.cjs"
+      "types": "./dist/types/index.d.ts",
+      "import": "./dist/src/index.mjs",
+      "require": "./dist/src/index.js"
     }
     }
   },
   },
   "files": [
   "files": [

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

@@ -27,7 +27,7 @@ import {
   getCreateAccountInstruction,
   getCreateAccountInstruction,
   getInitializeNonceAccountInstruction,
   getInitializeNonceAccountInstruction,
   getNonceSize,
   getNonceSize,
-} from '../src/index.js';
+} from '../src';
 
 
 type Client = {
 type Client = {
   rpc: Rpc<SolanaRpcApi>;
   rpc: Rpc<SolanaRpcApi>;

+ 2 - 2
clients/js/test/advanceNonceAccount.test.ts

@@ -4,14 +4,14 @@ import {
   pipe,
   pipe,
 } from '@solana/web3.js';
 } from '@solana/web3.js';
 import test from 'ava';
 import test from 'ava';
-import { fetchNonce, getAdvanceNonceAccountInstruction } from '../src/index.js';
+import { fetchNonce, getAdvanceNonceAccountInstruction } from '../src';
 import {
 import {
   createDefaultSolanaClient,
   createDefaultSolanaClient,
   createDefaultTransaction,
   createDefaultTransaction,
   createNonceAccount,
   createNonceAccount,
   generateKeyPairSignerWithSol,
   generateKeyPairSignerWithSol,
   signAndSendTransaction,
   signAndSendTransaction,
-} from './_setup.js';
+} from './_setup';
 
 
 test('it advances the nonce account', async (t) => {
 test('it advances the nonce account', async (t) => {
   // Given an existing nonce account.
   // Given an existing nonce account.

+ 2 - 5
clients/js/test/createAccount.test.ts

@@ -5,16 +5,13 @@ import {
   pipe,
   pipe,
 } from '@solana/web3.js';
 } from '@solana/web3.js';
 import test from 'ava';
 import test from 'ava';
-import {
-  SYSTEM_PROGRAM_ADDRESS,
-  getCreateAccountInstruction,
-} from '../src/index.js';
+import { SYSTEM_PROGRAM_ADDRESS, getCreateAccountInstruction } from '../src';
 import {
 import {
   createDefaultSolanaClient,
   createDefaultSolanaClient,
   createDefaultTransaction,
   createDefaultTransaction,
   generateKeyPairSignerWithSol,
   generateKeyPairSignerWithSol,
   signAndSendTransaction,
   signAndSendTransaction,
-} from './_setup.js';
+} from './_setup';
 
 
 test('it creates a new empty account', async (t) => {
 test('it creates a new empty account', async (t) => {
   // Given we have a newly generated account keypair to create with 42 bytes of space.
   // Given we have a newly generated account keypair to create with 42 bytes of space.

+ 2 - 2
clients/js/test/initializeNonceAccount.test.ts

@@ -14,13 +14,13 @@ import {
   getCreateAccountInstruction,
   getCreateAccountInstruction,
   getInitializeNonceAccountInstruction,
   getInitializeNonceAccountInstruction,
   getNonceSize,
   getNonceSize,
-} from '../src/index.js';
+} from '../src';
 import {
 import {
   createDefaultSolanaClient,
   createDefaultSolanaClient,
   createDefaultTransaction,
   createDefaultTransaction,
   generateKeyPairSignerWithSol,
   generateKeyPairSignerWithSol,
   signAndSendTransaction,
   signAndSendTransaction,
-} from './_setup.js';
+} from './_setup';
 
 
 test('it creates and initialize a durable nonce account', async (t) => {
 test('it creates and initialize a durable nonce account', async (t) => {
   // Given some brand now payer, authority, and nonce KeyPairSigners.
   // Given some brand now payer, authority, and nonce KeyPairSigners.

+ 2 - 5
clients/js/test/transferSol.test.ts

@@ -7,17 +7,14 @@ import {
   pipe,
   pipe,
 } from '@solana/web3.js';
 } from '@solana/web3.js';
 import test from 'ava';
 import test from 'ava';
-import {
-  getTransferSolInstruction,
-  parseTransferSolInstruction,
-} from '../src/index.js';
+import { getTransferSolInstruction, parseTransferSolInstruction } from '../src';
 import {
 import {
   createDefaultSolanaClient,
   createDefaultSolanaClient,
   createDefaultTransaction,
   createDefaultTransaction,
   generateKeyPairSignerWithSol,
   generateKeyPairSignerWithSol,
   getBalance,
   getBalance,
   signAndSendTransaction,
   signAndSendTransaction,
-} from './_setup.js';
+} from './_setup';
 
 
 test('it transfers SOL from one account to another', async (t) => {
 test('it transfers SOL from one account to another', async (t) => {
   // Given a source account with 3 SOL and a destination account with no SOL.
   // Given a source account with 3 SOL and a destination account with no SOL.

+ 6 - 5
clients/js/tsconfig.declarations.json

@@ -1,9 +1,10 @@
 {
 {
   "compilerOptions": {
   "compilerOptions": {
-      "declaration": true,
-      "declarationMap": true,
-      "emitDeclarationOnly": true,
-      "outDir": "./dist/types",
+    "declaration": true,
+    "declarationMap": true,
+    "emitDeclarationOnly": true,
+    "outDir": "./dist/types"
   },
   },
-  "extends": "./tsconfig.json"
+  "extends": "./tsconfig.json",
+  "include": ["src"]
 }
 }

+ 2 - 2
clients/js/tsup.config.ts

@@ -7,7 +7,7 @@ const SHARED_OPTIONS: Options = {
   entry: ['./src/index.ts'],
   entry: ['./src/index.ts'],
   inject: [path.resolve(__dirname, 'env-shim.ts')],
   inject: [path.resolve(__dirname, 'env-shim.ts')],
   outDir: './dist/src',
   outDir: './dist/src',
-  outExtension: ({ format }) => ({ js: format === 'cjs' ? '.cjs' : '.js' }),
+  outExtension: ({ format }) => ({ js: format === 'cjs' ? '.js' : '.mjs' }),
   sourcemap: true,
   sourcemap: true,
   treeshake: true,
   treeshake: true,
 };
 };
@@ -22,7 +22,7 @@ export default defineConfig(() => [
     ...SHARED_OPTIONS,
     ...SHARED_OPTIONS,
     bundle: false,
     bundle: false,
     entry: ['./test/*.ts'],
     entry: ['./test/*.ts'],
-    format: 'esm',
+    format: 'cjs',
     outDir: './dist/test',
     outDir: './dist/test',
   },
   },
 ]);
 ]);