@getkist/action-typescript 0.0.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/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.d.ts +112 -0
- package/dist/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.d.ts.map +1 -0
- package/dist/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.js +151 -0
- package/dist/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.js.map +1 -0
- package/dist/actions/TypeScriptCompilerAction/index.d.ts +7 -0
- package/dist/actions/TypeScriptCompilerAction/index.d.ts.map +1 -0
- package/dist/actions/TypeScriptCompilerAction/index.js +9 -0
- package/dist/actions/TypeScriptCompilerAction/index.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 kist
|
|
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
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# @kist/action-typescript
|
|
2
|
+
|
|
3
|
+
TypeScript compilation actions for [kist](https://github.com/getkist/kist) build tool.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@kist/action-typescript)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **TypeScript Compilation** - Full TypeScript compiler integration
|
|
11
|
+
- **Custom tsconfig** - Use any tsconfig.json configuration
|
|
12
|
+
- **Flexible File Selection** - Compile specific files or entire projects
|
|
13
|
+
- **Compiler Options Override** - Runtime compiler option customization
|
|
14
|
+
- **Error Reporting** - Detailed compilation diagnostics
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install --save-dev @kist/action-typescript
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Basic Compilation
|
|
25
|
+
|
|
26
|
+
Add to your `kist.yml`:
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
pipeline:
|
|
30
|
+
stages:
|
|
31
|
+
- name: compile
|
|
32
|
+
steps:
|
|
33
|
+
- name: compile-typescript
|
|
34
|
+
action: TypeScriptCompilerAction
|
|
35
|
+
options:
|
|
36
|
+
tsconfigPath: ./tsconfig.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Compile Specific Files
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
pipeline:
|
|
43
|
+
stages:
|
|
44
|
+
- name: compile
|
|
45
|
+
steps:
|
|
46
|
+
- name: compile-sources
|
|
47
|
+
action: TypeScriptCompilerAction
|
|
48
|
+
options:
|
|
49
|
+
tsconfigPath: ./tsconfig.json
|
|
50
|
+
filePaths:
|
|
51
|
+
- src/index.ts
|
|
52
|
+
- src/utils.ts
|
|
53
|
+
outputDir: ./dist
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Custom Compiler Options
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
pipeline:
|
|
60
|
+
stages:
|
|
61
|
+
- name: compile
|
|
62
|
+
steps:
|
|
63
|
+
- name: compile-custom
|
|
64
|
+
action: TypeScriptCompilerAction
|
|
65
|
+
options:
|
|
66
|
+
tsconfigPath: ./tsconfig.json
|
|
67
|
+
outputDir: ./build
|
|
68
|
+
compilerOptions:
|
|
69
|
+
target: ES2020
|
|
70
|
+
module: CommonJS
|
|
71
|
+
sourceMap: true
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Action: TypeScriptCompilerAction
|
|
75
|
+
|
|
76
|
+
Compiles TypeScript files using the TypeScript compiler.
|
|
77
|
+
|
|
78
|
+
### Options
|
|
79
|
+
|
|
80
|
+
| Option | Type | Required | Description |
|
|
81
|
+
| ----------------- | -------- | -------- | ---------------------------------------------------- |
|
|
82
|
+
| `tsconfigPath` | string | No | Path to tsconfig.json (default: "tsconfig.json") |
|
|
83
|
+
| `filePaths` | string[] | No | Specific files to compile (overrides tsconfig files) |
|
|
84
|
+
| `outputDir` | string | No | Output directory (overrides tsconfig outDir) |
|
|
85
|
+
| `compilerOptions` | object | No | Custom compiler options to merge with tsconfig |
|
|
86
|
+
|
|
87
|
+
### Compiler Options
|
|
88
|
+
|
|
89
|
+
Any valid TypeScript compiler option can be passed:
|
|
90
|
+
|
|
91
|
+
```yaml
|
|
92
|
+
compilerOptions:
|
|
93
|
+
target: ES2020
|
|
94
|
+
module: ESNext
|
|
95
|
+
declaration: true
|
|
96
|
+
sourceMap: true
|
|
97
|
+
strict: true
|
|
98
|
+
esModuleInterop: true
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Examples
|
|
102
|
+
|
|
103
|
+
### Multi-Target Compilation
|
|
104
|
+
|
|
105
|
+
```yaml
|
|
106
|
+
pipeline:
|
|
107
|
+
stages:
|
|
108
|
+
- name: compile-all
|
|
109
|
+
steps:
|
|
110
|
+
- name: compile-esm
|
|
111
|
+
action: TypeScriptCompilerAction
|
|
112
|
+
options:
|
|
113
|
+
tsconfigPath: ./tsconfig.json
|
|
114
|
+
outputDir: ./dist/esm
|
|
115
|
+
compilerOptions:
|
|
116
|
+
module: ESNext
|
|
117
|
+
|
|
118
|
+
- name: compile-cjs
|
|
119
|
+
action: TypeScriptCompilerAction
|
|
120
|
+
options:
|
|
121
|
+
tsconfigPath: ./tsconfig.json
|
|
122
|
+
outputDir: ./dist/cjs
|
|
123
|
+
compilerOptions:
|
|
124
|
+
module: CommonJS
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Development vs Production
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
pipeline:
|
|
131
|
+
stages:
|
|
132
|
+
- name: dev-build
|
|
133
|
+
steps:
|
|
134
|
+
- name: compile-dev
|
|
135
|
+
action: TypeScriptCompilerAction
|
|
136
|
+
options:
|
|
137
|
+
tsconfigPath: ./tsconfig.json
|
|
138
|
+
compilerOptions:
|
|
139
|
+
sourceMap: true
|
|
140
|
+
declaration: false
|
|
141
|
+
|
|
142
|
+
- name: prod-build
|
|
143
|
+
steps:
|
|
144
|
+
- name: compile-prod
|
|
145
|
+
action: TypeScriptCompilerAction
|
|
146
|
+
options:
|
|
147
|
+
tsconfigPath: ./tsconfig.json
|
|
148
|
+
compilerOptions:
|
|
149
|
+
sourceMap: false
|
|
150
|
+
declaration: true
|
|
151
|
+
removeComments: true
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## TypeScript Types
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { TypeScriptCompilerAction } from "@kist/action-typescript";
|
|
158
|
+
|
|
159
|
+
const action = new TypeScriptCompilerAction();
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### TypeScriptCompilerActionOptions
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
interface TypeScriptCompilerActionOptions {
|
|
166
|
+
tsconfigPath?: string;
|
|
167
|
+
filePaths?: string[];
|
|
168
|
+
outputDir?: string;
|
|
169
|
+
compilerOptions?: Record<string, any>;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Error Handling
|
|
174
|
+
|
|
175
|
+
The action provides detailed error messages for:
|
|
176
|
+
|
|
177
|
+
- Invalid tsconfig.json files
|
|
178
|
+
- Compilation errors with file locations
|
|
179
|
+
- Pre-emit diagnostics
|
|
180
|
+
- Configuration parsing errors
|
|
181
|
+
|
|
182
|
+
## Requirements
|
|
183
|
+
|
|
184
|
+
- Node.js >= 18.0.0
|
|
185
|
+
- kist >= 0.1.0
|
|
186
|
+
- TypeScript >= 5.0.0
|
|
187
|
+
|
|
188
|
+
## Contributing
|
|
189
|
+
|
|
190
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT © kist
|
|
195
|
+
|
|
196
|
+
## Links
|
|
197
|
+
|
|
198
|
+
- [GitHub Repository](https://github.com/getkist/action-typescript)
|
|
199
|
+
- [npm Package](https://www.npmjs.com/package/@kist/action-typescript)
|
|
200
|
+
- [kist Build Tool](https://github.com/getkist/kist)
|
|
201
|
+
- [Issue Tracker](https://github.com/getkist/action-typescript/issues)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module TypeScriptCompilerAction
|
|
3
|
+
* @description TypeScript compilation action for the Kist build system
|
|
4
|
+
*
|
|
5
|
+
* This module provides a Kist action that compiles TypeScript files to JavaScript
|
|
6
|
+
* using the TypeScript compiler. It supports loading tsconfig.json configurations,
|
|
7
|
+
* custom compiler options, and output directory configuration.
|
|
8
|
+
*/
|
|
9
|
+
import type { ActionOptionsType } from "kist";
|
|
10
|
+
import { Action } from "kist";
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for the TypeScript compiler action.
|
|
13
|
+
*
|
|
14
|
+
* @interface TypeScriptCompilerActionOptions
|
|
15
|
+
* @extends {ActionOptionsType}
|
|
16
|
+
*
|
|
17
|
+
* @property {string} [tsconfigPath="tsconfig.json"] - Path to the tsconfig.json file.
|
|
18
|
+
* If not provided, defaults to "tsconfig.json" in the current directory.
|
|
19
|
+
* @property {string[]} [filePaths] - Optional array of file paths to compile.
|
|
20
|
+
* If provided, overrides the files specified in tsconfig.json.
|
|
21
|
+
* @property {string} [outputDir] - Optional output directory for compiled JavaScript files.
|
|
22
|
+
* Overrides the outDir specified in tsconfig.json if provided.
|
|
23
|
+
* @property {Record<string, any>} [compilerOptions] - Optional additional compiler options
|
|
24
|
+
* to merge with those from tsconfig.json. Takes precedence over tsconfig options.
|
|
25
|
+
*/
|
|
26
|
+
export interface TypeScriptCompilerActionOptions extends ActionOptionsType {
|
|
27
|
+
tsconfigPath?: string;
|
|
28
|
+
filePaths?: string[];
|
|
29
|
+
outputDir?: string;
|
|
30
|
+
compilerOptions?: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* TypeScript Compiler Action for the Kist build system.
|
|
34
|
+
*
|
|
35
|
+
* This action compiles TypeScript source files to JavaScript using the TypeScript compiler.
|
|
36
|
+
* It handles:
|
|
37
|
+
* - Loading and parsing tsconfig.json configurations
|
|
38
|
+
* - Merging custom compiler options
|
|
39
|
+
* - Handling compilation diagnostics and errors
|
|
40
|
+
* - Logging compilation progress and results
|
|
41
|
+
*
|
|
42
|
+
* @class TypeScriptCompilerAction
|
|
43
|
+
* @extends {Action}
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const action = new TypeScriptCompilerAction();
|
|
47
|
+
* await action.execute({
|
|
48
|
+
* tsconfigPath: 'tsconfig.json',
|
|
49
|
+
* compilerOptions: { declaration: true },
|
|
50
|
+
* outputDir: 'dist'
|
|
51
|
+
* });
|
|
52
|
+
*/
|
|
53
|
+
export declare class TypeScriptCompilerAction extends Action {
|
|
54
|
+
/**
|
|
55
|
+
* Executes the TypeScript compilation process.
|
|
56
|
+
*
|
|
57
|
+
* This method:
|
|
58
|
+
* 1. Loads and parses the tsconfig.json file
|
|
59
|
+
* 2. Merges custom compiler options (if provided)
|
|
60
|
+
* 3. Creates a TypeScript program with the final options
|
|
61
|
+
* 4. Emits compiled JavaScript files
|
|
62
|
+
* 5. Collects and reports any compilation diagnostics
|
|
63
|
+
*
|
|
64
|
+
* @async
|
|
65
|
+
* @param {TypeScriptCompilerActionOptions} options - Configuration for compilation
|
|
66
|
+
* @returns {Promise<void>} Resolves when compilation is completed successfully.
|
|
67
|
+
* @throws {Error} Throws an error if compilation fails with details about the failure.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* await action.execute({
|
|
71
|
+
* tsconfigPath: './tsconfig.json',
|
|
72
|
+
* outputDir: './build',
|
|
73
|
+
* compilerOptions: { sourceMap: true }
|
|
74
|
+
* });
|
|
75
|
+
*/
|
|
76
|
+
execute(options: TypeScriptCompilerActionOptions): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Loads and parses a tsconfig.json file with proper error handling.
|
|
79
|
+
*
|
|
80
|
+
* This method:
|
|
81
|
+
* 1. Reads the tsconfig.json file from disk
|
|
82
|
+
* 2. Parses the JSON content
|
|
83
|
+
* 3. Validates the configuration against TypeScript's schema
|
|
84
|
+
* 4. Resolves relative paths based on the tsconfig directory
|
|
85
|
+
*
|
|
86
|
+
* @private
|
|
87
|
+
* @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.
|
|
88
|
+
* @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler
|
|
89
|
+
* options and file names to compile.
|
|
90
|
+
* @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* const config = this.loadAndParseTsConfig('./tsconfig.json');
|
|
94
|
+
* console.log(config.options.target); // 'ES2020' or similar
|
|
95
|
+
*/
|
|
96
|
+
private loadAndParseTsConfig;
|
|
97
|
+
/**
|
|
98
|
+
* Provides a human-readable description of this action.
|
|
99
|
+
*
|
|
100
|
+
* This method is used by the Kist build system to display information about
|
|
101
|
+
* what this action does in logs and documentation.
|
|
102
|
+
*
|
|
103
|
+
* @returns {string} A description of the TypeScript compilation action.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const action = new TypeScriptCompilerAction();
|
|
107
|
+
* console.log(action.describe());
|
|
108
|
+
* // Output: "Compiles TypeScript files using a given tsconfig.json configuration."
|
|
109
|
+
*/
|
|
110
|
+
describe(): string;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=TypeScriptCompilerAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptCompilerAction.d.ts","sourceRoot":"","sources":["../../../src/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAQ9B;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,+BAAgC,SAAQ,iBAAiB;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC;AAMD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,wBAAyB,SAAQ,MAAM;IAChD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,OAAO,CAAC,OAAO,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC;IA8EtE;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,oBAAoB;IAiC5B;;;;;;;;;;;;OAYG;IACH,QAAQ,IAAI,MAAM;CAGrB"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module TypeScriptCompilerAction
|
|
3
|
+
* @description TypeScript compilation action for the Kist build system
|
|
4
|
+
*
|
|
5
|
+
* This module provides a Kist action that compiles TypeScript files to JavaScript
|
|
6
|
+
* using the TypeScript compiler. It supports loading tsconfig.json configurations,
|
|
7
|
+
* custom compiler options, and output directory configuration.
|
|
8
|
+
*/
|
|
9
|
+
import { Action } from "kist";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import ts from "typescript";
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Classes
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* TypeScript Compiler Action for the Kist build system.
|
|
17
|
+
*
|
|
18
|
+
* This action compiles TypeScript source files to JavaScript using the TypeScript compiler.
|
|
19
|
+
* It handles:
|
|
20
|
+
* - Loading and parsing tsconfig.json configurations
|
|
21
|
+
* - Merging custom compiler options
|
|
22
|
+
* - Handling compilation diagnostics and errors
|
|
23
|
+
* - Logging compilation progress and results
|
|
24
|
+
*
|
|
25
|
+
* @class TypeScriptCompilerAction
|
|
26
|
+
* @extends {Action}
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const action = new TypeScriptCompilerAction();
|
|
30
|
+
* await action.execute({
|
|
31
|
+
* tsconfigPath: 'tsconfig.json',
|
|
32
|
+
* compilerOptions: { declaration: true },
|
|
33
|
+
* outputDir: 'dist'
|
|
34
|
+
* });
|
|
35
|
+
*/
|
|
36
|
+
export class TypeScriptCompilerAction extends Action {
|
|
37
|
+
/**
|
|
38
|
+
* Executes the TypeScript compilation process.
|
|
39
|
+
*
|
|
40
|
+
* This method:
|
|
41
|
+
* 1. Loads and parses the tsconfig.json file
|
|
42
|
+
* 2. Merges custom compiler options (if provided)
|
|
43
|
+
* 3. Creates a TypeScript program with the final options
|
|
44
|
+
* 4. Emits compiled JavaScript files
|
|
45
|
+
* 5. Collects and reports any compilation diagnostics
|
|
46
|
+
*
|
|
47
|
+
* @async
|
|
48
|
+
* @param {TypeScriptCompilerActionOptions} options - Configuration for compilation
|
|
49
|
+
* @returns {Promise<void>} Resolves when compilation is completed successfully.
|
|
50
|
+
* @throws {Error} Throws an error if compilation fails with details about the failure.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* await action.execute({
|
|
54
|
+
* tsconfigPath: './tsconfig.json',
|
|
55
|
+
* outputDir: './build',
|
|
56
|
+
* compilerOptions: { sourceMap: true }
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
async execute(options) {
|
|
60
|
+
const { tsconfigPath = "tsconfig.json", filePaths, outputDir, compilerOptions = {}, } = options;
|
|
61
|
+
const resolvedTsconfigPath = path.resolve(tsconfigPath);
|
|
62
|
+
this.logInfo(`Compiling TypeScript using configuration: ${resolvedTsconfigPath}`);
|
|
63
|
+
try {
|
|
64
|
+
// **Properly Parse tsconfig.json**
|
|
65
|
+
const parsedConfig = this.loadAndParseTsConfig(resolvedTsconfigPath);
|
|
66
|
+
// Merge custom compiler options
|
|
67
|
+
const mergedCompilerOptions = ts.convertCompilerOptionsFromJson(compilerOptions, path.dirname(resolvedTsconfigPath)).options;
|
|
68
|
+
const finalCompilerOptions = {
|
|
69
|
+
...parsedConfig.options,
|
|
70
|
+
...mergedCompilerOptions,
|
|
71
|
+
};
|
|
72
|
+
// Set output directory if specified
|
|
73
|
+
if (outputDir) {
|
|
74
|
+
finalCompilerOptions.outDir = outputDir;
|
|
75
|
+
}
|
|
76
|
+
// **Create a TypeScript Program**
|
|
77
|
+
const program = ts.createProgram(filePaths ?? parsedConfig.fileNames, finalCompilerOptions);
|
|
78
|
+
const emitResult = program.emit();
|
|
79
|
+
// **Collect Diagnostics**
|
|
80
|
+
const allDiagnostics = ts
|
|
81
|
+
.getPreEmitDiagnostics(program)
|
|
82
|
+
.concat(emitResult.diagnostics);
|
|
83
|
+
if (allDiagnostics.length > 0) {
|
|
84
|
+
const diagnosticMessages = allDiagnostics
|
|
85
|
+
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"))
|
|
86
|
+
.join("\n");
|
|
87
|
+
allDiagnostics.forEach((diagnostic) => {
|
|
88
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
89
|
+
this.logError(`TypeScript Error: ${message}`);
|
|
90
|
+
});
|
|
91
|
+
throw new Error(`TypeScript compilation failed: ${diagnosticMessages}`);
|
|
92
|
+
}
|
|
93
|
+
this.logInfo("TypeScript compilation completed successfully.");
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
this.logError("Error during TypeScript compilation:", error);
|
|
97
|
+
throw new Error(`TypeScript compilation failed: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Loads and parses a tsconfig.json file with proper error handling.
|
|
102
|
+
*
|
|
103
|
+
* This method:
|
|
104
|
+
* 1. Reads the tsconfig.json file from disk
|
|
105
|
+
* 2. Parses the JSON content
|
|
106
|
+
* 3. Validates the configuration against TypeScript's schema
|
|
107
|
+
* 4. Resolves relative paths based on the tsconfig directory
|
|
108
|
+
*
|
|
109
|
+
* @private
|
|
110
|
+
* @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.
|
|
111
|
+
* @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler
|
|
112
|
+
* options and file names to compile.
|
|
113
|
+
* @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const config = this.loadAndParseTsConfig('./tsconfig.json');
|
|
117
|
+
* console.log(config.options.target); // 'ES2020' or similar
|
|
118
|
+
*/
|
|
119
|
+
loadAndParseTsConfig(tsconfigPath) {
|
|
120
|
+
// **Read and Parse tsconfig.json**
|
|
121
|
+
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
122
|
+
if (configFile.error) {
|
|
123
|
+
throw new Error(`Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`);
|
|
124
|
+
}
|
|
125
|
+
// **Parse the configuration content**
|
|
126
|
+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(tsconfigPath));
|
|
127
|
+
if (parsedConfig.errors.length > 0) {
|
|
128
|
+
throw new Error(`Error parsing tsconfig.json: ${parsedConfig.errors
|
|
129
|
+
.map((diag) => ts.flattenDiagnosticMessageText(diag.messageText, "\n"))
|
|
130
|
+
.join("\n")}`);
|
|
131
|
+
}
|
|
132
|
+
return parsedConfig;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Provides a human-readable description of this action.
|
|
136
|
+
*
|
|
137
|
+
* This method is used by the Kist build system to display information about
|
|
138
|
+
* what this action does in logs and documentation.
|
|
139
|
+
*
|
|
140
|
+
* @returns {string} A description of the TypeScript compilation action.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const action = new TypeScriptCompilerAction();
|
|
144
|
+
* console.log(action.describe());
|
|
145
|
+
* // Output: "Compiles TypeScript files using a given tsconfig.json configuration."
|
|
146
|
+
*/
|
|
147
|
+
describe() {
|
|
148
|
+
return "Compiles TypeScript files using a given tsconfig.json configuration.";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=TypeScriptCompilerAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptCompilerAction.js","sourceRoot":"","sources":["../../../src/actions/TypeScriptCompilerAction/TypeScri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C,WAAW,EAAE,IAAI,CAAC,EAAE,CACxG,CAAC;QACN,CAAC;QAED,sCAAsC;QACtC,MAAM,YAAY,GAAG,EAAE,CAAC,0BAA0B,CAC9C,UAAU,CAAC,MAAM,EACjB,EAAE,CAAC,GAAG,EACN,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAC7B,CAAC;QAEF,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACX,gCAAgC,YAAY,CAAC,MAAM;iBAC9C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACV,EAAE,CAAC,4BAA4B,CAC3B,IAAI,CAAC,WAAW,EAChB,IAAI,CACP,CACJ;iBACA,IAAI,CAAC,IAAI,CAAC,EAAE,CACpB,CAAC;QACN,CAAC;QAED,OAAO,YAAY,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,QAAQ;QACJ,OAAO,sEAAsE,CAAC;IAClF,CAAC;CACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module TypeScriptCompilerAction
|
|
3
|
+
* @description Exports the TypeScript compiler action and its configuration types
|
|
4
|
+
*/
|
|
5
|
+
export { TypeScriptCompilerAction } from "./TypeScriptCompilerAction.js";
|
|
6
|
+
export type { TypeScriptCompilerActionOptions } from "./TypeScriptCompilerAction.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/TypeScriptCompilerAction/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module TypeScriptCompilerAction
|
|
3
|
+
* @description Exports the TypeScript compiler action and its configuration types
|
|
4
|
+
*/
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Export
|
|
7
|
+
// ============================================================================
|
|
8
|
+
export { TypeScriptCompilerAction } from "./TypeScriptCompilerAction.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/actions/TypeScriptCompilerAction/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @kist/action-typescript
|
|
3
|
+
* @description TypeScript compilation plugin for the Kist build tool
|
|
4
|
+
*
|
|
5
|
+
* This module provides TypeScript compilation capabilities as a Kist action plugin.
|
|
6
|
+
* It handles tsconfig.json parsing and TypeScript compilation with support for
|
|
7
|
+
* custom compiler options and output directory configuration.
|
|
8
|
+
*/
|
|
9
|
+
export { TypeScriptCompilerAction } from "./actions/TypeScriptCompilerAction/index.js";
|
|
10
|
+
export type { TypeScriptCompilerActionOptions } from "./actions/TypeScriptCompilerAction/index.js";
|
|
11
|
+
import { ActionPlugin } from "kist";
|
|
12
|
+
/**
|
|
13
|
+
* Kist plugin for TypeScript compilation.
|
|
14
|
+
*
|
|
15
|
+
* This plugin provides the TypeScriptCompilerAction which compiles TypeScript files
|
|
16
|
+
* using the TypeScript compiler with support for tsconfig.json configurations.
|
|
17
|
+
*
|
|
18
|
+
* @type {ActionPlugin}
|
|
19
|
+
*/
|
|
20
|
+
declare const plugin: ActionPlugin;
|
|
21
|
+
export default plugin;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,YAAY,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAMnG,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAGpC;;;;;;;GAOG;AACH,QAAA,MAAM,MAAM,EAAE,YASb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @kist/action-typescript
|
|
3
|
+
* @description TypeScript compilation plugin for the Kist build tool
|
|
4
|
+
*
|
|
5
|
+
* This module provides TypeScript compilation capabilities as a Kist action plugin.
|
|
6
|
+
* It handles tsconfig.json parsing and TypeScript compilation with support for
|
|
7
|
+
* custom compiler options and output directory configuration.
|
|
8
|
+
*/
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Export
|
|
11
|
+
// ============================================================================
|
|
12
|
+
export { TypeScriptCompilerAction } from "./actions/TypeScriptCompilerAction/index.js";
|
|
13
|
+
import { TypeScriptCompilerAction } from "./actions/TypeScriptCompilerAction/index.js";
|
|
14
|
+
/**
|
|
15
|
+
* Kist plugin for TypeScript compilation.
|
|
16
|
+
*
|
|
17
|
+
* This plugin provides the TypeScriptCompilerAction which compiles TypeScript files
|
|
18
|
+
* using the TypeScript compiler with support for tsconfig.json configurations.
|
|
19
|
+
*
|
|
20
|
+
* @type {ActionPlugin}
|
|
21
|
+
*/
|
|
22
|
+
const plugin = {
|
|
23
|
+
version: "1.0.0",
|
|
24
|
+
description: "TypeScript compilation actions for kist",
|
|
25
|
+
author: "kist",
|
|
26
|
+
repository: "https://github.com/getkist/action-typescript",
|
|
27
|
+
keywords: ["kist", "kist-action", "typescript", "compiler", "tsc"],
|
|
28
|
+
registerActions: () => ({
|
|
29
|
+
TypeScriptCompilerAction,
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
export default plugin;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAQvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF;;;;;;;GAOG;AACH,MAAM,MAAM,GAAiB;IACzB,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,yCAAyC;IACtD,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,8CAA8C;IAC1D,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,CAAC;IAClE,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;QACpB,wBAAwB;KAC3B,CAAC;CACL,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getkist/action-typescript",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "TypeScript compilation actions for kist build tool",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"kist",
|
|
10
|
+
"kist-action",
|
|
11
|
+
"typescript",
|
|
12
|
+
"compiler",
|
|
13
|
+
"tsc",
|
|
14
|
+
"transpilation"
|
|
15
|
+
],
|
|
16
|
+
"author": "kist",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/getkist/action-typescript.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/getkist/action-typescript/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/getkist/action-typescript#readme",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.0.0",
|
|
28
|
+
"npm": ">=9.0.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"build:watch": "tsc --watch",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"test:watch": "jest --watch",
|
|
35
|
+
"test:coverage": "jest --coverage",
|
|
36
|
+
"test:unit": "jest --testPathPattern=\\.test\\.ts$",
|
|
37
|
+
"test:integration": "jest --testPathPattern=\\.integration\\.test\\.ts$",
|
|
38
|
+
"test:e2e": "jest --testPathPattern=e2e\\.test\\.ts$",
|
|
39
|
+
"test:coverage:enforce": "jest --coverage && jest --listTests | grep -E '\\.(test|integration|e2e)\\.ts$' | wc -l && echo 'Coverage thresholds enforced'",
|
|
40
|
+
"benchmark": "npx ts-node src/tests/benchmark.ts",
|
|
41
|
+
"lint": "eslint 'src/**/*.ts'",
|
|
42
|
+
"lint:fix": "eslint 'src/**/*.ts' --fix",
|
|
43
|
+
"format": "prettier --write 'src/**/*.ts'",
|
|
44
|
+
"clean": "rm -rf dist",
|
|
45
|
+
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"kist": "^0.1.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"typescript": "^5.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/jest": "30.0.0",
|
|
55
|
+
"@types/node": "25.0.3",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "8.50.0",
|
|
57
|
+
"@typescript-eslint/parser": "8.50.0",
|
|
58
|
+
"eslint": "9.39.2",
|
|
59
|
+
"jest": "30.2.0",
|
|
60
|
+
"kist": "^0.1.57",
|
|
61
|
+
"prettier": "^3.0.0",
|
|
62
|
+
"ts-jest": "^29.1.0"
|
|
63
|
+
},
|
|
64
|
+
"files": [
|
|
65
|
+
"dist",
|
|
66
|
+
"README.md",
|
|
67
|
+
"LICENSE"
|
|
68
|
+
]
|
|
69
|
+
}
|