Fix cjs build
This commit is contained in:
parent
2070393423
commit
0888234da3
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"presets": [
|
||||
[ "@babel/preset-env", { "modules": "auto" } ]
|
||||
],
|
||||
"plugins": [
|
||||
"@babel/transform-runtime",
|
||||
["@babel/plugin-proposal-class-properties", { "loose": true }]
|
||||
],
|
||||
"ignore": [
|
||||
"**/*.test.js"
|
||||
]
|
||||
}
|
|
@ -4,6 +4,7 @@ node_modules
|
|||
# builds
|
||||
build
|
||||
dist
|
||||
lib
|
||||
.rpt2_cache
|
||||
|
||||
# misc
|
||||
|
|
24
package.json
24
package.json
|
@ -4,16 +4,14 @@
|
|||
"description": "Library for interacting with the serum dex",
|
||||
"license": "MIT",
|
||||
"repository": "serum-foundation/serum-js",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.module.js",
|
||||
"unpkg": "dist/index.umd.js",
|
||||
"main": "lib/index.js",
|
||||
"source": "src/index.js",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "microbundle",
|
||||
"start": "microbundle watch",
|
||||
"build": "yarn babel src --out-dir lib",
|
||||
"start": "yarn babel src --out-dir lib --watch",
|
||||
"prepare": "run-s build",
|
||||
"test": "run-s test:unit test:lint test:build",
|
||||
"test:build": "run-s build",
|
||||
|
@ -24,6 +22,11 @@
|
|||
"deploy": "gh-pages -d example/build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.10.5",
|
||||
"@babel/core": "^7.11.1",
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"@babel/plugin-transform-runtime": "^7.11.0",
|
||||
"@babel/preset-env": "^7.11.0",
|
||||
"@solana/web3.js": "^0.64.0",
|
||||
"babel-eslint": "^10.0.3",
|
||||
"cross-env": "^7.0.2",
|
||||
|
@ -38,7 +41,6 @@
|
|||
"eslint-plugin-react": "^7.17.0",
|
||||
"eslint-plugin-standard": "^4.0.1",
|
||||
"gh-pages": "^2.2.0",
|
||||
"microbundle": "^0.12.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.0.4",
|
||||
"react": "^16.13.1",
|
||||
|
@ -46,7 +48,7 @@
|
|||
"react-scripts": "^3.4.1"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"lib"
|
||||
],
|
||||
"jest": {
|
||||
"transformIgnorePatterns": [
|
||||
|
@ -61,5 +63,11 @@
|
|||
"@solana/web3.js": "^0.64.0",
|
||||
"bn.js": "^5.1.2",
|
||||
"buffer-layout": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all",
|
||||
"maintained node versions"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
export { Slab } from './slab';
|
||||
export { MarketState, Orderbook } from './market-state';
|
||||
|
|
|
@ -1,35 +1,11 @@
|
|||
import { blob, Layout, struct, u16, u32, u8, union } from 'buffer-layout';
|
||||
import { u64 } from './layout';
|
||||
import { u64, VersionedLayout } from './layout';
|
||||
import { PublicKey } from '@solana/web3.js';
|
||||
|
||||
export const DEX_PROGRAM_ID = new PublicKey(
|
||||
'6iM2JjaPVViB2u82aVjf3ZfHDNHQ4G635XgnvgN6CNhY',
|
||||
);
|
||||
|
||||
class VersionedLayout extends Layout {
|
||||
constructor(version, inner, property) {
|
||||
super(inner.span > 0 ? inner.span + 1 : inner.span, property);
|
||||
this.version = version;
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
decode(b, offset = 0) {
|
||||
if (b.readUInt8(offset) !== this._version) {
|
||||
throw new Error('invalid version');
|
||||
}
|
||||
return this.inner.decode(b, offset + 1);
|
||||
}
|
||||
|
||||
encode(src, b, offset = 0) {
|
||||
b.writeUInt8(this.version, offset);
|
||||
return 1 + this.inner.encode(src, b, offset + 1);
|
||||
}
|
||||
|
||||
getSpan(b, offset = 0) {
|
||||
return 1 + this.inner.getSpan(b, offset + 1);
|
||||
}
|
||||
}
|
||||
|
||||
export const INSTRUCTION_LAYOUT = new VersionedLayout(
|
||||
0,
|
||||
union(u32('instruction')),
|
||||
|
|
|
@ -81,9 +81,41 @@ export class WideBits extends Layout {
|
|||
}
|
||||
}
|
||||
|
||||
export class VersionedLayout extends Layout {
|
||||
constructor(version, inner, property) {
|
||||
super(inner.span > 0 ? inner.span + 1 : inner.span, property);
|
||||
this.version = version;
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
decode(b, offset = 0) {
|
||||
if (b.readUInt8(offset) !== this._version) {
|
||||
throw new Error('invalid version');
|
||||
}
|
||||
return this.inner.decode(b, offset + 1);
|
||||
}
|
||||
|
||||
encode(src, b, offset = 0) {
|
||||
b.writeUInt8(this.version, offset);
|
||||
return 1 + this.inner.encode(src, b, offset + 1);
|
||||
}
|
||||
|
||||
getSpan(b, offset = 0) {
|
||||
return 1 + this.inner.getSpan(b, offset + 1);
|
||||
}
|
||||
}
|
||||
|
||||
export function setLayoutDecoder(layout, decoder) {
|
||||
const originalDecode = layout.decode;
|
||||
layout.decode = function decode(b, offset = 0) {
|
||||
return decoder(originalDecode.call(this, b, offset));
|
||||
};
|
||||
}
|
||||
|
||||
export function setLayoutEncoder(layout, encoder) {
|
||||
const originalEncode = layout.encode;
|
||||
layout.encode = function encode(src, b, offset) {
|
||||
return originalEncode(encoder(src), b, offset);
|
||||
};
|
||||
return layout;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue