|
1 | 1 | import { extname, relative, resolve } from 'node:path' |
2 | 2 | import { rm, mkdir } from 'node:fs/promises' |
3 | 3 | import { createRequire } from 'node:module' |
| 4 | +import { DEBUG_MODE } from './utils/env' |
| 5 | +import { b, d, l } from './utils/log' |
4 | 6 | import { emitDts } from 'svelte2tsx' |
5 | 7 | import { existsSync } from 'node:fs' |
6 | 8 | import glob from 'tiny-glob' |
7 | 9 |
|
8 | 10 | const require = createRequire(import.meta.url) |
9 | 11 |
|
10 | | -const DEBUG_MODE = typeof process.env['DEBUG'] == 'string' |
11 | | - |
12 | 12 | export async function emit_dts(input: string) { |
13 | 13 | //? Generate a unique TEMP_DIR for this instance of extractinator. |
14 | | - const TEMP_DIR = resolve(`.extractinator/dts-${DEBUG_MODE ? 'debug' : Date.now()}`) |
| 14 | + const TEMP_DIR = resolve(`.extractinator/dts-${Date.now()}`) |
15 | 15 |
|
16 | | - if (!DEBUG_MODE || !existsSync(TEMP_DIR)) { |
17 | | - //? [re]create the TEMP_DIR. |
18 | | - await rm(TEMP_DIR, { force: true, recursive: true }) |
19 | | - await mkdir(TEMP_DIR, { recursive: true }) |
| 16 | + l(d(`Writing ${b('dts')} files to "${b(TEMP_DIR)}"\n`)) |
20 | 17 |
|
21 | | - //? Use svelte2tsx to generate the dts files for Svelte/TS/JS. |
22 | | - await emitDts({ |
23 | | - svelteShimsPath: require.resolve('svelte2tsx/svelte-shims-v4.d.ts'), |
24 | | - //? Relative path for the output - abs path won't work here. |
25 | | - declarationDir: relative(process.cwd(), TEMP_DIR), |
26 | | - libRoot: input, |
27 | | - }) |
28 | | - } |
| 18 | + //? [re]create the TEMP_DIR. |
| 19 | + await rm(TEMP_DIR, { force: true, recursive: true }) |
| 20 | + await mkdir(TEMP_DIR, { recursive: true }) |
| 21 | + |
| 22 | + //? Use svelte2tsx to generate the dts files for Svelte/TS/JS. |
| 23 | + await emitDts({ |
| 24 | + svelteShimsPath: require.resolve('svelte2tsx/svelte-shims-v4.d.ts'), |
| 25 | + //? Relative path for the output - abs path won't work here. |
| 26 | + declarationDir: relative(process.cwd(), TEMP_DIR), |
| 27 | + libRoot: input, |
| 28 | + }) |
29 | 29 |
|
30 | 30 | // todo js files? |
31 | 31 | const input_file_paths = await glob(`${input}/**/*.{svelte,ts}`, { |
@@ -67,7 +67,7 @@ export async function emit_dts(input: string) { |
67 | 67 | return { |
68 | 68 | dts_file_map, |
69 | 69 | async cleanup() { |
70 | | - if (process.env['DEBUG']) return |
| 70 | + if (DEBUG_MODE) return |
71 | 71 | await rm(TEMP_DIR, { recursive: true }) |
72 | 72 | }, |
73 | 73 | } |
|
0 commit comments