Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Make "go to source definition" work #658

Merged
merged 15 commits into from
May 7, 2024
38 changes: 38 additions & 0 deletions .github/workflows/hub-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,44 @@ jobs:
git add ../..
git commit -m "🔖 @hugginface/hub $BUMPED_VERSION"
git tag "hub-v$BUMPED_VERSION"

- name: Make sure that the latest version of @huggingface/tasks is consistent with the local version
run: |
LOCAL_TASKS_VERSION=$(node -p "require('./package.json').version")
REMOTE_TASKS_VERSION=$(npm view @huggingface/tasks version)

# If the versions are different, error
if [ "$LOCAL_TASKS_VERSION" != "$REMOTE_TASKS_VERSION" ]; then
echo "Error: The local @huggingface/tasks package version ($LOCAL_TASKS_VERSION) differs from the remote version ($REMOTE_TASKS_VERSION). Release halted."
exit 1
fi

npm pack @huggingface/tasks
mv huggingface-tasks-$LOCAL_TASKS_VERSION.tgz tasks-local.tgz

npm pack @huggingface/tasks@$REMOTE_TASKS_VERSION
mv huggingface-tasks-$REMOTE_TASKS_VERSION.tgz tasks-remote.tgz

# Compute checksum of local tar. We need to extract both tar since the remote compression might be different
tar -xf tasks-local.tgz
LOCAL_CHECKSUM=$(cd package && tar --mtime='1970-01-01' --mode=755 -cf - . | sha256sum | cut -d' ' -f1)
echo "Local package checksum: $LOCAL_CHECKSUM"

rm -Rf package

tar -xf tasks-remote.tgz
REMOTE_CHECKSUM=$(cd package && tar --mtime='1970-01-01' --mode=755 -cf - . | sha256sum | cut -d' ' -f1)
echo "Remote package checksum: $REMOTE_CHECKSUM"

rm -Rf package

if [ "$LOCAL_CHECKSUM" != "$REMOTE_CHECKSUM" ]; then
echo "Checksum Verification Failed: The local @huggingface/tasks package differs from the remote version. Release halted. Local Checksum: $LOCAL_CHECKSUM, Remote Checksum: $REMOTE_CHECKSUM"
exit 1
fi
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."
working-directory: packages/tasks

- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
5 changes: 2 additions & 3 deletions packages/agents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublishOnly": "pnpm run build",
"build": "tsup",
"build": "tsup && tsc --emitDeclarationOnly --declaration",
"test": "vitest run",
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest-browser.config.mts",
"check": "tsc"
Expand All @@ -53,8 +53,7 @@
"author": "Hugging Face",
"license": "MIT",
"devDependencies": {
"@types/node": "^18.13.0",
"type-fest": "^3.9.0"
"@types/node": "^18.13.0"
},
"dependencies": {
"@huggingface/inference": "^2.6.1"
Expand Down
8 changes: 0 additions & 8 deletions packages/agents/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/agents/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"skipLibCheck": true,
"noImplicitOverride": true,
"outDir": "./dist",
"declaration": true
"declaration": true,
"declarationMap": true
},
"include": ["src", "test", "index.ts", "../shared/src"],
"include": ["src", "test", "index.ts"],
"exclude": ["dist"]
}
3 changes: 0 additions & 3 deletions packages/agents/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const baseConfig: Options = {
format: ["cjs", "esm"],
outDir: "dist",
clean: true,
dts: {
resolve: true,
},
};

const nodeConfig: Options = {
Expand Down
1 change: 1 addition & 0 deletions packages/gguf/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
7 changes: 2 additions & 5 deletions packages/gguf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublishOnly": "pnpm run build",
"build": "tsup src/index.ts --format cjs,esm --clean --dts",
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
"build:llm": "tsx scripts/generate-llm.ts && pnpm run format",
"test": "vitest run",
"check": "tsc"
Expand All @@ -47,8 +47,5 @@
"gguf"
],
"author": "Hugging Face",
"license": "MIT",
"devDependencies": {
"type-fest": "^3.9.0"
}
"license": "MIT"
}
12 changes: 0 additions & 12 deletions packages/gguf/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/gguf/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"strictNullChecks": true,
"skipLibCheck": true,
"noImplicitOverride": true,
"outDir": "./dist"
"outDir": "./dist",
"declaration": true,
"declarationMap": true
},
"include": ["src"],
"exclude": ["dist"]
Expand Down
3 changes: 0 additions & 3 deletions packages/gguf/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const baseConfig: Options = {
format: ["cjs", "esm"],
outDir: "dist",
clean: true,
dts: {
resolve: true,
},
};

const nodeConfig: Options = {
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ Under the hood, `@huggingface/hub` uses a lazy blob implementation to load the f
## Dependencies

- `hash-wasm` : Only used in the browser, when committing files over 10 MB. Browsers do not natively support streaming sha256 computations.
- `type-fest` : Typings only
- `@huggingface/tasks` : Typings only
7 changes: 3 additions & 4 deletions packages/hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublishOnly": "pnpm run build",
"build": "tsup",
"build": "tsup && tsc --emitDeclarationOnly --declaration",
"prepare": "pnpm run build",
"test": "vitest run",
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest-browser.config.mts",
Expand All @@ -56,11 +56,10 @@
"author": "Hugging Face",
"license": "MIT",
"devDependencies": {
"@huggingface/tasks": "workspace:^",
"@types/node": "^20.11.28",
"type-fest": "^3.9.0"
"@types/node": "^20.11.28"
},
"dependencies": {
"@huggingface/tasks": "workspace:^",
"hash-wasm": "^4.9.0"
}
}
14 changes: 3 additions & 11 deletions packages/hub/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/hub/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonObject } from "type-fest";
import type { JsonObject } from "./vendor/type-fest/basic";

