|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import { fileURLToPath } from "node:url"; |
10 | | -import { dirname, join, relative } from "node:path"; |
| 10 | +import { dirname, extname, join, relative } from "node:path"; |
11 | 11 | import { glob, mkdir, readFile, rm, writeFile } from "node:fs/promises"; |
12 | 12 |
|
13 | 13 | import oxcTransform from "oxc-transform"; |
@@ -42,19 +42,36 @@ async function transformDir(cwd: string, input: string, output: string) { |
42 | 42 | const srcDir = join(cwd, input); |
43 | 43 | const distDir = join(cwd, output); |
44 | 44 | const promises: Promise<void>[] = []; |
45 | | - for await (const entryName of glob("**/*.ts", { cwd: srcDir })) { |
| 45 | + for await (const entryName of glob("**/*.*", { cwd: srcDir })) { |
46 | 46 | promises.push( |
47 | 47 | (async () => { |
48 | 48 | 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 | + } |
58 | 75 | })(), |
59 | 76 | ); |
60 | 77 | } |
@@ -184,7 +201,3 @@ function resolvePath(id: string, parent: string) { |
184 | 201 | Error.captureStackTrace?.(error, resolvePath); |
185 | 202 | throw error; |
186 | 203 | } |
187 | | - |
188 | | -function relativeWithDot(path: string) { |
189 | | - return path.startsWith(".") ? path : `./${path}`; |
190 | | -} |
|
0 commit comments