@remotex-labs/xbuild 1.5.11 → 1.5.12
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/cli.d.ts +1282 -1477
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1563 -1732
- package/dist/index.js +13 -13
- package/dist/index.js.map +3 -3
- package/package.json +7 -7
package/dist/cli.d.ts
CHANGED
|
@@ -1,106 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* This file was automatically generated by xBuild.
|
|
4
|
-
* DO NOT EDIT MANUALLY.
|
|
5
|
-
*/
|
|
6
|
-
import type { SourceService } from '@remotex-labs/xmap';
|
|
7
|
-
import { SourceService } from '@remotex-labs/xmap';
|
|
8
|
-
export type { BuildResult, OnLoadArgs, OnLoadResult, OnResolveArgs, OnResolveResult, PluginBuild } from 'esbuild';
|
|
9
|
-
import type { BuildResult } from 'esbuild';
|
|
10
|
-
import type { BuildOptions } from 'esbuild';
|
|
11
|
-
import type { IncomingMessage, ServerResponse } from 'http';
|
|
12
|
-
import type { Loader, OnLoadArgs, BuildResult, OnEndResult, PluginBuild, OnLoadResult, OnResolveArgs, OnResolveResult } from 'esbuild';
|
|
13
|
-
import type { Format } from 'esbuild';
|
|
14
|
-
import type { Argv } from 'yargs';
|
|
15
|
-
import type { ChildProcessWithoutNullStreams } from 'child_process';
|
|
16
|
-
import type { Loader, Metafile, OnLoadArgs, OnLoadResult } from 'esbuild';
|
|
17
|
-
import type { BuildOptions, BuildResult, Metafile } from 'esbuild';
|
|
18
|
-
import type { Message } from 'esbuild';
|
|
19
|
-
import type { Plugin } from 'esbuild';
|
|
20
|
-
import type { ParsedCommandLine, Diagnostic } from 'typescript';
|
|
21
|
-
import type { OutputFile } from 'typescript';
|
|
22
|
-
import type { FormatDiagnosticsHost } from 'typescript';
|
|
23
|
-
import type { CompilerOptions, IScriptSnapshot } from 'typescript';
|
|
24
|
-
import type { ParsedCommandLine, LanguageService } from 'typescript';
|
|
25
|
-
import type { Context } from 'vm';
|
|
26
|
-
|
|
27
1
|
#!/usr/bin/env node
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* Represents an error specific to the xBuild process.
|
|
38
|
-
*
|
|
39
|
-
* The `xBuildError` class extends the `BaseError` class to provide a custom error type for the xBuild system.
|
|
40
|
-
* It includes additional functionality to maintain stack trace information and assigns a specific name to
|
|
41
|
-
* the error, making it easier to identify and handle in different parts of the application.
|
|
42
|
-
*
|
|
43
|
-
* @augments BaseError
|
|
44
|
-
*/
|
|
45
|
-
declare class xBuildError extends BaseError {
|
|
46
|
-
/**
|
|
47
|
-
* Original error stack
|
|
48
|
-
*/
|
|
49
|
-
originalErrorStack: string | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Creates an instance of `xBuildError`.
|
|
52
|
-
*
|
|
53
|
-
* @param message - The error message that describes the error. This message is passed to the base class
|
|
54
|
-
* `BaseError` constructor and is used to provide context about the nature of the error.
|
|
55
|
-
* @param options - Optional configuration for the error. This can include additional properties or settings
|
|
56
|
-
* that customize the error's behavior.
|
|
57
|
-
*/
|
|
58
|
-
constructor(message: string, options?: ErrorOptions);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Import will remove at compile time
|
|
63
|
-
*/
|
|
64
|
-
/**
|
|
65
|
-
* A base class for custom errors with enhanced stack trace formatting and source code information.
|
|
66
|
-
*
|
|
67
|
-
* The `BaseError` class extends the native `Error` class, adding functionality to format the error stack
|
|
68
|
-
* trace and include details from a source map service. This is useful for debugging errors in compiled
|
|
69
|
-
* or transpiled code by providing clearer information about the source of the error.
|
|
70
|
-
*/
|
|
71
|
-
export declare abstract class BaseError extends Error {
|
|
72
|
-
readonly sourceMap?: SourceService | undefined;
|
|
73
|
-
callStacks: Array<NodeJS.CallSite>;
|
|
74
|
-
/**
|
|
75
|
-
* Creates a new instance of `BaseError`.
|
|
76
|
-
*
|
|
77
|
-
* This constructor initializes a new `BaseError` instance by setting the error message and formatting
|
|
78
|
-
* the stack trace using the provided source map information. It also ensures the stack trace is maintained
|
|
79
|
-
* correctly by using `Error.captureStackTrace` (if available). The default source map service is used if
|
|
80
|
-
* none is provided.
|
|
81
|
-
*
|
|
82
|
-
* @param message - A descriptive error message to be associated with the error.
|
|
83
|
-
* @param sourceMap - (Optional) The `SourceService` instance used to format and resolve the stack trace.
|
|
84
|
-
* If not provided, the default source map service (`defaultSourceService`) is used.
|
|
85
|
-
*/
|
|
86
|
-
protected constructor(message: string, sourceMap?: SourceService | undefined);
|
|
87
|
-
/**
|
|
88
|
-
* Reformats the error stack trace using source map information.
|
|
89
|
-
*
|
|
90
|
-
* This function enhances the original error stack trace by attempting to map each entry
|
|
91
|
-
* back to its original position in the source file using the provided source map service.
|
|
92
|
-
* If the source map information is not available, it returns the original stack trace.
|
|
93
|
-
*
|
|
94
|
-
* @param error - The original error with stack trace of the error.
|
|
95
|
-
* @returns The reformatted stack trace or the original stack trace if no mapping is available.
|
|
96
|
-
*/
|
|
97
|
-
protected reformatStack(error: ErrorType): string;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* A custom error type that extends the native `Error` object by adding a `callStacks` property.
|
|
102
|
-
* This property contains an array of `NodeJS.CallSite` objects, representing the call stack details.
|
|
103
|
-
*/
|
|
2
|
+
import type { SourceService } from "@remotex-labs/xmap";
|
|
3
|
+
import type { Loader, OnLoadArgs, BuildResult, OnEndResult, PluginBuild, OnLoadResult, OnResolveArgs, OnResolveResult, BuildOptions, Format, Metafile, Message, Plugin } from "esbuild";
|
|
4
|
+
import type { IncomingMessage, ServerResponse } from "http";
|
|
5
|
+
import type { Argv } from "yargs";
|
|
6
|
+
import type { ChildProcessWithoutNullStreams } from "child_process";
|
|
7
|
+
import type { OutputFile, FormatDiagnosticsHost, CompilerOptions, IScriptSnapshot, ParsedCommandLine, LanguageService, Diagnostic } from "typescript";
|
|
8
|
+
import type { Context } from "vm";
|
|
104
9
|
/**
|
|
105
10
|
* Represents an enhanced error type that extends the built-in Error object.
|
|
106
11
|
* This type adds an optional property to store call stack information.
|
|
@@ -120,7 +25,7 @@ export declare abstract class BaseError extends Error {
|
|
|
120
25
|
* console.error(myError);
|
|
121
26
|
* ```
|
|
122
27
|
*/
|
|
123
|
-
type ErrorType = Error & {
|
|
28
|
+
export type ErrorType = Error & {
|
|
124
29
|
callStacks?: Array<NodeJS.CallSite>;
|
|
125
30
|
};
|
|
126
31
|
/**
|
|
@@ -131,7 +36,7 @@ type ErrorType = Error & {
|
|
|
131
36
|
* @property blockCode - The block of code (if any) related to the error, or `null` if unavailable.
|
|
132
37
|
* @property formattedError - A formatted string representing the error details.
|
|
133
38
|
*/
|
|
134
|
-
interface StackTraceStateInterface {
|
|
39
|
+
export interface StackTraceStateInterface {
|
|
135
40
|
error: ErrorType & BaseError;
|
|
136
41
|
blockCode: null | string;
|
|
137
42
|
formattedError: string;
|
|
@@ -145,31 +50,12 @@ interface StackTraceStateInterface {
|
|
|
145
50
|
* @property source - The source file path where the frame occurred.
|
|
146
51
|
* @property functionName - The name of the function being executed at this frame, or an empty string if not available.
|
|
147
52
|
*/
|
|
148
|
-
interface FrameDetailsInterface {
|
|
53
|
+
export interface FrameDetailsInterface {
|
|
149
54
|
line: number;
|
|
150
55
|
column: number;
|
|
151
56
|
source: string;
|
|
152
57
|
functionName: string;
|
|
153
58
|
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Import will remove at compile time
|
|
157
|
-
*/
|
|
158
|
-
declare const xBuildLazy: {
|
|
159
|
-
service: SourceService;
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Prepares the error stack trace for display.
|
|
163
|
-
*
|
|
164
|
-
* This function overrides the default stack trace preparation to provide a custom format,
|
|
165
|
-
* including enhanced stack trace information and error details.
|
|
166
|
-
*
|
|
167
|
-
* @param error - The error object (Error or BaseError).
|
|
168
|
-
* @param stackEntries - The array of stack entries from the call stack.
|
|
169
|
-
* @returns The formatted stack trace as a string.
|
|
170
|
-
*/
|
|
171
|
-
declare function formatStackTrace(error: ErrorType & BaseError, stackEntries: Array<NodeJS.CallSite>): string;
|
|
172
|
-
|
|
173
59
|
/**
|
|
174
60
|
* An enumeration of ANSI color codes used for text formatting in the terminal.
|
|
175
61
|
*
|
|
@@ -184,7 +70,7 @@ declare function formatStackTrace(error: ErrorType & BaseError, stackEntries: Ar
|
|
|
184
70
|
* console.log(Color.BrightPink, 'This is bright pink text', Color.Reset);
|
|
185
71
|
* ```
|
|
186
72
|
*/
|
|
187
|
-
declare const enum Colors {
|
|
73
|
+
export declare const enum Colors {
|
|
188
74
|
Reset = "\u001B[0m",
|
|
189
75
|
Red = "\u001B[38;5;9m",
|
|
190
76
|
Gray = "\u001B[38;5;243m",
|
|
@@ -228,14 +114,80 @@ declare const enum Colors {
|
|
|
228
114
|
* console.log(plainMessage); // Output will be without color formatting
|
|
229
115
|
* ```
|
|
230
116
|
*/
|
|
231
|
-
declare function setColor(color: Colors, msg: string, activeColor?: boolean): string;
|
|
232
|
-
|
|
117
|
+
export declare function setColor(color: Colors, msg: string, activeColor?: boolean): string;
|
|
118
|
+
export declare const xBuildLazy: {
|
|
119
|
+
service: SourceService;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Prepares the error stack trace for display.
|
|
123
|
+
*
|
|
124
|
+
* This function overrides the default stack trace preparation to provide a custom format,
|
|
125
|
+
* including enhanced stack trace information and error details.
|
|
126
|
+
*
|
|
127
|
+
* @param error - The error object (Error or BaseError).
|
|
128
|
+
* @param stackEntries - The array of stack entries from the call stack.
|
|
129
|
+
* @returns The formatted stack trace as a string.
|
|
130
|
+
*/
|
|
131
|
+
export declare function formatStackTrace(error: ErrorType & BaseError, stackEntries: Array<NodeJS.CallSite>): string;
|
|
233
132
|
/**
|
|
234
|
-
*
|
|
133
|
+
* A base class for custom errors with enhanced stack trace formatting and source code information.
|
|
134
|
+
*
|
|
135
|
+
* The `BaseError` class extends the native `Error` class, adding functionality to format the error stack
|
|
136
|
+
* trace and include details from a source map service. This is useful for debugging errors in compiled
|
|
137
|
+
* or transpiled code by providing clearer information about the source of the error.
|
|
235
138
|
*/
|
|
139
|
+
export declare abstract class BaseError extends Error {
|
|
140
|
+
readonly sourceMap?: SourceService | undefined;
|
|
141
|
+
callStacks: Array<NodeJS.CallSite>;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a new instance of `BaseError`.
|
|
144
|
+
*
|
|
145
|
+
* This constructor initializes a new `BaseError` instance by setting the error message and formatting
|
|
146
|
+
* the stack trace using the provided source map information. It also ensures the stack trace is maintained
|
|
147
|
+
* correctly by using `Error.captureStackTrace` (if available). The default source map service is used if
|
|
148
|
+
* none is provided.
|
|
149
|
+
*
|
|
150
|
+
* @param message - A descriptive error message to be associated with the error.
|
|
151
|
+
* @param sourceMap - (Optional) The `SourceService` instance used to format and resolve the stack trace.
|
|
152
|
+
* If not provided, the default source map service (`defaultSourceService`) is used.
|
|
153
|
+
*/
|
|
154
|
+
protected constructor(message: string, sourceMap?: SourceService | undefined);
|
|
155
|
+
/**
|
|
156
|
+
* Reformats the error stack trace using source map information.
|
|
157
|
+
*
|
|
158
|
+
* This function enhances the original error stack trace by attempting to map each entry
|
|
159
|
+
* back to its original position in the source file using the provided source map service.
|
|
160
|
+
* If the source map information is not available, it returns the original stack trace.
|
|
161
|
+
*
|
|
162
|
+
* @param error - The original error with stack trace of the error.
|
|
163
|
+
* @returns The reformatted stack trace or the original stack trace if no mapping is available.
|
|
164
|
+
*/
|
|
165
|
+
protected reformatStack(error: ErrorType): string;
|
|
166
|
+
}
|
|
236
167
|
/**
|
|
237
|
-
*
|
|
168
|
+
* Represents an error specific to the xBuild process.
|
|
169
|
+
*
|
|
170
|
+
* The `xBuildError` class extends the `BaseError` class to provide a custom error type for the xBuild system.
|
|
171
|
+
* It includes additional functionality to maintain stack trace information and assigns a specific name to
|
|
172
|
+
* the error, making it easier to identify and handle in different parts of the application.
|
|
173
|
+
*
|
|
174
|
+
* @augments BaseError
|
|
238
175
|
*/
|
|
176
|
+
export declare class xBuildError extends BaseError {
|
|
177
|
+
/**
|
|
178
|
+
* Original error stack
|
|
179
|
+
*/
|
|
180
|
+
originalErrorStack: string | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Creates an instance of `xBuildError`.
|
|
183
|
+
*
|
|
184
|
+
* @param message - The error message that describes the error. This message is passed to the base class
|
|
185
|
+
* `BaseError` constructor and is used to provide context about the nature of the error.
|
|
186
|
+
* @param options - Optional configuration for the error. This can include additional properties or settings
|
|
187
|
+
* that customize the error's behavior.
|
|
188
|
+
*/
|
|
189
|
+
constructor(message: string, options?: ErrorOptions);
|
|
190
|
+
}
|
|
239
191
|
/**
|
|
240
192
|
* A custom error class to handle errors occurring within a virtual machine (VM) execution context.
|
|
241
193
|
*
|
|
@@ -256,7 +208,7 @@ declare function setColor(color: Colors, msg: string, activeColor?: boolean): st
|
|
|
256
208
|
* }
|
|
257
209
|
* ```
|
|
258
210
|
*/
|
|
259
|
-
declare class VMRuntimeError extends BaseError {
|
|
211
|
+
export declare class VMRuntimeError extends BaseError {
|
|
260
212
|
/**
|
|
261
213
|
* The original error thrown during the VM execution.
|
|
262
214
|
*/
|
|
@@ -288,73 +240,58 @@ declare class VMRuntimeError extends BaseError {
|
|
|
288
240
|
*/
|
|
289
241
|
constructor(originalError: ErrorType, sourceMap?: SourceService);
|
|
290
242
|
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Exports
|
|
294
|
-
*/
|
|
295
243
|
/**
|
|
296
|
-
*
|
|
244
|
+
* Interface for the build state that users can modify.
|
|
245
|
+
*
|
|
246
|
+
* This interface allows users to store and manage any custom data related to the build process.
|
|
247
|
+
*
|
|
248
|
+
* @template T - The type of values that can be stored in the state.
|
|
297
249
|
*/
|
|
250
|
+
export interface PluginsBuildStateInterface {
|
|
251
|
+
[key: string]: unknown;
|
|
252
|
+
}
|
|
298
253
|
/**
|
|
299
|
-
*
|
|
254
|
+
* A type that defines the possible return values of a plugin function.
|
|
255
|
+
*
|
|
256
|
+
* The function can return a Promise that resolves to `null` or `void`, or it can return `null` or `void` directly.
|
|
300
257
|
*/
|
|
301
|
-
|
|
302
|
-
import '@errors/uncaught.error';
|
|
258
|
+
export type PluginResultType = Promise<null | void> | null | void;
|
|
303
259
|
/**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* This function parses the CLI arguments, configures the build settings, and executes
|
|
307
|
-
* the appropriate build tasks, including type checking, serving, or running in debug mode.
|
|
308
|
-
*
|
|
309
|
-
* @param argv - An array of strings representing the CLI arguments.
|
|
310
|
-
*
|
|
311
|
-
* @returns A promise that resolves when all build tasks are completed.
|
|
260
|
+
* Defines the signature of a function that is called at the end of the build process.
|
|
312
261
|
*
|
|
313
|
-
* @
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
* ```
|
|
262
|
+
* @param result - The `BuildResult` object that contains information about the outcome of the build process.
|
|
263
|
+
* @param state - The current build state that users can modify.
|
|
264
|
+
* @returns A `PluginResultType`, which may include asynchronous operations.
|
|
317
265
|
*/
|
|
318
|
-
|
|
266
|
+
export type OnEndType = (result: BuildResult, state: PluginsBuildStateInterface) => PluginResultType | OnEndResult | Promise<OnEndResult>;
|
|
319
267
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* This function reads the configuration from the provided file path, processes it,
|
|
323
|
-
* and initiates the build tasks.
|
|
324
|
-
*
|
|
325
|
-
* @param configFilePath - The path to the configuration file to be used for the build.
|
|
326
|
-
*
|
|
327
|
-
* @returns A promise that resolves to an array of `BuildResult` objects once all build tasks are completed.
|
|
328
|
-
*
|
|
329
|
-
* @throws Error Throws an error if the configuration file does not exist or is invalid.
|
|
268
|
+
* Defines the signature of a function that is called at the start of the build process.
|
|
330
269
|
*
|
|
331
|
-
* @
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* console.log('Build results:', results);
|
|
335
|
-
* ```
|
|
270
|
+
* @param build - The `PluginBuild` object that contains information about the build process and allows modifying build options.
|
|
271
|
+
* @param state - The current build state that users can modify.
|
|
272
|
+
* @returns A `PluginResultType`, which may include asynchronous operations.
|
|
336
273
|
*/
|
|
337
|
-
|
|
274
|
+
export type OnStartType = (build: PluginBuild, state: PluginsBuildStateInterface) => PluginResultType | OnEndResult | Promise<OnEndResult>;
|
|
338
275
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* This function processes the given configuration and executes the build tasks accordingly.
|
|
342
|
-
*
|
|
343
|
-
* @param config - A partial configuration object used to define the build settings.
|
|
344
|
-
*
|
|
345
|
-
* @returns A promise that resolves to an array of `BuildResult` objects once all build tasks are completed.
|
|
276
|
+
* Defines the signature of a function that is called during the resolution of an import path.
|
|
346
277
|
*
|
|
347
|
-
* @
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* ```
|
|
278
|
+
* @param args - The `OnResolveArgs` object, containing information about the file being resolved, such as its path, importer, namespace, etc.
|
|
279
|
+
* @param state - The current build state that users can modify.
|
|
280
|
+
* @returns A `Promise` or a direct `OnResolveResult` which can modify the resolved path, or a `PluginResultType` for
|
|
281
|
+
* performing additional async tasks without altering resolution.
|
|
352
282
|
*/
|
|
353
|
-
|
|
354
|
-
|
|
283
|
+
export type OnResolveType = (args: OnResolveArgs, state: PluginsBuildStateInterface) => Promise<OnResolveResult | PluginResultType> | OnResolveResult | PluginResultType;
|
|
355
284
|
/**
|
|
356
|
-
*
|
|
285
|
+
* Defines the signature of a function that is called when a file is loaded.
|
|
286
|
+
*
|
|
287
|
+
* @param content - The content of the file being loaded, as either a `string` or `Uint8Array`.
|
|
288
|
+
* @param loader - The type of loader used for the file, such as `js`, `ts`, `json`, or others. It can also be `undefined`.
|
|
289
|
+
* @param args - The `OnLoadArgs` object, containing information about the file being loaded, such as its path, namespace, etc.
|
|
290
|
+
* @param state - The current build state that users can modify.
|
|
291
|
+
* @returns A `Promise` or direct `OnLoadResult`, which can modify the file content and loader, or a `PluginResultType`
|
|
292
|
+
* for performing additional async tasks without altering the content.
|
|
357
293
|
*/
|
|
294
|
+
export type OnLoadType = (content: string | Uint8Array, loader: Loader | undefined, args: OnLoadArgs, state: PluginsBuildStateInterface) => Promise<OnLoadResult | PluginResultType> | OnLoadResult | PluginResultType;
|
|
358
295
|
/**
|
|
359
296
|
* Represents the format for specifying entry points in TypeScript declaration generation and esbuild configuration.
|
|
360
297
|
*
|
|
@@ -395,7 +332,7 @@ declare function build(config: PartialDeepConfigurationsType): Promise<BuildResu
|
|
|
395
332
|
* When used with esbuild configuration, the format determines how output files are named and structured.
|
|
396
333
|
* When used for TypeScript declaration generation, it affects how declaration files are generated and organized.
|
|
397
334
|
*/
|
|
398
|
-
type EntryPointsType = (string | {
|
|
335
|
+
export type EntryPointsType = (string | {
|
|
399
336
|
in: string;
|
|
400
337
|
out: string;
|
|
401
338
|
})[] | Record<string, string> | undefined;
|
|
@@ -444,7 +381,7 @@ type EntryPointsType = (string | {
|
|
|
444
381
|
* // }
|
|
445
382
|
* ```
|
|
446
383
|
*/
|
|
447
|
-
type PartialDeepType<T> = {
|
|
384
|
+
export type PartialDeepType<T> = {
|
|
448
385
|
[P in keyof T]?: T[P] extends object ? PartialDeepType<T[P]> : T[P];
|
|
449
386
|
};
|
|
450
387
|
/**
|
|
@@ -464,7 +401,7 @@ type PartialDeepType<T> = {
|
|
|
464
401
|
* @property [exports.default] - An optional default export.
|
|
465
402
|
* The default export, if present, is of type `ConfigurationInterface`.
|
|
466
403
|
*/
|
|
467
|
-
interface ModuleInterface {
|
|
404
|
+
export interface ModuleInterface {
|
|
468
405
|
/**
|
|
469
406
|
* An object representing the exports of the module.
|
|
470
407
|
* The keys are strings representing export names, and the values can be of any type.
|
|
@@ -504,7 +441,7 @@ interface ModuleInterface {
|
|
|
504
441
|
*
|
|
505
442
|
* @public
|
|
506
443
|
*/
|
|
507
|
-
interface ServeInterface {
|
|
444
|
+
export interface ServeInterface {
|
|
508
445
|
port: number;
|
|
509
446
|
host: string;
|
|
510
447
|
active: boolean;
|
|
@@ -558,7 +495,7 @@ interface ServeInterface {
|
|
|
558
495
|
* @see OnStartType
|
|
559
496
|
* @see OnResolveType
|
|
560
497
|
*/
|
|
561
|
-
interface HooksInterface {
|
|
498
|
+
export interface HooksInterface {
|
|
562
499
|
onEnd: OnEndType;
|
|
563
500
|
onLoad: OnLoadType;
|
|
564
501
|
onStart: OnStartType;
|
|
@@ -603,7 +540,7 @@ interface HooksInterface {
|
|
|
603
540
|
* @public
|
|
604
541
|
* @category Configuration
|
|
605
542
|
*/
|
|
606
|
-
interface ConfigurationInterface {
|
|
543
|
+
export interface ConfigurationInterface {
|
|
607
544
|
/**
|
|
608
545
|
* Build and run entryPoint for development
|
|
609
546
|
*/
|
|
@@ -737,7 +674,7 @@ interface ExportedConfigurationInterface extends ConfigurationInterface {
|
|
|
737
674
|
* `ConfigurationInterface` are optional. It allows for flexible configuration
|
|
738
675
|
* objects where only a subset of properties need to be specified.
|
|
739
676
|
*/
|
|
740
|
-
type xBuildConfig = PartialDeepType<ExportedConfigurationInterface>;
|
|
677
|
+
export type xBuildConfig = PartialDeepType<ExportedConfigurationInterface>;
|
|
741
678
|
/**
|
|
742
679
|
* Represents a partially deep configuration type based on the `ConfigurationInterface`.
|
|
743
680
|
*
|
|
@@ -745,7 +682,7 @@ type xBuildConfig = PartialDeepType<ExportedConfigurationInterface>;
|
|
|
745
682
|
* missing or undefined. It leverages the `PartialDeepType` utility type to allow
|
|
746
683
|
* for flexibility in configuration management.
|
|
747
684
|
*/
|
|
748
|
-
type PartialDeepConfigurationsType = PartialDeepType<ConfigurationInterface>;
|
|
685
|
+
export type PartialDeepConfigurationsType = PartialDeepType<ConfigurationInterface>;
|
|
749
686
|
/**
|
|
750
687
|
* Defines the possible types for configurations.
|
|
751
688
|
*
|
|
@@ -786,88 +723,27 @@ type PartialDeepConfigurationsType = PartialDeepType<ConfigurationInterface>;
|
|
|
786
723
|
* ];
|
|
787
724
|
* ```
|
|
788
725
|
*/
|
|
789
|
-
type ConfigurationsType = PartialDeepConfigurationsType | Array<PartialDeepConfigurationsType>;
|
|
790
|
-
export {};
|
|
791
|
-
|
|
792
|
-
/**
|
|
793
|
-
* Import will remove at compile time
|
|
794
|
-
*/
|
|
726
|
+
export type ConfigurationsType = PartialDeepConfigurationsType | Array<PartialDeepConfigurationsType>;
|
|
795
727
|
/**
|
|
796
|
-
* Interface
|
|
797
|
-
*
|
|
798
|
-
* This interface allows users to store and manage any custom data related to the build process.
|
|
728
|
+
* Interface representing the command-line arguments for the build tool.
|
|
799
729
|
*
|
|
800
|
-
* @
|
|
730
|
+
* @interface ArgvInterface
|
|
731
|
+
* @property typeCheck - Flag indicating if the tool should perform type checking only.
|
|
732
|
+
* @property node - Flag indicating if the build is intended for Node.js environment.
|
|
733
|
+
* @property file - The entry file(s) to build.
|
|
734
|
+
* @property dev - List of development-related options for the build.
|
|
735
|
+
* @property debug - List of debugging-related options for the build.
|
|
736
|
+
* @property serve - Flag indicating if an HTTP server should be started for the build folder.
|
|
737
|
+
* @property outdir - The output directory for the build files.
|
|
738
|
+
* @property declaration - Flag indicating if TypeScript declaration files should be generated.
|
|
739
|
+
* @property watch - Flag indicating if the build should watch for file changes.
|
|
740
|
+
* @property config - Path to the build configuration file (JavaScript or TypeScript).
|
|
741
|
+
* @property tsconfig - Path to the TypeScript configuration file to use.
|
|
742
|
+
* @property minify - Flag indicating if the code should be minified.
|
|
743
|
+
* @property bundle - Flag indicating if the code should be bundled.
|
|
744
|
+
* @property format - Defines the formats for the build output.
|
|
801
745
|
*/
|
|
802
|
-
interface
|
|
803
|
-
[key: string]: unknown;
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* A type that defines the possible return values of a plugin function.
|
|
807
|
-
*
|
|
808
|
-
* The function can return a Promise that resolves to `null` or `void`, or it can return `null` or `void` directly.
|
|
809
|
-
*/
|
|
810
|
-
type PluginResultType = Promise<null | void> | null | void;
|
|
811
|
-
/**
|
|
812
|
-
* Defines the signature of a function that is called at the end of the build process.
|
|
813
|
-
*
|
|
814
|
-
* @param result - The `BuildResult` object that contains information about the outcome of the build process.
|
|
815
|
-
* @param state - The current build state that users can modify.
|
|
816
|
-
* @returns A `PluginResultType`, which may include asynchronous operations.
|
|
817
|
-
*/
|
|
818
|
-
type OnEndType = (result: BuildResult, state: PluginsBuildStateInterface) => PluginResultType | OnEndResult | Promise<OnEndResult>;
|
|
819
|
-
/**
|
|
820
|
-
* Defines the signature of a function that is called at the start of the build process.
|
|
821
|
-
*
|
|
822
|
-
* @param build - The `PluginBuild` object that contains information about the build process and allows modifying build options.
|
|
823
|
-
* @param state - The current build state that users can modify.
|
|
824
|
-
* @returns A `PluginResultType`, which may include asynchronous operations.
|
|
825
|
-
*/
|
|
826
|
-
type OnStartType = (build: PluginBuild, state: PluginsBuildStateInterface) => PluginResultType | OnEndResult | Promise<OnEndResult>;
|
|
827
|
-
/**
|
|
828
|
-
* Defines the signature of a function that is called during the resolution of an import path.
|
|
829
|
-
*
|
|
830
|
-
* @param args - The `OnResolveArgs` object, containing information about the file being resolved, such as its path, importer, namespace, etc.
|
|
831
|
-
* @param state - The current build state that users can modify.
|
|
832
|
-
* @returns A `Promise` or a direct `OnResolveResult` which can modify the resolved path, or a `PluginResultType` for
|
|
833
|
-
* performing additional async tasks without altering resolution.
|
|
834
|
-
*/
|
|
835
|
-
type OnResolveType = (args: OnResolveArgs, state: PluginsBuildStateInterface) => Promise<OnResolveResult | PluginResultType> | OnResolveResult | PluginResultType;
|
|
836
|
-
/**
|
|
837
|
-
* Defines the signature of a function that is called when a file is loaded.
|
|
838
|
-
*
|
|
839
|
-
* @param content - The content of the file being loaded, as either a `string` or `Uint8Array`.
|
|
840
|
-
* @param loader - The type of loader used for the file, such as `js`, `ts`, `json`, or others. It can also be `undefined`.
|
|
841
|
-
* @param args - The `OnLoadArgs` object, containing information about the file being loaded, such as its path, namespace, etc.
|
|
842
|
-
* @param state - The current build state that users can modify.
|
|
843
|
-
* @returns A `Promise` or direct `OnLoadResult`, which can modify the file content and loader, or a `PluginResultType`
|
|
844
|
-
* for performing additional async tasks without altering the content.
|
|
845
|
-
*/
|
|
846
|
-
type OnLoadType = (content: string | Uint8Array, loader: Loader | undefined, args: OnLoadArgs, state: PluginsBuildStateInterface) => Promise<OnLoadResult | PluginResultType> | OnLoadResult | PluginResultType;
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* Import will remove at compile time
|
|
850
|
-
*/
|
|
851
|
-
/**
|
|
852
|
-
* Interface representing the command-line arguments for the build tool.
|
|
853
|
-
*
|
|
854
|
-
* @interface ArgvInterface
|
|
855
|
-
* @property typeCheck - Flag indicating if the tool should perform type checking only.
|
|
856
|
-
* @property node - Flag indicating if the build is intended for Node.js environment.
|
|
857
|
-
* @property file - The entry file(s) to build.
|
|
858
|
-
* @property dev - List of development-related options for the build.
|
|
859
|
-
* @property debug - List of debugging-related options for the build.
|
|
860
|
-
* @property serve - Flag indicating if an HTTP server should be started for the build folder.
|
|
861
|
-
* @property outdir - The output directory for the build files.
|
|
862
|
-
* @property declaration - Flag indicating if TypeScript declaration files should be generated.
|
|
863
|
-
* @property watch - Flag indicating if the build should watch for file changes.
|
|
864
|
-
* @property config - Path to the build configuration file (JavaScript or TypeScript).
|
|
865
|
-
* @property tsconfig - Path to the TypeScript configuration file to use.
|
|
866
|
-
* @property minify - Flag indicating if the code should be minified.
|
|
867
|
-
* @property bundle - Flag indicating if the code should be bundled.
|
|
868
|
-
* @property format - Defines the formats for the build output.
|
|
869
|
-
*/
|
|
870
|
-
interface ArgvInterface {
|
|
746
|
+
export interface ArgvInterface {
|
|
871
747
|
typeCheck: boolean;
|
|
872
748
|
node: boolean;
|
|
873
749
|
file: string;
|
|
@@ -883,36 +759,6 @@ interface ArgvInterface {
|
|
|
883
759
|
bundle: boolean;
|
|
884
760
|
format: Format;
|
|
885
761
|
}
|
|
886
|
-
|
|
887
|
-
/**
|
|
888
|
-
* Handles uncaught exceptions in the Node.js process.
|
|
889
|
-
*
|
|
890
|
-
* This handler is triggered when an error is thrown that is not caught by any try-catch blocks.
|
|
891
|
-
* It captures such exceptions and logs them to the console. If the exception is an instance of `Error`,
|
|
892
|
-
* its string representation is logged. Otherwise, the raw error object is logged.
|
|
893
|
-
*
|
|
894
|
-
* This setup helps in debugging by ensuring that all uncaught exceptions are logged, providing visibility
|
|
895
|
-
* into errors that might otherwise go unnoticed.
|
|
896
|
-
*
|
|
897
|
-
* @example
|
|
898
|
-
* ```ts
|
|
899
|
-
* process.on('uncaughtException', (error) => {
|
|
900
|
-
* if (error instanceof Error) {
|
|
901
|
-
* console.error(error.toString());
|
|
902
|
-
* } else {
|
|
903
|
-
* console.error(error);
|
|
904
|
-
* }
|
|
905
|
-
* });
|
|
906
|
-
* ```
|
|
907
|
-
*
|
|
908
|
-
* @throws Will log uncaught exceptions to the console.
|
|
909
|
-
* Custom handling logic should be added if additional error handling or logging is required.
|
|
910
|
-
*/
|
|
911
|
-
export {};
|
|
912
|
-
|
|
913
|
-
/**
|
|
914
|
-
* Import will remove at compile time
|
|
915
|
-
*/
|
|
916
762
|
/**
|
|
917
763
|
* Parses command-line arguments into an `ArgvInterface` object using `yargs`.
|
|
918
764
|
*
|
|
@@ -930,414 +776,45 @@ export {};
|
|
|
930
776
|
* console.log(args.file); // Output: the file to build
|
|
931
777
|
* console.log(args.dev); // Output: true or false based on the --dev flag
|
|
932
778
|
*/
|
|
933
|
-
declare function argvParser(argv: Array<string>): Argv<ArgvInterface>;
|
|
934
|
-
|
|
779
|
+
export declare function argvParser(argv: Array<string>): Argv<ArgvInterface>;
|
|
935
780
|
/**
|
|
936
|
-
*
|
|
781
|
+
* The `BuildStateInterface` extends the `PluginsBuildStateInterface` interface to include additional properties related to the build
|
|
782
|
+
* process, specifically for handling `ifdef` conditions and function removals in macros.
|
|
783
|
+
*
|
|
784
|
+
* @interface BuildStateInterface
|
|
937
785
|
*/
|
|
786
|
+
export interface BuildStateInterface extends PluginsBuildStateInterface {
|
|
787
|
+
ifdef: Array<string>;
|
|
788
|
+
macros: {
|
|
789
|
+
removeFunctions: Set<string>;
|
|
790
|
+
};
|
|
791
|
+
}
|
|
938
792
|
/**
|
|
939
|
-
*
|
|
793
|
+
* Custom error class to represent type-related errors.
|
|
940
794
|
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
*
|
|
795
|
+
* This class extends the built-in `Error` class to provide more specific
|
|
796
|
+
* error handling for issues related to types. It can be used to distinguish
|
|
797
|
+
* errors that occur due to type mismatches or other type-related problems
|
|
798
|
+
* in your application.
|
|
944
799
|
*
|
|
945
|
-
* @
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
* based on the configuration.
|
|
800
|
+
* @example
|
|
801
|
+
* ```ts
|
|
802
|
+
* throw new TypesError('Invalid type encountered.');
|
|
803
|
+
* ```
|
|
950
804
|
*
|
|
951
|
-
* @
|
|
952
|
-
* @category Services
|
|
805
|
+
* @augments Error
|
|
953
806
|
*/
|
|
954
|
-
declare class
|
|
955
|
-
private config;
|
|
956
|
-
/**
|
|
957
|
-
* Provides TypeScript-related functionality for the build process.
|
|
958
|
-
*/
|
|
959
|
-
readonly typescriptModule: TypescriptModule;
|
|
960
|
-
/**
|
|
961
|
-
* Keeps track of active development processes spawned during the build.
|
|
962
|
-
* This property holds an array of `ChildProcessWithoutNullStreams` instances that represent Node.js processes spawned
|
|
963
|
-
* for running development tasks. These processes are used to handle development builds or runtime tasks and are managed
|
|
964
|
-
* by the `BuildService` class to ensure they are properly started and stopped.
|
|
965
|
-
*
|
|
966
|
-
* @remarks
|
|
967
|
-
* - The array is populated when development processes are spawned, such as when specific development files are
|
|
968
|
-
* processed or when running in development mode.
|
|
969
|
-
* - The processes are terminated gracefully at the end of the build to avoid leaving orphaned processes running.
|
|
970
|
-
* - It is important to manage these processes correctly to avoid resource leaks and ensure proper cleanup.
|
|
971
|
-
*
|
|
972
|
-
* @see ChildProcessWithoutNullStreams
|
|
973
|
-
*/
|
|
974
|
-
private activePossess;
|
|
975
|
-
/**
|
|
976
|
-
* Plugin provider
|
|
977
|
-
*
|
|
978
|
-
* @private
|
|
979
|
-
*/
|
|
980
|
-
private pluginsProvider;
|
|
981
|
-
/**
|
|
982
|
-
* A mapping of output filenames to their corresponding source file paths.
|
|
983
|
-
*
|
|
984
|
-
* @remarks
|
|
985
|
-
* This property stores the entry points configuration for TypeScript compilation.
|
|
986
|
-
* - Keys represent the output filenames (with or without .d.ts extension)
|
|
987
|
-
* - Values represent the source file paths to use as entry points
|
|
988
|
-
*
|
|
989
|
-
* Used by declaration bundling operations to determine which files to process
|
|
990
|
-
* and how to name the resulting declaration outputs.
|
|
991
|
-
*
|
|
992
|
-
* @example
|
|
993
|
-
* ```ts
|
|
994
|
-
* // Example entryPoints structure
|
|
995
|
-
* {
|
|
996
|
-
* 'index': 'src/index.ts',
|
|
997
|
-
* 'components/button': 'src/components/button.ts'
|
|
998
|
-
* }
|
|
999
|
-
* ```
|
|
1000
|
-
*
|
|
1001
|
-
* @private
|
|
1002
|
-
* @since 1.5.9
|
|
1003
|
-
*/
|
|
1004
|
-
private readonly entryPoints;
|
|
1005
|
-
/**
|
|
1006
|
-
* Initializes the build service with the provided configuration.
|
|
1007
|
-
*
|
|
1008
|
-
* The constructor configures the TypeScript provider, suppresses esbuild logging,
|
|
1009
|
-
* sets up development modes, and registers the necessary plugins.
|
|
1010
|
-
*
|
|
1011
|
-
* Declaration files will be output based on the following order of precedence:
|
|
1012
|
-
* 1. If `declarationOutDir` is set in the configuration, it will be used.
|
|
1013
|
-
* 2. If `declarationOutDir` is not provided, it will use the `outDir` value from the tsconfig.
|
|
1014
|
-
* 3. If neither of the above is available, it falls back to using the `outdir` specified in the esbuild configuration.
|
|
1015
|
-
*
|
|
1016
|
-
* @param config - The configuration object for the build process, including esbuild and TypeScript settings.
|
|
1017
|
-
*/
|
|
1018
|
-
constructor(config: ConfigurationInterface);
|
|
1019
|
-
/**
|
|
1020
|
-
* Executes the build process.
|
|
1021
|
-
* This method performs the build and handles any errors that occur during the execution.
|
|
1022
|
-
* If watching or development mode is enabled in the configuration, it starts watching for changes
|
|
1023
|
-
* to automatically rebuild as needed.
|
|
1024
|
-
* The method logs errors that are not related to TypeScript
|
|
1025
|
-
* compilation issues.
|
|
1026
|
-
*
|
|
1027
|
-
* @returns A promise that resolves with a `BuildResult` when the build process is complete,
|
|
1028
|
-
* or `undefined` if an error occurs during execution.
|
|
1029
|
-
*
|
|
1030
|
-
* @throws Error Throws an error if the build process encounters issues that are not related
|
|
1031
|
-
* to TypeScript. Such errors are logged, but the method does not rethrow them.
|
|
1032
|
-
*
|
|
1033
|
-
* @example
|
|
1034
|
-
* ```ts
|
|
1035
|
-
* import { BuildService } from './build-service';
|
|
1036
|
-
*
|
|
1037
|
-
* const buildService = new BuildService(config);
|
|
1038
|
-
* buildService.run().then(() => {
|
|
1039
|
-
* console.log('Build process completed successfully.');
|
|
1040
|
-
* }).catch((error) => {
|
|
1041
|
-
* console.error('Build process failed:', error);
|
|
1042
|
-
* });
|
|
1043
|
-
* ```
|
|
1044
|
-
*
|
|
1045
|
-
* In this example, the `run` method is invoked to execute the build process. It handles both successful
|
|
1046
|
-
* completion and logs any encountered errors, allowing the user to understand the outcome of the build.
|
|
1047
|
-
*/
|
|
1048
|
-
run(): Promise<BuildResult | void>;
|
|
1049
|
-
/**
|
|
1050
|
-
* Runs the build process in debug mode for the specified entry points.
|
|
1051
|
-
* This method temporarily disables development and watch mode, initiates the build process, and spawns development processes
|
|
1052
|
-
* for the specified entry points. If any errors occur during the build, they are handled appropriately.
|
|
1053
|
-
*
|
|
1054
|
-
* @param entryPoints - An array of entry point file names for which the development processes will be spawned.
|
|
1055
|
-
* These entry points are matched against the build output files.
|
|
1056
|
-
*
|
|
1057
|
-
* @returns A `Promise<void>` that resolves when the build and process spawning have completed.
|
|
1058
|
-
*
|
|
1059
|
-
* @throws Handles any build-related errors using the `handleErrors` method.
|
|
1060
|
-
*
|
|
1061
|
-
* @remarks
|
|
1062
|
-
* - The `config.dev` and `config.watch` settings are temporarily disabled to prevent development mode or file watching during the build.
|
|
1063
|
-
* - The `build()` method is called to generate the necessary build outputs.
|
|
1064
|
-
* - The `spawnDev` method is then invoked to spawn processes for the matching entry points.
|
|
1065
|
-
* - If any errors occur during the build, they are caught and passed to the `handleErrors` method.
|
|
1066
|
-
*
|
|
1067
|
-
* @example
|
|
1068
|
-
* ```ts
|
|
1069
|
-
* const entryPoints = ['index', 'main'];
|
|
1070
|
-
* await this.runDebug(entryPoints);
|
|
1071
|
-
* ```
|
|
1072
|
-
*
|
|
1073
|
-
* In this example, the `runDebug` method runs the build process and spawns development processes for `index` and `main`.
|
|
1074
|
-
*
|
|
1075
|
-
* @public
|
|
1076
|
-
*/
|
|
1077
|
-
runDebug(entryPoints: Array<string>): Promise<void>;
|
|
807
|
+
export declare class TypesError extends Error {
|
|
1078
808
|
/**
|
|
1079
|
-
*
|
|
1080
|
-
* This method starts the development server using the `ServerProvider`, builds the project using esbuild,
|
|
1081
|
-
* and watches for file changes to automatically rebuild as needed. It initializes the server and invokes
|
|
1082
|
-
* the build process, enabling continuous development mode.
|
|
1083
|
-
*
|
|
1084
|
-
* @returns A promise that resolves when the server is started and the build process is complete.
|
|
1085
|
-
*
|
|
1086
|
-
* @throws This method catches any errors thrown during the build process and handles them using the
|
|
1087
|
-
* `handleErrors` method.
|
|
1088
|
-
*
|
|
1089
|
-
* @example
|
|
1090
|
-
* ```ts
|
|
1091
|
-
* const buildService = new BuildService(config);
|
|
1092
|
-
* buildService.serve().then(() => {
|
|
1093
|
-
* console.log('Server is running and watching for changes.');
|
|
1094
|
-
* }).catch((error) => {
|
|
1095
|
-
* console.error('Failed to start the server:', error);
|
|
1096
|
-
* });
|
|
1097
|
-
* ```
|
|
809
|
+
* Creates an instance of `TypesError`.
|
|
1098
810
|
*
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
*/
|
|
1102
|
-
serve(): Promise<void>;
|
|
1103
|
-
/**
|
|
1104
|
-
* Executes a provided asynchronous callback function within a try-catch block.
|
|
1105
|
-
* This method ensures that any errors thrown during the execution of the callback
|
|
1106
|
-
* are properly handled and logged. If the error appears to be an `esbuild`-related
|
|
1107
|
-
* `OnEndResult` error with an array of errors, it avoids redundant logging.
|
|
1108
|
-
* Otherwise, it wraps the error in a `VMRuntimeError` and logs the stack trace.
|
|
1109
|
-
*
|
|
1110
|
-
* @template T - The return type of the callback function, allowing flexibility
|
|
1111
|
-
* in the expected result type. Defaults to `BuildResult`.
|
|
1112
|
-
*
|
|
1113
|
-
* @param callback - A function that returns a `Promise<T>`, which is executed asynchronously.
|
|
1114
|
-
* The callback is wrapped in error handling logic to catch and process any exceptions.
|
|
1115
|
-
*
|
|
1116
|
-
* @returns A `Promise<T | void>` that resolves with the result of the callback function if successful,
|
|
1117
|
-
* or `void` if an error was thrown and handled. This allows for optional chaining on the return value.
|
|
1118
|
-
*
|
|
1119
|
-
* @throws This method does not throw explicitly but will log an error message if an exception is caught
|
|
1120
|
-
* and is not an `esbuild`-related error. The error stack is logged via `VMRuntimeError` for non-esbuild errors.
|
|
1121
|
-
*
|
|
1122
|
-
* @example
|
|
1123
|
-
* ```ts
|
|
1124
|
-
* await execute(async () => {
|
|
1125
|
-
* // Perform some asynchronous operation here
|
|
1126
|
-
* return someResult;
|
|
1127
|
-
* });
|
|
1128
|
-
* ```
|
|
1129
|
-
*/
|
|
1130
|
-
private execute;
|
|
1131
|
-
/**
|
|
1132
|
-
* Configures the development mode by ensuring that `config.dev` is set properly.
|
|
1133
|
-
*/
|
|
1134
|
-
private configureDevelopmentMode;
|
|
1135
|
-
/**
|
|
1136
|
-
* Sets up the plugin's provider and registers the plugin HooksInterface.
|
|
1137
|
-
*/
|
|
1138
|
-
private setupPlugins;
|
|
1139
|
-
/**
|
|
1140
|
-
* Registers the plugin HooksInterface for start, end, and load events.
|
|
1141
|
-
*
|
|
1142
|
-
* @param paths - The resolved path aliases.
|
|
1143
|
-
* @param rootDir - The root directory for resolving paths.
|
|
1144
|
-
*/
|
|
1145
|
-
private registerPluginHooks;
|
|
1146
|
-
/**
|
|
1147
|
-
* Generates a path alias object from the TypeScript provider's path options.
|
|
1148
|
-
* This method processes the `paths` property from the TypeScript provider's options,
|
|
1149
|
-
* which is expected to be an object where each key represents a path alias pattern,
|
|
1150
|
-
* and the corresponding value is an array of paths. The method removes any wildcard
|
|
1151
|
-
* characters (`*`) from both the keys and the first values of the arrays. It also
|
|
1152
|
-
* resolves the paths relative to the specified `rootDir`, returning a simplified
|
|
1153
|
-
* object that maps the cleaned keys to their respective paths.
|
|
1154
|
-
*
|
|
1155
|
-
* The resolved paths will be formatted to use a relative path notation.
|
|
1156
|
-
*
|
|
1157
|
-
* Example:
|
|
1158
|
-
* Given the following paths:
|
|
1159
|
-
* ```ts
|
|
1160
|
-
* {
|
|
1161
|
-
* '@core/*': ['src/core/*'],
|
|
1162
|
-
* '@utils/*': ['src/utils/*']
|
|
1163
|
-
* }
|
|
1164
|
-
* ```
|
|
1165
|
-
* And assuming `rootDir` is set to the base directory of your project, the method
|
|
1166
|
-
* will return:
|
|
1167
|
-
* ```ts
|
|
1168
|
-
* {
|
|
1169
|
-
* '@core/': './core/',
|
|
1170
|
-
* '@utils/': './utils/'
|
|
1171
|
-
* }
|
|
1172
|
-
* ```
|
|
1173
|
-
*
|
|
1174
|
-
* @param rootDir - The root directory to resolve paths against.
|
|
1175
|
-
* @returns An object mapping cleaned path aliases to their respective resolved paths.
|
|
1176
|
-
*/
|
|
1177
|
-
private generatePathAlias;
|
|
1178
|
-
/**
|
|
1179
|
-
* Handles errors during the build process.
|
|
1180
|
-
* This method processes and logs errors that occur during the esbuild process. It specifically filters out
|
|
1181
|
-
* errors related to TypeScript (`TypesError`) to prevent them from being logged, while logging all other errors
|
|
1182
|
-
* to the console. The error object is assumed to contain a list of messages, each with detailed information.
|
|
1183
|
-
*
|
|
1184
|
-
* @param esbuildError - The error object returned by esbuild, which is expected to contain an array of
|
|
1185
|
-
* error messages.
|
|
1186
|
-
*
|
|
1187
|
-
* @private
|
|
1188
|
-
*
|
|
1189
|
-
* @remarks
|
|
1190
|
-
* - TypeScript errors (denoted as `TypesError`) are skipped and not logged.
|
|
1191
|
-
* - Other errors are logged to the console with their text descriptions.
|
|
1192
|
-
*
|
|
1193
|
-
* @example
|
|
1194
|
-
* ```ts
|
|
1195
|
-
* try {
|
|
1196
|
-
* await buildService.run();
|
|
1197
|
-
* } catch (esbuildError) {
|
|
1198
|
-
* buildService.handleErrors(esbuildError);
|
|
1199
|
-
* }
|
|
1200
|
-
* ```
|
|
1201
|
-
*
|
|
1202
|
-
* In this example, if an error occurs during the build process, the `handleErrors` method is used to
|
|
1203
|
-
* process and log the errors.
|
|
1204
|
-
*/
|
|
1205
|
-
private handleErrors;
|
|
1206
|
-
/**
|
|
1207
|
-
* Injects a configuration object (banner or footer) into the `esbuild` options.
|
|
1208
|
-
* This method will update the `esbuild` object by adding or modifying the `banner` or `footer`
|
|
1209
|
-
* property based on the provided configuration.
|
|
1210
|
-
* The function handles both static values
|
|
1211
|
-
* and functions within the configuration.
|
|
1212
|
-
*
|
|
1213
|
-
* @param esbuild - The `esbuild` configuration object where the `banner` or `footer`
|
|
1214
|
-
* should be injected or updated.
|
|
1215
|
-
* @param object - The configuration object that contains the properties to inject.
|
|
1216
|
-
* The properties can either be static values or functions.
|
|
1217
|
-
* @param name - A string that determines whether the method modifies the `banner` or `footer`
|
|
1218
|
-
* property of the `esbuild` object.
|
|
1219
|
-
*
|
|
1220
|
-
* @returns void - This method does not return any value.
|
|
1221
|
-
* It modifies the `esbuild` object directly.
|
|
1222
|
-
*
|
|
1223
|
-
* @throws Error - If the `object` parameter is not provided, nothing is injected.
|
|
1224
|
-
* No action will be taken if the specific `name` property (either
|
|
1225
|
-
* 'banner' or 'footer') does not exist in the `esbuild` object.
|
|
1226
|
-
*/
|
|
1227
|
-
private injects;
|
|
1228
|
-
/**
|
|
1229
|
-
* Builds the project based on the configuration.
|
|
1230
|
-
* Depending on the configuration, this method either uses esbuild's `context` for watching or `build` for a one-time build.
|
|
1231
|
-
*
|
|
1232
|
-
* @returns A promise that resolves with the build context or result.
|
|
1233
|
-
*
|
|
1234
|
-
* @private
|
|
1235
|
-
*/
|
|
1236
|
-
private build;
|
|
1237
|
-
/**
|
|
1238
|
-
* Manages development processes for specified entry points.*
|
|
1239
|
-
* This method spawns development processes for each file in the metafile that matches any of the specified entry points.
|
|
1240
|
-
* It enables features like source maps and optional debugging mode for each spawned process.
|
|
1241
|
-
*
|
|
1242
|
-
* @param meta - The metafile containing information about build outputs.
|
|
1243
|
-
* This typically includes a mapping of output files and their dependencies.
|
|
1244
|
-
* @param entryPoint - An array of entry point file names to match against the metafile outputs.
|
|
1245
|
-
* Only files that match these entry points will have development processes spawned.
|
|
1246
|
-
* @param debug - A boolean flag to enable debugging mode for spawned processes.
|
|
1247
|
-
* If `true`, the processes will start in debug mode with the `--inspect-brk` option. Defaults to `false`.
|
|
1248
|
-
*
|
|
1249
|
-
* @returns void
|
|
1250
|
-
*
|
|
1251
|
-
* @remarks
|
|
1252
|
-
* - Files that contain 'map' in their names (e.g., source map files) are ignored and no process is spawned for them.
|
|
1253
|
-
* - For each matching file in the metafile outputs, a new development process is spawned using the `spawn` function.
|
|
1254
|
-
* - The `activePossess` array tracks all spawned processes, allowing further management (e.g., termination).
|
|
1255
|
-
*
|
|
1256
|
-
* @example
|
|
1257
|
-
* ```ts
|
|
1258
|
-
* const meta = {
|
|
1259
|
-
* outputs: {
|
|
1260
|
-
* 'dist/index.js': { \/* ... *\/ },
|
|
1261
|
-
* 'dist/index.js.map': { \/* ... *\/ }
|
|
1262
|
-
* }
|
|
1263
|
-
* };
|
|
1264
|
-
* const entryPoints = ['index'];
|
|
1265
|
-
*
|
|
1266
|
-
* this.spawnDev(meta, entryPoints, true); // Spawns processes in debug mode
|
|
1267
|
-
* ```
|
|
1268
|
-
*
|
|
1269
|
-
* @private
|
|
1270
|
-
*/
|
|
1271
|
-
private spawnDev;
|
|
1272
|
-
/**
|
|
1273
|
-
* Starts the build process and type checking.
|
|
1274
|
-
* This method performs initial setup for the build and ensures that any child processes are terminated properly.
|
|
1275
|
-
*
|
|
1276
|
-
* @private
|
|
1277
|
-
*/
|
|
1278
|
-
private start;
|
|
1279
|
-
/**
|
|
1280
|
-
* Finalizes the build process and logs results.
|
|
1281
|
-
* This method handles the end of the build process, logs build results, and processes development files if applicable.
|
|
1282
|
-
*
|
|
1283
|
-
* @private
|
|
1284
|
-
*/
|
|
1285
|
-
private end;
|
|
1286
|
-
/**
|
|
1287
|
-
* Processes and updates entry points based on project dependencies.
|
|
1288
|
-
* This method analyzes the project's dependencies and adjusts entry points configuration as needed.
|
|
1289
|
-
*
|
|
1290
|
-
* @private
|
|
1291
|
-
*/
|
|
1292
|
-
private processEntryPoints;
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
/**
|
|
1296
|
-
* Import will remove at compile time
|
|
1297
|
-
*/
|
|
1298
|
-
/**
|
|
1299
|
-
* The `BuildStateInterface` extends the `PluginsBuildStateInterface` interface to include additional properties related to the build
|
|
1300
|
-
* process, specifically for handling `ifdef` conditions and function removals in macros.
|
|
1301
|
-
*
|
|
1302
|
-
* @interface BuildStateInterface
|
|
1303
|
-
*/
|
|
1304
|
-
interface BuildStateInterface extends PluginsBuildStateInterface {
|
|
1305
|
-
ifdef: Array<string>;
|
|
1306
|
-
macros: {
|
|
1307
|
-
removeFunctions: Set<string>;
|
|
1308
|
-
};
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
/**
|
|
1312
|
-
* Custom error class to represent type-related errors.
|
|
1313
|
-
*
|
|
1314
|
-
* This class extends the built-in `Error` class to provide more specific
|
|
1315
|
-
* error handling for issues related to types. It can be used to distinguish
|
|
1316
|
-
* errors that occur due to type mismatches or other type-related problems
|
|
1317
|
-
* in your application.
|
|
1318
|
-
*
|
|
1319
|
-
* @example
|
|
1320
|
-
* ```ts
|
|
1321
|
-
* throw new TypesError('Invalid type encountered.');
|
|
1322
|
-
* ```
|
|
1323
|
-
*
|
|
1324
|
-
* @augments Error
|
|
1325
|
-
*/
|
|
1326
|
-
declare class TypesError extends Error {
|
|
1327
|
-
/**
|
|
1328
|
-
* Creates an instance of `TypesError`.
|
|
1329
|
-
*
|
|
1330
|
-
* @param message - A human-readable message providing details about the error.
|
|
1331
|
-
* @param options - Optional configuration for the error, such as a `cause` (ECMAScript 2022+).
|
|
811
|
+
* @param message - A human-readable message providing details about the error.
|
|
812
|
+
* @param options - Optional configuration for the error, such as a `cause` (ECMAScript 2022+).
|
|
1332
813
|
*/
|
|
1333
814
|
constructor(message?: string, options?: {
|
|
1334
815
|
cause?: Error;
|
|
1335
816
|
});
|
|
1336
817
|
}
|
|
1337
|
-
|
|
1338
|
-
/**
|
|
1339
|
-
* Import will remove at compile time
|
|
1340
|
-
*/
|
|
1341
818
|
/**
|
|
1342
819
|
* Spawns a new Node.js process to execute the provided JavaScript file, with optional debugging support.
|
|
1343
820
|
*
|
|
@@ -1388,101 +865,44 @@ declare class TypesError extends Error {
|
|
|
1388
865
|
* @public
|
|
1389
866
|
* @category Services
|
|
1390
867
|
*/
|
|
1391
|
-
declare function spawn(filePath: string, debug?: boolean): ChildProcessWithoutNullStreams;
|
|
1392
|
-
|
|
1393
|
-
/**
|
|
1394
|
-
* Import will remove at compile time
|
|
1395
|
-
*/
|
|
868
|
+
export declare function spawn(filePath: string, debug?: boolean): ChildProcessWithoutNullStreams;
|
|
1396
869
|
/**
|
|
1397
|
-
*
|
|
1398
|
-
* that should be removed based on specific conditions. The function searches for function declarations and variable
|
|
1399
|
-
* declarations where the function name or variable is prefixed with `$$`, and adds these function names to the
|
|
1400
|
-
* `removeFunctions` set in the provided `state` object.
|
|
870
|
+
* Represents the result of transpiling a TypeScript file.
|
|
1401
871
|
*
|
|
1402
|
-
*
|
|
1403
|
-
*
|
|
1404
|
-
* - `state`: An object representing the current build state, specifically the `mocks` state, which includes
|
|
1405
|
-
* a `removeFunctions` set that will hold the names of functions that need to be removed.
|
|
872
|
+
* This interface defines the structure of the output returned from a TypeScript transpilation process,
|
|
873
|
+
* including the transpiled JavaScript code and the associated source map.
|
|
1406
874
|
*
|
|
1407
|
-
* -
|
|
1408
|
-
*
|
|
875
|
+
* @property code - The transpiled JavaScript code generated from the TypeScript file.
|
|
876
|
+
* @property sourceMap - The source map associated with the transpiled JavaScript code.
|
|
1409
877
|
*
|
|
1410
|
-
*
|
|
1411
|
-
* - The
|
|
1412
|
-
*
|
|
878
|
+
* @remarks
|
|
879
|
+
* - The `code` property contains the JavaScript code after TypeScript transpilation.
|
|
880
|
+
* - The `sourceMap` property provides the source map that maps the transpiled JavaScript code back to the original TypeScript source.
|
|
881
|
+
* - The source map is useful for debugging as it allows developers to trace errors in the generated JavaScript back to the original TypeScript code.
|
|
1413
882
|
*
|
|
1414
|
-
* @
|
|
1415
|
-
*
|
|
1416
|
-
*
|
|
1417
|
-
*/
|
|
1418
|
-
declare function collectFunctionNames(code: string, state: BuildStateInterface['macros']): void;
|
|
1419
|
-
/**
|
|
1420
|
-
* The `collectDeclaredFunctions` function processes the provided `meta` metafile and reads each file's contents
|
|
1421
|
-
* to find function declarations within preprocessor directives. It uses regular expressions to match `// ifdef` and
|
|
1422
|
-
* `// endif` blocks in the code and collects the function names from the code inside the `ifdef` block, based on the
|
|
1423
|
-
* `define` configuration in the `config` object. If the condition defined in the `ifdef` is not met (i.e., not defined
|
|
1424
|
-
* in the `config.define`), the function names found inside the block will be collected and added to the `removeFunctions`
|
|
1425
|
-
* set in the `state` object.
|
|
1426
|
-
*
|
|
1427
|
-
* - **Input**:
|
|
1428
|
-
* - `meta`: The `Metafile` object that contains the input files. The keys are file paths, and the values contain
|
|
1429
|
-
* metadata about those files.
|
|
1430
|
-
* - `config`: The configuration object containing a `define` field, which is an object of conditions that may be used
|
|
1431
|
-
* in the `ifdef` blocks. If a condition in an `ifdef` block is not defined in `config.define`, the functions in
|
|
1432
|
-
* that block will be collected.
|
|
1433
|
-
* - `state`: The build state, specifically the `mocks` state, which includes a `removeFunctions` set that stores
|
|
1434
|
-
* function names to be removed.
|
|
1435
|
-
*
|
|
1436
|
-
* - **Output**: This function does not return a value. It modifies the `removeFunctions` set within the provided `state`
|
|
1437
|
-
* object by adding the names of functions found inside unprocessed `ifdef` blocks.
|
|
1438
|
-
*
|
|
1439
|
-
* ## Error Handling:
|
|
1440
|
-
* - If a file cannot be read due to a filesystem error, the function will throw an error.
|
|
1441
|
-
* - If the provided `meta` or `config` is malformed, it may result in runtime errors. The caller should ensure valid input.
|
|
1442
|
-
*
|
|
1443
|
-
* @param meta - The `Metafile` object containing the list of input files and their metadata.
|
|
1444
|
-
* @param config - The configuration object that defines conditions used in `ifdef` blocks.
|
|
1445
|
-
* @param state - The build state containing the `removeFunctions` set to store function names to be removed.
|
|
1446
|
-
* @returns `void` - The function modifies the `state` directly and does not return a value.
|
|
1447
|
-
*/
|
|
1448
|
-
declare function collectDeclaredFunctions(meta: Metafile, config: ConfigurationInterface, state: BuildStateInterface['macros']): Promise<void>;
|
|
1449
|
-
/**
|
|
1450
|
-
* The `parseMacros` function processes TypeScript or JavaScript files to transform macros defined within the content.
|
|
1451
|
-
* It ensures that the build state is initialized if necessary, analyzes file dependencies, collects declared functions
|
|
1452
|
-
* that are marked for removal, and applies transformations to the source code based on the macros.
|
|
1453
|
-
* If the file's extension is not `.ts` or `.js`, the function returns `undefined`. Otherwise, it transforms the code
|
|
1454
|
-
* and returns the result in the specified loader format.
|
|
883
|
+
* @example
|
|
884
|
+
* ```typescript
|
|
885
|
+
* import { TranspileFileInterface } from './TranspileFileInterface';
|
|
1455
886
|
*
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
* - `state`: The build state containing the `mocks` object, which includes a `removeFunctions` set that tracks
|
|
1461
|
-
* functions to be removed.
|
|
1462
|
-
* - `config`: The configuration object that defines how macros should be handled (e.g., conditions for macro processing).
|
|
887
|
+
* const result: TranspileFileInterface = {
|
|
888
|
+
* code: 'console.log("Hello, world!");',
|
|
889
|
+
* sourceMap: 'version: 3\nfile: out.js\nsources: ["file.ts"]\n'
|
|
890
|
+
* };
|
|
1463
891
|
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1466
|
-
*
|
|
892
|
+
* console.log(result.code); // Output: console.log("Hello, world!");
|
|
893
|
+
* console.log(result.sourceMap); // Output: version: 3\nfile: out.js\nsources: ["file.ts"]\n
|
|
894
|
+
* ```
|
|
1467
895
|
*
|
|
1468
|
-
*
|
|
1469
|
-
*
|
|
1470
|
-
* - If `state.mocks` is not initialized, it will be set up by analyzing the file dependencies and collecting declared functions.
|
|
1471
|
-
* - If any errors occur during the analysis, function collection, or transformation, the function may throw an error.
|
|
896
|
+
* In this example, the `TranspileFileInterface` is used to represent the result of transpiling a TypeScript file.
|
|
897
|
+
* The `code` contains the JavaScript code, while the `sourceMap` provides the mapping information for debugging purposes.
|
|
1472
898
|
*
|
|
1473
|
-
* @
|
|
1474
|
-
* @
|
|
1475
|
-
* @param args - The `OnLoadArgs` containing metadata, including the file path.
|
|
1476
|
-
* @param state - The build state that includes `mocks` with the `removeFunctions` set.
|
|
1477
|
-
* @param config - The configuration object defining how macros should be handled.
|
|
1478
|
-
* @returns A `Promise` that resolves to the transformed code (`OnLoadResult` or `PluginResultType`), or `undefined`
|
|
1479
|
-
* if the file is not of type `.ts` or `.js`.
|
|
1480
|
-
*/
|
|
1481
|
-
declare function parseMacros(content: string | Uint8Array, loader: Loader | undefined, args: OnLoadArgs, state: BuildStateInterface, config: ConfigurationInterface): Promise<OnLoadResult | PluginResultType | undefined>;
|
|
1482
|
-
|
|
1483
|
-
/**
|
|
1484
|
-
* Import will remove at compile time
|
|
899
|
+
* @public
|
|
900
|
+
* @category Interfaces
|
|
1485
901
|
*/
|
|
902
|
+
export interface TranspileFileInterface {
|
|
903
|
+
code: string;
|
|
904
|
+
sourceMap: string;
|
|
905
|
+
}
|
|
1486
906
|
/**
|
|
1487
907
|
* Default build options for esbuild bundler in RemoteX framework.
|
|
1488
908
|
*
|
|
@@ -1492,7 +912,7 @@ declare function parseMacros(content: string | Uint8Array, loader: Loader | unde
|
|
|
1492
912
|
* @public
|
|
1493
913
|
* @category Configuration
|
|
1494
914
|
*/
|
|
1495
|
-
declare const defaultBuildOptions: BuildOptions;
|
|
915
|
+
export declare const defaultBuildOptions: BuildOptions;
|
|
1496
916
|
/**
|
|
1497
917
|
* Extracts the source map from the provided data string and returns the modified code and source map separately.
|
|
1498
918
|
*
|
|
@@ -1506,7 +926,7 @@ declare const defaultBuildOptions: BuildOptions;
|
|
|
1506
926
|
*
|
|
1507
927
|
* @public
|
|
1508
928
|
*/
|
|
1509
|
-
declare function extractSourceMap(dataString: string): TranspileFileInterface;
|
|
929
|
+
export declare function extractSourceMap(dataString: string): TranspileFileInterface;
|
|
1510
930
|
/**
|
|
1511
931
|
* Transpiles a TypeScript file and extracts the source map.
|
|
1512
932
|
*
|
|
@@ -1521,7 +941,7 @@ declare function extractSourceMap(dataString: string): TranspileFileInterface;
|
|
|
1521
941
|
* @public
|
|
1522
942
|
* @category Services
|
|
1523
943
|
*/
|
|
1524
|
-
declare function transpileFile(filePath: string, buildOptions?: BuildOptions): Promise<TranspileFileInterface>;
|
|
944
|
+
export declare function transpileFile(filePath: string, buildOptions?: BuildOptions): Promise<TranspileFileInterface>;
|
|
1525
945
|
/**
|
|
1526
946
|
* The `analyzeDependencies` function analyzes the dependencies of a given entry point for a specified platform.
|
|
1527
947
|
* It performs a bundling operation and generates a metafile that contains detailed information about the
|
|
@@ -1554,51 +974,95 @@ declare function transpileFile(filePath: string, buildOptions?: BuildOptions): P
|
|
|
1554
974
|
* @returns A `Promise` that resolves to a `BuildResult` object along with a `metafile` containing dependency details.
|
|
1555
975
|
* @throws Error If the build process fails for any reason.
|
|
1556
976
|
*/
|
|
1557
|
-
declare function analyzeDependencies(entryPoint: EntryPointsType, platform?: BuildOptions['platform']): Promise<BuildResult & {
|
|
977
|
+
export declare function analyzeDependencies(entryPoint: EntryPointsType, platform?: BuildOptions['platform']): Promise<BuildResult & {
|
|
1558
978
|
metafile: Metafile;
|
|
1559
979
|
}>;
|
|
1560
|
-
|
|
1561
980
|
/**
|
|
1562
|
-
*
|
|
981
|
+
* The `collectFunctionNames` function analyzes the provided TypeScript code and collects the names of functions
|
|
982
|
+
* that should be removed based on specific conditions. The function searches for function declarations and variable
|
|
983
|
+
* declarations where the function name or variable is prefixed with `$$`, and adds these function names to the
|
|
984
|
+
* `removeFunctions` set in the provided `state` object.
|
|
1563
985
|
*
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
986
|
+
* - **Input**:
|
|
987
|
+
* - `code`: A string containing the TypeScript code to be analyzed.
|
|
988
|
+
* - `state`: An object representing the current build state, specifically the `mocks` state, which includes
|
|
989
|
+
* a `removeFunctions` set that will hold the names of functions that need to be removed.
|
|
1566
990
|
*
|
|
1567
|
-
*
|
|
1568
|
-
*
|
|
991
|
+
* - **Output**: The function does not return any value. Instead, it modifies the `removeFunctions` set inside the
|
|
992
|
+
* `state` object by adding function names that meet the criteria for removal.
|
|
1569
993
|
*
|
|
1570
|
-
*
|
|
1571
|
-
* - The
|
|
1572
|
-
*
|
|
1573
|
-
* - The source map is useful for debugging as it allows developers to trace errors in the generated JavaScript back to the original TypeScript code.
|
|
994
|
+
* ## Error Handling:
|
|
995
|
+
* - The function does not explicitly handle errors. If invalid TypeScript code is provided, `ts.createSourceFile`
|
|
996
|
+
* may throw an error, which should be handled by the caller if necessary.
|
|
1574
997
|
*
|
|
1575
|
-
* @
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
998
|
+
* @param code - The TypeScript code as a string that will be analyzed.
|
|
999
|
+
* @param state - The build state containing the `removeFunctions` set to store the names of functions to be removed.
|
|
1000
|
+
* @returns `void` - The function modifies the `state` directly and does not return a value.
|
|
1001
|
+
*/
|
|
1002
|
+
export declare function collectFunctionNames(code: string, state: BuildStateInterface['macros']): void;
|
|
1003
|
+
/**
|
|
1004
|
+
* The `collectDeclaredFunctions` function processes the provided `meta` metafile and reads each file's contents
|
|
1005
|
+
* to find function declarations within preprocessor directives. It uses regular expressions to match `// ifdef` and
|
|
1006
|
+
* `// endif` blocks in the code and collects the function names from the code inside the `ifdef` block, based on the
|
|
1007
|
+
* `define` configuration in the `config` object. If the condition defined in the `ifdef` is not met (i.e., not defined
|
|
1008
|
+
* in the `config.define`), the function names found inside the block will be collected and added to the `removeFunctions`
|
|
1009
|
+
* set in the `state` object.
|
|
1578
1010
|
*
|
|
1579
|
-
*
|
|
1580
|
-
*
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1011
|
+
* - **Input**:
|
|
1012
|
+
* - `meta`: The `Metafile` object that contains the input files. The keys are file paths, and the values contain
|
|
1013
|
+
* metadata about those files.
|
|
1014
|
+
* - `config`: The configuration object containing a `define` field, which is an object of conditions that may be used
|
|
1015
|
+
* in the `ifdef` blocks. If a condition in an `ifdef` block is not defined in `config.define`, the functions in
|
|
1016
|
+
* that block will be collected.
|
|
1017
|
+
* - `state`: The build state, specifically the `mocks` state, which includes a `removeFunctions` set that stores
|
|
1018
|
+
* function names to be removed.
|
|
1583
1019
|
*
|
|
1584
|
-
*
|
|
1585
|
-
*
|
|
1586
|
-
* ```
|
|
1020
|
+
* - **Output**: This function does not return a value. It modifies the `removeFunctions` set within the provided `state`
|
|
1021
|
+
* object by adding the names of functions found inside unprocessed `ifdef` blocks.
|
|
1587
1022
|
*
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1023
|
+
* ## Error Handling:
|
|
1024
|
+
* - If a file cannot be read due to a filesystem error, the function will throw an error.
|
|
1025
|
+
* - If the provided `meta` or `config` is malformed, it may result in runtime errors. The caller should ensure valid input.
|
|
1590
1026
|
*
|
|
1591
|
-
* @
|
|
1592
|
-
* @
|
|
1027
|
+
* @param meta - The `Metafile` object containing the list of input files and their metadata.
|
|
1028
|
+
* @param config - The configuration object that defines conditions used in `ifdef` blocks.
|
|
1029
|
+
* @param state - The build state containing the `removeFunctions` set to store function names to be removed.
|
|
1030
|
+
* @returns `void` - The function modifies the `state` directly and does not return a value.
|
|
1593
1031
|
*/
|
|
1594
|
-
|
|
1595
|
-
code: string;
|
|
1596
|
-
sourceMap: string;
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1032
|
+
export declare function collectDeclaredFunctions(meta: Metafile, config: ConfigurationInterface, state: BuildStateInterface['macros']): Promise<void>;
|
|
1599
1033
|
/**
|
|
1600
|
-
*
|
|
1034
|
+
* The `parseMacros` function processes TypeScript or JavaScript files to transform macros defined within the content.
|
|
1035
|
+
* It ensures that the build state is initialized if necessary, analyzes file dependencies, collects declared functions
|
|
1036
|
+
* that are marked for removal, and applies transformations to the source code based on the macros.
|
|
1037
|
+
* If the file's extension is not `.ts` or `.js`, the function returns `undefined`. Otherwise, it transforms the code
|
|
1038
|
+
* and returns the result in the specified loader format.
|
|
1039
|
+
*
|
|
1040
|
+
* - **Input**:
|
|
1041
|
+
* - `content`: The content of the file as a string or `Uint8Array` to be parsed.
|
|
1042
|
+
* - `loader`: A string representing the loader type for transforming the code (e.g., `'ts'`, `'js'`).
|
|
1043
|
+
* - `args`: The `OnLoadArgs` object containing metadata for the current loading process, including the file path.
|
|
1044
|
+
* - `state`: The build state containing the `mocks` object, which includes a `removeFunctions` set that tracks
|
|
1045
|
+
* functions to be removed.
|
|
1046
|
+
* - `config`: The configuration object that defines how macros should be handled (e.g., conditions for macro processing).
|
|
1047
|
+
*
|
|
1048
|
+
* - **Output**: A `Promise` that resolves to an `OnLoadResult`, `PluginResultType`, or `undefined`. If the file is
|
|
1049
|
+
* of type `.ts` or `.js`, the transformed code is returned in the specified loader format (e.g., `'ts'`). If the file
|
|
1050
|
+
* extension is not recognized, the function returns `undefined`.
|
|
1051
|
+
*
|
|
1052
|
+
* ## Error Handling:
|
|
1053
|
+
* - If the file path does not end with `.ts` or `.js`, the function returns `undefined`.
|
|
1054
|
+
* - If `state.mocks` is not initialized, it will be set up by analyzing the file dependencies and collecting declared functions.
|
|
1055
|
+
* - If any errors occur during the analysis, function collection, or transformation, the function may throw an error.
|
|
1056
|
+
*
|
|
1057
|
+
* @param content - The content of the file as a string or `Uint8Array` to be parsed.
|
|
1058
|
+
* @param loader - The loader type for transforming the code (e.g., `'ts'` or `'js'`).
|
|
1059
|
+
* @param args - The `OnLoadArgs` containing metadata, including the file path.
|
|
1060
|
+
* @param state - The build state that includes `mocks` with the `removeFunctions` set.
|
|
1061
|
+
* @param config - The configuration object defining how macros should be handled.
|
|
1062
|
+
* @returns A `Promise` that resolves to the transformed code (`OnLoadResult` or `PluginResultType`), or `undefined`
|
|
1063
|
+
* if the file is not of type `.ts` or `.js`.
|
|
1601
1064
|
*/
|
|
1065
|
+
export declare function parseMacros(content: string | Uint8Array, loader: Loader | undefined, args: OnLoadArgs, state: BuildStateInterface, config: ConfigurationInterface): Promise<OnLoadResult | PluginResultType | undefined>;
|
|
1602
1066
|
/**
|
|
1603
1067
|
* Represents an error that occurs during the esbuild process.
|
|
1604
1068
|
*
|
|
@@ -1609,7 +1073,7 @@ interface TranspileFileInterface {
|
|
|
1609
1073
|
* @class esBuildError
|
|
1610
1074
|
* @extends BaseError
|
|
1611
1075
|
*/
|
|
1612
|
-
declare class esBuildError extends BaseError {
|
|
1076
|
+
export declare class esBuildError extends BaseError {
|
|
1613
1077
|
originalErrorStack?: string;
|
|
1614
1078
|
/**
|
|
1615
1079
|
* Creates an instance of the EsbuildError class.
|
|
@@ -1649,10 +1113,6 @@ declare class esBuildError extends BaseError {
|
|
|
1649
1113
|
*/
|
|
1650
1114
|
private applyColor;
|
|
1651
1115
|
}
|
|
1652
|
-
|
|
1653
|
-
/**
|
|
1654
|
-
* Imports
|
|
1655
|
-
*/
|
|
1656
1116
|
/**
|
|
1657
1117
|
* ASCII Logo and Version Information
|
|
1658
1118
|
*
|
|
@@ -1663,8 +1123,8 @@ declare class esBuildError extends BaseError {
|
|
|
1663
1123
|
*
|
|
1664
1124
|
* The `cleanScreen` constant contains an ANSI escape code to clear the terminal screen.
|
|
1665
1125
|
*/
|
|
1666
|
-
declare const asciiLogo = "\n ______ _ _ _\n | ___ \\ (_) | | |\n__ _| |_/ /_ _ _| | __| |\n\\ \\/ / ___ \\ | | | | |/ _` |\n > <| |_/ / |_| | | | (_| |\n/_/\\_\\____/ \\__,_|_|_|\\__,_|\n";
|
|
1667
|
-
declare const cleanScreen = "\u001Bc";
|
|
1126
|
+
export declare const asciiLogo = "\n ______ _ _ _\n | ___ \\ (_) | | |\n__ _| |_/ /_ _ _| | __| |\n\\ \\/ / ___ \\ | | | | |/ _` |\n > <| |_/ / |_| | | | (_| |\n/_/\\_\\____/ \\__,_|_|_|\\__,_|\n";
|
|
1127
|
+
export declare const cleanScreen = "\u001Bc";
|
|
1668
1128
|
/**
|
|
1669
1129
|
* Renders the banner with the ASCII logo and version information.
|
|
1670
1130
|
*
|
|
@@ -1697,16 +1157,12 @@ declare const cleanScreen = "\u001Bc";
|
|
|
1697
1157
|
*
|
|
1698
1158
|
* @public
|
|
1699
1159
|
*/
|
|
1700
|
-
declare function bannerComponent(activeColor?: boolean): string;
|
|
1160
|
+
export declare function bannerComponent(activeColor?: boolean): string;
|
|
1701
1161
|
/**
|
|
1702
1162
|
* A formatted string prefix used for logging build-related messages.
|
|
1703
1163
|
* // todo optimize this
|
|
1704
1164
|
*/
|
|
1705
|
-
declare function prefix(): string;
|
|
1706
|
-
|
|
1707
|
-
/**
|
|
1708
|
-
* Import will remove at compile time
|
|
1709
|
-
*/
|
|
1165
|
+
export declare function prefix(): string;
|
|
1710
1166
|
/**
|
|
1711
1167
|
* Manages the HTTP or HTTPS server based on the provided configuration.
|
|
1712
1168
|
*
|
|
@@ -1716,7 +1172,7 @@ declare function prefix(): string;
|
|
|
1716
1172
|
*
|
|
1717
1173
|
* @class
|
|
1718
1174
|
*/
|
|
1719
|
-
declare class ServerProvider {
|
|
1175
|
+
export declare class ServerProvider {
|
|
1720
1176
|
/**
|
|
1721
1177
|
* Root dir to serve
|
|
1722
1178
|
*/
|
|
@@ -1911,15 +1367,11 @@ declare class ServerProvider {
|
|
|
1911
1367
|
*/
|
|
1912
1368
|
private sendError;
|
|
1913
1369
|
}
|
|
1914
|
-
|
|
1915
|
-
/**
|
|
1916
|
-
* Import will remove at compile time
|
|
1917
|
-
*/
|
|
1918
1370
|
/**
|
|
1919
1371
|
* Plugin provider for esbuild that registers hooks for lifecycle events such as onStart, onEnd, onResolve, and onLoad.
|
|
1920
1372
|
* This class allows dynamic behavior by registering multiple hooks for different stages of the build process.
|
|
1921
1373
|
*/
|
|
1922
|
-
declare class PluginsProvider {
|
|
1374
|
+
export declare class PluginsProvider {
|
|
1923
1375
|
/**
|
|
1924
1376
|
* Holds the build state that hooks can modify.
|
|
1925
1377
|
*/
|
|
@@ -2133,7 +1585,6 @@ declare class PluginsProvider {
|
|
|
2133
1585
|
*/
|
|
2134
1586
|
private handleOnLoad;
|
|
2135
1587
|
}
|
|
2136
|
-
|
|
2137
1588
|
/**
|
|
2138
1589
|
* Parses and filters content based on conditional directives.
|
|
2139
1590
|
*
|
|
@@ -2146,890 +1597,1237 @@ declare class PluginsProvider {
|
|
|
2146
1597
|
* @returns The processed code contents with conditional blocks removed
|
|
2147
1598
|
* according to the `defines` object.
|
|
2148
1599
|
*/
|
|
2149
|
-
declare function parseIfDefConditionals(contents: string, defines: Record<string, unknown>): string;
|
|
2150
|
-
|
|
1600
|
+
export declare function parseIfDefConditionals(contents: string, defines: Record<string, unknown>): string;
|
|
1601
|
+
/**
|
|
1602
|
+
* Represents the result of a TypeScript compilation emit operation.
|
|
1603
|
+
*
|
|
1604
|
+
* @property outputFile - The emitted output file information,
|
|
1605
|
+
* or undefined if no file was emitted. Contains details such as file name, content,
|
|
1606
|
+
* and any related metadata.
|
|
1607
|
+
*
|
|
1608
|
+
* @property emitSkipped - Indicates whether the emit operation was skipped.
|
|
1609
|
+
* When true, typically indicates compilation errors prevented emission or the operation
|
|
1610
|
+
* was explicitly configured to skip emission.
|
|
1611
|
+
*
|
|
1612
|
+
* @remarks
|
|
1613
|
+
* This interface is used to represent the result of TypeScript declaration emit operations.
|
|
1614
|
+
*
|
|
1615
|
+
* @since 1.5.9
|
|
1616
|
+
*/
|
|
1617
|
+
export interface EmitOutputInterface {
|
|
1618
|
+
outputFile: OutputFile | undefined;
|
|
1619
|
+
emitSkipped: boolean;
|
|
1620
|
+
}
|
|
2151
1621
|
/**
|
|
2152
|
-
*
|
|
1622
|
+
* A host object that provides formatting functionality for typescript diagnostic messages
|
|
1623
|
+
*
|
|
1624
|
+
* @remarks
|
|
1625
|
+
* This constant implements the FormatDiagnosticsHost interface from TypeScript,
|
|
1626
|
+
* providing methods needed for proper diagnostic message formatting.
|
|
1627
|
+
*
|
|
1628
|
+
* @default Uses TypeScript's system utilities for line breaks and directory information
|
|
1629
|
+
*
|
|
1630
|
+
* @see FormatDiagnosticsHost - The TypeScript interface this implements
|
|
1631
|
+
*
|
|
1632
|
+
* @since 1.5.9
|
|
2153
1633
|
*/
|
|
1634
|
+
export declare const formatHost: FormatDiagnosticsHost;
|
|
2154
1635
|
/**
|
|
2155
|
-
*
|
|
2156
|
-
* language service API.
|
|
1636
|
+
* Header text included at the top of generated declaration bundle files
|
|
2157
1637
|
*
|
|
2158
1638
|
* @remarks
|
|
2159
|
-
* This
|
|
2160
|
-
*
|
|
2161
|
-
*
|
|
1639
|
+
* This constant provides a standardized header comment that prepended to all
|
|
1640
|
+
* declaration bundle files generated by the DeclarationBundlerService. The header
|
|
1641
|
+
* clearly indicates that the file was automatically generated and should not be
|
|
1642
|
+
* edited manually.
|
|
2162
1643
|
*
|
|
2163
|
-
* @
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* const bundledContent = `${HeaderDeclarationBundle}${actualContent}`;
|
|
1647
|
+
* writeFileSync('dist/index.d.ts', bundledContent);
|
|
1648
|
+
* ```
|
|
1649
|
+
*
|
|
1650
|
+
* @since 1.5.9
|
|
1651
|
+
*/
|
|
1652
|
+
export declare const HeaderDeclarationBundle = "\n/**\n * This file was automatically generated by xBuild.\n * DO NOT EDIT MANUALLY.\n */\n ";
|
|
1653
|
+
/**
|
|
1654
|
+
* Service that implements TypeScript's language service host interfaces required for compiler operations.
|
|
1655
|
+
* This class provides the necessary methods for the TypeScript language service to interact with the
|
|
1656
|
+
* file system and manage compilation resources.
|
|
1657
|
+
*
|
|
1658
|
+
* @remarks
|
|
1659
|
+
* This service implements the TypeScript LanguageServiceHost interface, which is required
|
|
1660
|
+
* for creating a TypeScript language service using ts.createLanguageService().
|
|
1661
|
+
*
|
|
1662
|
+
* @see ts.LanguageServiceHost
|
|
2164
1663
|
* @see ts.createLanguageService
|
|
2165
1664
|
*
|
|
2166
1665
|
* @since 1.5.9
|
|
2167
1666
|
*/
|
|
2168
|
-
declare class
|
|
1667
|
+
export declare class LanguageHostService {
|
|
1668
|
+
private readonly options;
|
|
2169
1669
|
/**
|
|
2170
|
-
*
|
|
1670
|
+
* Map to track file versions for detecting changes in source files.
|
|
1671
|
+
* Keys are absolute file paths and values are incrementing version numbers.
|
|
1672
|
+
*
|
|
2171
1673
|
* @since 1.5.9
|
|
2172
1674
|
*/
|
|
2173
|
-
readonly
|
|
1675
|
+
private readonly fileVersions;
|
|
2174
1676
|
/**
|
|
2175
|
-
*
|
|
1677
|
+
* Creates a new language host service with TypeScript compiler options.
|
|
1678
|
+
*
|
|
1679
|
+
* @param options - Compiler options to use for TypeScript operations
|
|
1680
|
+
*
|
|
2176
1681
|
* @since 1.5.9
|
|
2177
1682
|
*/
|
|
2178
|
-
|
|
1683
|
+
constructor(options: CompilerOptions);
|
|
2179
1684
|
/**
|
|
2180
|
-
*
|
|
1685
|
+
* Increments the version number of a file to indicate it has changed.
|
|
1686
|
+
* Used to signal to the language service that a file needs to be reprocessed.
|
|
1687
|
+
*
|
|
1688
|
+
* @param touchFiles - Path to the file that has been modified
|
|
1689
|
+
*
|
|
2181
1690
|
* @since 1.5.9
|
|
2182
1691
|
*/
|
|
2183
|
-
|
|
1692
|
+
touchFiles(touchFiles: string): void;
|
|
2184
1693
|
/**
|
|
2185
|
-
*
|
|
1694
|
+
* Checks if a file exists at the specified path.
|
|
1695
|
+
* Required by the LanguageServiceHost interface.
|
|
1696
|
+
*
|
|
1697
|
+
* @param path - Path to check for file existence
|
|
1698
|
+
* @returns True if the file exists, false otherwise
|
|
1699
|
+
*
|
|
1700
|
+
* @see ts.LanguageServiceHost.fileExists
|
|
2186
1701
|
* @since 1.5.9
|
|
2187
1702
|
*/
|
|
2188
|
-
|
|
1703
|
+
fileExists(path: string): boolean;
|
|
2189
1704
|
/**
|
|
2190
|
-
*
|
|
2191
|
-
*
|
|
2192
|
-
* @remarks
|
|
2193
|
-
* This service instance handles the bundling of TypeScript declaration files (.d.ts)
|
|
2194
|
-
* by traversing the dependency graph starting from entry points, collecting exports,
|
|
2195
|
-
* and generating single bundled declaration files.
|
|
1705
|
+
* Reads the content of a file at the specified path.
|
|
1706
|
+
* Required by the LanguageServiceHost interface.
|
|
2196
1707
|
*
|
|
2197
|
-
* @
|
|
1708
|
+
* @param path - Path to the file to read
|
|
1709
|
+
* @param encoding - Optional encoding to use when reading the file
|
|
1710
|
+
* @returns The content of the file as a string, or undefined if the file cannot be read
|
|
2198
1711
|
*
|
|
1712
|
+
* @see ts.LanguageServiceHost.readFile
|
|
2199
1713
|
* @since 1.5.9
|
|
2200
1714
|
*/
|
|
2201
|
-
|
|
1715
|
+
readFile(path: string, encoding?: string): string | undefined;
|
|
2202
1716
|
/**
|
|
2203
|
-
*
|
|
2204
|
-
*
|
|
2205
|
-
* @param tsconfigPath - Path to the tsconfig.json file
|
|
2206
|
-
* @param outDir - Optional output directory to override the one in tsconfig
|
|
2207
|
-
* @param fallbackOutDir - Optional fallback output directory to use if outDir is not specified in tsconfig or outDir
|
|
1717
|
+
* Reads the contents of a directory with filtering options.
|
|
1718
|
+
* Required by the LanguageServiceHost interface.
|
|
2208
1719
|
*
|
|
2209
|
-
* @
|
|
1720
|
+
* @param path - Path to the directory to read
|
|
1721
|
+
* @param extensions - Optional array of file extensions to filter by
|
|
1722
|
+
* @param exclude - Optional array of glob patterns to exclude
|
|
1723
|
+
* @param include - Optional array of glob patterns to include
|
|
1724
|
+
* @param depth - Optional maximum depth to search
|
|
1725
|
+
* @returns Array of file paths found in the directory
|
|
2210
1726
|
*
|
|
1727
|
+
* @see ts.LanguageServiceHost.readDirectory
|
|
2211
1728
|
* @since 1.5.9
|
|
2212
1729
|
*/
|
|
2213
|
-
|
|
1730
|
+
readDirectory(path: string, extensions?: Array<string>, exclude?: Array<string>, include?: Array<string>, depth?: number): Array<string>;
|
|
2214
1731
|
/**
|
|
2215
|
-
*
|
|
1732
|
+
* Gets all subdirectories within a directory.
|
|
1733
|
+
* Required by the LanguageServiceHost interface.
|
|
2216
1734
|
*
|
|
2217
|
-
* @param
|
|
1735
|
+
* @param path - Path to the directory to search
|
|
1736
|
+
* @returns Array of directory paths found
|
|
2218
1737
|
*
|
|
1738
|
+
* @see ts.LanguageServiceHost.getDirectories
|
|
2219
1739
|
* @since 1.5.9
|
|
2220
1740
|
*/
|
|
2221
|
-
|
|
1741
|
+
getDirectories(path: string): Array<string>;
|
|
2222
1742
|
/**
|
|
2223
|
-
*
|
|
1743
|
+
* Checks if a directory exists at the specified path.
|
|
2224
1744
|
*
|
|
2225
|
-
* @
|
|
1745
|
+
* @param path - Path to check for directory existence
|
|
1746
|
+
* @returns True if the directory exists, false otherwise
|
|
2226
1747
|
*
|
|
2227
1748
|
* @since 1.5.9
|
|
2228
1749
|
*/
|
|
2229
|
-
|
|
1750
|
+
directoryExists(path: string): boolean;
|
|
2230
1751
|
/**
|
|
2231
|
-
*
|
|
1752
|
+
* Gets the current working directory.
|
|
1753
|
+
* Required by the LanguageServiceHost interface.
|
|
2232
1754
|
*
|
|
2233
|
-
* @
|
|
1755
|
+
* @returns The current working directory path
|
|
2234
1756
|
*
|
|
1757
|
+
* @see ts.LanguageServiceHost.getCurrentDirectory
|
|
2235
1758
|
* @since 1.5.9
|
|
2236
1759
|
*/
|
|
2237
|
-
|
|
1760
|
+
getCurrentDirectory(): string;
|
|
2238
1761
|
/**
|
|
2239
|
-
*
|
|
2240
|
-
*
|
|
2241
|
-
* @param entryPoints - Record mapping output filenames to source file paths
|
|
1762
|
+
* Gets all script file names tracked by this language host.
|
|
1763
|
+
* Required by the LanguageServiceHost interface to identify the set of source files.
|
|
2242
1764
|
*
|
|
2243
|
-
* @
|
|
2244
|
-
* @throws Error - If file system operations fail during writing
|
|
1765
|
+
* @returns Array of script file paths that should be included in the program
|
|
2245
1766
|
*
|
|
2246
|
-
* @
|
|
2247
|
-
*
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
1767
|
+
* @see ts.LanguageServiceHost.getScriptFileNames
|
|
1768
|
+
* @since 1.5.9
|
|
1769
|
+
*/
|
|
1770
|
+
getScriptFileNames(): Array<string>;
|
|
1771
|
+
/**
|
|
1772
|
+
* Gets the compiler options used by this language host.
|
|
1773
|
+
* Required by the LanguageServiceHost interface to configure the TypeScript compiler.
|
|
2251
1774
|
*
|
|
2252
|
-
* The
|
|
2253
|
-
* exist before writing the output files. If the output filename doesn't end with
|
|
2254
|
-
* '.d.ts', the extension will be appended automatically.
|
|
1775
|
+
* @returns The compiler options for program creation
|
|
2255
1776
|
*
|
|
2256
|
-
* @
|
|
2257
|
-
*
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
*
|
|
2262
|
-
*
|
|
2263
|
-
* ```
|
|
1777
|
+
* @see ts.LanguageServiceHost.getCompilationSettings
|
|
1778
|
+
* @since 1.5.9
|
|
1779
|
+
*/
|
|
1780
|
+
getCompilationSettings(): CompilerOptions;
|
|
1781
|
+
/**
|
|
1782
|
+
* Gets the default library file name for TypeScript compilation.
|
|
1783
|
+
* Required by the LanguageServiceHost interface to include standard TypeScript definitions.
|
|
2264
1784
|
*
|
|
2265
|
-
* @
|
|
1785
|
+
* @param options - Compiler options to use for determining the default library
|
|
1786
|
+
* @returns Path to the default library file
|
|
2266
1787
|
*
|
|
1788
|
+
* @see ts.LanguageServiceHost.getDefaultLibFileName
|
|
2267
1789
|
* @since 1.5.9
|
|
2268
1790
|
*/
|
|
2269
|
-
|
|
1791
|
+
getDefaultLibFileName(options: CompilerOptions): string;
|
|
2270
1792
|
/**
|
|
2271
|
-
*
|
|
1793
|
+
* Gets the current version of a script file.
|
|
1794
|
+
* Required by the LanguageServiceHost interface to determine if a file has changed.
|
|
2272
1795
|
*
|
|
2273
|
-
* @param
|
|
2274
|
-
* @returns
|
|
1796
|
+
* @param fileName - Path to the script file
|
|
1797
|
+
* @returns The version of the file as a string
|
|
2275
1798
|
*
|
|
2276
|
-
* @
|
|
2277
|
-
*
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
*
|
|
1799
|
+
* @see ts.LanguageServiceHost.getScriptVersion
|
|
1800
|
+
* @since 1.5.9
|
|
1801
|
+
*/
|
|
1802
|
+
getScriptVersion(fileName: string): string;
|
|
1803
|
+
/**
|
|
1804
|
+
* Gets a script snapshot for a file which represents its content.
|
|
1805
|
+
* Required by the LanguageServiceHost interface to provide file content to the language service.
|
|
2282
1806
|
*
|
|
2283
|
-
*
|
|
2284
|
-
*
|
|
1807
|
+
* @param fileName - Path to the script file
|
|
1808
|
+
* @returns A script snapshot object or undefined if the file doesn't exist or can't be read
|
|
2285
1809
|
*
|
|
2286
|
-
*
|
|
1810
|
+
* @see ts.LanguageServiceHost.getScriptSnapshot
|
|
1811
|
+
* @see ts.IScriptSnapshot
|
|
1812
|
+
* @since 1.5.9
|
|
1813
|
+
*/
|
|
1814
|
+
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined;
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Service responsible for bundling TypeScript declaration files by collecting
|
|
1818
|
+
* all exports from entry points and generating a single declaration bundle
|
|
1819
|
+
*
|
|
1820
|
+
* @throws Error - If the language service program is not available
|
|
1821
|
+
* @throws Error - If a source file cannot be found
|
|
1822
|
+
*
|
|
1823
|
+
* @remarks
|
|
1824
|
+
* This service handles the process of bundling TypeScript declaration files (.d.ts)
|
|
1825
|
+
* by traversing the dependency graph starting from specified entry points.
|
|
1826
|
+
* It collects all necessary files and symbols, processes their declarations,
|
|
1827
|
+
* and generates a single bundled declaration file that can be used in place
|
|
1828
|
+
* of multiple individual declaration files.
|
|
1829
|
+
*
|
|
1830
|
+
* The service maintains a cache of processed files to improve performance
|
|
1831
|
+
* when processing multiple entry points or when called multiple times.
|
|
1832
|
+
*
|
|
1833
|
+
* @example
|
|
1834
|
+
* ```ts
|
|
1835
|
+
* const bundler = new DeclarationBundlerService(config, languageService);
|
|
1836
|
+
* const bundledDeclarations = bundler.emitBundledDeclarations(['src/index.ts']);
|
|
1837
|
+
* writeFileSync('dist/index.d.ts', bundledDeclarations[0]);
|
|
1838
|
+
* ```
|
|
1839
|
+
*
|
|
1840
|
+
* @see ts.LanguageService
|
|
1841
|
+
* @see ts.ParsedCommandLine
|
|
1842
|
+
*
|
|
1843
|
+
* @since 1.5.9
|
|
1844
|
+
*/
|
|
1845
|
+
export declare class DeclarationBundlerService {
|
|
1846
|
+
private readonly config;
|
|
1847
|
+
private readonly languageService;
|
|
1848
|
+
/**
|
|
1849
|
+
* Creates a new DeclarationBundlerService instance
|
|
2287
1850
|
*
|
|
2288
|
-
* @
|
|
2289
|
-
*
|
|
2290
|
-
* const ts = new TypescriptModule('tsconfig.json');
|
|
2291
|
-
* const diagnostics = ts.check();
|
|
2292
|
-
* const formattedMessages = ts.formatDiagnostics(diagnostics);
|
|
2293
|
-
* console.log(formattedMessages.join('\n'));
|
|
2294
|
-
* ```
|
|
1851
|
+
* @param config - TypeScript configuration with compiler options
|
|
1852
|
+
* @param languageService - TypeScript language service for compilation
|
|
2295
1853
|
*
|
|
2296
1854
|
* @since 1.5.9
|
|
2297
1855
|
*/
|
|
2298
|
-
|
|
1856
|
+
constructor(config: ParsedCommandLine, languageService: LanguageService);
|
|
2299
1857
|
/**
|
|
2300
|
-
* Generates
|
|
2301
|
-
*
|
|
2302
|
-
* @param fileName - The path to the TypeScript file for which to generate declaration output
|
|
2303
|
-
* @returns The result of the emit operation, including the declaration file content or an indication that emit was skipped
|
|
1858
|
+
* Generates bundled declaration files for the provided entry points
|
|
2304
1859
|
*
|
|
2305
|
-
* @
|
|
1860
|
+
* @param entryPoints - Array of file paths to use as entry points
|
|
1861
|
+
* @returns Array of bundled declaration content strings
|
|
2306
1862
|
*
|
|
2307
|
-
* @
|
|
2308
|
-
*
|
|
1863
|
+
* @remarks
|
|
1864
|
+
* This method clears any existing cache and processes each entry point
|
|
1865
|
+
* to generate bundled declarations. Entry points should be absolute paths
|
|
1866
|
+
* to TypeScript source files.
|
|
2309
1867
|
*
|
|
2310
1868
|
* @since 1.5.9
|
|
2311
1869
|
*/
|
|
2312
|
-
|
|
1870
|
+
emitBundledDeclarations(entryPoints: Array<string>): Array<string>;
|
|
2313
1871
|
/**
|
|
2314
|
-
*
|
|
2315
|
-
*
|
|
2316
|
-
* @param specifier - The module specifier string to resolve
|
|
2317
|
-
* @returns The resolved file path relative to the root directory, or undefined if resolution fails
|
|
1872
|
+
* Generates a bundled declaration for a single entry point
|
|
2318
1873
|
*
|
|
2319
|
-
* @
|
|
2320
|
-
*
|
|
2321
|
-
* into an actual file path. It specifically filters out node_modules dependencies and ensures
|
|
2322
|
-
* paths are relative to the project's root directory.
|
|
1874
|
+
* @param entryPath - Path to the entry point file
|
|
1875
|
+
* @returns Bundled declaration content or undefined if generation fails
|
|
2323
1876
|
*
|
|
2324
|
-
*
|
|
2325
|
-
*
|
|
2326
|
-
* - All paths will be calculated relative to 'src', not the project root
|
|
2327
|
-
* - For example, with project structure:
|
|
2328
|
-
* ```text
|
|
2329
|
-
* /project-root/
|
|
2330
|
-
* ├── src/
|
|
2331
|
-
* │ ├── components/
|
|
2332
|
-
* │ │ └── button.ts
|
|
2333
|
-
* │ └── utils/
|
|
2334
|
-
* │ └── helpers.ts
|
|
2335
|
-
* └── tsconfig.json
|
|
2336
|
-
* ```
|
|
2337
|
-
* - A resolved path might be 'components/button.ts' relative to 'src'
|
|
2338
|
-
* - This maintains proper path structure for TypeScript's internal module resolution
|
|
1877
|
+
* @throws EntryPointError - When the specified entry point file cannot be found
|
|
1878
|
+
* @throws CompilationError - When the TypeScript program cannot be accessed
|
|
2339
1879
|
*
|
|
2340
|
-
* @
|
|
2341
|
-
*
|
|
2342
|
-
*
|
|
2343
|
-
*
|
|
2344
|
-
* // Might return 'components/button.ts' (relative to src/)
|
|
2345
|
-
* ```
|
|
1880
|
+
* @remarks
|
|
1881
|
+
* This method processes a single entry point to generate a bundled declaration file.
|
|
1882
|
+
* It collects all necessary files and exported symbols, processes them, and
|
|
1883
|
+
* combines them into a single declaration output.
|
|
2346
1884
|
*
|
|
2347
|
-
*
|
|
1885
|
+
* The method requires that the entry point file exists and is included in the
|
|
1886
|
+
* TypeScript project configuration.
|
|
2348
1887
|
*
|
|
2349
1888
|
* @since 1.5.9
|
|
2350
1889
|
*/
|
|
2351
|
-
private
|
|
1890
|
+
private generateBundledDeclaration;
|
|
2352
1891
|
/**
|
|
2353
|
-
*
|
|
1892
|
+
* Resolves a module name to its file path
|
|
2354
1893
|
*
|
|
2355
|
-
* @param
|
|
2356
|
-
* @param
|
|
2357
|
-
* @
|
|
1894
|
+
* @param moduleName - The module name to resolve
|
|
1895
|
+
* @param containingFile - The file containing the import
|
|
1896
|
+
* @param program - The TypeScript program
|
|
2358
1897
|
*
|
|
2359
|
-
* @
|
|
2360
|
-
* This private method computes a relative path from one file to another in the output directory,
|
|
2361
|
-
* ensuring the path is properly formatted for JavaScript module imports.
|
|
1898
|
+
* @returns The resolved file path or undefined if resolution fails
|
|
2362
1899
|
*
|
|
2363
|
-
*
|
|
2364
|
-
|
|
1900
|
+
* @since 1.5.9
|
|
1901
|
+
*/
|
|
1902
|
+
private resolveModule;
|
|
1903
|
+
/**
|
|
1904
|
+
* Recursively collects all files by following imports and exports
|
|
2365
1905
|
*
|
|
2366
|
-
* @
|
|
2367
|
-
*
|
|
2368
|
-
*
|
|
2369
|
-
*
|
|
2370
|
-
*
|
|
2371
|
-
*
|
|
2372
|
-
*
|
|
2373
|
-
* ```
|
|
1906
|
+
* @param sourceFile - The source file to process
|
|
1907
|
+
* @param program - The TypeScript program
|
|
1908
|
+
* @param collectedFiles - Set of collected file paths
|
|
1909
|
+
*
|
|
1910
|
+
* @remarks
|
|
1911
|
+
* This method traverses the dependency graph starting from the provided source file
|
|
1912
|
+
* and collects all files that contribute to the final bundle, excluding node_modules.
|
|
2374
1913
|
*
|
|
2375
1914
|
* @since 1.5.9
|
|
2376
1915
|
*/
|
|
2377
|
-
private
|
|
1916
|
+
private collectFilesRecursive;
|
|
2378
1917
|
/**
|
|
2379
|
-
*
|
|
1918
|
+
* Recursively collects exports from a module symbol
|
|
2380
1919
|
*
|
|
2381
|
-
* @param
|
|
2382
|
-
* @param
|
|
2383
|
-
* @
|
|
1920
|
+
* @param symbol - The module symbol to process
|
|
1921
|
+
* @param checker - The TypeScript type checker
|
|
1922
|
+
* @param collectedSymbols - Set of collected symbol names
|
|
2384
1923
|
*
|
|
2385
1924
|
* @remarks
|
|
2386
|
-
* This
|
|
2387
|
-
*
|
|
2388
|
-
* correctly point to the compiled output files.
|
|
1925
|
+
* This method collects all exported symbols from a module, including
|
|
1926
|
+
* nested module exports for namespace declarations.
|
|
2389
1927
|
*
|
|
2390
|
-
*
|
|
2391
|
-
|
|
1928
|
+
* @since 1.5.9
|
|
1929
|
+
*/
|
|
1930
|
+
private collectExportsRecursive;
|
|
1931
|
+
/**
|
|
1932
|
+
* Processes all collected files and extracts their declarations
|
|
2392
1933
|
*
|
|
2393
|
-
*
|
|
2394
|
-
*
|
|
2395
|
-
*
|
|
2396
|
-
* - This ensures imports continue to work correctly after compilation
|
|
1934
|
+
* @param collectedFiles - Set of file paths to process
|
|
1935
|
+
* @param collectedSymbols - Set of exported symbol names
|
|
1936
|
+
* @returns Object containing bundled content and external imports
|
|
2397
1937
|
*
|
|
2398
1938
|
* @since 1.5.9
|
|
2399
1939
|
*/
|
|
2400
|
-
private
|
|
1940
|
+
private processDeclaredFiles;
|
|
2401
1941
|
/**
|
|
2402
|
-
*
|
|
1942
|
+
* Collects all exported symbols from a source file
|
|
2403
1943
|
*
|
|
2404
|
-
* @param
|
|
2405
|
-
* @param
|
|
2406
|
-
* @param
|
|
1944
|
+
* @param sourceFile - The source file to process
|
|
1945
|
+
* @param checker - The TypeScript type checker
|
|
1946
|
+
* @param collectedSymbols - Set to store collected symbol names
|
|
2407
1947
|
*
|
|
2408
|
-
* @
|
|
1948
|
+
* @since 1.5.9
|
|
1949
|
+
*/
|
|
1950
|
+
private collectExportsFromSourceFile;
|
|
1951
|
+
/**
|
|
1952
|
+
* Processes a declaration file to extract its content
|
|
2409
1953
|
*
|
|
2410
|
-
* @
|
|
1954
|
+
* @param fileName - Path to the declaration file
|
|
1955
|
+
* @param collectedSymbols - Set of exported symbol names
|
|
1956
|
+
* @param externalImports - Set to store external import statements
|
|
1957
|
+
* @returns Processed declaration content or undefined if processing fails
|
|
1958
|
+
*
|
|
1959
|
+
* @remarks
|
|
1960
|
+
* This method processes a single declaration file, filtering its content
|
|
1961
|
+
* to include only relevant declarations and collecting external imports.
|
|
1962
|
+
* It uses a cache to avoid reprocessing the same file multiple times.
|
|
2411
1963
|
*
|
|
2412
1964
|
* @since 1.5.9
|
|
2413
1965
|
*/
|
|
2414
|
-
private
|
|
1966
|
+
private processDeclarationFile;
|
|
2415
1967
|
/**
|
|
2416
|
-
*
|
|
1968
|
+
* Checks if a line is an import or export statement with a from clause
|
|
2417
1969
|
*
|
|
2418
|
-
* @
|
|
1970
|
+
* @param line - The line to check
|
|
1971
|
+
* @returns True if the line is an import or export with from clause
|
|
2419
1972
|
*
|
|
2420
|
-
* @see ts.createLanguageService
|
|
2421
1973
|
* @since 1.5.9
|
|
2422
1974
|
*/
|
|
2423
|
-
private
|
|
1975
|
+
private isImportOrExportWithFrom;
|
|
2424
1976
|
/**
|
|
2425
|
-
*
|
|
1977
|
+
* Extracts the module path from an import or export statement
|
|
1978
|
+
*
|
|
1979
|
+
* @param line - The import or export statement
|
|
1980
|
+
* @returns The extracted module path or undefined if not found
|
|
1981
|
+
*
|
|
2426
1982
|
* @since 1.5.9
|
|
2427
1983
|
*/
|
|
2428
|
-
private
|
|
1984
|
+
private extractModulePath;
|
|
2429
1985
|
/**
|
|
2430
|
-
*
|
|
1986
|
+
* Determines if a module is external (from node_modules)
|
|
2431
1987
|
*
|
|
2432
|
-
* @param
|
|
2433
|
-
* @
|
|
1988
|
+
* @param modulePath - The module path to check
|
|
1989
|
+
* @param fileName - The file containing the import
|
|
1990
|
+
* @returns True if the module is external
|
|
2434
1991
|
*
|
|
2435
1992
|
* @remarks
|
|
2436
|
-
* This method
|
|
2437
|
-
*
|
|
2438
|
-
* - Syntactic diagnostics (parsing errors)
|
|
2439
|
-
* - Suggestion diagnostics (code improvement hints)
|
|
1993
|
+
* This method determines if a module is external by checking if it's a relative
|
|
1994
|
+
* or absolute path, and by resolving the module to see if it's in node_modules.
|
|
2440
1995
|
*
|
|
2441
|
-
* @
|
|
2442
|
-
|
|
2443
|
-
|
|
1996
|
+
* @since 1.5.9
|
|
1997
|
+
*/
|
|
1998
|
+
private isExternalModule;
|
|
1999
|
+
/**
|
|
2000
|
+
* Processes an export line, removing 'export' if needed
|
|
2001
|
+
*
|
|
2002
|
+
* @param line - The export statement to process
|
|
2003
|
+
* @param collectedSymbols - Set of exported symbol names
|
|
2004
|
+
* @returns The processed line
|
|
2005
|
+
*
|
|
2006
|
+
* @remarks
|
|
2007
|
+
* This method processes an export declaration line, removing the 'export'
|
|
2008
|
+
* keyword if the symbol is not in the collected exports.
|
|
2444
2009
|
*
|
|
2445
2010
|
* @since 1.5.9
|
|
2446
2011
|
*/
|
|
2447
|
-
private
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
* and any related metadata.
|
|
2459
|
-
*
|
|
2460
|
-
* @property emitSkipped - Indicates whether the emit operation was skipped.
|
|
2461
|
-
* When true, typically indicates compilation errors prevented emission or the operation
|
|
2462
|
-
* was explicitly configured to skip emission.
|
|
2463
|
-
*
|
|
2464
|
-
* @remarks
|
|
2465
|
-
* This interface is used to represent the result of TypeScript declaration emit operations.
|
|
2466
|
-
*
|
|
2467
|
-
* @since 1.5.9
|
|
2468
|
-
*/
|
|
2469
|
-
interface EmitOutputInterface {
|
|
2470
|
-
outputFile: OutputFile | undefined;
|
|
2471
|
-
emitSkipped: boolean;
|
|
2012
|
+
private processExportLine;
|
|
2013
|
+
/**
|
|
2014
|
+
* Creates the final bundled declaration content
|
|
2015
|
+
*
|
|
2016
|
+
* @param externalImports - Set of external import statements
|
|
2017
|
+
* @param bundledContent - Array of processed declaration content
|
|
2018
|
+
* @returns The final bundled declaration content
|
|
2019
|
+
*
|
|
2020
|
+
* @since 1.5.9
|
|
2021
|
+
*/
|
|
2022
|
+
private createFinalBundleContent;
|
|
2472
2023
|
}
|
|
2473
|
-
|
|
2474
|
-
/**
|
|
2475
|
-
* Import will remove at compile time
|
|
2476
|
-
*/
|
|
2477
|
-
/**
|
|
2478
|
-
* A host object that provides formatting functionality for typescript diagnostic messages
|
|
2479
|
-
*
|
|
2480
|
-
* @remarks
|
|
2481
|
-
* This constant implements the FormatDiagnosticsHost interface from TypeScript,
|
|
2482
|
-
* providing methods needed for proper diagnostic message formatting.
|
|
2483
|
-
*
|
|
2484
|
-
* @default Uses TypeScript's system utilities for line breaks and directory information
|
|
2485
|
-
*
|
|
2486
|
-
* @see FormatDiagnosticsHost - The TypeScript interface this implements
|
|
2487
|
-
*
|
|
2488
|
-
* @since 1.5.9
|
|
2489
|
-
*/
|
|
2490
|
-
declare const formatHost: FormatDiagnosticsHost;
|
|
2491
|
-
/**
|
|
2492
|
-
* Header text included at the top of generated declaration bundle files
|
|
2493
|
-
*
|
|
2494
|
-
* @remarks
|
|
2495
|
-
* This constant provides a standardized header comment that prepended to all
|
|
2496
|
-
* declaration bundle files generated by the DeclarationBundlerService. The header
|
|
2497
|
-
* clearly indicates that the file was automatically generated and should not be
|
|
2498
|
-
* edited manually.
|
|
2499
|
-
*
|
|
2500
|
-
* @example
|
|
2501
|
-
* ```ts
|
|
2502
|
-
* const bundledContent = `${HeaderDeclarationBundle}${actualContent}`;
|
|
2503
|
-
* writeFileSync('dist/index.d.ts', bundledContent);
|
|
2504
|
-
* ```
|
|
2505
|
-
*
|
|
2506
|
-
* @since 1.5.9
|
|
2507
|
-
*/
|
|
2508
|
-
declare const HeaderDeclarationBundle = "\n/**\n * This file was automatically generated by xBuild.\n * DO NOT EDIT MANUALLY.\n */\n ";
|
|
2509
|
-
|
|
2510
|
-
/**
|
|
2511
|
-
* Import will remove at compile time
|
|
2512
|
-
*/
|
|
2513
2024
|
/**
|
|
2514
|
-
*
|
|
2515
|
-
*
|
|
2516
|
-
* file system and manage compilation resources.
|
|
2025
|
+
* Manages TypeScript compilation, type checking, and declaration file generation using TypeScript's
|
|
2026
|
+
* language service API.
|
|
2517
2027
|
*
|
|
2518
2028
|
* @remarks
|
|
2519
|
-
* This
|
|
2520
|
-
*
|
|
2029
|
+
* This module provides an interface to TypeScript's compiler API for performing type checking
|
|
2030
|
+
* and generating declaration files. It uses the language service API rather than the direct
|
|
2031
|
+
* compiler API for better performance with incremental compilation.
|
|
2521
2032
|
*
|
|
2522
|
-
* @see ts.
|
|
2033
|
+
* @see ts.LanguageService
|
|
2523
2034
|
* @see ts.createLanguageService
|
|
2524
2035
|
*
|
|
2525
2036
|
* @since 1.5.9
|
|
2526
2037
|
*/
|
|
2527
|
-
declare class
|
|
2528
|
-
private readonly options;
|
|
2038
|
+
export declare class TypescriptModule {
|
|
2529
2039
|
/**
|
|
2530
|
-
*
|
|
2531
|
-
* Keys are absolute file paths and values are incrementing version numbers.
|
|
2532
|
-
*
|
|
2040
|
+
* The root directory of the TypeScript project.
|
|
2533
2041
|
* @since 1.5.9
|
|
2534
2042
|
*/
|
|
2535
|
-
|
|
2043
|
+
readonly root: string;
|
|
2536
2044
|
/**
|
|
2537
|
-
*
|
|
2538
|
-
*
|
|
2539
|
-
* @param options - Compiler options to use for TypeScript operations
|
|
2540
|
-
*
|
|
2045
|
+
* Parsed TypeScript configuration from tsconfig.
|
|
2541
2046
|
* @since 1.5.9
|
|
2542
2047
|
*/
|
|
2543
|
-
|
|
2048
|
+
readonly config: ParsedCommandLine;
|
|
2544
2049
|
/**
|
|
2545
|
-
*
|
|
2546
|
-
* Used to signal to the language service that a file needs to be reprocessed.
|
|
2547
|
-
*
|
|
2548
|
-
* @param touchFiles - Path to the file that has been modified
|
|
2549
|
-
*
|
|
2050
|
+
* TypeScript language service instance for compiler operations.
|
|
2550
2051
|
* @since 1.5.9
|
|
2551
2052
|
*/
|
|
2552
|
-
|
|
2053
|
+
private readonly languageService;
|
|
2553
2054
|
/**
|
|
2554
|
-
*
|
|
2555
|
-
* Required by the LanguageServiceHost interface.
|
|
2556
|
-
*
|
|
2557
|
-
* @param path - Path to check for file existence
|
|
2558
|
-
* @returns True if the file exists, false otherwise
|
|
2559
|
-
*
|
|
2560
|
-
* @see ts.LanguageServiceHost.fileExists
|
|
2055
|
+
* Language service host that provides file system access to the language service.
|
|
2561
2056
|
* @since 1.5.9
|
|
2562
2057
|
*/
|
|
2563
|
-
|
|
2058
|
+
private readonly languageServiceHost;
|
|
2564
2059
|
/**
|
|
2565
|
-
*
|
|
2566
|
-
*
|
|
2567
|
-
*
|
|
2568
|
-
*
|
|
2569
|
-
*
|
|
2570
|
-
*
|
|
2060
|
+
* Service for bundling TypeScript declaration files
|
|
2061
|
+
*
|
|
2062
|
+
* @remarks
|
|
2063
|
+
* This service instance handles the bundling of TypeScript declaration files (.d.ts)
|
|
2064
|
+
* by traversing the dependency graph starting from entry points, collecting exports,
|
|
2065
|
+
* and generating single bundled declaration files.
|
|
2066
|
+
*
|
|
2067
|
+
* @see DeclarationBundlerService
|
|
2571
2068
|
*
|
|
2572
|
-
* @see ts.LanguageServiceHost.readFile
|
|
2573
2069
|
* @since 1.5.9
|
|
2574
2070
|
*/
|
|
2575
|
-
|
|
2071
|
+
private readonly declarationBundlerService;
|
|
2576
2072
|
/**
|
|
2577
|
-
*
|
|
2578
|
-
* Required by the LanguageServiceHost interface.
|
|
2073
|
+
* Creates a new TypeScript module with the specified configuration.
|
|
2579
2074
|
*
|
|
2580
|
-
* @param
|
|
2581
|
-
* @param
|
|
2582
|
-
* @param
|
|
2583
|
-
*
|
|
2584
|
-
* @
|
|
2585
|
-
* @returns Array of file paths found in the directory
|
|
2075
|
+
* @param tsconfigPath - Path to the tsconfig.json file
|
|
2076
|
+
* @param outDir - Optional output directory to override the one in tsconfig
|
|
2077
|
+
* @param fallbackOutDir - Optional fallback output directory to use if outDir is not specified in tsconfig or outDir
|
|
2078
|
+
*
|
|
2079
|
+
* @throws Error - If the TypeScript configuration cannot be parsed
|
|
2586
2080
|
*
|
|
2587
|
-
* @see ts.LanguageServiceHost.readDirectory
|
|
2588
2081
|
* @since 1.5.9
|
|
2589
2082
|
*/
|
|
2590
|
-
|
|
2083
|
+
constructor(tsconfigPath: string, outDir?: string, fallbackOutDir?: string);
|
|
2591
2084
|
/**
|
|
2592
|
-
*
|
|
2593
|
-
* Required by the LanguageServiceHost interface.
|
|
2085
|
+
* Updates the version of one or more files to indicate they have changed.
|
|
2594
2086
|
*
|
|
2595
|
-
* @param
|
|
2596
|
-
* @returns Array of directory paths found
|
|
2087
|
+
* @param touchFiles - Path or array of paths to files that have been modified
|
|
2597
2088
|
*
|
|
2598
|
-
* @see ts.LanguageServiceHost.getDirectories
|
|
2599
2089
|
* @since 1.5.9
|
|
2600
2090
|
*/
|
|
2601
|
-
|
|
2091
|
+
updateFiles(touchFiles: string | Array<string>): void;
|
|
2602
2092
|
/**
|
|
2603
|
-
*
|
|
2093
|
+
* Performs type checking on all source files in the project.
|
|
2604
2094
|
*
|
|
2605
|
-
* @
|
|
2606
|
-
* @returns True if the directory exists, false otherwise
|
|
2095
|
+
* @returns Array of diagnostic
|
|
2607
2096
|
*
|
|
2608
2097
|
* @since 1.5.9
|
|
2609
2098
|
*/
|
|
2610
|
-
|
|
2099
|
+
check(): Array<Diagnostic>;
|
|
2611
2100
|
/**
|
|
2612
|
-
*
|
|
2613
|
-
* Required by the LanguageServiceHost interface.
|
|
2101
|
+
* Generates TypeScript declaration (.d.ts) files for all source files.
|
|
2614
2102
|
*
|
|
2615
|
-
* @
|
|
2103
|
+
* @throws Error - If outDir is not specified in the compiler options
|
|
2616
2104
|
*
|
|
2617
|
-
* @see ts.LanguageServiceHost.getCurrentDirectory
|
|
2618
2105
|
* @since 1.5.9
|
|
2619
2106
|
*/
|
|
2620
|
-
|
|
2107
|
+
emitDeclarations(): void;
|
|
2621
2108
|
/**
|
|
2622
|
-
*
|
|
2623
|
-
* Required by the LanguageServiceHost interface to identify the set of source files.
|
|
2109
|
+
* Generates and writes bundled declaration files for specified entry points
|
|
2624
2110
|
*
|
|
2625
|
-
* @
|
|
2111
|
+
* @param entryPoints - Record mapping output filenames to source file paths
|
|
2112
|
+
*
|
|
2113
|
+
* @throws Error - If the language service program is not available
|
|
2114
|
+
* @throws Error - If file system operations fail during writing
|
|
2115
|
+
*
|
|
2116
|
+
* @remarks
|
|
2117
|
+
* This method generates bundled declaration files from the provided entry points
|
|
2118
|
+
* and writes them to the configured output directory. The input is a record where:
|
|
2119
|
+
* - Keys represent the output filenames (with or without .d.ts extension)
|
|
2120
|
+
* - Values represent the source file paths to use as entry points
|
|
2121
|
+
*
|
|
2122
|
+
* The method handles directory creation, ensuring all necessary parent directories
|
|
2123
|
+
* exist before writing the output files. If the output filename doesn't end with
|
|
2124
|
+
* '.d.ts', the extension will be appended automatically.
|
|
2125
|
+
*
|
|
2126
|
+
* @example
|
|
2127
|
+
* ```ts
|
|
2128
|
+
* // Generate bundled declarations for multiple entry points
|
|
2129
|
+
* typescriptModule.emitBundleDeclarations({
|
|
2130
|
+
* 'index': 'src/index.ts',
|
|
2131
|
+
* 'components/index': 'src/components/index.ts'
|
|
2132
|
+
* });
|
|
2133
|
+
* ```
|
|
2134
|
+
*
|
|
2135
|
+
* @see DeclarationBundlerService.emitBundledDeclarations
|
|
2626
2136
|
*
|
|
2627
|
-
* @see ts.LanguageServiceHost.getScriptFileNames
|
|
2628
2137
|
* @since 1.5.9
|
|
2629
2138
|
*/
|
|
2630
|
-
|
|
2139
|
+
emitBundleDeclarations(entryPoints: Record<string, string>): void;
|
|
2631
2140
|
/**
|
|
2632
|
-
*
|
|
2633
|
-
* Required by the LanguageServiceHost interface to configure the TypeScript compiler.
|
|
2141
|
+
* Formats TypeScript diagnostic messages into human-readable, colored strings.
|
|
2634
2142
|
*
|
|
2635
|
-
* @
|
|
2143
|
+
* @param diagnostics - Array of TypeScript diagnostic objects to format
|
|
2144
|
+
* @returns Array of formatted diagnostic messages with location and error information
|
|
2145
|
+
*
|
|
2146
|
+
* @remarks
|
|
2147
|
+
* This method transforms raw TypeScript diagnostic objects into user-friendly
|
|
2148
|
+
* colored console output strings. For each diagnostic, it:
|
|
2149
|
+
* - Extracts file path, line, and character position information
|
|
2150
|
+
* - Formats error messages with proper indentation and coloring
|
|
2151
|
+
* - Includes error codes and prefixes with consistent styling
|
|
2152
|
+
*
|
|
2153
|
+
* For diagnostics with file information, the output format is:
|
|
2154
|
+
* `[TS] filename:line:column - error TS1234: Error message`
|
|
2155
|
+
*
|
|
2156
|
+
* For diagnostics without file information, only the flattened message text is returned.
|
|
2157
|
+
*
|
|
2158
|
+
* @example
|
|
2159
|
+
* ```ts
|
|
2160
|
+
* const ts = new TypescriptModule('tsconfig.json');
|
|
2161
|
+
* const diagnostics = ts.check();
|
|
2162
|
+
* const formattedMessages = ts.formatDiagnostics(diagnostics);
|
|
2163
|
+
* console.log(formattedMessages.join('\n'));
|
|
2164
|
+
* ```
|
|
2636
2165
|
*
|
|
2637
|
-
* @see ts.LanguageServiceHost.getCompilationSettings
|
|
2638
2166
|
* @since 1.5.9
|
|
2639
2167
|
*/
|
|
2640
|
-
|
|
2168
|
+
formatDiagnostics(diagnostics: readonly Diagnostic[]): Array<string>;
|
|
2641
2169
|
/**
|
|
2642
|
-
*
|
|
2643
|
-
* Required by the LanguageServiceHost interface to include standard TypeScript definitions.
|
|
2170
|
+
* Generates TypeScript declaration file output for a specified file
|
|
2644
2171
|
*
|
|
2645
|
-
* @param
|
|
2646
|
-
* @returns
|
|
2172
|
+
* @param fileName - The path to the TypeScript file for which to generate declaration output
|
|
2173
|
+
* @returns The result of the emit operation, including the declaration file content or an indication that emit was skipped
|
|
2174
|
+
*
|
|
2175
|
+
* @throws Error - When the language service fails to generate valid output
|
|
2176
|
+
*
|
|
2177
|
+
* @see ts.transform
|
|
2178
|
+
* @see ts.LanguageService.getEmitOutput
|
|
2647
2179
|
*
|
|
2648
|
-
* @see ts.LanguageServiceHost.getDefaultLibFileName
|
|
2649
2180
|
* @since 1.5.9
|
|
2650
2181
|
*/
|
|
2651
|
-
|
|
2182
|
+
private getEmitOutput;
|
|
2652
2183
|
/**
|
|
2653
|
-
*
|
|
2654
|
-
* Required by the LanguageServiceHost interface to determine if a file has changed.
|
|
2184
|
+
* Resolves a module specifier to its file path relative to the root directory
|
|
2655
2185
|
*
|
|
2656
|
-
* @param
|
|
2657
|
-
* @returns The
|
|
2186
|
+
* @param specifier - The module specifier string to resolve
|
|
2187
|
+
* @returns The resolved file path relative to the root directory, or undefined if resolution fails
|
|
2188
|
+
*
|
|
2189
|
+
* @remarks
|
|
2190
|
+
* This private method uses TypeScript's module resolution system to convert an import specifier
|
|
2191
|
+
* into an actual file path. It specifically filters out node_modules dependencies and ensures
|
|
2192
|
+
* paths are relative to the project's root directory.
|
|
2193
|
+
*
|
|
2194
|
+
* When rootDir is set to 'src' and baseUrl is set to the project root:
|
|
2195
|
+
* - The method will only resolve files contained within the 'src' directory
|
|
2196
|
+
* - All paths will be calculated relative to 'src', not the project root
|
|
2197
|
+
* - For example, with project structure:
|
|
2198
|
+
* ```text
|
|
2199
|
+
* /project-root/
|
|
2200
|
+
* ├── src/
|
|
2201
|
+
* │ ├── components/
|
|
2202
|
+
* │ │ └── button.ts
|
|
2203
|
+
* │ └── utils/
|
|
2204
|
+
* │ └── helpers.ts
|
|
2205
|
+
* └── tsconfig.json
|
|
2206
|
+
* ```
|
|
2207
|
+
* - A resolved path might be 'components/button.ts' relative to 'src'
|
|
2208
|
+
* - This maintains proper path structure for TypeScript's internal module resolution
|
|
2209
|
+
*
|
|
2210
|
+
* @example
|
|
2211
|
+
* ```ts
|
|
2212
|
+
* // For a specifier like '@components/button' with rootDir='src'
|
|
2213
|
+
* const relativePath = this.resolveModuleFileName('@components/button');
|
|
2214
|
+
* // Might return 'components/button.ts' (relative to src/)
|
|
2215
|
+
* ```
|
|
2216
|
+
*
|
|
2217
|
+
* @see ts.resolveModuleName
|
|
2658
2218
|
*
|
|
2659
|
-
* @see ts.LanguageServiceHost.getScriptVersion
|
|
2660
2219
|
* @since 1.5.9
|
|
2661
2220
|
*/
|
|
2662
|
-
|
|
2221
|
+
private resolveModuleFileName;
|
|
2663
2222
|
/**
|
|
2664
|
-
*
|
|
2665
|
-
* Required by the LanguageServiceHost interface to provide file content to the language service.
|
|
2223
|
+
* Calculates the relative path from a source file to a target file in the output directory
|
|
2666
2224
|
*
|
|
2667
|
-
* @param
|
|
2668
|
-
* @
|
|
2225
|
+
* @param fromFile - The source file path from which the relative path is calculated
|
|
2226
|
+
* @param toFile - The target file path in the output directory
|
|
2227
|
+
* @returns A properly formatted relative path string that can be used in import statements
|
|
2228
|
+
*
|
|
2229
|
+
* @remarks
|
|
2230
|
+
* This private method computes a relative path from one file to another in the output directory,
|
|
2231
|
+
* ensuring the path is properly formatted for JavaScript module imports.
|
|
2232
|
+
*
|
|
2233
|
+
* This is particularly useful when generating import statements in emitted files that
|
|
2234
|
+
* need to reference other modules in the output directory structure.
|
|
2235
|
+
*
|
|
2236
|
+
* @example
|
|
2237
|
+
* ```ts
|
|
2238
|
+
* // If fromFile is '/project/dist/components/button.js'
|
|
2239
|
+
* // toFile is 'utils/helpers.js'
|
|
2240
|
+
* // outDir is '/project/dist'
|
|
2241
|
+
* this.getRelativePathToOutDir(fromFile, toFile);
|
|
2242
|
+
* // Returns '../utils/helpers'
|
|
2243
|
+
* ```
|
|
2669
2244
|
*
|
|
2670
|
-
* @see ts.LanguageServiceHost.getScriptSnapshot
|
|
2671
|
-
* @see ts.IScriptSnapshot
|
|
2672
2245
|
* @since 1.5.9
|
|
2673
2246
|
*/
|
|
2674
|
-
|
|
2247
|
+
private getRelativePathToOutDir;
|
|
2248
|
+
/**
|
|
2249
|
+
* Creates a TypeScript transformer visitor that updates import and export paths
|
|
2250
|
+
*
|
|
2251
|
+
* @param fileName - The current file being transformed
|
|
2252
|
+
* @param context - The TypeScript transformation context
|
|
2253
|
+
* @returns A transformer function that processes a source file
|
|
2254
|
+
*
|
|
2255
|
+
* @remarks
|
|
2256
|
+
* This private method creates a visitor function that transforms import and export declarations
|
|
2257
|
+
* in TypeScript source files. The main purpose is to rewrite module specifiers to ensure they
|
|
2258
|
+
* correctly point to the compiled output files.
|
|
2259
|
+
*
|
|
2260
|
+
* This is crucial for maintaining correct module references when TypeScript files are compiled
|
|
2261
|
+
* and moved to an output directory with potentially different structure.
|
|
2262
|
+
*
|
|
2263
|
+
* When rootDir is set to 'src' and baseUrl is the project root:
|
|
2264
|
+
* - Module paths are resolved within the 'src' directory
|
|
2265
|
+
* - The new paths will be calculated relative to each file's position in the output structure
|
|
2266
|
+
* - This ensures imports continue to work correctly after compilation
|
|
2267
|
+
*
|
|
2268
|
+
* @since 1.5.9
|
|
2269
|
+
*/
|
|
2270
|
+
private createVisitor;
|
|
2271
|
+
/**
|
|
2272
|
+
* Parses the TypeScript configuration file.
|
|
2273
|
+
*
|
|
2274
|
+
* @param tsconfigPath - Path to the tsconfig.json file
|
|
2275
|
+
* @param outDir - Optional output directory to override the one in tsconfig
|
|
2276
|
+
* @param fallbackOutDir - Optional fallback output directory to use if outDir is not specified in tsconfig or outDir
|
|
2277
|
+
*
|
|
2278
|
+
* @returns Parsed command line object containing compiler options
|
|
2279
|
+
*
|
|
2280
|
+
* @throws Error - If the TypeScript configuration cannot be parsed
|
|
2281
|
+
*
|
|
2282
|
+
* @since 1.5.9
|
|
2283
|
+
*/
|
|
2284
|
+
private parseConfig;
|
|
2285
|
+
/**
|
|
2286
|
+
* Creates a TypeScript language service.
|
|
2287
|
+
*
|
|
2288
|
+
* @returns Language service instance
|
|
2289
|
+
*
|
|
2290
|
+
* @see ts.createLanguageService
|
|
2291
|
+
* @since 1.5.9
|
|
2292
|
+
*/
|
|
2293
|
+
private createLanguageService;
|
|
2294
|
+
/**
|
|
2295
|
+
* Initializes diagnostic plugins for macro supports
|
|
2296
|
+
* @since 1.5.9
|
|
2297
|
+
*/
|
|
2298
|
+
private initializeDiagnostics;
|
|
2299
|
+
/**
|
|
2300
|
+
* Retrieves all diagnostics for a specified file.
|
|
2301
|
+
*
|
|
2302
|
+
* @param fileName - Path to the TypeScript file to analyze
|
|
2303
|
+
* @returns Combined array of semantic, syntactic, and suggestion diagnostics
|
|
2304
|
+
*
|
|
2305
|
+
* @remarks
|
|
2306
|
+
* This method aggregates all three types of TypeScript diagnostics:
|
|
2307
|
+
* - Semantic diagnostics (type errors, etc.)
|
|
2308
|
+
* - Syntactic diagnostics (parsing errors)
|
|
2309
|
+
* - Suggestion diagnostics (code improvement hints)
|
|
2310
|
+
*
|
|
2311
|
+
* @see ts.LanguageService.getSemanticDiagnostics
|
|
2312
|
+
* @see ts.LanguageService.getSyntacticDiagnostics
|
|
2313
|
+
* @see ts.LanguageService.getSuggestionDiagnostics
|
|
2314
|
+
*
|
|
2315
|
+
* @since 1.5.9
|
|
2316
|
+
*/
|
|
2317
|
+
private getDiagnostics;
|
|
2675
2318
|
}
|
|
2676
|
-
|
|
2677
2319
|
/**
|
|
2678
|
-
*
|
|
2320
|
+
* Resolves path aliases in the provided content based on the specified paths and root directory.
|
|
2321
|
+
*
|
|
2322
|
+
* This function takes a string of content and replaces occurrences of defined path alias keys
|
|
2323
|
+
* with their corresponding relative paths derived from the specified source file and root directory.
|
|
2324
|
+
* It ensures that the resulting paths are relative to the directory of the source file and formatted
|
|
2325
|
+
* correctly for use in a JavaScript/TypeScript environment.
|
|
2326
|
+
*
|
|
2327
|
+
* Example:
|
|
2328
|
+
* Given the following inputs:
|
|
2329
|
+
* ```ts
|
|
2330
|
+
* const content = "import { foo } from '@core/foo';";
|
|
2331
|
+
* const sourceFile = "/project/src/index.ts";
|
|
2332
|
+
* const paths = {
|
|
2333
|
+
* '@core/': 'src/core',
|
|
2334
|
+
* '@utils/': 'src/utils'
|
|
2335
|
+
* };
|
|
2336
|
+
* const rootDir = "/project";
|
|
2337
|
+
* ```
|
|
2338
|
+
* The function will replace `@core/foo` with a relative path based on the source file's location,
|
|
2339
|
+
* potentially resulting in:
|
|
2340
|
+
* ```ts
|
|
2341
|
+
* const content = "import { foo } from './core/foo';";
|
|
2342
|
+
* ```
|
|
2343
|
+
*
|
|
2344
|
+
* @param content - The content in which path aliases need to be resolved.
|
|
2345
|
+
* @param sourceFile - The path of the source file from which relative paths will be calculated.
|
|
2346
|
+
* @param paths - An object mapping path alias keys to their corresponding paths.
|
|
2347
|
+
* @param esm - A flag indicating whether ESM is enabled.
|
|
2348
|
+
* @returns The updated content with resolved path aliases.
|
|
2679
2349
|
*/
|
|
2350
|
+
export declare function resolveAliasPlugin(content: string, sourceFile: string, paths: Record<string, string>, esm: boolean): string;
|
|
2680
2351
|
/**
|
|
2681
|
-
*
|
|
2682
|
-
*
|
|
2352
|
+
* Maps an array of file paths to an object where the keys are filenames (without extensions)
|
|
2353
|
+
* and the values are the corresponding file paths.
|
|
2683
2354
|
*
|
|
2684
|
-
*
|
|
2685
|
-
*
|
|
2355
|
+
* Each key in the resulting object is derived from the filename by removing the file extension.
|
|
2356
|
+
* For example, given a file path `src/index.ts`, the key in the resulting object will be `src/index`.
|
|
2686
2357
|
*
|
|
2687
|
-
* @
|
|
2688
|
-
*
|
|
2689
|
-
* by traversing the dependency graph starting from specified entry points.
|
|
2690
|
-
* It collects all necessary files and symbols, processes their declarations,
|
|
2691
|
-
* and generates a single bundled declaration file that can be used in place
|
|
2692
|
-
* of multiple individual declaration files.
|
|
2358
|
+
* @param filePaths - An array of file paths to map. Each file path should be a string.
|
|
2359
|
+
* @returns An object where the keys are filenames (without extensions) and the values are the corresponding file paths.
|
|
2693
2360
|
*
|
|
2694
|
-
*
|
|
2695
|
-
*
|
|
2361
|
+
* @example
|
|
2362
|
+
* ```ts
|
|
2363
|
+
* const filePaths = ['src/index.ts', 'src/utils.ts'];
|
|
2364
|
+
* const result = mapFilePathsToNames(filePaths);
|
|
2365
|
+
* console.log(result);
|
|
2366
|
+
* // Output: {
|
|
2367
|
+
* // 'src/index': 'src/index.ts',
|
|
2368
|
+
* // 'src/utils': 'src/utils.ts'
|
|
2369
|
+
* // }
|
|
2370
|
+
* ```
|
|
2371
|
+
*/
|
|
2372
|
+
export declare function mapFilePathsToNames(filePaths: Array<string>): Record<string, string>;
|
|
2373
|
+
/**
|
|
2374
|
+
* Extracts and returns an object mapping output file paths to input file paths from the provided `EntryPointsType` object.
|
|
2375
|
+
*
|
|
2376
|
+
* This function handles multiple formats of entry points, including:
|
|
2377
|
+
* - An array of strings representing file paths.
|
|
2378
|
+
* - An array of objects containing `in` and `out` properties, where `in` is the input file path and `out` is the output file path.
|
|
2379
|
+
* - A `Record<string, string>` where the keys represent input file paths and the values represent output file paths.
|
|
2380
|
+
*
|
|
2381
|
+
* Depending on the format, the function constructs an object with the output file paths as keys and the input file paths as values.
|
|
2382
|
+
* If the output path is not available, the filename (without extension) is used as the key.
|
|
2383
|
+
*
|
|
2384
|
+
* If a regular object with string keys and values (not in the supported formats) is provided, it will be returned as is.
|
|
2385
|
+
*
|
|
2386
|
+
* @param entryPoints - The entry points to extract from, which can be in different formats: an array of strings,
|
|
2387
|
+
* an array of objects with `in` and `out` properties, or a `Record<string, string>`.
|
|
2388
|
+
*
|
|
2389
|
+
* @returns An object mapping output file paths to input file paths, or filename (without extension) to file path.
|
|
2390
|
+
*
|
|
2391
|
+
* @throws Will throw an `Error` if the entry points format is unsupported.
|
|
2696
2392
|
*
|
|
2697
2393
|
* @example
|
|
2698
2394
|
* ```ts
|
|
2699
|
-
* const
|
|
2700
|
-
*
|
|
2701
|
-
* writeFileSync('dist/index.d.ts', bundledDeclarations[0]);
|
|
2395
|
+
* const entryPoints = extractEntryPoints(['src/index.ts', 'src/utils.ts']);
|
|
2396
|
+
* console.log(entryPoints); // { 'index': 'src/index.ts', 'utils': 'src/utils.ts' }
|
|
2702
2397
|
* ```
|
|
2703
2398
|
*
|
|
2704
|
-
* @
|
|
2705
|
-
*
|
|
2399
|
+
* @example
|
|
2400
|
+
* ```ts
|
|
2401
|
+
* const entryPoints = extractEntryPoints([{ in: 'src/index.ts', out: 'dist/index.js' }]);
|
|
2402
|
+
* console.log(entryPoints); // { 'dist/index.js': 'src/index.ts' }
|
|
2403
|
+
* ```
|
|
2706
2404
|
*
|
|
2707
|
-
* @
|
|
2405
|
+
* @example
|
|
2406
|
+
* ```ts
|
|
2407
|
+
* const entryPoints = extractEntryPoints({ index: 'src/index.ts', index2: 'dist/index2.js' });
|
|
2408
|
+
* console.log(entryPoints); // { index: 'src/index.ts', index2: 'dist/index2.js' }
|
|
2409
|
+
* ```
|
|
2708
2410
|
*/
|
|
2709
|
-
declare
|
|
2710
|
-
|
|
2711
|
-
|
|
2411
|
+
export declare function extractEntryPoints(entryPoints: EntryPointsType): Record<string, string>;
|
|
2412
|
+
/**
|
|
2413
|
+
* Generates a `package.json` file with the appropriate `type` field
|
|
2414
|
+
* based on the format specified in the configuration.
|
|
2415
|
+
*
|
|
2416
|
+
* - If the format is `esm`, the `type` will be set to `"module"`.
|
|
2417
|
+
* - If the format is `cjs`, the `type` will be set to `"commonjs"`.
|
|
2418
|
+
*
|
|
2419
|
+
* The function will ensure that the specified output directory exists, and if it doesn't,
|
|
2420
|
+
* it will create the necessary directories before writing the `package.json` file.
|
|
2421
|
+
*
|
|
2422
|
+
* @param config - The build configuration object containing
|
|
2423
|
+
* esbuild-related settings, such as the format (`format`).
|
|
2424
|
+
*
|
|
2425
|
+
* - `config.esbuild.format`: The module format, either `'esm'` or `'cjs'`, that determines the `type` field.
|
|
2426
|
+
*
|
|
2427
|
+
* @throws Will throw an error if there is a problem creating the directory or writing the file.
|
|
2428
|
+
*
|
|
2429
|
+
* Example usage:
|
|
2430
|
+
*
|
|
2431
|
+
* ```ts
|
|
2432
|
+
* const config = {
|
|
2433
|
+
* esbuild: {
|
|
2434
|
+
* format: 'esm'
|
|
2435
|
+
* }
|
|
2436
|
+
* };
|
|
2437
|
+
* packageTypeComponent(config);
|
|
2438
|
+
* // This will create 'dist/package.json' with the content: {"type": "module"}
|
|
2439
|
+
* ```
|
|
2440
|
+
*/
|
|
2441
|
+
export declare function packageTypeComponent(config: ConfigurationInterface): void;
|
|
2442
|
+
/**
|
|
2443
|
+
* Manages the build process for a TypeScript project using esbuild.
|
|
2444
|
+
*
|
|
2445
|
+
* The `BuildService` class orchestrates the build process, including TypeScript compilation, handling of build errors,
|
|
2446
|
+
* and lifecycle management of the build. It can operate in various modes, such as watching for file changes or running
|
|
2447
|
+
* in development mode. It also provides functionality for spawning development processes and processing entry points.
|
|
2448
|
+
*
|
|
2449
|
+
* @remarks
|
|
2450
|
+
* - The build process can be configured using the provided `ConfigurationInterface`.
|
|
2451
|
+
* - Errors related to TypeScript are handled separately and are not logged by default.
|
|
2452
|
+
* - The class supports various build modes, including watch mode and development mode, and handles different scenarios
|
|
2453
|
+
* based on the configuration.
|
|
2454
|
+
*
|
|
2455
|
+
* @public
|
|
2456
|
+
* @category Services
|
|
2457
|
+
*/
|
|
2458
|
+
export declare class BuildService {
|
|
2459
|
+
private config;
|
|
2460
|
+
/**
|
|
2461
|
+
* Provides TypeScript-related functionality for the build process.
|
|
2462
|
+
*/
|
|
2463
|
+
readonly typescriptModule: TypescriptModule;
|
|
2712
2464
|
/**
|
|
2713
|
-
*
|
|
2465
|
+
* Keeps track of active development processes spawned during the build.
|
|
2466
|
+
* This property holds an array of `ChildProcessWithoutNullStreams` instances that represent Node.js processes spawned
|
|
2467
|
+
* for running development tasks. These processes are used to handle development builds or runtime tasks and are managed
|
|
2468
|
+
* by the `BuildService` class to ensure they are properly started and stopped.
|
|
2714
2469
|
*
|
|
2715
|
-
* @
|
|
2470
|
+
* @remarks
|
|
2471
|
+
* - The array is populated when development processes are spawned, such as when specific development files are
|
|
2472
|
+
* processed or when running in development mode.
|
|
2473
|
+
* - The processes are terminated gracefully at the end of the build to avoid leaving orphaned processes running.
|
|
2474
|
+
* - It is important to manage these processes correctly to avoid resource leaks and ensure proper cleanup.
|
|
2475
|
+
*
|
|
2476
|
+
* @see ChildProcessWithoutNullStreams
|
|
2716
2477
|
*/
|
|
2717
|
-
private
|
|
2478
|
+
private activePossess;
|
|
2718
2479
|
/**
|
|
2719
|
-
*
|
|
2480
|
+
* Plugin provider
|
|
2720
2481
|
*
|
|
2721
|
-
* @
|
|
2722
|
-
|
|
2482
|
+
* @private
|
|
2483
|
+
*/
|
|
2484
|
+
private pluginsProvider;
|
|
2485
|
+
/**
|
|
2486
|
+
* A mapping of output filenames to their corresponding source file paths.
|
|
2487
|
+
*
|
|
2488
|
+
* @remarks
|
|
2489
|
+
* This property stores the entry points configuration for TypeScript compilation.
|
|
2490
|
+
* - Keys represent the output filenames (with or without .d.ts extension)
|
|
2491
|
+
* - Values represent the source file paths to use as entry points
|
|
2492
|
+
*
|
|
2493
|
+
* Used by declaration bundling operations to determine which files to process
|
|
2494
|
+
* and how to name the resulting declaration outputs.
|
|
2495
|
+
*
|
|
2496
|
+
* @example
|
|
2497
|
+
* ```ts
|
|
2498
|
+
* // Example entryPoints structure
|
|
2499
|
+
* {
|
|
2500
|
+
* 'index': 'src/index.ts',
|
|
2501
|
+
* 'components/button': 'src/components/button.ts'
|
|
2502
|
+
* }
|
|
2503
|
+
* ```
|
|
2723
2504
|
*
|
|
2505
|
+
* @private
|
|
2724
2506
|
* @since 1.5.9
|
|
2725
2507
|
*/
|
|
2726
|
-
|
|
2508
|
+
private readonly entryPoints;
|
|
2727
2509
|
/**
|
|
2728
|
-
*
|
|
2510
|
+
* Initializes the build service with the provided configuration.
|
|
2729
2511
|
*
|
|
2730
|
-
*
|
|
2731
|
-
*
|
|
2512
|
+
* The constructor configures the TypeScript provider, suppresses esbuild logging,
|
|
2513
|
+
* sets up development modes, and registers the necessary plugins.
|
|
2732
2514
|
*
|
|
2733
|
-
*
|
|
2734
|
-
*
|
|
2735
|
-
*
|
|
2736
|
-
* to
|
|
2515
|
+
* Declaration files will be output based on the following order of precedence:
|
|
2516
|
+
* 1. If `declarationOutDir` is set in the configuration, it will be used.
|
|
2517
|
+
* 2. If `declarationOutDir` is not provided, it will use the `outDir` value from the tsconfig.
|
|
2518
|
+
* 3. If neither of the above is available, it falls back to using the `outdir` specified in the esbuild configuration.
|
|
2519
|
+
*
|
|
2520
|
+
* @param config - The configuration object for the build process, including esbuild and TypeScript settings.
|
|
2521
|
+
*/
|
|
2522
|
+
constructor(config: ConfigurationInterface);
|
|
2523
|
+
/**
|
|
2524
|
+
* Executes the build process.
|
|
2525
|
+
* This method performs the build and handles any errors that occur during the execution.
|
|
2526
|
+
* If watching or development mode is enabled in the configuration, it starts watching for changes
|
|
2527
|
+
* to automatically rebuild as needed.
|
|
2528
|
+
* The method logs errors that are not related to TypeScript
|
|
2529
|
+
* compilation issues.
|
|
2530
|
+
*
|
|
2531
|
+
* @returns A promise that resolves with a `BuildResult` when the build process is complete,
|
|
2532
|
+
* or `undefined` if an error occurs during execution.
|
|
2533
|
+
*
|
|
2534
|
+
* @throws Error Throws an error if the build process encounters issues that are not related
|
|
2535
|
+
* to TypeScript. Such errors are logged, but the method does not rethrow them.
|
|
2536
|
+
*
|
|
2537
|
+
* @example
|
|
2538
|
+
* ```ts
|
|
2539
|
+
* import { BuildService } from './build-service';
|
|
2540
|
+
*
|
|
2541
|
+
* const buildService = new BuildService(config);
|
|
2542
|
+
* buildService.run().then(() => {
|
|
2543
|
+
* console.log('Build process completed successfully.');
|
|
2544
|
+
* }).catch((error) => {
|
|
2545
|
+
* console.error('Build process failed:', error);
|
|
2546
|
+
* });
|
|
2547
|
+
* ```
|
|
2737
2548
|
*
|
|
2738
|
-
*
|
|
2549
|
+
* In this example, the `run` method is invoked to execute the build process. It handles both successful
|
|
2550
|
+
* completion and logs any encountered errors, allowing the user to understand the outcome of the build.
|
|
2739
2551
|
*/
|
|
2740
|
-
|
|
2552
|
+
run(): Promise<BuildResult | void>;
|
|
2741
2553
|
/**
|
|
2742
|
-
*
|
|
2554
|
+
* Runs the build process in debug mode for the specified entry points.
|
|
2555
|
+
* This method temporarily disables development and watch mode, initiates the build process, and spawns development processes
|
|
2556
|
+
* for the specified entry points. If any errors occur during the build, they are handled appropriately.
|
|
2743
2557
|
*
|
|
2744
|
-
* @param
|
|
2745
|
-
*
|
|
2558
|
+
* @param entryPoints - An array of entry point file names for which the development processes will be spawned.
|
|
2559
|
+
* These entry points are matched against the build output files.
|
|
2746
2560
|
*
|
|
2747
|
-
* @
|
|
2748
|
-
*
|
|
2561
|
+
* @returns A `Promise<void>` that resolves when the build and process spawning have completed.
|
|
2562
|
+
*
|
|
2563
|
+
* @throws Handles any build-related errors using the `handleErrors` method.
|
|
2749
2564
|
*
|
|
2750
2565
|
* @remarks
|
|
2751
|
-
*
|
|
2752
|
-
*
|
|
2753
|
-
*
|
|
2566
|
+
* - The `config.dev` and `config.watch` settings are temporarily disabled to prevent development mode or file watching during the build.
|
|
2567
|
+
* - The `build()` method is called to generate the necessary build outputs.
|
|
2568
|
+
* - The `spawnDev` method is then invoked to spawn processes for the matching entry points.
|
|
2569
|
+
* - If any errors occur during the build, they are caught and passed to the `handleErrors` method.
|
|
2754
2570
|
*
|
|
2755
|
-
*
|
|
2756
|
-
*
|
|
2571
|
+
* @example
|
|
2572
|
+
* ```ts
|
|
2573
|
+
* const entryPoints = ['index', 'main'];
|
|
2574
|
+
* await this.runDebug(entryPoints);
|
|
2575
|
+
* ```
|
|
2757
2576
|
*
|
|
2758
|
-
*
|
|
2577
|
+
* In this example, the `runDebug` method runs the build process and spawns development processes for `index` and `main`.
|
|
2578
|
+
*
|
|
2579
|
+
* @public
|
|
2759
2580
|
*/
|
|
2760
|
-
|
|
2581
|
+
runDebug(entryPoints: Array<string>): Promise<void>;
|
|
2761
2582
|
/**
|
|
2762
|
-
*
|
|
2583
|
+
* Serves the project and watches for changes.
|
|
2584
|
+
* This method starts the development server using the `ServerProvider`, builds the project using esbuild,
|
|
2585
|
+
* and watches for file changes to automatically rebuild as needed. It initializes the server and invokes
|
|
2586
|
+
* the build process, enabling continuous development mode.
|
|
2763
2587
|
*
|
|
2764
|
-
* @
|
|
2765
|
-
* @param containingFile - The file containing the import
|
|
2766
|
-
* @param program - The TypeScript program
|
|
2588
|
+
* @returns A promise that resolves when the server is started and the build process is complete.
|
|
2767
2589
|
*
|
|
2768
|
-
* @
|
|
2590
|
+
* @throws This method catches any errors thrown during the build process and handles them using the
|
|
2591
|
+
* `handleErrors` method.
|
|
2769
2592
|
*
|
|
2770
|
-
* @
|
|
2593
|
+
* @example
|
|
2594
|
+
* ```ts
|
|
2595
|
+
* const buildService = new BuildService(config);
|
|
2596
|
+
* buildService.serve().then(() => {
|
|
2597
|
+
* console.log('Server is running and watching for changes.');
|
|
2598
|
+
* }).catch((error) => {
|
|
2599
|
+
* console.error('Failed to start the server:', error);
|
|
2600
|
+
* });
|
|
2601
|
+
* ```
|
|
2602
|
+
*
|
|
2603
|
+
* In this example, the `serve` method starts the server and watches for changes. If an error occurs during
|
|
2604
|
+
* the build or server startup, it is handled and logged.
|
|
2771
2605
|
*/
|
|
2772
|
-
|
|
2606
|
+
serve(): Promise<void>;
|
|
2773
2607
|
/**
|
|
2774
|
-
*
|
|
2775
|
-
*
|
|
2776
|
-
*
|
|
2777
|
-
*
|
|
2778
|
-
*
|
|
2608
|
+
* Executes a provided asynchronous callback function within a try-catch block.
|
|
2609
|
+
* This method ensures that any errors thrown during the execution of the callback
|
|
2610
|
+
* are properly handled and logged. If the error appears to be an `esbuild`-related
|
|
2611
|
+
* `OnEndResult` error with an array of errors, it avoids redundant logging.
|
|
2612
|
+
* Otherwise, it wraps the error in a `VMRuntimeError` and logs the stack trace.
|
|
2779
2613
|
*
|
|
2780
|
-
* @
|
|
2781
|
-
*
|
|
2782
|
-
* and collects all files that contribute to the final bundle, excluding node_modules.
|
|
2614
|
+
* @template T - The return type of the callback function, allowing flexibility
|
|
2615
|
+
* in the expected result type. Defaults to `BuildResult`.
|
|
2783
2616
|
*
|
|
2784
|
-
* @
|
|
2785
|
-
|
|
2786
|
-
private collectFilesRecursive;
|
|
2787
|
-
/**
|
|
2788
|
-
* Recursively collects exports from a module symbol
|
|
2617
|
+
* @param callback - A function that returns a `Promise<T>`, which is executed asynchronously.
|
|
2618
|
+
* The callback is wrapped in error handling logic to catch and process any exceptions.
|
|
2789
2619
|
*
|
|
2790
|
-
* @
|
|
2791
|
-
*
|
|
2792
|
-
* @param collectedSymbols - Set of collected symbol names
|
|
2620
|
+
* @returns A `Promise<T | void>` that resolves with the result of the callback function if successful,
|
|
2621
|
+
* or `void` if an error was thrown and handled. This allows for optional chaining on the return value.
|
|
2793
2622
|
*
|
|
2794
|
-
* @
|
|
2795
|
-
*
|
|
2796
|
-
* nested module exports for namespace declarations.
|
|
2623
|
+
* @throws This method does not throw explicitly but will log an error message if an exception is caught
|
|
2624
|
+
* and is not an `esbuild`-related error. The error stack is logged via `VMRuntimeError` for non-esbuild errors.
|
|
2797
2625
|
*
|
|
2798
|
-
* @
|
|
2626
|
+
* @example
|
|
2627
|
+
* ```ts
|
|
2628
|
+
* await execute(async () => {
|
|
2629
|
+
* // Perform some asynchronous operation here
|
|
2630
|
+
* return someResult;
|
|
2631
|
+
* });
|
|
2632
|
+
* ```
|
|
2799
2633
|
*/
|
|
2800
|
-
private
|
|
2634
|
+
private execute;
|
|
2801
2635
|
/**
|
|
2802
|
-
*
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
*
|
|
2636
|
+
* Configures the development mode by ensuring that `config.dev` is set properly.
|
|
2637
|
+
*/
|
|
2638
|
+
private configureDevelopmentMode;
|
|
2639
|
+
/**
|
|
2640
|
+
* Sets up the plugin's provider and registers the plugin HooksInterface.
|
|
2641
|
+
*/
|
|
2642
|
+
private setupPlugins;
|
|
2643
|
+
/**
|
|
2644
|
+
* Registers the plugin HooksInterface for start, end, and load events.
|
|
2807
2645
|
*
|
|
2808
|
-
* @
|
|
2646
|
+
* @param paths - The resolved path aliases.
|
|
2647
|
+
* @param rootDir - The root directory for resolving paths.
|
|
2809
2648
|
*/
|
|
2810
|
-
private
|
|
2649
|
+
private registerPluginHooks;
|
|
2811
2650
|
/**
|
|
2812
|
-
*
|
|
2651
|
+
* Generates a path alias object from the TypeScript provider's path options.
|
|
2652
|
+
* This method processes the `paths` property from the TypeScript provider's options,
|
|
2653
|
+
* which is expected to be an object where each key represents a path alias pattern,
|
|
2654
|
+
* and the corresponding value is an array of paths. The method removes any wildcard
|
|
2655
|
+
* characters (`*`) from both the keys and the first values of the arrays. It also
|
|
2656
|
+
* resolves the paths relative to the specified `rootDir`, returning a simplified
|
|
2657
|
+
* object that maps the cleaned keys to their respective paths.
|
|
2813
2658
|
*
|
|
2814
|
-
*
|
|
2815
|
-
* @param checker - The TypeScript type checker
|
|
2816
|
-
* @param collectedSymbols - Set to store collected symbol names
|
|
2659
|
+
* The resolved paths will be formatted to use a relative path notation.
|
|
2817
2660
|
*
|
|
2818
|
-
*
|
|
2661
|
+
* Example:
|
|
2662
|
+
* Given the following paths:
|
|
2663
|
+
* ```ts
|
|
2664
|
+
* {
|
|
2665
|
+
* '@core/*': ['src/core/*'],
|
|
2666
|
+
* '@utils/*': ['src/utils/*']
|
|
2667
|
+
* }
|
|
2668
|
+
* ```
|
|
2669
|
+
* And assuming `rootDir` is set to the base directory of your project, the method
|
|
2670
|
+
* will return:
|
|
2671
|
+
* ```ts
|
|
2672
|
+
* {
|
|
2673
|
+
* '@core/': './core/',
|
|
2674
|
+
* '@utils/': './utils/'
|
|
2675
|
+
* }
|
|
2676
|
+
* ```
|
|
2677
|
+
*
|
|
2678
|
+
* @param rootDir - The root directory to resolve paths against.
|
|
2679
|
+
* @returns An object mapping cleaned path aliases to their respective resolved paths.
|
|
2819
2680
|
*/
|
|
2820
|
-
private
|
|
2681
|
+
private generatePathAlias;
|
|
2821
2682
|
/**
|
|
2822
|
-
*
|
|
2683
|
+
* Handles errors during the build process.
|
|
2684
|
+
* This method processes and logs errors that occur during the esbuild process. It specifically filters out
|
|
2685
|
+
* errors related to TypeScript (`TypesError`) to prevent them from being logged, while logging all other errors
|
|
2686
|
+
* to the console. The error object is assumed to contain a list of messages, each with detailed information.
|
|
2823
2687
|
*
|
|
2824
|
-
* @param
|
|
2825
|
-
*
|
|
2826
|
-
*
|
|
2827
|
-
* @
|
|
2688
|
+
* @param esbuildError - The error object returned by esbuild, which is expected to contain an array of
|
|
2689
|
+
* error messages.
|
|
2690
|
+
*
|
|
2691
|
+
* @private
|
|
2828
2692
|
*
|
|
2829
2693
|
* @remarks
|
|
2830
|
-
*
|
|
2831
|
-
*
|
|
2832
|
-
* It uses a cache to avoid reprocessing the same file multiple times.
|
|
2694
|
+
* - TypeScript errors (denoted as `TypesError`) are skipped and not logged.
|
|
2695
|
+
* - Other errors are logged to the console with their text descriptions.
|
|
2833
2696
|
*
|
|
2834
|
-
* @
|
|
2697
|
+
* @example
|
|
2698
|
+
* ```ts
|
|
2699
|
+
* try {
|
|
2700
|
+
* await buildService.run();
|
|
2701
|
+
* } catch (esbuildError) {
|
|
2702
|
+
* buildService.handleErrors(esbuildError);
|
|
2703
|
+
* }
|
|
2704
|
+
* ```
|
|
2705
|
+
*
|
|
2706
|
+
* In this example, if an error occurs during the build process, the `handleErrors` method is used to
|
|
2707
|
+
* process and log the errors.
|
|
2835
2708
|
*/
|
|
2836
|
-
private
|
|
2709
|
+
private handleErrors;
|
|
2837
2710
|
/**
|
|
2838
|
-
*
|
|
2711
|
+
* Injects a configuration object (banner or footer) into the `esbuild` options.
|
|
2712
|
+
* This method will update the `esbuild` object by adding or modifying the `banner` or `footer`
|
|
2713
|
+
* property based on the provided configuration.
|
|
2714
|
+
* The function handles both static values
|
|
2715
|
+
* and functions within the configuration.
|
|
2839
2716
|
*
|
|
2840
|
-
* @param
|
|
2841
|
-
*
|
|
2717
|
+
* @param esbuild - The `esbuild` configuration object where the `banner` or `footer`
|
|
2718
|
+
* should be injected or updated.
|
|
2719
|
+
* @param object - The configuration object that contains the properties to inject.
|
|
2720
|
+
* The properties can either be static values or functions.
|
|
2721
|
+
* @param name - A string that determines whether the method modifies the `banner` or `footer`
|
|
2722
|
+
* property of the `esbuild` object.
|
|
2842
2723
|
*
|
|
2843
|
-
* @
|
|
2724
|
+
* @returns void - This method does not return any value.
|
|
2725
|
+
* It modifies the `esbuild` object directly.
|
|
2726
|
+
*
|
|
2727
|
+
* @throws Error - If the `object` parameter is not provided, nothing is injected.
|
|
2728
|
+
* No action will be taken if the specific `name` property (either
|
|
2729
|
+
* 'banner' or 'footer') does not exist in the `esbuild` object.
|
|
2844
2730
|
*/
|
|
2845
|
-
private
|
|
2731
|
+
private injects;
|
|
2846
2732
|
/**
|
|
2847
|
-
*
|
|
2733
|
+
* Builds the project based on the configuration.
|
|
2734
|
+
* Depending on the configuration, this method either uses esbuild's `context` for watching or `build` for a one-time build.
|
|
2848
2735
|
*
|
|
2849
|
-
* @
|
|
2850
|
-
* @returns The extracted module path or undefined if not found
|
|
2736
|
+
* @returns A promise that resolves with the build context or result.
|
|
2851
2737
|
*
|
|
2852
|
-
* @
|
|
2738
|
+
* @private
|
|
2853
2739
|
*/
|
|
2854
|
-
private
|
|
2740
|
+
private build;
|
|
2855
2741
|
/**
|
|
2856
|
-
*
|
|
2742
|
+
* Manages development processes for specified entry points.*
|
|
2743
|
+
* This method spawns development processes for each file in the metafile that matches any of the specified entry points.
|
|
2744
|
+
* It enables features like source maps and optional debugging mode for each spawned process.
|
|
2857
2745
|
*
|
|
2858
|
-
* @param
|
|
2859
|
-
*
|
|
2860
|
-
* @
|
|
2746
|
+
* @param meta - The metafile containing information about build outputs.
|
|
2747
|
+
* This typically includes a mapping of output files and their dependencies.
|
|
2748
|
+
* @param entryPoint - An array of entry point file names to match against the metafile outputs.
|
|
2749
|
+
* Only files that match these entry points will have development processes spawned.
|
|
2750
|
+
* @param debug - A boolean flag to enable debugging mode for spawned processes.
|
|
2751
|
+
* If `true`, the processes will start in debug mode with the `--inspect-brk` option. Defaults to `false`.
|
|
2752
|
+
*
|
|
2753
|
+
* @returns void
|
|
2861
2754
|
*
|
|
2862
2755
|
* @remarks
|
|
2863
|
-
*
|
|
2864
|
-
*
|
|
2756
|
+
* - Files that contain 'map' in their names (e.g., source map files) are ignored and no process is spawned for them.
|
|
2757
|
+
* - For each matching file in the metafile outputs, a new development process is spawned using the `spawn` function.
|
|
2758
|
+
* - The `activePossess` array tracks all spawned processes, allowing further management (e.g., termination).
|
|
2759
|
+
*
|
|
2760
|
+
* @example
|
|
2761
|
+
* ```ts
|
|
2762
|
+
* const meta = {
|
|
2763
|
+
* outputs: {
|
|
2764
|
+
* 'dist/index.js': { \/* ... *\/ },
|
|
2765
|
+
* 'dist/index.js.map': { \/* ... *\/ }
|
|
2766
|
+
* }
|
|
2767
|
+
* };
|
|
2768
|
+
* const entryPoints = ['index'];
|
|
2769
|
+
*
|
|
2770
|
+
* this.spawnDev(meta, entryPoints, true); // Spawns processes in debug mode
|
|
2771
|
+
* ```
|
|
2865
2772
|
*
|
|
2866
|
-
* @
|
|
2773
|
+
* @private
|
|
2867
2774
|
*/
|
|
2868
|
-
private
|
|
2775
|
+
private spawnDev;
|
|
2869
2776
|
/**
|
|
2870
|
-
*
|
|
2871
|
-
*
|
|
2872
|
-
* @param line - The export statement to process
|
|
2873
|
-
* @param collectedSymbols - Set of exported symbol names
|
|
2874
|
-
* @returns The processed line
|
|
2875
|
-
*
|
|
2876
|
-
* @remarks
|
|
2877
|
-
* This method processes an export declaration line, removing the 'export'
|
|
2878
|
-
* keyword if the symbol is not in the collected exports.
|
|
2777
|
+
* Starts the build process and type checking.
|
|
2778
|
+
* This method performs initial setup for the build and ensures that any child processes are terminated properly.
|
|
2879
2779
|
*
|
|
2880
|
-
* @
|
|
2780
|
+
* @private
|
|
2881
2781
|
*/
|
|
2882
|
-
private
|
|
2782
|
+
private start;
|
|
2883
2783
|
/**
|
|
2884
|
-
*
|
|
2784
|
+
* Finalizes the build process and logs results.
|
|
2785
|
+
* This method handles the end of the build process, logs build results, and processes development files if applicable.
|
|
2885
2786
|
*
|
|
2886
|
-
* @
|
|
2887
|
-
|
|
2888
|
-
|
|
2787
|
+
* @private
|
|
2788
|
+
*/
|
|
2789
|
+
private end;
|
|
2790
|
+
/**
|
|
2791
|
+
* Processes and updates entry points based on project dependencies.
|
|
2792
|
+
* This method analyzes the project's dependencies and adjusts entry points configuration as needed.
|
|
2889
2793
|
*
|
|
2890
|
-
* @
|
|
2794
|
+
* @private
|
|
2891
2795
|
*/
|
|
2892
|
-
private
|
|
2796
|
+
private processEntryPoints;
|
|
2893
2797
|
}
|
|
2894
|
-
|
|
2895
|
-
/**
|
|
2896
|
-
* Imports
|
|
2897
|
-
*/
|
|
2898
|
-
/**
|
|
2899
|
-
* Resolves path aliases in the provided content based on the specified paths and root directory.
|
|
2900
|
-
*
|
|
2901
|
-
* This function takes a string of content and replaces occurrences of defined path alias keys
|
|
2902
|
-
* with their corresponding relative paths derived from the specified source file and root directory.
|
|
2903
|
-
* It ensures that the resulting paths are relative to the directory of the source file and formatted
|
|
2904
|
-
* correctly for use in a JavaScript/TypeScript environment.
|
|
2905
|
-
*
|
|
2906
|
-
* Example:
|
|
2907
|
-
* Given the following inputs:
|
|
2908
|
-
* ```ts
|
|
2909
|
-
* const content = "import { foo } from '@core/foo';";
|
|
2910
|
-
* const sourceFile = "/project/src/index.ts";
|
|
2911
|
-
* const paths = {
|
|
2912
|
-
* '@core/': 'src/core',
|
|
2913
|
-
* '@utils/': 'src/utils'
|
|
2914
|
-
* };
|
|
2915
|
-
* const rootDir = "/project";
|
|
2916
|
-
* ```
|
|
2917
|
-
* The function will replace `@core/foo` with a relative path based on the source file's location,
|
|
2918
|
-
* potentially resulting in:
|
|
2919
|
-
* ```ts
|
|
2920
|
-
* const content = "import { foo } from './core/foo';";
|
|
2921
|
-
* ```
|
|
2922
|
-
*
|
|
2923
|
-
* @param content - The content in which path aliases need to be resolved.
|
|
2924
|
-
* @param sourceFile - The path of the source file from which relative paths will be calculated.
|
|
2925
|
-
* @param paths - An object mapping path alias keys to their corresponding paths.
|
|
2926
|
-
* @param esm - A flag indicating whether ESM is enabled.
|
|
2927
|
-
* @returns The updated content with resolved path aliases.
|
|
2928
|
-
*/
|
|
2929
|
-
declare function resolveAliasPlugin(content: string, sourceFile: string, paths: Record<string, string>, esm: boolean): string;
|
|
2930
|
-
|
|
2931
|
-
/**
|
|
2932
|
-
* Import will remove at compile time
|
|
2933
|
-
*/
|
|
2934
|
-
/**
|
|
2935
|
-
* Maps an array of file paths to an object where the keys are filenames (without extensions)
|
|
2936
|
-
* and the values are the corresponding file paths.
|
|
2937
|
-
*
|
|
2938
|
-
* Each key in the resulting object is derived from the filename by removing the file extension.
|
|
2939
|
-
* For example, given a file path `src/index.ts`, the key in the resulting object will be `src/index`.
|
|
2940
|
-
*
|
|
2941
|
-
* @param filePaths - An array of file paths to map. Each file path should be a string.
|
|
2942
|
-
* @returns An object where the keys are filenames (without extensions) and the values are the corresponding file paths.
|
|
2943
|
-
*
|
|
2944
|
-
* @example
|
|
2945
|
-
* ```ts
|
|
2946
|
-
* const filePaths = ['src/index.ts', 'src/utils.ts'];
|
|
2947
|
-
* const result = mapFilePathsToNames(filePaths);
|
|
2948
|
-
* console.log(result);
|
|
2949
|
-
* // Output: {
|
|
2950
|
-
* // 'src/index': 'src/index.ts',
|
|
2951
|
-
* // 'src/utils': 'src/utils.ts'
|
|
2952
|
-
* // }
|
|
2953
|
-
* ```
|
|
2954
|
-
*/
|
|
2955
|
-
declare function mapFilePathsToNames(filePaths: Array<string>): Record<string, string>;
|
|
2956
2798
|
/**
|
|
2957
|
-
*
|
|
2958
|
-
*
|
|
2959
|
-
* This function handles multiple formats of entry points, including:
|
|
2960
|
-
* - An array of strings representing file paths.
|
|
2961
|
-
* - An array of objects containing `in` and `out` properties, where `in` is the input file path and `out` is the output file path.
|
|
2962
|
-
* - A `Record<string, string>` where the keys represent input file paths and the values represent output file paths.
|
|
2963
|
-
*
|
|
2964
|
-
* Depending on the format, the function constructs an object with the output file paths as keys and the input file paths as values.
|
|
2965
|
-
* If the output path is not available, the filename (without extension) is used as the key.
|
|
2966
|
-
*
|
|
2967
|
-
* If a regular object with string keys and values (not in the supported formats) is provided, it will be returned as is.
|
|
2799
|
+
* Executes JavaScript code within a sandboxed environment using Node.js's `vm` module.
|
|
2968
2800
|
*
|
|
2969
|
-
* @param
|
|
2970
|
-
*
|
|
2801
|
+
* @param code - The JavaScript code to be executed within the sandbox.
|
|
2802
|
+
* @param sandbox - An optional context object to be used as the global scope for the executed code.
|
|
2971
2803
|
*
|
|
2972
|
-
* @returns
|
|
2804
|
+
* @returns The result of executing the provided code within the sandboxed environment.
|
|
2973
2805
|
*
|
|
2974
|
-
* @
|
|
2806
|
+
* @remarks
|
|
2807
|
+
* The `sandboxExecute` function creates a new `Script` instance with the provided code and
|
|
2808
|
+
* runs it within a sandboxed context using the `createContext` function from the `vm` module.
|
|
2809
|
+
* This approach ensures that the executed code is isolated from the rest of the application,
|
|
2810
|
+
* mitigating potential security risks.
|
|
2975
2811
|
*
|
|
2976
|
-
*
|
|
2977
|
-
*
|
|
2978
|
-
*
|
|
2979
|
-
* console.log(entryPoints); // { 'index': 'src/index.ts', 'utils': 'src/utils.ts' }
|
|
2980
|
-
* ```
|
|
2812
|
+
* The `sandbox` parameter allows you to provide a custom context or global object for the
|
|
2813
|
+
* sandboxed code. If not provided, an empty context is used. The function also supports
|
|
2814
|
+
* breaking execution on interrupt signals (e.g., Ctrl+C) with the `breakOnSigint` option.
|
|
2981
2815
|
*
|
|
2982
|
-
* @
|
|
2983
|
-
* ```ts
|
|
2984
|
-
* const entryPoints = extractEntryPoints([{ in: 'src/index.ts', out: 'dist/index.js' }]);
|
|
2985
|
-
* console.log(entryPoints); // { 'dist/index.js': 'src/index.ts' }
|
|
2986
|
-
* ```
|
|
2816
|
+
* @throws Error Throws an error if the code cannot be compiled or executed within the context.
|
|
2987
2817
|
*
|
|
2988
2818
|
* @example
|
|
2989
2819
|
* ```ts
|
|
2990
|
-
* const
|
|
2991
|
-
* console.log(
|
|
2820
|
+
* const result = sandboxExecute('return 2 + 2;', { myGlobal: 10 });
|
|
2821
|
+
* console.log(result); // Output: 4
|
|
2992
2822
|
* ```
|
|
2993
|
-
*/
|
|
2994
|
-
declare function extractEntryPoints(entryPoints: EntryPointsType): Record<string, string>;
|
|
2995
|
-
|
|
2996
|
-
/**
|
|
2997
|
-
* Import will remove at compile time
|
|
2998
|
-
*/
|
|
2999
|
-
/**
|
|
3000
|
-
* Generates a `package.json` file with the appropriate `type` field
|
|
3001
|
-
* based on the format specified in the configuration.
|
|
3002
2823
|
*
|
|
3003
|
-
*
|
|
3004
|
-
*
|
|
3005
|
-
*
|
|
3006
|
-
* The function will ensure that the specified output directory exists, and if it doesn't,
|
|
3007
|
-
* it will create the necessary directories before writing the `package.json` file.
|
|
3008
|
-
*
|
|
3009
|
-
* @param config - The build configuration object containing
|
|
3010
|
-
* esbuild-related settings, such as the format (`format`).
|
|
3011
|
-
*
|
|
3012
|
-
* - `config.esbuild.format`: The module format, either `'esm'` or `'cjs'`, that determines the `type` field.
|
|
3013
|
-
*
|
|
3014
|
-
* @throws Will throw an error if there is a problem creating the directory or writing the file.
|
|
3015
|
-
*
|
|
3016
|
-
* Example usage:
|
|
2824
|
+
* In this example, the `sandboxExecute` function runs a simple JavaScript expression and returns
|
|
2825
|
+
* the result. The `sandbox` parameter is provided with an empty object in this case.
|
|
3017
2826
|
*
|
|
3018
|
-
*
|
|
3019
|
-
*
|
|
3020
|
-
* esbuild: {
|
|
3021
|
-
* format: 'esm'
|
|
3022
|
-
* }
|
|
3023
|
-
* };
|
|
3024
|
-
* packageTypeComponent(config);
|
|
3025
|
-
* // This will create 'dist/package.json' with the content: {"type": "module"}
|
|
3026
|
-
* ```
|
|
3027
|
-
*/
|
|
3028
|
-
declare function packageTypeComponent(config: ConfigurationInterface): void;
|
|
3029
|
-
|
|
3030
|
-
/**
|
|
3031
|
-
* Import will remove at compile time
|
|
2827
|
+
* @public
|
|
2828
|
+
* @category Services
|
|
3032
2829
|
*/
|
|
2830
|
+
export declare function sandboxExecute(code: string, sandbox?: Context): unknown;
|
|
3033
2831
|
/**
|
|
3034
2832
|
* Parses a configuration file and returns a wrapped `ConfigurationInterface` object.
|
|
3035
2833
|
*
|
|
@@ -3046,54 +2844,30 @@ declare function packageTypeComponent(config: ConfigurationInterface): void;
|
|
|
3046
2844
|
*
|
|
3047
2845
|
* @throws Will throw an error if the transpilation or execution of the configuration file fails.
|
|
3048
2846
|
* The thrown error will have sourcemap information attached if available.
|
|
2847
|
+
|
|
3049
2848
|
* @example
|
|
3050
2849
|
* ```ts
|
|
3051
2850
|
* const config = await parseConfigurationFile('./config.jet.ts');
|
|
3052
2851
|
* console.log(config);
|
|
3053
2852
|
* ```
|
|
3054
2853
|
*/
|
|
3055
|
-
declare function parseConfigurationFile(file: string): Promise<ConfigurationInterface>;
|
|
3056
|
-
|
|
3057
|
-
/**
|
|
3058
|
-
* Import will remove at compile time
|
|
3059
|
-
*/
|
|
2854
|
+
export declare function parseConfigurationFile(file: string): Promise<ConfigurationInterface>;
|
|
3060
2855
|
/**
|
|
3061
|
-
*
|
|
3062
|
-
*
|
|
3063
|
-
* @param code - The JavaScript code to be executed within the sandbox.
|
|
3064
|
-
* @param sandbox - An optional context object to be used as the global scope for the executed code.
|
|
3065
|
-
*
|
|
3066
|
-
* @returns The result of executing the provided code within the sandboxed environment.
|
|
3067
|
-
*
|
|
3068
|
-
* @remarks
|
|
3069
|
-
* The `sandboxExecute` function creates a new `Script` instance with the provided code and
|
|
3070
|
-
* runs it within a sandboxed context using the `createContext` function from the `vm` module.
|
|
3071
|
-
* This approach ensures that the executed code is isolated from the rest of the application,
|
|
3072
|
-
* mitigating potential security risks.
|
|
3073
|
-
*
|
|
3074
|
-
* The `sandbox` parameter allows you to provide a custom context or global object for the
|
|
3075
|
-
* sandboxed code. If not provided, an empty context is used. The function also supports
|
|
3076
|
-
* breaking execution on interrupt signals (e.g., Ctrl+C) with the `breakOnSigint` option.
|
|
3077
|
-
*
|
|
3078
|
-
* @throws Error Throws an error if the code cannot be compiled or executed within the context.
|
|
2856
|
+
* The default configuration options for the build.
|
|
3079
2857
|
*
|
|
3080
2858
|
* @example
|
|
3081
2859
|
* ```ts
|
|
3082
|
-
*
|
|
3083
|
-
*
|
|
2860
|
+
* import { defaultConfiguration } from '@configuration/default-configuration';
|
|
2861
|
+
*
|
|
2862
|
+
* console.log(defaultConfiguration);
|
|
3084
2863
|
* ```
|
|
3085
2864
|
*
|
|
3086
|
-
* In this example, the `
|
|
3087
|
-
* the result. The `sandbox` parameter is provided with an empty object in this case.
|
|
2865
|
+
* In this example, the `defaultConfiguration` is imported and logged to the console to view the default settings.
|
|
3088
2866
|
*
|
|
3089
2867
|
* @public
|
|
3090
|
-
* @category
|
|
3091
|
-
*/
|
|
3092
|
-
declare function sandboxExecute(code: string, sandbox?: Context): unknown;
|
|
3093
|
-
|
|
3094
|
-
/**
|
|
3095
|
-
* Import will remove at compile time
|
|
2868
|
+
* @category Configuration
|
|
3096
2869
|
*/
|
|
2870
|
+
export declare const defaultConfiguration: ConfigurationInterface;
|
|
3097
2871
|
/**
|
|
3098
2872
|
* Merges user configurations with CLI configurations and default settings
|
|
3099
2873
|
* to produce a final configuration object for the build process.
|
|
@@ -3124,7 +2898,7 @@ declare function sandboxExecute(code: string, sandbox?: Context): unknown;
|
|
|
3124
2898
|
* console.log('Merged Configuration:', finalConfigs);
|
|
3125
2899
|
* ```
|
|
3126
2900
|
*/
|
|
3127
|
-
declare function configuration(userConfig: Array<PartialDeepConfigurationsType> | PartialDeepConfigurationsType, cliConfig?: PartialDeepConfigurationsType): Promise<Array<ConfigurationInterface>>;
|
|
2901
|
+
export declare function configuration(userConfig: Array<PartialDeepConfigurationsType> | PartialDeepConfigurationsType, cliConfig?: PartialDeepConfigurationsType): Promise<Array<ConfigurationInterface>>;
|
|
3128
2902
|
/**
|
|
3129
2903
|
* Merges CLI arguments with a configuration file to produce a final configuration object.
|
|
3130
2904
|
* This function reads the specified configuration file and merges its contents with
|
|
@@ -3152,24 +2926,55 @@ declare function configuration(userConfig: Array<PartialDeepConfigurationsType>
|
|
|
3152
2926
|
* });
|
|
3153
2927
|
* ```
|
|
3154
2928
|
*/
|
|
3155
|
-
declare function cliConfiguration(configFile: string, cli: Argv<ArgvInterface>): Promise<Array<ConfigurationInterface>>;
|
|
3156
|
-
|
|
2929
|
+
export declare function cliConfiguration(configFile: string, cli: Argv<ArgvInterface>): Promise<Array<ConfigurationInterface>>;
|
|
3157
2930
|
/**
|
|
3158
|
-
*
|
|
2931
|
+
* Main run function that initiates the build process based on CLI arguments.
|
|
2932
|
+
*
|
|
2933
|
+
* This function parses the CLI arguments, configures the build settings, and executes
|
|
2934
|
+
* the appropriate build tasks, including type checking, serving, or running in debug mode.
|
|
2935
|
+
*
|
|
2936
|
+
* @param argv - An array of strings representing the CLI arguments.
|
|
2937
|
+
*
|
|
2938
|
+
* @returns A promise that resolves when all build tasks are completed.
|
|
2939
|
+
*
|
|
2940
|
+
* @example
|
|
2941
|
+
* ```ts
|
|
2942
|
+
* await buildWithArgv(process.argv);
|
|
2943
|
+
* ```
|
|
3159
2944
|
*/
|
|
2945
|
+
export declare function buildWithArgv(argv: Array<string>): Promise<void>;
|
|
3160
2946
|
/**
|
|
3161
|
-
*
|
|
2947
|
+
* Builds the project using a configuration file specified by its path.
|
|
2948
|
+
*
|
|
2949
|
+
* This function reads the configuration from the provided file path, processes it,
|
|
2950
|
+
* and initiates the build tasks.
|
|
2951
|
+
*
|
|
2952
|
+
* @param configFilePath - The path to the configuration file to be used for the build.
|
|
2953
|
+
*
|
|
2954
|
+
* @returns A promise that resolves to an array of `BuildResult` objects once all build tasks are completed.
|
|
2955
|
+
*
|
|
2956
|
+
* @throws Error Throws an error if the configuration file does not exist or is invalid.
|
|
3162
2957
|
*
|
|
3163
2958
|
* @example
|
|
3164
2959
|
* ```ts
|
|
3165
|
-
*
|
|
3166
|
-
*
|
|
3167
|
-
* console.log(defaultConfiguration);
|
|
2960
|
+
* const results = await buildWithPath('./config.ts');
|
|
2961
|
+
* console.log('Build results:', results);
|
|
3168
2962
|
* ```
|
|
2963
|
+
*/
|
|
2964
|
+
export declare function buildWithConfigPath(configFilePath: string): Promise<BuildResult[]>;
|
|
2965
|
+
/**
|
|
2966
|
+
* Builds the project based on the provided configuration object.
|
|
3169
2967
|
*
|
|
3170
|
-
*
|
|
2968
|
+
* This function processes the given configuration and executes the build tasks accordingly.
|
|
3171
2969
|
*
|
|
3172
|
-
* @
|
|
3173
|
-
*
|
|
2970
|
+
* @param config - A partial configuration object used to define the build settings.
|
|
2971
|
+
*
|
|
2972
|
+
* @returns A promise that resolves to an array of `BuildResult` objects once all build tasks are completed.
|
|
2973
|
+
*
|
|
2974
|
+
* @example
|
|
2975
|
+
* ```ts
|
|
2976
|
+
* const results = await build({ entryPoints: ['./src/index.ts'] });
|
|
2977
|
+
* console.log('Build results:', results);
|
|
2978
|
+
* ```
|
|
3174
2979
|
*/
|
|
3175
|
-
declare
|
|
2980
|
+
export declare function build(config: PartialDeepConfigurationsType): Promise<BuildResult[]>;
|