Skip to content

Commit

Permalink
Merge pull request #1363 from drift-labs/chester/browser-only-compat
Browse files Browse the repository at this point in the history
refactor(sdk): force browser compatibility
  • Loading branch information
ChesterSim authored Dec 6, 2024
2 parents 2388c82 + c9736af commit 2237f06
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Binary file modified sdk/bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"lint": "eslint './**/*.{ts,tsx}' --quiet",
"build": "yarn clean && tsc -p tsconfig.json && tsc -p tsconfig.browser.json && node scripts/postbuild.js",
"build:browser": "yarn clean && tsc -p tsconfig.json && tsc -p tsconfig.browser.json && node scripts/postbuild.js --force-env browser",
"clean": "rm -rf lib",
"test": "mocha -r ts-node/register tests/**/*.ts",
"test:inspect": "mocha --inspect-brk -r ts-node/register tests/**/*.ts",
Expand Down Expand Up @@ -55,6 +56,7 @@
"strict-event-emitter-types": "^2.0.0",
"tweetnacl": "1.0.3",
"uuid": "^8.3.2",
"yargs": "^17.7.2",
"zstddec": "^0.1.0"
},
"devDependencies": {
Expand Down Expand Up @@ -87,4 +89,4 @@
"@solana/errors": "2.0.0-preview.4",
"@solana/codecs-data-structures": "2.0.0-preview.4"
}
}
}
15 changes: 13 additions & 2 deletions sdk/scripts/postbuild.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// scripts/postbuild.js
const fs = require('fs');
const path = require('path');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');

const isomorphicPackages = ['grpc'];
const forceEnv = yargs(hideBin(process.argv))
.option('force-env', {
type: 'string',
description: 'Specify environment to force (node or browser)',
choices: ['node', 'browser']
})
.argv?.forceEnv;

const isomorphicPackages = ['grpc'];
const environments = ['node', 'browser'];

environments.forEach((environment) => {
Expand All @@ -20,13 +29,15 @@ environments.forEach((environment) => {
package + '.js'
);

const targetEnv = forceEnv ? forceEnv : environment;

const targetPath = path.join(
__dirname,
'..',
'lib',
environment,
'isomorphic',
`${package}.${environment}.js`
`${package}.${targetEnv}.js`
);

try {
Expand Down

0 comments on commit 2237f06

Please sign in to comment.