Skip to content

Commit 175e121

Browse files
committed
Export a constant on the api-client-core connection for the current package version so we can selectively apply tracing gadget side
1 parent c0c5156 commit 175e121

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import fs from "fs/promises";
2+
import globby from "globby";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
// replace version constant strings with the version we're about to release
10+
11+
const version = JSON.parse(await fs.readFile(path.join(__dirname, "..", "package.json"), "utf-8")).version;
12+
13+
for (const file of await globby(path.join(__dirname, "..", "dist"), { onlyFiles: true })) {
14+
const content = await fs.readFile(file, "utf-8");
15+
if (content.includes("<prerelease>")) {
16+
await fs.writeFile(file, content.replace("<prerelease>", version));
17+
}
18+
}

packages/api-client-core/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"sideEffects": false,
2323
"scripts": {
2424
"typecheck": "tsc --noEmit",
25-
"build": "rm -rf dist && tsc -b tsconfig.cjs.json tsconfig.esm.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
25+
"build": "rm -rf dist && tsc -b tsconfig.cjs.json tsconfig.esm.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && echo '{\"type\": \"module\"}' > dist/esm/package.json && node --loader ts-node/esm build/replace-version-constant.ts",
2626
"watch": "rm -rf dist && tsc --watch --preserveWatchOutput",
2727
"prepublishOnly": "pnpm build",
2828
"prerelease": "gitpkg publish"
@@ -40,11 +40,13 @@
4040
"devDependencies": {
4141
"@types/node": "^16.11.7",
4242
"conditional-type-checks": "^1.0.6",
43+
"globby": "^11.0.4",
4344
"gql-tag": "^1.0.1",
4445
"nock": "^13.3.1",
4546
"react": "^18.2.0",
4647
"react-dom": "^18.2.0",
4748
"tiny-graphql-query-compiler": "workspace:*",
49+
"ts-node": "^10.9.1",
4850
"type-fest": "^3.3.0",
4951
"typescript": "5.0.4"
5052
}

packages/api-client-core/src/GadgetConnection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export enum AuthenticationMode {
6666
* Manages transactions and the connection to a Gadget API
6767
*/
6868
export class GadgetConnection {
69+
version = "<prerelease>" as const;
70+
6971
// Options used when generating new GraphQL clients for the base connection and for for transactions
7072
private endpoint: string;
7173
private subscriptionClientOptions?: SubscriptionClientOptions;

packages/api-client-core/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"module": "ES2022",
55
"noEmit": true
66
},
7-
"include": ["./src", "./spec"]
7+
"include": ["./src", "./spec", "./build"]
88
}

pnpm-lock.yaml

Lines changed: 22 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)