Skip to content

Commit 5304752

Browse files
authored
Merge branch 'main' into feature/update_downloads
2 parents 955efdc + 7cd79cd commit 5304752

File tree

85 files changed

+450
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+450
-564
lines changed

.github/workflows/inference-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')")
5353
# Update package.json with the new version
5454
node -e "const fs = require('fs'); const package = JSON.parse(fs.readFileSync('./package.json')); package.version = '$BUMPED_VERSION'; fs.writeFileSync('./package.json', JSON.stringify(package, null, '\t') + '\n');"
55+
pnpm --filter inference package-to-ts
5556
pnpm --filter doc-internal run fix-cdn-versions
5657
git add ../..
5758
git commit -m "🔖 @huggingface/inference $BUMPED_VERSION"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ yarn-debug.log*
66
yarn-error.log*
77
lerna-debug.log*
88

9+
.tshy-build
910
# Diagnostic reports (https://nodejs.org/api/report.html)
1011
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
1112

packages/hub/src/lib/cache-management.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type CachedFileInfo,
99
} from "./cache-management";
1010
import { stat, readdir, realpath, lstat } from "node:fs/promises";
11-
import type { Dirent, Stats } from "node:fs";
11+
import type { Stats } from "node:fs";
1212
import { join } from "node:path";
1313

1414
// Mocks
@@ -86,7 +86,9 @@ describe("scanSnapshotDir", () => {
8686
test("should scan a valid snapshot directory", async () => {
8787
const cachedFiles: CachedFileInfo[] = [];
8888
const blobStats = new Map<string, Stats>();
89-
vi.mocked(readdir).mockResolvedValueOnce([{ name: "file1", isDirectory: () => false } as Dirent]);
89+
vi.mocked(readdir).mockResolvedValueOnce([
90+
{ name: "file1", isDirectory: () => false } as unknown as Awaited<ReturnType<typeof readdir>>[0],
91+
]);
9092

9193
vi.mocked(realpath).mockResolvedValueOnce("/fake/realpath");
9294
vi.mocked(lstat).mockResolvedValueOnce({ size: 1024, atimeMs: Date.now(), mtimeMs: Date.now() } as Stats);

packages/inference/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
tapes.json
3-
src/vendor
3+
src/vendor
4+
.tshy-build

packages/inference/.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ pnpm-lock.yaml
33
README.md
44
dist
55
test/tapes.json
6-
src/vendor
6+
src/vendor
7+
.tshy-build
8+
.tshy

packages/inference/.tshy/build.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "../src",
5+
"module": "nodenext",
6+
"moduleResolution": "nodenext"
7+
}
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "./build.json",
3+
"include": [
4+
"../src/**/*.ts",
5+
"../src/**/*.cts",
6+
"../src/**/*.tsx",
7+
"../src/**/*.json"
8+
],
9+
"exclude": [
10+
"../src/**/*.mts",
11+
"../src/package.json"
12+
],
13+
"compilerOptions": {
14+
"outDir": "../.tshy-build/commonjs"
15+
}
16+
}

packages/inference/.tshy/esm.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./build.json",
3+
"include": [
4+
"../src/**/*.ts",
5+
"../src/**/*.mts",
6+
"../src/**/*.tsx",
7+
"../src/**/*.json"
8+
],
9+
"exclude": [
10+
"../src/package.json"
11+
],
12+
"compilerOptions": {
13+
"outDir": "../.tshy-build/esm"
14+
}
15+
}

packages/inference/package.json

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@huggingface/inference",
3-
"version": "3.13.2",
3+
"version": "3.14.0",
44
"packageManager": "[email protected]",
55
"license": "MIT",
66
"author": "Hugging Face and Tim Mikeladze <[email protected]>",
@@ -30,18 +30,18 @@
3030
"!src/snippets/templates/**/*.jinja"
3131
],
3232
"source": "src/index.ts",
33-
"types": "./dist/src/index.d.ts",
34-
"main": "./dist/index.cjs",
35-
"module": "./dist/index.js",
36-
"exports": {
37-
"types": "./dist/src/index.d.ts",
38-
"require": "./dist/index.cjs",
39-
"import": "./dist/index.js"
33+
"types": "./dist/commonjs/index.d.ts",
34+
"main": "./dist/commonjs/index.js",
35+
"module": "./dist/esm/index.js",
36+
"tshy": {
37+
"exports": {
38+
"./package.json": "./package.json",
39+
".": "./src/index.ts"
40+
}
4041
},
4142
"type": "module",
4243
"scripts": {
43-
"build": "pnpm run export-templates && tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
44-
"dts": "tsx scripts/generate-dts.ts && tsc --noEmit dist/index.d.ts",
44+
"build": "pnpm run export-templates && pnpm run package-to-ts && tshy",
4545
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
4646
"lint:check": "eslint --ext .cjs,.ts .",
4747
"format": "prettier --write .",
@@ -52,7 +52,8 @@
5252
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest.config.mts",
5353
"check": "tsc",
5454
"dev": "pnpm run export-templates && tsup src/index.ts --format cjs,esm --watch",
55-
"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"
5657
},
5758
"dependencies": {
5859
"@huggingface/tasks": "workspace:^",
@@ -61,5 +62,18 @@
6162
"devDependencies": {
6263
"@types/node": "18.13.0"
6364
},
64-
"resolutions": {}
65+
"resolutions": {},
66+
"exports": {
67+
"./package.json": "./package.json",
68+
".": {
69+
"import": {
70+
"types": "./dist/esm/index.d.ts",
71+
"default": "./dist/esm/index.js"
72+
},
73+
"require": {
74+
"types": "./dist/commonjs/index.d.ts",
75+
"default": "./dist/commonjs/index.js"
76+
}
77+
}
78+
}
6579
}

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/InferenceClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as tasks from "./tasks";
2-
import type { Options } from "./types";
3-
import { omit } from "./utils/omit";
4-
import { typedEntries } from "./utils/typedEntries";
1+
import * as tasks from "./tasks/index.js";
2+
import type { Options } from "./types.js";
3+
import { omit } from "./utils/omit.js";
4+
import { typedEntries } from "./utils/typedEntries.js";
55

66
/* eslint-disable @typescript-eslint/no-empty-interface */
77
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */

packages/inference/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient";
2-
export { InferenceOutputError } from "./lib/InferenceOutputError";
3-
export * from "./types";
4-
export * from "./tasks";
1+
export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient.js";
2+
export { InferenceOutputError } from "./lib/InferenceOutputError.js";
3+
export * from "./types.js";
4+
export * from "./tasks/index.js";
55
import * as snippets from "./snippets/index.js";
66

77
export { snippets };

0 commit comments

Comments
 (0)