Skip to content

Commit 5d18c2b

Browse files
committed
build: copy non .ts files as is
keep `dist/runtime/polyfill/package.json`
1 parent a263447 commit 5d18c2b

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

scripts/build.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { fileURLToPath } from "node:url";
10-
import { dirname, join, relative } from "node:path";
10+
import { dirname, extname, join, relative } from "node:path";
1111
import { glob, mkdir, readFile, rm, writeFile } from "node:fs/promises";
1212

1313
import oxcTransform from "oxc-transform";
@@ -42,19 +42,36 @@ async function transformDir(cwd: string, input: string, output: string) {
4242
const srcDir = join(cwd, input);
4343
const distDir = join(cwd, output);
4444
const promises: Promise<void>[] = [];
45-
for await (const entryName of glob("**/*.ts", { cwd: srcDir })) {
45+
for await (const entryName of glob("**/*.*", { cwd: srcDir })) {
4646
promises.push(
4747
(async () => {
4848
const entryPath = join(srcDir, entryName);
49-
const transformed = await transformModule(entryPath);
50-
const entryDistPath = join(distDir, entryName.replace(/\.ts$/, ".mjs"));
51-
await mkdir(dirname(entryDistPath), { recursive: true });
52-
await writeFile(entryDistPath, transformed.code, "utf8");
53-
await writeFile(
54-
entryDistPath.replace(/\.mjs$/, ".d.mts"),
55-
transformed.declaration!,
56-
"utf8",
57-
);
49+
const ext = extname(entryPath);
50+
switch (ext) {
51+
case ".ts":
52+
{
53+
const transformed = await transformModule(entryPath);
54+
const entryDistPath = join(
55+
distDir,
56+
entryName.replace(/\.ts$/, ".mjs"),
57+
);
58+
await mkdir(dirname(entryDistPath), { recursive: true });
59+
await writeFile(entryDistPath, transformed.code, "utf8");
60+
await writeFile(
61+
entryDistPath.replace(/\.mjs$/, ".d.mts"),
62+
transformed.declaration!,
63+
"utf8",
64+
);
65+
}
66+
break;
67+
default:
68+
{
69+
const entryDistPath = join(distDir, entryName);
70+
await mkdir(dirname(entryDistPath), { recursive: true });
71+
await writeFile(entryDistPath, await readFile(entryPath), "utf8");
72+
}
73+
break;
74+
}
5875
})(),
5976
);
6077
}
@@ -184,7 +201,3 @@ function resolvePath(id: string, parent: string) {
184201
Error.captureStackTrace?.(error, resolvePath);
185202
throw error;
186203
}
187-
188-
function relativeWithDot(path: string) {
189-
return path.startsWith(".") ? path : `./${path}`;
190-
}

0 commit comments

Comments
 (0)