Skip to content

Commit

Permalink
Fix polyfills and update SDK version (#4)
Browse files Browse the repository at this point in the history
* FIX: polyfills now don't need fs module

* [email protected]

---------

Co-authored-by: Lesther Caballero <[email protected]>
  • Loading branch information
itslesther and Lesther Caballero authored Mar 12, 2024
1 parent d486ea1 commit c680ecf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swisstronik/sdk",
"version": "1.3.0",
"version": "1.4.0",
"description": "TypeScript SDK for Swisstronik Network",
"license": "Apache-2.0",
"source": "src/index.ts",
Expand Down
28 changes: 11 additions & 17 deletions packages/sdk/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import pathModule from "path";
import fs from "fs";
import { esmCjsMaps } from "./esm-cjs-maps.js";

// @ts-ignore
import packageJson from "./package.json" assert { type: "json" };

/*
This is a polyfill for the "require" Commonjs function
This is needed because there are some dependencies that are not ESM compatible
and we need to use the Commonjs version of the package
*/
if (fs.existsSync("package.json")) {
const packageJson = fs.readFileSync("package.json", "utf-8");
const packageJsonObj = JSON.parse(packageJson);

if (packageJsonObj && packageJsonObj.type === "commonjs") {
module.constructor.prototype.require = function (path: string) {
var self = this;
if (packageJson && packageJson.type === "commonjs") {
module.constructor.prototype.require = function (path: string) {
var self = this;

if (
typeof esmCjsMaps[path] === "string"
) {
const dep = pathModule.resolve(__dirname, "deps", esmCjsMaps[path]);
return self.constructor._load(dep, self);
}
return self.constructor._load(path, self);
};
}
if (typeof esmCjsMaps[path] === "string") {
const dep = pathModule.resolve(__dirname, "deps", esmCjsMaps[path]);
return self.constructor._load(dep, self);
}
return self.constructor._load(path, self);
};
}
2 changes: 1 addition & 1 deletion packages/sdk/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
TxRaw
} from 'cosmjs-types/cosmos/tx/v1beta1/tx.js'
import { SignMode } from 'cosmjs-types/cosmos/tx/signing/v1beta1/signing.js'
import { Any } from 'cosmjs-types/google/protobuf/any.js'
import {Any } from './types-proto/google/protobuf/any.js'
import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin.js'
import Long from 'long'
import { PubKey as CosmosCryptoEd25519Pubkey } from "cosmjs-types/cosmos/crypto/ed25519/keys.js";
Expand Down

0 comments on commit c680ecf

Please sign in to comment.