Skip to content

Commit 06fb210

Browse files
authored
✨ Switch to nodenext resolution (#1026)
Seems necessary for #1025 - also handle #1001 (only for tasks at the moment) cc @martin-gorner also so that https://arethetypeswrong.github.io/?p=@huggingface/tasks is :heavy_check_mark: cc @Pierrci - in addition to the .cts exports And finally export snippets types (https://github.com/huggingface-internal/moon-landing/pull/10998/files#r1841375306) Types pass: https://arethetypeswrong.github.io/?p=%40huggingface%2Ftasks%400.13.0-test5 !
1 parent a626ee5 commit 06fb210

File tree

61 files changed

+196
-168
lines changed

Some content is hidden

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

61 files changed

+196
-168
lines changed

packages/gguf/src/gguf.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("gguf", () => {
3333
const arrayBuf = await res.arrayBuffer();
3434
fs.writeFileSync(".cache/model.gguf", Buffer.from(arrayBuf));
3535
}
36-
});
36+
}, 30_000);
3737

3838
it("should parse a llama2 7b", async () => {
3939
const { metadata, tensorInfos } = await gguf(URL_LLAMA);

packages/tasks/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
},
1010
"main": "./dist/index.cjs",
1111
"module": "./dist/index.js",
12-
"types": "./dist/src/index.d.ts",
12+
"types": "./dist/index.d.ts",
1313
"exports": {
1414
".": {
15-
"types": "./dist/src/index.d.ts",
1615
"require": "./dist/index.cjs",
1716
"import": "./dist/index.js"
1817
}
@@ -24,13 +23,14 @@
2423
"format": "prettier --write .",
2524
"format:check": "prettier --check .",
2625
"prepublishOnly": "pnpm run inference-codegen && git diff --name-only --exit-code src && pnpm run build",
27-
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
26+
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration && pnpm run generate-cts",
2827
"watch:export": "tsup src/index.ts --format cjs,esm --watch",
2928
"watch:types": "tsc --emitDeclarationOnly --declaration --watch",
3029
"watch": "npm-run-all --parallel watch:export watch:types",
3130
"prepare": "pnpm run build",
3231
"check": "tsc",
3332
"test": "vitest run",
33+
"generate-cts": "tsx scripts/generate-cts.ts",
3434
"inference-codegen": "tsx scripts/inference-codegen.ts && prettier --write src/tasks/*/inference.ts",
3535
"inference-tgi-import": "tsx scripts/inference-tgi-import.ts && prettier --write src/tasks/text-generation/spec/*.json && prettier --write src/tasks/chat-completion/spec/*.json",
3636
"inference-tei-import": "tsx scripts/inference-tei-import.ts && prettier --write src/tasks/feature-extraction/spec/*.json"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Just copy over the already generated .d.ts and .d.ts.map files to .d.cts and .d.cts.map files
2+
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3+
import { join } from "node:path";
4+
5+
function recursiveCopy(path: string) {
6+
for (const item of readdirSync(path)) {
7+
if (item.endsWith(".d.ts")) {
8+
const content = readFileSync(join(path, item), "utf-8");
9+
writeFileSync(join(path, item.replace(".d.ts", ".d.cts")), content.replaceAll(".d.ts.map", ".d.cts.map"));
10+
} else if (item.endsWith(".d.ts.map")) {
11+
const content = readFileSync(join(path, item), "utf-8");
12+
writeFileSync(join(path, item.replace(".d.ts.map", ".d.cts.map")), content.replaceAll(".d.ts", ".d.cts"));
13+
} else if (statSync(join(path, item)).isDirectory()) {
14+
recursiveCopy(join(path, item));
15+
}
16+
}
17+
}
18+
19+
recursiveCopy("dist");

packages/tasks/src/default-widget-inputs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { WidgetExample } from "./widget-example";
2-
import type { WidgetType } from "./pipelines";
1+
import type { WidgetExample } from "./widget-example.js";
2+
import type { WidgetType } from "./pipelines.js";
33

44
type LanguageCode = string;
55

packages/tasks/src/index.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export { LIBRARY_TASK_MAPPING } from "./library-to-tasks";
2-
export { MAPPING_DEFAULT_WIDGET } from "./default-widget-inputs";
3-
export type { TaskData, TaskDemo, TaskDemoEntry, ExampleRepo } from "./tasks";
4-
export * from "./tasks";
1+
export { LIBRARY_TASK_MAPPING } from "./library-to-tasks.js";
2+
export { MAPPING_DEFAULT_WIDGET } from "./default-widget-inputs.js";
3+
export type { TaskData, TaskDemo, TaskDemoEntry, ExampleRepo } from "./tasks/index.js";
4+
export * from "./tasks/index.js";
55
export {
66
PIPELINE_DATA,
77
PIPELINE_TYPES,
@@ -13,11 +13,15 @@ export {
1313
MODALITY_LABELS,
1414
SUBTASK_TYPES,
1515
PIPELINE_TYPES_SET,
16-
} from "./pipelines";
17-
export { ALL_DISPLAY_MODEL_LIBRARY_KEYS, ALL_MODEL_LIBRARY_KEYS, MODEL_LIBRARIES_UI_ELEMENTS } from "./model-libraries";
18-
export type { LibraryUiElement, ModelLibraryKey } from "./model-libraries";
19-
export type { ModelData, TransformersInfo } from "./model-data";
20-
export type { AddedToken, SpecialTokensMap, TokenizerConfig } from "./tokenizer-data";
16+
} from "./pipelines.js";
17+
export {
18+
ALL_DISPLAY_MODEL_LIBRARY_KEYS,
19+
ALL_MODEL_LIBRARY_KEYS,
20+
MODEL_LIBRARIES_UI_ELEMENTS,
21+
} from "./model-libraries.js";
22+
export type { LibraryUiElement, ModelLibraryKey } from "./model-libraries.js";
23+
export type { ModelData, TransformersInfo } from "./model-data.js";
24+
export type { AddedToken, SpecialTokensMap, TokenizerConfig } from "./tokenizer-data.js";
2125
export type {
2226
WidgetExample,
2327
WidgetExampleAttribute,
@@ -38,18 +42,18 @@ export type {
3842
WidgetExampleOutputLabels,
3943
WidgetExampleOutputAnswerScore,
4044
WidgetExampleOutputText,
41-
} from "./widget-example";
42-
export { SPECIAL_TOKENS_ATTRIBUTES } from "./tokenizer-data";
45+
} from "./widget-example.js";
46+
export { SPECIAL_TOKENS_ATTRIBUTES } from "./tokenizer-data.js";
4347

44-
import * as snippets from "./snippets";
45-
export * from "./gguf";
48+
import * as snippets from "./snippets/index.js";
49+
export * from "./gguf.js";
4650

4751
export { snippets };
4852

49-
export { SKUS, DEFAULT_MEMORY_OPTIONS } from "./hardware";
50-
export type { HardwareSpec, SkuType } from "./hardware";
51-
export { LOCAL_APPS } from "./local-apps";
52-
export type { LocalApp, LocalAppKey, LocalAppSnippet } from "./local-apps";
53+
export { SKUS, DEFAULT_MEMORY_OPTIONS } from "./hardware.js";
54+
export type { HardwareSpec, SkuType } from "./hardware.js";
55+
export { LOCAL_APPS } from "./local-apps.js";
56+
export type { LocalApp, LocalAppKey, LocalAppSnippet } from "./local-apps.js";
5357

54-
export { DATASET_LIBRARIES_UI_ELEMENTS } from "./dataset-libraries";
55-
export type { DatasetLibraryUiElement, DatasetLibraryKey } from "./dataset-libraries";
58+
export { DATASET_LIBRARIES_UI_ELEMENTS } from "./dataset-libraries.js";
59+
export type { DatasetLibraryUiElement, DatasetLibraryKey } from "./dataset-libraries.js";

packages/tasks/src/library-to-tasks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { ModelLibraryKey } from "./model-libraries";
2-
import type { PipelineType } from "./pipelines";
1+
import type { ModelLibraryKey } from "./model-libraries.js";
2+
import type { PipelineType } from "./pipelines.js";
33

44
/**
55
* Mapping from library name to its supported tasks.

packages/tasks/src/local-apps.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { parseGGUFQuantLabel } from "./gguf";
2-
import type { ModelData } from "./model-data";
3-
import type { PipelineType } from "./pipelines";
1+
import { parseGGUFQuantLabel } from "./gguf.js";
2+
import type { ModelData } from "./model-data.js";
3+
import type { PipelineType } from "./pipelines.js";
44

55
export interface LocalAppSnippet {
66
/**

packages/tasks/src/model-data.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { PipelineType } from "./pipelines";
2-
import type { WidgetExample } from "./widget-example";
3-
import type { TokenizerConfig } from "./tokenizer-data";
1+
import type { PipelineType } from "./pipelines.js";
2+
import type { WidgetExample } from "./widget-example.js";
3+
import type { TokenizerConfig } from "./tokenizer-data.js";
44

55
/**
66
* Public interface for model metadata

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { ModelData } from "./model-data";
2-
import type { WidgetExampleTextInput, WidgetExampleSentenceSimilarityInput } from "./widget-example";
3-
import { LIBRARY_TASK_MAPPING } from "./library-to-tasks";
1+
import type { ModelData } from "./model-data.js";
2+
import type { WidgetExampleTextInput, WidgetExampleSentenceSimilarityInput } from "./widget-example.js";
3+
import { LIBRARY_TASK_MAPPING } from "./library-to-tasks.js";
44

55
const TAG_CUSTOM_CODE = "custom_code";
66

packages/tasks/src/model-libraries.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as snippets from "./model-libraries-snippets";
2-
import type { ModelData } from "./model-data";
3-
import type { ElasticSearchQuery } from "./model-libraries-downloads";
1+
import * as snippets from "./model-libraries-snippets.js";
2+
import type { ModelData } from "./model-data.js";
3+
import type { ElasticSearchQuery } from "./model-libraries-downloads.js";
44

55
/**
66
* Elements configurable by a model library.

packages/tasks/src/snippets/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks";
1+
import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js";
22

33
export function stringifyMessages(
44
messages: ChatCompletionInputMessage[],

packages/tasks/src/snippets/curl.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { ModelDataMinimal } from "./types";
1+
import type { ModelDataMinimal } from "./types.js";
22
import { describe, expect, it } from "vitest";
3-
import { getCurlInferenceSnippet } from "./curl";
3+
import { getCurlInferenceSnippet } from "./curl.js";
44

55
describe("inference API snippets", () => {
66
it("conversational llm", async () => {

packages/tasks/src/snippets/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import * as inputs from "./inputs";
2-
import * as curl from "./curl";
3-
import * as python from "./python";
4-
import * as js from "./js";
1+
import * as inputs from "./inputs.js";
2+
import * as curl from "./curl.js";
3+
import * as python from "./python.js";
4+
import * as js from "./js.js";
5+
export * from "./types.js";
56

67
export { inputs, curl, python, js };

packages/tasks/src/snippets/inputs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { PipelineType } from "../pipelines";
2-
import type { ChatCompletionInputMessage } from "../tasks";
3-
import type { ModelDataMinimal } from "./types";
1+
import type { PipelineType } from "../pipelines.js";
2+
import type { ChatCompletionInputMessage } from "../tasks/index.js";
3+
import type { ModelDataMinimal } from "./types.js";
44

55
const inputsZeroShotClassification = () =>
66
`"Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!"`;

packages/tasks/src/snippets/js.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { InferenceSnippet, ModelDataMinimal } from "./types";
1+
import type { InferenceSnippet, ModelDataMinimal } from "./types.js";
22
import { describe, expect, it } from "vitest";
3-
import { getJsInferenceSnippet } from "./js";
3+
import { getJsInferenceSnippet } from "./js.js";
44

55
describe("inference API snippets", () => {
66
it("conversational llm", async () => {

packages/tasks/src/snippets/python.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { InferenceSnippet, ModelDataMinimal } from "./types";
1+
import type { InferenceSnippet, ModelDataMinimal } from "./types.js";
22
import { describe, expect, it } from "vitest";
3-
import { getPythonInferenceSnippet } from "./python";
3+
import { getPythonInferenceSnippet } from "./python.js";
44

55
describe("inference API snippets", () => {
66
it("conversational llm", async () => {

packages/tasks/src/snippets/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ModelData } from "../model-data";
1+
import type { ModelData } from "../model-data.js";
22

33
/**
44
* Minimal model data required for snippets.

packages/tasks/src/tasks/audio-classification/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/audio-to-audio/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/automatic-speech-recognition/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/depth-estimation/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/document-question-answering/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/feature-extraction/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/fill-mask/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/image-classification/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/image-feature-extraction/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/image-segmentation/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/image-text-to-text/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/image-to-3d/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/image-to-image/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

packages/tasks/src/tasks/image-to-text/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaskDataCustom } from "..";
1+
import type { TaskDataCustom } from "../index.js";
22

33
const taskData: TaskDataCustom = {
44
datasets: [

0 commit comments

Comments
 (0)