Skip to content

Commit 99bbf1f

Browse files
authored
♻️ Make "go to source definition" work (#658)
Sorry for all the codeowners reviews Make "go to source definition" work by using the package, thanks to `.d.ts.map` files generated by `tsc`. Defer type generation to `tsc` instead of `tsup`, since `tsup` is not able to generate `.d.ts.map`. Also removed `shared` package - since we don't want to publish it, having "go to source" with it would have been problematic. Instead, "shared" files are duplicated between `@huggingface/inference` and `@huggingface/hub`. Maybe later we can create `@huggingface/webblob` and `@huggingface/fileblob` if we want to reuse them. See also: https://www.npmjs.com/package/dts-buddy used by svelte-kit
1 parent a7caba5 commit 99bbf1f

Some content is hidden

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

71 files changed

+537
-131
lines changed

.github/workflows/hub-publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,44 @@ jobs:
5252
git add ../..
5353
git commit -m "🔖 @hugginface/hub $BUMPED_VERSION"
5454
git tag "hub-v$BUMPED_VERSION"
55+
56+
- name: Make sure that the latest version of @huggingface/tasks is consistent with the local version
57+
run: |
58+
LOCAL_TASKS_VERSION=$(node -p "require('./package.json').version")
59+
REMOTE_TASKS_VERSION=$(npm view @huggingface/tasks version)
60+
61+
# If the versions are different, error
62+
if [ "$LOCAL_TASKS_VERSION" != "$REMOTE_TASKS_VERSION" ]; then
63+
echo "Error: The local @huggingface/tasks package version ($LOCAL_TASKS_VERSION) differs from the remote version ($REMOTE_TASKS_VERSION). Release halted."
64+
exit 1
65+
fi
66+
67+
npm pack @huggingface/tasks
68+
mv huggingface-tasks-$LOCAL_TASKS_VERSION.tgz tasks-local.tgz
69+
70+
npm pack @huggingface/tasks@$REMOTE_TASKS_VERSION
71+
mv huggingface-tasks-$REMOTE_TASKS_VERSION.tgz tasks-remote.tgz
72+
73+
# Compute checksum of local tar. We need to extract both tar since the remote compression might be different
74+
tar -xf tasks-local.tgz
75+
LOCAL_CHECKSUM=$(cd package && tar --mtime='1970-01-01' --mode=755 -cf - . | sha256sum | cut -d' ' -f1)
76+
echo "Local package checksum: $LOCAL_CHECKSUM"
77+
78+
rm -Rf package
79+
80+
tar -xf tasks-remote.tgz
81+
REMOTE_CHECKSUM=$(cd package && tar --mtime='1970-01-01' --mode=755 -cf - . | sha256sum | cut -d' ' -f1)
82+
echo "Remote package checksum: $REMOTE_CHECKSUM"
83+
84+
rm -Rf package
85+
86+
if [ "$LOCAL_CHECKSUM" != "$REMOTE_CHECKSUM" ]; then
87+
echo "Checksum Verification Failed: The local @huggingface/tasks package differs from the remote version. Release halted. Local Checksum: $LOCAL_CHECKSUM, Remote Checksum: $REMOTE_CHECKSUM"
88+
exit 1
89+
fi
90+
echo "Checksum Verification Successful: The local and remote @huggingface/tasks packages are consistent. Proceeding with the @huggingface/widgets package release. Local Checksum: $LOCAL_CHECKSUM, Remote Checksum: $REMOTE_CHECKSUM."
91+
working-directory: packages/tasks
92+
5593
- run: pnpm publish --no-git-checks .
5694
env:
5795
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
jobs:
9-
test:
9+
node:
1010
runs-on: ubuntu-latest
1111
timeout-minutes: 10
1212

@@ -42,11 +42,57 @@ jobs:
4242
env:
4343
HF_TOKEN: ${{ secrets.HF_TOKEN }}
4444

45+
browser:
46+
runs-on: ubuntu-latest
47+
timeout-minutes: 10
48+
49+
steps:
50+
- uses: actions/checkout@v3
51+
with:
52+
# Could use something like rmacklin/fetch-through-merge-base@v0 instead when the repo gets bigger
53+
fetch-depth: 0
54+
- name: "Extracting the merge base into 'SINCE'"
55+
id: since
56+
run: |
57+
if [ -z "${{ github.event.pull_request.head.ref }}" ]
58+
then
59+
echo "SINCE=${{ github.sha }}^1" >> $GITHUB_OUTPUT
60+
else
61+
echo "SINCE=$(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }})" >> $GITHUB_OUTPUT
62+
fi
63+
64+
- run: corepack enable
65+
66+
- uses: actions/setup-node@v3
67+
with:
68+
node-version: "20"
69+
cache: "pnpm"
70+
cache-dependency-path: "**/pnpm-lock.yaml"
71+
- run: |
72+
pnpm install --frozen-lockfile --filter .
73+
pnpm install --frozen-lockfile --filter ...[${{ steps.since.outputs.SINCE }}]...
74+
pnpm --filter ...[${{ steps.since.outputs.SINCE }}]... build
75+
4576
- name: Test in browser
4677
run: VCR_MODE=playback pnpm --filter ...[${{ steps.since.outputs.SINCE }}] test:browser
4778
env:
4879
HF_TOKEN: ${{ secrets.HF_TOKEN }}
4980

81+
e2e:
82+
runs-on: ubuntu-latest
83+
timeout-minutes: 10
84+
85+
steps:
86+
- uses: actions/checkout@v3
87+
88+
- run: corepack enable
89+
90+
- uses: actions/setup-node@v3
91+
with:
92+
node-version: "20"
93+
cache: "pnpm"
94+
cache-dependency-path: "**/pnpm-lock.yaml"
95+
5096
- name: E2E - start mock npm registry
5197
run: |
5298
npm i -g verdaccio verdaccio-memory verdaccio-auth-memory
@@ -58,7 +104,7 @@ jobs:
58104
working-directory: e2e
59105
run: |
60106
sleep 3
61-
pnpm i --filter inference... --filter hub... --frozen-lockfile
107+
pnpm i --filter root --filter inference... --filter hub... --frozen-lockfile
62108
pnpm --filter inference --filter hub --filter tasks publish --force --no-git-checks --registry http://localhost:4874/
63109
64110
- name: E2E test - test yarn install

e2e/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Modified during E2E tests
2+
.npmrc

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"private": true,
3+
"name": "@huggingface/root",
24
"license": "MIT",
35
"packageManager": "[email protected]",
46
"scripts": {

packages/agents/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"format": "prettier --write .",
3232
"format:check": "prettier --check .",
3333
"prepublishOnly": "pnpm run build",
34-
"build": "tsup",
34+
"build": "tsup && tsc --emitDeclarationOnly --declaration",
3535
"test": "vitest run",
3636
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest-browser.config.mts",
3737
"check": "tsc"
@@ -53,8 +53,7 @@
5353
"author": "Hugging Face",
5454
"license": "MIT",
5555
"devDependencies": {
56-
"@types/node": "^18.13.0",
57-
"type-fest": "^3.9.0"
56+
"@types/node": "^18.13.0"
5857
},
5958
"dependencies": {
6059
"@huggingface/inference": "^2.6.1"

packages/agents/pnpm-lock.yaml

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

packages/agents/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
"skipLibCheck": true,
1313
"noImplicitOverride": true,
1414
"outDir": "./dist",
15-
"declaration": true
15+
"declaration": true,
16+
"declarationMap": true
1617
},
17-
"include": ["src", "test", "index.ts", "../shared/src"],
18+
"include": ["src", "test", "index.ts"],
1819
"exclude": ["dist"]
1920
}

packages/agents/tsup.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const baseConfig: Options = {
55
format: ["cjs", "esm"],
66
outDir: "dist",
77
clean: true,
8-
dts: {
9-
resolve: true,
10-
},
118
};
129

1310
const nodeConfig: Options = {

packages/gguf/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

packages/gguf/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"format": "prettier --write .",
3232
"format:check": "prettier --check .",
3333
"prepublishOnly": "pnpm run build",
34-
"build": "tsup src/index.ts --format cjs,esm --clean --dts",
34+
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
3535
"build:llm": "tsx scripts/generate-llm.ts && pnpm run format",
3636
"test": "vitest run",
3737
"check": "tsc"
@@ -47,8 +47,5 @@
4747
"gguf"
4848
],
4949
"author": "Hugging Face",
50-
"license": "MIT",
51-
"devDependencies": {
52-
"type-fest": "^3.9.0"
53-
}
50+
"license": "MIT"
5451
}

