@stacksjs/dtsx 0.9.9 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +243 -15
- package/dist/bin/cli.js +10 -22
- package/dist/branded-types.d.ts +168 -0
- package/dist/bundler.d.ts +55 -0
- package/dist/cache.d.ts +43 -0
- package/dist/checker.d.ts +107 -0
- package/dist/chunk-09zp67d8.js +6 -0
- package/dist/chunk-0kmfaaz6.js +2 -0
- package/dist/chunk-1mm3t0nr.js +3 -0
- package/dist/chunk-2f046tgr.js +2 -0
- package/dist/chunk-3g2v2ns2.js +2 -0
- package/dist/chunk-3j7r0fxz.js +2 -0
- package/dist/chunk-3mxzfgcv.js +75 -0
- package/dist/chunk-4ev1n7r7.js +3 -0
- package/dist/chunk-57agx6g8.js +3 -0
- package/dist/chunk-6ppqaypd.js +2 -0
- package/dist/chunk-6qv7p9sg.js +170 -0
- package/dist/chunk-6s7n1gt0.js +2 -0
- package/dist/chunk-74j5mydx.js +3 -0
- package/dist/chunk-7cpp6v8f.js +2 -0
- package/dist/chunk-9a3jfxnc.js +3 -0
- package/dist/chunk-9mjc7ddv.js +19 -0
- package/dist/chunk-axb2kjeq.js +2 -0
- package/dist/chunk-bn29kee5.js +102 -0
- package/dist/chunk-c18vx9sq.js +2 -0
- package/dist/chunk-d0p3jzwb.js +34 -0
- package/dist/chunk-dk2vv0np.js +15 -0
- package/dist/chunk-e3j9tecw.js +3 -0
- package/dist/chunk-f18nyrrb.js +32 -0
- package/dist/chunk-fbqcsr60.js +22 -0
- package/dist/chunk-ffqpf34b.js +3 -0
- package/dist/chunk-fw6wcdfd.js +4 -0
- package/dist/chunk-h12gdfk9.js +2 -0
- package/dist/chunk-j22v8wfe.js +33 -0
- package/dist/chunk-jm5ywn4e.js +13 -0
- package/dist/chunk-jvz9t6pq.js +2 -0
- package/dist/chunk-k5h5ppp5.js +2 -0
- package/dist/chunk-p1d09y82.js +449 -0
- package/dist/chunk-pyxbb193.js +2 -0
- package/dist/chunk-q75q4w1s.js +3 -0
- package/dist/chunk-r1m3q3dj.js +2 -0
- package/dist/chunk-r1ywapeb.js +6 -0
- package/dist/chunk-rnt0wkrk.js +23 -0
- package/dist/chunk-rrkq4k1n.js +2 -0
- package/dist/chunk-rw6j20e2.js +3 -0
- package/dist/chunk-v96rjx7x.js +134 -0
- package/dist/circular.d.ts +82 -0
- package/dist/compat.d.ts +108 -0
- package/dist/config.d.ts +33 -3
- package/dist/diff.d.ts +82 -0
- package/dist/docs.d.ts +97 -0
- package/dist/errors.d.ts +113 -0
- package/dist/extractor/builders.d.ts +38 -0
- package/dist/extractor/cache.d.ts +47 -0
- package/dist/extractor/declarations.d.ts +50 -0
- package/dist/extractor/directives.d.ts +9 -0
- package/dist/extractor/extract.d.ts +10 -0
- package/dist/extractor/hash.d.ts +1 -0
- package/dist/extractor/helpers.d.ts +39 -0
- package/dist/extractor/index.d.ts +70 -0
- package/dist/extractor/scanner.d.ts +6 -0
- package/dist/extractor.d.ts +3 -4
- package/dist/formats.d.ts +50 -0
- package/dist/formatter.d.ts +61 -0
- package/dist/generator.d.ts +12 -3
- package/dist/import-sorter.d.ts +99 -0
- package/dist/incremental.d.ts +84 -0
- package/dist/index.d.ts +54 -1
- package/dist/logger.d.ts +57 -0
- package/dist/lsp.d.ts +317 -0
- package/dist/memory.d.ts +110 -0
- package/dist/merger.d.ts +38 -0
- package/dist/optimizer.d.ts +52 -0
- package/dist/output-normalizer.d.ts +123 -0
- package/dist/parallel-processor.d.ts +63 -0
- package/dist/parser.d.ts +24 -15
- package/dist/plugins/bun.d.ts +58 -0
- package/dist/plugins/esbuild.d.ts +63 -0
- package/dist/plugins/index.d.ts +14 -0
- package/dist/plugins/tsup.d.ts +53 -0
- package/dist/plugins/vite.d.ts +49 -0
- package/dist/plugins/webpack.d.ts +66 -0
- package/dist/plugins.d.ts +83 -0
- package/dist/process-source.d.ts +11 -0
- package/dist/processor/cache.d.ts +16 -0
- package/dist/processor/comments.d.ts +7 -0
- package/dist/processor/declarations.d.ts +37 -0
- package/dist/processor/imports.d.ts +65 -0
- package/dist/processor/index.d.ts +34 -0
- package/dist/processor/type-inference.d.ts +106 -0
- package/dist/processor.d.ts +3 -43
- package/dist/profiling.d.ts +101 -0
- package/dist/security.d.ts +100 -0
- package/dist/sourcemap.d.ts +125 -0
- package/dist/src/index.js +55 -2
- package/dist/src/plugins/bun.js +2 -0
- package/dist/src/plugins/esbuild.js +2 -0
- package/dist/src/plugins/index.js +2 -0
- package/dist/src/plugins/tsup.js +2 -0
- package/dist/src/plugins/vite.js +2 -0
- package/dist/src/plugins/webpack.js +2 -0
- package/dist/tracking.d.ts +89 -0
- package/dist/transformers.d.ts +173 -0
- package/dist/tree-shaker.d.ts +69 -0
- package/dist/type-mappings.d.ts +148 -0
- package/dist/types.d.ts +137 -7
- package/dist/utils.d.ts +53 -1
- package/dist/watcher.d.ts +64 -0
- package/dist/worker.d.ts +84 -0
- package/dist/workspace.d.ts +62 -0
- package/package.json +49 -11
- package/dist/chunk-qsyn1k3w.js +0 -504
package/dist/parser.d.ts
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @deprecated Use TypeScript AST-based extraction instead
|
|
3
3
|
*/
|
|
4
|
-
/* eslint-disable regexp/no-super-linear-backtracking */
|
|
5
4
|
export declare function removeLeadingComments(text: string): string;
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
6
|
+
* @deprecated Use extractJSDocComments from extractor/helpers instead
|
|
8
7
|
*/
|
|
9
8
|
export declare function extractLeadingComments(source: string, position: number): string[];
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* @deprecated Not commonly used - use inline logic instead
|
|
12
11
|
*/
|
|
13
12
|
export declare function extractTrailingComment(line: string): string | null;
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export declare function formatComments(comments: string[]): string[];
|
|
18
|
-
/**
|
|
19
|
-
* Extract balanced content between symbols (e.g., <>, (), {})
|
|
14
|
+
* @deprecated Use findMatchingBracket from processor/type-inference instead
|
|
20
15
|
*/
|
|
21
16
|
export declare function extractBalancedSymbols(text: string, openSymbol: string, closeSymbol: string): { content: string, rest: string } | null;
|
|
22
17
|
/**
|
|
23
|
-
*
|
|
18
|
+
* @deprecated Use TypeScript AST-based extraction instead
|
|
24
19
|
*/
|
|
25
20
|
export declare function parseFunctionDeclaration(text: string): FunctionSignature | null;
|
|
26
21
|
/**
|
|
27
|
-
*
|
|
22
|
+
* @deprecated Use hasExportModifier from extractor/helpers instead
|
|
28
23
|
*/
|
|
29
24
|
export declare function isExportStatement(line: string): boolean;
|
|
30
25
|
/**
|
|
31
|
-
*
|
|
26
|
+
* @deprecated Not commonly used
|
|
32
27
|
*/
|
|
33
28
|
export declare function isTypeOnlyExport(line: string): boolean;
|
|
34
29
|
/**
|
|
35
|
-
*
|
|
30
|
+
* @deprecated Use TypeScript AST-based extraction instead
|
|
36
31
|
*/
|
|
37
32
|
export declare function parseVariableDeclaration(text: string): {
|
|
38
33
|
name: string
|
|
@@ -41,7 +36,7 @@ export declare function parseVariableDeclaration(text: string): {
|
|
|
41
36
|
value?: string
|
|
42
37
|
} | null;
|
|
43
38
|
/**
|
|
44
|
-
*
|
|
39
|
+
* @deprecated Interface kept for backward compatibility
|
|
45
40
|
*/
|
|
46
41
|
export declare interface FunctionSignature {
|
|
47
42
|
name: string
|
|
@@ -49,4 +44,18 @@ export declare interface FunctionSignature {
|
|
|
49
44
|
parameters: string
|
|
50
45
|
returnType: string
|
|
51
46
|
modifiers: string[]
|
|
52
|
-
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parser utilities - DEPRECATED
|
|
50
|
+
*
|
|
51
|
+
* This module contains legacy string-based parsing utilities.
|
|
52
|
+
* Most functionality has been superseded by TypeScript AST-based extraction
|
|
53
|
+
* in the extractor module.
|
|
54
|
+
*
|
|
55
|
+
* @deprecated Use extractor module for AST-based extraction and
|
|
56
|
+
* processor/type-inference for type inference utilities.
|
|
57
|
+
*/
|
|
58
|
+
export { extractJSDocComments as extractLeadingCommentsFromNode, getNodeText } from './extractor/helpers';
|
|
59
|
+
export { formatComments } from './processor/comments';
|
|
60
|
+
// Re-export commonly used utilities from their new locations
|
|
61
|
+
export { findMatchingBracket } from './processor/type-inference';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { DtsGenerationConfig, GenerationStats } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a Bun build plugin for dtsx
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // build.ts
|
|
8
|
+
* import { dts } from '@stacksjs/dtsx/plugins/bun'
|
|
9
|
+
*
|
|
10
|
+
* await Bun.build({
|
|
11
|
+
* entrypoints: ['./src/index.ts'],
|
|
12
|
+
* outdir: './dist',
|
|
13
|
+
* plugins: [
|
|
14
|
+
* dts({
|
|
15
|
+
* root: './src',
|
|
16
|
+
* outdir: './dist',
|
|
17
|
+
* }),
|
|
18
|
+
* ],
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function dts(options?: BunPluginOptions): BunPlugin;
|
|
23
|
+
/**
|
|
24
|
+
* Alias for dts
|
|
25
|
+
*/
|
|
26
|
+
export declare const bunDts: typeof dts;
|
|
27
|
+
/**
|
|
28
|
+
* Bun plugin options
|
|
29
|
+
*/
|
|
30
|
+
export declare interface BunPluginOptions extends Partial<DtsGenerationConfig> {
|
|
31
|
+
preBuild?: boolean
|
|
32
|
+
postBuild?: boolean
|
|
33
|
+
onGenerated?: (stats: GenerationStats) => void
|
|
34
|
+
onError?: (error: Error) => void
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Bun plugin interface
|
|
38
|
+
*/
|
|
39
|
+
declare interface BunPlugin {
|
|
40
|
+
name: string
|
|
41
|
+
setup: (build: BunBuild) => void | Promise<void>
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Bun build interface (minimal type)
|
|
45
|
+
*/
|
|
46
|
+
declare interface BunBuild {
|
|
47
|
+
onStart: (callback: () => void | Promise<void>) => void
|
|
48
|
+
onLoad: (options: { filter: RegExp }, callback: (args: { path: string }) => unknown) => void
|
|
49
|
+
config: {
|
|
50
|
+
entrypoints: string[]
|
|
51
|
+
outdir?: string
|
|
52
|
+
root?: string
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Default export
|
|
57
|
+
*/
|
|
58
|
+
export default dts;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { DtsGenerationConfig, GenerationStats } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Create an esbuild plugin for dtsx
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // build.ts
|
|
8
|
+
* import { dtsx } from '@stacksjs/dtsx/plugins/esbuild'
|
|
9
|
+
* import * as esbuild from 'esbuild'
|
|
10
|
+
*
|
|
11
|
+
* await esbuild.build({
|
|
12
|
+
* entryPoints: ['./src/index.ts'],
|
|
13
|
+
* outdir: './dist',
|
|
14
|
+
* plugins: [
|
|
15
|
+
* dtsx({
|
|
16
|
+
* root: './src',
|
|
17
|
+
* outdir: './dist',
|
|
18
|
+
* }),
|
|
19
|
+
* ],
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function dtsx(options?: EsbuildPluginOptions): EsbuildPlugin;
|
|
24
|
+
/**
|
|
25
|
+
* Alias for dtsx
|
|
26
|
+
*/
|
|
27
|
+
export declare const esbuildDts: typeof dtsx;
|
|
28
|
+
/**
|
|
29
|
+
* Alias matching common naming convention
|
|
30
|
+
*/
|
|
31
|
+
export declare const dts: typeof dtsx;
|
|
32
|
+
/**
|
|
33
|
+
* esbuild plugin options
|
|
34
|
+
*/
|
|
35
|
+
export declare interface EsbuildPluginOptions extends Partial<DtsGenerationConfig> {
|
|
36
|
+
onStart?: boolean
|
|
37
|
+
onEnd?: boolean
|
|
38
|
+
onGenerated?: (stats: GenerationStats) => void
|
|
39
|
+
onError?: (error: Error) => void
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* esbuild plugin interface
|
|
43
|
+
*/
|
|
44
|
+
declare interface EsbuildPlugin {
|
|
45
|
+
name: string
|
|
46
|
+
setup: (build: EsbuildBuild) => void | Promise<void>
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* esbuild build interface (minimal type)
|
|
50
|
+
*/
|
|
51
|
+
declare interface EsbuildBuild {
|
|
52
|
+
onStart: (callback: () => { errors?: Array<{ text: string }> } | Promise<{ errors?: Array<{ text: string }> } | void> | void) => void
|
|
53
|
+
onEnd: (callback: (result: { errors: unknown[] }) => void | Promise<void>) => void
|
|
54
|
+
initialOptions: {
|
|
55
|
+
entryPoints?: string[] | Record<string, string>
|
|
56
|
+
outdir?: string
|
|
57
|
+
outfile?: string
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Default export
|
|
62
|
+
*/
|
|
63
|
+
export default dtsx;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build tool plugins for dtsx
|
|
3
|
+
* Re-exports all available build tool integrations
|
|
4
|
+
*/
|
|
5
|
+
// Vite
|
|
6
|
+
export { dts as viteDts, dts as vite, type VitePluginOptions } from './vite';
|
|
7
|
+
// Bun
|
|
8
|
+
export { dts as bunDts, dts as bun, type BunPluginOptions } from './bun';
|
|
9
|
+
// esbuild
|
|
10
|
+
export { dtsx as esbuildDts, dtsx as esbuild, dts as esbuildPlugin, type EsbuildPluginOptions } from './esbuild';
|
|
11
|
+
// tsup
|
|
12
|
+
export { dtsxPlugin as tsupDts, dtsxPlugin as tsup, dts as tsupPlugin, type TsupPluginOptions } from './tsup';
|
|
13
|
+
// webpack
|
|
14
|
+
export { DtsxWebpackPlugin, dtsxWebpack as webpackDts, dts as webpackPlugin, type WebpackPluginOptions } from './webpack';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DtsGenerationConfig, GenerationStats } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a tsup plugin for dtsx
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // tsup.config.ts
|
|
8
|
+
* import { dtsxPlugin } from '@stacksjs/dtsx/plugins/tsup'
|
|
9
|
+
* import { defineConfig } from 'tsup'
|
|
10
|
+
*
|
|
11
|
+
* export default defineConfig({
|
|
12
|
+
* entry: ['./src/index.ts'],
|
|
13
|
+
* outDir: './dist',
|
|
14
|
+
* plugins: [
|
|
15
|
+
* dtsxPlugin({
|
|
16
|
+
* root: './src',
|
|
17
|
+
* outdir: './dist',
|
|
18
|
+
* }),
|
|
19
|
+
* ],
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function dtsxPlugin(options?: TsupPluginOptions): TsupPlugin;
|
|
24
|
+
/**
|
|
25
|
+
* Alias for dtsxPlugin
|
|
26
|
+
*/
|
|
27
|
+
export declare const tsupDts: typeof dtsxPlugin;
|
|
28
|
+
/**
|
|
29
|
+
* Alias matching common naming convention
|
|
30
|
+
*/
|
|
31
|
+
export declare const dts: typeof dtsxPlugin;
|
|
32
|
+
/**
|
|
33
|
+
* tsup plugin options
|
|
34
|
+
*/
|
|
35
|
+
export declare interface TsupPluginOptions extends Partial<DtsGenerationConfig> {
|
|
36
|
+
onBuildStart?: boolean
|
|
37
|
+
onBuildEnd?: boolean
|
|
38
|
+
onGenerated?: (stats: GenerationStats) => void
|
|
39
|
+
onError?: (error: Error) => void
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* tsup plugin interface
|
|
43
|
+
*/
|
|
44
|
+
declare interface TsupPlugin {
|
|
45
|
+
name: string
|
|
46
|
+
buildStart?: () => void | Promise<void>
|
|
47
|
+
buildEnd?: (ctx: { writtenFiles: Array<{ name: string, size: number }> }) => void | Promise<void>
|
|
48
|
+
esbuildOptions?: (options: Record<string, unknown>) => void
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Default export
|
|
52
|
+
*/
|
|
53
|
+
export default dtsxPlugin;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { DtsGenerationConfig, GenerationStats } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a Vite plugin for dtsx
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // vite.config.ts
|
|
8
|
+
* import { dts } from '@stacksjs/dtsx/plugins/vite'
|
|
9
|
+
*
|
|
10
|
+
* export default {
|
|
11
|
+
* plugins: [
|
|
12
|
+
* dts({
|
|
13
|
+
* root: './src',
|
|
14
|
+
* outdir: './dist',
|
|
15
|
+
* }),
|
|
16
|
+
* ],
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function dts(options?: VitePluginOptions): VitePlugin;
|
|
21
|
+
/**
|
|
22
|
+
* Alias for dts
|
|
23
|
+
*/
|
|
24
|
+
export declare const viteDts: typeof dts;
|
|
25
|
+
/**
|
|
26
|
+
* Vite plugin options
|
|
27
|
+
*/
|
|
28
|
+
export declare interface VitePluginOptions extends Partial<DtsGenerationConfig> {
|
|
29
|
+
buildStart?: boolean
|
|
30
|
+
buildEnd?: boolean
|
|
31
|
+
writeBundle?: boolean
|
|
32
|
+
modes?: string[]
|
|
33
|
+
onGenerated?: (stats: GenerationStats) => void
|
|
34
|
+
onError?: (error: Error) => void
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Vite plugin interface (minimal type for compatibility)
|
|
38
|
+
*/
|
|
39
|
+
declare interface VitePlugin {
|
|
40
|
+
name: string
|
|
41
|
+
apply?: 'build' | 'serve' | ((_config: { mode: string }) => boolean)
|
|
42
|
+
buildStart?: () => Promise<void> | void
|
|
43
|
+
buildEnd?: () => Promise<void> | void
|
|
44
|
+
writeBundle?: () => Promise<void> | void
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Default export
|
|
48
|
+
*/
|
|
49
|
+
export default dts;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { DtsGenerationConfig, GenerationStats } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Factory function for creating webpack plugin
|
|
4
|
+
*/
|
|
5
|
+
export declare function dtsxWebpack(options?: WebpackPluginOptions): DtsxWebpackPlugin;
|
|
6
|
+
/**
|
|
7
|
+
* Alias matching common naming convention
|
|
8
|
+
*/
|
|
9
|
+
export declare const dts: typeof dtsxWebpack;
|
|
10
|
+
/**
|
|
11
|
+
* webpack plugin options
|
|
12
|
+
*/
|
|
13
|
+
export declare interface WebpackPluginOptions extends Partial<DtsGenerationConfig> {
|
|
14
|
+
onCompile?: boolean
|
|
15
|
+
afterEmit?: boolean
|
|
16
|
+
onWatchRun?: boolean
|
|
17
|
+
onGenerated?: (stats: GenerationStats) => void
|
|
18
|
+
onError?: (error: Error) => void
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* webpack compiler interface (minimal type)
|
|
22
|
+
*/
|
|
23
|
+
declare interface WebpackCompiler {
|
|
24
|
+
hooks: {
|
|
25
|
+
compile: { tap: (name: string, callback: () => void) => void }
|
|
26
|
+
afterEmit: { tapAsync: (name: string, callback: (compilation: unknown, done: () => void) => void) => void }
|
|
27
|
+
watchRun: { tapAsync: (name: string, callback: (compiler: unknown, done: () => void) => void) => void }
|
|
28
|
+
}
|
|
29
|
+
options: {
|
|
30
|
+
entry?: unknown
|
|
31
|
+
output?: {
|
|
32
|
+
path?: string
|
|
33
|
+
}
|
|
34
|
+
context?: string
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* webpack plugin for dtsx
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // webpack.config.js
|
|
43
|
+
* const { DtsxWebpackPlugin } = require('@stacksjs/dtsx/plugins/webpack')
|
|
44
|
+
*
|
|
45
|
+
* module.exports = {
|
|
46
|
+
* entry: './src/index.ts',
|
|
47
|
+
* output: {
|
|
48
|
+
* path: path.resolve(__dirname, 'dist'),
|
|
49
|
+
* },
|
|
50
|
+
* plugins: [
|
|
51
|
+
* new DtsxWebpackPlugin({
|
|
52
|
+
* root: './src',
|
|
53
|
+
* outdir: './dist',
|
|
54
|
+
* }),
|
|
55
|
+
* ],
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare class DtsxWebpackPlugin {
|
|
60
|
+
constructor(options?: WebpackPluginOptions);
|
|
61
|
+
apply(compiler: WebpackCompiler): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Default export
|
|
65
|
+
*/
|
|
66
|
+
export default DtsxWebpackPlugin;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Declaration, DtsGenerationConfig, GenerationStats } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Helper to create a plugin
|
|
4
|
+
*/
|
|
5
|
+
export declare function definePlugin(plugin: Plugin): Plugin;
|
|
6
|
+
/**
|
|
7
|
+
* Built-in plugin: Add banner comment
|
|
8
|
+
* Adds a banner comment to the top of generated files
|
|
9
|
+
*/
|
|
10
|
+
export declare function createBannerPlugin(banner: string): Plugin;
|
|
11
|
+
/**
|
|
12
|
+
* Built-in plugin: Filter exports
|
|
13
|
+
* Only include declarations matching the filter
|
|
14
|
+
*/
|
|
15
|
+
export declare function createFilterPlugin(filter: (name: string) => boolean): Plugin;
|
|
16
|
+
/**
|
|
17
|
+
* Global plugin manager instance
|
|
18
|
+
*/
|
|
19
|
+
export declare const pluginManager: PluginManager;
|
|
20
|
+
/**
|
|
21
|
+
* Built-in plugin: Strip internal declarations
|
|
22
|
+
* Removes declarations marked with @internal in JSDoc
|
|
23
|
+
*/
|
|
24
|
+
export declare const stripInternalPlugin: Plugin;
|
|
25
|
+
/**
|
|
26
|
+
* Context passed to plugin hooks
|
|
27
|
+
*/
|
|
28
|
+
export declare interface PluginContext {
|
|
29
|
+
filePath: string
|
|
30
|
+
sourceCode: string
|
|
31
|
+
config: DtsGenerationConfig
|
|
32
|
+
log: {
|
|
33
|
+
debug: (message: string) => void
|
|
34
|
+
info: (message: string) => void
|
|
35
|
+
warn: (message: string) => void
|
|
36
|
+
error: (message: string) => void
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Transform context with mutable content
|
|
41
|
+
*/
|
|
42
|
+
export declare interface TransformContext extends PluginContext {
|
|
43
|
+
content: string
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Declaration context for declaration hooks
|
|
47
|
+
*/
|
|
48
|
+
export declare interface DeclarationContext extends PluginContext {
|
|
49
|
+
declarations: Declaration[]
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Plugin hook definitions
|
|
53
|
+
*/
|
|
54
|
+
export declare interface PluginHooks {
|
|
55
|
+
onStart?: (config: DtsGenerationConfig) => DtsGenerationConfig | void | Promise<DtsGenerationConfig | void>
|
|
56
|
+
onBeforeFile?: (ctx: TransformContext) => string | void | Promise<string | void>
|
|
57
|
+
onDeclarations?: (ctx: DeclarationContext) => Declaration[] | void | Promise<Declaration[] | void>
|
|
58
|
+
onAfterFile?: (ctx: TransformContext) => string | void | Promise<string | void>
|
|
59
|
+
onEnd?: (stats: GenerationStats) => void | Promise<void>
|
|
60
|
+
onError?: (error: Error, ctx: PluginContext) => void | Promise<void>
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Plugin definition
|
|
64
|
+
*/
|
|
65
|
+
export declare interface Plugin extends PluginHooks {
|
|
66
|
+
name: string
|
|
67
|
+
version?: string
|
|
68
|
+
description?: string
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Plugin manager for handling multiple plugins
|
|
72
|
+
*/
|
|
73
|
+
export declare class PluginManager {
|
|
74
|
+
register(plugin: Plugin): void;
|
|
75
|
+
unregister(name: string): boolean;
|
|
76
|
+
getPlugins(): readonly Plugin[];
|
|
77
|
+
runOnStart(config: DtsGenerationConfig): Promise<DtsGenerationConfig>;
|
|
78
|
+
runOnBeforeFile(filePath: string, sourceCode: string): Promise<string>;
|
|
79
|
+
runOnDeclarations(filePath: string, sourceCode: string, declarations: Declaration[]): Promise<Declaration[]>;
|
|
80
|
+
runOnAfterFile(filePath: string, sourceCode: string, dtsContent: string): Promise<string>;
|
|
81
|
+
runOnEnd(stats: GenerationStats): Promise<void>;
|
|
82
|
+
runOnError(error: Error, filePath: string, sourceCode: string): Promise<void>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process TypeScript source code from a string (for stdin support)
|
|
3
|
+
* This is a lightweight module that avoids pulling in heavy dependencies
|
|
4
|
+
* like bun Glob, fs/promises, bundler, cache, config, etc.
|
|
5
|
+
*/
|
|
6
|
+
export declare function processSource(sourceCode: string, filename?: string, keepComments?: boolean, importOrder?: string[], isolatedDeclarations?: boolean): string;
|
|
7
|
+
/**
|
|
8
|
+
* Fast path for project mode — skips cache lookup/store.
|
|
9
|
+
* Use when processing many files once (no cache benefit).
|
|
10
|
+
*/
|
|
11
|
+
export declare function processSourceDirect(sourceCode: string, filename?: string, keepComments?: boolean, importOrder?: string[], isolatedDeclarations?: boolean): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get or create a cached RegExp for word boundary matching
|
|
3
|
+
*/
|
|
4
|
+
export declare function getCachedRegex(pattern: string): RegExp;
|
|
5
|
+
/**
|
|
6
|
+
* Get cached import items or null if not cached
|
|
7
|
+
*/
|
|
8
|
+
export declare function getImportItemsFromCache(importText: string): string[] | null;
|
|
9
|
+
/**
|
|
10
|
+
* Store import items in cache with eviction
|
|
11
|
+
*/
|
|
12
|
+
export declare function setImportItemsCache(importText: string, items: string[]): void;
|
|
13
|
+
/**
|
|
14
|
+
* Clear processor caches (useful for testing or memory management)
|
|
15
|
+
*/
|
|
16
|
+
export declare function clearProcessorCaches(): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Declaration } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Process function declaration to DTS format
|
|
4
|
+
*/
|
|
5
|
+
export declare function processFunctionDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
6
|
+
/**
|
|
7
|
+
* Process variable declaration to DTS format
|
|
8
|
+
*/
|
|
9
|
+
export declare function processVariableDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
10
|
+
/**
|
|
11
|
+
* Process interface declaration to DTS format
|
|
12
|
+
*/
|
|
13
|
+
export declare function processInterfaceDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
14
|
+
/**
|
|
15
|
+
* Process type alias declaration to DTS format
|
|
16
|
+
*/
|
|
17
|
+
export declare function processTypeDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
18
|
+
/**
|
|
19
|
+
* Process class declaration to DTS format
|
|
20
|
+
*/
|
|
21
|
+
export declare function processClassDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
22
|
+
/**
|
|
23
|
+
* Process enum declaration to DTS format
|
|
24
|
+
*/
|
|
25
|
+
export declare function processEnumDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
26
|
+
/**
|
|
27
|
+
* Process import statement
|
|
28
|
+
*/
|
|
29
|
+
export declare function processImportDeclaration(decl: Declaration): string;
|
|
30
|
+
/**
|
|
31
|
+
* Process export statement
|
|
32
|
+
*/
|
|
33
|
+
export declare function processExportDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
34
|
+
/**
|
|
35
|
+
* Process module/namespace declaration to DTS format
|
|
36
|
+
*/
|
|
37
|
+
export declare function processModuleDeclaration(decl: Declaration, keepComments?: boolean): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse an import statement into its components using string operations
|
|
3
|
+
* Avoids regex backtracking issues
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseImportStatement(importText: string): {
|
|
6
|
+
defaultName: string | null
|
|
7
|
+
namedItems: string[]
|
|
8
|
+
source: string
|
|
9
|
+
isTypeOnly: boolean
|
|
10
|
+
} | null;
|
|
11
|
+
/**
|
|
12
|
+
* Extract all imported items from an import statement (with caching)
|
|
13
|
+
* Uses simple string operations to avoid regex backtracking
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractAllImportedItems(importText: string): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Parse an import statement with detailed type-only information for each item
|
|
18
|
+
* Handles: import type { X }, import { type X, Y }, import * as X, etc.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseImportDetailed(importText: string): ParsedImport | null;
|
|
21
|
+
/**
|
|
22
|
+
* Parse an export statement with detailed type-only information
|
|
23
|
+
* Handles: export type { X }, export { type X, Y }, export * from, etc.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseExportDetailed(exportText: string): {
|
|
26
|
+
namedItems: ImportItem[]
|
|
27
|
+
source: string | null
|
|
28
|
+
isTypeOnly: boolean
|
|
29
|
+
isNamespace: boolean
|
|
30
|
+
isDefault: boolean
|
|
31
|
+
} | null;
|
|
32
|
+
/**
|
|
33
|
+
* Check if an import item is type-only
|
|
34
|
+
*/
|
|
35
|
+
export declare function isTypeOnlyImportItem(itemText: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Convert import items to type-only format
|
|
38
|
+
* E.g., "{ X, Y }" becomes "{ type X, type Y }"
|
|
39
|
+
*/
|
|
40
|
+
export declare function convertToTypeOnlyImport(importText: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Merge value and type imports from the same module
|
|
43
|
+
* Combines separate import statements into one where possible
|
|
44
|
+
*/
|
|
45
|
+
export declare function mergeImports(imports: string[]): string[];
|
|
46
|
+
/**
|
|
47
|
+
* Represents a single imported item with its type-only status
|
|
48
|
+
*/
|
|
49
|
+
export declare interface ImportItem {
|
|
50
|
+
name: string
|
|
51
|
+
originalName: string
|
|
52
|
+
isTypeOnly: boolean
|
|
53
|
+
isDefault: boolean
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Detailed import statement parse result
|
|
57
|
+
*/
|
|
58
|
+
export declare interface ParsedImport {
|
|
59
|
+
defaultName: string | null
|
|
60
|
+
namedItems: ImportItem[]
|
|
61
|
+
source: string
|
|
62
|
+
isTypeOnly: boolean
|
|
63
|
+
isNamespace: boolean
|
|
64
|
+
namespaceName: string | null
|
|
65
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { extractAllImportedItems, parseImportStatement } from './imports';
|
|
2
|
+
import { formatComments } from './comments';
|
|
3
|
+
import { processClassDeclaration, processEnumDeclaration, processFunctionDeclaration, processInterfaceDeclaration, processModuleDeclaration, processTypeDeclaration, processVariableDeclaration } from './declarations';
|
|
4
|
+
import type { Declaration, ProcessingContext } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Process declarations and convert them to narrow DTS format
|
|
7
|
+
*/
|
|
8
|
+
export declare function processDeclarations(declarations: Declaration[], context: ProcessingContext, keepComments?: boolean, importOrder?: string[]): string;
|
|
9
|
+
// Re-export all public APIs
|
|
10
|
+
export { clearProcessorCaches } from './cache';
|
|
11
|
+
export { formatComments } from './comments';
|
|
12
|
+
export {
|
|
13
|
+
processClassDeclaration,
|
|
14
|
+
processEnumDeclaration,
|
|
15
|
+
processExportDeclaration,
|
|
16
|
+
processFunctionDeclaration,
|
|
17
|
+
processImportDeclaration,
|
|
18
|
+
processInterfaceDeclaration,
|
|
19
|
+
processModuleDeclaration,
|
|
20
|
+
processTypeDeclaration,
|
|
21
|
+
processVariableDeclaration,
|
|
22
|
+
} from './declarations';
|
|
23
|
+
export { extractAllImportedItems, parseImportStatement } from './imports';
|
|
24
|
+
export {
|
|
25
|
+
extractSatisfiesType,
|
|
26
|
+
findMatchingBracket,
|
|
27
|
+
inferArrayType,
|
|
28
|
+
inferFunctionType,
|
|
29
|
+
inferNarrowType,
|
|
30
|
+
inferNarrowTypeInUnion,
|
|
31
|
+
inferObjectType,
|
|
32
|
+
isGenericType,
|
|
33
|
+
parseArrayElements,
|
|
34
|
+
} from './type-inference';
|