Skip to content

Commit

Permalink
this is getting silly
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Sep 20, 2024
1 parent 7ac9093 commit 5d12c5f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"dist/**/*"
],
"scripts": {
"build": "rm -rf dist/* && yarn build:esm && yarn build:cjs",
"build:esm": "tsc -p tsconfig.esm.json && cp package.json dist/esm",
"build:cjs": "tsc -p tsconfig.cjs.json && cp package.json dist/cjs",
"build": "rm -rf dist/* && yarn build:esm && yarn build:cjs && package.json dist",
"build:esm": "tsc -p tsconfig.esm.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"test": "jest",
"fmt": "prettier --write \"./**/*.ts\"",
"lint": "eslint ./src"
Expand Down
6 changes: 3 additions & 3 deletions src/api/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
payloadJSON,
payloadSearchParams,
} from "../types";
import { version } from "../../package.json";
import fetch from "cross-fetch";
import log from "loglevel";
import { logPrefix } from "../utils";
import { getVersion, logPrefix } from "../utils";

const CLIENT_VERSION = getVersion();
const BASE_URL = "https://api.dune.com/api";

enum RequestMethod {
Expand Down Expand Up @@ -86,7 +86,7 @@ export class Router {
method,
headers: {
"x-dune-api-key": this.apiKey,
"User-Agent": `client-sdk@${version} (https://www.npmjs.com/package/@duneanalytics/client-sdk)`,
"User-Agent": `client-sdk@${CLIENT_VERSION} (https://www.npmjs.com/package/@duneanalytics/client-sdk)`,
"Content-Type": content_type,
},
// conditionally add the body property
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@ export function withDefaults<T>(obj: T, defaults: Partial<T>): T {
}
return result as T;
}

export function getVersion(): string {
try {
// @ts-expect-error: cheeky hack
import { version } from "../package.json";
return version;
} catch {
// @ts-expect-error: cheeky hack
import { version } from "../../package.json";
return version;
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@

"rootDir": "src"
},
"include": ["src"],
"include": ["src", "package.json"],
"exclude": ["node_modules", "dist", "tests"] // Added "dist" to avoid recompiling the output
}

0 comments on commit 5d12c5f

Please sign in to comment.