Skip to content

Commit b21193a

Browse files
committed
fix json import error
1 parent 9252652 commit b21193a

File tree

5 files changed

+20
-205
lines changed

5 files changed

+20
-205
lines changed

packages/inference/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
},
4242
"type": "module",
4343
"scripts": {
44-
"build": "pnpm run export-templates && tshy",
45-
"dts": "tsx scripts/generate-dts.ts && tsc --noEmit dist/index.d.ts",
44+
"build": "pnpm run export-templates && pnpm run package-to-ts && tshy",
4645
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
4746
"lint:check": "eslint --ext .cjs,.ts .",
4847
"format": "prettier --write .",
@@ -53,7 +52,8 @@
5352
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest.config.mts",
5453
"check": "tsc",
5554
"dev": "pnpm run export-templates && tsup src/index.ts --format cjs,esm --watch",
56-
"export-templates": "tsx scripts/export-templates.ts"
55+
"export-templates": "tsx scripts/export-templates.ts",
56+
"package-to-ts": "tsx scripts/package-json-to-ts.ts"
5757
},
5858
"dependencies": {
5959
"@huggingface/tasks": "workspace:^",

packages/inference/scripts/generate-dts.ts

Lines changed: 0 additions & 198 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { readFileSync, writeFileSync } from "node:fs";
2+
3+
const pkg = JSON.parse(readFileSync("./package.json", "utf8"));
4+
5+
const content = [
6+
"// Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783",
7+
`export const PACKAGE_VERSION = ${JSON.stringify(pkg.version)};`,
8+
`export const PACKAGE_NAME = ${JSON.stringify(pkg.name)};`,
9+
"",
10+
].join("\n");
11+
12+
writeFileSync("./src/package.ts", content);

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2-
// @ts-ignore this works or not depending on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
3-
import pkg from "../../package.json" with { type: "json" };
41
import { HF_HEADER_X_BILL_TO, HF_HUB_URL } from "../config.js";
2+
import { PACKAGE_NAME, PACKAGE_VERSION } from "../package.js";
53
import type { InferenceTask, Options, RequestArgs } from "../types.js";
64
import type { InferenceProviderModelMapping } from "./getInferenceProviderMapping.js";
75
import { getInferenceProviderMapping } from "./getInferenceProviderMapping.js";
@@ -160,7 +158,7 @@ export function makeRequestOptionsFromResolvedModel(
160158

161159
// Add user-agent to headers
162160
// e.g. @huggingface/inference/3.1.3
163-
const ownUserAgent = `${pkg.name}/${pkg.version}`;
161+
const ownUserAgent = `${PACKAGE_NAME}/${PACKAGE_VERSION}`;
164162
const userAgent = [ownUserAgent, typeof navigator !== "undefined" ? navigator.userAgent : undefined]
165163
.filter((x) => x !== undefined)
166164
.join(" ");

packages/inference/src/package.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
2+
export const PACKAGE_VERSION = "3.13.2";
3+
export const PACKAGE_NAME = "@huggingface/inference";

0 commit comments

Comments
 (0)