Skip to content

Commit c6a1b86

Browse files
committed
fix: DEBUG mode not refreshing dts files
Closes #20
1 parent 7d05007 commit c6a1b86

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

.changeset/slow-dogs-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'extractinator': patch
3+
---
4+
5+
fix: DEBUG mode not refreshing dts files

src/emit.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import { extname, relative, resolve } from 'node:path'
22
import { rm, mkdir } from 'node:fs/promises'
33
import { createRequire } from 'node:module'
4+
import { DEBUG_MODE } from './utils/env'
5+
import { b, d, l } from './utils/log'
46
import { emitDts } from 'svelte2tsx'
57
import { existsSync } from 'node:fs'
68
import glob from 'tiny-glob'
79

810
const require = createRequire(import.meta.url)
911

10-
const DEBUG_MODE = typeof process.env['DEBUG'] == 'string'
11-
1212
export async function emit_dts(input: string) {
1313
//? 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()}`)
1515

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`))
2017

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+
})
2929

3030
// todo js files?
3131
const input_file_paths = await glob(`${input}/**/*.{svelte,ts}`, {
@@ -67,7 +67,7 @@ export async function emit_dts(input: string) {
6767
return {
6868
dts_file_map,
6969
async cleanup() {
70-
if (process.env['DEBUG']) return
70+
if (DEBUG_MODE) return
7171
await rm(TEMP_DIR, { recursive: true })
7272
},
7373
}

src/utils/env.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Whether the program is running in debug mode.
3+
*
4+
* @example
5+
* DEBUG=1 extractinator
6+
*/
7+
export const DEBUG_MODE = !!process.env['DEBUG']?.length

src/utils/log.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { type DocNode, DocExcerpt } from '@microsoft/tsdoc'
2+
import { DEBUG_MODE } from './env'
23
import c from 'chalk'
34

4-
let log = typeof process.env['DEBUG'] == 'string';
5+
let log = DEBUG_MODE
56

67
export function shouldLog(state: boolean) {
7-
log = state;
8+
log = state
89
}
910

1011
// Ridiculously short color logging functions that
@@ -88,15 +89,10 @@ export function n(
8889
}
8990
}
9091

91-
9292
/**
9393
* Pretty prints a {@link DocNode} tree to the console.
9494
*/
95-
export function logTSDocTree(
96-
docNode: DocNode,
97-
outputLines: string[] = [],
98-
indent: string = '',
99-
) {
95+
export function logTSDocTree(docNode: DocNode, outputLines: string[] = [], indent: string = '') {
10096
let dumpText: string = ''
10197
if (docNode instanceof DocExcerpt) {
10298
const content: string = docNode.content.toString()

0 commit comments

Comments
 (0)