Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Fix Memo program ESM exports #3507

Merged
merged 8 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions memo/js/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
5 changes: 4 additions & 1 deletion memo/js/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
lib
docs
lib
test-ledger

package-lock.json
20 changes: 20 additions & 0 deletions memo/js/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier"
],
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/consistent-type-imports": "error"
}
}
12 changes: 0 additions & 12 deletions memo/js/.eslintrc.cjs

This file was deleted.

14 changes: 13 additions & 1 deletion memo/js/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
lib
.idea
.vscode
.DS_Store

node_modules

package-lock.json
pnpm-lock.yaml
yarn.lock

docs
lib
test-ledger
*.tsbuildinfo
Empty file added memo/js/.nojekyll
Empty file.
5 changes: 5 additions & 0 deletions memo/js/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docs
lib
test-ledger

package-lock.json
7 changes: 7 additions & 0 deletions memo/js/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": true
}
6 changes: 0 additions & 6 deletions memo/js/.prettierrc.yaml

This file was deleted.

17 changes: 13 additions & 4 deletions memo/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ A TypeScript library for interacting with the SPL Memo program.
## Install

```shell
yarn add @solana/spl-memo
npm install --save @solana/spl-memo @solana/web3.js
```
_OR_
```shell
yarn add @solana/spl-memo @solana/web3.js
```

## Build from Source

0. Prerequisites

* Node 16+
* NPM 8+

