@remotex-labs/xbuild 1.5.9 → 1.5.11
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 +1775 -1586
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +2 -2
- package/dist/index.d.ts +1775 -1612
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/package.json +4 -4
package/dist/cli.d.ts
CHANGED
|
@@ -1,11 +1,106 @@
|
|
|
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
|
+
|
|
1
27
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Import will remove at compile time
|
|
30
|
+
*/
|
|
31
|
+
export {};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Imports
|
|
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
|
+
*/
|
|
9
104
|
/**
|
|
10
105
|
* Represents an enhanced error type that extends the built-in Error object.
|
|
11
106
|
* This type adds an optional property to store call stack information.
|
|
@@ -25,7 +120,7 @@ import type { Context } from "vm";
|
|
|
25
120
|
* console.error(myError);
|
|
26
121
|
* ```
|
|
27
122
|
*/
|
|
28
|
-
|
|
123
|
+
type ErrorType = Error & {
|
|
29
124
|
callStacks?: Array<NodeJS.CallSite>;
|
|
30
125
|
};
|
|
31
126
|
/**
|
|
@@ -36,7 +131,7 @@ export type ErrorType = Error & {
|
|
|
36
131
|
* @property blockCode - The block of code (if any) related to the error, or `null` if unavailable.
|
|
37
132
|
* @property formattedError - A formatted string representing the error details.
|
|
38
133
|
*/
|
|
39
|
-
|
|
134
|
+
interface StackTraceStateInterface {
|
|
40
135
|
error: ErrorType & BaseError;
|
|
41
136
|
blockCode: null | string;
|
|
42
137
|
formattedError: string;
|
|
@@ -50,12 +145,31 @@ export interface StackTraceStateInterface {
|
|
|
50
145
|
* @property source - The source file path where the frame occurred.
|
|
51
146
|
* @property functionName - The name of the function being executed at this frame, or an empty string if not available.
|
|
52
147
|
*/
|
|
53
|
-
|
|
148
|
+
interface FrameDetailsInterface {
|
|
54
149
|
line: number;
|
|
55
150
|
column: number;
|
|
56
151
|
source: string;
|
|
57
152
|
functionName: string;
|
|
58
153
|
}
|
|
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
|
+
|
|
59
173
|
/**
|
|
60
174
|
* An enumeration of ANSI color codes used for text formatting in the terminal.
|
|
61
175
|
*
|
|
@@ -70,7 +184,7 @@ export interface FrameDetailsInterface {
|
|
|
70
184
|
* console.log(Color.BrightPink, 'This is bright pink text', Color.Reset);
|
|
71
185
|
* ```
|
|
72
186
|
*/
|
|
73
|
-
|
|
187
|
+
declare const enum Colors {
|
|
74
188
|
Reset = "\u001B[0m",
|
|
75
189
|
Red = "\u001B[38;5;9m",
|
|
76
190
|
Gray = "\u001B[38;5;243m",
|
|
@@ -114,80 +228,14 @@ export declare const enum Colors {
|
|
|
114
228
|
* console.log(plainMessage); // Output will be without color formatting
|
|
115
229
|
* ```
|
|
116
230
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
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;
|
|
231
|
+
declare function setColor(color: Colors, msg: string, activeColor?: boolean): string;
|
|
232
|
+
|
|
132
233
|
/**
|
|
133
|
-
*
|
|
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.
|
|
234
|
+
* Import will remove at compile time
|
|
138
235
|
*/
|
|
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
|
-
}
|
|
167
236
|
/**
|
|
168
|
-
*
|
|
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
|
|
237
|
+
* Imports
|
|
175
238
|
*/
|
|
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
|
-
}
|
|
191
239
|
/**
|
|
192
240
|
* A custom error class to handle errors occurring within a virtual machine (VM) execution context.
|
|
193
241
|
*
|
|
@@ -208,7 +256,7 @@ export declare class xBuildError extends BaseError {
|
|
|
208
256
|
* }
|
|
209
257
|
* ```
|
|
210
258
|
*/
|
|
211
|
-
|
|
259
|
+
declare class VMRuntimeError extends BaseError {
|
|
212
260
|
/**
|
|
213
261
|
* The original error thrown during the VM execution.
|
|
214
262
|
*/
|
|
@@ -240,58 +288,73 @@ export declare class VMRuntimeError extends BaseError {
|
|
|
240
288
|
*/
|
|
241
289
|
constructor(originalError: ErrorType, sourceMap?: SourceService);
|
|
242
290
|
}
|
|
291
|
+
|
|
243
292
|
/**
|
|
244
|
-
*
|
|
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.
|
|
293
|
+
* Exports
|
|
249
294
|
*/
|
|
250
|
-
export interface PluginsBuildStateInterface {
|
|
251
|
-
[key: string]: unknown;
|
|
252
|
-
}
|
|
253
295
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* The function can return a Promise that resolves to `null` or `void`, or it can return `null` or `void` directly.
|
|
296
|
+
* Import will remove at compile time
|
|
257
297
|
*/
|
|
258
|
-
export type PluginResultType = Promise<null | void> | null | void;
|
|
259
298
|
/**
|
|
260
|
-
*
|
|
261
|
-
*
|
|
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.
|
|
299
|
+
* Imports
|
|
265
300
|
*/
|
|
266
|
-
|
|
301
|
+
import '@errors/stack.error';
|
|
302
|
+
import '@errors/uncaught.error';
|
|
267
303
|
/**
|
|
268
|
-
*
|
|
304
|
+
* Main run function that initiates the build process based on CLI arguments.
|
|
269
305
|
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
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.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* await buildWithArgv(process.argv);
|
|
316
|
+
* ```
|
|
273
317
|
*/
|
|
274
|
-
|
|
318
|
+
declare function buildWithArgv(argv: Array<string>): Promise<void>;
|
|
275
319
|
/**
|
|
276
|
-
*
|
|
320
|
+
* Builds the project using a configuration file specified by its path.
|
|
277
321
|
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
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.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* const results = await buildWithPath('./config.ts');
|
|
334
|
+
* console.log('Build results:', results);
|
|
335
|
+
* ```
|
|
282
336
|
*/
|
|
283
|
-
|
|
337
|
+
declare function buildWithConfigPath(configFilePath: string): Promise<BuildResult[]>;
|
|
284
338
|
/**
|
|
285
|
-
*
|
|
339
|
+
* Builds the project based on the provided configuration object.
|
|
286
340
|
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
* @param
|
|
290
|
-
*
|
|
291
|
-
* @returns A
|
|
292
|
-
*
|
|
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.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* const results = await build({ entryPoints: ['./src/index.ts'] });
|
|
350
|
+
* console.log('Build results:', results);
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
declare function build(config: PartialDeepConfigurationsType): Promise<BuildResult[]>;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Import will remove at compile time
|
|
293
357
|
*/
|
|
294
|
-
export type OnLoadType = (content: string | Uint8Array, loader: Loader | undefined, args: OnLoadArgs, state: PluginsBuildStateInterface) => Promise<OnLoadResult | PluginResultType> | OnLoadResult | PluginResultType;
|
|
295
358
|
/**
|
|
296
359
|
* Represents the format for specifying entry points in TypeScript declaration generation and esbuild configuration.
|
|
297
360
|
*
|
|
@@ -332,7 +395,7 @@ export type OnLoadType = (content: string | Uint8Array, loader: Loader | undefin
|
|
|
332
395
|
* When used with esbuild configuration, the format determines how output files are named and structured.
|
|
333
396
|
* When used for TypeScript declaration generation, it affects how declaration files are generated and organized.
|
|
334
397
|
*/
|
|
335
|
-
|
|
398
|
+
type EntryPointsType = (string | {
|
|
336
399
|
in: string;
|
|
337
400
|
out: string;
|
|
338
401
|
})[] | Record<string, string> | undefined;
|
|
@@ -381,7 +444,7 @@ export type EntryPointsType = (string | {
|
|
|
381
444
|
* // }
|
|
382
445
|
* ```
|
|
383
446
|
*/
|
|
384
|
-
|
|
447
|
+
type PartialDeepType<T> = {
|
|
385
448
|
[P in keyof T]?: T[P] extends object ? PartialDeepType<T[P]> : T[P];
|
|
386
449
|
};
|
|
387
450
|
/**
|
|
@@ -401,7 +464,7 @@ export type PartialDeepType<T> = {
|
|
|
401
464
|
* @property [exports.default] - An optional default export.
|
|
402
465
|
* The default export, if present, is of type `ConfigurationInterface`.
|
|
403
466
|
*/
|
|
404
|
-
|
|
467
|
+
interface ModuleInterface {
|
|
405
468
|
/**
|
|
406
469
|
* An object representing the exports of the module.
|
|
407
470
|
* The keys are strings representing export names, and the values can be of any type.
|
|
@@ -441,7 +504,7 @@ export interface ModuleInterface {
|
|
|
441
504
|
*
|
|
442
505
|
* @public
|
|
443
506
|
*/
|
|
444
|
-
|
|
507
|
+
interface ServeInterface {
|
|
445
508
|
port: number;
|
|
446
509
|
host: string;
|
|
447
510
|
active: boolean;
|
|
@@ -495,7 +558,7 @@ export interface ServeInterface {
|
|
|
495
558
|
* @see OnStartType
|
|
496
559
|
* @see OnResolveType
|
|
497
560
|
*/
|
|
498
|
-
|
|
561
|
+
interface HooksInterface {
|
|
499
562
|
onEnd: OnEndType;
|
|
500
563
|
onLoad: OnLoadType;
|
|
501
564
|
onStart: OnStartType;
|
|
@@ -540,7 +603,7 @@ export interface HooksInterface {
|
|
|
540
603
|
* @public
|
|
541
604
|
* @category Configuration
|
|
542
605
|
*/
|
|
543
|
-
|
|
606
|
+
interface ConfigurationInterface {
|
|
544
607
|
/**
|
|
545
608
|
* Build and run entryPoint for development
|
|
546
609
|
*/
|
|
@@ -674,7 +737,7 @@ interface ExportedConfigurationInterface extends ConfigurationInterface {
|
|
|
674
737
|
* `ConfigurationInterface` are optional. It allows for flexible configuration
|
|
675
738
|
* objects where only a subset of properties need to be specified.
|
|
676
739
|
*/
|
|
677
|
-
|
|
740
|
+
type xBuildConfig = PartialDeepType<ExportedConfigurationInterface>;
|
|
678
741
|
/**
|
|
679
742
|
* Represents a partially deep configuration type based on the `ConfigurationInterface`.
|
|
680
743
|
*
|
|
@@ -682,7 +745,7 @@ export type xBuildConfig = PartialDeepType<ExportedConfigurationInterface>;
|
|
|
682
745
|
* missing or undefined. It leverages the `PartialDeepType` utility type to allow
|
|
683
746
|
* for flexibility in configuration management.
|
|
684
747
|
*/
|
|
685
|
-
|
|
748
|
+
type PartialDeepConfigurationsType = PartialDeepType<ConfigurationInterface>;
|
|
686
749
|
/**
|
|
687
750
|
* Defines the possible types for configurations.
|
|
688
751
|
*
|
|
@@ -723,1310 +786,1371 @@ export type PartialDeepConfigurationsType = PartialDeepType<ConfigurationInterfa
|
|
|
723
786
|
* ];
|
|
724
787
|
* ```
|
|
725
788
|
*/
|
|
726
|
-
|
|
789
|
+
type ConfigurationsType = PartialDeepConfigurationsType | Array<PartialDeepConfigurationsType>;
|
|
790
|
+
export {};
|
|
791
|
+
|
|
727
792
|
/**
|
|
728
|
-
*
|
|
793
|
+
* Import will remove at compile time
|
|
794
|
+
*/
|
|
795
|
+
/**
|
|
796
|
+
* Interface for the build state that users can modify.
|
|
729
797
|
*
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
* @
|
|
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.
|
|
798
|
+
* This interface allows users to store and manage any custom data related to the build process.
|
|
799
|
+
*
|
|
800
|
+
* @template T - The type of values that can be stored in the state.
|
|
745
801
|
*/
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
node: boolean;
|
|
749
|
-
file: string;
|
|
750
|
-
dev: Array<string>;
|
|
751
|
-
debug: Array<string>;
|
|
752
|
-
serve: boolean;
|
|
753
|
-
outdir: string;
|
|
754
|
-
declaration: boolean;
|
|
755
|
-
watch: boolean;
|
|
756
|
-
config: string;
|
|
757
|
-
tsconfig: string;
|
|
758
|
-
minify: boolean;
|
|
759
|
-
bundle: boolean;
|
|
760
|
-
format: Format;
|
|
802
|
+
interface PluginsBuildStateInterface {
|
|
803
|
+
[key: string]: unknown;
|
|
761
804
|
}
|
|
762
805
|
/**
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
* This function configures `yargs` to handle various build-related options for a JavaScript and TypeScript toolchain.
|
|
766
|
-
* It returns an object that adheres to the `ArgvInterface` structure based on the parsed arguments.
|
|
767
|
-
*
|
|
768
|
-
* @param argv - An array of command-line arguments (e.g., `process.argv`).
|
|
769
|
-
* @returns An object representing the parsed command-line arguments.
|
|
806
|
+
* A type that defines the possible return values of a plugin function.
|
|
770
807
|
*
|
|
771
|
-
*
|
|
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.
|
|
772
813
|
*
|
|
773
|
-
* @
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
* console.log(args.file); // Output: the file to build
|
|
777
|
-
* console.log(args.dev); // Output: true or false based on the --dev flag
|
|
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.
|
|
778
817
|
*/
|
|
779
|
-
|
|
818
|
+
type OnEndType = (result: BuildResult, state: PluginsBuildStateInterface) => PluginResultType | OnEndResult | Promise<OnEndResult>;
|
|
780
819
|
/**
|
|
781
|
-
*
|
|
782
|
-
* process, specifically for handling `ifdef` conditions and function removals in macros.
|
|
820
|
+
* Defines the signature of a function that is called at the start of the build process.
|
|
783
821
|
*
|
|
784
|
-
* @
|
|
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.
|
|
785
825
|
*/
|
|
786
|
-
|
|
787
|
-
ifdef: Array<string>;
|
|
788
|
-
macros: {
|
|
789
|
-
removeFunctions: Set<string>;
|
|
790
|
-
};
|
|
791
|
-
}
|
|
826
|
+
type OnStartType = (build: PluginBuild, state: PluginsBuildStateInterface) => PluginResultType | OnEndResult | Promise<OnEndResult>;
|
|
792
827
|
/**
|
|
793
|
-
*
|
|
828
|
+
* Defines the signature of a function that is called during the resolution of an import path.
|
|
794
829
|
*
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
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.
|
|
799
838
|
*
|
|
800
|
-
* @
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
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.
|
|
804
853
|
*
|
|
805
|
-
* @
|
|
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.
|
|
806
869
|
*/
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
870
|
+
interface ArgvInterface {
|
|
871
|
+
typeCheck: boolean;
|
|
872
|
+
node: boolean;
|
|
873
|
+
file: string;
|
|
874
|
+
dev: Array<string>;
|
|
875
|
+
debug: Array<string>;
|
|
876
|
+
serve: boolean;
|
|
877
|
+
outdir: string;
|
|
878
|
+
declaration: boolean;
|
|
879
|
+
watch: boolean;
|
|
880
|
+
config: string;
|
|
881
|
+
tsconfig: string;
|
|
882
|
+
minify: boolean;
|
|
883
|
+
bundle: boolean;
|
|
884
|
+
format: Format;
|
|
817
885
|
}
|
|
886
|
+
|
|
818
887
|
/**
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
* This function creates a new Node.js process to run the specified JavaScript file with source map support enabled.
|
|
822
|
-
* It optionally starts the process in debug mode, which allows WebStorm or other debuggers to attach to the process.
|
|
823
|
-
* The output and error streams of the spawned process are captured and logged to the console.
|
|
824
|
-
*
|
|
825
|
-
* @param filePath - The path to the JavaScript file to execute.
|
|
826
|
-
* @param debug - A boolean flag to enable debugging. If `true`, the process will be started with the `--inspect-brk` option,
|
|
827
|
-
* which opens a debugger on `0.0.0.0:9229`, allowing external debuggers to attach.
|
|
828
|
-
*
|
|
829
|
-
* @returns A `ChildProcessWithoutNullStreams` object representing the spawned process.
|
|
830
|
-
* This object allows interaction with the process, including capturing its output and error streams.
|
|
888
|
+
* Handles uncaught exceptions in the Node.js process.
|
|
831
889
|
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
* - If `debug` is `true`, the `--inspect-brk=0.0.0.0:9229` flag is added, starting the process in debug mode and pausing
|
|
836
|
-
* execution until a debugger is attached.
|
|
837
|
-
* - The output (`stdout`) and error (`stderr`) streams of the spawned process are logged to the console.
|
|
838
|
-
* - The function returns a `ChildProcessWithoutNullStreams` object that can be used to interact with the spawned process,
|
|
839
|
-
* such as handling its termination or sending input.
|
|
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.
|
|
840
893
|
*
|
|
841
|
-
*
|
|
894
|
+
* This setup helps in debugging by ensuring that all uncaught exceptions are logged, providing visibility
|
|
895
|
+
* into errors that might otherwise go unnoticed.
|
|
842
896
|
*
|
|
843
897
|
* @example
|
|
844
898
|
* ```ts
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
* console.log(`Process exited with code ${code}`);
|
|
852
|
-
* });
|
|
853
|
-
*
|
|
854
|
-
* // Run with debugging enabled
|
|
855
|
-
* const debugProcess = spawn('./path/to/script.js', true);
|
|
856
|
-
*
|
|
857
|
-
* debugProcess.on('close', (code) => {
|
|
858
|
-
* console.log(`Debug process exited with code ${code}`);
|
|
899
|
+
* process.on('uncaughtException', (error) => {
|
|
900
|
+
* if (error instanceof Error) {
|
|
901
|
+
* console.error(error.toString());
|
|
902
|
+
* } else {
|
|
903
|
+
* console.error(error);
|
|
904
|
+
* }
|
|
859
905
|
* });
|
|
860
906
|
* ```
|
|
861
907
|
*
|
|
862
|
-
*
|
|
863
|
-
*
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
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
|
|
867
915
|
*/
|
|
868
|
-
export declare function spawn(filePath: string, debug?: boolean): ChildProcessWithoutNullStreams;
|
|
869
916
|
/**
|
|
870
|
-
*
|
|
917
|
+
* Parses command-line arguments into an `ArgvInterface` object using `yargs`.
|
|
871
918
|
*
|
|
872
|
-
* This
|
|
873
|
-
*
|
|
919
|
+
* This function configures `yargs` to handle various build-related options for a JavaScript and TypeScript toolchain.
|
|
920
|
+
* It returns an object that adheres to the `ArgvInterface` structure based on the parsed arguments.
|
|
874
921
|
*
|
|
875
|
-
* @
|
|
876
|
-
* @
|
|
922
|
+
* @param argv - An array of command-line arguments (e.g., `process.argv`).
|
|
923
|
+
* @returns An object representing the parsed command-line arguments.
|
|
877
924
|
*
|
|
878
|
-
* @
|
|
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.
|
|
925
|
+
* @see {@link ArgvInterface} for the structure of the returned object.
|
|
882
926
|
*
|
|
883
927
|
* @example
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
*
|
|
888
|
-
* code: 'console.log("Hello, world!");',
|
|
889
|
-
* sourceMap: 'version: 3\nfile: out.js\nsources: ["file.ts"]\n'
|
|
890
|
-
* };
|
|
891
|
-
*
|
|
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
|
-
* ```
|
|
895
|
-
*
|
|
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.
|
|
898
|
-
*
|
|
899
|
-
* @public
|
|
900
|
-
* @category Interfaces
|
|
901
|
-
*/
|
|
902
|
-
export interface TranspileFileInterface {
|
|
903
|
-
code: string;
|
|
904
|
-
sourceMap: string;
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Default build options for esbuild bundler in RemoteX framework.
|
|
908
|
-
*
|
|
909
|
-
* These options are used to configure how esbuild processes and bundles the TypeScript
|
|
910
|
-
* files for the RemoteX testing framework.
|
|
911
|
-
*
|
|
912
|
-
* @public
|
|
913
|
-
* @category Configuration
|
|
928
|
+
* // Example usage:
|
|
929
|
+
* const args = argvParser(process.argv);
|
|
930
|
+
* console.log(args.file); // Output: the file to build
|
|
931
|
+
* console.log(args.dev); // Output: true or false based on the --dev flag
|
|
914
932
|
*/
|
|
915
|
-
|
|
933
|
+
declare function argvParser(argv: Array<string>): Argv<ArgvInterface>;
|
|
934
|
+
|
|
916
935
|
/**
|
|
917
|
-
*
|
|
918
|
-
*
|
|
919
|
-
* This function searches for the inline source map in the data string using a regular expression, removes the
|
|
920
|
-
* source map comment from the data string, and returns an object containing the code without the source map
|
|
921
|
-
* comment and the extracted source map.
|
|
922
|
-
*
|
|
923
|
-
* @param dataString - The string containing the transpiled code with an inline source map.
|
|
924
|
-
* @returns An object containing the modified code without the source map comment and the extracted source map.
|
|
925
|
-
* @throws Error -Throws an error if the source map URL is not found in the data string.
|
|
926
|
-
*
|
|
927
|
-
* @public
|
|
936
|
+
* Import will remove at compile time
|
|
928
937
|
*/
|
|
929
|
-
export declare function extractSourceMap(dataString: string): TranspileFileInterface;
|
|
930
938
|
/**
|
|
931
|
-
*
|
|
939
|
+
* Manages the build process for a TypeScript project using esbuild.
|
|
932
940
|
*
|
|
933
|
-
*
|
|
934
|
-
* and
|
|
941
|
+
* The `BuildService` class orchestrates the build process, including TypeScript compilation, handling of build errors,
|
|
942
|
+
* and lifecycle management of the build. It can operate in various modes, such as watching for file changes or running
|
|
943
|
+
* in development mode. It also provides functionality for spawning development processes and processing entry points.
|
|
935
944
|
*
|
|
936
|
-
* @
|
|
937
|
-
*
|
|
938
|
-
*
|
|
939
|
-
*
|
|
945
|
+
* @remarks
|
|
946
|
+
* - The build process can be configured using the provided `ConfigurationInterface`.
|
|
947
|
+
* - Errors related to TypeScript are handled separately and are not logged by default.
|
|
948
|
+
* - The class supports various build modes, including watch mode and development mode, and handles different scenarios
|
|
949
|
+
* based on the configuration.
|
|
940
950
|
*
|
|
941
951
|
* @public
|
|
942
952
|
* @category Services
|
|
943
953
|
*/
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
* The `analyzeDependencies` function analyzes the dependencies of a given entry point for a specified platform.
|
|
947
|
-
* It performs a bundling operation and generates a metafile that contains detailed information about the
|
|
948
|
-
* dependencies involved in the build process.
|
|
949
|
-
* This is typically used to inspect the external packages and modules
|
|
950
|
-
* that the entry point depends on.
|
|
951
|
-
*
|
|
952
|
-
* - **Input**:
|
|
953
|
-
* - `entryPoint`: A string or array of strings representing the entry points for the build.
|
|
954
|
-
* This defines the starting point(s) for the bundling process.
|
|
955
|
-
* - `platform`: An optional parameter that specifies the platform to target for the build.
|
|
956
|
-
* Default is `'browser'`.
|
|
957
|
-
*
|
|
958
|
-
* - **Output**: A `Promise` that resolves to an object containing:
|
|
959
|
-
* - The `BuildResult` from the bundling process.
|
|
960
|
-
* - A `metafile`, which contains detailed metadata about the build, including the dependencies analyzed.
|
|
961
|
-
*
|
|
962
|
-
* ## Example:
|
|
963
|
-
*
|
|
964
|
-
* ```ts
|
|
965
|
-
* const result = await analyzeDependencies(['src/index.ts']);
|
|
966
|
-
* console.log(result.metafile); // { inputs: { 'src/index.ts': { ... } }, outputs: { ... } }
|
|
967
|
-
*
|
|
968
|
-
* const nodeResult = await analyzeDependencies(['src/server.ts'], 'node');
|
|
969
|
-
* console.log(nodeResult.metafile); // { inputs: { 'src/server.ts': { ... } }, outputs: { ... } }
|
|
970
|
-
* ```
|
|
971
|
-
*
|
|
972
|
-
* @param entryPoint - The entry point(s) to be analyzed.
|
|
973
|
-
* @param platform - The target platform for the build.
|
|
974
|
-
* @returns A `Promise` that resolves to a `BuildResult` object along with a `metafile` containing dependency details.
|
|
975
|
-
* @throws Error If the build process fails for any reason.
|
|
976
|
-
*/
|
|
977
|
-
export declare function analyzeDependencies(entryPoint: EntryPointsType, platform?: BuildOptions['platform']): Promise<BuildResult & {
|
|
978
|
-
metafile: Metafile;
|
|
979
|
-
}>;
|
|
980
|
-
/**
|
|
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.
|
|
985
|
-
*
|
|
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.
|
|
990
|
-
*
|
|
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.
|
|
993
|
-
*
|
|
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.
|
|
997
|
-
*
|
|
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.
|
|
1010
|
-
*
|
|
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.
|
|
1019
|
-
*
|
|
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.
|
|
1022
|
-
*
|
|
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.
|
|
1026
|
-
*
|
|
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.
|
|
1031
|
-
*/
|
|
1032
|
-
export declare function collectDeclaredFunctions(meta: Metafile, config: ConfigurationInterface, state: BuildStateInterface['macros']): Promise<void>;
|
|
1033
|
-
/**
|
|
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`.
|
|
1064
|
-
*/
|
|
1065
|
-
export declare function parseMacros(content: string | Uint8Array, loader: Loader | undefined, args: OnLoadArgs, state: BuildStateInterface, config: ConfigurationInterface): Promise<OnLoadResult | PluginResultType | undefined>;
|
|
1066
|
-
/**
|
|
1067
|
-
* Represents an error that occurs during the esbuild process.
|
|
1068
|
-
*
|
|
1069
|
-
* This class extends the base error class to provide specific error handling for esbuild-related issues.
|
|
1070
|
-
* It captures the error message and maintains the proper stack trace, allowing for easier debugging
|
|
1071
|
-
* and identification of errors that occur during the build process.
|
|
1072
|
-
*
|
|
1073
|
-
* @class esBuildError
|
|
1074
|
-
* @extends BaseError
|
|
1075
|
-
*/
|
|
1076
|
-
export declare class esBuildError extends BaseError {
|
|
1077
|
-
originalErrorStack?: string;
|
|
954
|
+
declare class BuildService {
|
|
955
|
+
private config;
|
|
1078
956
|
/**
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
1081
|
-
* @param message - An object containing the error message. The `text` property is used to initialize
|
|
1082
|
-
* the base error class with a descriptive message about the error encountered during the esbuild process.
|
|
957
|
+
* Provides TypeScript-related functionality for the build process.
|
|
1083
958
|
*/
|
|
1084
|
-
|
|
959
|
+
readonly typescriptModule: TypescriptModule;
|
|
1085
960
|
/**
|
|
1086
|
-
*
|
|
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.
|
|
1087
965
|
*
|
|
1088
|
-
* @
|
|
1089
|
-
*
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
* Reads code from a file if it exists.
|
|
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.
|
|
1094
971
|
*
|
|
1095
|
-
* @
|
|
1096
|
-
* @returns Array of lines if file exists, otherwise null.
|
|
972
|
+
* @see ChildProcessWithoutNullStreams
|
|
1097
973
|
*/
|
|
1098
|
-
private
|
|
974
|
+
private activePossess;
|
|
1099
975
|
/**
|
|
1100
|
-
*
|
|
976
|
+
* Plugin provider
|
|
1101
977
|
*
|
|
1102
|
-
* @
|
|
1103
|
-
* @param location - The error location within the file.
|
|
1104
|
-
* @returns A formatted and highlighted code snippet string.
|
|
978
|
+
* @private
|
|
1105
979
|
*/
|
|
1106
|
-
private
|
|
980
|
+
private pluginsProvider;
|
|
1107
981
|
/**
|
|
1108
|
-
*
|
|
982
|
+
* A mapping of output filenames to their corresponding source file paths.
|
|
1109
983
|
*
|
|
1110
|
-
* @
|
|
1111
|
-
*
|
|
1112
|
-
*
|
|
1113
|
-
|
|
1114
|
-
private applyColor;
|
|
1115
|
-
}
|
|
1116
|
-
/**
|
|
1117
|
-
* ASCII Logo and Version Information
|
|
1118
|
-
*
|
|
1119
|
-
* @remarks
|
|
1120
|
-
* The `asciiLogo` constant stores an ASCII representation of the project logo
|
|
1121
|
-
* that will be displayed in the banner. This banner is rendered in a formatted
|
|
1122
|
-
* string in the `bannerComponent` function.
|
|
1123
|
-
*
|
|
1124
|
-
* The `cleanScreen` constant contains an ANSI escape code to clear the terminal screen.
|
|
1125
|
-
*/
|
|
1126
|
-
export declare const asciiLogo = "\n ______ _ _ _\n | ___ \\ (_) | | |\n__ _| |_/ /_ _ _| | __| |\n\\ \\/ / ___ \\ | | | | |/ _` |\n > <| |_/ / |_| | | | (_| |\n/_/\\_\\____/ \\__,_|_|_|\\__,_|\n";
|
|
1127
|
-
export declare const cleanScreen = "\u001Bc";
|
|
1128
|
-
/**
|
|
1129
|
-
* Renders the banner with the ASCII logo and version information.
|
|
1130
|
-
*
|
|
1131
|
-
* This function constructs and returns a formatted banner string that includes an ASCII logo and the version number.
|
|
1132
|
-
* The colors used for the ASCII logo and version number can be enabled or disabled based on the `activeColor` parameter.
|
|
1133
|
-
* If color formatting is enabled, the ASCII logo will be rendered in burnt orange, and the version number will be in bright pink.
|
|
1134
|
-
*
|
|
1135
|
-
* @param activeColor - A boolean flag indicating whether ANSI color formatting should be applied. Default is `__ACTIVE_COLOR`.
|
|
1136
|
-
*
|
|
1137
|
-
* @returns A formatted string containing the ASCII logo, version number, and ANSI color codes if `activeColor` is `true`.
|
|
1138
|
-
*
|
|
1139
|
-
* @remarks
|
|
1140
|
-
* The `bannerComponent` function clears the terminal screen, applies color formatting if enabled, and displays
|
|
1141
|
-
* the ASCII logo and version number. The version number is retrieved from the global `__VERSION` variable, and
|
|
1142
|
-
* the colors are reset after the text is rendered.
|
|
1143
|
-
*
|
|
1144
|
-
* @example
|
|
1145
|
-
* ```ts
|
|
1146
|
-
* console.log(bannerComponent());
|
|
1147
|
-
* ```
|
|
1148
|
-
*
|
|
1149
|
-
* This will output the banner to the console with the ASCII logo, version, and colors.
|
|
1150
|
-
*
|
|
1151
|
-
* @example
|
|
1152
|
-
* ```ts
|
|
1153
|
-
* console.log(bannerComponent(false));
|
|
1154
|
-
* ```
|
|
1155
|
-
*
|
|
1156
|
-
* This will output the banner to the console with the ASCII logo and version number without color formatting.
|
|
1157
|
-
*
|
|
1158
|
-
* @public
|
|
1159
|
-
*/
|
|
1160
|
-
export declare function bannerComponent(activeColor?: boolean): string;
|
|
1161
|
-
/**
|
|
1162
|
-
* A formatted string prefix used for logging build-related messages.
|
|
1163
|
-
* // todo optimize this
|
|
1164
|
-
*/
|
|
1165
|
-
export declare function prefix(): string;
|
|
1166
|
-
/**
|
|
1167
|
-
* Manages the HTTP or HTTPS server based on the provided configuration.
|
|
1168
|
-
*
|
|
1169
|
-
* The `ServerProvider` class initializes and starts either an HTTP or HTTPS server based on whether SSL certificates
|
|
1170
|
-
* are provided. It handles incoming requests, serves static files, and lists directory contents with appropriate
|
|
1171
|
-
* icons and colors.
|
|
1172
|
-
*
|
|
1173
|
-
* @class
|
|
1174
|
-
*/
|
|
1175
|
-
export declare class ServerProvider {
|
|
1176
|
-
/**
|
|
1177
|
-
* Root dir to serve
|
|
1178
|
-
*/
|
|
1179
|
-
private readonly rootDir;
|
|
1180
|
-
/**
|
|
1181
|
-
* Indicates whether the server is configured to use HTTPS.
|
|
1182
|
-
*/
|
|
1183
|
-
private readonly isHttps;
|
|
1184
|
-
/**
|
|
1185
|
-
* The server configuration object, including SSL certificate paths and other settings.
|
|
1186
|
-
*/
|
|
1187
|
-
private readonly config;
|
|
1188
|
-
/**
|
|
1189
|
-
* Creates an instance of ServerProvider.
|
|
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
|
|
1190
988
|
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
989
|
+
* Used by declaration bundling operations to determine which files to process
|
|
990
|
+
* and how to name the resulting declaration outputs.
|
|
1193
991
|
*
|
|
1194
992
|
* @example
|
|
1195
993
|
* ```ts
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
* certfile: './path/to/certfile',
|
|
1202
|
-
* onRequest: (req, res, next) => { /* custom request handling *\/ }
|
|
1203
|
-
* };
|
|
1204
|
-
* const provider = new ServerProvider(serverConfig, './public');
|
|
1205
|
-
* provider.start();
|
|
994
|
+
* // Example entryPoints structure
|
|
995
|
+
* {
|
|
996
|
+
* 'index': 'src/index.ts',
|
|
997
|
+
* 'components/button': 'src/components/button.ts'
|
|
998
|
+
* }
|
|
1206
999
|
* ```
|
|
1207
1000
|
*
|
|
1208
|
-
*
|
|
1001
|
+
* @private
|
|
1002
|
+
* @since 1.5.9
|
|
1209
1003
|
*/
|
|
1210
|
-
|
|
1004
|
+
private readonly entryPoints;
|
|
1211
1005
|
/**
|
|
1212
|
-
*
|
|
1213
|
-
* If SSL certificates are provided and valid, an HTTPS server is started. Otherwise, an HTTP server is started.
|
|
1214
|
-
*
|
|
1215
|
-
* @example
|
|
1216
|
-
* ```ts
|
|
1217
|
-
* provider.start();
|
|
1218
|
-
* ```
|
|
1006
|
+
* Initializes the build service with the provided configuration.
|
|
1219
1007
|
*
|
|
1220
|
-
*
|
|
1221
|
-
|
|
1222
|
-
start(): void;
|
|
1223
|
-
/**
|
|
1224
|
-
* Starts an HTTP server.
|
|
1225
|
-
* This method creates an HTTP server that listens on the configured port and handles incoming requests.
|
|
1008
|
+
* The constructor configures the TypeScript provider, suppresses esbuild logging,
|
|
1009
|
+
* sets up development modes, and registers the necessary plugins.
|
|
1226
1010
|
*
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
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.
|
|
1231
1015
|
*
|
|
1232
|
-
*
|
|
1016
|
+
* @param config - The configuration object for the build process, including esbuild and TypeScript settings.
|
|
1233
1017
|
*/
|
|
1234
|
-
|
|
1018
|
+
constructor(config: ConfigurationInterface);
|
|
1235
1019
|
/**
|
|
1236
|
-
*
|
|
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.
|
|
1237
1026
|
*
|
|
1238
|
-
*
|
|
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.
|
|
1239
1032
|
*
|
|
1240
1033
|
* @example
|
|
1241
1034
|
* ```ts
|
|
1242
|
-
*
|
|
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
|
+
* });
|
|
1243
1043
|
* ```
|
|
1244
1044
|
*
|
|
1245
|
-
*
|
|
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.
|
|
1246
1047
|
*/
|
|
1247
|
-
|
|
1048
|
+
run(): Promise<BuildResult | void>;
|
|
1248
1049
|
/**
|
|
1249
|
-
*
|
|
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.
|
|
1250
1053
|
*
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
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.
|
|
1253
1056
|
*
|
|
1254
|
-
* @
|
|
1255
|
-
*
|
|
1256
|
-
* @
|
|
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.
|
|
1257
1066
|
*
|
|
1258
1067
|
* @example
|
|
1259
1068
|
* ```ts
|
|
1260
|
-
*
|
|
1069
|
+
* const entryPoints = ['index', 'main'];
|
|
1070
|
+
* await this.runDebug(entryPoints);
|
|
1261
1071
|
* ```
|
|
1072
|
+
*
|
|
1073
|
+
* In this example, the `runDebug` method runs the build process and spawns development processes for `index` and `main`.
|
|
1074
|
+
*
|
|
1075
|
+
* @public
|
|
1262
1076
|
*/
|
|
1263
|
-
|
|
1077
|
+
runDebug(entryPoints: Array<string>): Promise<void>;
|
|
1264
1078
|
/**
|
|
1265
|
-
*
|
|
1079
|
+
* Serves the project and watches for changes.
|
|
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.
|
|
1266
1083
|
*
|
|
1267
|
-
*
|
|
1084
|
+
* @returns A promise that resolves when the server is started and the build process is complete.
|
|
1268
1085
|
*
|
|
1269
|
-
* @
|
|
1270
|
-
*
|
|
1086
|
+
* @throws This method catches any errors thrown during the build process and handles them using the
|
|
1087
|
+
* `handleErrors` method.
|
|
1271
1088
|
*
|
|
1272
1089
|
* @example
|
|
1273
1090
|
* ```ts
|
|
1274
|
-
* const
|
|
1275
|
-
*
|
|
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
|
+
* });
|
|
1276
1097
|
* ```
|
|
1098
|
+
*
|
|
1099
|
+
* In this example, the `serve` method starts the server and watches for changes. If an error occurs during
|
|
1100
|
+
* the build or server startup, it is handled and logged.
|
|
1277
1101
|
*/
|
|
1278
|
-
|
|
1102
|
+
serve(): Promise<void>;
|
|
1279
1103
|
/**
|
|
1280
|
-
*
|
|
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.
|
|
1281
1109
|
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1110
|
+
* @template T - The return type of the callback function, allowing flexibility
|
|
1111
|
+
* in the expected result type. Defaults to `BuildResult`.
|
|
1284
1112
|
*
|
|
1285
|
-
* @param
|
|
1286
|
-
*
|
|
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.
|
|
1287
1115
|
*
|
|
1288
|
-
* @returns A
|
|
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.
|
|
1289
1118
|
*
|
|
1290
|
-
* @throws
|
|
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.
|
|
1291
1121
|
*
|
|
1292
1122
|
* @example
|
|
1293
1123
|
* ```ts
|
|
1294
|
-
*
|
|
1124
|
+
* await execute(async () => {
|
|
1125
|
+
* // Perform some asynchronous operation here
|
|
1126
|
+
* return someResult;
|
|
1127
|
+
* });
|
|
1295
1128
|
* ```
|
|
1296
1129
|
*/
|
|
1297
|
-
private
|
|
1130
|
+
private execute;
|
|
1298
1131
|
/**
|
|
1299
|
-
*
|
|
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.
|
|
1300
1141
|
*
|
|
1301
|
-
*
|
|
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.
|
|
1302
1154
|
*
|
|
1303
|
-
*
|
|
1304
|
-
* @returns A promise that resolves with the file statistics.
|
|
1155
|
+
* The resolved paths will be formatted to use a relative path notation.
|
|
1305
1156
|
*
|
|
1306
|
-
*
|
|
1157
|
+
* Example:
|
|
1158
|
+
* Given the following paths:
|
|
1307
1159
|
* ```ts
|
|
1308
|
-
*
|
|
1309
|
-
*
|
|
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
|
+
* }
|
|
1310
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.
|
|
1311
1176
|
*/
|
|
1312
|
-
private
|
|
1177
|
+
private generatePathAlias;
|
|
1313
1178
|
/**
|
|
1314
|
-
* Handles
|
|
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.
|
|
1315
1183
|
*
|
|
1316
|
-
*
|
|
1184
|
+
* @param esbuildError - The error object returned by esbuild, which is expected to contain an array of
|
|
1185
|
+
* error messages.
|
|
1317
1186
|
*
|
|
1318
|
-
* @
|
|
1319
|
-
*
|
|
1320
|
-
* @
|
|
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.
|
|
1321
1192
|
*
|
|
1322
1193
|
* @example
|
|
1323
1194
|
* ```ts
|
|
1324
|
-
*
|
|
1195
|
+
* try {
|
|
1196
|
+
* await buildService.run();
|
|
1197
|
+
* } catch (esbuildError) {
|
|
1198
|
+
* buildService.handleErrors(esbuildError);
|
|
1199
|
+
* }
|
|
1325
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.
|
|
1326
1204
|
*/
|
|
1327
|
-
private
|
|
1205
|
+
private handleErrors;
|
|
1328
1206
|
/**
|
|
1329
|
-
*
|
|
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.
|
|
1330
1212
|
*
|
|
1331
|
-
*
|
|
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.
|
|
1332
1219
|
*
|
|
1333
|
-
* @
|
|
1334
|
-
*
|
|
1220
|
+
* @returns void - This method does not return any value.
|
|
1221
|
+
* It modifies the `esbuild` object directly.
|
|
1335
1222
|
*
|
|
1336
|
-
* @
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1339
|
-
* ```
|
|
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.
|
|
1340
1226
|
*/
|
|
1341
|
-
private
|
|
1227
|
+
private injects;
|
|
1342
1228
|
/**
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
* @param res - The response object.
|
|
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.
|
|
1346
1231
|
*
|
|
1347
|
-
* @
|
|
1348
|
-
* ```ts
|
|
1349
|
-
* provider.sendNotFound(response);
|
|
1350
|
-
* ```
|
|
1232
|
+
* @returns A promise that resolves with the build context or result.
|
|
1351
1233
|
*
|
|
1352
|
-
*
|
|
1234
|
+
* @private
|
|
1353
1235
|
*/
|
|
1354
|
-
private
|
|
1236
|
+
private build;
|
|
1355
1237
|
/**
|
|
1356
|
-
*
|
|
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.
|
|
1357
1241
|
*
|
|
1358
|
-
* @param
|
|
1359
|
-
*
|
|
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`.
|
|
1360
1248
|
*
|
|
1361
|
-
* @
|
|
1362
|
-
* ```ts
|
|
1363
|
-
* provider.sendError(response, new Error('Some error'));
|
|
1364
|
-
* ```
|
|
1365
|
-
*
|
|
1366
|
-
* This example shows how to send an error response using the `sendError` method.
|
|
1367
|
-
*/
|
|
1368
|
-
private sendError;
|
|
1369
|
-
}
|
|
1370
|
-
/**
|
|
1371
|
-
* Plugin provider for esbuild that registers hooks for lifecycle events such as onStart, onEnd, onResolve, and onLoad.
|
|
1372
|
-
* This class allows dynamic behavior by registering multiple hooks for different stages of the build process.
|
|
1373
|
-
*/
|
|
1374
|
-
export declare class PluginsProvider {
|
|
1375
|
-
/**
|
|
1376
|
-
* Holds the build state that hooks can modify.
|
|
1377
|
-
*/
|
|
1378
|
-
private buildState;
|
|
1379
|
-
/**
|
|
1380
|
-
* Holds the registered hooks for the `onEnd` lifecycle event.
|
|
1381
|
-
* This array contains functions that are called after the build process completes.
|
|
1382
|
-
*/
|
|
1383
|
-
private onEndHooks;
|
|
1384
|
-
/**
|
|
1385
|
-
* Holds the registered hooks for the `onSuccess` lifecycle event.
|
|
1386
|
-
* This array contains functions that are called after the build success finish.
|
|
1387
|
-
*/
|
|
1388
|
-
private onSuccess;
|
|
1389
|
-
/**
|
|
1390
|
-
* Holds the registered hooks for the `onLoad` lifecycle event.
|
|
1391
|
-
* This array contains functions that are called when esbuild attempts to load a module.
|
|
1392
|
-
*/
|
|
1393
|
-
private onLoadHooks;
|
|
1394
|
-
/**
|
|
1395
|
-
* Holds the registered hooks for the `onStart` lifecycle event.
|
|
1396
|
-
* This array contains functions that are called before the build process starts.
|
|
1397
|
-
*/
|
|
1398
|
-
private onStartHooks;
|
|
1399
|
-
/**
|
|
1400
|
-
* Holds the registered hooks for the `onResolve` lifecycle event.
|
|
1401
|
-
* This array contains functions that are called when esbuild attempts to resolve a module path.
|
|
1402
|
-
*/
|
|
1403
|
-
private onResolveHooks;
|
|
1404
|
-
/**
|
|
1405
|
-
* Registers a hook function for the `onStart` lifecycle event.
|
|
1406
|
-
* The hook will be called before the build process starts.
|
|
1249
|
+
* @returns void
|
|
1407
1250
|
*
|
|
1408
|
-
* @
|
|
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).
|
|
1409
1255
|
*
|
|
1410
1256
|
* @example
|
|
1411
1257
|
* ```ts
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
* }
|
|
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
|
|
1415
1267
|
* ```
|
|
1268
|
+
*
|
|
1269
|
+
* @private
|
|
1416
1270
|
*/
|
|
1417
|
-
|
|
1271
|
+
private spawnDev;
|
|
1418
1272
|
/**
|
|
1419
|
-
*
|
|
1420
|
-
*
|
|
1421
|
-
*
|
|
1422
|
-
* @param fn - A function of type `OnEndType` that will be executed after the build completes.
|
|
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.
|
|
1423
1275
|
*
|
|
1424
|
-
* @
|
|
1425
|
-
* ```ts
|
|
1426
|
-
* pluginProvider.registerOnEnd(async (result) => {
|
|
1427
|
-
* console.log('Build finished:', result);
|
|
1428
|
-
* });
|
|
1429
|
-
* ```
|
|
1276
|
+
* @private
|
|
1430
1277
|
*/
|
|
1431
|
-
|
|
1278
|
+
private start;
|
|
1432
1279
|
/**
|
|
1433
|
-
*
|
|
1434
|
-
*
|
|
1435
|
-
*
|
|
1436
|
-
* @param fn - A function of type `OnEndType` that will be executed after the build completes.
|
|
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.
|
|
1437
1282
|
*
|
|
1438
|
-
* @
|
|
1439
|
-
* ```ts
|
|
1440
|
-
* pluginProvider.registerOnSuccess(async (result) => {
|
|
1441
|
-
* console.log('Build Success finished:', result);
|
|
1442
|
-
* });
|
|
1443
|
-
* ```
|
|
1283
|
+
* @private
|
|
1444
1284
|
*/
|
|
1445
|
-
|
|
1285
|
+
private end;
|
|
1446
1286
|
/**
|
|
1447
|
-
*
|
|
1448
|
-
*
|
|
1449
|
-
*
|
|
1450
|
-
* @param fn - A function of type `OnResolveType` that will be executed during module resolution.
|
|
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.
|
|
1451
1289
|
*
|
|
1452
|
-
* @
|
|
1453
|
-
* ```ts
|
|
1454
|
-
* pluginProvider.registerOnResolve(async (args) => {
|
|
1455
|
-
* if (args.path === 'my-module') {
|
|
1456
|
-
* return { path: './src/my-module.ts' };
|
|
1457
|
-
* }
|
|
1458
|
-
* return null;
|
|
1459
|
-
* });
|
|
1460
|
-
* ```
|
|
1290
|
+
* @private
|
|
1461
1291
|
*/
|
|
1462
|
-
|
|
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 {
|
|
1463
1327
|
/**
|
|
1464
|
-
*
|
|
1465
|
-
* The hook will be called when esbuild attempts to load a module.
|
|
1466
|
-
*
|
|
1467
|
-
* @param fn - A function of type `OnLoadType` that will be executed during module loading.
|
|
1328
|
+
* Creates an instance of `TypesError`.
|
|
1468
1329
|
*
|
|
1469
|
-
* @
|
|
1470
|
-
*
|
|
1471
|
-
* pluginProvider.registerOnLoad(async (contents, loader, args) => {
|
|
1472
|
-
* if (args.path.endsWith('.json')) {
|
|
1473
|
-
* return { contents: JSON.stringify({ key: 'value' }), loader: 'json' };
|
|
1474
|
-
* }
|
|
1475
|
-
* return null;
|
|
1476
|
-
* });
|
|
1477
|
-
* ```
|
|
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+).
|
|
1478
1332
|
*/
|
|
1479
|
-
|
|
1333
|
+
constructor(message?: string, options?: {
|
|
1334
|
+
cause?: Error;
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* Import will remove at compile time
|
|
1340
|
+
*/
|
|
1341
|
+
/**
|
|
1342
|
+
* Spawns a new Node.js process to execute the provided JavaScript file, with optional debugging support.
|
|
1343
|
+
*
|
|
1344
|
+
* This function creates a new Node.js process to run the specified JavaScript file with source map support enabled.
|
|
1345
|
+
* It optionally starts the process in debug mode, which allows WebStorm or other debuggers to attach to the process.
|
|
1346
|
+
* The output and error streams of the spawned process are captured and logged to the console.
|
|
1347
|
+
*
|
|
1348
|
+
* @param filePath - The path to the JavaScript file to execute.
|
|
1349
|
+
* @param debug - A boolean flag to enable debugging. If `true`, the process will be started with the `--inspect-brk` option,
|
|
1350
|
+
* which opens a debugger on `0.0.0.0:9229`, allowing external debuggers to attach.
|
|
1351
|
+
*
|
|
1352
|
+
* @returns A `ChildProcessWithoutNullStreams` object representing the spawned process.
|
|
1353
|
+
* This object allows interaction with the process, including capturing its output and error streams.
|
|
1354
|
+
*
|
|
1355
|
+
* @remarks
|
|
1356
|
+
* - The `--enable-source-maps` flag is used to enable source map support, which allows better debugging by mapping
|
|
1357
|
+
* errors and stack traces to the original source code.
|
|
1358
|
+
* - If `debug` is `true`, the `--inspect-brk=0.0.0.0:9229` flag is added, starting the process in debug mode and pausing
|
|
1359
|
+
* execution until a debugger is attached.
|
|
1360
|
+
* - The output (`stdout`) and error (`stderr`) streams of the spawned process are logged to the console.
|
|
1361
|
+
* - The function returns a `ChildProcessWithoutNullStreams` object that can be used to interact with the spawned process,
|
|
1362
|
+
* such as handling its termination or sending input.
|
|
1363
|
+
*
|
|
1364
|
+
* @throws Error Throws an error if the Node.js process fails to start or if there are issues with the provided file path.
|
|
1365
|
+
*
|
|
1366
|
+
* @example
|
|
1367
|
+
* ```ts
|
|
1368
|
+
* import { spawn } from '@services/process.service';
|
|
1369
|
+
*
|
|
1370
|
+
* // Run without debugging
|
|
1371
|
+
* const process = spawn('./path/to/script.js', false);
|
|
1372
|
+
*
|
|
1373
|
+
* process.on('close', (code) => {
|
|
1374
|
+
* console.log(`Process exited with code ${code}`);
|
|
1375
|
+
* });
|
|
1376
|
+
*
|
|
1377
|
+
* // Run with debugging enabled
|
|
1378
|
+
* const debugProcess = spawn('./path/to/script.js', true);
|
|
1379
|
+
*
|
|
1380
|
+
* debugProcess.on('close', (code) => {
|
|
1381
|
+
* console.log(`Debug process exited with code ${code}`);
|
|
1382
|
+
* });
|
|
1383
|
+
* ```
|
|
1384
|
+
*
|
|
1385
|
+
* In these examples, the `spawn` function is used to execute a JavaScript file, once in normal mode and once with debugging enabled.
|
|
1386
|
+
* The process's exit code is logged when the process completes.
|
|
1387
|
+
*
|
|
1388
|
+
* @public
|
|
1389
|
+
* @category Services
|
|
1390
|
+
*/
|
|
1391
|
+
declare function spawn(filePath: string, debug?: boolean): ChildProcessWithoutNullStreams;
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Import will remove at compile time
|
|
1395
|
+
*/
|
|
1396
|
+
/**
|
|
1397
|
+
* The `collectFunctionNames` function analyzes the provided TypeScript code and collects the names of functions
|
|
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.
|
|
1401
|
+
*
|
|
1402
|
+
* - **Input**:
|
|
1403
|
+
* - `code`: A string containing the TypeScript code to be analyzed.
|
|
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.
|
|
1406
|
+
*
|
|
1407
|
+
* - **Output**: The function does not return any value. Instead, it modifies the `removeFunctions` set inside the
|
|
1408
|
+
* `state` object by adding function names that meet the criteria for removal.
|
|
1409
|
+
*
|
|
1410
|
+
* ## Error Handling:
|
|
1411
|
+
* - The function does not explicitly handle errors. If invalid TypeScript code is provided, `ts.createSourceFile`
|
|
1412
|
+
* may throw an error, which should be handled by the caller if necessary.
|
|
1413
|
+
*
|
|
1414
|
+
* @param code - The TypeScript code as a string that will be analyzed.
|
|
1415
|
+
* @param state - The build state containing the `removeFunctions` set to store the names of functions to be removed.
|
|
1416
|
+
* @returns `void` - The function modifies the `state` directly and does not return a value.
|
|
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.
|
|
1455
|
+
*
|
|
1456
|
+
* - **Input**:
|
|
1457
|
+
* - `content`: The content of the file as a string or `Uint8Array` to be parsed.
|
|
1458
|
+
* - `loader`: A string representing the loader type for transforming the code (e.g., `'ts'`, `'js'`).
|
|
1459
|
+
* - `args`: The `OnLoadArgs` object containing metadata for the current loading process, including the file path.
|
|
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).
|
|
1463
|
+
*
|
|
1464
|
+
* - **Output**: A `Promise` that resolves to an `OnLoadResult`, `PluginResultType`, or `undefined`. If the file is
|
|
1465
|
+
* of type `.ts` or `.js`, the transformed code is returned in the specified loader format (e.g., `'ts'`). If the file
|
|
1466
|
+
* extension is not recognized, the function returns `undefined`.
|
|
1467
|
+
*
|
|
1468
|
+
* ## Error Handling:
|
|
1469
|
+
* - If the file path does not end with `.ts` or `.js`, the function returns `undefined`.
|
|
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.
|
|
1472
|
+
*
|
|
1473
|
+
* @param content - The content of the file as a string or `Uint8Array` to be parsed.
|
|
1474
|
+
* @param loader - The loader type for transforming the code (e.g., `'ts'` or `'js'`).
|
|
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
|
|
1485
|
+
*/
|
|
1486
|
+
/**
|
|
1487
|
+
* Default build options for esbuild bundler in RemoteX framework.
|
|
1488
|
+
*
|
|
1489
|
+
* These options are used to configure how esbuild processes and bundles the TypeScript
|
|
1490
|
+
* files for the RemoteX testing framework.
|
|
1491
|
+
*
|
|
1492
|
+
* @public
|
|
1493
|
+
* @category Configuration
|
|
1494
|
+
*/
|
|
1495
|
+
declare const defaultBuildOptions: BuildOptions;
|
|
1496
|
+
/**
|
|
1497
|
+
* Extracts the source map from the provided data string and returns the modified code and source map separately.
|
|
1498
|
+
*
|
|
1499
|
+
* This function searches for the inline source map in the data string using a regular expression, removes the
|
|
1500
|
+
* source map comment from the data string, and returns an object containing the code without the source map
|
|
1501
|
+
* comment and the extracted source map.
|
|
1502
|
+
*
|
|
1503
|
+
* @param dataString - The string containing the transpiled code with an inline source map.
|
|
1504
|
+
* @returns An object containing the modified code without the source map comment and the extracted source map.
|
|
1505
|
+
* @throws Error -Throws an error if the source map URL is not found in the data string.
|
|
1506
|
+
*
|
|
1507
|
+
* @public
|
|
1508
|
+
*/
|
|
1509
|
+
declare function extractSourceMap(dataString: string): TranspileFileInterface;
|
|
1510
|
+
/**
|
|
1511
|
+
* Transpiles a TypeScript file and extracts the source map.
|
|
1512
|
+
*
|
|
1513
|
+
* This function uses esbuild to transpile the specified TypeScript file based on provided build options,
|
|
1514
|
+
* and then extracts the source map from the transpiled code.
|
|
1515
|
+
*
|
|
1516
|
+
* @param filePath - The path to the TypeScript file to be transpiled.
|
|
1517
|
+
* @param buildOptions - Optional build options to override the default build options.
|
|
1518
|
+
* @returns A promise that resolves to an object containing the transpiled code and the extracted source map.
|
|
1519
|
+
* @throws Error - Throws an error if the build process fails or the source map extraction fails.
|
|
1520
|
+
*
|
|
1521
|
+
* @public
|
|
1522
|
+
* @category Services
|
|
1523
|
+
*/
|
|
1524
|
+
declare function transpileFile(filePath: string, buildOptions?: BuildOptions): Promise<TranspileFileInterface>;
|
|
1525
|
+
/**
|
|
1526
|
+
* The `analyzeDependencies` function analyzes the dependencies of a given entry point for a specified platform.
|
|
1527
|
+
* It performs a bundling operation and generates a metafile that contains detailed information about the
|
|
1528
|
+
* dependencies involved in the build process.
|
|
1529
|
+
* This is typically used to inspect the external packages and modules
|
|
1530
|
+
* that the entry point depends on.
|
|
1531
|
+
*
|
|
1532
|
+
* - **Input**:
|
|
1533
|
+
* - `entryPoint`: A string or array of strings representing the entry points for the build.
|
|
1534
|
+
* This defines the starting point(s) for the bundling process.
|
|
1535
|
+
* - `platform`: An optional parameter that specifies the platform to target for the build.
|
|
1536
|
+
* Default is `'browser'`.
|
|
1537
|
+
*
|
|
1538
|
+
* - **Output**: A `Promise` that resolves to an object containing:
|
|
1539
|
+
* - The `BuildResult` from the bundling process.
|
|
1540
|
+
* - A `metafile`, which contains detailed metadata about the build, including the dependencies analyzed.
|
|
1541
|
+
*
|
|
1542
|
+
* ## Example:
|
|
1543
|
+
*
|
|
1544
|
+
* ```ts
|
|
1545
|
+
* const result = await analyzeDependencies(['src/index.ts']);
|
|
1546
|
+
* console.log(result.metafile); // { inputs: { 'src/index.ts': { ... } }, outputs: { ... } }
|
|
1547
|
+
*
|
|
1548
|
+
* const nodeResult = await analyzeDependencies(['src/server.ts'], 'node');
|
|
1549
|
+
* console.log(nodeResult.metafile); // { inputs: { 'src/server.ts': { ... } }, outputs: { ... } }
|
|
1550
|
+
* ```
|
|
1551
|
+
*
|
|
1552
|
+
* @param entryPoint - The entry point(s) to be analyzed.
|
|
1553
|
+
* @param platform - The target platform for the build.
|
|
1554
|
+
* @returns A `Promise` that resolves to a `BuildResult` object along with a `metafile` containing dependency details.
|
|
1555
|
+
* @throws Error If the build process fails for any reason.
|
|
1556
|
+
*/
|
|
1557
|
+
declare function analyzeDependencies(entryPoint: EntryPointsType, platform?: BuildOptions['platform']): Promise<BuildResult & {
|
|
1558
|
+
metafile: Metafile;
|
|
1559
|
+
}>;
|
|
1560
|
+
|
|
1561
|
+
/**
|
|
1562
|
+
* Represents the result of transpiling a TypeScript file.
|
|
1563
|
+
*
|
|
1564
|
+
* This interface defines the structure of the output returned from a TypeScript transpilation process,
|
|
1565
|
+
* including the transpiled JavaScript code and the associated source map.
|
|
1566
|
+
*
|
|
1567
|
+
* @property code - The transpiled JavaScript code generated from the TypeScript file.
|
|
1568
|
+
* @property sourceMap - The source map associated with the transpiled JavaScript code.
|
|
1569
|
+
*
|
|
1570
|
+
* @remarks
|
|
1571
|
+
* - The `code` property contains the JavaScript code after TypeScript transpilation.
|
|
1572
|
+
* - The `sourceMap` property provides the source map that maps the transpiled JavaScript code back to the original TypeScript source.
|
|
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.
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* import { TranspileFileInterface } from './TranspileFileInterface';
|
|
1578
|
+
*
|
|
1579
|
+
* const result: TranspileFileInterface = {
|
|
1580
|
+
* code: 'console.log("Hello, world!");',
|
|
1581
|
+
* sourceMap: 'version: 3\nfile: out.js\nsources: ["file.ts"]\n'
|
|
1582
|
+
* };
|
|
1583
|
+
*
|
|
1584
|
+
* console.log(result.code); // Output: console.log("Hello, world!");
|
|
1585
|
+
* console.log(result.sourceMap); // Output: version: 3\nfile: out.js\nsources: ["file.ts"]\n
|
|
1586
|
+
* ```
|
|
1587
|
+
*
|
|
1588
|
+
* In this example, the `TranspileFileInterface` is used to represent the result of transpiling a TypeScript file.
|
|
1589
|
+
* The `code` contains the JavaScript code, while the `sourceMap` provides the mapping information for debugging purposes.
|
|
1590
|
+
*
|
|
1591
|
+
* @public
|
|
1592
|
+
* @category Interfaces
|
|
1593
|
+
*/
|
|
1594
|
+
interface TranspileFileInterface {
|
|
1595
|
+
code: string;
|
|
1596
|
+
sourceMap: string;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* Import will remove at compile time
|
|
1601
|
+
*/
|
|
1602
|
+
/**
|
|
1603
|
+
* Represents an error that occurs during the esbuild process.
|
|
1604
|
+
*
|
|
1605
|
+
* This class extends the base error class to provide specific error handling for esbuild-related issues.
|
|
1606
|
+
* It captures the error message and maintains the proper stack trace, allowing for easier debugging
|
|
1607
|
+
* and identification of errors that occur during the build process.
|
|
1608
|
+
*
|
|
1609
|
+
* @class esBuildError
|
|
1610
|
+
* @extends BaseError
|
|
1611
|
+
*/
|
|
1612
|
+
declare class esBuildError extends BaseError {
|
|
1613
|
+
originalErrorStack?: string;
|
|
1480
1614
|
/**
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1483
|
-
* This function defines the setup for an esbuild plugin, enabling hooks for various lifecycle events:
|
|
1484
|
-
* onStart, onEnd, onResolve, and onLoad. It ensures that hooks registered by the user are called at
|
|
1485
|
-
* the appropriate stages of the build process.
|
|
1486
|
-
*
|
|
1487
|
-
* @returns An object with the plugin configuration that can be passed to esbuild's `plugins` array.
|
|
1488
|
-
* The configuration includes the plugin name and setup function.
|
|
1489
|
-
*
|
|
1490
|
-
* @example
|
|
1491
|
-
* ```ts
|
|
1492
|
-
* // Example usage with esbuild:
|
|
1493
|
-
* const esbuild = require('esbuild');
|
|
1494
|
-
* const pluginProvider = new PluginsProvider();
|
|
1615
|
+
* Creates an instance of the EsbuildError class.
|
|
1495
1616
|
*
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
1498
|
-
* bundle: true,
|
|
1499
|
-
* plugins: [pluginProvider.setup()],
|
|
1500
|
-
* }).catch(() => process.exit(1));
|
|
1501
|
-
* ```
|
|
1617
|
+
* @param message - An object containing the error message. The `text` property is used to initialize
|
|
1618
|
+
* the base error class with a descriptive message about the error encountered during the esbuild process.
|
|
1502
1619
|
*/
|
|
1503
|
-
|
|
1620
|
+
constructor(message: Message);
|
|
1504
1621
|
/**
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
* This function is called when the build process starts and invokes each hook registered via
|
|
1508
|
-
* `registerOnStart`. Hooks can perform actions such as initializing tasks, logging, or setting
|
|
1509
|
-
* up build conditions.
|
|
1510
|
-
*
|
|
1511
|
-
* @param build - The esbuild `PluginBuild` object that represents the current build process.
|
|
1512
|
-
*
|
|
1513
|
-
* @returns A promise that resolves when all hooks have been executed.
|
|
1622
|
+
* Generates a formatted error message with highlighted code.
|
|
1514
1623
|
*
|
|
1515
|
-
* @
|
|
1516
|
-
*
|
|
1517
|
-
* // Registering an onStart hook
|
|
1518
|
-
* pluginProvider.registerOnStart(async (build) => {
|
|
1519
|
-
* console.log('Build started:', build);
|
|
1520
|
-
* });
|
|
1521
|
-
* ```
|
|
1624
|
+
* @param message - An esbuild Message object containing error information.
|
|
1625
|
+
* @returns A formatted string of the error message.
|
|
1522
1626
|
*/
|
|
1523
|
-
private
|
|
1627
|
+
private generateFormattedError;
|
|
1524
1628
|
/**
|
|
1525
|
-
*
|
|
1526
|
-
*
|
|
1527
|
-
* This function is called after the build process completes and invokes each hook registered via
|
|
1528
|
-
* `registerOnEnd`. Hooks can be used to process the build results, such as performing analysis or cleanup.
|
|
1529
|
-
*
|
|
1530
|
-
* @param buildResult - The build buildResult object provided by esbuild, containing details about the build process.
|
|
1531
|
-
*
|
|
1532
|
-
* @returns A promise that resolves when all hooks have been executed.
|
|
1629
|
+
* Reads code from a file if it exists.
|
|
1533
1630
|
*
|
|
1534
|
-
* @
|
|
1535
|
-
*
|
|
1536
|
-
* // Registering an onEnd hook
|
|
1537
|
-
* pluginProvider.registerOnEnd(async (buildResult) => {
|
|
1538
|
-
* console.log('Build completed:', buildResult);
|
|
1539
|
-
* });
|
|
1540
|
-
* ```
|
|
1631
|
+
* @param path - The file path to read from.
|
|
1632
|
+
* @returns Array of lines if file exists, otherwise null.
|
|
1541
1633
|
*/
|
|
1542
|
-
private
|
|
1634
|
+
private readCode;
|
|
1543
1635
|
/**
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1546
|
-
* This function is called whenever esbuild attempts to resolve a module path. It iterates over all registered
|
|
1547
|
-
* onResolve hooks and merges their results. If no hook resolves a path, `null` is returned.
|
|
1548
|
-
*
|
|
1549
|
-
* @param args - The esbuild `OnResolveArgs` object containing information about the module being resolved.
|
|
1550
|
-
*
|
|
1551
|
-
* @returns A promise that resolves to an `OnResolveResult` containing the resolved path, or `null` if no path is found.
|
|
1636
|
+
* Formats a code snippet with highlighted errors.
|
|
1552
1637
|
*
|
|
1553
|
-
* @
|
|
1554
|
-
*
|
|
1555
|
-
*
|
|
1556
|
-
* pluginProvider.registerOnResolve(async (args) => {
|
|
1557
|
-
* if (args.path === 'my-module') {
|
|
1558
|
-
* return { path: './src/my-module.ts' };
|
|
1559
|
-
* }
|
|
1560
|
-
* return null;
|
|
1561
|
-
* });
|
|
1562
|
-
* ```
|
|
1638
|
+
* @param code - Array of code lines.
|
|
1639
|
+
* @param location - The error location within the file.
|
|
1640
|
+
* @returns A formatted and highlighted code snippet string.
|
|
1563
1641
|
*/
|
|
1564
|
-
private
|
|
1642
|
+
private formatCodeSnippet;
|
|
1565
1643
|
/**
|
|
1566
|
-
*
|
|
1567
|
-
*
|
|
1568
|
-
* This function is called when esbuild attempts to load a module. It reads the module contents and then
|
|
1569
|
-
* processes it through all registered onLoad hooks. The hooks can modify the contents and loader type.
|
|
1570
|
-
*
|
|
1571
|
-
* @param args - The esbuild `OnLoadArgs` object containing information about the module being loaded.
|
|
1572
|
-
*
|
|
1573
|
-
* @returns A promise that resolves to an `OnLoadResult` containing the module contents and loader, or `null` if no contents are loaded.
|
|
1644
|
+
* Applies color to a given text if colors are enabled.
|
|
1574
1645
|
*
|
|
1575
|
-
* @
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
* pluginProvider.registerOnLoad(async (contents, loader, args) => {
|
|
1579
|
-
* if (args.path.endsWith('.json')) {
|
|
1580
|
-
* return { contents: JSON.stringify({ key: 'value' }), loader: 'json' };
|
|
1581
|
-
* }
|
|
1582
|
-
* return null;
|
|
1583
|
-
* });
|
|
1584
|
-
* ```
|
|
1646
|
+
* @param color - The color code.
|
|
1647
|
+
* @param text - The text to colorize.
|
|
1648
|
+
* @returns The colorized text if colors are active, otherwise plain text.
|
|
1585
1649
|
*/
|
|
1586
|
-
private
|
|
1650
|
+
private applyColor;
|
|
1587
1651
|
}
|
|
1652
|
+
|
|
1588
1653
|
/**
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1591
|
-
* This function processes the given code contents and removes sections that
|
|
1592
|
-
* are conditionally compiled based on the provided `defines` object.
|
|
1593
|
-
*
|
|
1594
|
-
* @param contents - The code contents to be processed.
|
|
1595
|
-
* @param defines - An object containing conditional
|
|
1596
|
-
* definitions. Keys are condition names, and values are their definitions.
|
|
1597
|
-
* @returns The processed code contents with conditional blocks removed
|
|
1598
|
-
* according to the `defines` object.
|
|
1654
|
+
* Imports
|
|
1599
1655
|
*/
|
|
1600
|
-
export declare function parseIfDefConditionals(contents: string, defines: Record<string, unknown>): string;
|
|
1601
1656
|
/**
|
|
1602
|
-
*
|
|
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.
|
|
1657
|
+
* ASCII Logo and Version Information
|
|
1611
1658
|
*
|
|
1612
1659
|
* @remarks
|
|
1613
|
-
*
|
|
1660
|
+
* The `asciiLogo` constant stores an ASCII representation of the project logo
|
|
1661
|
+
* that will be displayed in the banner. This banner is rendered in a formatted
|
|
1662
|
+
* string in the `bannerComponent` function.
|
|
1614
1663
|
*
|
|
1615
|
-
*
|
|
1664
|
+
* The `cleanScreen` constant contains an ANSI escape code to clear the terminal screen.
|
|
1616
1665
|
*/
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
emitSkipped: boolean;
|
|
1620
|
-
}
|
|
1666
|
+
declare const asciiLogo = "\n ______ _ _ _\n | ___ \\ (_) | | |\n__ _| |_/ /_ _ _| | __| |\n\\ \\/ / ___ \\ | | | | |/ _` |\n > <| |_/ / |_| | | | (_| |\n/_/\\_\\____/ \\__,_|_|_|\\__,_|\n";
|
|
1667
|
+
declare const cleanScreen = "\u001Bc";
|
|
1621
1668
|
/**
|
|
1622
|
-
*
|
|
1669
|
+
* Renders the banner with the ASCII logo and version information.
|
|
1623
1670
|
*
|
|
1624
|
-
*
|
|
1625
|
-
*
|
|
1626
|
-
*
|
|
1671
|
+
* This function constructs and returns a formatted banner string that includes an ASCII logo and the version number.
|
|
1672
|
+
* The colors used for the ASCII logo and version number can be enabled or disabled based on the `activeColor` parameter.
|
|
1673
|
+
* If color formatting is enabled, the ASCII logo will be rendered in burnt orange, and the version number will be in bright pink.
|
|
1627
1674
|
*
|
|
1628
|
-
* @
|
|
1675
|
+
* @param activeColor - A boolean flag indicating whether ANSI color formatting should be applied. Default is `__ACTIVE_COLOR`.
|
|
1629
1676
|
*
|
|
1630
|
-
* @
|
|
1677
|
+
* @returns A formatted string containing the ASCII logo, version number, and ANSI color codes if `activeColor` is `true`.
|
|
1631
1678
|
*
|
|
1632
|
-
* @
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
* Header text included at the top of generated declaration bundle files
|
|
1679
|
+
* @remarks
|
|
1680
|
+
* The `bannerComponent` function clears the terminal screen, applies color formatting if enabled, and displays
|
|
1681
|
+
* the ASCII logo and version number. The version number is retrieved from the global `__VERSION` variable, and
|
|
1682
|
+
* the colors are reset after the text is rendered.
|
|
1637
1683
|
*
|
|
1638
|
-
* @
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
*
|
|
1642
|
-
*
|
|
1684
|
+
* @example
|
|
1685
|
+
* ```ts
|
|
1686
|
+
* console.log(bannerComponent());
|
|
1687
|
+
* ```
|
|
1688
|
+
*
|
|
1689
|
+
* This will output the banner to the console with the ASCII logo, version, and colors.
|
|
1643
1690
|
*
|
|
1644
1691
|
* @example
|
|
1645
1692
|
* ```ts
|
|
1646
|
-
*
|
|
1647
|
-
* writeFileSync('dist/index.d.ts', bundledContent);
|
|
1693
|
+
* console.log(bannerComponent(false));
|
|
1648
1694
|
* ```
|
|
1649
1695
|
*
|
|
1650
|
-
*
|
|
1696
|
+
* This will output the banner to the console with the ASCII logo and version number without color formatting.
|
|
1697
|
+
*
|
|
1698
|
+
* @public
|
|
1651
1699
|
*/
|
|
1652
|
-
|
|
1700
|
+
declare function bannerComponent(activeColor?: boolean): string;
|
|
1653
1701
|
/**
|
|
1654
|
-
*
|
|
1655
|
-
*
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
*
|
|
1702
|
+
* A formatted string prefix used for logging build-related messages.
|
|
1703
|
+
* // todo optimize this
|
|
1704
|
+
*/
|
|
1705
|
+
declare function prefix(): string;
|
|
1706
|
+
|
|
1707
|
+
/**
|
|
1708
|
+
* Import will remove at compile time
|
|
1709
|
+
*/
|
|
1710
|
+
/**
|
|
1711
|
+
* Manages the HTTP or HTTPS server based on the provided configuration.
|
|
1661
1712
|
*
|
|
1662
|
-
*
|
|
1663
|
-
*
|
|
1713
|
+
* The `ServerProvider` class initializes and starts either an HTTP or HTTPS server based on whether SSL certificates
|
|
1714
|
+
* are provided. It handles incoming requests, serves static files, and lists directory contents with appropriate
|
|
1715
|
+
* icons and colors.
|
|
1664
1716
|
*
|
|
1665
|
-
* @
|
|
1717
|
+
* @class
|
|
1666
1718
|
*/
|
|
1667
|
-
|
|
1668
|
-
private readonly options;
|
|
1719
|
+
declare class ServerProvider {
|
|
1669
1720
|
/**
|
|
1670
|
-
*
|
|
1671
|
-
* Keys are absolute file paths and values are incrementing version numbers.
|
|
1672
|
-
*
|
|
1673
|
-
* @since 1.5.9
|
|
1721
|
+
* Root dir to serve
|
|
1674
1722
|
*/
|
|
1675
|
-
private readonly
|
|
1723
|
+
private readonly rootDir;
|
|
1676
1724
|
/**
|
|
1677
|
-
*
|
|
1678
|
-
*
|
|
1679
|
-
* @param options - Compiler options to use for TypeScript operations
|
|
1680
|
-
*
|
|
1681
|
-
* @since 1.5.9
|
|
1725
|
+
* Indicates whether the server is configured to use HTTPS.
|
|
1682
1726
|
*/
|
|
1683
|
-
|
|
1727
|
+
private readonly isHttps;
|
|
1684
1728
|
/**
|
|
1685
|
-
*
|
|
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
|
-
*
|
|
1690
|
-
* @since 1.5.9
|
|
1729
|
+
* The server configuration object, including SSL certificate paths and other settings.
|
|
1691
1730
|
*/
|
|
1692
|
-
|
|
1731
|
+
private readonly config;
|
|
1693
1732
|
/**
|
|
1694
|
-
*
|
|
1695
|
-
* Required by the LanguageServiceHost interface.
|
|
1733
|
+
* Creates an instance of ServerProvider.
|
|
1696
1734
|
*
|
|
1697
|
-
* @param
|
|
1698
|
-
* @
|
|
1735
|
+
* @param config - The server configuration object, including port number, SSL certificate paths, and an optional request handler.
|
|
1736
|
+
* @param dir - The root directory from which to serve files.
|
|
1699
1737
|
*
|
|
1700
|
-
* @
|
|
1701
|
-
*
|
|
1702
|
-
|
|
1703
|
-
fileExists(path: string): boolean;
|
|
1704
|
-
/**
|
|
1705
|
-
* Reads the content of a file at the specified path.
|
|
1706
|
-
* Required by the LanguageServiceHost interface.
|
|
1738
|
+
* @example
|
|
1739
|
+
* ```ts
|
|
1740
|
+
* import { ServerProvider } from './server-provider';
|
|
1707
1741
|
*
|
|
1708
|
-
*
|
|
1709
|
-
*
|
|
1710
|
-
*
|
|
1742
|
+
* const serverConfig = {
|
|
1743
|
+
* port: 8080,
|
|
1744
|
+
* keyfile: './path/to/keyfile',
|
|
1745
|
+
* certfile: './path/to/certfile',
|
|
1746
|
+
* onRequest: (req, res, next) => { /* custom request handling *\/ }
|
|
1747
|
+
* };
|
|
1748
|
+
* const provider = new ServerProvider(serverConfig, './public');
|
|
1749
|
+
* provider.start();
|
|
1750
|
+
* ```
|
|
1711
1751
|
*
|
|
1712
|
-
*
|
|
1713
|
-
* @since 1.5.9
|
|
1752
|
+
* This example shows how to create an instance of `ServerProvider` and start the server.
|
|
1714
1753
|
*/
|
|
1715
|
-
|
|
1754
|
+
constructor(config: ServeInterface, dir: string);
|
|
1716
1755
|
/**
|
|
1717
|
-
*
|
|
1718
|
-
*
|
|
1756
|
+
* Starts the server based on the configuration.
|
|
1757
|
+
* If SSL certificates are provided and valid, an HTTPS server is started. Otherwise, an HTTP server is started.
|
|
1719
1758
|
*
|
|
1720
|
-
* @
|
|
1721
|
-
*
|
|
1722
|
-
*
|
|
1723
|
-
*
|
|
1724
|
-
* @param depth - Optional maximum depth to search
|
|
1725
|
-
* @returns Array of file paths found in the directory
|
|
1759
|
+
* @example
|
|
1760
|
+
* ```ts
|
|
1761
|
+
* provider.start();
|
|
1762
|
+
* ```
|
|
1726
1763
|
*
|
|
1727
|
-
*
|
|
1728
|
-
* @since 1.5.9
|
|
1764
|
+
* This example demonstrates how to start the server. It will either start an HTTP or HTTPS server based on the configuration.
|
|
1729
1765
|
*/
|
|
1730
|
-
|
|
1766
|
+
start(): void;
|
|
1731
1767
|
/**
|
|
1732
|
-
*
|
|
1733
|
-
*
|
|
1768
|
+
* Starts an HTTP server.
|
|
1769
|
+
* This method creates an HTTP server that listens on the configured port and handles incoming requests.
|
|
1734
1770
|
*
|
|
1735
|
-
* @
|
|
1736
|
-
*
|
|
1771
|
+
* @example
|
|
1772
|
+
* ```ts
|
|
1773
|
+
* provider.startHttpServer();
|
|
1774
|
+
* ```
|
|
1737
1775
|
*
|
|
1738
|
-
*
|
|
1739
|
-
* @since 1.5.9
|
|
1776
|
+
* This example shows how the `startHttpServer` method is used internally to start an HTTP server.
|
|
1740
1777
|
*/
|
|
1741
|
-
|
|
1778
|
+
private startHttpServer;
|
|
1742
1779
|
/**
|
|
1743
|
-
*
|
|
1744
|
-
*
|
|
1745
|
-
* @param path - Path to check for directory existence
|
|
1746
|
-
* @returns True if the directory exists, false otherwise
|
|
1780
|
+
* Starts an HTTPS server.
|
|
1747
1781
|
*
|
|
1748
|
-
*
|
|
1749
|
-
*/
|
|
1750
|
-
directoryExists(path: string): boolean;
|
|
1751
|
-
/**
|
|
1752
|
-
* Gets the current working directory.
|
|
1753
|
-
* Required by the LanguageServiceHost interface.
|
|
1782
|
+
* This method creates an HTTPS server with SSL/TLS certificates, listens on the configured port, and handles incoming requests.
|
|
1754
1783
|
*
|
|
1755
|
-
* @
|
|
1784
|
+
* @example
|
|
1785
|
+
* ```ts
|
|
1786
|
+
* provider.startHttpsServer();
|
|
1787
|
+
* ```
|
|
1756
1788
|
*
|
|
1757
|
-
*
|
|
1758
|
-
* @since 1.5.9
|
|
1789
|
+
* This example shows how the `startHttpsServer` method is used internally to start an HTTPS server.
|
|
1759
1790
|
*/
|
|
1760
|
-
|
|
1791
|
+
private startHttpsServer;
|
|
1761
1792
|
/**
|
|
1762
|
-
*
|
|
1763
|
-
* Required by the LanguageServiceHost interface to identify the set of source files.
|
|
1764
|
-
*
|
|
1765
|
-
* @returns Array of script file paths that should be included in the program
|
|
1793
|
+
* Handles incoming requests.
|
|
1766
1794
|
*
|
|
1767
|
-
*
|
|
1768
|
-
*
|
|
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.
|
|
1795
|
+
* This method checks if a custom request handler is provided in the configuration. If so, it uses the custom handler.
|
|
1796
|
+
* Otherwise, it delegates to the default request handler.
|
|
1774
1797
|
*
|
|
1775
|
-
* @
|
|
1798
|
+
* @param req - The incoming request object.
|
|
1799
|
+
* @param res - The response object.
|
|
1800
|
+
* @param defaultHandler - The default handler functions to be called if no custom handler is provided.
|
|
1776
1801
|
*
|
|
1777
|
-
* @
|
|
1778
|
-
*
|
|
1802
|
+
* @example
|
|
1803
|
+
* ```ts
|
|
1804
|
+
* // This method is used internally to handle requests
|
|
1805
|
+
* ```
|
|
1779
1806
|
*/
|
|
1780
|
-
|
|
1807
|
+
private handleRequest;
|
|
1781
1808
|
/**
|
|
1782
|
-
*
|
|
1783
|
-
* Required by the LanguageServiceHost interface to include standard TypeScript definitions.
|
|
1784
|
-
*
|
|
1785
|
-
* @param options - Compiler options to use for determining the default library
|
|
1786
|
-
* @returns Path to the default library file
|
|
1809
|
+
* Returns the MIME type for a given file extension.
|
|
1787
1810
|
*
|
|
1788
|
-
*
|
|
1789
|
-
* @since 1.5.9
|
|
1790
|
-
*/
|
|
1791
|
-
getDefaultLibFileName(options: CompilerOptions): string;
|
|
1792
|
-
/**
|
|
1793
|
-
* Gets the current version of a script file.
|
|
1794
|
-
* Required by the LanguageServiceHost interface to determine if a file has changed.
|
|
1811
|
+
* This method maps file extensions to their corresponding MIME types.
|
|
1795
1812
|
*
|
|
1796
|
-
* @param
|
|
1797
|
-
* @returns The
|
|
1813
|
+
* @param ext - The file extension.
|
|
1814
|
+
* @returns The MIME type associated with the file extension.
|
|
1798
1815
|
*
|
|
1799
|
-
* @
|
|
1800
|
-
*
|
|
1816
|
+
* @example
|
|
1817
|
+
* ```ts
|
|
1818
|
+
* const mimeType = provider.getContentType('html');
|
|
1819
|
+
* console.log(mimeType); // 'text/html'
|
|
1820
|
+
* ```
|
|
1801
1821
|
*/
|
|
1802
|
-
|
|
1822
|
+
private getContentType;
|
|
1803
1823
|
/**
|
|
1804
|
-
*
|
|
1805
|
-
* Required by the LanguageServiceHost interface to provide file content to the language service.
|
|
1824
|
+
* Handles the default response for requests, serving files or directories.
|
|
1806
1825
|
*
|
|
1807
|
-
*
|
|
1808
|
-
*
|
|
1826
|
+
* This method serves the content of files or directories. If the request is for a directory, it lists the contents with
|
|
1827
|
+
* appropriate icons and colors.
|
|
1809
1828
|
*
|
|
1810
|
-
* @
|
|
1811
|
-
* @
|
|
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
|
-
* Cache of processed declaration files to avoid redundant processing
|
|
1829
|
+
* @param req - The incoming request object.
|
|
1830
|
+
* @param res - The response object.
|
|
1850
1831
|
*
|
|
1851
|
-
* @
|
|
1852
|
-
*/
|
|
1853
|
-
private readonly processedFiles;
|
|
1854
|
-
/**
|
|
1855
|
-
* Creates a new DeclarationBundlerService instance
|
|
1832
|
+
* @returns A promise that resolves when the response is sent.
|
|
1856
1833
|
*
|
|
1857
|
-
* @
|
|
1858
|
-
* @param languageService - TypeScript language service for compilation
|
|
1834
|
+
* @throws Throws an error if the file or directory cannot be accessed.
|
|
1859
1835
|
*
|
|
1860
|
-
* @
|
|
1836
|
+
* @example
|
|
1837
|
+
* ```ts
|
|
1838
|
+
* // This method is used internally to handle file and directory responses
|
|
1839
|
+
* ```
|
|
1861
1840
|
*/
|
|
1862
|
-
|
|
1841
|
+
private defaultResponse;
|
|
1863
1842
|
/**
|
|
1864
|
-
*
|
|
1843
|
+
* promisifyStat the `fs.stat` method.
|
|
1865
1844
|
*
|
|
1866
|
-
*
|
|
1867
|
-
* @returns Array of bundled declaration content strings
|
|
1845
|
+
* Converts the `fs.stat` callback-based method to return a promise.
|
|
1868
1846
|
*
|
|
1869
|
-
* @
|
|
1870
|
-
*
|
|
1871
|
-
* to generate bundled declarations. Entry points should be absolute paths
|
|
1872
|
-
* to TypeScript source files.
|
|
1847
|
+
* @param path - The file or directory path.
|
|
1848
|
+
* @returns A promise that resolves with the file statistics.
|
|
1873
1849
|
*
|
|
1874
|
-
* @
|
|
1850
|
+
* @example
|
|
1851
|
+
* ```ts
|
|
1852
|
+
* const stats = await provider.promisifyStat('./path/to/file');
|
|
1853
|
+
* console.log(stats.isFile()); // true or false
|
|
1854
|
+
* ```
|
|
1875
1855
|
*/
|
|
1876
|
-
|
|
1856
|
+
private promisifyStat;
|
|
1877
1857
|
/**
|
|
1878
|
-
*
|
|
1858
|
+
* Handles directory listings.
|
|
1879
1859
|
*
|
|
1880
|
-
*
|
|
1881
|
-
* @returns Bundled declaration content or undefined if generation fails
|
|
1860
|
+
* Reads the contents of a directory and generates an HTML response with file icons and colors.
|
|
1882
1861
|
*
|
|
1883
|
-
* @
|
|
1884
|
-
* @
|
|
1862
|
+
* @param fullPath - The full path to the directory.
|
|
1863
|
+
* @param requestPath - The request path for generating relative links.
|
|
1864
|
+
* @param res - The response object.
|
|
1885
1865
|
*
|
|
1886
|
-
* @
|
|
1887
|
-
*
|
|
1888
|
-
*
|
|
1889
|
-
*
|
|
1866
|
+
* @example
|
|
1867
|
+
* ```ts
|
|
1868
|
+
* // This method is used internally to handle directory listings
|
|
1869
|
+
* ```
|
|
1870
|
+
*/
|
|
1871
|
+
private handleDirectory;
|
|
1872
|
+
/**
|
|
1873
|
+
* Handles file responses.
|
|
1890
1874
|
*
|
|
1891
|
-
*
|
|
1892
|
-
* TypeScript project configuration.
|
|
1875
|
+
* Reads and serves the content of a file.
|
|
1893
1876
|
*
|
|
1894
|
-
* @
|
|
1877
|
+
* @param fullPath - The full path to the file.
|
|
1878
|
+
* @param res - The response object.
|
|
1879
|
+
*
|
|
1880
|
+
* @example
|
|
1881
|
+
* ```ts
|
|
1882
|
+
* // This method is used internally to handle file responses
|
|
1883
|
+
* ```
|
|
1895
1884
|
*/
|
|
1896
|
-
private
|
|
1885
|
+
private handleFile;
|
|
1897
1886
|
/**
|
|
1898
|
-
*
|
|
1887
|
+
* Sends a 404 Not Found response.
|
|
1899
1888
|
*
|
|
1900
|
-
* @param
|
|
1901
|
-
* @param containingFile - The file containing the import
|
|
1902
|
-
* @param program - The TypeScript program
|
|
1889
|
+
* @param res - The response object.
|
|
1903
1890
|
*
|
|
1904
|
-
* @
|
|
1891
|
+
* @example
|
|
1892
|
+
* ```ts
|
|
1893
|
+
* provider.sendNotFound(response);
|
|
1894
|
+
* ```
|
|
1905
1895
|
*
|
|
1906
|
-
*
|
|
1896
|
+
* This example demonstrates how to send a 404 response using the `sendNotFound` method.
|
|
1907
1897
|
*/
|
|
1908
|
-
private
|
|
1898
|
+
private sendNotFound;
|
|
1909
1899
|
/**
|
|
1910
|
-
*
|
|
1900
|
+
* Sends an error response.
|
|
1911
1901
|
*
|
|
1912
|
-
* @param
|
|
1913
|
-
* @param
|
|
1914
|
-
* @param collectedFiles - Set of collected file paths
|
|
1902
|
+
* @param res - The response object.
|
|
1903
|
+
* @param error - The error object.
|
|
1915
1904
|
*
|
|
1916
|
-
* @
|
|
1917
|
-
*
|
|
1918
|
-
*
|
|
1905
|
+
* @example
|
|
1906
|
+
* ```ts
|
|
1907
|
+
* provider.sendError(response, new Error('Some error'));
|
|
1908
|
+
* ```
|
|
1919
1909
|
*
|
|
1920
|
-
*
|
|
1910
|
+
* This example shows how to send an error response using the `sendError` method.
|
|
1921
1911
|
*/
|
|
1922
|
-
private
|
|
1912
|
+
private sendError;
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* Import will remove at compile time
|
|
1917
|
+
*/
|
|
1918
|
+
/**
|
|
1919
|
+
* Plugin provider for esbuild that registers hooks for lifecycle events such as onStart, onEnd, onResolve, and onLoad.
|
|
1920
|
+
* This class allows dynamic behavior by registering multiple hooks for different stages of the build process.
|
|
1921
|
+
*/
|
|
1922
|
+
declare class PluginsProvider {
|
|
1923
1923
|
/**
|
|
1924
|
-
*
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
*
|
|
1924
|
+
* Holds the build state that hooks can modify.
|
|
1925
|
+
*/
|
|
1926
|
+
private buildState;
|
|
1927
|
+
/**
|
|
1928
|
+
* Holds the registered hooks for the `onEnd` lifecycle event.
|
|
1929
|
+
* This array contains functions that are called after the build process completes.
|
|
1930
|
+
*/
|
|
1931
|
+
private onEndHooks;
|
|
1932
|
+
/**
|
|
1933
|
+
* Holds the registered hooks for the `onSuccess` lifecycle event.
|
|
1934
|
+
* This array contains functions that are called after the build success finish.
|
|
1935
|
+
*/
|
|
1936
|
+
private onSuccess;
|
|
1937
|
+
/**
|
|
1938
|
+
* Holds the registered hooks for the `onLoad` lifecycle event.
|
|
1939
|
+
* This array contains functions that are called when esbuild attempts to load a module.
|
|
1940
|
+
*/
|
|
1941
|
+
private onLoadHooks;
|
|
1942
|
+
/**
|
|
1943
|
+
* Holds the registered hooks for the `onStart` lifecycle event.
|
|
1944
|
+
* This array contains functions that are called before the build process starts.
|
|
1945
|
+
*/
|
|
1946
|
+
private onStartHooks;
|
|
1947
|
+
/**
|
|
1948
|
+
* Holds the registered hooks for the `onResolve` lifecycle event.
|
|
1949
|
+
* This array contains functions that are called when esbuild attempts to resolve a module path.
|
|
1950
|
+
*/
|
|
1951
|
+
private onResolveHooks;
|
|
1952
|
+
/**
|
|
1953
|
+
* Registers a hook function for the `onStart` lifecycle event.
|
|
1954
|
+
* The hook will be called before the build process starts.
|
|
1929
1955
|
*
|
|
1930
|
-
* @
|
|
1931
|
-
* This method collects all exported symbols from a module, including
|
|
1932
|
-
* nested module exports for namespace declarations.
|
|
1956
|
+
* @param fn - A function of type `OnStartType` that will be executed when the build process starts.
|
|
1933
1957
|
*
|
|
1934
|
-
* @
|
|
1958
|
+
* @example
|
|
1959
|
+
* ```ts
|
|
1960
|
+
* pluginProvider.registerOnStart(async (build) => {
|
|
1961
|
+
* console.log('Build started:', build);
|
|
1962
|
+
* });
|
|
1963
|
+
* ```
|
|
1935
1964
|
*/
|
|
1936
|
-
|
|
1965
|
+
registerOnStart(fn: OnStartType | undefined): void;
|
|
1937
1966
|
/**
|
|
1938
|
-
*
|
|
1967
|
+
* Registers a hook function for the `onEnd` lifecycle event.
|
|
1968
|
+
* The hook will be called after the build process completes.
|
|
1939
1969
|
*
|
|
1940
|
-
* @param
|
|
1941
|
-
* @param collectedSymbols - Set of exported symbol names
|
|
1942
|
-
* @returns Object containing bundled content and external imports
|
|
1970
|
+
* @param fn - A function of type `OnEndType` that will be executed after the build completes.
|
|
1943
1971
|
*
|
|
1944
|
-
* @
|
|
1972
|
+
* @example
|
|
1973
|
+
* ```ts
|
|
1974
|
+
* pluginProvider.registerOnEnd(async (result) => {
|
|
1975
|
+
* console.log('Build finished:', result);
|
|
1976
|
+
* });
|
|
1977
|
+
* ```
|
|
1945
1978
|
*/
|
|
1946
|
-
|
|
1979
|
+
registerOnEnd(fn: OnEndType | undefined): void;
|
|
1947
1980
|
/**
|
|
1948
|
-
*
|
|
1981
|
+
* Registers a hook function for the `onSuccess` lifecycle event.
|
|
1982
|
+
* The hook will be called after the build success completes.
|
|
1949
1983
|
*
|
|
1950
|
-
* @param
|
|
1951
|
-
* @param checker - The TypeScript type checker
|
|
1952
|
-
* @param collectedSymbols - Set to store collected symbol names
|
|
1984
|
+
* @param fn - A function of type `OnEndType` that will be executed after the build completes.
|
|
1953
1985
|
*
|
|
1954
|
-
* @
|
|
1986
|
+
* @example
|
|
1987
|
+
* ```ts
|
|
1988
|
+
* pluginProvider.registerOnSuccess(async (result) => {
|
|
1989
|
+
* console.log('Build Success finished:', result);
|
|
1990
|
+
* });
|
|
1991
|
+
* ```
|
|
1955
1992
|
*/
|
|
1956
|
-
|
|
1993
|
+
registerOnSuccess(fn: OnEndType | undefined): void;
|
|
1957
1994
|
/**
|
|
1958
|
-
*
|
|
1995
|
+
* Registers a hook function for the `onResolve` lifecycle event.
|
|
1996
|
+
* The hook will be called when esbuild attempts to resolve a module path.
|
|
1959
1997
|
*
|
|
1960
|
-
* @param
|
|
1961
|
-
* @param collectedSymbols - Set of exported symbol names
|
|
1962
|
-
* @param externalImports - Set to store external import statements
|
|
1963
|
-
* @returns Processed declaration content or undefined if processing fails
|
|
1998
|
+
* @param fn - A function of type `OnResolveType` that will be executed during module resolution.
|
|
1964
1999
|
*
|
|
1965
|
-
* @
|
|
1966
|
-
*
|
|
1967
|
-
*
|
|
1968
|
-
*
|
|
2000
|
+
* @example
|
|
2001
|
+
* ```ts
|
|
2002
|
+
* pluginProvider.registerOnResolve(async (args) => {
|
|
2003
|
+
* if (args.path === 'my-module') {
|
|
2004
|
+
* return { path: './src/my-module.ts' };
|
|
2005
|
+
* }
|
|
2006
|
+
* return null;
|
|
2007
|
+
* });
|
|
2008
|
+
* ```
|
|
2009
|
+
*/
|
|
2010
|
+
registerOnResolve(fn: OnResolveType | undefined): void;
|
|
2011
|
+
/**
|
|
2012
|
+
* Registers a hook function for the `onLoad` lifecycle event.
|
|
2013
|
+
* The hook will be called when esbuild attempts to load a module.
|
|
1969
2014
|
*
|
|
1970
|
-
* @
|
|
2015
|
+
* @param fn - A function of type `OnLoadType` that will be executed during module loading.
|
|
2016
|
+
*
|
|
2017
|
+
* @example
|
|
2018
|
+
* ```ts
|
|
2019
|
+
* pluginProvider.registerOnLoad(async (contents, loader, args) => {
|
|
2020
|
+
* if (args.path.endsWith('.json')) {
|
|
2021
|
+
* return { contents: JSON.stringify({ key: 'value' }), loader: 'json' };
|
|
2022
|
+
* }
|
|
2023
|
+
* return null;
|
|
2024
|
+
* });
|
|
2025
|
+
* ```
|
|
1971
2026
|
*/
|
|
1972
|
-
|
|
2027
|
+
registerOnLoad(fn: OnLoadType | undefined): void;
|
|
1973
2028
|
/**
|
|
1974
|
-
*
|
|
2029
|
+
* Registers esbuild plugin hooks and sets up the middleware plugin.
|
|
1975
2030
|
*
|
|
1976
|
-
*
|
|
1977
|
-
*
|
|
2031
|
+
* This function defines the setup for an esbuild plugin, enabling hooks for various lifecycle events:
|
|
2032
|
+
* onStart, onEnd, onResolve, and onLoad. It ensures that hooks registered by the user are called at
|
|
2033
|
+
* the appropriate stages of the build process.
|
|
1978
2034
|
*
|
|
1979
|
-
* @
|
|
2035
|
+
* @returns An object with the plugin configuration that can be passed to esbuild's `plugins` array.
|
|
2036
|
+
* The configuration includes the plugin name and setup function.
|
|
2037
|
+
*
|
|
2038
|
+
* @example
|
|
2039
|
+
* ```ts
|
|
2040
|
+
* // Example usage with esbuild:
|
|
2041
|
+
* const esbuild = require('esbuild');
|
|
2042
|
+
* const pluginProvider = new PluginsProvider();
|
|
2043
|
+
*
|
|
2044
|
+
* esbuild.build({
|
|
2045
|
+
* entryPoints: ['./src/index.ts'],
|
|
2046
|
+
* bundle: true,
|
|
2047
|
+
* plugins: [pluginProvider.setup()],
|
|
2048
|
+
* }).catch(() => process.exit(1));
|
|
2049
|
+
* ```
|
|
1980
2050
|
*/
|
|
1981
|
-
|
|
2051
|
+
setup(): Plugin;
|
|
1982
2052
|
/**
|
|
1983
|
-
*
|
|
2053
|
+
* Executes all registered onStart hooks.
|
|
1984
2054
|
*
|
|
1985
|
-
*
|
|
1986
|
-
*
|
|
2055
|
+
* This function is called when the build process starts and invokes each hook registered via
|
|
2056
|
+
* `registerOnStart`. Hooks can perform actions such as initializing tasks, logging, or setting
|
|
2057
|
+
* up build conditions.
|
|
1987
2058
|
*
|
|
1988
|
-
* @
|
|
2059
|
+
* @param build - The esbuild `PluginBuild` object that represents the current build process.
|
|
2060
|
+
*
|
|
2061
|
+
* @returns A promise that resolves when all hooks have been executed.
|
|
2062
|
+
*
|
|
2063
|
+
* @example
|
|
2064
|
+
* ```ts
|
|
2065
|
+
* // Registering an onStart hook
|
|
2066
|
+
* pluginProvider.registerOnStart(async (build) => {
|
|
2067
|
+
* console.log('Build started:', build);
|
|
2068
|
+
* });
|
|
2069
|
+
* ```
|
|
1989
2070
|
*/
|
|
1990
|
-
private
|
|
2071
|
+
private handleOnStart;
|
|
1991
2072
|
/**
|
|
1992
|
-
*
|
|
2073
|
+
* Executes all registered onEnd hooks after the build finishes.
|
|
1993
2074
|
*
|
|
1994
|
-
*
|
|
1995
|
-
*
|
|
1996
|
-
* @returns True if the module is external
|
|
2075
|
+
* This function is called after the build process completes and invokes each hook registered via
|
|
2076
|
+
* `registerOnEnd`. Hooks can be used to process the build results, such as performing analysis or cleanup.
|
|
1997
2077
|
*
|
|
1998
|
-
* @
|
|
1999
|
-
* This method determines if a module is external by checking if it's a relative
|
|
2000
|
-
* or absolute path, and by resolving the module to see if it's in node_modules.
|
|
2078
|
+
* @param buildResult - The build buildResult object provided by esbuild, containing details about the build process.
|
|
2001
2079
|
*
|
|
2002
|
-
* @
|
|
2080
|
+
* @returns A promise that resolves when all hooks have been executed.
|
|
2081
|
+
*
|
|
2082
|
+
* @example
|
|
2083
|
+
* ```ts
|
|
2084
|
+
* // Registering an onEnd hook
|
|
2085
|
+
* pluginProvider.registerOnEnd(async (buildResult) => {
|
|
2086
|
+
* console.log('Build completed:', buildResult);
|
|
2087
|
+
* });
|
|
2088
|
+
* ```
|
|
2003
2089
|
*/
|
|
2004
|
-
private
|
|
2090
|
+
private handleOnEnd;
|
|
2005
2091
|
/**
|
|
2006
|
-
*
|
|
2092
|
+
* Resolves module imports using registered onResolve hooks.
|
|
2007
2093
|
*
|
|
2008
|
-
*
|
|
2009
|
-
*
|
|
2010
|
-
* @returns The processed line
|
|
2094
|
+
* This function is called whenever esbuild attempts to resolve a module path. It iterates over all registered
|
|
2095
|
+
* onResolve hooks and merges their results. If no hook resolves a path, `null` is returned.
|
|
2011
2096
|
*
|
|
2012
|
-
* @
|
|
2013
|
-
* This method processes an export declaration line, removing the 'export'
|
|
2014
|
-
* keyword if the symbol is not in the collected exports.
|
|
2097
|
+
* @param args - The esbuild `OnResolveArgs` object containing information about the module being resolved.
|
|
2015
2098
|
*
|
|
2016
|
-
* @
|
|
2099
|
+
* @returns A promise that resolves to an `OnResolveResult` containing the resolved path, or `null` if no path is found.
|
|
2100
|
+
*
|
|
2101
|
+
* @example
|
|
2102
|
+
* ```ts
|
|
2103
|
+
* // Registering an onResolve hook
|
|
2104
|
+
* pluginProvider.registerOnResolve(async (args) => {
|
|
2105
|
+
* if (args.path === 'my-module') {
|
|
2106
|
+
* return { path: './src/my-module.ts' };
|
|
2107
|
+
* }
|
|
2108
|
+
* return null;
|
|
2109
|
+
* });
|
|
2110
|
+
* ```
|
|
2017
2111
|
*/
|
|
2018
|
-
private
|
|
2112
|
+
private handleOnResolve;
|
|
2019
2113
|
/**
|
|
2020
|
-
*
|
|
2114
|
+
* Loads module contents using registered onLoad hooks.
|
|
2021
2115
|
*
|
|
2022
|
-
*
|
|
2023
|
-
*
|
|
2024
|
-
* @returns The final bundled declaration content
|
|
2116
|
+
* This function is called when esbuild attempts to load a module. It reads the module contents and then
|
|
2117
|
+
* processes it through all registered onLoad hooks. The hooks can modify the contents and loader type.
|
|
2025
2118
|
*
|
|
2026
|
-
* @
|
|
2119
|
+
* @param args - The esbuild `OnLoadArgs` object containing information about the module being loaded.
|
|
2120
|
+
*
|
|
2121
|
+
* @returns A promise that resolves to an `OnLoadResult` containing the module contents and loader, or `null` if no contents are loaded.
|
|
2122
|
+
*
|
|
2123
|
+
* @example
|
|
2124
|
+
* ```ts
|
|
2125
|
+
* // Registering an onLoad hook
|
|
2126
|
+
* pluginProvider.registerOnLoad(async (contents, loader, args) => {
|
|
2127
|
+
* if (args.path.endsWith('.json')) {
|
|
2128
|
+
* return { contents: JSON.stringify({ key: 'value' }), loader: 'json' };
|
|
2129
|
+
* }
|
|
2130
|
+
* return null;
|
|
2131
|
+
* });
|
|
2132
|
+
* ```
|
|
2027
2133
|
*/
|
|
2028
|
-
private
|
|
2134
|
+
private handleOnLoad;
|
|
2029
2135
|
}
|
|
2136
|
+
|
|
2137
|
+
/**
|
|
2138
|
+
* Parses and filters content based on conditional directives.
|
|
2139
|
+
*
|
|
2140
|
+
* This function processes the given code contents and removes sections that
|
|
2141
|
+
* are conditionally compiled based on the provided `defines` object.
|
|
2142
|
+
*
|
|
2143
|
+
* @param contents - The code contents to be processed.
|
|
2144
|
+
* @param defines - An object containing conditional
|
|
2145
|
+
* definitions. Keys are condition names, and values are their definitions.
|
|
2146
|
+
* @returns The processed code contents with conditional blocks removed
|
|
2147
|
+
* according to the `defines` object.
|
|
2148
|
+
*/
|
|
2149
|
+
declare function parseIfDefConditionals(contents: string, defines: Record<string, unknown>): string;
|
|
2150
|
+
|
|
2151
|
+
/**
|
|
2152
|
+
* Import will remove at compile time
|
|
2153
|
+
*/
|
|
2030
2154
|
/**
|
|
2031
2155
|
* Manages TypeScript compilation, type checking, and declaration file generation using TypeScript's
|
|
2032
2156
|
* language service API.
|
|
@@ -2041,7 +2165,7 @@ export declare class DeclarationBundlerService {
|
|
|
2041
2165
|
*
|
|
2042
2166
|
* @since 1.5.9
|
|
2043
2167
|
*/
|
|
2044
|
-
|
|
2168
|
+
declare class TypescriptModule {
|
|
2045
2169
|
/**
|
|
2046
2170
|
* The root directory of the TypeScript project.
|
|
2047
2171
|
* @since 1.5.9
|
|
@@ -2322,518 +2446,590 @@ export declare class TypescriptModule {
|
|
|
2322
2446
|
*/
|
|
2323
2447
|
private getDiagnostics;
|
|
2324
2448
|
}
|
|
2449
|
+
|
|
2325
2450
|
/**
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2328
|
-
* This function takes a string of content and replaces occurrences of defined path alias keys
|
|
2329
|
-
* with their corresponding relative paths derived from the specified source file and root directory.
|
|
2330
|
-
* It ensures that the resulting paths are relative to the directory of the source file and formatted
|
|
2331
|
-
* correctly for use in a JavaScript/TypeScript environment.
|
|
2332
|
-
*
|
|
2333
|
-
* Example:
|
|
2334
|
-
* Given the following inputs:
|
|
2335
|
-
* ```ts
|
|
2336
|
-
* const content = "import { foo } from '@core/foo';";
|
|
2337
|
-
* const sourceFile = "/project/src/index.ts";
|
|
2338
|
-
* const paths = {
|
|
2339
|
-
* '@core/': 'src/core',
|
|
2340
|
-
* '@utils/': 'src/utils'
|
|
2341
|
-
* };
|
|
2342
|
-
* const rootDir = "/project";
|
|
2343
|
-
* ```
|
|
2344
|
-
* The function will replace `@core/foo` with a relative path based on the source file's location,
|
|
2345
|
-
* potentially resulting in:
|
|
2346
|
-
* ```ts
|
|
2347
|
-
* const content = "import { foo } from './core/foo';";
|
|
2348
|
-
* ```
|
|
2349
|
-
*
|
|
2350
|
-
* @param content - The content in which path aliases need to be resolved.
|
|
2351
|
-
* @param sourceFile - The path of the source file from which relative paths will be calculated.
|
|
2352
|
-
* @param paths - An object mapping path alias keys to their corresponding paths.
|
|
2353
|
-
* @param esm - A flag indicating whether ESM is enabled.
|
|
2354
|
-
* @returns The updated content with resolved path aliases.
|
|
2451
|
+
* Import will remove at compile time
|
|
2355
2452
|
*/
|
|
2356
|
-
export declare function resolveAliasPlugin(content: string, sourceFile: string, paths: Record<string, string>, esm: boolean): string;
|
|
2357
2453
|
/**
|
|
2358
|
-
*
|
|
2359
|
-
* and the values are the corresponding file paths.
|
|
2454
|
+
* Represents the result of a TypeScript compilation emit operation.
|
|
2360
2455
|
*
|
|
2361
|
-
*
|
|
2362
|
-
*
|
|
2456
|
+
* @property outputFile - The emitted output file information,
|
|
2457
|
+
* or undefined if no file was emitted. Contains details such as file name, content,
|
|
2458
|
+
* and any related metadata.
|
|
2363
2459
|
*
|
|
2364
|
-
* @
|
|
2365
|
-
*
|
|
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.
|
|
2366
2463
|
*
|
|
2367
|
-
* @
|
|
2368
|
-
*
|
|
2369
|
-
*
|
|
2370
|
-
*
|
|
2371
|
-
* console.log(result);
|
|
2372
|
-
* // Output: {
|
|
2373
|
-
* // 'src/index': 'src/index.ts',
|
|
2374
|
-
* // 'src/utils': 'src/utils.ts'
|
|
2375
|
-
* // }
|
|
2376
|
-
* ```
|
|
2464
|
+
* @remarks
|
|
2465
|
+
* This interface is used to represent the result of TypeScript declaration emit operations.
|
|
2466
|
+
*
|
|
2467
|
+
* @since 1.5.9
|
|
2377
2468
|
*/
|
|
2378
|
-
|
|
2469
|
+
interface EmitOutputInterface {
|
|
2470
|
+
outputFile: OutputFile | undefined;
|
|
2471
|
+
emitSkipped: boolean;
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2379
2474
|
/**
|
|
2380
|
-
*
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
*
|
|
2384
|
-
* - An array of objects containing `in` and `out` properties, where `in` is the input file path and `out` is the output file path.
|
|
2385
|
-
* - A `Record<string, string>` where the keys represent input file paths and the values represent output file paths.
|
|
2386
|
-
*
|
|
2387
|
-
* Depending on the format, the function constructs an object with the output file paths as keys and the input file paths as values.
|
|
2388
|
-
* If the output path is not available, the filename (without extension) is used as the key.
|
|
2475
|
+
* Import will remove at compile time
|
|
2476
|
+
*/
|
|
2477
|
+
/**
|
|
2478
|
+
* A host object that provides formatting functionality for typescript diagnostic messages
|
|
2389
2479
|
*
|
|
2390
|
-
*
|
|
2480
|
+
* @remarks
|
|
2481
|
+
* This constant implements the FormatDiagnosticsHost interface from TypeScript,
|
|
2482
|
+
* providing methods needed for proper diagnostic message formatting.
|
|
2391
2483
|
*
|
|
2392
|
-
* @
|
|
2393
|
-
* an array of objects with `in` and `out` properties, or a `Record<string, string>`.
|
|
2484
|
+
* @default Uses TypeScript's system utilities for line breaks and directory information
|
|
2394
2485
|
*
|
|
2395
|
-
* @
|
|
2486
|
+
* @see FormatDiagnosticsHost - The TypeScript interface this implements
|
|
2396
2487
|
*
|
|
2397
|
-
* @
|
|
2488
|
+
* @since 1.5.9
|
|
2489
|
+
*/
|
|
2490
|
+
declare const formatHost: FormatDiagnosticsHost;
|
|
2491
|
+
/**
|
|
2492
|
+
* Header text included at the top of generated declaration bundle files
|
|
2398
2493
|
*
|
|
2399
|
-
* @
|
|
2400
|
-
*
|
|
2401
|
-
*
|
|
2402
|
-
*
|
|
2403
|
-
*
|
|
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.
|
|
2404
2499
|
*
|
|
2405
2500
|
* @example
|
|
2406
2501
|
* ```ts
|
|
2407
|
-
* const
|
|
2408
|
-
*
|
|
2502
|
+
* const bundledContent = `${HeaderDeclarationBundle}${actualContent}`;
|
|
2503
|
+
* writeFileSync('dist/index.d.ts', bundledContent);
|
|
2409
2504
|
* ```
|
|
2410
2505
|
*
|
|
2411
|
-
* @
|
|
2412
|
-
* ```ts
|
|
2413
|
-
* const entryPoints = extractEntryPoints({ index: 'src/index.ts', index2: 'dist/index2.js' });
|
|
2414
|
-
* console.log(entryPoints); // { index: 'src/index.ts', index2: 'dist/index2.js' }
|
|
2415
|
-
* ```
|
|
2506
|
+
* @since 1.5.9
|
|
2416
2507
|
*/
|
|
2417
|
-
|
|
2508
|
+
declare const HeaderDeclarationBundle = "\n/**\n * This file was automatically generated by xBuild.\n * DO NOT EDIT MANUALLY.\n */\n ";
|
|
2509
|
+
|
|
2418
2510
|
/**
|
|
2419
|
-
*
|
|
2420
|
-
* based on the format specified in the configuration.
|
|
2421
|
-
*
|
|
2422
|
-
* - If the format is `esm`, the `type` will be set to `"module"`.
|
|
2423
|
-
* - If the format is `cjs`, the `type` will be set to `"commonjs"`.
|
|
2424
|
-
*
|
|
2425
|
-
* The function will ensure that the specified output directory exists, and if it doesn't,
|
|
2426
|
-
* it will create the necessary directories before writing the `package.json` file.
|
|
2427
|
-
*
|
|
2428
|
-
* @param config - The build configuration object containing
|
|
2429
|
-
* esbuild-related settings, such as the format (`format`).
|
|
2430
|
-
*
|
|
2431
|
-
* - `config.esbuild.format`: The module format, either `'esm'` or `'cjs'`, that determines the `type` field.
|
|
2432
|
-
*
|
|
2433
|
-
* @throws Will throw an error if there is a problem creating the directory or writing the file.
|
|
2434
|
-
*
|
|
2435
|
-
* Example usage:
|
|
2436
|
-
*
|
|
2437
|
-
* ```ts
|
|
2438
|
-
* const config = {
|
|
2439
|
-
* esbuild: {
|
|
2440
|
-
* format: 'esm'
|
|
2441
|
-
* }
|
|
2442
|
-
* };
|
|
2443
|
-
* packageTypeComponent(config);
|
|
2444
|
-
* // This will create 'dist/package.json' with the content: {"type": "module"}
|
|
2445
|
-
* ```
|
|
2511
|
+
* Import will remove at compile time
|
|
2446
2512
|
*/
|
|
2447
|
-
export declare function packageTypeComponent(config: ConfigurationInterface): void;
|
|
2448
2513
|
/**
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2451
|
-
*
|
|
2452
|
-
* and lifecycle management of the build. It can operate in various modes, such as watching for file changes or running
|
|
2453
|
-
* in development mode. It also provides functionality for spawning development processes and processing entry points.
|
|
2514
|
+
* Service that implements TypeScript's language service host interfaces required for compiler operations.
|
|
2515
|
+
* This class provides the necessary methods for the TypeScript language service to interact with the
|
|
2516
|
+
* file system and manage compilation resources.
|
|
2454
2517
|
*
|
|
2455
2518
|
* @remarks
|
|
2456
|
-
*
|
|
2457
|
-
*
|
|
2458
|
-
* - The class supports various build modes, including watch mode and development mode, and handles different scenarios
|
|
2459
|
-
* based on the configuration.
|
|
2519
|
+
* This service implements the TypeScript LanguageServiceHost interface, which is required
|
|
2520
|
+
* for creating a TypeScript language service using ts.createLanguageService().
|
|
2460
2521
|
*
|
|
2461
|
-
* @
|
|
2462
|
-
* @
|
|
2522
|
+
* @see ts.LanguageServiceHost
|
|
2523
|
+
* @see ts.createLanguageService
|
|
2524
|
+
*
|
|
2525
|
+
* @since 1.5.9
|
|
2463
2526
|
*/
|
|
2464
|
-
|
|
2465
|
-
private
|
|
2527
|
+
declare class LanguageHostService {
|
|
2528
|
+
private readonly options;
|
|
2466
2529
|
/**
|
|
2467
|
-
*
|
|
2530
|
+
* Map to track file versions for detecting changes in source files.
|
|
2531
|
+
* Keys are absolute file paths and values are incrementing version numbers.
|
|
2532
|
+
*
|
|
2533
|
+
* @since 1.5.9
|
|
2468
2534
|
*/
|
|
2469
|
-
readonly
|
|
2535
|
+
private readonly fileVersions;
|
|
2470
2536
|
/**
|
|
2471
|
-
*
|
|
2472
|
-
* This property holds an array of `ChildProcessWithoutNullStreams` instances that represent Node.js processes spawned
|
|
2473
|
-
* for running development tasks. These processes are used to handle development builds or runtime tasks and are managed
|
|
2474
|
-
* by the `BuildService` class to ensure they are properly started and stopped.
|
|
2537
|
+
* Creates a new language host service with TypeScript compiler options.
|
|
2475
2538
|
*
|
|
2476
|
-
* @
|
|
2477
|
-
* - The array is populated when development processes are spawned, such as when specific development files are
|
|
2478
|
-
* processed or when running in development mode.
|
|
2479
|
-
* - The processes are terminated gracefully at the end of the build to avoid leaving orphaned processes running.
|
|
2480
|
-
* - It is important to manage these processes correctly to avoid resource leaks and ensure proper cleanup.
|
|
2539
|
+
* @param options - Compiler options to use for TypeScript operations
|
|
2481
2540
|
*
|
|
2482
|
-
* @
|
|
2541
|
+
* @since 1.5.9
|
|
2483
2542
|
*/
|
|
2484
|
-
|
|
2543
|
+
constructor(options: CompilerOptions);
|
|
2485
2544
|
/**
|
|
2486
|
-
*
|
|
2545
|
+
* Increments the version number of a file to indicate it has changed.
|
|
2546
|
+
* Used to signal to the language service that a file needs to be reprocessed.
|
|
2487
2547
|
*
|
|
2488
|
-
* @
|
|
2548
|
+
* @param touchFiles - Path to the file that has been modified
|
|
2549
|
+
*
|
|
2550
|
+
* @since 1.5.9
|
|
2489
2551
|
*/
|
|
2490
|
-
|
|
2552
|
+
touchFiles(touchFiles: string): void;
|
|
2491
2553
|
/**
|
|
2492
|
-
*
|
|
2554
|
+
* Checks if a file exists at the specified path.
|
|
2555
|
+
* Required by the LanguageServiceHost interface.
|
|
2493
2556
|
*
|
|
2494
|
-
* @
|
|
2495
|
-
*
|
|
2496
|
-
* - Keys represent the output filenames (with or without .d.ts extension)
|
|
2497
|
-
* - Values represent the source file paths to use as entry points
|
|
2557
|
+
* @param path - Path to check for file existence
|
|
2558
|
+
* @returns True if the file exists, false otherwise
|
|
2498
2559
|
*
|
|
2499
|
-
*
|
|
2500
|
-
*
|
|
2560
|
+
* @see ts.LanguageServiceHost.fileExists
|
|
2561
|
+
* @since 1.5.9
|
|
2562
|
+
*/
|
|
2563
|
+
fileExists(path: string): boolean;
|
|
2564
|
+
/**
|
|
2565
|
+
* Reads the content of a file at the specified path.
|
|
2566
|
+
* Required by the LanguageServiceHost interface.
|
|
2501
2567
|
*
|
|
2502
|
-
* @
|
|
2503
|
-
*
|
|
2504
|
-
*
|
|
2505
|
-
* {
|
|
2506
|
-
* 'index': 'src/index.ts',
|
|
2507
|
-
* 'components/button': 'src/components/button.ts'
|
|
2508
|
-
* }
|
|
2509
|
-
* ```
|
|
2568
|
+
* @param path - Path to the file to read
|
|
2569
|
+
* @param encoding - Optional encoding to use when reading the file
|
|
2570
|
+
* @returns The content of the file as a string, or undefined if the file cannot be read
|
|
2510
2571
|
*
|
|
2511
|
-
* @
|
|
2572
|
+
* @see ts.LanguageServiceHost.readFile
|
|
2512
2573
|
* @since 1.5.9
|
|
2513
2574
|
*/
|
|
2514
|
-
|
|
2575
|
+
readFile(path: string, encoding?: string): string | undefined;
|
|
2515
2576
|
/**
|
|
2516
|
-
*
|
|
2577
|
+
* Reads the contents of a directory with filtering options.
|
|
2578
|
+
* Required by the LanguageServiceHost interface.
|
|
2517
2579
|
*
|
|
2518
|
-
*
|
|
2519
|
-
*
|
|
2580
|
+
* @param path - Path to the directory to read
|
|
2581
|
+
* @param extensions - Optional array of file extensions to filter by
|
|
2582
|
+
* @param exclude - Optional array of glob patterns to exclude
|
|
2583
|
+
* @param include - Optional array of glob patterns to include
|
|
2584
|
+
* @param depth - Optional maximum depth to search
|
|
2585
|
+
* @returns Array of file paths found in the directory
|
|
2520
2586
|
*
|
|
2521
|
-
*
|
|
2522
|
-
* 1.
|
|
2523
|
-
|
|
2524
|
-
|
|
2587
|
+
* @see ts.LanguageServiceHost.readDirectory
|
|
2588
|
+
* @since 1.5.9
|
|
2589
|
+
*/
|
|
2590
|
+
readDirectory(path: string, extensions?: Array<string>, exclude?: Array<string>, include?: Array<string>, depth?: number): Array<string>;
|
|
2591
|
+
/**
|
|
2592
|
+
* Gets all subdirectories within a directory.
|
|
2593
|
+
* Required by the LanguageServiceHost interface.
|
|
2525
2594
|
*
|
|
2526
|
-
* @param
|
|
2595
|
+
* @param path - Path to the directory to search
|
|
2596
|
+
* @returns Array of directory paths found
|
|
2597
|
+
*
|
|
2598
|
+
* @see ts.LanguageServiceHost.getDirectories
|
|
2599
|
+
* @since 1.5.9
|
|
2527
2600
|
*/
|
|
2528
|
-
|
|
2601
|
+
getDirectories(path: string): Array<string>;
|
|
2529
2602
|
/**
|
|
2530
|
-
*
|
|
2531
|
-
* This method performs the build and handles any errors that occur during the execution.
|
|
2532
|
-
* If watching or development mode is enabled in the configuration, it starts watching for changes
|
|
2533
|
-
* to automatically rebuild as needed.
|
|
2534
|
-
* The method logs errors that are not related to TypeScript
|
|
2535
|
-
* compilation issues.
|
|
2603
|
+
* Checks if a directory exists at the specified path.
|
|
2536
2604
|
*
|
|
2537
|
-
* @
|
|
2538
|
-
*
|
|
2605
|
+
* @param path - Path to check for directory existence
|
|
2606
|
+
* @returns True if the directory exists, false otherwise
|
|
2539
2607
|
*
|
|
2540
|
-
* @
|
|
2541
|
-
|
|
2608
|
+
* @since 1.5.9
|
|
2609
|
+
*/
|
|
2610
|
+
directoryExists(path: string): boolean;
|
|
2611
|
+
/**
|
|
2612
|
+
* Gets the current working directory.
|
|
2613
|
+
* Required by the LanguageServiceHost interface.
|
|
2542
2614
|
*
|
|
2543
|
-
* @
|
|
2544
|
-
* ```ts
|
|
2545
|
-
* import { BuildService } from './build-service';
|
|
2615
|
+
* @returns The current working directory path
|
|
2546
2616
|
*
|
|
2547
|
-
*
|
|
2548
|
-
*
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
*
|
|
2553
|
-
*
|
|
2617
|
+
* @see ts.LanguageServiceHost.getCurrentDirectory
|
|
2618
|
+
* @since 1.5.9
|
|
2619
|
+
*/
|
|
2620
|
+
getCurrentDirectory(): string;
|
|
2621
|
+
/**
|
|
2622
|
+
* Gets all script file names tracked by this language host.
|
|
2623
|
+
* Required by the LanguageServiceHost interface to identify the set of source files.
|
|
2624
|
+
*
|
|
2625
|
+
* @returns Array of script file paths that should be included in the program
|
|
2626
|
+
*
|
|
2627
|
+
* @see ts.LanguageServiceHost.getScriptFileNames
|
|
2628
|
+
* @since 1.5.9
|
|
2629
|
+
*/
|
|
2630
|
+
getScriptFileNames(): Array<string>;
|
|
2631
|
+
/**
|
|
2632
|
+
* Gets the compiler options used by this language host.
|
|
2633
|
+
* Required by the LanguageServiceHost interface to configure the TypeScript compiler.
|
|
2634
|
+
*
|
|
2635
|
+
* @returns The compiler options for program creation
|
|
2636
|
+
*
|
|
2637
|
+
* @see ts.LanguageServiceHost.getCompilationSettings
|
|
2638
|
+
* @since 1.5.9
|
|
2639
|
+
*/
|
|
2640
|
+
getCompilationSettings(): CompilerOptions;
|
|
2641
|
+
/**
|
|
2642
|
+
* Gets the default library file name for TypeScript compilation.
|
|
2643
|
+
* Required by the LanguageServiceHost interface to include standard TypeScript definitions.
|
|
2644
|
+
*
|
|
2645
|
+
* @param options - Compiler options to use for determining the default library
|
|
2646
|
+
* @returns Path to the default library file
|
|
2647
|
+
*
|
|
2648
|
+
* @see ts.LanguageServiceHost.getDefaultLibFileName
|
|
2649
|
+
* @since 1.5.9
|
|
2650
|
+
*/
|
|
2651
|
+
getDefaultLibFileName(options: CompilerOptions): string;
|
|
2652
|
+
/**
|
|
2653
|
+
* Gets the current version of a script file.
|
|
2654
|
+
* Required by the LanguageServiceHost interface to determine if a file has changed.
|
|
2655
|
+
*
|
|
2656
|
+
* @param fileName - Path to the script file
|
|
2657
|
+
* @returns The version of the file as a string
|
|
2658
|
+
*
|
|
2659
|
+
* @see ts.LanguageServiceHost.getScriptVersion
|
|
2660
|
+
* @since 1.5.9
|
|
2661
|
+
*/
|
|
2662
|
+
getScriptVersion(fileName: string): string;
|
|
2663
|
+
/**
|
|
2664
|
+
* Gets a script snapshot for a file which represents its content.
|
|
2665
|
+
* Required by the LanguageServiceHost interface to provide file content to the language service.
|
|
2666
|
+
*
|
|
2667
|
+
* @param fileName - Path to the script file
|
|
2668
|
+
* @returns A script snapshot object or undefined if the file doesn't exist or can't be read
|
|
2669
|
+
*
|
|
2670
|
+
* @see ts.LanguageServiceHost.getScriptSnapshot
|
|
2671
|
+
* @see ts.IScriptSnapshot
|
|
2672
|
+
* @since 1.5.9
|
|
2673
|
+
*/
|
|
2674
|
+
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined;
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
/**
|
|
2678
|
+
* Import will remove at compile time
|
|
2679
|
+
*/
|
|
2680
|
+
/**
|
|
2681
|
+
* Service responsible for bundling TypeScript declaration files by collecting
|
|
2682
|
+
* all exports from entry points and generating a single declaration bundle
|
|
2683
|
+
*
|
|
2684
|
+
* @throws Error - If the language service program is not available
|
|
2685
|
+
* @throws Error - If a source file cannot be found
|
|
2686
|
+
*
|
|
2687
|
+
* @remarks
|
|
2688
|
+
* This service handles the process of bundling TypeScript declaration files (.d.ts)
|
|
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.
|
|
2693
|
+
*
|
|
2694
|
+
* The service maintains a cache of processed files to improve performance
|
|
2695
|
+
* when processing multiple entry points or when called multiple times.
|
|
2696
|
+
*
|
|
2697
|
+
* @example
|
|
2698
|
+
* ```ts
|
|
2699
|
+
* const bundler = new DeclarationBundlerService(config, languageService);
|
|
2700
|
+
* const bundledDeclarations = bundler.emitBundledDeclarations(['src/index.ts']);
|
|
2701
|
+
* writeFileSync('dist/index.d.ts', bundledDeclarations[0]);
|
|
2702
|
+
* ```
|
|
2703
|
+
*
|
|
2704
|
+
* @see ts.LanguageService
|
|
2705
|
+
* @see ts.ParsedCommandLine
|
|
2706
|
+
*
|
|
2707
|
+
* @since 1.5.9
|
|
2708
|
+
*/
|
|
2709
|
+
declare class DeclarationBundlerService {
|
|
2710
|
+
private readonly config;
|
|
2711
|
+
private readonly languageService;
|
|
2712
|
+
/**
|
|
2713
|
+
* Cache of processed declaration files to avoid redundant processing
|
|
2714
|
+
*
|
|
2715
|
+
* @since 1.5.9
|
|
2716
|
+
*/
|
|
2717
|
+
private readonly processedFiles;
|
|
2718
|
+
/**
|
|
2719
|
+
* Creates a new DeclarationBundlerService instance
|
|
2720
|
+
*
|
|
2721
|
+
* @param config - TypeScript configuration with compiler options
|
|
2722
|
+
* @param languageService - TypeScript language service for compilation
|
|
2723
|
+
*
|
|
2724
|
+
* @since 1.5.9
|
|
2725
|
+
*/
|
|
2726
|
+
constructor(config: ParsedCommandLine, languageService: LanguageService);
|
|
2727
|
+
/**
|
|
2728
|
+
* Generates bundled declaration files for the provided entry points
|
|
2729
|
+
*
|
|
2730
|
+
* @param entryPoints - Array of file paths to use as entry points
|
|
2731
|
+
* @returns Array of bundled declaration content strings
|
|
2732
|
+
*
|
|
2733
|
+
* @remarks
|
|
2734
|
+
* This method clears any existing cache and processes each entry point
|
|
2735
|
+
* to generate bundled declarations. Entry points should be absolute paths
|
|
2736
|
+
* to TypeScript source files.
|
|
2554
2737
|
*
|
|
2555
|
-
*
|
|
2556
|
-
* completion and logs any encountered errors, allowing the user to understand the outcome of the build.
|
|
2738
|
+
* @since 1.5.9
|
|
2557
2739
|
*/
|
|
2558
|
-
|
|
2740
|
+
emitBundledDeclarations(entryPoints: Array<string>): Array<string>;
|
|
2559
2741
|
/**
|
|
2560
|
-
*
|
|
2561
|
-
* This method temporarily disables development and watch mode, initiates the build process, and spawns development processes
|
|
2562
|
-
* for the specified entry points. If any errors occur during the build, they are handled appropriately.
|
|
2563
|
-
*
|
|
2564
|
-
* @param entryPoints - An array of entry point file names for which the development processes will be spawned.
|
|
2565
|
-
* These entry points are matched against the build output files.
|
|
2742
|
+
* Generates a bundled declaration for a single entry point
|
|
2566
2743
|
*
|
|
2567
|
-
* @
|
|
2744
|
+
* @param entryPath - Path to the entry point file
|
|
2745
|
+
* @returns Bundled declaration content or undefined if generation fails
|
|
2568
2746
|
*
|
|
2569
|
-
* @throws
|
|
2747
|
+
* @throws EntryPointError - When the specified entry point file cannot be found
|
|
2748
|
+
* @throws CompilationError - When the TypeScript program cannot be accessed
|
|
2570
2749
|
*
|
|
2571
2750
|
* @remarks
|
|
2572
|
-
*
|
|
2573
|
-
*
|
|
2574
|
-
*
|
|
2575
|
-
* - If any errors occur during the build, they are caught and passed to the `handleErrors` method.
|
|
2576
|
-
*
|
|
2577
|
-
* @example
|
|
2578
|
-
* ```ts
|
|
2579
|
-
* const entryPoints = ['index', 'main'];
|
|
2580
|
-
* await this.runDebug(entryPoints);
|
|
2581
|
-
* ```
|
|
2751
|
+
* This method processes a single entry point to generate a bundled declaration file.
|
|
2752
|
+
* It collects all necessary files and exported symbols, processes them, and
|
|
2753
|
+
* combines them into a single declaration output.
|
|
2582
2754
|
*
|
|
2583
|
-
*
|
|
2755
|
+
* The method requires that the entry point file exists and is included in the
|
|
2756
|
+
* TypeScript project configuration.
|
|
2584
2757
|
*
|
|
2585
|
-
* @
|
|
2758
|
+
* @since 1.5.9
|
|
2586
2759
|
*/
|
|
2587
|
-
|
|
2760
|
+
private generateBundledDeclaration;
|
|
2588
2761
|
/**
|
|
2589
|
-
*
|
|
2590
|
-
* This method starts the development server using the `ServerProvider`, builds the project using esbuild,
|
|
2591
|
-
* and watches for file changes to automatically rebuild as needed. It initializes the server and invokes
|
|
2592
|
-
* the build process, enabling continuous development mode.
|
|
2593
|
-
*
|
|
2594
|
-
* @returns A promise that resolves when the server is started and the build process is complete.
|
|
2762
|
+
* Resolves a module name to its file path
|
|
2595
2763
|
*
|
|
2596
|
-
* @
|
|
2597
|
-
*
|
|
2764
|
+
* @param moduleName - The module name to resolve
|
|
2765
|
+
* @param containingFile - The file containing the import
|
|
2766
|
+
* @param program - The TypeScript program
|
|
2598
2767
|
*
|
|
2599
|
-
* @
|
|
2600
|
-
* ```ts
|
|
2601
|
-
* const buildService = new BuildService(config);
|
|
2602
|
-
* buildService.serve().then(() => {
|
|
2603
|
-
* console.log('Server is running and watching for changes.');
|
|
2604
|
-
* }).catch((error) => {
|
|
2605
|
-
* console.error('Failed to start the server:', error);
|
|
2606
|
-
* });
|
|
2607
|
-
* ```
|
|
2768
|
+
* @returns The resolved file path or undefined if resolution fails
|
|
2608
2769
|
*
|
|
2609
|
-
*
|
|
2610
|
-
* the build or server startup, it is handled and logged.
|
|
2770
|
+
* @since 1.5.9
|
|
2611
2771
|
*/
|
|
2612
|
-
|
|
2772
|
+
private resolveModule;
|
|
2613
2773
|
/**
|
|
2614
|
-
*
|
|
2615
|
-
* This method ensures that any errors thrown during the execution of the callback
|
|
2616
|
-
* are properly handled and logged. If the error appears to be an `esbuild`-related
|
|
2617
|
-
* `OnEndResult` error with an array of errors, it avoids redundant logging.
|
|
2618
|
-
* Otherwise, it wraps the error in a `VMRuntimeError` and logs the stack trace.
|
|
2619
|
-
*
|
|
2620
|
-
* @template T - The return type of the callback function, allowing flexibility
|
|
2621
|
-
* in the expected result type. Defaults to `BuildResult`.
|
|
2622
|
-
*
|
|
2623
|
-
* @param callback - A function that returns a `Promise<T>`, which is executed asynchronously.
|
|
2624
|
-
* The callback is wrapped in error handling logic to catch and process any exceptions.
|
|
2774
|
+
* Recursively collects all files by following imports and exports
|
|
2625
2775
|
*
|
|
2626
|
-
* @
|
|
2627
|
-
*
|
|
2776
|
+
* @param sourceFile - The source file to process
|
|
2777
|
+
* @param program - The TypeScript program
|
|
2778
|
+
* @param collectedFiles - Set of collected file paths
|
|
2628
2779
|
*
|
|
2629
|
-
* @
|
|
2630
|
-
*
|
|
2780
|
+
* @remarks
|
|
2781
|
+
* This method traverses the dependency graph starting from the provided source file
|
|
2782
|
+
* and collects all files that contribute to the final bundle, excluding node_modules.
|
|
2631
2783
|
*
|
|
2632
|
-
* @
|
|
2633
|
-
* ```ts
|
|
2634
|
-
* await execute(async () => {
|
|
2635
|
-
* // Perform some asynchronous operation here
|
|
2636
|
-
* return someResult;
|
|
2637
|
-
* });
|
|
2638
|
-
* ```
|
|
2639
|
-
*/
|
|
2640
|
-
private execute;
|
|
2641
|
-
/**
|
|
2642
|
-
* Configures the development mode by ensuring that `config.dev` is set properly.
|
|
2784
|
+
* @since 1.5.9
|
|
2643
2785
|
*/
|
|
2644
|
-
private
|
|
2786
|
+
private collectFilesRecursive;
|
|
2645
2787
|
/**
|
|
2646
|
-
*
|
|
2788
|
+
* Recursively collects exports from a module symbol
|
|
2789
|
+
*
|
|
2790
|
+
* @param symbol - The module symbol to process
|
|
2791
|
+
* @param checker - The TypeScript type checker
|
|
2792
|
+
* @param collectedSymbols - Set of collected symbol names
|
|
2793
|
+
*
|
|
2794
|
+
* @remarks
|
|
2795
|
+
* This method collects all exported symbols from a module, including
|
|
2796
|
+
* nested module exports for namespace declarations.
|
|
2797
|
+
*
|
|
2798
|
+
* @since 1.5.9
|
|
2647
2799
|
*/
|
|
2648
|
-
private
|
|
2800
|
+
private collectExportsRecursive;
|
|
2649
2801
|
/**
|
|
2650
|
-
*
|
|
2802
|
+
* Processes all collected files and extracts their declarations
|
|
2651
2803
|
*
|
|
2652
|
-
* @param
|
|
2653
|
-
* @param
|
|
2804
|
+
* @param collectedFiles - Set of file paths to process
|
|
2805
|
+
* @param collectedSymbols - Set of exported symbol names
|
|
2806
|
+
* @returns Object containing bundled content and external imports
|
|
2807
|
+
*
|
|
2808
|
+
* @since 1.5.9
|
|
2654
2809
|
*/
|
|
2655
|
-
private
|
|
2810
|
+
private processDeclaredFiles;
|
|
2656
2811
|
/**
|
|
2657
|
-
*
|
|
2658
|
-
* This method processes the `paths` property from the TypeScript provider's options,
|
|
2659
|
-
* which is expected to be an object where each key represents a path alias pattern,
|
|
2660
|
-
* and the corresponding value is an array of paths. The method removes any wildcard
|
|
2661
|
-
* characters (`*`) from both the keys and the first values of the arrays. It also
|
|
2662
|
-
* resolves the paths relative to the specified `rootDir`, returning a simplified
|
|
2663
|
-
* object that maps the cleaned keys to their respective paths.
|
|
2664
|
-
*
|
|
2665
|
-
* The resolved paths will be formatted to use a relative path notation.
|
|
2812
|
+
* Collects all exported symbols from a source file
|
|
2666
2813
|
*
|
|
2667
|
-
*
|
|
2668
|
-
*
|
|
2669
|
-
*
|
|
2670
|
-
* {
|
|
2671
|
-
* '@core/*': ['src/core/*'],
|
|
2672
|
-
* '@utils/*': ['src/utils/*']
|
|
2673
|
-
* }
|
|
2674
|
-
* ```
|
|
2675
|
-
* And assuming `rootDir` is set to the base directory of your project, the method
|
|
2676
|
-
* will return:
|
|
2677
|
-
* ```ts
|
|
2678
|
-
* {
|
|
2679
|
-
* '@core/': './core/',
|
|
2680
|
-
* '@utils/': './utils/'
|
|
2681
|
-
* }
|
|
2682
|
-
* ```
|
|
2814
|
+
* @param sourceFile - The source file to process
|
|
2815
|
+
* @param checker - The TypeScript type checker
|
|
2816
|
+
* @param collectedSymbols - Set to store collected symbol names
|
|
2683
2817
|
*
|
|
2684
|
-
* @
|
|
2685
|
-
* @returns An object mapping cleaned path aliases to their respective resolved paths.
|
|
2818
|
+
* @since 1.5.9
|
|
2686
2819
|
*/
|
|
2687
|
-
private
|
|
2820
|
+
private collectExportsFromSourceFile;
|
|
2688
2821
|
/**
|
|
2689
|
-
*
|
|
2690
|
-
* This method processes and logs errors that occur during the esbuild process. It specifically filters out
|
|
2691
|
-
* errors related to TypeScript (`TypesError`) to prevent them from being logged, while logging all other errors
|
|
2692
|
-
* to the console. The error object is assumed to contain a list of messages, each with detailed information.
|
|
2693
|
-
*
|
|
2694
|
-
* @param esbuildError - The error object returned by esbuild, which is expected to contain an array of
|
|
2695
|
-
* error messages.
|
|
2822
|
+
* Processes a declaration file to extract its content
|
|
2696
2823
|
*
|
|
2697
|
-
* @
|
|
2824
|
+
* @param fileName - Path to the declaration file
|
|
2825
|
+
* @param collectedSymbols - Set of exported symbol names
|
|
2826
|
+
* @param externalImports - Set to store external import statements
|
|
2827
|
+
* @returns Processed declaration content or undefined if processing fails
|
|
2698
2828
|
*
|
|
2699
2829
|
* @remarks
|
|
2700
|
-
*
|
|
2701
|
-
*
|
|
2702
|
-
*
|
|
2703
|
-
* @example
|
|
2704
|
-
* ```ts
|
|
2705
|
-
* try {
|
|
2706
|
-
* await buildService.run();
|
|
2707
|
-
* } catch (esbuildError) {
|
|
2708
|
-
* buildService.handleErrors(esbuildError);
|
|
2709
|
-
* }
|
|
2710
|
-
* ```
|
|
2830
|
+
* This method processes a single declaration file, filtering its content
|
|
2831
|
+
* to include only relevant declarations and collecting external imports.
|
|
2832
|
+
* It uses a cache to avoid reprocessing the same file multiple times.
|
|
2711
2833
|
*
|
|
2712
|
-
*
|
|
2713
|
-
* process and log the errors.
|
|
2834
|
+
* @since 1.5.9
|
|
2714
2835
|
*/
|
|
2715
|
-
private
|
|
2836
|
+
private processDeclarationFile;
|
|
2716
2837
|
/**
|
|
2717
|
-
*
|
|
2718
|
-
* This method will update the `esbuild` object by adding or modifying the `banner` or `footer`
|
|
2719
|
-
* property based on the provided configuration.
|
|
2720
|
-
* The function handles both static values
|
|
2721
|
-
* and functions within the configuration.
|
|
2722
|
-
*
|
|
2723
|
-
* @param esbuild - The `esbuild` configuration object where the `banner` or `footer`
|
|
2724
|
-
* should be injected or updated.
|
|
2725
|
-
* @param object - The configuration object that contains the properties to inject.
|
|
2726
|
-
* The properties can either be static values or functions.
|
|
2727
|
-
* @param name - A string that determines whether the method modifies the `banner` or `footer`
|
|
2728
|
-
* property of the `esbuild` object.
|
|
2838
|
+
* Checks if a line is an import or export statement with a from clause
|
|
2729
2839
|
*
|
|
2730
|
-
* @
|
|
2731
|
-
*
|
|
2840
|
+
* @param line - The line to check
|
|
2841
|
+
* @returns True if the line is an import or export with from clause
|
|
2732
2842
|
*
|
|
2733
|
-
* @
|
|
2734
|
-
* No action will be taken if the specific `name` property (either
|
|
2735
|
-
* 'banner' or 'footer') does not exist in the `esbuild` object.
|
|
2843
|
+
* @since 1.5.9
|
|
2736
2844
|
*/
|
|
2737
|
-
private
|
|
2845
|
+
private isImportOrExportWithFrom;
|
|
2738
2846
|
/**
|
|
2739
|
-
*
|
|
2740
|
-
* Depending on the configuration, this method either uses esbuild's `context` for watching or `build` for a one-time build.
|
|
2847
|
+
* Extracts the module path from an import or export statement
|
|
2741
2848
|
*
|
|
2742
|
-
* @
|
|
2849
|
+
* @param line - The import or export statement
|
|
2850
|
+
* @returns The extracted module path or undefined if not found
|
|
2743
2851
|
*
|
|
2744
|
-
* @
|
|
2852
|
+
* @since 1.5.9
|
|
2745
2853
|
*/
|
|
2746
|
-
private
|
|
2854
|
+
private extractModulePath;
|
|
2747
2855
|
/**
|
|
2748
|
-
*
|
|
2749
|
-
* This method spawns development processes for each file in the metafile that matches any of the specified entry points.
|
|
2750
|
-
* It enables features like source maps and optional debugging mode for each spawned process.
|
|
2751
|
-
*
|
|
2752
|
-
* @param meta - The metafile containing information about build outputs.
|
|
2753
|
-
* This typically includes a mapping of output files and their dependencies.
|
|
2754
|
-
* @param entryPoint - An array of entry point file names to match against the metafile outputs.
|
|
2755
|
-
* Only files that match these entry points will have development processes spawned.
|
|
2756
|
-
* @param debug - A boolean flag to enable debugging mode for spawned processes.
|
|
2757
|
-
* If `true`, the processes will start in debug mode with the `--inspect-brk` option. Defaults to `false`.
|
|
2856
|
+
* Determines if a module is external (from node_modules)
|
|
2758
2857
|
*
|
|
2759
|
-
* @
|
|
2858
|
+
* @param modulePath - The module path to check
|
|
2859
|
+
* @param fileName - The file containing the import
|
|
2860
|
+
* @returns True if the module is external
|
|
2760
2861
|
*
|
|
2761
2862
|
* @remarks
|
|
2762
|
-
*
|
|
2763
|
-
*
|
|
2764
|
-
* - The `activePossess` array tracks all spawned processes, allowing further management (e.g., termination).
|
|
2765
|
-
*
|
|
2766
|
-
* @example
|
|
2767
|
-
* ```ts
|
|
2768
|
-
* const meta = {
|
|
2769
|
-
* outputs: {
|
|
2770
|
-
* 'dist/index.js': { \/* ... *\/ },
|
|
2771
|
-
* 'dist/index.js.map': { \/* ... *\/ }
|
|
2772
|
-
* }
|
|
2773
|
-
* };
|
|
2774
|
-
* const entryPoints = ['index'];
|
|
2775
|
-
*
|
|
2776
|
-
* this.spawnDev(meta, entryPoints, true); // Spawns processes in debug mode
|
|
2777
|
-
* ```
|
|
2863
|
+
* This method determines if a module is external by checking if it's a relative
|
|
2864
|
+
* or absolute path, and by resolving the module to see if it's in node_modules.
|
|
2778
2865
|
*
|
|
2779
|
-
* @
|
|
2866
|
+
* @since 1.5.9
|
|
2780
2867
|
*/
|
|
2781
|
-
private
|
|
2868
|
+
private isExternalModule;
|
|
2782
2869
|
/**
|
|
2783
|
-
*
|
|
2784
|
-
* This method performs initial setup for the build and ensures that any child processes are terminated properly.
|
|
2870
|
+
* Processes an export line, removing 'export' if needed
|
|
2785
2871
|
*
|
|
2786
|
-
* @
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
/**
|
|
2790
|
-
* Finalizes the build process and logs results.
|
|
2791
|
-
* This method handles the end of the build process, logs build results, and processes development files if applicable.
|
|
2872
|
+
* @param line - The export statement to process
|
|
2873
|
+
* @param collectedSymbols - Set of exported symbol names
|
|
2874
|
+
* @returns The processed line
|
|
2792
2875
|
*
|
|
2793
|
-
* @
|
|
2876
|
+
* @remarks
|
|
2877
|
+
* This method processes an export declaration line, removing the 'export'
|
|
2878
|
+
* keyword if the symbol is not in the collected exports.
|
|
2879
|
+
*
|
|
2880
|
+
* @since 1.5.9
|
|
2794
2881
|
*/
|
|
2795
|
-
private
|
|
2882
|
+
private processExportLine;
|
|
2796
2883
|
/**
|
|
2797
|
-
*
|
|
2798
|
-
* This method analyzes the project's dependencies and adjusts entry points configuration as needed.
|
|
2884
|
+
* Creates the final bundled declaration content
|
|
2799
2885
|
*
|
|
2800
|
-
* @
|
|
2886
|
+
* @param externalImports - Set of external import statements
|
|
2887
|
+
* @param bundledContent - Array of processed declaration content
|
|
2888
|
+
* @returns The final bundled declaration content
|
|
2889
|
+
*
|
|
2890
|
+
* @since 1.5.9
|
|
2801
2891
|
*/
|
|
2802
|
-
private
|
|
2892
|
+
private createFinalBundleContent;
|
|
2803
2893
|
}
|
|
2894
|
+
|
|
2804
2895
|
/**
|
|
2805
|
-
*
|
|
2896
|
+
* Imports
|
|
2897
|
+
*/
|
|
2898
|
+
/**
|
|
2899
|
+
* Resolves path aliases in the provided content based on the specified paths and root directory.
|
|
2806
2900
|
*
|
|
2807
|
-
*
|
|
2808
|
-
*
|
|
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.
|
|
2809
2905
|
*
|
|
2810
|
-
*
|
|
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
|
+
* ```
|
|
2811
2922
|
*
|
|
2812
|
-
* @
|
|
2813
|
-
* The
|
|
2814
|
-
*
|
|
2815
|
-
*
|
|
2816
|
-
*
|
|
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.
|
|
2817
2937
|
*
|
|
2818
|
-
*
|
|
2819
|
-
*
|
|
2820
|
-
* breaking execution on interrupt signals (e.g., Ctrl+C) with the `breakOnSigint` option.
|
|
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`.
|
|
2821
2940
|
*
|
|
2822
|
-
* @
|
|
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.
|
|
2823
2943
|
*
|
|
2824
2944
|
* @example
|
|
2825
2945
|
* ```ts
|
|
2826
|
-
* const
|
|
2827
|
-
*
|
|
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
|
+
* // }
|
|
2828
2953
|
* ```
|
|
2954
|
+
*/
|
|
2955
|
+
declare function mapFilePathsToNames(filePaths: Array<string>): Record<string, string>;
|
|
2956
|
+
/**
|
|
2957
|
+
* Extracts and returns an object mapping output file paths to input file paths from the provided `EntryPointsType` object.
|
|
2829
2958
|
*
|
|
2830
|
-
*
|
|
2831
|
-
*
|
|
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.
|
|
2832
2963
|
*
|
|
2833
|
-
*
|
|
2834
|
-
*
|
|
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.
|
|
2968
|
+
*
|
|
2969
|
+
* @param entryPoints - The entry points to extract from, which can be in different formats: an array of strings,
|
|
2970
|
+
* an array of objects with `in` and `out` properties, or a `Record<string, string>`.
|
|
2971
|
+
*
|
|
2972
|
+
* @returns An object mapping output file paths to input file paths, or filename (without extension) to file path.
|
|
2973
|
+
*
|
|
2974
|
+
* @throws Will throw an `Error` if the entry points format is unsupported.
|
|
2975
|
+
*
|
|
2976
|
+
* @example
|
|
2977
|
+
* ```ts
|
|
2978
|
+
* const entryPoints = extractEntryPoints(['src/index.ts', 'src/utils.ts']);
|
|
2979
|
+
* console.log(entryPoints); // { 'index': 'src/index.ts', 'utils': 'src/utils.ts' }
|
|
2980
|
+
* ```
|
|
2981
|
+
*
|
|
2982
|
+
* @example
|
|
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
|
+
* ```
|
|
2987
|
+
*
|
|
2988
|
+
* @example
|
|
2989
|
+
* ```ts
|
|
2990
|
+
* const entryPoints = extractEntryPoints({ index: 'src/index.ts', index2: 'dist/index2.js' });
|
|
2991
|
+
* console.log(entryPoints); // { index: 'src/index.ts', index2: 'dist/index2.js' }
|
|
2992
|
+
* ```
|
|
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
|
+
*
|
|
3003
|
+
* - If the format is `esm`, the `type` will be set to `"module"`.
|
|
3004
|
+
* - If the format is `cjs`, the `type` will be set to `"commonjs"`.
|
|
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:
|
|
3017
|
+
*
|
|
3018
|
+
* ```ts
|
|
3019
|
+
* const config = {
|
|
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
|
|
2835
3032
|
*/
|
|
2836
|
-
export declare function sandboxExecute(code: string, sandbox?: Context): unknown;
|
|
2837
3033
|
/**
|
|
2838
3034
|
* Parses a configuration file and returns a wrapped `ConfigurationInterface` object.
|
|
2839
3035
|
*
|
|
@@ -2850,30 +3046,54 @@ export declare function sandboxExecute(code: string, sandbox?: Context): unknown
|
|
|
2850
3046
|
*
|
|
2851
3047
|
* @throws Will throw an error if the transpilation or execution of the configuration file fails.
|
|
2852
3048
|
* The thrown error will have sourcemap information attached if available.
|
|
2853
|
-
|
|
2854
3049
|
* @example
|
|
2855
3050
|
* ```ts
|
|
2856
3051
|
* const config = await parseConfigurationFile('./config.jet.ts');
|
|
2857
3052
|
* console.log(config);
|
|
2858
3053
|
* ```
|
|
2859
3054
|
*/
|
|
2860
|
-
|
|
3055
|
+
declare function parseConfigurationFile(file: string): Promise<ConfigurationInterface>;
|
|
3056
|
+
|
|
3057
|
+
/**
|
|
3058
|
+
* Import will remove at compile time
|
|
3059
|
+
*/
|
|
2861
3060
|
/**
|
|
2862
|
-
*
|
|
3061
|
+
* Executes JavaScript code within a sandboxed environment using Node.js's `vm` module.
|
|
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.
|
|
2863
3079
|
*
|
|
2864
3080
|
* @example
|
|
2865
3081
|
* ```ts
|
|
2866
|
-
*
|
|
2867
|
-
*
|
|
2868
|
-
* console.log(defaultConfiguration);
|
|
3082
|
+
* const result = sandboxExecute('return 2 + 2;', { myGlobal: 10 });
|
|
3083
|
+
* console.log(result); // Output: 4
|
|
2869
3084
|
* ```
|
|
2870
3085
|
*
|
|
2871
|
-
* In this example, the `
|
|
3086
|
+
* In this example, the `sandboxExecute` function runs a simple JavaScript expression and returns
|
|
3087
|
+
* the result. The `sandbox` parameter is provided with an empty object in this case.
|
|
2872
3088
|
*
|
|
2873
3089
|
* @public
|
|
2874
|
-
* @category
|
|
3090
|
+
* @category Services
|
|
3091
|
+
*/
|
|
3092
|
+
declare function sandboxExecute(code: string, sandbox?: Context): unknown;
|
|
3093
|
+
|
|
3094
|
+
/**
|
|
3095
|
+
* Import will remove at compile time
|
|
2875
3096
|
*/
|
|
2876
|
-
export declare const defaultConfiguration: ConfigurationInterface;
|
|
2877
3097
|
/**
|
|
2878
3098
|
* Merges user configurations with CLI configurations and default settings
|
|
2879
3099
|
* to produce a final configuration object for the build process.
|
|
@@ -2904,7 +3124,7 @@ export declare const defaultConfiguration: ConfigurationInterface;
|
|
|
2904
3124
|
* console.log('Merged Configuration:', finalConfigs);
|
|
2905
3125
|
* ```
|
|
2906
3126
|
*/
|
|
2907
|
-
|
|
3127
|
+
declare function configuration(userConfig: Array<PartialDeepConfigurationsType> | PartialDeepConfigurationsType, cliConfig?: PartialDeepConfigurationsType): Promise<Array<ConfigurationInterface>>;
|
|
2908
3128
|
/**
|
|
2909
3129
|
* Merges CLI arguments with a configuration file to produce a final configuration object.
|
|
2910
3130
|
* This function reads the specified configuration file and merges its contents with
|
|
@@ -2932,55 +3152,24 @@ export declare function configuration(userConfig: Array<PartialDeepConfiguration
|
|
|
2932
3152
|
* });
|
|
2933
3153
|
* ```
|
|
2934
3154
|
*/
|
|
2935
|
-
|
|
3155
|
+
declare function cliConfiguration(configFile: string, cli: Argv<ArgvInterface>): Promise<Array<ConfigurationInterface>>;
|
|
3156
|
+
|
|
2936
3157
|
/**
|
|
2937
|
-
*
|
|
2938
|
-
*
|
|
2939
|
-
* This function parses the CLI arguments, configures the build settings, and executes
|
|
2940
|
-
* the appropriate build tasks, including type checking, serving, or running in debug mode.
|
|
2941
|
-
*
|
|
2942
|
-
* @param argv - An array of strings representing the CLI arguments.
|
|
2943
|
-
*
|
|
2944
|
-
* @returns A promise that resolves when all build tasks are completed.
|
|
2945
|
-
*
|
|
2946
|
-
* @example
|
|
2947
|
-
* ```ts
|
|
2948
|
-
* await buildWithArgv(process.argv);
|
|
2949
|
-
* ```
|
|
3158
|
+
* Import will remove at compile time
|
|
2950
3159
|
*/
|
|
2951
|
-
export declare function buildWithArgv(argv: Array<string>): Promise<void>;
|
|
2952
3160
|
/**
|
|
2953
|
-
*
|
|
2954
|
-
*
|
|
2955
|
-
* This function reads the configuration from the provided file path, processes it,
|
|
2956
|
-
* and initiates the build tasks.
|
|
2957
|
-
*
|
|
2958
|
-
* @param configFilePath - The path to the configuration file to be used for the build.
|
|
2959
|
-
*
|
|
2960
|
-
* @returns A promise that resolves to an array of `BuildResult` objects once all build tasks are completed.
|
|
2961
|
-
*
|
|
2962
|
-
* @throws Error Throws an error if the configuration file does not exist or is invalid.
|
|
3161
|
+
* The default configuration options for the build.
|
|
2963
3162
|
*
|
|
2964
3163
|
* @example
|
|
2965
3164
|
* ```ts
|
|
2966
|
-
*
|
|
2967
|
-
* console.log('Build results:', results);
|
|
2968
|
-
* ```
|
|
2969
|
-
*/
|
|
2970
|
-
export declare function buildWithConfigPath(configFilePath: string): Promise<BuildResult[]>;
|
|
2971
|
-
/**
|
|
2972
|
-
* Builds the project based on the provided configuration object.
|
|
2973
|
-
*
|
|
2974
|
-
* This function processes the given configuration and executes the build tasks accordingly.
|
|
3165
|
+
* import { defaultConfiguration } from '@configuration/default-configuration';
|
|
2975
3166
|
*
|
|
2976
|
-
*
|
|
3167
|
+
* console.log(defaultConfiguration);
|
|
3168
|
+
* ```
|
|
2977
3169
|
*
|
|
2978
|
-
*
|
|
3170
|
+
* In this example, the `defaultConfiguration` is imported and logged to the console to view the default settings.
|
|
2979
3171
|
*
|
|
2980
|
-
* @
|
|
2981
|
-
*
|
|
2982
|
-
* const results = await build({ entryPoints: ['./src/index.ts'] });
|
|
2983
|
-
* console.log('Build results:', results);
|
|
2984
|
-
* ```
|
|
3172
|
+
* @public
|
|
3173
|
+
* @category Configuration
|
|
2985
3174
|
*/
|
|
2986
|
-
|
|
3175
|
+
declare const defaultConfiguration: ConfigurationInterface;
|