packages/gguf/pnpm-lock.yaml

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

packages/gguf/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"strictNullChecks": true,
1212
"skipLibCheck": true,
1313
"noImplicitOverride": true,
14-
"outDir": "./dist"
14+
"outDir": "./dist",
15+
"declaration": true,
16+
"declarationMap": true
1517
},
1618
"include": ["src"],
1719
"exclude": ["dist"]

packages/gguf/tsup.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const baseConfig: Options = {
55
format: ["cjs", "esm"],
66
outDir: "dist",
77
clean: true,
8-
dts: {
9-
resolve: true,
10-
},
118
};
129

1310
const nodeConfig: Options = {

packages/hub/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ Under the hood, `@huggingface/hub` uses a lazy blob implementation to load the f
122122
## Dependencies
123123

124124
- `hash-wasm` : Only used in the browser, when committing files over 10 MB. Browsers do not natively support streaming sha256 computations.
125-
- `type-fest` : Typings only
125+
- `@huggingface/tasks` : Typings only

packages/hub/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"format": "prettier --write .",
3434
"format:check": "prettier --check .",
3535
"prepublishOnly": "pnpm run build",
36-
"build": "tsup",
36+
"build": "tsup && tsc --emitDeclarationOnly --declaration",
3737
"prepare": "pnpm run build",
3838
"test": "vitest run",
3939
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest-browser.config.mts",
@@ -56,11 +56,10 @@
5656
"author": "Hugging Face",
5757
"license": "MIT",
5858
"devDependencies": {
59-
"@huggingface/tasks": "workspace:^",
60-
"@types/node": "^20.11.28",
61-
"type-fest": "^3.9.0"
59+
"@types/node": "^20.11.28"
6260
},
6361
"dependencies": {
62+
"@huggingface/tasks": "workspace:^",
6463
"hash-wasm": "^4.9.0"
6564
}
6665
}

