Skip to content

Commit

Permalink
fix: early pollyfill import (#81)
Browse files Browse the repository at this point in the history
* chore: rework on sonarcloud

* fix: support axios imports before w3f library

* fix: jest test
  • Loading branch information
mkykadir authored Nov 24, 2023
1 parent a09c9a1 commit 9af7269
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-meals-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gelatonetwork/web3-functions-sdk": patch
---

fix: support axios imports before lib import
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
src/resolvers/fails
.tmp
jest.config.ts
jest.setup.ts
__test__
src/web3-functions
polyfill
Expand Down
2 changes: 2 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
module: "commonjs",
transform: {},
collectCoverage: true,
collectCoverageFrom: ["src/**/*.ts"],
Expand All @@ -25,4 +26,5 @@ module.exports = {
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
setupFilesAfterEnv: ["./jest.setup.ts"],
};
10 changes: 10 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { dirname } from "path";
import { fileURLToPath } from "url";

// Mimic __dirname behavior in ES modules for Jest
const currentFolder = dirname(fileURLToPath(import.meta.url));

///Users/mky/Projects/gelato/w3f/sdk/web3-functions-sdk/src/lib/builder/Web3FunctionBuilder.ts
const __dirname = `${currentFolder}/src/lib/builder/`;

global.__dirname = __dirname;
9 changes: 5 additions & 4 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ sonar.javascript.lcov.reportPaths=./coverage/lcov.info

sonar.qualitygate.wait=true

sonar.exclusions=**\*spec.ts,src\lib\polyfill,src\web3-functions,jest.config.ts
sonar.coverage.exclusions=**\*spec.ts,src\lib\polyfill,src\web3-functions,jest.config.ts
sonar.cpd.exclusions=**\*spec.ts,src\lib\polyfill,src\web3-functions,jest.config.ts
sonar.exclusions=**/*spec.ts,src/lib/polyfill/*,jest.config.ts
sonar.coverage.exclusions=**/*spec.ts,src/lib/polyfill/*,jest.config.ts
sonar.cpd.exclusions=**/*spec.ts,src/lib/polyfill/*,jest.config.ts

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=web3-functions-sdk
#sonar.projectVersion=1.0


# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.
sonar.sources=src/lib/
sonar.tests=src/web3-functions/

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
1 change: 0 additions & 1 deletion src/lib/Web3Function.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BigNumber } from "@ethersproject/bignumber";
import { diff } from "deep-object-diff";
import { Web3FunctionHttpServer } from "./net/Web3FunctionHttpServer";
import "./polyfill/XMLHttpRequest";
import { Web3FunctionMultiChainProvider } from "./provider/Web3FunctionMultiChainProvider";
import {
Web3FunctionContext,
Expand Down
1 change: 1 addition & 0 deletions src/lib/builder/Web3FunctionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class Web3FunctionBuilder {
target: "es2022",
format: "esm",
minify: true,
inject: [path.join(__dirname, "../polyfill/XMLHttpRequest.js")],
alias,
outfile,
};
Expand Down
3 changes: 2 additions & 1 deletion src/web3-functions/axios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Web3Function } from "@gelatonetwork/web3-functions-sdk";
import axios from "axios";

import { Web3Function } from "@gelatonetwork/web3-functions-sdk";

Web3Function.onRun(async () => {
try {
console.log("Sending zenquote API request");
Expand Down

0 comments on commit 9af7269

Please sign in to comment.