@getkist/action-typescript 0.0.10 → 0.0.13
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/index.cjs +172 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{actions/TypeScriptCompilerAction/TypeScriptCompilerAction.d.ts → index.d.cts} +27 -6
- package/dist/index.d.ts +117 -5
- package/dist/index.mjs +162 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +24 -8
- package/dist/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.d.ts.map +0 -1
- package/dist/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.js +0 -152
- package/dist/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.js.map +0 -1
- package/dist/actions/TypeScriptCompilerAction/index.d.ts +0 -7
- package/dist/actions/TypeScriptCompilerAction/index.d.ts.map +0 -1
- package/dist/actions/TypeScriptCompilerAction/index.js +0 -9
- package/dist/actions/TypeScriptCompilerAction/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -33
- package/dist/index.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var kist = require('kist');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var ts = require('typescript');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
|
+
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
13
|
+
|
|
14
|
+
// src/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts
|
|
15
|
+
var TypeScriptCompilerAction = class extends kist.Action {
|
|
16
|
+
/**
|
|
17
|
+
* Executes the TypeScript compilation process.
|
|
18
|
+
*
|
|
19
|
+
* This method:
|
|
20
|
+
* 1. Loads and parses the tsconfig.json file
|
|
21
|
+
* 2. Merges custom compiler options (if provided)
|
|
22
|
+
* 3. Creates a TypeScript program with the final options
|
|
23
|
+
* 4. Emits compiled JavaScript files
|
|
24
|
+
* 5. Collects and reports any compilation diagnostics
|
|
25
|
+
*
|
|
26
|
+
* @async
|
|
27
|
+
* @param {TypeScriptCompilerActionOptions} options - Configuration for compilation
|
|
28
|
+
* @returns {Promise<void>} Resolves when compilation is completed successfully.
|
|
29
|
+
* @throws {Error} Throws an error if compilation fails with details about the failure.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* await action.execute({
|
|
33
|
+
* tsconfigPath: './tsconfig.json',
|
|
34
|
+
* outputDir: './build',
|
|
35
|
+
* compilerOptions: { sourceMap: true }
|
|
36
|
+
* });
|
|
37
|
+
*/
|
|
38
|
+
async execute(options) {
|
|
39
|
+
const {
|
|
40
|
+
tsconfigPath = "tsconfig.json",
|
|
41
|
+
filePaths,
|
|
42
|
+
outputDir,
|
|
43
|
+
compilerOptions = {}
|
|
44
|
+
} = options;
|
|
45
|
+
const resolvedTsconfigPath = path__default.default.resolve(tsconfigPath);
|
|
46
|
+
this.logInfo(
|
|
47
|
+
`Compiling TypeScript using configuration: ${resolvedTsconfigPath}`
|
|
48
|
+
);
|
|
49
|
+
try {
|
|
50
|
+
const parsedConfig = this.loadAndParseTsConfig(
|
|
51
|
+
resolvedTsconfigPath
|
|
52
|
+
);
|
|
53
|
+
const mergedCompilerOptions = ts__default.default.convertCompilerOptionsFromJson(
|
|
54
|
+
compilerOptions,
|
|
55
|
+
path__default.default.dirname(resolvedTsconfigPath)
|
|
56
|
+
).options;
|
|
57
|
+
const finalCompilerOptions = {
|
|
58
|
+
...parsedConfig.options,
|
|
59
|
+
...mergedCompilerOptions
|
|
60
|
+
};
|
|
61
|
+
if (outputDir) {
|
|
62
|
+
finalCompilerOptions.outDir = outputDir;
|
|
63
|
+
}
|
|
64
|
+
const program = ts__default.default.createProgram(
|
|
65
|
+
filePaths ?? parsedConfig.fileNames,
|
|
66
|
+
finalCompilerOptions
|
|
67
|
+
);
|
|
68
|
+
const emitResult = program.emit();
|
|
69
|
+
const allDiagnostics = ts__default.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
70
|
+
if (allDiagnostics.length > 0) {
|
|
71
|
+
const diagnosticMessages = allDiagnostics.map(
|
|
72
|
+
(diagnostic) => ts__default.default.flattenDiagnosticMessageText(
|
|
73
|
+
diagnostic.messageText,
|
|
74
|
+
"\n"
|
|
75
|
+
)
|
|
76
|
+
).join("\n");
|
|
77
|
+
allDiagnostics.forEach((diagnostic) => {
|
|
78
|
+
const message = ts__default.default.flattenDiagnosticMessageText(
|
|
79
|
+
diagnostic.messageText,
|
|
80
|
+
"\n"
|
|
81
|
+
);
|
|
82
|
+
this.logError(`TypeScript Error: ${message}`);
|
|
83
|
+
});
|
|
84
|
+
throw new Error(
|
|
85
|
+
`TypeScript compilation failed: ${diagnosticMessages}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
this.logInfo("TypeScript compilation completed successfully.");
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
91
|
+
this.logError("Error during TypeScript compilation:", error);
|
|
92
|
+
throw new Error(`TypeScript compilation failed: ${message}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Loads and parses a tsconfig.json file with proper error handling.
|
|
97
|
+
*
|
|
98
|
+
* This method:
|
|
99
|
+
* 1. Reads the tsconfig.json file from disk
|
|
100
|
+
* 2. Parses the JSON content
|
|
101
|
+
* 3. Validates the configuration against TypeScript's schema
|
|
102
|
+
* 4. Resolves relative paths based on the tsconfig directory
|
|
103
|
+
*
|
|
104
|
+
* @private
|
|
105
|
+
* @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.
|
|
106
|
+
* @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler
|
|
107
|
+
* options and file names to compile.
|
|
108
|
+
* @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const config = this.loadAndParseTsConfig('./tsconfig.json');
|
|
112
|
+
* console.log(config.options.target); // 'ES2020' or similar
|
|
113
|
+
*/
|
|
114
|
+
loadAndParseTsConfig(tsconfigPath) {
|
|
115
|
+
const configFile = ts__default.default.readConfigFile(tsconfigPath, ts__default.default.sys.readFile);
|
|
116
|
+
if (configFile.error) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Error reading tsconfig.json: ${ts__default.default.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
const parsedConfig = ts__default.default.parseJsonConfigFileContent(
|
|
122
|
+
configFile.config,
|
|
123
|
+
ts__default.default.sys,
|
|
124
|
+
path__default.default.dirname(tsconfigPath)
|
|
125
|
+
);
|
|
126
|
+
if (parsedConfig.errors.length > 0) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`Error parsing tsconfig.json: ${parsedConfig.errors.map(
|
|
129
|
+
(diag) => ts__default.default.flattenDiagnosticMessageText(
|
|
130
|
+
diag.messageText,
|
|
131
|
+
"\n"
|
|
132
|
+
)
|
|
133
|
+
).join("\n")}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return parsedConfig;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Provides a human-readable description of this action.
|
|
140
|
+
*
|
|
141
|
+
* This method is used by the Kist build system to display information about
|
|
142
|
+
* what this action does in logs and documentation.
|
|
143
|
+
*
|
|
144
|
+
* @returns {string} A description of the TypeScript compilation action.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const action = new TypeScriptCompilerAction();
|
|
148
|
+
* console.log(action.describe());
|
|
149
|
+
* // Output: "Compiles TypeScript files using a given tsconfig.json configuration."
|
|
150
|
+
*/
|
|
151
|
+
describe() {
|
|
152
|
+
return "Compiles TypeScript files using a given tsconfig.json configuration.";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/index.ts
|
|
157
|
+
var plugin = {
|
|
158
|
+
version: "1.0.0",
|
|
159
|
+
description: "TypeScript compilation actions for kist",
|
|
160
|
+
author: "kist",
|
|
161
|
+
repository: "https://github.com/getkist/kist-action-typescript",
|
|
162
|
+
keywords: ["kist", "kist-action", "typescript", "compiler", "tsc"],
|
|
163
|
+
registerActions: () => ({
|
|
164
|
+
TypeScriptCompilerAction
|
|
165
|
+
})
|
|
166
|
+
};
|
|
167
|
+
var src_default = plugin;
|
|
168
|
+
|
|
169
|
+
exports.TypeScriptCompilerAction = TypeScriptCompilerAction;
|
|
170
|
+
exports.default = src_default;
|
|
171
|
+
//# sourceMappingURL=index.cjs.map
|
|
172
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts","../src/index.ts"],"names":["Action","path","ts"],"mappings":";;;;;;;;;;;;;;AAqEO,IAAM,wBAAA,GAAN,cAAuCA,WAAA,CAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBjD,MAAM,QAAQ,OAAA,EAAyD;AACnE,IAAA,MAAM;AAAA,MACF,YAAA,GAAe,eAAA;AAAA,MACf,SAAA;AAAA,MACA,SAAA;AAAA,MACA,kBAAkB;AAAC,KACvB,GAAI,OAAA;AAEJ,IAAA,MAAM,oBAAA,GAAuBC,qBAAA,CAAK,OAAA,CAAQ,YAAY,CAAA;AAEtD,IAAA,IAAA,CAAK,OAAA;AAAA,MACD,6CAA6C,oBAAoB,CAAA;AAAA,KACrE;AAEA,IAAA,IAAI;AAEA,MAAA,MAAM,eAAe,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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,QAAA,GAAmB;AACf,IAAA,OAAO,sEAAA;AAAA,EACX;AACJ;;;ACjNA,IAAM,MAAA,GAAuB;AAAA,EACzB,OAAA,EAAS,OAAA;AAAA,EACT,WAAA,EAAa,yCAAA;AAAA,EACb,MAAA,EAAQ,MAAA;AAAA,EACR,UAAA,EAAY,mDAAA;AAAA,EACZ,UAAU,CAAC,MAAA,EAAQ,aAAA,EAAe,YAAA,EAAc,YAAY,KAAK,CAAA;AAAA,EACjE,iBAAiB,OAAO;AAAA,IACpB;AAAA,GACJ;AACJ,CAAA;AAEA,IAAO,WAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * @module TypeScriptCompilerAction\n * @description TypeScript compilation action for the Kist build system\n *\n * This module provides a Kist action that compiles TypeScript files to JavaScript\n * using the TypeScript compiler. It supports loading tsconfig.json configurations,\n * custom compiler options, and output directory configuration.\n */\n\n// ============================================================================\n// Imports\n// ============================================================================\n\nimport type { ActionOptionsType } from \"kist\";\nimport { Action } from \"kist\";\nimport path from \"path\";\nimport ts from \"typescript\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Configuration options for the TypeScript compiler action.\n *\n * @interface TypeScriptCompilerActionOptions\n * @extends {ActionOptionsType}\n *\n * @property {string} [tsconfigPath=\"tsconfig.json\"] - Path to the tsconfig.json file.\n * If not provided, defaults to \"tsconfig.json\" in the current directory.\n * @property {string[]} [filePaths] - Optional array of file paths to compile.\n * If provided, overrides the files specified in tsconfig.json.\n * @property {string} [outputDir] - Optional output directory for compiled JavaScript files.\n * Overrides the outDir specified in tsconfig.json if provided.\n * @property {Record<string, any>} [compilerOptions] - Optional additional compiler options\n * to merge with those from tsconfig.json. Takes precedence over tsconfig options.\n */\nexport interface TypeScriptCompilerActionOptions extends ActionOptionsType {\n tsconfigPath?: string;\n filePaths?: string[];\n outputDir?: string;\n compilerOptions?: ts.CompilerOptions;\n}\n\n// ============================================================================\n// Classes\n// ============================================================================\n\n/**\n * TypeScript Compiler Action for the Kist build system.\n *\n * This action compiles TypeScript source files to JavaScript using the TypeScript compiler.\n * It handles:\n * - Loading and parsing tsconfig.json configurations\n * - Merging custom compiler options\n * - Handling compilation diagnostics and errors\n * - Logging compilation progress and results\n *\n * @class TypeScriptCompilerAction\n * @extends {Action}\n *\n * @example\n * const action = new TypeScriptCompilerAction();\n * await action.execute({\n * tsconfigPath: 'tsconfig.json',\n * compilerOptions: { declaration: true },\n * outputDir: 'dist'\n * });\n */\nexport class TypeScriptCompilerAction extends Action {\n /**\n * Executes the TypeScript compilation process.\n *\n * This method:\n * 1. Loads and parses the tsconfig.json file\n * 2. Merges custom compiler options (if provided)\n * 3. Creates a TypeScript program with the final options\n * 4. Emits compiled JavaScript files\n * 5. Collects and reports any compilation diagnostics\n *\n * @async\n * @param {TypeScriptCompilerActionOptions} options - Configuration for compilation\n * @returns {Promise<void>} Resolves when compilation is completed successfully.\n * @throws {Error} Throws an error if compilation fails with details about the failure.\n *\n * @example\n * await action.execute({\n * tsconfigPath: './tsconfig.json',\n * outputDir: './build',\n * compilerOptions: { sourceMap: true }\n * });\n */\n async execute(options: TypeScriptCompilerActionOptions): Promise<void> {\n const {\n tsconfigPath = \"tsconfig.json\",\n filePaths,\n outputDir,\n compilerOptions = {},\n } = options;\n\n const resolvedTsconfigPath = path.resolve(tsconfigPath);\n\n this.logInfo(\n `Compiling TypeScript using configuration: ${resolvedTsconfigPath}`,\n );\n\n try {\n // **Properly Parse tsconfig.json**\n const parsedConfig = this.loadAndParseTsConfig(\n resolvedTsconfigPath,\n );\n\n // Merge custom compiler options\n const mergedCompilerOptions = ts.convertCompilerOptionsFromJson(\n compilerOptions,\n path.dirname(resolvedTsconfigPath),\n ).options;\n\n const finalCompilerOptions = {\n ...parsedConfig.options,\n ...mergedCompilerOptions,\n };\n\n // Set output directory if specified\n if (outputDir) {\n finalCompilerOptions.outDir = outputDir;\n }\n\n // **Create a TypeScript Program**\n const program = ts.createProgram(\n filePaths ?? parsedConfig.fileNames,\n finalCompilerOptions,\n );\n\n const emitResult = program.emit();\n\n // **Collect Diagnostics**\n const allDiagnostics = ts\n .getPreEmitDiagnostics(program)\n .concat(emitResult.diagnostics);\n if (allDiagnostics.length > 0) {\n const diagnosticMessages = allDiagnostics\n .map((diagnostic) =>\n ts.flattenDiagnosticMessageText(\n diagnostic.messageText,\n \"\\n\",\n ),\n )\n .join(\"\\n\");\n\n allDiagnostics.forEach((diagnostic) => {\n const message = ts.flattenDiagnosticMessageText(\n diagnostic.messageText,\n \"\\n\",\n );\n this.logError(`TypeScript Error: ${message}`);\n });\n\n throw new Error(\n `TypeScript compilation failed: ${diagnosticMessages}`,\n );\n }\n\n this.logInfo(\"TypeScript compilation completed successfully.\");\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n this.logError(\"Error during TypeScript compilation:\", error);\n throw new Error(`TypeScript compilation failed: ${message}`);\n }\n }\n\n /**\n * Loads and parses a tsconfig.json file with proper error handling.\n *\n * This method:\n * 1. Reads the tsconfig.json file from disk\n * 2. Parses the JSON content\n * 3. Validates the configuration against TypeScript's schema\n * 4. Resolves relative paths based on the tsconfig directory\n *\n * @private\n * @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.\n * @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler\n * options and file names to compile.\n * @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.\n *\n * @example\n * const config = this.loadAndParseTsConfig('./tsconfig.json');\n * console.log(config.options.target); // 'ES2020' or similar\n */\n private loadAndParseTsConfig(tsconfigPath: string): ts.ParsedCommandLine {\n // **Read and Parse tsconfig.json**\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (configFile.error) {\n throw new Error(\n `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, \"\\n\")}`,\n );\n }\n\n // **Parse the configuration content**\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(tsconfigPath),\n );\n\n if (parsedConfig.errors.length > 0) {\n throw new Error(\n `Error parsing tsconfig.json: ${parsedConfig.errors\n .map((diag) =>\n ts.flattenDiagnosticMessageText(\n diag.messageText,\n \"\\n\",\n ),\n )\n .join(\"\\n\")}`,\n );\n }\n\n return parsedConfig;\n }\n\n /**\n * Provides a human-readable description of this action.\n *\n * This method is used by the Kist build system to display information about\n * what this action does in logs and documentation.\n *\n * @returns {string} A description of the TypeScript compilation action.\n *\n * @example\n * const action = new TypeScriptCompilerAction();\n * console.log(action.describe());\n * // Output: \"Compiles TypeScript files using a given tsconfig.json configuration.\"\n */\n describe(): string {\n return \"Compiles TypeScript files using a given tsconfig.json configuration.\";\n }\n}\n","/**\n * @module @getkist/action-typescript\n * @description TypeScript compilation plugin for the Kist build tool\n *\n * This module provides TypeScript compilation capabilities as a Kist action plugin.\n * It handles tsconfig.json parsing and TypeScript compilation with support for\n * custom compiler options and output directory configuration.\n */\n\n// ============================================================================\n// Export\n// ============================================================================\n\nexport { TypeScriptCompilerAction } from \"./actions/TypeScriptCompilerAction/index.js\";\nexport type { TypeScriptCompilerActionOptions } from \"./actions/TypeScriptCompilerAction/index.js\";\n\n// ============================================================================\n// Plugin Definition\n// ============================================================================\n\nimport { ActionPlugin } from \"kist\";\nimport { TypeScriptCompilerAction } from \"./actions/TypeScriptCompilerAction/index.js\";\n\n/**\n * Kist plugin for TypeScript compilation.\n *\n * This plugin provides the TypeScriptCompilerAction which compiles TypeScript files\n * using the TypeScript compiler with support for tsconfig.json configurations.\n *\n * @type {ActionPlugin}\n */\nconst plugin: ActionPlugin = {\n version: \"1.0.0\",\n description: \"TypeScript compilation actions for kist\",\n author: \"kist\",\n repository: \"https://github.com/getkist/kist-action-typescript\",\n keywords: [\"kist\", \"kist-action\", \"typescript\", \"compiler\", \"tsc\"],\n registerActions: () => ({\n TypeScriptCompilerAction,\n }),\n};\n\nexport default plugin;\n"]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Action, ActionOptionsType, ActionPlugin } from 'kist';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* @module TypeScriptCompilerAction
|
|
3
6
|
* @description TypeScript compilation action for the Kist build system
|
|
@@ -6,9 +9,7 @@
|
|
|
6
9
|
* using the TypeScript compiler. It supports loading tsconfig.json configurations,
|
|
7
10
|
* custom compiler options, and output directory configuration.
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
import { Action } from "kist";
|
|
11
|
-
import ts from "typescript";
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Configuration options for the TypeScript compiler action.
|
|
14
15
|
*
|
|
@@ -24,7 +25,7 @@ import ts from "typescript";
|
|
|
24
25
|
* @property {Record<string, any>} [compilerOptions] - Optional additional compiler options
|
|
25
26
|
* to merge with those from tsconfig.json. Takes precedence over tsconfig options.
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
interface TypeScriptCompilerActionOptions extends ActionOptionsType {
|
|
28
29
|
tsconfigPath?: string;
|
|
29
30
|
filePaths?: string[];
|
|
30
31
|
outputDir?: string;
|
|
@@ -51,7 +52,7 @@ export interface TypeScriptCompilerActionOptions extends ActionOptionsType {
|
|
|
51
52
|
* outputDir: 'dist'
|
|
52
53
|
* });
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
+
declare class TypeScriptCompilerAction extends Action {
|
|
55
56
|
/**
|
|
56
57
|
* Executes the TypeScript compilation process.
|
|
57
58
|
*
|
|
@@ -110,4 +111,24 @@ export declare class TypeScriptCompilerAction extends Action {
|
|
|
110
111
|
*/
|
|
111
112
|
describe(): string;
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @module @getkist/action-typescript
|
|
117
|
+
* @description TypeScript compilation plugin for the Kist build tool
|
|
118
|
+
*
|
|
119
|
+
* This module provides TypeScript compilation capabilities as a Kist action plugin.
|
|
120
|
+
* It handles tsconfig.json parsing and TypeScript compilation with support for
|
|
121
|
+
* custom compiler options and output directory configuration.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Kist plugin for TypeScript compilation.
|
|
126
|
+
*
|
|
127
|
+
* This plugin provides the TypeScriptCompilerAction which compiles TypeScript files
|
|
128
|
+
* using the TypeScript compiler with support for tsconfig.json configurations.
|
|
129
|
+
*
|
|
130
|
+
* @type {ActionPlugin}
|
|
131
|
+
*/
|
|
132
|
+
declare const plugin: ActionPlugin;
|
|
133
|
+
|
|
134
|
+
export { TypeScriptCompilerAction, type TypeScriptCompilerActionOptions, plugin as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
+
import { Action, ActionOptionsType, ActionPlugin } from 'kist';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module TypeScriptCompilerAction
|
|
6
|
+
* @description TypeScript compilation action for the Kist build system
|
|
7
|
+
*
|
|
8
|
+
* This module provides a Kist action that compiles TypeScript files to JavaScript
|
|
9
|
+
* using the TypeScript compiler. It supports loading tsconfig.json configurations,
|
|
10
|
+
* custom compiler options, and output directory configuration.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration options for the TypeScript compiler action.
|
|
15
|
+
*
|
|
16
|
+
* @interface TypeScriptCompilerActionOptions
|
|
17
|
+
* @extends {ActionOptionsType}
|
|
18
|
+
*
|
|
19
|
+
* @property {string} [tsconfigPath="tsconfig.json"] - Path to the tsconfig.json file.
|
|
20
|
+
* If not provided, defaults to "tsconfig.json" in the current directory.
|
|
21
|
+
* @property {string[]} [filePaths] - Optional array of file paths to compile.
|
|
22
|
+
* If provided, overrides the files specified in tsconfig.json.
|
|
23
|
+
* @property {string} [outputDir] - Optional output directory for compiled JavaScript files.
|
|
24
|
+
* Overrides the outDir specified in tsconfig.json if provided.
|
|
25
|
+
* @property {Record<string, any>} [compilerOptions] - Optional additional compiler options
|
|
26
|
+
* to merge with those from tsconfig.json. Takes precedence over tsconfig options.
|
|
27
|
+
*/
|
|
28
|
+
interface TypeScriptCompilerActionOptions extends ActionOptionsType {
|
|
29
|
+
tsconfigPath?: string;
|
|
30
|
+
filePaths?: string[];
|
|
31
|
+
outputDir?: string;
|
|
32
|
+
compilerOptions?: ts.CompilerOptions;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* TypeScript Compiler Action for the Kist build system.
|
|
36
|
+
*
|
|
37
|
+
* This action compiles TypeScript source files to JavaScript using the TypeScript compiler.
|
|
38
|
+
* It handles:
|
|
39
|
+
* - Loading and parsing tsconfig.json configurations
|
|
40
|
+
* - Merging custom compiler options
|
|
41
|
+
* - Handling compilation diagnostics and errors
|
|
42
|
+
* - Logging compilation progress and results
|
|
43
|
+
*
|
|
44
|
+
* @class TypeScriptCompilerAction
|
|
45
|
+
* @extends {Action}
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const action = new TypeScriptCompilerAction();
|
|
49
|
+
* await action.execute({
|
|
50
|
+
* tsconfigPath: 'tsconfig.json',
|
|
51
|
+
* compilerOptions: { declaration: true },
|
|
52
|
+
* outputDir: 'dist'
|
|
53
|
+
* });
|
|
54
|
+
*/
|
|
55
|
+
declare class TypeScriptCompilerAction extends Action {
|
|
56
|
+
/**
|
|
57
|
+
* Executes the TypeScript compilation process.
|
|
58
|
+
*
|
|
59
|
+
* This method:
|
|
60
|
+
* 1. Loads and parses the tsconfig.json file
|
|
61
|
+
* 2. Merges custom compiler options (if provided)
|
|
62
|
+
* 3. Creates a TypeScript program with the final options
|
|
63
|
+
* 4. Emits compiled JavaScript files
|
|
64
|
+
* 5. Collects and reports any compilation diagnostics
|
|
65
|
+
*
|
|
66
|
+
* @async
|
|
67
|
+
* @param {TypeScriptCompilerActionOptions} options - Configuration for compilation
|
|
68
|
+
* @returns {Promise<void>} Resolves when compilation is completed successfully.
|
|
69
|
+
* @throws {Error} Throws an error if compilation fails with details about the failure.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* await action.execute({
|
|
73
|
+
* tsconfigPath: './tsconfig.json',
|
|
74
|
+
* outputDir: './build',
|
|
75
|
+
* compilerOptions: { sourceMap: true }
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
execute(options: TypeScriptCompilerActionOptions): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Loads and parses a tsconfig.json file with proper error handling.
|
|
81
|
+
*
|
|
82
|
+
* This method:
|
|
83
|
+
* 1. Reads the tsconfig.json file from disk
|
|
84
|
+
* 2. Parses the JSON content
|
|
85
|
+
* 3. Validates the configuration against TypeScript's schema
|
|
86
|
+
* 4. Resolves relative paths based on the tsconfig directory
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
* @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.
|
|
90
|
+
* @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler
|
|
91
|
+
* options and file names to compile.
|
|
92
|
+
* @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* const config = this.loadAndParseTsConfig('./tsconfig.json');
|
|
96
|
+
* console.log(config.options.target); // 'ES2020' or similar
|
|
97
|
+
*/
|
|
98
|
+
private loadAndParseTsConfig;
|
|
99
|
+
/**
|
|
100
|
+
* Provides a human-readable description of this action.
|
|
101
|
+
*
|
|
102
|
+
* This method is used by the Kist build system to display information about
|
|
103
|
+
* what this action does in logs and documentation.
|
|
104
|
+
*
|
|
105
|
+
* @returns {string} A description of the TypeScript compilation action.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const action = new TypeScriptCompilerAction();
|
|
109
|
+
* console.log(action.describe());
|
|
110
|
+
* // Output: "Compiles TypeScript files using a given tsconfig.json configuration."
|
|
111
|
+
*/
|
|
112
|
+
describe(): string;
|
|
113
|
+
}
|
|
114
|
+
|
|
1
115
|
/**
|
|
2
116
|
* @module @getkist/action-typescript
|
|
3
117
|
* @description TypeScript compilation plugin for the Kist build tool
|
|
@@ -6,9 +120,7 @@
|
|
|
6
120
|
* It handles tsconfig.json parsing and TypeScript compilation with support for
|
|
7
121
|
* custom compiler options and output directory configuration.
|
|
8
122
|
*/
|
|
9
|
-
|
|
10
|
-
export type { TypeScriptCompilerActionOptions } from "./actions/TypeScriptCompilerAction/index.js";
|
|
11
|
-
import { ActionPlugin } from "kist";
|
|
123
|
+
|
|
12
124
|
/**
|
|
13
125
|
* Kist plugin for TypeScript compilation.
|
|
14
126
|
*
|
|
@@ -18,5 +130,5 @@ import { ActionPlugin } from "kist";
|
|
|
18
130
|
* @type {ActionPlugin}
|
|
19
131
|
*/
|
|
20
132
|
declare const plugin: ActionPlugin;
|
|
21
|
-
|
|
22
|
-
|
|
133
|
+
|
|
134
|
+
export { TypeScriptCompilerAction, type TypeScriptCompilerActionOptions, plugin as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Action } from 'kist';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
// src/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts
|
|
6
|
+
var TypeScriptCompilerAction = class extends Action {
|
|
7
|
+
/**
|
|
8
|
+
* Executes the TypeScript compilation process.
|
|
9
|
+
*
|
|
10
|
+
* This method:
|
|
11
|
+
* 1. Loads and parses the tsconfig.json file
|
|
12
|
+
* 2. Merges custom compiler options (if provided)
|
|
13
|
+
* 3. Creates a TypeScript program with the final options
|
|
14
|
+
* 4. Emits compiled JavaScript files
|
|
15
|
+
* 5. Collects and reports any compilation diagnostics
|
|
16
|
+
*
|
|
17
|
+
* @async
|
|
18
|
+
* @param {TypeScriptCompilerActionOptions} options - Configuration for compilation
|
|
19
|
+
* @returns {Promise<void>} Resolves when compilation is completed successfully.
|
|
20
|
+
* @throws {Error} Throws an error if compilation fails with details about the failure.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* await action.execute({
|
|
24
|
+
* tsconfigPath: './tsconfig.json',
|
|
25
|
+
* outputDir: './build',
|
|
26
|
+
* compilerOptions: { sourceMap: true }
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
async execute(options) {
|
|
30
|
+
const {
|
|
31
|
+
tsconfigPath = "tsconfig.json",
|
|
32
|
+
filePaths,
|
|
33
|
+
outputDir,
|
|
34
|
+
compilerOptions = {}
|
|
35
|
+
} = options;
|
|
36
|
+
const resolvedTsconfigPath = path.resolve(tsconfigPath);
|
|
37
|
+
this.logInfo(
|
|
38
|
+
`Compiling TypeScript using configuration: ${resolvedTsconfigPath}`
|
|
39
|
+
);
|
|
40
|
+
try {
|
|
41
|
+
const parsedConfig = this.loadAndParseTsConfig(
|
|
42
|
+
resolvedTsconfigPath
|
|
43
|
+
);
|
|
44
|
+
const mergedCompilerOptions = ts.convertCompilerOptionsFromJson(
|
|
45
|
+
compilerOptions,
|
|
46
|
+
path.dirname(resolvedTsconfigPath)
|
|
47
|
+
).options;
|
|
48
|
+
const finalCompilerOptions = {
|
|
49
|
+
...parsedConfig.options,
|
|
50
|
+
...mergedCompilerOptions
|
|
51
|
+
};
|
|
52
|
+
if (outputDir) {
|
|
53
|
+
finalCompilerOptions.outDir = outputDir;
|
|
54
|
+
}
|
|
55
|
+
const program = ts.createProgram(
|
|
56
|
+
filePaths ?? parsedConfig.fileNames,
|
|
57
|
+
finalCompilerOptions
|
|
58
|
+
);
|
|
59
|
+
const emitResult = program.emit();
|
|
60
|
+
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
61
|
+
if (allDiagnostics.length > 0) {
|
|
62
|
+
const diagnosticMessages = allDiagnostics.map(
|
|
63
|
+
(diagnostic) => ts.flattenDiagnosticMessageText(
|
|
64
|
+
diagnostic.messageText,
|
|
65
|
+
"\n"
|
|
66
|
+
)
|
|
67
|
+
).join("\n");
|
|
68
|
+
allDiagnostics.forEach((diagnostic) => {
|
|
69
|
+
const message = ts.flattenDiagnosticMessageText(
|
|
70
|
+
diagnostic.messageText,
|
|
71
|
+
"\n"
|
|
72
|
+
);
|
|
73
|
+
this.logError(`TypeScript Error: ${message}`);
|
|
74
|
+
});
|
|
75
|
+
throw new Error(
|
|
76
|
+
`TypeScript compilation failed: ${diagnosticMessages}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
this.logInfo("TypeScript compilation completed successfully.");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
82
|
+
this.logError("Error during TypeScript compilation:", error);
|
|
83
|
+
throw new Error(`TypeScript compilation failed: ${message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Loads and parses a tsconfig.json file with proper error handling.
|
|
88
|
+
*
|
|
89
|
+
* This method:
|
|
90
|
+
* 1. Reads the tsconfig.json file from disk
|
|
91
|
+
* 2. Parses the JSON content
|
|
92
|
+
* 3. Validates the configuration against TypeScript's schema
|
|
93
|
+
* 4. Resolves relative paths based on the tsconfig directory
|
|
94
|
+
*
|
|
95
|
+
* @private
|
|
96
|
+
* @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.
|
|
97
|
+
* @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler
|
|
98
|
+
* options and file names to compile.
|
|
99
|
+
* @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const config = this.loadAndParseTsConfig('./tsconfig.json');
|
|
103
|
+
* console.log(config.options.target); // 'ES2020' or similar
|
|
104
|
+
*/
|
|
105
|
+
loadAndParseTsConfig(tsconfigPath) {
|
|
106
|
+
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
107
|
+
if (configFile.error) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const parsedConfig = ts.parseJsonConfigFileContent(
|
|
113
|
+
configFile.config,
|
|
114
|
+
ts.sys,
|
|
115
|
+
path.dirname(tsconfigPath)
|
|
116
|
+
);
|
|
117
|
+
if (parsedConfig.errors.length > 0) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Error parsing tsconfig.json: ${parsedConfig.errors.map(
|
|
120
|
+
(diag) => ts.flattenDiagnosticMessageText(
|
|
121
|
+
diag.messageText,
|
|
122
|
+
"\n"
|
|
123
|
+
)
|
|
124
|
+
).join("\n")}`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return parsedConfig;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Provides a human-readable description of this action.
|
|
131
|
+
*
|
|
132
|
+
* This method is used by the Kist build system to display information about
|
|
133
|
+
* what this action does in logs and documentation.
|
|
134
|
+
*
|
|
135
|
+
* @returns {string} A description of the TypeScript compilation action.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* const action = new TypeScriptCompilerAction();
|
|
139
|
+
* console.log(action.describe());
|
|
140
|
+
* // Output: "Compiles TypeScript files using a given tsconfig.json configuration."
|
|
141
|
+
*/
|
|
142
|
+
describe() {
|
|
143
|
+
return "Compiles TypeScript files using a given tsconfig.json configuration.";
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/index.ts
|
|
148
|
+
var plugin = {
|
|
149
|
+
version: "1.0.0",
|
|
150
|
+
description: "TypeScript compilation actions for kist",
|
|
151
|
+
author: "kist",
|
|
152
|
+
repository: "https://github.com/getkist/kist-action-typescript",
|
|
153
|
+
keywords: ["kist", "kist-action", "typescript", "compiler", "tsc"],
|
|
154
|
+
registerActions: () => ({
|
|
155
|
+
TypeScriptCompilerAction
|
|
156
|
+
})
|
|
157
|
+
};
|
|
158
|
+
var src_default = plugin;
|
|
159
|
+
|
|
160
|
+
export { TypeScriptCompilerAction, src_default as default };
|
|
161
|
+
//# sourceMappingURL=index.mjs.map
|
|
162
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts","../src/index.ts"],"names":[],"mappings":";;;;;AAqEO,IAAM,wBAAA,GAAN,cAAuC,MAAA,CAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBjD,MAAM,QAAQ,OAAA,EAAyD;AACnE,IAAA,MAAM;AAAA,MACF,YAAA,GAAe,eAAA;AAAA,MACf,SAAA;AAAA,MACA,SAAA;AAAA,MACA,kBAAkB;AAAC,KACvB,GAAI,OAAA;AAEJ,IAAA,MAAM,oBAAA,GAAuB,IAAA,CAAK,OAAA,CAAQ,YAAY,CAAA;AAEtD,IAAA,IAAA,CAAK,OAAA;AAAA,MACD,6CAA6C,oBAAoB,CAAA;AAAA,KACrE;AAEA,IAAA,IAAI;AAEA,MAAA,MAAM,eAAe,IAAA,CAAK,oBAAA;AAAA,QACtB;AAAA,OACJ;AAGA,MAAA,MAAM,wBAAwB,EAAA,CAAG,8BAAA;AAAA,QAC7B,eAAA;AAAA,QACA,IAAA,CAAK,QAAQ,oBAAoB;AAAA,OACrC,CAAE,OAAA;AAEF,MAAA,MAAM,oBAAA,GAAuB;AAAA,QACzB,GAAG,YAAA,CAAa,OAAA;AAAA,QAChB,GAAG;AAAA,OACP;AAGA,MAAA,IAAI,SAAA,EAAW;AACX,QAAA,oBAAA,CAAqB,MAAA,GAAS,SAAA;AAAA,MAClC;AAGA,MAAA,MAAM,UAAU,EAAA,CAAG,aAAA;AAAA,QACf,aAAa,YAAA,CAAa,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js","sourcesContent":["/**\n * @module TypeScriptCompilerAction\n * @description TypeScript compilation action for the Kist build system\n *\n * This module provides a Kist action that compiles TypeScript files to JavaScript\n * using the TypeScript compiler. It supports loading tsconfig.json configurations,\n * custom compiler options, and output directory configuration.\n */\n\n// ============================================================================\n// Imports\n// ============================================================================\n\nimport type { ActionOptionsType } from \"kist\";\nimport { Action } from \"kist\";\nimport path from \"path\";\nimport ts from \"typescript\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Configuration options for the TypeScript compiler action.\n *\n * @interface TypeScriptCompilerActionOptions\n * @extends {ActionOptionsType}\n *\n * @property {string} [tsconfigPath=\"tsconfig.json\"] - Path to the tsconfig.json file.\n * If not provided, defaults to \"tsconfig.json\" in the current directory.\n * @property {string[]} [filePaths] - Optional array of file paths to compile.\n * If provided, overrides the files specified in tsconfig.json.\n * @property {string} [outputDir] - Optional output directory for compiled JavaScript files.\n * Overrides the outDir specified in tsconfig.json if provided.\n * @property {Record<string, any>} [compilerOptions] - Optional additional compiler options\n * to merge with those from tsconfig.json. Takes precedence over tsconfig options.\n */\nexport interface TypeScriptCompilerActionOptions extends ActionOptionsType {\n tsconfigPath?: string;\n filePaths?: string[];\n outputDir?: string;\n compilerOptions?: ts.CompilerOptions;\n}\n\n// ============================================================================\n// Classes\n// ============================================================================\n\n/**\n * TypeScript Compiler Action for the Kist build system.\n *\n * This action compiles TypeScript source files to JavaScript using the TypeScript compiler.\n * It handles:\n * - Loading and parsing tsconfig.json configurations\n * - Merging custom compiler options\n * - Handling compilation diagnostics and errors\n * - Logging compilation progress and results\n *\n * @class TypeScriptCompilerAction\n * @extends {Action}\n *\n * @example\n * const action = new TypeScriptCompilerAction();\n * await action.execute({\n * tsconfigPath: 'tsconfig.json',\n * compilerOptions: { declaration: true },\n * outputDir: 'dist'\n * });\n */\nexport class TypeScriptCompilerAction extends Action {\n /**\n * Executes the TypeScript compilation process.\n *\n * This method:\n * 1. Loads and parses the tsconfig.json file\n * 2. Merges custom compiler options (if provided)\n * 3. Creates a TypeScript program with the final options\n * 4. Emits compiled JavaScript files\n * 5. Collects and reports any compilation diagnostics\n *\n * @async\n * @param {TypeScriptCompilerActionOptions} options - Configuration for compilation\n * @returns {Promise<void>} Resolves when compilation is completed successfully.\n * @throws {Error} Throws an error if compilation fails with details about the failure.\n *\n * @example\n * await action.execute({\n * tsconfigPath: './tsconfig.json',\n * outputDir: './build',\n * compilerOptions: { sourceMap: true }\n * });\n */\n async execute(options: TypeScriptCompilerActionOptions): Promise<void> {\n const {\n tsconfigPath = \"tsconfig.json\",\n filePaths,\n outputDir,\n compilerOptions = {},\n } = options;\n\n const resolvedTsconfigPath = path.resolve(tsconfigPath);\n\n this.logInfo(\n `Compiling TypeScript using configuration: ${resolvedTsconfigPath}`,\n );\n\n try {\n // **Properly Parse tsconfig.json**\n const parsedConfig = this.loadAndParseTsConfig(\n resolvedTsconfigPath,\n );\n\n // Merge custom compiler options\n const mergedCompilerOptions = ts.convertCompilerOptionsFromJson(\n compilerOptions,\n path.dirname(resolvedTsconfigPath),\n ).options;\n\n const finalCompilerOptions = {\n ...parsedConfig.options,\n ...mergedCompilerOptions,\n };\n\n // Set output directory if specified\n if (outputDir) {\n finalCompilerOptions.outDir = outputDir;\n }\n\n // **Create a TypeScript Program**\n const program = ts.createProgram(\n filePaths ?? parsedConfig.fileNames,\n finalCompilerOptions,\n );\n\n const emitResult = program.emit();\n\n // **Collect Diagnostics**\n const allDiagnostics = ts\n .getPreEmitDiagnostics(program)\n .concat(emitResult.diagnostics);\n if (allDiagnostics.length > 0) {\n const diagnosticMessages = allDiagnostics\n .map((diagnostic) =>\n ts.flattenDiagnosticMessageText(\n diagnostic.messageText,\n \"\\n\",\n ),\n )\n .join(\"\\n\");\n\n allDiagnostics.forEach((diagnostic) => {\n const message = ts.flattenDiagnosticMessageText(\n diagnostic.messageText,\n \"\\n\",\n );\n this.logError(`TypeScript Error: ${message}`);\n });\n\n throw new Error(\n `TypeScript compilation failed: ${diagnosticMessages}`,\n );\n }\n\n this.logInfo(\"TypeScript compilation completed successfully.\");\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n this.logError(\"Error during TypeScript compilation:\", error);\n throw new Error(`TypeScript compilation failed: ${message}`);\n }\n }\n\n /**\n * Loads and parses a tsconfig.json file with proper error handling.\n *\n * This method:\n * 1. Reads the tsconfig.json file from disk\n * 2. Parses the JSON content\n * 3. Validates the configuration against TypeScript's schema\n * 4. Resolves relative paths based on the tsconfig directory\n *\n * @private\n * @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.\n * @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler\n * options and file names to compile.\n * @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.\n *\n * @example\n * const config = this.loadAndParseTsConfig('./tsconfig.json');\n * console.log(config.options.target); // 'ES2020' or similar\n */\n private loadAndParseTsConfig(tsconfigPath: string): ts.ParsedCommandLine {\n // **Read and Parse tsconfig.json**\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (configFile.error) {\n throw new Error(\n `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, \"\\n\")}`,\n );\n }\n\n // **Parse the configuration content**\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(tsconfigPath),\n );\n\n if (parsedConfig.errors.length > 0) {\n throw new Error(\n `Error parsing tsconfig.json: ${parsedConfig.errors\n .map((diag) =>\n ts.flattenDiagnosticMessageText(\n diag.messageText,\n \"\\n\",\n ),\n )\n .join(\"\\n\")}`,\n );\n }\n\n return parsedConfig;\n }\n\n /**\n * Provides a human-readable description of this action.\n *\n * This method is used by the Kist build system to display information about\n * what this action does in logs and documentation.\n *\n * @returns {string} A description of the TypeScript compilation action.\n *\n * @example\n * const action = new TypeScriptCompilerAction();\n * console.log(action.describe());\n * // Output: \"Compiles TypeScript files using a given tsconfig.json configuration.\"\n */\n describe(): string {\n return \"Compiles TypeScript files using a given tsconfig.json configuration.\";\n }\n}\n","/**\n * @module @getkist/action-typescript\n * @description TypeScript compilation plugin for the Kist build tool\n *\n * This module provides TypeScript compilation capabilities as a Kist action plugin.\n * It handles tsconfig.json parsing and TypeScript compilation with support for\n * custom compiler options and output directory configuration.\n */\n\n// ============================================================================\n// Export\n// ============================================================================\n\nexport { TypeScriptCompilerAction } from \"./actions/TypeScriptCompilerAction/index.js\";\nexport type { TypeScriptCompilerActionOptions } from \"./actions/TypeScriptCompilerAction/index.js\";\n\n// ============================================================================\n// Plugin Definition\n// ============================================================================\n\nimport { ActionPlugin } from \"kist\";\nimport { TypeScriptCompilerAction } from \"./actions/TypeScriptCompilerAction/index.js\";\n\n/**\n * Kist plugin for TypeScript compilation.\n *\n * This plugin provides the TypeScriptCompilerAction which compiles TypeScript files\n * using the TypeScript compiler with support for tsconfig.json configurations.\n *\n * @type {ActionPlugin}\n */\nconst plugin: ActionPlugin = {\n version: \"1.0.0\",\n description: \"TypeScript compilation actions for kist\",\n author: \"kist\",\n repository: \"https://github.com/getkist/kist-action-typescript\",\n keywords: [\"kist\", \"kist-action\", \"typescript\", \"compiler\", \"tsc\"],\n registerActions: () => ({\n TypeScriptCompilerAction,\n }),\n};\n\nexport default plugin;\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getkist/action-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "TypeScript compilation actions for kist build tool",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"npm": ">=9.0.0"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "
|
|
32
|
-
"build:watch": "
|
|
31
|
+
"build": "tsup",
|
|
32
|
+
"build:watch": "tsup --watch",
|
|
33
33
|
"test": "jest",
|
|
34
34
|
"test:watch": "jest --watch",
|
|
35
35
|
"test:coverage": "jest --coverage",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"kist": "^0.1.
|
|
48
|
+
"kist": "^0.1.64"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"typescript": "^5.9.3"
|
|
@@ -57,13 +57,29 @@
|
|
|
57
57
|
"@typescript-eslint/parser": "8.54.0",
|
|
58
58
|
"eslint": "10.0.0",
|
|
59
59
|
"jest": "30.2.0",
|
|
60
|
-
"kist": "
|
|
60
|
+
"kist": "file:../kist",
|
|
61
61
|
"prettier": "^3.8.1",
|
|
62
|
-
"ts-jest": "^29.4.6"
|
|
62
|
+
"ts-jest": "^29.4.6",
|
|
63
|
+
"tsup": "^8.5.1"
|
|
63
64
|
},
|
|
64
65
|
"files": [
|
|
65
66
|
"dist",
|
|
66
67
|
"README.md",
|
|
67
68
|
"LICENSE"
|
|
68
|
-
]
|
|
69
|
+
],
|
|
70
|
+
"module": "./dist/index.mjs",
|
|
71
|
+
"exports": {
|
|
72
|
+
".": {
|
|
73
|
+
"import": {
|
|
74
|
+
"types": "./dist/index.d.ts",
|
|
75
|
+
"default": "./dist/index.mjs"
|
|
76
|
+
},
|
|
77
|
+
"require": {
|
|
78
|
+
"types": "./dist/index.d.ts",
|
|
79
|
+
"default": "./dist/index.cjs"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"./package.json": "./package.json"
|
|
83
|
+
},
|
|
84
|
+
"sideEffects": false
|
|
69
85
|
}
|
|
@@ -1 +0,0 @@
|
|
|
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;AAE9B,OAAO,EAAE,MAAM,YAAY,CAAC;AAM5B;;;;;;;;;;;;;;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,EAAE,CAAC,eAAe,CAAC;CACxC;AAMD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,wBAAyB,SAAQ,MAAM;IAChD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,OAAO,CAAC,OAAO,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC;IAgFtE;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,oBAAoB;IAiC5B;;;;;;;;;;;;OAYG;IACH,QAAQ,IAAI,MAAM;CAGrB"}
|
|
@@ -1,152 +0,0 @@
|
|
|
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
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
-
this.logError("Error during TypeScript compilation:", error);
|
|
98
|
-
throw new Error(`TypeScript compilation failed: ${message}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Loads and parses a tsconfig.json file with proper error handling.
|
|
103
|
-
*
|
|
104
|
-
* This method:
|
|
105
|
-
* 1. Reads the tsconfig.json file from disk
|
|
106
|
-
* 2. Parses the JSON content
|
|
107
|
-
* 3. Validates the configuration against TypeScript's schema
|
|
108
|
-
* 4. Resolves relative paths based on the tsconfig directory
|
|
109
|
-
*
|
|
110
|
-
* @private
|
|
111
|
-
* @param {string} tsconfigPath - The absolute or relative path to the tsconfig.json file.
|
|
112
|
-
* @returns {ts.ParsedCommandLine} The parsed TypeScript configuration including compiler
|
|
113
|
-
* options and file names to compile.
|
|
114
|
-
* @throws {Error} Throws an error if the file cannot be read or the JSON is invalid.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* const config = this.loadAndParseTsConfig('./tsconfig.json');
|
|
118
|
-
* console.log(config.options.target); // 'ES2020' or similar
|
|
119
|
-
*/
|
|
120
|
-
loadAndParseTsConfig(tsconfigPath) {
|
|
121
|
-
// **Read and Parse tsconfig.json**
|
|
122
|
-
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
123
|
-
if (configFile.error) {
|
|
124
|
-
throw new Error(`Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`);
|
|
125
|
-
}
|
|
126
|
-
// **Parse the configuration content**
|
|
127
|
-
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(tsconfigPath));
|
|
128
|
-
if (parsedConfig.errors.length > 0) {
|
|
129
|
-
throw new Error(`Error parsing tsconfig.json: ${parsedConfig.errors
|
|
130
|
-
.map((diag) => ts.flattenDiagnosticMessageText(diag.messageText, "\n"))
|
|
131
|
-
.join("\n")}`);
|
|
132
|
-
}
|
|
133
|
-
return parsedConfig;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Provides a human-readable description of this action.
|
|
137
|
-
*
|
|
138
|
-
* This method is used by the Kist build system to display information about
|
|
139
|
-
* what this action does in logs and documentation.
|
|
140
|
-
*
|
|
141
|
-
* @returns {string} A description of the TypeScript compilation action.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* const action = new TypeScriptCompilerAction();
|
|
145
|
-
* console.log(action.describe());
|
|
146
|
-
* // Output: "Compiles TypeScript files using a given tsconfig.json configuration."
|
|
147
|
-
*/
|
|
148
|
-
describe() {
|
|
149
|
-
return "Compiles TypeScript files using a given tsconfig.json configuration.";
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=TypeScriptCompilerAction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptCompilerAction.js","sourceRoot":"","sources":["../../../src/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,YAAY,CAAC;AA4B5B,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,wBAAyB,SAAQ,MAAM;IAChD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,OAAO,CAAC,OAAwC;QAClD,MAAM,EACF,YAAY,GAAG,eAAe,EAC9B,SAAS,EACT,SAAS,EACT,eAAe,GAAG,EAAE,GACvB,GAAG,OAAO,CAAC;QAEZ,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAExD,IAAI,CAAC,OAAO,CACR,6CAA6C,oBAAoB,EAAE,CACtE,CAAC;QAEF,IAAI,CAAC;YACD,mCAAmC;YACnC,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAC1C,oBAAoB,CACvB,CAAC;YAEF,gCAAgC;YAChC,MAAM,qBAAqB,GAAG,EAAE,CAAC,8BAA8B,C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 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @getkist/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/kist-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
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,mDAAmD;IAC/D,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"}
|