From a282b6e8243b85c62b88a9f323df6945095df07d Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 14 Nov 2024 02:33:06 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Fix=20types=20in=20published=20?= =?UTF-8?q?tasks=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/tasks/package.json | 6 +++--- packages/tasks/scripts/generate-cts.ts | 18 ++++++++++++++++++ packages/tasks/tsconfig.json | 2 +- packages/tasks/tsconfig.local.json | 4 ++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 packages/tasks/scripts/generate-cts.ts create mode 100644 packages/tasks/tsconfig.local.json diff --git a/packages/tasks/package.json b/packages/tasks/package.json index ad7193d933..7b46ece734 100644 --- a/packages/tasks/package.json +++ b/packages/tasks/package.json @@ -9,10 +9,9 @@ }, "main": "./dist/index.cjs", "module": "./dist/index.js", - "types": "./dist/src/index.d.ts", + "types": "./dist/index.d.ts", "exports": { ".": { - "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs", "import": "./dist/index.js" } @@ -24,13 +23,14 @@ "format": "prettier --write .", "format:check": "prettier --check .", "prepublishOnly": "pnpm run inference-codegen && git diff --name-only --exit-code src && pnpm run build", - "build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", + "build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration && pnpm run generate-cts", "watch:export": "tsup src/index.ts --format cjs,esm --watch", "watch:types": "tsc --emitDeclarationOnly --declaration --watch", "watch": "npm-run-all --parallel watch:export watch:types", "prepare": "pnpm run build", "check": "tsc", "test": "vitest run", + "generate-cts": "tsx scripts/generate-cts.ts", "inference-codegen": "tsx scripts/inference-codegen.ts && prettier --write src/tasks/*/inference.ts", "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", "inference-tei-import": "tsx scripts/inference-tei-import.ts && prettier --write src/tasks/feature-extraction/spec/*.json" diff --git a/packages/tasks/scripts/generate-cts.ts b/packages/tasks/scripts/generate-cts.ts new file mode 100644 index 0000000000..fc53438ce3 --- /dev/null +++ b/packages/tasks/scripts/generate-cts.ts @@ -0,0 +1,18 @@ +import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; + +function recursiveCopy(path: string) { + for (const item of readdirSync(path)) { + if (item.endsWith(".d.ts")) { + const content = readFileSync(join(path, item), "utf-8"); + writeFileSync(join(path, item.replace(".d.ts", ".d.cts")), content.replaceAll(".d.ts.map", ".d.cts.map")); + } else if (item.endsWith(".d.ts.map")) { + const content = readFileSync(join(path, item), "utf-8"); + writeFileSync(join(path, item.replace(".d.ts.map", ".d.cts.map")), content.replaceAll(".d.ts", ".d.cts")); + } else if (statSync(join(path, item)).isDirectory()) { + recursiveCopy(join(path, item)); + } + } +} + +recursiveCopy("dist"); diff --git a/packages/tasks/tsconfig.json b/packages/tasks/tsconfig.json index 6a2bad7587..157abae981 100644 --- a/packages/tasks/tsconfig.json +++ b/packages/tasks/tsconfig.json @@ -15,6 +15,6 @@ "declaration": true, "declarationMap": true }, - "include": ["src", "scripts"], + "include": ["src"], "exclude": ["dist"] } diff --git a/packages/tasks/tsconfig.local.json b/packages/tasks/tsconfig.local.json new file mode 100644 index 0000000000..aefb178279 --- /dev/null +++ b/packages/tasks/tsconfig.local.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src", "scripts"] +} From 451a223f52740986702ab48814ceb7f6220e3116 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 14 Nov 2024 02:36:17 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Also=20export=20snippet=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/tasks/src/snippets/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/tasks/src/snippets/index.ts b/packages/tasks/src/snippets/index.ts index 3cf9b9d236..ea1d0b9a52 100644 --- a/packages/tasks/src/snippets/index.ts +++ b/packages/tasks/src/snippets/index.ts @@ -2,5 +2,6 @@ import * as inputs from "./inputs"; import * as curl from "./curl"; import * as python from "./python"; import * as js from "./js"; +export * from "./types"; export { inputs, curl, python, js };