export async function createApiError(
response: Response,
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/commit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deleteRepo } from "./delete-repo";
import { downloadFile } from "./download-file";
import { fileDownloadInfo } from "./file-download-info";
import { insecureRandomString } from "../utils/insecureRandomString";
import { isFrontend } from "../../../shared";
import { isFrontend } from "../utils/isFrontend";

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

Expand Down
3 changes: 2 additions & 1 deletion packages/hub/src/lib/commit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isFrontend, base64FromBytes } from "../../../shared";
import { HUB_URL } from "../consts";
import { HubApiError, createApiError, InvalidApiResponseFormatError } from "../error";
import type {
Expand All @@ -21,6 +20,8 @@ import { toRepoId } from "../utils/toRepoId";
import { WebBlob } from "../utils/WebBlob";
import { createBlob } from "../utils/createBlob";
import { eventToGenerator } from "../utils/eventToGenerator";
import { base64FromBytes } from "../utils/base64FromBytes";
import { isFrontend } from "../utils/isFrontend";

const CONCURRENT_SHAS = 5;
const CONCURRENT_LFS_UPLOADS = 5;
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/create-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HUB_URL } from "../consts";
import { createApiError } from "../error";
import type { ApiCreateRepoPayload } from "../types/api/api-create-repo";
import type { Credentials, RepoDesignation, SpaceSdk } from "../types/public";
import { base64FromBytes } from "../../../shared";
import { base64FromBytes } from "../utils/base64FromBytes";
import { checkCredentials } from "../utils/checkCredentials";
import { toRepoId } from "../utils/toRepoId";

Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/oauth-login-url.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { base64FromBytes } from "../../../shared/src";
import { HUB_URL } from "../consts";
import { createApiError } from "../error";
import { base64FromBytes } from "../utils/base64FromBytes";

/**
* Use "Sign in with Hub" to authenticate a user, and get oauth user info / access token.
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/parse-safetensors-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { SetRequired } from "type-fest";
import type { Credentials, RepoDesignation } from "../types/public";
import { checkCredentials } from "../utils/checkCredentials";
import { omit } from "../utils/omit";
Expand All @@ -7,6 +6,7 @@ import { typedEntries } from "../utils/typedEntries";
import { downloadFile } from "./download-file";
import { fileExists } from "./file-exists";
import { promisesQueue } from "../utils/promisesQueue";
import type { SetRequired } from "../vendor/type-fest/set-required";

export const SAFETENSORS_FILE = "model.safetensors";
export const SAFETENSORS_INDEX_FILE = "model.safetensors.index.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface ApiCommitDeletedEntry {
path: string;
}

interface ApiCommitLfsFile {
export interface ApiCommitLfsFile {
path: string;
oldPath?: string;
/** Required if {@link oldPath} is not set */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SetRequired } from "type-fest";
import type { SpaceHardwareFlavor, SpaceSdk } from "../public";
import type { SetRequired } from "../../vendor/type-fest/set-required";
import type { RepoType, SpaceHardwareFlavor, SpaceSdk } from "../public";
import type { ApiCommitFile } from "./api-commit";

export type ApiCreateRepoPayload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ApiFileScanResult {
pickleImportScan?: ApiPickleImportScan;
}

interface AVScan {
interface ApiAVScan {
virusFound: boolean;
virusNames?: string[];
}
Expand All @@ -41,6 +41,6 @@ interface ApiPickleImport {
}

interface ApiPickleImportScan {
highestSafetyLevel: ApiSafetyLevelafetyLevel;
highestSafetyLevel: ApiSafetyLevel;
imports: ApiPickleImport[];
}
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/hub/src/utils/WebBlob.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it, beforeAll } from "vitest";
import { base64FromBytes } from "../../../shared";
import { WebBlob } from "./WebBlob";
import { base64FromBytes } from "./base64FromBytes";

describe("WebBlob", () => {
const resourceUrl = new URL("https://huggingface.co/spaces/aschen/push-model-from-web/raw/main/mobilenet/model.json");
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/utils/createBlob.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isFrontend } from "../../../shared";
import { WebBlob } from "./WebBlob";
import { isFrontend } from "./isFrontend";

/**
* This function allow to retrieve either a FileBlob or a WebBlob from a URL.
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/utils/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isFrontend } from "../../../shared";
import { eventToGenerator } from "./eventToGenerator";
import { hexFromBytes } from "./hexFromBytes";
import { isFrontend } from "./isFrontend";

const webWorkerCode = `
// Would prefer no CDN, but need a clever way to not burden the main file of the bundle
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/utils/typedEntries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Entries } from "type-fest";
import type { Entries } from "../vendor/type-fest/entries";

export function typedEntries<T extends { [s: string]: T[keyof T] } | ArrayLike<T[keyof T]>>(obj: T): Entries<T> {
return Object.entries(obj) as Entries<T>;
Expand Down
31 changes: 31 additions & 0 deletions packages/hub/src/vendor/type-fest/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
Matches a JSON object.

This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.

@category JSON
*/
export type JsonObject = { [Key in string]: JsonValue } & { [Key in string]?: JsonValue | undefined };

/**
Matches a JSON array.

@category JSON
*/
export type JsonArray = JsonValue[] | readonly JsonValue[];

/**
Matches any valid JSON primitive value.

@category JSON
*/
export type JsonPrimitive = string | number | boolean | null;

/**
Matches any valid JSON value.

@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.

@category JSON
*/
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
Loading
Loading