packages/hub/pnpm-lock.yaml

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

packages/hub/src/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { JsonObject } from "type-fest";
1+
import type { JsonObject } from "./vendor/type-fest/basic";
22

33
export async function createApiError(
44
response: Response,

packages/hub/src/lib/commit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { deleteRepo } from "./delete-repo";
99
import { downloadFile } from "./download-file";
1010
import { fileDownloadInfo } from "./file-download-info";
1111
import { insecureRandomString } from "../utils/insecureRandomString";
12-
import { isFrontend } from "../../../shared";
12+
import { isFrontend } from "../utils/isFrontend";
1313

1414
const lfsContent = "O123456789".repeat(100_000);
1515

packages/hub/src/lib/commit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isFrontend, base64FromBytes } from "../../../shared";
21
import { HUB_URL } from "../consts";
32
import { HubApiError, createApiError, InvalidApiResponseFormatError } from "../error";
43
import type {
@@ -21,6 +20,8 @@ import { toRepoId } from "../utils/toRepoId";
2120
import { WebBlob } from "../utils/WebBlob";
2221
import { createBlob } from "../utils/createBlob";
2322
import { eventToGenerator } from "../utils/eventToGenerator";
23+
import { base64FromBytes } from "../utils/base64FromBytes";
24+
import { isFrontend } from "../utils/isFrontend";
2425

2526
const CONCURRENT_SHAS = 5;
2627
const CONCURRENT_LFS_UPLOADS = 5;

packages/hub/src/lib/create-repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HUB_URL } from "../consts";
22
import { createApiError } from "../error";
33
import type { ApiCreateRepoPayload } from "../types/api/api-create-repo";
44
import type { Credentials, RepoDesignation, SpaceSdk } from "../types/public";
5-
import { base64FromBytes } from "../../../shared";
5+
import { base64FromBytes } from "../utils/base64FromBytes";
66
import { checkCredentials } from "../utils/checkCredentials";
77
import { toRepoId } from "../utils/toRepoId";
88

packages/hub/src/lib/oauth-login-url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { base64FromBytes } from "../../../shared/src";
21
import { HUB_URL } from "../consts";
32
import { createApiError } from "../error";
3+
import { base64FromBytes } from "../utils/base64FromBytes";
44

55
/**
66
* Use "Sign in with Hub" to authenticate a user, and get oauth user info / access token.

packages/hub/src/lib/parse-safetensors-metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { SetRequired } from "type-fest";
21
import type { Credentials, RepoDesignation } from "../types/public";
32
import { checkCredentials } from "../utils/checkCredentials";
43
import { omit } from "../utils/omit";
@@ -7,6 +6,7 @@ import { typedEntries } from "../utils/typedEntries";
76
import { downloadFile } from "./download-file";
87
import { fileExists } from "./file-exists";
98
import { promisesQueue } from "../utils/promisesQueue";
9+
import type { SetRequired } from "../vendor/type-fest/set-required";
1010

1111
export const SAFETENSORS_FILE = "model.safetensors";
1212
export const SAFETENSORS_INDEX_FILE = "model.safetensors.index.json";

packages/hub/src/types/api/api-commit.d.ts renamed to packages/hub/src/types/api/api-commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export interface ApiCommitDeletedEntry {
149149
path: string;
150150
}
151151

152-
interface ApiCommitLfsFile {
152+
export interface ApiCommitLfsFile {
153153
path: string;
154154
oldPath?: string;
155155
/** Required if {@link oldPath} is not set */

packages/hub/src/types/api/api-create-repo.d.ts renamed to packages/hub/src/types/api/api-create-repo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { SetRequired } from "type-fest";
2-
import type { SpaceHardwareFlavor, SpaceSdk } from "../public";
1+
import type { SetRequired } from "../../vendor/type-fest/set-required";
2+
import type { RepoType, SpaceHardwareFlavor, SpaceSdk } from "../public";
33
import type { ApiCommitFile } from "./api-commit";
44

55
export type ApiCreateRepoPayload = {

0 commit comments

Comments
 (0)