Skip to content

Commit

Permalink
⚗️ Use TSC only
Browse files Browse the repository at this point in the history
  • Loading branch information
coyotte508 committed Nov 14, 2024
1 parent 06fb210 commit dc0fe5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
11 changes: 6 additions & 5 deletions packages/tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
"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 && 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",
"build": "rm -Rf dist && tsc --declaration --outdir dist/esm && pnpm run switch-package-type commonjs && tsc --declaration --outdir dist/cjs && pnpm run switch-package-type module && pnpm run rename-cts",
"watch:cjs": "tsc --declaration --outdir dist/cjs --module commonjs --watch",
"watch:esm": "tsc --declaration --outdir dist/esm --watch",
"watch": "npm-run-all --parallel watch:esm watch:cjs",
"prepare": "pnpm run build",
"check": "tsc",
"test": "vitest run",
"generate-cts": "tsx scripts/generate-cts.ts",
"switch-package-type": "tsx scripts/switch-package-type.ts",
"rename-cts": "tsx scripts/rename-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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
// Just copy over the already generated .d.ts and .d.ts.map files to .d.cts and .d.cts.map files
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
import { readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
import { join } from "node:path";

function recursiveCopy(path: string) {
function recursiveRename(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"));
rmSync(join(path, item));
} 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));
rmSync(join(path, item));
} /* else if (item.endsWith(".js")) {
const content = readFileSync(join(path, item), "utf-8");
writeFileSync(join(path, item.replace(".js", ".cjs")), content);
} */ else if (statSync(join(path, item)).isDirectory()) {
recursiveRename(join(path, item));
}
}
}

recursiveCopy("dist");
recursiveRename("dist/cjs");
7 changes: 7 additions & 0 deletions packages/tasks/scripts/switch-package-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { readFileSync, writeFileSync } from "fs";

const arg = process.argv[2];

const file = readFileSync("package.json", "utf-8");

writeFileSync("package.json", file.replace(/"type": ".*"/, `"type": "${arg}"`));

0 comments on commit dc0fe5b

Please sign in to comment.