Skip to content

Commit dca88cc

Browse files
committed
⚗️ Use TSC only
1 parent 06fb210 commit dca88cc

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

packages/tasks/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
"format": "prettier --write .",
2424
"format:check": "prettier --check .",
2525
"prepublishOnly": "pnpm run inference-codegen && git diff --name-only --exit-code src && pnpm run build",
26-
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration && pnpm run generate-cts",
27-
"watch:export": "tsup src/index.ts --format cjs,esm --watch",
28-
"watch:types": "tsc --emitDeclarationOnly --declaration --watch",
29-
"watch": "npm-run-all --parallel watch:export watch:types",
26+
"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",
27+
"watch:cjs": "tsc --declaration --outdir dist/cjs --module commonjs --watch",
28+
"watch:esm": "tsc --declaration --outdir dist/esm --watch",
29+
"watch": "npm-run-all --parallel watch:esm watch:cjs",
3030
"prepare": "pnpm run build",
3131
"check": "tsc",
3232
"test": "vitest run",
33-
"generate-cts": "tsx scripts/generate-cts.ts",
33+
"switch-package-type": "tsx scripts/switch-package-type.ts",
34+
"rename-cts": "tsx scripts/rename-cts.ts",
3435
"inference-codegen": "tsx scripts/inference-codegen.ts && prettier --write src/tasks/*/inference.ts",
3536
"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",
3637
"inference-tei-import": "tsx scripts/inference-tei-import.ts && prettier --write src/tasks/feature-extraction/spec/*.json"
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// 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";
2+
import { readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
33
import { join } from "node:path";
44

5-
function recursiveCopy(path: string) {
5+
function recursiveRename(path: string) {
66
for (const item of readdirSync(path)) {
77
if (item.endsWith(".d.ts")) {
88
const content = readFileSync(join(path, item), "utf-8");
99
writeFileSync(join(path, item.replace(".d.ts", ".d.cts")), content.replaceAll(".d.ts.map", ".d.cts.map"));
10+
rmSync(join(path, item));
1011
} else if (item.endsWith(".d.ts.map")) {
1112
const content = readFileSync(join(path, item), "utf-8");
1213
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));
14+
rmSync(join(path, item));
15+
} /* else if (item.endsWith(".js")) {
16+
const content = readFileSync(join(path, item), "utf-8");
17+
writeFileSync(join(path, item.replace(".js", ".cjs")), content);
18+
} */ else if (statSync(join(path, item)).isDirectory()) {
19+
recursiveRename(join(path, item));
1520
}
1621
}
1722
}
1823

19-
recursiveCopy("dist");
24+
recursiveRename("dist/cjs");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { readFileSync, writeFileSync } from "fs";
2+
3+
const arg = process.argv[2];
4+
5+
const file = readFileSync("package.json", "utf-8");
6+
7+
writeFileSync("package.json", file.replace(/"type": ".*"/, `"type": "${arg}"`));

0 commit comments

Comments
 (0)