1. Clone the project:
```shell
git clone https://github.com/solana-labs/solana-program-library.git
Expand All @@ -28,15 +37,15 @@ cd solana-program-library/memo/js

3. Install the dependencies:
```shell
yarn install
npm install
```

4. Build the library:
```shell
yarn build
npm run build
```

5. Run the tests:
```shell
yarn test
npm run test
```
4 changes: 2 additions & 2 deletions memo/js/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
preset: 'ts-jest',
testEnvironment: 'node',
};
143 changes: 75 additions & 68 deletions memo/js/package.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,77 @@
{
"name": "@solana/spl-memo",
"version": "0.2.0",
"description": "SPL Memo Program JS API",
"files": [
"lib",
"src",
"LICENSE",
"README.md"
],
"main": "lib/cjs/index.js",
"module": "lib/esm/index.mjs",
"types": "lib/types/index.d.ts",
"type": "module",
"sideEffects": false,
"exports": {
"import": "./lib/esm/index.mjs",
"require": "./lib/cjs/index.js",
"types": "./lib/types/index.d.ts"
},
"scripts": {
"build": "yarn clean && tsc -p tsconfig.json && tsc-esm -p tsconfig.json && tsc -p tsconfig.cjs.json",
"postbuild": "echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
"clean": "rimraf ./lib",
"deploy": "yarn docs && gh-pages --dist docs --dest memo/ts --dotfiles",
"docs": "rimraf docs && NODE_OPTIONS=--max_old_space_size=4096 typedoc",
"lint": "eslint --max-warnings 0 . && npm run pretty",
"lint:fix": "eslint . --fix && npm run pretty:fix",
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "jest test/unit",
"test:e2e": "start-server-and-test 'solana-test-validator -r -q' http://localhost:8899/health 'jest test/e2e'"
},
"repository": {
"type": "git",
"url": "https://github.com/solana-labs/solana-program-library"
},
"publishConfig": {
"access": "public"
},
"author": "Solana Maintainers <[email protected]>",
"license": "Apache-2.0",
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/jest": "^28.1.1",
"@types/node": "^17.0.42",
"@types/node-fetch": "^2.6.1",
"@types/prettier": "^2.6.3",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"chai": "^4.3.6",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"jest": "^28.1.1",
"prettier": "^2.7.0",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"start-server-and-test": "^1.14.0",
"ts-jest": "^28.0.5",
"ts-node": "^10.8.1",
"typedoc": "^0.23.10",
"typescript": "^4.7.3",
"typescript-esm": "^2.0.0"
},
"dependencies": {
"@solana/web3.js": "^1.41.0",
"buffer": "^6.0.3"
}
"name": "@solana/spl-memo",
"description": "SPL Memo Program JS API",
"version": "0.3.1",
"author": "Solana Maintainers <[email protected]>",
"repository": "https://github.com/solana-labs/solana-program-library",
"license": "Apache-2.0",
"type": "module",
"sideEffects": false,
"engines": {
"node": ">=16"
},
"files": [
"lib",
"src",
"LICENSE",
"README.md"
],
"publishConfig": {
"access": "public"
},
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"exports": {
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts"
},
"scripts": {
"nuke": "shx rm -rf node_modules package-lock.json || true",
"reinstall": "npm run nuke && npm install",
"clean": "shx rm -rf lib **/*.tsbuildinfo || true",
"build": "tsc --build --verbose tsconfig.all.json",
"watch": "tsc --build --verbose --watch tsconfig.all.json",
"release": "npm run clean && npm run build",
"fmt": "prettier --write '{*,**/*}.{ts,tsx,js,jsx,json}'",
"lint": "prettier --check '{*,**/*}.{ts,tsx,js,jsx,json}' && eslint --max-warnings 0 .",
"lint:fix": "npm run fmt && eslint --fix .",
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "jest test/unit",
"test:e2e": "start-server-and-test 'solana-test-validator -r -q' http://localhost:8899/health 'jest test/e2e'",
"deploy": "npm run deploy:docs",
"docs": "shx rm -rf docs && typedoc && shx cp .nojekyll docs/",
"deploy:docs": "npm run docs && gh-pages --dist memo/js --dotfiles"
},
"peerDependencies": {
"@solana/web3.js": "^1.20.0"
},
"dependencies": {
"buffer": "^6.0.3"
},
"devDependencies": {
"@solana/web3.js": "^1.20.0",
"@types/chai": "^4.3.3",
"@types/jest": "^28.1.7",
"@types/node": "^18.7.9",
"@types/node-fetch": "^2.6.2",
"@types/prettier": "^2.7.0",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
"chai": "^4.3.6",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"gh-pages": "^3.2.3",
"jest": "^28.1.3",
"prettier": "^2.7.1",
"process": "^0.11.10",
"shx": "^0.3.4",
"start-server-and-test": "^1.14.0",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typedoc": "^0.23.10",
"typescript": "^4.7.4"
}
}
35 changes: 15 additions & 20 deletions memo/js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {Buffer} from 'buffer';
import {PublicKey, TransactionInstruction} from '@solana/web3.js';
import { Buffer } from 'buffer';
import { PublicKey, TransactionInstruction } from '@solana/web3.js';

export const MEMO_PROGRAM_ID: PublicKey = new PublicKey(
'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr',
);
export const MEMO_PROGRAM_ID: PublicKey = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');

/**
* Creates and returns an instruction which validates a string of UTF-8
Expand All @@ -24,20 +22,17 @@ export const MEMO_PROGRAM_ID: PublicKey = new PublicKey(
* succeed. null is allowed if there are no signers for the memo
* verification.
**/
export function createMemoInstruction(
memo: string,
signerPubkeys?: Array<PublicKey>,
): TransactionInstruction {
const keys =
signerPubkeys == null
? []
: signerPubkeys.map(function (key) {
return {pubkey: key, isSigner: true, isWritable: false};
});
export function createMemoInstruction(memo: string, signerPubkeys?: Array<PublicKey>): TransactionInstruction {
const keys =
signerPubkeys == null
? []
: signerPubkeys.map(function (key) {
return { pubkey: key, isSigner: true, isWritable: false };
});

return new TransactionInstruction({
keys: keys,
programId: MEMO_PROGRAM_ID,
data: Buffer.from(memo, 'utf8'),
});
return new TransactionInstruction({
keys: keys,
programId: MEMO_PROGRAM_ID,
data: Buffer.from(memo, 'utf8'),
});
}
35 changes: 12 additions & 23 deletions memo/js/test/e2e/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import {createMemoInstruction} from '../../src';
import {
Connection,
Keypair,
Transaction,
LAMPORTS_PER_SOL,
sendAndConfirmTransaction,
} from '@solana/web3.js';
import { createMemoInstruction } from '../../src';
import { Connection, Keypair, Transaction, LAMPORTS_PER_SOL, sendAndConfirmTransaction } from '@solana/web3.js';

test('transaction: live', async () => {
const url = 'http://localhost:8899';
const connection = new Connection(url, 'confirmed');
await connection.getVersion();
const signer = new Keypair(); // also fee-payer
const url = 'http://localhost:8899';
const connection = new Connection(url, 'confirmed');
await connection.getVersion();
const signer = new Keypair(); // also fee-payer

const airdropSignature = await connection.requestAirdrop(
signer.publicKey,
LAMPORTS_PER_SOL / 10,
);
await connection.confirmTransaction(airdropSignature, 'confirmed');
const airdropSignature = await connection.requestAirdrop(signer.publicKey, LAMPORTS_PER_SOL / 10);
await connection.confirmTransaction(airdropSignature, 'confirmed');

const memoTx = new Transaction().add(
createMemoInstruction('this is a test memo', [signer.publicKey]),
);
await sendAndConfirmTransaction(connection, memoTx, [signer], {
preflightCommitment: 'confirmed',
});
const memoTx = new Transaction().add(createMemoInstruction('this is a test memo', [signer.publicKey]));
await sendAndConfirmTransaction(connection, memoTx, [signer], {
preflightCommitment: 'confirmed',
});
});
Loading