@stacksjs/dtsx 0.8.2 → 0.9.2

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/dist/types.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * DtsGenerationConfig
3
+ *
4
+ * This is the configuration object for the DTS generation process.
5
+ */
1
6
  export declare interface DtsGenerationConfig {
2
7
  cwd: string
3
8
  root: string
@@ -9,108 +14,76 @@ export declare interface DtsGenerationConfig {
9
14
  verbose: boolean | string[]
10
15
  outputStructure?: 'mirror' | 'flat'
11
16
  }
12
- export declare type DtsGenerationOption = Partial<DtsGenerationConfig>
13
-
14
- export type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[]
15
-
16
- export interface RegexPatterns {
17
- readonly typeImport: RegExp
18
- readonly regularImport: RegExp
19
- readonly bracketOpen: RegExp
20
- readonly bracketClose: RegExp
21
- readonly functionReturn: RegExp
22
- readonly typeAnnotation: RegExp
23
- readonly asyncFunction: RegExp
24
- readonly genericParams: RegExp
25
- readonly functionParams: RegExp
26
- readonly functionReturnType: RegExp
27
- readonly destructuredParams: RegExp
28
- readonly typePattern: RegExp
29
- readonly valueReference: RegExp
30
- readonly typeReference: RegExp
31
- readonly functionName: RegExp
32
- readonly exportCleanup: RegExp
33
- readonly defaultExport: RegExp
34
- readonly complexType: RegExp
35
- readonly unionIntersection: RegExp
36
- readonly mappedType: RegExp
37
- readonly conditionalType: RegExp
38
- readonly genericConstraints: RegExp
39
- readonly functionOverload: RegExp
40
- readonly moduleDeclaration: RegExp
41
- readonly moduleAugmentation: RegExp
42
- }
43
-
44
- export interface ImportTrackingState {
45
- typeImports: Map<string, Set<string>>
46
- valueImports: Map<string, Set<string>>
47
- usedTypes: Set<string>
48
- usedValues: Set<string>
49
- exportedTypes: Set<string>
50
- exportedValues: Set<string>
51
- valueAliases: Map<string, string>
52
- importSources: Map<string, string>
53
- typeExportSources: Map<string, string>
54
- defaultExportValue?: string
55
- }
56
-
57
- export interface ProcessingState {
58
- dtsLines: string[]
59
- imports: string[]
60
- usedTypes: Set<string>
61
- typeSources: Map<string, string>
62
- defaultExport: string | null
63
- exportAllStatements: string[]
64
- currentDeclaration: string
65
- lastCommentBlock: string
66
- bracketCount: number
67
- isMultiLineDeclaration: boolean
68
- moduleImports: Map<string, ImportInfo>
69
- availableTypes: Map<string, string>
70
- availableValues: Map<string, string>
71
- currentIndentation: string
72
- declarationBuffer: {
73
- type: 'interface' | 'type' | 'const' | 'function' | 'import' | 'export'
74
- indent: string
75
- lines: string[]
76
- comments: string[]
77
- } | null
78
- importTracking: ImportTrackingState
79
- defaultExports: Set<string>
80
- currentScope: 'top' | 'function'
17
+ /**
18
+ * Declaration
19
+ *
20
+ * Represents a parsed declaration from TypeScript source
21
+ */
22
+ export declare interface Declaration {
23
+ kind: 'function' | 'variable' | 'interface' | 'type' | 'class' | 'enum' | 'import' | 'export' | 'module'
24
+ name: string
25
+ text: string
26
+ leadingComments?: string[]
27
+ isExported: boolean
28
+ isDefault?: boolean
29
+ typeAnnotation?: string
30
+ modifiers?: string[]
31
+ generics?: string
32
+ extends?: string
33
+ implements?: string[]
34
+ members?: Declaration[]
35
+ parameters?: ParameterDeclaration[]
36
+ returnType?: string
37
+ value?: any
38
+ source?: string
39
+ specifiers?: ImportSpecifier[]
40
+ isTypeOnly?: boolean
41
+ isAsync?: boolean
42
+ isGenerator?: boolean
43
+ overloads?: string[]
44
+ start?: number
45
+ end?: number
81
46
  }
82
-
83
- export interface MethodSignature {
47
+ /**
48
+ * ParameterDeclaration
49
+ */
50
+ export declare interface ParameterDeclaration {
84
51
  name: string
85
- async: boolean
86
- generics: string
87
- params: string
88
- returnType: string
52
+ type?: string
53
+ optional?: boolean
54
+ rest?: boolean
55
+ defaultValue?: string
89
56
  }
90
-
91
- export interface PropertyInfo {
92
- key: string
93
- value: string
94
- type: string
95
- nested?: PropertyInfo[]
96
- method?: MethodSignature
57
+ /**
58
+ * ImportSpecifier
59
+ */
60
+ export declare interface ImportSpecifier {
61
+ name: string
62
+ alias?: string
63
+ isType?: boolean
97
64
  }
98
-
99
- export interface ImportInfo {
100
- kind: 'type' | 'value' | 'mixed'
65
+ /**
66
+ * ProcessingContext
67
+ *
68
+ * Context passed through processing pipeline
69
+ */
70
+ export declare interface ProcessingContext {
71
+ filePath: string
72
+ sourceCode: string
73
+ declarations: Declaration[]
74
+ imports: Map<string, Set<string>>
75
+ exports: Set<string>
101
76
  usedTypes: Set<string>
102
- usedValues: Set<string>
103
- source: string
104
- }
105
-
106
- export interface FunctionSignature {
107
- name: string
108
- params: string
109
- returnType: string
110
- generics: string
111
77
  }
112
-
113
- export interface ProcessedMethod {
114
- name: string
115
- signature: string
116
- }
78
+ /**
79
+ * DtsGenerationOption
80
+ *
81
+ * This is the configuration object for the DTS generation process.
82
+ */
83
+ export type DtsGenerationOption = Partial<DtsGenerationConfig>
84
+ /**
85
+ * DtsGenerationOptions
86
+ *
87
+ * This is the configuration object for the DTS generation process.
88
+ */
89
+ export type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[]
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { DtsGenerationConfig } from './types';
2
-
3
2
  export declare function writeToFile(filePath: string, content: string): Promise<void>;
4
3
  export declare function getAllTypeScriptFiles(directory?: string): Promise<string[]>;
5
- export declare function checkIsolatedDeclarations(options?: DtsGenerationConfig): Promise<boolean>;
6
- declare function makeAbsolute(basePath: string, configPath: string): string;
4
+ // only checks for 2 potentially nested levels
5
+ export declare function checkIsolatedDeclarations(options?: DtsGenerationConfig): Promise<boolean>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/dtsx",
3
3
  "type": "module",
4
- "version": "0.8.2",
4
+ "version": "0.9.2",
5
5
  "description": "A modern, fast .d.ts generation tool, powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -25,16 +25,16 @@
25
25
  ],
26
26
  "exports": {
27
27
  ".": {
28
- "import": "./dist/index.js"
28
+ "import": "./dist/src/index.js"
29
29
  },
30
30
  "./*": {
31
31
  "import": "./dist/*"
32
32
  }
33
33
  },
34
- "module": "./dist/index.js",
34
+ "module": "./dist/src/index.js",
35
35
  "types": "./dist/index.d.ts",
36
36
  "bin": {
37
- "dtsx": "./dist/cli.js"
37
+ "dtsx": "./dist/bin/cli.js"
38
38
  },
39
39
  "files": [
40
40
  "dist"
@@ -56,9 +56,6 @@
56
56
  "release": "bun run changelog && bunx bumpp package.json --all",
57
57
  "test": "bun test",
58
58
  "typecheck": "bunx tsc --noEmit",
59
- "dev:docs": "bun --bun vitepress dev docs",
60
- "build:docs": "bun --bun vitepress build docs",
61
- "preview:docs": "bun --bun vitepress preview docs",
62
59
  "zip": "bun run zip:all",
63
60
  "zip:all": "bun run zip:linux-x64 && bun run zip:linux-arm64 && bun run zip:windows-x64 && bun run zip:darwin-x64 && bun run zip:darwin-arm64",
64
61
  "zip:linux-x64": "zip -j bin/dtsx-linux-x64.zip bin/dtsx-linux-x64",
@@ -68,23 +65,14 @@
68
65
  "zip:darwin-arm64": "zip -j bin/dtsx-darwin-arm64.zip bin/dtsx-darwin-arm64"
69
66
  },
70
67
  "devDependencies": {
71
- "@stacksjs/cli": "^0.70.23",
72
- "@stacksjs/development": "^0.70.23",
73
- "@stacksjs/docs": "^0.70.23",
74
- "@stacksjs/eslint-config": "^4.10.2-beta.3",
75
- "@types/bun": "^1.2.12",
76
- "bun-plugin-dtsx": "^0.21.12",
77
- "bunfig": "^0.8.5",
78
- "tinyglobby": "^0.2.13",
79
- "unocss": "^66.1.1"
68
+ "bunfig": "^0.10.0",
69
+ "tinyglobby": "^0.2.13"
80
70
  },
81
- "overrides": {
82
- "unconfig": "0.3.10"
83
- },
84
- "simple-git-hooks": {
85
- "pre-commit": "bunx lint-staged"
86
- },
87
- "lint-staged": {
88
- "*.{js,ts}": "bunx eslint . --fix"
71
+ "git-hooks": {
72
+ "pre-commit": {
73
+ "staged-lint": {
74
+ "*.{js,ts,json,yaml,yml,md}": "bunx --bun eslint . --fix"
75
+ }
76
+ }
89
77
  }
90
78
  }
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- # MIT License
2
-
3
- Copyright (c) 2024 Open Web Foundation
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,192 +0,0 @@
1
- <p align="center"><img src="https://github.com/stacksjs/dtsx/blob/main/.github/art/cover.jpg?raw=true" alt="Social Card of this repo"></p>
2
-
3
- [![npm version][npm-version-src]][npm-version-href]
4
- [![GitHub Actions][github-actions-src]][github-actions-href]
5
- [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
6
- <!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
7
- <!-- [![Codecov][codecov-src]][codecov-href] -->
8
-
9
- # dtsx
10
-
11
- > A library that helps you generate TypeScript declaration files from your project. Given we do not know the user's input ever, we need to never hardcode based results based from our examples, always create a dynamic solution.
12
-
13
- ## Features
14
-
15
- - ⚡ Extremely fast .d.ts generation
16
- - ⚙️ Highly configurable
17
- - 🪶 Lightweight library
18
- - 🤖 Cross-platform binary
19
-
20
- ## Install
21
-
22
- ```bash
23
- bun install -d @stacksjs/dtsx
24
- ```
25
-
26
- <_@npmjs.com>, please allow us to use the `dtsx` package name 🙏_
27
-
28
- <!-- _Alternatively, you can install:_
29
-
30
- ```bash
31
- brew install dtsx # wip
32
- pkgx install dtsx # wip
33
- ``` -->
34
-
35
- ## Get Started
36
-
37
- There are two ways of using this ".d.ts generation" tool: _as a library or as a CLI._
38
-
39
- _But before you get started, please ensure you enabled `isolatedDeclarations` in your `tsconfig.json` file._
40
-
41
- ```json
42
- {
43
- "compilerOptions": {
44
- "isolatedDeclarations": true
45
- }
46
- }
47
- ```
48
-
49
- ## Library
50
-
51
- Given the npm package is installed, you can use the `generate` function to generate TypeScript declaration files from your project.
52
-
53
- ### Usage
54
-
55
- ```ts
56
- import type { DtsGenerationOptions } from '@stacksjs/dtsx'
57
- import { generate } from '@stacksjs/dtsx'
58
-
59
- const options: DtsGenerationOptions = {
60
- cwd: './', // default: process.cwd()
61
- root: './src', // default: './src'
62
- entrypoints: ['**/*.ts'], // default: ['**/*.ts']
63
- outdir: './dist', // default: './dist'
64
- clean: true, // default: false
65
- verbose: true, // default: false
66
- // keepComments: true, // coming soon
67
- }
68
-
69
- await generate(options)
70
- ```
71
-
72
- _Available options:_
73
-
74
- Library usage can also be configured using a `dts.config.ts` _(or `dts.config.js`)_ file which is automatically loaded when running the `./dtsx` _(or `bunx dtsx`)_ command. It is also loaded when the `generate` function is called, unless custom options are provided.
75
-
76
- ```ts
77
- // dts.config.ts (or dts.config.js)
78
-
79
- export default {
80
- cwd: './',
81
- root: './src',
82
- entrypoints: ['**/*.ts'],
83
- outdir: './dist',
84
- keepComments: true,
85
- clean: true,
86
- verbose: true,
87
- }
88
- ```
89
-
90
- _You may also run:_
91
-
92
- ```bash
93
- ./dtsx generate
94
-
95
- # if the package is installed, you can also run:
96
- # bunx dtsx generate
97
- ```
98
-
99
- ## CLI
100
-
101
- The `dtsx` CLI provides a simple way to generate TypeScript declaration files from your project. Here's how to use it:
102
-
103
- ### Usage
104
-
105
- Generate declaration files using the default options:
106
-
107
- ```bash
108
- dtsx generate
109
- ```
110
-
111
- _Or use custom options:_
112
-
113
- ```bash
114
- # Generate declarations for specific entry points:
115
- dtsx generate --entrypoints src/index.ts,src/utils.ts --outdir dist/types
116
-
117
- # Generate declarations with custom configuration:
118
- dtsx generate --root ./lib --outdir ./types --clean
119
-
120
- dtsx --help
121
- dtsx --version
122
- ```
123
-
124
- _Available options:_
125
-
126
- - `--cwd <path>`: Set the current working directory _(default: current directory)_
127
- - `--root <path>`: Specify the root directory of the project _(default: './src')_
128
- - `--entrypoints <files>`: Define entry point files _(comma-separated, default: '**/*.ts')_
129
- - `--outdir <path>`: Set the output directory for generated .d.ts files _(default: './dist')_
130
- - `--keep-comments`: Keep comments in generated .d.ts files _(default: true)_
131
- - `--clean`: Clean output directory before generation _(default: false)_
132
- - `--tsconfig <path>`: Specify the path to tsconfig.json _(default: 'tsconfig.json')_
133
- - `--verbose`: Enable verbose output _(default: false)_
134
-
135
- To learn more, head over to the [documentation](https://dtsx.stacksjs.org/).
136
-
137
- ## Testing
138
-
139
- ```bash
140
- bun test
141
- ```
142
-
143
- ## Changelog
144
-
145
- Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
146
-
147
- ## Contributing
148
-
149
- Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
150
-
151
- ## Community
152
-
153
- For help, discussion about best practices, or any other conversation that would benefit from being searchable:
154
-
155
- [Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
156
-
157
- For casual chit-chat with others using this package:
158
-
159
- [Join the Stacks Discord Server](https://discord.gg/stacksjs)
160
-
161
- ## Postcardware
162
-
163
- “Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where `dtsx` is being used! We showcase them on our website too.
164
-
165
- Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
166
-
167
- ## Sponsors
168
-
169
- We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
170
-
171
- - [JetBrains](https://www.jetbrains.com/)
172
- - [The Solana Foundation](https://solana.com/)
173
-
174
- ## Credits
175
-
176
- - [Chris Breuer](https://github.com/chrisbbreuer)
177
- - [All Contributors](../../contributors)
178
-
179
- ## License
180
-
181
- The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/dtsx/tree/main/LICENSE.md) for more information.
182
-
183
- Made with 💙
184
-
185
- <!-- Badges -->
186
- [npm-version-src]: https://img.shields.io/npm/v/@stacksjs/dtsx?style=flat-square
187
- [npm-version-href]: https://npmjs.com/package/@stacksjs/dtsx
188
- [github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/dtsx/ci.yml?style=flat-square&branch=main
189
- [github-actions-href]: https://github.com/stacksjs/dtsx/actions?query=workflow%3Aci
190
-
191
- <!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/dtsx/main?style=flat-square
192
- [codecov-href]: https://codecov.io/gh/stacksjs/dtsx -->