Skip to content

Commit 4d4e207

Browse files
authored
1 parent bc251da commit 4d4e207

Some content is hidden

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

79 files changed

+417
-542
lines changed

.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/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
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: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

0 commit comments

Comments
 (0)