fix: update buffer-layout to fix downstream bundler issues (#18529)
* fix: update buffer-layout to fix downstream bundler issues * chore: run check on generated type declaration
This commit is contained in:
parent
6188283ba6
commit
4fb1c9da26
File diff suppressed because it is too large
Load Diff
|
@ -63,11 +63,11 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@solana/buffer-layout": "^3.0.0",
|
||||
"bn.js": "^5.0.0",
|
||||
"borsh": "^0.4.0",
|
||||
"bs58": "^4.0.1",
|
||||
"buffer": "6.0.1",
|
||||
"buffer-layout": "^1.2.0",
|
||||
"crypto-hash": "^1.2.2",
|
||||
"jayson": "^3.4.4",
|
||||
"js-sha3": "^0.8.0",
|
||||
|
@ -98,6 +98,7 @@
|
|||
"@types/bs58": "^4.0.1",
|
||||
"@types/chai": "^4.2.15",
|
||||
"@types/chai-as-promised": "^7.1.3",
|
||||
"@types/express-serve-static-core": "^4.17.21",
|
||||
"@types/mocha": "^8.2.1",
|
||||
"@types/mz": "^2.7.3",
|
||||
"@types/node": "^16.0.0",
|
||||
|
|
|
@ -51,10 +51,11 @@ function generateConfig(configType, format) {
|
|||
// Prevent dependencies from being bundled
|
||||
config.external = [
|
||||
/@babel\/runtime/,
|
||||
'@solana/buffer-layout',
|
||||
'bn.js',
|
||||
'borsh',
|
||||
'bs58',
|
||||
'buffer-layout',
|
||||
'buffer',
|
||||
'crypto-hash',
|
||||
'jayson/lib/client/browser',
|
||||
'js-sha3',
|
||||
|
@ -81,11 +82,11 @@ function generateConfig(configType, format) {
|
|||
// Prevent dependencies from being bundled
|
||||
config.external = [
|
||||
/@babel\/runtime/,
|
||||
'@solana/buffer-layout',
|
||||
'bn.js',
|
||||
'borsh',
|
||||
'bs58',
|
||||
'buffer',
|
||||
'buffer-layout',
|
||||
'crypto-hash',
|
||||
'jayson/lib/client/browser',
|
||||
'js-sha3',
|
||||
|
|
|
@ -17,3 +17,6 @@ sed -i '2s;^;declare module "@solana/web3.js" {\n;' lib/index.d.ts
|
|||
|
||||
# Run prettier
|
||||
npx prettier --write lib/index.d.ts
|
||||
|
||||
# Check result
|
||||
npx tsc lib/index.d.ts
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as nacl from 'tweetnacl';
|
||||
import type {SignKeyPair as KeyPair} from 'tweetnacl';
|
||||
import type {Buffer} from 'buffer';
|
||||
|
||||
import {toBuffer} from './util/to-buffer';
|
||||
import {PublicKey} from './publickey';
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import type {Buffer} from 'buffer';
|
||||
|
||||
import {PublicKey} from './publickey';
|
||||
import {Loader} from './loader';
|
||||
import type {Connection} from './connection';
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
declare module 'buffer-layout';
|
|
@ -1,5 +1,4 @@
|
|||
// @ts-ignore
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
/**
|
||||
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {Buffer} from 'buffer';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
import * as Layout from './layout';
|
||||
|
||||
|
@ -10,7 +10,7 @@ export type InstructionType = {
|
|||
/** The Instruction index (from solana upstream program) */
|
||||
index: number;
|
||||
/** The BufferLayout to use to build data */
|
||||
layout: typeof BufferLayout;
|
||||
layout: BufferLayout.Layout;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
import {Buffer} from 'buffer';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
/**
|
||||
* Layout for a public key
|
||||
*/
|
||||
export const publicKey = (property: string = 'publicKey'): Object => {
|
||||
export const publicKey = (
|
||||
property: string = 'publicKey',
|
||||
): BufferLayout.Layout => {
|
||||
return BufferLayout.blob(32, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Layout for a 64bit unsigned value
|
||||
*/
|
||||
export const uint64 = (property: string = 'uint64'): Object => {
|
||||
export const uint64 = (property: string = 'uint64'): BufferLayout.Layout => {
|
||||
return BufferLayout.blob(8, property);
|
||||
};
|
||||
|
||||
|
@ -32,7 +34,7 @@ export const rustString = (property: string = 'string') => {
|
|||
|
||||
rsl.decode = (buffer: any, offset: any) => {
|
||||
const data = _decode(buffer, offset);
|
||||
return data.chars.toString('utf8');
|
||||
return data['chars'].toString('utf8');
|
||||
};
|
||||
|
||||
rsl.encode = (str: any, buffer: any, offset: any) => {
|
||||
|
@ -42,7 +44,7 @@ export const rustString = (property: string = 'string') => {
|
|||
return _encode(data, buffer, offset);
|
||||
};
|
||||
|
||||
rsl.alloc = (str: any) => {
|
||||
(rsl as any).alloc = (str: any) => {
|
||||
return (
|
||||
BufferLayout.u32().span +
|
||||
BufferLayout.u32().span +
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {Buffer} from 'buffer';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
import {PublicKey} from './publickey';
|
||||
import {Transaction, PACKET_DATA_SIZE} from './transaction';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import bs58 from 'bs58';
|
||||
import {Buffer} from 'buffer';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
import {PublicKey} from './publickey';
|
||||
import type {Blockhash} from './blockhash';
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
import {Buffer} from 'buffer';
|
||||
|
||||
import type {Blockhash} from './blockhash';
|
||||
import * as Layout from './layout';
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import BN from 'bn.js';
|
||||
import bs58 from 'bs58';
|
||||
import {Buffer} from 'buffer';
|
||||
import nacl from 'tweetnacl';
|
||||
import {sha256} from 'crypto-hash';
|
||||
import {Buffer} from 'buffer';
|
||||
|
||||
import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
|
||||
import {toBuffer} from './util/to-buffer';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {Buffer} from 'buffer';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
import secp256k1 from 'secp256k1';
|
||||
import assert from 'assert';
|
||||
import {keccak_256} from 'js-sha3';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
import {encodeData, decodeData, InstructionType} from './instruction';
|
||||
import * as Layout from './layout';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
import {encodeData, decodeData, InstructionType} from './instruction';
|
||||
import * as Layout from './layout';
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import type {Buffer} from 'buffer';
|
||||
|
||||
import {Connection} from '../connection';
|
||||
import type {TransactionSignature} from '../transaction';
|
||||
import type {ConfirmOptions} from '../connection';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {Buffer} from 'buffer';
|
||||
|
||||
export const toBuffer = (arr: Buffer | Uint8Array | Array<number>): Buffer => {
|
||||
if (arr instanceof Buffer) {
|
||||
if (Buffer.isBuffer(arr)) {
|
||||
return arr;
|
||||
} else if (arr instanceof Uint8Array) {
|
||||
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
||||
|
|
|
@ -94,8 +94,8 @@ export class ValidatorInfo {
|
|||
|
||||
if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
|
||||
if (configKeys[1].isSigner) {
|
||||
const rawInfo = Layout.rustString().decode(Buffer.from(byteArray));
|
||||
const info = JSON.parse(rawInfo);
|
||||
const rawInfo: any = Layout.rustString().decode(Buffer.from(byteArray));
|
||||
const info = JSON.parse(rawInfo as string);
|
||||
assertType(info, InfoString);
|
||||
return new ValidatorInfo(configKeys[1].publicKey, info);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as BufferLayout from 'buffer-layout';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
import type {Buffer} from 'buffer';
|
||||
|
||||
import * as Layout from './layout';
|
||||
import {PublicKey} from './publickey';
|
||||
|
|
|
@ -2363,8 +2363,8 @@ describe('Connection', () => {
|
|||
).value;
|
||||
if (accountInfo) {
|
||||
const data = accountInfo.data;
|
||||
if (data instanceof Buffer) {
|
||||
expect(data instanceof Buffer).to.eq(false);
|
||||
if (Buffer.isBuffer(data)) {
|
||||
expect(Buffer.isBuffer(data)).to.eq(false);
|
||||
} else {
|
||||
expect(data.program).to.eq('spl-token');
|
||||
expect(data.parsed).to.be.ok;
|
||||
|
@ -2379,8 +2379,8 @@ describe('Connection', () => {
|
|||
tokenAccounts.forEach(({account}) => {
|
||||
expect(account.owner).to.eql(TOKEN_PROGRAM_ID);
|
||||
const data = account.data;
|
||||
if (data instanceof Buffer) {
|
||||
expect(data instanceof Buffer).to.eq(false);
|
||||
if (Buffer.isBuffer(data)) {
|
||||
expect(Buffer.isBuffer(data)).to.eq(false);
|
||||
} else {
|
||||
expect(data.parsed).to.be.ok;
|
||||
expect(data.program).to.eq('spl-token');
|
||||
|
@ -2397,8 +2397,8 @@ describe('Connection', () => {
|
|||
tokenAccounts.forEach(({account}) => {
|
||||
expect(account.owner).to.eql(TOKEN_PROGRAM_ID);
|
||||
const data = account.data;
|
||||
if (data instanceof Buffer) {
|
||||
expect(data instanceof Buffer).to.eq(false);
|
||||
if (Buffer.isBuffer(data)) {
|
||||
expect(Buffer.isBuffer(data)).to.eq(false);
|
||||
} else {
|
||||
expect(data.parsed).to.be.ok;
|
||||
expect(data.program).to.eq('spl-token');
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"declarationDir": "declarations",
|
||||
"esModuleInterop": true,
|
||||
|
|
Loading…
Reference in New Issue