@rzl-zone/build-tools 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/.references/index.d.cts +18 -0
- package/dist/.references/index.d.ts +18 -0
- package/dist/bundler/rolldown.cjs +32 -0
- package/dist/bundler/rolldown.cjs.map +1 -0
- package/dist/bundler/rolldown.d.cts +162 -0
- package/dist/bundler/rolldown.d.ts +162 -0
- package/dist/bundler/rolldown.js +25 -0
- package/dist/bundler/rolldown.js.map +1 -0
- package/dist/bundler/tsdown.cjs +132 -0
- package/dist/bundler/tsdown.cjs.map +1 -0
- package/dist/bundler/tsdown.d.cts +1165 -0
- package/dist/bundler/tsdown.d.ts +1165 -0
- package/dist/bundler/tsdown.js +124 -0
- package/dist/bundler/tsdown.js.map +1 -0
- package/dist/bundler/utils.cjs +24 -0
- package/dist/bundler/utils.cjs.map +1 -0
- package/dist/bundler/utils.d.cts +40 -0
- package/dist/bundler/utils.d.ts +40 -0
- package/dist/bundler/utils.js +21 -0
- package/dist/bundler/utils.js.map +1 -0
- package/dist/client-XhkdKJ4d.js +160 -0
- package/dist/client-XhkdKJ4d.js.map +1 -0
- package/dist/client-u8yLSxEI.cjs +221 -0
- package/dist/client-u8yLSxEI.cjs.map +1 -0
- package/dist/commander-kit/index.cjs +569 -0
- package/dist/commander-kit/index.cjs.map +1 -0
- package/dist/commander-kit/index.d.cts +1383 -0
- package/dist/commander-kit/index.d.ts +1383 -0
- package/dist/commander-kit/index.js +550 -0
- package/dist/commander-kit/index.js.map +1 -0
- package/dist/extra-CVuXMpEw.d.ts +994 -0
- package/dist/extra-CxDwtQEy.d.cts +994 -0
- package/dist/fast-globe-options-6r2aj6UC.d.ts +126 -0
- package/dist/fast-globe-options-BFt__e__.d.cts +126 -0
- package/dist/helper-BdjaR8Yv.js +215 -0
- package/dist/helper-BdjaR8Yv.js.map +1 -0
- package/dist/helper-DorgNsB9.cjs +377 -0
- package/dist/helper-DorgNsB9.cjs.map +1 -0
- package/dist/identity-BJ0QX7AJ.js +88 -0
- package/dist/identity-BJ0QX7AJ.js.map +1 -0
- package/dist/identity-CxR9DRMh.cjs +100 -0
- package/dist/identity-CxR9DRMh.cjs.map +1 -0
- package/dist/index-B-NeF7PU.d.cts +670 -0
- package/dist/index-CzxZta4Z.d.ts +356 -0
- package/dist/index-Idak1iwg.d.cts +356 -0
- package/dist/index-PXsb85LI.d.ts +670 -0
- package/dist/index.cjs +1689 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2193 -0
- package/dist/index.d.ts +2193 -0
- package/dist/index.js +1641 -0
- package/dist/index.js.map +1 -0
- package/dist/package-banner-6RzEf-mV.cjs +54 -0
- package/dist/package-banner-6RzEf-mV.cjs.map +1 -0
- package/dist/package-banner-BzheZbxy.js +41 -0
- package/dist/package-banner-BzheZbxy.js.map +1 -0
- package/dist/server-B2hBoGDR.cjs +181 -0
- package/dist/server-B2hBoGDR.cjs.map +1 -0
- package/dist/server-CWrDd29Y.js +142 -0
- package/dist/server-CWrDd29Y.js.map +1 -0
- package/dist/utils/client.cjs +23 -0
- package/dist/utils/client.d.cts +887 -0
- package/dist/utils/client.d.ts +887 -0
- package/dist/utils/client.js +12 -0
- package/dist/utils/server.cjs +17 -0
- package/dist/utils/server.d.cts +124 -0
- package/dist/utils/server.d.ts +124 -0
- package/dist/utils/server.js +12 -0
- package/package.json +151 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2193 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/build-tools
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `0.0.5`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky1998@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/build-tools`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { a as OmitStrict, c as PrettifyOptions, r as DefaultPrettifyOptions, s as Prettify } from "./extra-CxDwtQEy.cjs";
|
|
12
|
+
import { n as generatePackageBanner, r as PackageJson, t as GeneratePackageBannerOptions } from "./index-B-NeF7PU.cjs";
|
|
13
|
+
import { t as CommandIdentity } from "./index-Idak1iwg.cjs";
|
|
14
|
+
import { n as PatternOptions, t as PatternConfig } from "./fast-globe-options-BFt__e__.cjs";
|
|
15
|
+
import * as acorn from "acorn";
|
|
16
|
+
import { ChildProcess, SpawnOptions, StdioOptions } from "node:child_process";
|
|
17
|
+
|
|
18
|
+
/** ----------------------------------------------------------------
|
|
19
|
+
* * ***Flexible input type for value collections.***
|
|
20
|
+
* ----------------------------------------------------------------
|
|
21
|
+
*
|
|
22
|
+
* Represents a value that can be provided either as a single item
|
|
23
|
+
* or as a collection of items.
|
|
24
|
+
*
|
|
25
|
+
* This enables APIs to accept both singular and multiple values
|
|
26
|
+
* without requiring callers to normalize the input beforehand.
|
|
27
|
+
*
|
|
28
|
+
* ----------------------------------------------------------------
|
|
29
|
+
* Supported Forms
|
|
30
|
+
*
|
|
31
|
+
* - A single value (`T`)
|
|
32
|
+
* - An array of values (`T[]`)
|
|
33
|
+
* - A `Set` containing values (`Set<T>`)
|
|
34
|
+
*
|
|
35
|
+
* ----------------------------------------------------------------
|
|
36
|
+
* Type Behavior
|
|
37
|
+
*
|
|
38
|
+
* - Wrapped with `Exclude<..., never>` to prevent accidental
|
|
39
|
+
* `never` propagation in complex generic transformations.
|
|
40
|
+
*
|
|
41
|
+
* - Uses `Prettify` to normalize and simplify the resulting type
|
|
42
|
+
* for improved readability.
|
|
43
|
+
*
|
|
44
|
+
* ----------------------------------------------------------------
|
|
45
|
+
* @template T The base value type.
|
|
46
|
+
*
|
|
47
|
+
* @template Options
|
|
48
|
+
* Configuration options for the `Prettify` utility.
|
|
49
|
+
* Controls how the resulting type is normalized and displayed
|
|
50
|
+
* in editor tooltips.
|
|
51
|
+
*
|
|
52
|
+
* ----------------------------------------------------------------
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // default behavior
|
|
57
|
+
* const a: Collection<string> = "value";
|
|
58
|
+
* const b: Collection<string> = ["a", "b", "c"];
|
|
59
|
+
* const c: Collection<string> = new Set(["x", "y", "z"]);
|
|
60
|
+
*
|
|
61
|
+
* // with custom Prettify options
|
|
62
|
+
* type Custom = Collection<string, { skipPrettify: true }>;
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
type Collection<T, Options extends PrettifyOptions = DefaultPrettifyOptions> = Prettify<Exclude<T | Prettify<T, Options>[] | Set<Prettify<T, Options>>, never>, Options>;
|
|
66
|
+
/** ----------------------------------------------------------------
|
|
67
|
+
* * ***Flexible input type for string collections.***
|
|
68
|
+
* ----------------------------------------------------------------
|
|
69
|
+
*
|
|
70
|
+
* Convenience alias for `Collection<string>`.
|
|
71
|
+
*
|
|
72
|
+
* Useful for APIs that accept either a single string or multiple
|
|
73
|
+
* strings in array or `Set` form.
|
|
74
|
+
*
|
|
75
|
+
* ----------------------------------------------------------------
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const a: StringCollection = "value";
|
|
80
|
+
* const b: StringCollection = ["a", "b", "c"];
|
|
81
|
+
* const c: StringCollection = new Set(["x", "y", "z"]);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
type StringCollection = Collection<string>;
|
|
85
|
+
/** ----------------------------------------------------------------
|
|
86
|
+
* * ***Special Internal options props.***
|
|
87
|
+
* ----------------------------------------------------------------
|
|
88
|
+
*/
|
|
89
|
+
interface InternalOptions {}
|
|
90
|
+
/** ----------------------------------------------------------------
|
|
91
|
+
* * ***Supported log verbosity levels.***
|
|
92
|
+
* ----------------------------------------------------------------
|
|
93
|
+
*/
|
|
94
|
+
type LogLevel = "silent" | "error" | "info" | "debug";
|
|
95
|
+
/** ----------------------------------------------------------------
|
|
96
|
+
* * ***Common logging configuration options.***
|
|
97
|
+
* ----------------------------------------------------------------
|
|
98
|
+
*/
|
|
99
|
+
type LoggingOptions = {
|
|
100
|
+
/** ----------------------------------------------------------------
|
|
101
|
+
* * ***Logging verbosity level.***
|
|
102
|
+
* ----------------------------------------------------------------
|
|
103
|
+
*
|
|
104
|
+
* Controls how verbose the logger output should be.
|
|
105
|
+
*
|
|
106
|
+
* - **Supported values:**
|
|
107
|
+
* - `silent` ➔ no output.
|
|
108
|
+
* - `error` ➔ errors only.
|
|
109
|
+
* - `info` **(default)** ➔ standard informational logs (include `error`).
|
|
110
|
+
* - `debug` ➔ verbose / debug logs (include `error`).
|
|
111
|
+
*
|
|
112
|
+
* - **Notes:**
|
|
113
|
+
* - If an invalid value is provided, it will be **silently coerced**
|
|
114
|
+
* to the default log level.
|
|
115
|
+
*
|
|
116
|
+
* @default "info"
|
|
117
|
+
*/
|
|
118
|
+
logLevel?: LogLevel;
|
|
119
|
+
};
|
|
120
|
+
/** ----------------------------------------------------------------
|
|
121
|
+
* * ***Base configuration options.***
|
|
122
|
+
* ----------------------------------------------------------------
|
|
123
|
+
*
|
|
124
|
+
* Shared option structure used across internal utilities.
|
|
125
|
+
*
|
|
126
|
+
* This type composes several configuration layers commonly required
|
|
127
|
+
* by file-processing utilities:
|
|
128
|
+
*
|
|
129
|
+
* - ***Logging options*** from {@link LoggingOptions | `LoggingOptions`}.
|
|
130
|
+
* - ***Pattern matching configuration*** from {@link PatternConfig | `PatternConfig`}.
|
|
131
|
+
*
|
|
132
|
+
* ----------------------------------------------------------------
|
|
133
|
+
*
|
|
134
|
+
* @template FilesOnly
|
|
135
|
+
* When `true`, directory-related pattern options (`onlyFiles`,
|
|
136
|
+
* `onlyDirectories`) are removed from the public configuration.
|
|
137
|
+
*
|
|
138
|
+
* This is typically used by utilities that must operate strictly
|
|
139
|
+
* on files and should not allow directory matches.
|
|
140
|
+
*
|
|
141
|
+
* @template ForceUnique
|
|
142
|
+
* When `true`, the `unique` option from the underlying
|
|
143
|
+
* {@link PatternOptions | `PatternOptions`} is removed to enforce
|
|
144
|
+
* internally deduplicated glob results.
|
|
145
|
+
*
|
|
146
|
+
* ----------------------------------------------------------------
|
|
147
|
+
*
|
|
148
|
+
* These generics allow higher-level utilities to enforce
|
|
149
|
+
* stricter pattern resolution behavior while still exposing
|
|
150
|
+
* a flexible configuration surface to consumers.
|
|
151
|
+
*/
|
|
152
|
+
type BaseOptions<FilesOnly extends boolean = false, ForceUnique extends boolean = false> = Prettify<LoggingOptions & InternalOptions & PatternConfig<FilesOnly, ForceUnique>>;
|
|
153
|
+
/** ----------------------------------------------------------------
|
|
154
|
+
* * ***Default Pattern Policy for **clean build artifact** operations.***
|
|
155
|
+
* ----------------------------------------------------------------
|
|
156
|
+
*
|
|
157
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
158
|
+
* - {@link cleanJsBuildArtifacts | `clean-js-build-artifacts`}.
|
|
159
|
+
* - {@link cleanTypesBuildArtifacts | `clean-types-build-artifacts`}.
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
162
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
163
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
164
|
+
*/
|
|
165
|
+
declare const DEFAULT_CLEAN_PATTERN_POLICY: {
|
|
166
|
+
readonly filesOnly: true;
|
|
167
|
+
readonly forceUnique: true;
|
|
168
|
+
};
|
|
169
|
+
/** ----------------------------------------------------------------
|
|
170
|
+
* * ***Resolved Pattern Options for **clean build artifact** operations.***
|
|
171
|
+
* ----------------------------------------------------------------
|
|
172
|
+
*
|
|
173
|
+
* Pattern options used by:
|
|
174
|
+
* - {@link cleanJsBuildArtifacts | `clean-js-build-artifacts`}.
|
|
175
|
+
* - {@link cleanTypesBuildArtifacts | `clean-types-build-artifacts`}.
|
|
176
|
+
*/
|
|
177
|
+
declare const resolvedCleanPatternOption: PatternOptions<true, true>;
|
|
178
|
+
/** Type Options for {@link cleanJsBuildArtifacts | `clean-js-build-artifacts`} and {@link cleanTypesBuildArtifacts | `clean-types-build-artifacts`}. */
|
|
179
|
+
type CleanCoreOptions = Prettify<{
|
|
180
|
+
/** ----------------------------------------------------------------
|
|
181
|
+
* * ***Whether to remove `sourceMappingURL` comments.***
|
|
182
|
+
* ----------------------------------------------------------------
|
|
183
|
+
*
|
|
184
|
+
* @default false
|
|
185
|
+
*/
|
|
186
|
+
removeSourceMap?: boolean;
|
|
187
|
+
/** ----------------------------------------------------------------
|
|
188
|
+
* * ***Whether to remove `region` comments.***
|
|
189
|
+
* ----------------------------------------------------------------
|
|
190
|
+
*
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
193
|
+
removeRegion?: boolean;
|
|
194
|
+
/** ----------------------------------------------------------------
|
|
195
|
+
* * ***Whether to remove empty lines adjacent to removed comments.***
|
|
196
|
+
* ----------------------------------------------------------------
|
|
197
|
+
* Useful for keeping output files compact and visually clean.
|
|
198
|
+
*
|
|
199
|
+
* @default false
|
|
200
|
+
*/
|
|
201
|
+
removeAdjacentEmptyLines?: boolean;
|
|
202
|
+
} & BaseOptions<typeof DEFAULT_CLEAN_PATTERN_POLICY.filesOnly, typeof DEFAULT_CLEAN_PATTERN_POLICY.forceUnique>>;
|
|
203
|
+
/** Command identity associated with {@link cleanJsBuildArtifacts | **`clean-js-build-artifacts`**}. */
|
|
204
|
+
declare const commandCjbaIdentity: CommandIdentity;
|
|
205
|
+
/** ----------------------------------------------------------------
|
|
206
|
+
* * ***Configuration options for {@link cleanJsBuildArtifacts | `clean-js-build-artifacts`}.***
|
|
207
|
+
* ----------------------------------------------------------------
|
|
208
|
+
*/
|
|
209
|
+
type CleanJsArtifactsOptions = CleanCoreOptions;
|
|
210
|
+
/** ----------------------------------------------------------------
|
|
211
|
+
* * ***Removes build artifact comments from compiled JavaScript files.***
|
|
212
|
+
* ----------------------------------------------------------------
|
|
213
|
+
*
|
|
214
|
+
* This function scans files matching the provided glob pattern(s) and removes:
|
|
215
|
+
* - Source path comments.
|
|
216
|
+
* - Source region comments.
|
|
217
|
+
* - ESLint directive comments.
|
|
218
|
+
* - Optional source map references.
|
|
219
|
+
*
|
|
220
|
+
* It can also remove empty lines adjacent to those comments to keep
|
|
221
|
+
* output files tidy.
|
|
222
|
+
*
|
|
223
|
+
* @param {string | string[] | Set<string>} pattern - Glob pattern or list of patterns pointing to JS output files.
|
|
224
|
+
* @param {CleanJsArtifactsOptions} options - Cleanup configuration options, see {@link CleanJsArtifactsOptions | **`CleanJsArtifactsOptions`**}.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* await cleanJsBuildArtifacts("dist/**\/*.js");
|
|
229
|
+
* await cleanJsBuildArtifacts("dist/**\/*.{js,cjs,mjs}");
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* await cleanJsBuildArtifacts(["dist/**\/*.js", "build/*\/*.mjs"], {
|
|
235
|
+
* removeSourceMap: false,
|
|
236
|
+
* removeRegionComment: false,
|
|
237
|
+
* removeAdjacentEmptyLines: true
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
declare const cleanJsBuildArtifacts: (pattern: StringCollection, options?: CleanJsArtifactsOptions) => Promise<void>;
|
|
242
|
+
/** Command identity associated with {@link cleanTypesBuildArtifacts | **`clean-types-build-artifacts`**}. */
|
|
243
|
+
declare const commandCtbaIdentity: CommandIdentity;
|
|
244
|
+
/** ----------------------------------------------------------------
|
|
245
|
+
* * ***Configuration options for {@link cleanTypesBuildArtifacts | **`cleanTypesBuildArtifacts`**}.***
|
|
246
|
+
* ----------------------------------------------------------------
|
|
247
|
+
*/
|
|
248
|
+
type CleanTypesArtifactsOptions = CleanCoreOptions;
|
|
249
|
+
/** ----------------------------------------------------------------
|
|
250
|
+
* * ***Removes build artifact comments from compiled Types files.***
|
|
251
|
+
* ----------------------------------------------------------------
|
|
252
|
+
*
|
|
253
|
+
* This function scans files matching the provided glob pattern(s) and removes:
|
|
254
|
+
* - Source path comments.
|
|
255
|
+
* - ESLint directive comments.
|
|
256
|
+
* - Optional source map references.
|
|
257
|
+
*
|
|
258
|
+
* It can also remove empty lines adjacent to those comments to keep
|
|
259
|
+
* output files tidy.
|
|
260
|
+
*
|
|
261
|
+
* @param pattern - Glob pattern or list of patterns pointing to Types output files.
|
|
262
|
+
* @param options - Cleanup configuration options, see {@link CleanTypesArtifactsOptions | **`CleanTypesArtifactsOptions`**}.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* await cleanTypesBuildArtifacts("dist/**\/*.d.ts");
|
|
267
|
+
* await cleanTypesBuildArtifacts("dist/**\/*.d.{ts,cts,mts}");
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* await cleanTypesBuildArtifacts(["dist/**\/*.d.ts", "build/*\/*.mts"], {
|
|
273
|
+
* removeSourceMap: false,
|
|
274
|
+
* removeAdjacentEmptyLines: true
|
|
275
|
+
* });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare const cleanTypesBuildArtifacts: (pattern: StringCollection, options?: CleanTypesArtifactsOptions) => Promise<void>;
|
|
279
|
+
/** ----------------------------------------------------------------
|
|
280
|
+
* * ***Creates a `Set` of parameters for {@link copyFileToDest | **`copy-file-to-dest`**}.***
|
|
281
|
+
* ----------------------------------------------------------------
|
|
282
|
+
*
|
|
283
|
+
* Utility helper to construct a `Set` of {@link CopyFileToDestParam | `CopyFileToDestParam`}
|
|
284
|
+
* with proper type inference and editor autocomplete support.
|
|
285
|
+
*
|
|
286
|
+
* This is primarily useful when passing parameters as a `Set`,
|
|
287
|
+
* since directly using `new Set([...])` may result in poor
|
|
288
|
+
* TypeScript inference and missing autocomplete for object literals.
|
|
289
|
+
*
|
|
290
|
+
* ----------------------------------------------------------------
|
|
291
|
+
* Behavior
|
|
292
|
+
*
|
|
293
|
+
* - Accepts a single parameter or an array of parameters.
|
|
294
|
+
* - Automatically normalizes the input into a `Set`.
|
|
295
|
+
*
|
|
296
|
+
* ----------------------------------------------------------------
|
|
297
|
+
*
|
|
298
|
+
* @param items
|
|
299
|
+
* A single {@link CopyFileToDestParam | `CopyFileToDestParam`} or an array of parameters.
|
|
300
|
+
*
|
|
301
|
+
* @returns
|
|
302
|
+
* A `Set` containing the provided parameters.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* // single item
|
|
307
|
+
* const setA = createCopyFileToDestParameterSet({
|
|
308
|
+
* source: "dist/index.d.ts",
|
|
309
|
+
* target: "dist"
|
|
310
|
+
* });
|
|
311
|
+
*
|
|
312
|
+
* // multiple items
|
|
313
|
+
* const setB = createCopyFileToDestParameterSet([
|
|
314
|
+
* {
|
|
315
|
+
* source: "dist/a.d.ts",
|
|
316
|
+
* target: "dist"
|
|
317
|
+
* },
|
|
318
|
+
* {
|
|
319
|
+
* source: "dist/b.d.ts",
|
|
320
|
+
* target: "dist"
|
|
321
|
+
* }
|
|
322
|
+
* ]);
|
|
323
|
+
*
|
|
324
|
+
* // usage with copyFileToDest
|
|
325
|
+
* await copyFileToDest(setB);
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
declare function createCopyFileToDestParameterSet(items: CopyFileToDestParam | CopyFileToDestParam[]): Set<CopyFileToDestParam>;
|
|
329
|
+
/** Command identity associated with {@link copyFileToDest | **`copy-file-to-dest`**}. */
|
|
330
|
+
declare const commandCftdIdentity: CommandIdentity;
|
|
331
|
+
/** ----------------------------------------------------------------
|
|
332
|
+
* * ***Configuration options for {@link copyFileToDest | **`copy-file-to-dest`**}.***
|
|
333
|
+
* ----------------------------------------------------------------
|
|
334
|
+
*/
|
|
335
|
+
type CopyFileToDestOptions = OmitStrict<BaseOptions, "patternOptions">;
|
|
336
|
+
/** ----------------------------------------------------------------
|
|
337
|
+
* * ***Describes the parameter options for copying a single file to a destination path of {@link copyFileToDest | **`copy-file-to-dest`**}.***
|
|
338
|
+
* ----------------------------------------------------------------
|
|
339
|
+
*/
|
|
340
|
+
type CopyFileToDestParam = {
|
|
341
|
+
/** ----------------------------------------------------------------
|
|
342
|
+
* * ***Path to the source file to be copied.***
|
|
343
|
+
* ----------------------------------------------------------------
|
|
344
|
+
* Can be either an absolute path or a path relative to the project root.
|
|
345
|
+
*
|
|
346
|
+
* @example "src/assets/logo.png"
|
|
347
|
+
*/
|
|
348
|
+
source: string;
|
|
349
|
+
/** ----------------------------------------------------------------
|
|
350
|
+
* * ***Target directory where the file will be copied.***
|
|
351
|
+
* ----------------------------------------------------------------
|
|
352
|
+
*
|
|
353
|
+
* - When `absoluteTarget` is `false` **(default)**, this path is resolved relative to `outputRoot`.
|
|
354
|
+
* - When `absoluteTarget` is `true`, this path is treated as an absolute path relative to the project root.
|
|
355
|
+
*
|
|
356
|
+
* @example "assets/images"
|
|
357
|
+
*/
|
|
358
|
+
target: string;
|
|
359
|
+
/** ----------------------------------------------------------------
|
|
360
|
+
* * ***Optional custom file name for the copied file.***
|
|
361
|
+
* ----------------------------------------------------------------
|
|
362
|
+
*
|
|
363
|
+
* If omitted, the original file name from `source` will be preserved.
|
|
364
|
+
*
|
|
365
|
+
* @example "logo-new.png"
|
|
366
|
+
*
|
|
367
|
+
* @default undefined
|
|
368
|
+
*/
|
|
369
|
+
fileName?: string;
|
|
370
|
+
/** ----------------------------------------------------------------
|
|
371
|
+
* * ***Output root directory used when resolving the `target` path.***
|
|
372
|
+
* ----------------------------------------------------------------
|
|
373
|
+
*
|
|
374
|
+
* When `absoluteTarget` is `false`, the final copy destination will be
|
|
375
|
+
* `<project-root>/<outputRoot>/<target>`.
|
|
376
|
+
*
|
|
377
|
+
* @default "dist"
|
|
378
|
+
* @example "build"
|
|
379
|
+
*/
|
|
380
|
+
outputRoot?: string;
|
|
381
|
+
/** ----------------------------------------------------------------
|
|
382
|
+
* * ***When `true`, disables `outputRoot` prefixing and treats `target`
|
|
383
|
+
* as an absolute path relative to the project root.***
|
|
384
|
+
* ----------------------------------------------------------------
|
|
385
|
+
*
|
|
386
|
+
* Use this when you want to copy directly to an absolute path inside the project,
|
|
387
|
+
* bypassing the `outputRoot` prefix.
|
|
388
|
+
*
|
|
389
|
+
* @default false
|
|
390
|
+
*/
|
|
391
|
+
absoluteTarget?: boolean;
|
|
392
|
+
/** ----------------------------------------------------------------
|
|
393
|
+
* * ***When `true`, suppresses errors when the source file does not exist.***
|
|
394
|
+
* ----------------------------------------------------------------
|
|
395
|
+
*
|
|
396
|
+
* - Instead of throwing or logging an error, the operation will be skipped.
|
|
397
|
+
* - Useful in development or watch mode where build outputs may not be immediately available.
|
|
398
|
+
*
|
|
399
|
+
* @default false
|
|
400
|
+
*/
|
|
401
|
+
ignoreMissingSourceError?: boolean;
|
|
402
|
+
};
|
|
403
|
+
/** ----------------------------------------------------------------
|
|
404
|
+
* * ***Copy one or more files of any type into destination directories.***
|
|
405
|
+
* ----------------------------------------------------------------
|
|
406
|
+
*
|
|
407
|
+
* This utility is **file-type agnostic** and can be used to copy any kind of asset,
|
|
408
|
+
* including CSS, JavaScript, JSON, images, fonts, or other static files.
|
|
409
|
+
*
|
|
410
|
+
* - *The function supports:*
|
|
411
|
+
* - Copying a **single file** using a single configuration object.
|
|
412
|
+
* - Copying **multiple files** using an ***array*** or a ***Set*** of configuration objects.
|
|
413
|
+
*
|
|
414
|
+
* - When using a `Set`, it is recommended to use
|
|
415
|
+
* {@link createCopyFileToDestParameterSet | **`createCopyFileToDestParameterSet`**}
|
|
416
|
+
* to ensure proper TypeScript inference and autocomplete support.
|
|
417
|
+
*
|
|
418
|
+
* - By default, files are copied into a `dist` directory relative to the project root.
|
|
419
|
+
* - This behavior can be customized per item via `outputRoot` or bypassed entirely
|
|
420
|
+
* using `absoluteTarget`.
|
|
421
|
+
*
|
|
422
|
+
* ----------------------------------------------------------------
|
|
423
|
+
*
|
|
424
|
+
* @param parameter
|
|
425
|
+
* A single {@link CopyFileToDestParam | **`CopyFileToDestParam`**} object,
|
|
426
|
+
* an array, or a `Set` of {@link CopyFileToDestParam | **`CopyFileToDestParam`**}.
|
|
427
|
+
*
|
|
428
|
+
* - *When a collection is provided:*
|
|
429
|
+
* - Each item is validated independently.
|
|
430
|
+
* - Files are copied sequentially.
|
|
431
|
+
* - Logging reflects the cumulative copy progress.
|
|
432
|
+
*
|
|
433
|
+
* ----------------------------------------------------------------
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* // Copy a single CSS file into "dist/".
|
|
437
|
+
* // Result: "dist/main.css".
|
|
438
|
+
* await copyFileToDest({
|
|
439
|
+
* source: "src/styles/main.css",
|
|
440
|
+
* target: "."
|
|
441
|
+
* });
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* // Copy a single CSS file into "dist/styles/".
|
|
445
|
+
* await copyFileToDest({
|
|
446
|
+
* source: "src/styles/main.css",
|
|
447
|
+
* target: "styles"
|
|
448
|
+
* });
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* // Copy multiple files into "dist/config/" (using array).
|
|
452
|
+
* // Result: "dist/config/a.json" and "dist/config/b.json".
|
|
453
|
+
* await copyFileToDest([
|
|
454
|
+
* {
|
|
455
|
+
* source: "src/config/a.json",
|
|
456
|
+
* target: "config"
|
|
457
|
+
* },
|
|
458
|
+
* {
|
|
459
|
+
* source: "src/config/b.json",
|
|
460
|
+
* target: "config"
|
|
461
|
+
* }
|
|
462
|
+
* ]);
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* // Copy multiple files into "dist/config/" (using Set).
|
|
466
|
+
* // ⚠️ Requires explicit typing for proper inference.
|
|
467
|
+
* await copyFileToDest(new Set<CopyFileToDestParam>([
|
|
468
|
+
* {
|
|
469
|
+
* source: "src/config/a.json",
|
|
470
|
+
* target: "config"
|
|
471
|
+
* },
|
|
472
|
+
* {
|
|
473
|
+
* source: "src/config/b.json",
|
|
474
|
+
* target: "config"
|
|
475
|
+
* }
|
|
476
|
+
* ]));
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* // Recommended: using helper for Set (better DX).
|
|
480
|
+
* await copyFileToDest(
|
|
481
|
+
* createCopyFileToDestParameterSet([
|
|
482
|
+
* {
|
|
483
|
+
* source: "src/config/a.json",
|
|
484
|
+
* target: "config"
|
|
485
|
+
* },
|
|
486
|
+
* {
|
|
487
|
+
* source: "src/config/b.json",
|
|
488
|
+
* target: "config"
|
|
489
|
+
* }
|
|
490
|
+
* ])
|
|
491
|
+
* );
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* // Copy multiple files with a custom output root.
|
|
495
|
+
* // Result: "build/scripts/setup.js" and "build/scripts/runtime.js".
|
|
496
|
+
* await copyFileToDest([
|
|
497
|
+
* {
|
|
498
|
+
* source: "src/scripts/setup.js",
|
|
499
|
+
* target: "scripts",
|
|
500
|
+
* outputRoot: "build"
|
|
501
|
+
* },
|
|
502
|
+
* {
|
|
503
|
+
* source: "src/scripts/runtime.js",
|
|
504
|
+
* target: "scripts",
|
|
505
|
+
* outputRoot: "build"
|
|
506
|
+
* }
|
|
507
|
+
* ]);
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* // Copy and rename a single file.
|
|
511
|
+
* // Result: "dist/config/app.json".
|
|
512
|
+
* await copyFileToDest({
|
|
513
|
+
* source: "src/config/app.config.json",
|
|
514
|
+
* target: "config",
|
|
515
|
+
* fileName: "app.json"
|
|
516
|
+
* });
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```ts
|
|
520
|
+
* // Copy using an absolute target path (no outputRoot prefix).
|
|
521
|
+
* // Result: "<project-root>/config/runtime/config.json".
|
|
522
|
+
* await copyFileToDest({
|
|
523
|
+
* source: "src/runtime/config.json",
|
|
524
|
+
* target: "config/runtime",
|
|
525
|
+
* absoluteTarget: true
|
|
526
|
+
* });
|
|
527
|
+
* ```
|
|
528
|
+
*
|
|
529
|
+
* ----------------------------------------------------------------
|
|
530
|
+
*
|
|
531
|
+
* @remarks
|
|
532
|
+
* - The function ensures that all target directories exist before copying.
|
|
533
|
+
* - Each item is validated to be a plain object with valid fields.
|
|
534
|
+
* - The original file contents are copied without transformation.
|
|
535
|
+
* - Errors during copying are caught and reported via the logger.
|
|
536
|
+
*/
|
|
537
|
+
declare function copyFileToDest(parameter: CopyFileToDestParam, options?: CopyFileToDestOptions): Promise<void>;
|
|
538
|
+
declare function copyFileToDest(parameter: CopyFileToDestParam[], options?: CopyFileToDestOptions): Promise<void>;
|
|
539
|
+
declare function copyFileToDest(parameter: Set<CopyFileToDestParam>, options?: CopyFileToDestOptions): Promise<void>;
|
|
540
|
+
/** ----------------------------------------------------------------
|
|
541
|
+
* * ***Default Pattern Policy for **ensure css import** operations.***
|
|
542
|
+
* ----------------------------------------------------------------
|
|
543
|
+
*
|
|
544
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
545
|
+
* - {@link ensureCssImport | **`ensure-css-import`**}.
|
|
546
|
+
*
|
|
547
|
+
* @remarks
|
|
548
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
549
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
550
|
+
*/
|
|
551
|
+
declare const DEFAULT_ECI_PATTERN_POLICY: {
|
|
552
|
+
readonly filesOnly: true;
|
|
553
|
+
readonly forceUnique: true;
|
|
554
|
+
};
|
|
555
|
+
/** ----------------------------------------------------------------
|
|
556
|
+
* * ***Resolved Pattern Options for **ensure css import** operations.***
|
|
557
|
+
* ----------------------------------------------------------------
|
|
558
|
+
*
|
|
559
|
+
* Pattern options used by:
|
|
560
|
+
* - {@link ensureCssImport | **`ensure-css-import`**}.
|
|
561
|
+
*/
|
|
562
|
+
declare const resolvedEciPatternOption: PatternOptions<true, true>;
|
|
563
|
+
/** Command identity associated with {@link ensureCssImport | **`ensure-css-import`**}. */
|
|
564
|
+
declare const commandEciIdentity: CommandIdentity;
|
|
565
|
+
/** ----------------------------------------------------------------
|
|
566
|
+
* * ***Configuration options for {@link ensureCssImport | **`ensure-css-import`**}.***
|
|
567
|
+
* ----------------------------------------------------------------
|
|
568
|
+
*/
|
|
569
|
+
type EnsureCssImportOptions = {
|
|
570
|
+
/** ----------------------------------------------------------------
|
|
571
|
+
* * ***CSS import path(s) to ensure exist in JS output.***
|
|
572
|
+
* ----------------------------------------------------------------
|
|
573
|
+
*
|
|
574
|
+
* Accepts a single path or multiple paths.
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```ts
|
|
578
|
+
* "./search.css"
|
|
579
|
+
* ```
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```ts
|
|
583
|
+
* ["./search.css", "./theme.css"]
|
|
584
|
+
* ```
|
|
585
|
+
*/
|
|
586
|
+
cssImportPath: string | readonly (string | readonly string[])[] | Set<string>;
|
|
587
|
+
/** ----------------------------------------------------------------
|
|
588
|
+
* * ***Remove duplicate CSS imports (recommended).***
|
|
589
|
+
* ----------------------------------------------------------------
|
|
590
|
+
*
|
|
591
|
+
* @default true
|
|
592
|
+
*/
|
|
593
|
+
dedupe?: boolean;
|
|
594
|
+
/** ----------------------------------------------------------------
|
|
595
|
+
* * ***Sort CSS imports alphabetically before inserting.***
|
|
596
|
+
* ----------------------------------------------------------------
|
|
597
|
+
*
|
|
598
|
+
* @default false
|
|
599
|
+
*/
|
|
600
|
+
sort?: boolean;
|
|
601
|
+
/** --------------------------------------------------------
|
|
602
|
+
* * ***Minify JS output (except directive prologue).***
|
|
603
|
+
* --------------------------------------------------------
|
|
604
|
+
*
|
|
605
|
+
* - Keeps `"use client"` / `"use strict"` on separate lines.
|
|
606
|
+
* - Everything else is collapsed into a single line.
|
|
607
|
+
*
|
|
608
|
+
* @default false
|
|
609
|
+
*/
|
|
610
|
+
minify?: boolean;
|
|
611
|
+
} & BaseOptions<typeof DEFAULT_ECI_PATTERN_POLICY.filesOnly, typeof DEFAULT_ECI_PATTERN_POLICY.forceUnique>;
|
|
612
|
+
/** ----------------------------------------------------------------
|
|
613
|
+
* * ***Ensures CSS import(s) exist in compiled JavaScript files.***
|
|
614
|
+
* ----------------------------------------------------------------
|
|
615
|
+
* - *Behavior:*
|
|
616
|
+
* - Supports **multiple CSS imports**.
|
|
617
|
+
* - Fully **idempotent**.
|
|
618
|
+
* - Optional **dedupe & sorting**.
|
|
619
|
+
*
|
|
620
|
+
* @param {string | string[] | Set<string>} pattern
|
|
621
|
+
* Glob pattern(s) pointing to compiled JS files.
|
|
622
|
+
*
|
|
623
|
+
* @param {EnsureCssImportOptions} options
|
|
624
|
+
* Configuration options.
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```ts
|
|
628
|
+
* await ensureCssImport("dist/**\/*.js", {
|
|
629
|
+
* cssImportPath: ["./search.css", "./theme.css"],
|
|
630
|
+
* dedupe: true,
|
|
631
|
+
* sort: true,
|
|
632
|
+
* minify: true
|
|
633
|
+
* });
|
|
634
|
+
* ```
|
|
635
|
+
*/
|
|
636
|
+
declare const ensureCssImport: (pattern: StringCollection, options: EnsureCssImportOptions) => Promise<void>;
|
|
637
|
+
/** ----------------------------------------------------------------
|
|
638
|
+
* * ***Default Pattern Policy for **ensure final newline** operations.***
|
|
639
|
+
* ----------------------------------------------------------------
|
|
640
|
+
*
|
|
641
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
642
|
+
* - {@link ensureFinalNewline | **`ensure-final-newline`**}.
|
|
643
|
+
*
|
|
644
|
+
* @remarks
|
|
645
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
646
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
647
|
+
*/
|
|
648
|
+
declare const DEFAULT_EFN_PATTERN_POLICY: {
|
|
649
|
+
readonly filesOnly: true;
|
|
650
|
+
readonly forceUnique: true;
|
|
651
|
+
};
|
|
652
|
+
/** ----------------------------------------------------------------
|
|
653
|
+
* * ***Resolved Pattern Options for **ensure final newline** operations.***
|
|
654
|
+
* ----------------------------------------------------------------
|
|
655
|
+
*
|
|
656
|
+
* Pattern options used by:
|
|
657
|
+
* - {@link ensureFinalNewline | **`ensure-final-newline`**}.
|
|
658
|
+
*/
|
|
659
|
+
declare const resolvedEfnPatternOption: PatternOptions<true, true>;
|
|
660
|
+
/** Command identity associated with {@link ensureFinalNewline | **`ensure-final-newline`**}. */
|
|
661
|
+
declare const commandEfnIdentity: CommandIdentity;
|
|
662
|
+
/** ----------------------------------------------------------------
|
|
663
|
+
* * ***Configuration options for {@link ensureFinalNewline | **`ensure-final-newline`**}.***
|
|
664
|
+
* ----------------------------------------------------------------
|
|
665
|
+
*/
|
|
666
|
+
type EnsureFinalNewlineOptions = BaseOptions<typeof DEFAULT_EFN_PATTERN_POLICY.filesOnly, typeof DEFAULT_EFN_PATTERN_POLICY.forceUnique>;
|
|
667
|
+
/** ----------------------------------------------------------------
|
|
668
|
+
* * ***Ensure files end with exactly one final newline.***
|
|
669
|
+
* ----------------------------------------------------------------
|
|
670
|
+
*
|
|
671
|
+
* Scans files matching the provided glob pattern(s) and ensures that
|
|
672
|
+
* **each file ends with exactly one newline character**.
|
|
673
|
+
*
|
|
674
|
+
* - *Behavior:*
|
|
675
|
+
* - Removes **all trailing newline characters** at the end of the file.
|
|
676
|
+
* - Appends **exactly one** platform-consistent newline (`EOL`).
|
|
677
|
+
* - Preserves all internal formatting and whitespace.
|
|
678
|
+
* - Does **not** modify files that are already compliant.
|
|
679
|
+
*
|
|
680
|
+
* - *Newline handling:*
|
|
681
|
+
* - Supports both `LF` (`\n`) and `CRLF` (`\r\n`).
|
|
682
|
+
* - Uses **`EOL`** to ensure consistent output across the project.
|
|
683
|
+
*
|
|
684
|
+
* - *Safety:*
|
|
685
|
+
* - Skips non-existent paths.
|
|
686
|
+
* - Skips non-file entries (directories, symlinks, etc.).
|
|
687
|
+
* - Writes only when the file content actually changes.
|
|
688
|
+
*
|
|
689
|
+
* @param {string | string[] | Set<string>} pattern
|
|
690
|
+
* Glob pattern(s) pointing to files that should be checked and normalized.
|
|
691
|
+
*
|
|
692
|
+
* @param {EnsureFinalNewlineOptions} [options]
|
|
693
|
+
* Internal execution options (CLI vs utility context).
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* ```ts
|
|
697
|
+
* await ensureFinalNewline("dist/**\/*.{js,cjs,mjs,d.ts}");
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* ```ts
|
|
702
|
+
* await ensureFinalNewline(["dist/**\/*.js", "dist/**\/*.d.ts"]);
|
|
703
|
+
* ```
|
|
704
|
+
*
|
|
705
|
+
* @remarks
|
|
706
|
+
* This utility is typically executed **post-build** to ensure output
|
|
707
|
+
* files follow POSIX tooling expectations and common formatting conventions.
|
|
708
|
+
*/
|
|
709
|
+
declare const ensureFinalNewline: (pattern: StringCollection, options?: EnsureFinalNewlineOptions) => Promise<void>;
|
|
710
|
+
/** ----------------------------------------------------------------
|
|
711
|
+
* * ***Default Pattern Policy for **generate reference index** operations.***
|
|
712
|
+
* ----------------------------------------------------------------
|
|
713
|
+
*
|
|
714
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
715
|
+
* - {@link generateReferenceIndex | **`generate-reference-index`**}.
|
|
716
|
+
*
|
|
717
|
+
* @remarks
|
|
718
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
719
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
720
|
+
*/
|
|
721
|
+
declare const DEFAULT_GRI_PATTERN_POLICY: {
|
|
722
|
+
readonly filesOnly: true;
|
|
723
|
+
readonly forceUnique: true;
|
|
724
|
+
};
|
|
725
|
+
/** ----------------------------------------------------------------
|
|
726
|
+
* * ***Resolved Pattern Options for **generate reference index** operations.***
|
|
727
|
+
* ----------------------------------------------------------------
|
|
728
|
+
*
|
|
729
|
+
* Pattern options used by:
|
|
730
|
+
* - {@link generateReferenceIndex | **`generate-reference-index`**}.
|
|
731
|
+
*/
|
|
732
|
+
declare const resolvedGriPatternOption: PatternOptions<true, true>;
|
|
733
|
+
/** Command identity associated with {@link generateReferenceIndex | **`generate-reference-index`**}. */
|
|
734
|
+
declare const commandGriIdentity: CommandIdentity;
|
|
735
|
+
/** ----------------------------------------------------------------
|
|
736
|
+
* * ***Configuration options for {@link generateReferenceIndex | **`generate-reference-index`**}.***
|
|
737
|
+
* ----------------------------------------------------------------
|
|
738
|
+
*/
|
|
739
|
+
type GenerateReferenceOptions = {
|
|
740
|
+
/** --------------------------------------------------------------
|
|
741
|
+
* * ***Output directory.***
|
|
742
|
+
* --------------------------------------------------------------
|
|
743
|
+
*
|
|
744
|
+
* Directory where the generated index file will be written.
|
|
745
|
+
*
|
|
746
|
+
* @default "dist/.references"
|
|
747
|
+
*/
|
|
748
|
+
outDir?: string;
|
|
749
|
+
/** --------------------------------------------------------------
|
|
750
|
+
* * ***Output index file name.***
|
|
751
|
+
* --------------------------------------------------------------
|
|
752
|
+
*
|
|
753
|
+
* Name of the generated `.d.ts` index file.
|
|
754
|
+
*
|
|
755
|
+
* @default "index.d.ts"
|
|
756
|
+
*/
|
|
757
|
+
outFileName?: string;
|
|
758
|
+
/** --------------------------------------------------------------
|
|
759
|
+
* * ***Enable exported type aggregation.***
|
|
760
|
+
* --------------------------------------------------------------
|
|
761
|
+
*
|
|
762
|
+
* When enabled, generates:
|
|
763
|
+
*
|
|
764
|
+
* ```ts
|
|
765
|
+
* export * from "./module";
|
|
766
|
+
* ```
|
|
767
|
+
*
|
|
768
|
+
* for each unique declaration entry.
|
|
769
|
+
*
|
|
770
|
+
* @default false
|
|
771
|
+
*/
|
|
772
|
+
withExportTypes?: boolean;
|
|
773
|
+
/** --------------------------------------------------------------
|
|
774
|
+
* * ***Base directory for resolving reference paths.***
|
|
775
|
+
* --------------------------------------------------------------
|
|
776
|
+
*
|
|
777
|
+
* Used to compute relative paths inside the generated index file.
|
|
778
|
+
*
|
|
779
|
+
* @default "dist"
|
|
780
|
+
*/
|
|
781
|
+
inputDirReference?: string;
|
|
782
|
+
/** --------------------------------------------------------------
|
|
783
|
+
* * ***Restrict input to TypeScript declaration files only.***
|
|
784
|
+
* --------------------------------------------------------------
|
|
785
|
+
*
|
|
786
|
+
* When enabled (`true`), this option filters the input files to include **only**
|
|
787
|
+
* TypeScript declaration files with extensions `.d.ts`, `.d.mts`, and `.d.cts`.
|
|
788
|
+
*
|
|
789
|
+
* This filtering is applied **after** matching files by the provided glob patterns,
|
|
790
|
+
* effectively excluding all other file types, including JavaScript outputs
|
|
791
|
+
* (`.js`, `.mjs`, `.cjs`) and TypeScript source files (`.ts`, `.mts`, `.cts`).
|
|
792
|
+
*
|
|
793
|
+
* - *Examples:*
|
|
794
|
+
* - With a pattern like `"dist/**\/*.d.ts"`, enabling this option has no practical effect,
|
|
795
|
+
* since the pattern already matches only declaration files.
|
|
796
|
+
* - With a broader pattern such as `"dist/**\/*"` or `"dist/**\/*.ts"`,
|
|
797
|
+
* enabling this option will exclude non-declaration files (e.g., `.ts` source files),
|
|
798
|
+
* resulting in only declaration files being included.
|
|
799
|
+
* - If your patterns include JavaScript outputs (`.js`, `.mjs`, `.cjs`),
|
|
800
|
+
* enabling this option will exclude those files as well.
|
|
801
|
+
*
|
|
802
|
+
* When disabled (`false`), all matched files are included regardless of extension,
|
|
803
|
+
* so JavaScript outputs and source files matching the patterns will be part of
|
|
804
|
+
* the reference and export generation.
|
|
805
|
+
*
|
|
806
|
+
* Use this option and set to `true`, when you want to guarantee that only TypeScript declaration files
|
|
807
|
+
* are included in the generated references and exports, preventing accidental
|
|
808
|
+
* inclusion of source or JavaScript build output files.
|
|
809
|
+
*
|
|
810
|
+
* @default true
|
|
811
|
+
*/
|
|
812
|
+
onlyDeclarations?: boolean;
|
|
813
|
+
/** --------------------------------------------------------------
|
|
814
|
+
* * ***Output banner configuration.***
|
|
815
|
+
* --------------------------------------------------------------
|
|
816
|
+
*
|
|
817
|
+
* Controls the banner text prepended to the generated output file.
|
|
818
|
+
*
|
|
819
|
+
* - `true` **(default)** ➔ automatically generates banner from `package.json`
|
|
820
|
+
* using {@link generatePackageBanner | `generatePackageBanner`}.
|
|
821
|
+
* - `false` ➔ disables banner injection entirely.
|
|
822
|
+
* - `string` ➔ uses the provided custom banner text.
|
|
823
|
+
* - `Promise<string>` ➔ resolved and used as banner text.
|
|
824
|
+
*
|
|
825
|
+
* @default true
|
|
826
|
+
*/
|
|
827
|
+
banner?: BannerInput;
|
|
828
|
+
} & BaseOptions<typeof DEFAULT_GRI_PATTERN_POLICY.filesOnly, typeof DEFAULT_GRI_PATTERN_POLICY.forceUnique>;
|
|
829
|
+
/** ----------------------------------------------------------------
|
|
830
|
+
* * ***Generates a TypeScript reference index file (.d.ts).***
|
|
831
|
+
* ----------------------------------------------------------------
|
|
832
|
+
*
|
|
833
|
+
* This function resolves files from the given glob pattern(s) and generates
|
|
834
|
+
* a single declaration index file containing:
|
|
835
|
+
*
|
|
836
|
+
* - `/// \<reference path="..." />` directives.
|
|
837
|
+
* - optional `export * from "..."` statements.
|
|
838
|
+
*
|
|
839
|
+
* Supported input files include declaration and JavaScript module outputs:
|
|
840
|
+
* - `.d.ts`.
|
|
841
|
+
* - `.js`.
|
|
842
|
+
* - `.cjs`.
|
|
843
|
+
* - `.mjs`.
|
|
844
|
+
*
|
|
845
|
+
* The output is typically used to aggregate multiple declaration or build
|
|
846
|
+
* artifacts into a single entry point.
|
|
847
|
+
*
|
|
848
|
+
* @param pattern - Glob pattern or list of patterns used to match output files, supports `.d.ts`, `.js`, `.cjs`, and `.mjs` extensions.
|
|
849
|
+
*
|
|
850
|
+
* @param options - Reference index generation options, see {@link GenerateReferenceOptions | **`GenerateReferenceOptions`**}.
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* Basic usage with declaration files only:
|
|
854
|
+
* ```ts
|
|
855
|
+
* await generateReferenceIndex("dist/**\/*.d.ts");
|
|
856
|
+
* ```
|
|
857
|
+
*
|
|
858
|
+
* Result (`dist/.references/index.d.ts`):
|
|
859
|
+
* ```ts
|
|
860
|
+
* // References Paths:
|
|
861
|
+
* /// \<reference path="../types/user.d.ts" />
|
|
862
|
+
* /// \<reference path="../types/post.d.ts" />
|
|
863
|
+
* ```
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* Restrict to declaration files even if pattern matches other files,
|
|
867
|
+
* by default `onlyDeclarations` options is `true`:
|
|
868
|
+
* ```ts
|
|
869
|
+
* await generateReferenceIndex("dist/**\/*", { onlyDeclarations: true });
|
|
870
|
+
* ```
|
|
871
|
+
*
|
|
872
|
+
* Result (`dist/.references/index.d.ts`):
|
|
873
|
+
* ```ts
|
|
874
|
+
* // References Paths:
|
|
875
|
+
* /// \<reference path="../types/user.d.ts" />
|
|
876
|
+
* /// \<reference path="../types/post.d.cts" />
|
|
877
|
+
* ```
|
|
878
|
+
*
|
|
879
|
+
* @example
|
|
880
|
+
* Include all matched files (source `.ts` and JS outputs) without filtering declaration files only:
|
|
881
|
+
* ```ts
|
|
882
|
+
* await generateReferenceIndex("dist/**\/*", { onlyDeclarations: false });
|
|
883
|
+
* ```
|
|
884
|
+
*
|
|
885
|
+
* Result (`dist/.references/index.d.ts`):
|
|
886
|
+
* ```ts
|
|
887
|
+
* // References Paths:
|
|
888
|
+
* /// \<reference path="../models/order.ts" />
|
|
889
|
+
* /// \<reference path="../models/user.js" />
|
|
890
|
+
* /// \<reference path="../models/another.cjs" />
|
|
891
|
+
* ```
|
|
892
|
+
*
|
|
893
|
+
* (Here, both `.ts` source files and declaration files are
|
|
894
|
+
* included if matched, because `onlyDeclarations` is `false`).
|
|
895
|
+
*
|
|
896
|
+
* @example
|
|
897
|
+
* Include JavaScript build outputs with no declaration-only restriction:
|
|
898
|
+
* ```ts
|
|
899
|
+
* await generateReferenceIndex("dist/**\/*.js", { onlyDeclarations: false });
|
|
900
|
+
* ```
|
|
901
|
+
*
|
|
902
|
+
* Result (`dist/.references/index.d.ts`):
|
|
903
|
+
* ```ts
|
|
904
|
+
* // References Paths:
|
|
905
|
+
* /// \<reference path="../runtime/helpers.js" />
|
|
906
|
+
* /// \<reference path="../runtime/constants.js" />
|
|
907
|
+
* ```
|
|
908
|
+
*
|
|
909
|
+
* (JavaScript files are included because `onlyDeclarations` is `false`).
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* Restrict to declaration files when pattern includes source `.ts` and JS files:
|
|
913
|
+
* ```ts
|
|
914
|
+
* await generateReferenceIndex("dist/**\/*.ts");
|
|
915
|
+
* ```
|
|
916
|
+
*
|
|
917
|
+
* Result (`dist/.references/index.d.ts`):
|
|
918
|
+
* ```ts
|
|
919
|
+
* // References Paths:
|
|
920
|
+
* /// \<reference path="../models/user.d.ts" />
|
|
921
|
+
* /// \<reference path="../models/order.d.ts" />
|
|
922
|
+
* ```
|
|
923
|
+
*
|
|
924
|
+
* (Here `.ts` source files are ignored; only `.d.ts` declarations are included).
|
|
925
|
+
*
|
|
926
|
+
* ----------------------------------------------------------------
|
|
927
|
+
*
|
|
928
|
+
* ***--- Existing examples below remain unchanged ---***
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* Generate references from types JavaScript build outputs:
|
|
932
|
+
* ```ts
|
|
933
|
+
* await generateReferenceIndex("dist/**\/*.d.{js,cjs,mjs}");
|
|
934
|
+
* ```
|
|
935
|
+
*
|
|
936
|
+
* Result (`dist/.references/index.d.ts`):
|
|
937
|
+
* ```ts
|
|
938
|
+
* // References Paths:
|
|
939
|
+
* /// \<reference path="../runtime/helpers.d.js" />
|
|
940
|
+
* /// \<reference path="../runtime/constants.d.mjs" />
|
|
941
|
+
* ```
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* Mix declaration and JavaScript module outputs:
|
|
945
|
+
* ```ts
|
|
946
|
+
* await generateReferenceIndex([
|
|
947
|
+
* "dist/**\/*.d.ts",
|
|
948
|
+
* "dist/**\/*.d.{js,cjs,mjs}"
|
|
949
|
+
* ]);
|
|
950
|
+
* ```
|
|
951
|
+
*
|
|
952
|
+
* Result (`dist/.references/index.d.ts`):
|
|
953
|
+
* ```ts
|
|
954
|
+
* // References Paths:
|
|
955
|
+
* /// \<reference path="../types/user.d.ts" />
|
|
956
|
+
* /// \<reference path="../types/post.d.mts" />
|
|
957
|
+
* /// \<reference path="../runtime/helpers.d.cjs" />
|
|
958
|
+
* ```
|
|
959
|
+
*
|
|
960
|
+
* @example
|
|
961
|
+
* Generate reference index and export all resolved modules:
|
|
962
|
+
* ```ts
|
|
963
|
+
* await generateReferenceIndex(
|
|
964
|
+
* "dist/**\/*",
|
|
965
|
+
* { withExportTypes: true }
|
|
966
|
+
* );
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* Result (`dist/.references/index.d.ts`):
|
|
970
|
+
* ```ts
|
|
971
|
+
* // References Paths:
|
|
972
|
+
* /// \<reference path="../types/user.d.ts" />
|
|
973
|
+
* /// \<reference path="../types/user.d.cts" />
|
|
974
|
+
* /// \<reference path="../types/post.d.ts" />
|
|
975
|
+
* /// \<reference path="../types/post.d.cts" />
|
|
976
|
+
*
|
|
977
|
+
* // Exported Types:
|
|
978
|
+
* export * from "../types/user";
|
|
979
|
+
* export * from "../types/post";
|
|
980
|
+
* ```
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* Use multiple input directories with a shared reference base:
|
|
984
|
+
* ```ts
|
|
985
|
+
* await generateReferenceIndex(
|
|
986
|
+
* [
|
|
987
|
+
* "dist/types/**\/*.d.ts",
|
|
988
|
+
* "dist/generated/**\/*.d.{js,cjs,mjs}"
|
|
989
|
+
* ],
|
|
990
|
+
* {
|
|
991
|
+
* inputDirReference: "dist",
|
|
992
|
+
* withExportTypes: true
|
|
993
|
+
* }
|
|
994
|
+
* );
|
|
995
|
+
* ```
|
|
996
|
+
*
|
|
997
|
+
* Result (`dist/index.d.ts`):
|
|
998
|
+
* ```ts
|
|
999
|
+
* // References Paths:
|
|
1000
|
+
* /// \<reference path="../types/user.d.ts" />
|
|
1001
|
+
* /// \<reference path="../data/config.d.cjs" />
|
|
1002
|
+
* /// \<reference path="../generated/schema.d.js" />
|
|
1003
|
+
*
|
|
1004
|
+
* // Exported Types:
|
|
1005
|
+
* export * from "../types/user";
|
|
1006
|
+
* export * from "../generated/schema";
|
|
1007
|
+
* ```
|
|
1008
|
+
*
|
|
1009
|
+
* @example
|
|
1010
|
+
* Customize output location and file name:
|
|
1011
|
+
* ```ts
|
|
1012
|
+
* await generateReferenceIndex(
|
|
1013
|
+
* "build/**\/*",
|
|
1014
|
+
* {
|
|
1015
|
+
* outDir: "build/types",
|
|
1016
|
+
* outFileName: "references-types.d.ts"
|
|
1017
|
+
* }
|
|
1018
|
+
* );
|
|
1019
|
+
* ```
|
|
1020
|
+
*
|
|
1021
|
+
* Result (`build/types/references-types.d.ts`):
|
|
1022
|
+
* ```ts
|
|
1023
|
+
* // References Paths:
|
|
1024
|
+
* /// \<reference path="../models/user.d.ts" />
|
|
1025
|
+
* /// \<reference path="../models/order.d.cts" />
|
|
1026
|
+
* /// \<reference path="../models/account.d.mts" />
|
|
1027
|
+
* ```
|
|
1028
|
+
*/
|
|
1029
|
+
declare const generateReferenceIndex: (pattern: StringCollection, options?: GenerateReferenceOptions) => Promise<void>;
|
|
1030
|
+
/** ----------------------------------------------------------------
|
|
1031
|
+
* * ***Configuration options for {@link getPackageJson | **`get-package-json`**}.***
|
|
1032
|
+
* ----------------------------------------------------------------
|
|
1033
|
+
*/
|
|
1034
|
+
type GetPackageJsonOptions = {
|
|
1035
|
+
/** ----------------------------------------------------------------
|
|
1036
|
+
* * ***Working directory of the target project.***
|
|
1037
|
+
* ----------------------------------------------------------------
|
|
1038
|
+
*
|
|
1039
|
+
* This determines where the lookup for `package.json`
|
|
1040
|
+
* will start.
|
|
1041
|
+
*
|
|
1042
|
+
* - If provided, resolution begins from this directory.
|
|
1043
|
+
* - If omitted, defaults to `process.cwd()`.
|
|
1044
|
+
*
|
|
1045
|
+
* - ***Typical use cases:***
|
|
1046
|
+
* - CLI tools executed in a project directory.
|
|
1047
|
+
* - Monorepo root resolution.
|
|
1048
|
+
* - Custom build pipelines.
|
|
1049
|
+
*
|
|
1050
|
+
* @default process.cwd()
|
|
1051
|
+
*
|
|
1052
|
+
* @remarks
|
|
1053
|
+
* This should be the directory containing your project's
|
|
1054
|
+
* `package.json`, not the directory of this package.
|
|
1055
|
+
*/
|
|
1056
|
+
cwd?: string;
|
|
1057
|
+
};
|
|
1058
|
+
/** ----------------------------------------------------------------
|
|
1059
|
+
* * ***Resolve and read the nearest `package.json`.***
|
|
1060
|
+
* ----------------------------------------------------------------
|
|
1061
|
+
*
|
|
1062
|
+
* This utility locates and loads the closest `package.json`
|
|
1063
|
+
* by walking up the directory tree starting from a given
|
|
1064
|
+
* working directory.
|
|
1065
|
+
*
|
|
1066
|
+
* - *Key characteristics:*
|
|
1067
|
+
* - Works in **Node ESM and CJS**.
|
|
1068
|
+
* - Compatible with **tsdown, rolldown, tsup, esbuild, vite, tsx, ts-node, and others**.
|
|
1069
|
+
* - Does **not** rely on JSON module imports.
|
|
1070
|
+
* - Fully typed via {@link PackageJson | **PackageJson**}.
|
|
1071
|
+
*
|
|
1072
|
+
* - *This function is intended for:*
|
|
1073
|
+
* - Build tools.
|
|
1074
|
+
* - Bundler configuration.
|
|
1075
|
+
* - CLI utilities.
|
|
1076
|
+
* - Monorepo-aware infrastructure code.
|
|
1077
|
+
*
|
|
1078
|
+
* @param options Optional resolution configuration.
|
|
1079
|
+
*
|
|
1080
|
+
* @returns The parsed contents of the resolved `package.json`.
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* const pkg = await getPackageJson();
|
|
1085
|
+
* console.log(pkg.name, pkg.version);
|
|
1086
|
+
* ```
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```ts
|
|
1090
|
+
* const pkg = await getPackageJson({
|
|
1091
|
+
* cwd: process.cwd()
|
|
1092
|
+
* });
|
|
1093
|
+
* ```
|
|
1094
|
+
*
|
|
1095
|
+
* @throws If no `package.json` can be found.
|
|
1096
|
+
* @throws If the located `package.json` is invalid JSON.
|
|
1097
|
+
*
|
|
1098
|
+
* @remarks
|
|
1099
|
+
* - Resolution always starts from `cwd` or `process.cwd()`.
|
|
1100
|
+
* - Results are not cached by default.
|
|
1101
|
+
* - Designed for infrastructure-level usage, not hot paths.
|
|
1102
|
+
*/
|
|
1103
|
+
declare const getPackageJson: (options?: GetPackageJsonOptions) => Promise<PackageJson>;
|
|
1104
|
+
/** ----------------------------------------------------------------
|
|
1105
|
+
* * ***Default Pattern Policy for **inject banner** operations.***
|
|
1106
|
+
* ----------------------------------------------------------------
|
|
1107
|
+
*
|
|
1108
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
1109
|
+
* - {@link injectBanner | **`inject-banner`**}.
|
|
1110
|
+
*
|
|
1111
|
+
* @remarks
|
|
1112
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
1113
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
1114
|
+
*/
|
|
1115
|
+
declare const DEFAULT_IB_PATTERN_POLICY: {
|
|
1116
|
+
readonly filesOnly: true;
|
|
1117
|
+
readonly forceUnique: true;
|
|
1118
|
+
};
|
|
1119
|
+
/** ----------------------------------------------------------------
|
|
1120
|
+
* * ***Resolved Pattern Options for **inject banner** operations.***
|
|
1121
|
+
* ----------------------------------------------------------------
|
|
1122
|
+
*
|
|
1123
|
+
* Pattern options used by:
|
|
1124
|
+
* - {@link injectBanner | **`inject-banner`**}.
|
|
1125
|
+
*/
|
|
1126
|
+
declare const resolvedIbPatternOption: PatternOptions<true, true>;
|
|
1127
|
+
/** Command identity associated with {@link injectBanner | **`inject-banner`**}. */
|
|
1128
|
+
declare const commandIbIdentity: CommandIdentity;
|
|
1129
|
+
/** ----------------------------------------------------------------
|
|
1130
|
+
* * ***Configuration options for {@link injectBanner | `inject-banner`}.***
|
|
1131
|
+
* ----------------------------------------------------------------
|
|
1132
|
+
*/
|
|
1133
|
+
type InjectBannerOptions = {
|
|
1134
|
+
/** Replace existing banner block(s).
|
|
1135
|
+
*
|
|
1136
|
+
* - `false` ➔ Preserve existing banners.
|
|
1137
|
+
* - `true` ➔ Replace banners matching default `/^(?:\/\*![\s\S]*?\*\/\s*)+/`.
|
|
1138
|
+
* - `RegExp` ➔ Replace banners matching provided pattern.
|
|
1139
|
+
*
|
|
1140
|
+
* Note:
|
|
1141
|
+
* The provided RegExp will be internally cloned without the `g` flag
|
|
1142
|
+
* to ensure safe `.test()` execution.
|
|
1143
|
+
*
|
|
1144
|
+
* @default false
|
|
1145
|
+
*/
|
|
1146
|
+
replaceBanner?: boolean | RegExp;
|
|
1147
|
+
/** Remove duplicated banner blocks.
|
|
1148
|
+
*
|
|
1149
|
+
* Deduplication is performed using `trim()` comparison.
|
|
1150
|
+
*
|
|
1151
|
+
* @default true
|
|
1152
|
+
*/
|
|
1153
|
+
removeDuplicate?: boolean;
|
|
1154
|
+
/** Control where new banner block(s) are injected.
|
|
1155
|
+
*
|
|
1156
|
+
* - `"top"` ➔ Place new banner before existing banner blocks.
|
|
1157
|
+
* - `"after-existing"` ➔ Append new banner after existing blocks.
|
|
1158
|
+
*
|
|
1159
|
+
* @default "after-existing"
|
|
1160
|
+
*/
|
|
1161
|
+
bannerPosition?: "top" | "after-existing";
|
|
1162
|
+
} & BaseOptions<typeof DEFAULT_IB_PATTERN_POLICY.filesOnly, typeof DEFAULT_IB_PATTERN_POLICY.forceUnique>;
|
|
1163
|
+
/** ----------------------------------------------------------------
|
|
1164
|
+
* * ***Injects banner comments into JavaScript output files.***
|
|
1165
|
+
* ----------------------------------------------------------------
|
|
1166
|
+
*
|
|
1167
|
+
* Scans files that match the provided glob pattern(s) and injects one or
|
|
1168
|
+
* more banner comment blocks at the top of each file when applicable.
|
|
1169
|
+
*
|
|
1170
|
+
* - ***Injection Rules:***
|
|
1171
|
+
* - Skips files that:
|
|
1172
|
+
* - Are empty after trimming.
|
|
1173
|
+
* - Contain no executable JavaScript code.
|
|
1174
|
+
* - Match `NON_COMMENTABLE_FILE_RE`.
|
|
1175
|
+
* - Preserves existing shebang (`#!`) at the very top of the file.
|
|
1176
|
+
* - Existing banner blocks are detected using `BANNER_RE`.
|
|
1177
|
+
*
|
|
1178
|
+
* - ***Replace Mode:***
|
|
1179
|
+
* - If `options.replaceBanner` is:
|
|
1180
|
+
* - `true` ➔ uses default `BANNER_RE`.
|
|
1181
|
+
* - `RegExp` ➔ uses the provided pattern.
|
|
1182
|
+
* - If the existing banner matches the replace pattern,
|
|
1183
|
+
* it will be fully replaced with the new banner block(s).
|
|
1184
|
+
* - The replace pattern is executed without the `g` flag internally
|
|
1185
|
+
* to avoid stateful RegExp side effects.
|
|
1186
|
+
*
|
|
1187
|
+
* - ***Banner Ordering:***
|
|
1188
|
+
* Controlled by `options.bannerPosition`:
|
|
1189
|
+
* - `"top"` ➔ new banner is placed before existing banner blocks.
|
|
1190
|
+
* - `"after-existing"` ➔ new banner is appended after existing blocks.
|
|
1191
|
+
*
|
|
1192
|
+
* - ***Deduplication:***
|
|
1193
|
+
* If `options.removeDuplicate` is `true` (default):
|
|
1194
|
+
* - Banner blocks are deduplicated based on `trim()` comparison.
|
|
1195
|
+
* - Order is preserved.
|
|
1196
|
+
*
|
|
1197
|
+
* - ***Normalization:***
|
|
1198
|
+
* - Line endings are normalized to the internal `EOL` constant.
|
|
1199
|
+
* - Each banner block is ensured to end with exactly two `EOL`s.
|
|
1200
|
+
* - The operation is idempotent — running multiple times
|
|
1201
|
+
* will not change the file further.
|
|
1202
|
+
*
|
|
1203
|
+
* @example
|
|
1204
|
+
* Basic usage:
|
|
1205
|
+
* ```ts
|
|
1206
|
+
* await injectBanner(
|
|
1207
|
+
* "dist/**\/*.js",
|
|
1208
|
+
* `
|
|
1209
|
+
* /**
|
|
1210
|
+
* * My Library v1.0.0
|
|
1211
|
+
* * (c) 2026 Your Name
|
|
1212
|
+
* *\/
|
|
1213
|
+
* `
|
|
1214
|
+
* );
|
|
1215
|
+
* ```
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1218
|
+
* Inject multiple banner blocks:
|
|
1219
|
+
* ```ts
|
|
1220
|
+
* await injectBanner(
|
|
1221
|
+
* ["dist/**\/*.js", "build/**\/*.mjs"],
|
|
1222
|
+
* [
|
|
1223
|
+
* `/** Project: MyApp *\/`,
|
|
1224
|
+
* `/** License: MIT *\/`
|
|
1225
|
+
* ]
|
|
1226
|
+
* );
|
|
1227
|
+
* ```
|
|
1228
|
+
*
|
|
1229
|
+
* @example
|
|
1230
|
+
* Replace existing banner entirely:
|
|
1231
|
+
* ```ts
|
|
1232
|
+
* await injectBanner(
|
|
1233
|
+
* "dist/**\/*.js",
|
|
1234
|
+
* `/** Updated License Banner *\/`,
|
|
1235
|
+
* { replaceBanner: true }
|
|
1236
|
+
* );
|
|
1237
|
+
* ```
|
|
1238
|
+
*
|
|
1239
|
+
* @example
|
|
1240
|
+
* Replace using custom RegExp:
|
|
1241
|
+
* ```ts
|
|
1242
|
+
* await injectBanner(
|
|
1243
|
+
* "dist/**\/*.js",
|
|
1244
|
+
* `/** New Banner *\/`,
|
|
1245
|
+
* {
|
|
1246
|
+
* replaceBanner: /^\/\*\*![\s\S]*?\*\/\s*\/,
|
|
1247
|
+
* }
|
|
1248
|
+
* );
|
|
1249
|
+
* ```
|
|
1250
|
+
*
|
|
1251
|
+
* @example
|
|
1252
|
+
* Always place banner at very top (after shebang):
|
|
1253
|
+
* ```ts
|
|
1254
|
+
* await injectBanner(
|
|
1255
|
+
* "dist/**\/*.js",
|
|
1256
|
+
* `/** Build: Production *\/`,
|
|
1257
|
+
* {
|
|
1258
|
+
* bannerPosition: "top"
|
|
1259
|
+
* }
|
|
1260
|
+
* );
|
|
1261
|
+
* ```
|
|
1262
|
+
*
|
|
1263
|
+
* @param pattern - Glob pattern(s) pointing to target JavaScript files.
|
|
1264
|
+
* @param bannerText - Banner string(s) to inject.
|
|
1265
|
+
* @param options - Injection configuration options.
|
|
1266
|
+
*/
|
|
1267
|
+
declare const injectBanner: (pattern: StringCollection, bannerText: StringCollection, options?: InjectBannerOptions) => Promise<void>;
|
|
1268
|
+
/** ----------------------------------------------------------------
|
|
1269
|
+
* * ***Default Pattern Policy for **inject directive** operations.***
|
|
1270
|
+
* ----------------------------------------------------------------
|
|
1271
|
+
*
|
|
1272
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
1273
|
+
* - {@link injectDirective | **`inject-directive`**}.
|
|
1274
|
+
*
|
|
1275
|
+
* @remarks
|
|
1276
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
1277
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
1278
|
+
*/
|
|
1279
|
+
declare const DEFAULT_ID_PATTERN_POLICY: {
|
|
1280
|
+
readonly filesOnly: true;
|
|
1281
|
+
readonly forceUnique: true;
|
|
1282
|
+
};
|
|
1283
|
+
/** ----------------------------------------------------------------
|
|
1284
|
+
* * ***Resolved Pattern Options for **inject directive** operations.***
|
|
1285
|
+
* ----------------------------------------------------------------
|
|
1286
|
+
*
|
|
1287
|
+
* Pattern options used by:
|
|
1288
|
+
* - {@link injectDirective | **`inject-directive`**}.
|
|
1289
|
+
*/
|
|
1290
|
+
declare const resolvedIdPatternOption: PatternOptions<true, true>;
|
|
1291
|
+
/** Command identity associated with {@link injectDirective | **`inject-directive`**}. */
|
|
1292
|
+
declare const commandIdIdentity: CommandIdentity;
|
|
1293
|
+
/** ----------------------------------------------------------------
|
|
1294
|
+
* * ***Configuration options for {@link injectDirective | **`inject-directive`**}.***
|
|
1295
|
+
* ----------------------------------------------------------------
|
|
1296
|
+
*/
|
|
1297
|
+
type InjectDirectiveOptions = BaseOptions<typeof DEFAULT_ID_PATTERN_POLICY.filesOnly, typeof DEFAULT_ID_PATTERN_POLICY.forceUnique>;
|
|
1298
|
+
/** ----------------------------------------------------------------
|
|
1299
|
+
* * ***Injects directive statements into JavaScript output files.***
|
|
1300
|
+
* ----------------------------------------------------------------
|
|
1301
|
+
*
|
|
1302
|
+
* This function scans files matching the provided glob pattern(s) and
|
|
1303
|
+
* injects one or more directive statements (e.g. `"use strict"`,
|
|
1304
|
+
* `"use client"`) at the top of each file when applicable.
|
|
1305
|
+
*
|
|
1306
|
+
* - *Injection behavior:*
|
|
1307
|
+
* - Skips empty files.
|
|
1308
|
+
* - Skips files that only contain directive statements.
|
|
1309
|
+
* - Avoids duplicating existing directives.
|
|
1310
|
+
* - Preserves existing file content order.
|
|
1311
|
+
*
|
|
1312
|
+
* - *Each directive is normalized and injected as a standalone statement:*
|
|
1313
|
+
* ```js
|
|
1314
|
+
* "directive-name";
|
|
1315
|
+
* ```
|
|
1316
|
+
*
|
|
1317
|
+
* @param pattern - Glob pattern or list of patterns pointing to JS output files.
|
|
1318
|
+
* @param directive - Directive string(s) to inject.
|
|
1319
|
+
* @param options - Injection configuration options, see {@link InjectDirectiveOptions | **`InjectDirectiveOptions`**}.
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* ```ts
|
|
1323
|
+
* await injectDirective("dist/**\/*.js", "use strict");
|
|
1324
|
+
* ```
|
|
1325
|
+
*
|
|
1326
|
+
* @example
|
|
1327
|
+
* ```ts
|
|
1328
|
+
* await injectDirective("dist/**\/*.js", "use client");
|
|
1329
|
+
* ```
|
|
1330
|
+
*
|
|
1331
|
+
* @example
|
|
1332
|
+
* ```ts
|
|
1333
|
+
* await injectDirective(
|
|
1334
|
+
* ["dist/**\/*.js", "build/*\/*.mjs"],
|
|
1335
|
+
* ["use strict", "use client"]
|
|
1336
|
+
* );
|
|
1337
|
+
* ```
|
|
1338
|
+
*/
|
|
1339
|
+
declare const injectDirective: (pattern: StringCollection, directive: StringCollection, options?: InjectDirectiveOptions) => Promise<void>;
|
|
1340
|
+
/** ----------------------------------------------------------------
|
|
1341
|
+
* * ***Default Pattern Policy for **normalize js build newlines** operations.***
|
|
1342
|
+
* ----------------------------------------------------------------
|
|
1343
|
+
*
|
|
1344
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
1345
|
+
* - {@link normalizeJsBuildNewlines | **`normalize-js-build-newlines`**}.
|
|
1346
|
+
*
|
|
1347
|
+
* @remarks
|
|
1348
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
1349
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
1350
|
+
*/
|
|
1351
|
+
declare const DEFAULT_NJBN_PATTERN_POLICY: {
|
|
1352
|
+
readonly filesOnly: true;
|
|
1353
|
+
readonly forceUnique: true;
|
|
1354
|
+
};
|
|
1355
|
+
/** ----------------------------------------------------------------
|
|
1356
|
+
* * ***Resolved Pattern Options for **normalize js build newlines** operations.***
|
|
1357
|
+
* ----------------------------------------------------------------
|
|
1358
|
+
*
|
|
1359
|
+
* Pattern options used by:
|
|
1360
|
+
* - {@link normalizeJsBuildNewlines | **`normalize-js-build-newlines`**}.
|
|
1361
|
+
*/
|
|
1362
|
+
declare const resolvedNjbnPatternOption: PatternOptions<true, true>;
|
|
1363
|
+
/** Generated Command Identity For {@link normalizeJsBuildNewlines | **`normalize-js-build-newlines`**}. */
|
|
1364
|
+
declare const commandNjbnIdentity: CommandIdentity;
|
|
1365
|
+
/** ----------------------------------------------------------------
|
|
1366
|
+
* * ***Configuration options for {@link normalizeJsBuildNewlines | **`normalizeJsBuildNewlines`**}.***
|
|
1367
|
+
* ----------------------------------------------------------------
|
|
1368
|
+
*/
|
|
1369
|
+
type NormalizeJsBuildNewlinesOptions = BaseOptions<typeof DEFAULT_NJBN_PATTERN_POLICY.filesOnly, typeof DEFAULT_NJBN_PATTERN_POLICY.forceUnique>;
|
|
1370
|
+
/** ----------------------------------------------------------------
|
|
1371
|
+
* * ***Normalizes excessive blank lines in compiled JavaScript files.***
|
|
1372
|
+
* ----------------------------------------------------------------
|
|
1373
|
+
*
|
|
1374
|
+
* This function scans JavaScript build output files and normalizes
|
|
1375
|
+
* excessive consecutive newlines.
|
|
1376
|
+
*
|
|
1377
|
+
* Any occurrence of **three or more consecutive line breaks**
|
|
1378
|
+
* (`\n` or `\r\n`) will be collapsed into exactly **two newlines**,
|
|
1379
|
+
* ensuring cleaner and more readable build artifacts.
|
|
1380
|
+
*
|
|
1381
|
+
* - *The process is **non-destructive**:*
|
|
1382
|
+
* - Files are only rewritten if normalization is actually needed.
|
|
1383
|
+
* - Duplicate file paths are automatically deduplicated using {@link Set | `Set`}.
|
|
1384
|
+
*
|
|
1385
|
+
* - *Supported JavaScript output extensions:*
|
|
1386
|
+
* - `.js`.
|
|
1387
|
+
* - `.cjs`.
|
|
1388
|
+
* - `.mjs`.
|
|
1389
|
+
* - `.esm.js`.
|
|
1390
|
+
* - `.module.js`.
|
|
1391
|
+
*
|
|
1392
|
+
* @param pattern - Glob pattern(s) or a set of file paths pointing to JS build outputs.
|
|
1393
|
+
* @param options - Normalization configuration options.
|
|
1394
|
+
*
|
|
1395
|
+
* @example
|
|
1396
|
+
* ```ts
|
|
1397
|
+
* await normalizeJsBuildNewlines("dist/**\/*.js");
|
|
1398
|
+
* ```
|
|
1399
|
+
*
|
|
1400
|
+
* @example
|
|
1401
|
+
* ```ts
|
|
1402
|
+
* await normalizeJsBuildNewlines("dist/**\/*.{js,cjs,mjs}");
|
|
1403
|
+
* ```
|
|
1404
|
+
*
|
|
1405
|
+
* @example
|
|
1406
|
+
* ```ts
|
|
1407
|
+
* await normalizeJsBuildNewlines(
|
|
1408
|
+
* ["dist/**\/*.js", "build/**\/*.mjs", "out/**\/*.{js,mjs}"],
|
|
1409
|
+
* );
|
|
1410
|
+
* ```
|
|
1411
|
+
*
|
|
1412
|
+
* @remarks
|
|
1413
|
+
* - This utility is intended for **post-build cleanup** and is safe to run
|
|
1414
|
+
* multiple times.
|
|
1415
|
+
* - Re-running it on already normalized files will result
|
|
1416
|
+
* in no changes.
|
|
1417
|
+
*/
|
|
1418
|
+
declare const normalizeJsBuildNewlines: (pattern: StringCollection, options?: NormalizeJsBuildNewlinesOptions) => Promise<void>;
|
|
1419
|
+
/** ----------------------------------------------------------------
|
|
1420
|
+
* * ***Default Pattern Policy for **strip js comments** operations.***
|
|
1421
|
+
* ----------------------------------------------------------------
|
|
1422
|
+
*
|
|
1423
|
+
* Defines the runtime behavior for pattern resolution used by:
|
|
1424
|
+
* - {@link stripJsComments | **`strip-js-comments`**}.
|
|
1425
|
+
*
|
|
1426
|
+
* @remarks
|
|
1427
|
+
* - `filesOnly`: Ensures only files are matched.
|
|
1428
|
+
* - `forceUnique`: Deduplicates matched results.
|
|
1429
|
+
*/
|
|
1430
|
+
declare const DEFAULT_SJC_PATTERN_POLICY: {
|
|
1431
|
+
readonly filesOnly: true;
|
|
1432
|
+
readonly forceUnique: true;
|
|
1433
|
+
};
|
|
1434
|
+
/** ----------------------------------------------------------------
|
|
1435
|
+
* * ***Resolved Pattern Options for **strip js comments** operations.***
|
|
1436
|
+
* ----------------------------------------------------------------
|
|
1437
|
+
*
|
|
1438
|
+
* Pattern options used by:
|
|
1439
|
+
* - {@link stripJsComments | **`strip-js-comments`**}.
|
|
1440
|
+
*/
|
|
1441
|
+
declare const resolvedSjcPatternOption: PatternOptions<true, true>;
|
|
1442
|
+
/** Command identity associated with {@link stripJsComments | **`strip-js-comments`**}. */
|
|
1443
|
+
declare const commandSjcIdentity: CommandIdentity;
|
|
1444
|
+
/** ----------------------------------------------------------------
|
|
1445
|
+
* * ***Configuration options for {@link stripJsComments | `strip-js-comment`}.***
|
|
1446
|
+
* ----------------------------------------------------------------
|
|
1447
|
+
*/
|
|
1448
|
+
type StripJsCommentsOptions = {
|
|
1449
|
+
/** ----------------------------------------------------------------
|
|
1450
|
+
* * ***Whether to remove `sourceMappingURL` comments.***
|
|
1451
|
+
* ----------------------------------------------------------------
|
|
1452
|
+
*
|
|
1453
|
+
* @default false
|
|
1454
|
+
*/
|
|
1455
|
+
removeSourceMap?: boolean;
|
|
1456
|
+
/** ----------------------------------------------------------------
|
|
1457
|
+
* * ***Whether to remove `region` comments.***
|
|
1458
|
+
* ----------------------------------------------------------------
|
|
1459
|
+
*
|
|
1460
|
+
* @default true
|
|
1461
|
+
*/
|
|
1462
|
+
removeRegion?: boolean;
|
|
1463
|
+
/** ----------------------------------------------------------------
|
|
1464
|
+
* * ***Parsing mode used when analyzing JavaScript code.***
|
|
1465
|
+
* ----------------------------------------------------------------
|
|
1466
|
+
*
|
|
1467
|
+
* Determines how the source file should be interpreted by the parser.
|
|
1468
|
+
* This affects strict mode behavior and how `import` / `export`
|
|
1469
|
+
* statements are handled.
|
|
1470
|
+
*
|
|
1471
|
+
*
|
|
1472
|
+
* Possible values:
|
|
1473
|
+
*
|
|
1474
|
+
* - `"module"` **(default)** ➔ Parse as an ES module.
|
|
1475
|
+
* - `"script"` ➔ Parse as a classic script.
|
|
1476
|
+
* - `"commonjs"` ➔ Parse using CommonJS semantics.
|
|
1477
|
+
*
|
|
1478
|
+
* ----------------------------------------------------------------
|
|
1479
|
+
*
|
|
1480
|
+
* ⚠️ Fallback to default, is invalid input.
|
|
1481
|
+
*
|
|
1482
|
+
*
|
|
1483
|
+
* @default "module"
|
|
1484
|
+
*
|
|
1485
|
+
*/
|
|
1486
|
+
sourceType?: acorn.Options["sourceType"];
|
|
1487
|
+
/** ----------------------------------------------------------------
|
|
1488
|
+
* * ***ECMAScript version used for parsing.***
|
|
1489
|
+
* ----------------------------------------------------------------
|
|
1490
|
+
*
|
|
1491
|
+
* Specifies the ECMAScript syntax version supported by the parser.
|
|
1492
|
+
* This determines which language features are recognized during parsing.
|
|
1493
|
+
*
|
|
1494
|
+
* Examples:
|
|
1495
|
+
*
|
|
1496
|
+
* - `5` ➔ ES5
|
|
1497
|
+
* - `2020` ➔ ES2020
|
|
1498
|
+
* - `"latest"` ➔ Latest supported version
|
|
1499
|
+
*
|
|
1500
|
+
* ----------------------------------------------------------------
|
|
1501
|
+
*
|
|
1502
|
+
* ⚠️ Invalid values will fallback to the default behavior.
|
|
1503
|
+
*
|
|
1504
|
+
* @default "latest"
|
|
1505
|
+
*/
|
|
1506
|
+
ecmaVersion?: acorn.ecmaVersion;
|
|
1507
|
+
} & BaseOptions<typeof DEFAULT_SJC_PATTERN_POLICY.filesOnly, typeof DEFAULT_SJC_PATTERN_POLICY.forceUnique>;
|
|
1508
|
+
/** ----------------------------------------------------------------
|
|
1509
|
+
* * ***Strip comments from JavaScript output files.***
|
|
1510
|
+
* ----------------------------------------------------------------
|
|
1511
|
+
*
|
|
1512
|
+
* Scans files matching the provided glob pattern(s) and removes
|
|
1513
|
+
* non-essential comments from JavaScript output.
|
|
1514
|
+
*
|
|
1515
|
+
* The process preserves important comments such as:
|
|
1516
|
+
*
|
|
1517
|
+
* - `/*! ... *\/` (bang / license comments)
|
|
1518
|
+
* - `@license`
|
|
1519
|
+
* - `@preserve`
|
|
1520
|
+
* - `@copyright`
|
|
1521
|
+
* - `@cc_on`
|
|
1522
|
+
* - `@__PURE__`
|
|
1523
|
+
* - `@__INLINE__`
|
|
1524
|
+
* - `@__NOINLINE__`
|
|
1525
|
+
* - `@__NO_SIDE_EFFECTS__`
|
|
1526
|
+
*
|
|
1527
|
+
* unless explicitly overridden by the `@removeDocRuntime` directive.
|
|
1528
|
+
*
|
|
1529
|
+
* ----------------------------------------------------------------
|
|
1530
|
+
*
|
|
1531
|
+
* **Supported Features**
|
|
1532
|
+
*
|
|
1533
|
+
* - Removes regular block comments from compiled JS files.
|
|
1534
|
+
* - Optionally removes `sourceMappingURL` comments.
|
|
1535
|
+
* - Optionally removes `region` comments such as:
|
|
1536
|
+
* - `// #region`
|
|
1537
|
+
* - `// #endregion`
|
|
1538
|
+
* - Supports runtime directives inside comments:
|
|
1539
|
+
* - `@keepDocRuntime`
|
|
1540
|
+
* - `@removeDocRuntime`
|
|
1541
|
+
*
|
|
1542
|
+
* ----------------------------------------------------------------
|
|
1543
|
+
*
|
|
1544
|
+
* @param pattern - Glob pattern(s) or a set of patterns pointing to
|
|
1545
|
+
* files whose comments should be stripped.
|
|
1546
|
+
*
|
|
1547
|
+
* @param options - Optional configuration controlling how comments
|
|
1548
|
+
* are removed.
|
|
1549
|
+
*
|
|
1550
|
+
* ----------------------------------------------------------------
|
|
1551
|
+
*
|
|
1552
|
+
* @example
|
|
1553
|
+
* ```ts
|
|
1554
|
+
* await stripJsComments("dist/**\/*.js");
|
|
1555
|
+
* ```
|
|
1556
|
+
*
|
|
1557
|
+
* @example
|
|
1558
|
+
* ```ts
|
|
1559
|
+
* await stripJsComments(["dist/**\/*.js", "build/**\/*.mjs"], {
|
|
1560
|
+
* removeSourceMap: true,
|
|
1561
|
+
* removeRegion: true
|
|
1562
|
+
* });
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* ----------------------------------------------------------------
|
|
1566
|
+
*
|
|
1567
|
+
* @removeDocRuntime
|
|
1568
|
+
*/
|
|
1569
|
+
declare const stripJsComments: (pattern: StringCollection, options?: StripJsCommentsOptions) => Promise<void>;
|
|
1570
|
+
/** ----------------------------------------------------------------
|
|
1571
|
+
* * ***Base Options for `runCommand` or `runCommandCapture`.***
|
|
1572
|
+
* ----------------------------------------------------------------
|
|
1573
|
+
*/
|
|
1574
|
+
type BaseRunCommandOptions = {
|
|
1575
|
+
/** ----------------------------------------------------------------
|
|
1576
|
+
* * ***Standard input/output configuration for the spawned process.***
|
|
1577
|
+
* ----------------------------------------------------------------
|
|
1578
|
+
* Controls how `stdin`, `stdout`, and `stderr` are handled.
|
|
1579
|
+
*
|
|
1580
|
+
* - *Can be set to:*
|
|
1581
|
+
* - `"pipe"` – create a pipe between parent and child.
|
|
1582
|
+
* - `"inherit"` – inherit the parent process streams.
|
|
1583
|
+
* - `"overlapped"` – use overlapped I/O (Windows only).
|
|
1584
|
+
* - `"ignore"` – discard the stream.
|
|
1585
|
+
*
|
|
1586
|
+
* - *An array form may be used to configure each stream individually:*
|
|
1587
|
+
* - Index `0` ➔ `stdin`.
|
|
1588
|
+
* - Index `1` ➔ `stdout`.
|
|
1589
|
+
* - Index `2` ➔ `stderr`.
|
|
1590
|
+
* - Index `3` ➔ additional custom stream (optional).
|
|
1591
|
+
*
|
|
1592
|
+
* If passed as an array, the first element is used for `stdin`, the second for
|
|
1593
|
+
* `stdout`, and the third for `stderr`.
|
|
1594
|
+
*
|
|
1595
|
+
* A fourth element can be used to
|
|
1596
|
+
* specify the `stdio` behavior beyond the standard streams.
|
|
1597
|
+
*
|
|
1598
|
+
* @See {@link ChildProcess.stdio | **`ChildProcess.stdio`**} for more information.
|
|
1599
|
+
*
|
|
1600
|
+
* @default "inherit"
|
|
1601
|
+
*/
|
|
1602
|
+
stdio?: StdioOptions;
|
|
1603
|
+
/** ----------------------------------------------------------------
|
|
1604
|
+
* * ***Working directory for the spawned process.***
|
|
1605
|
+
* ----------------------------------------------------------------
|
|
1606
|
+
*
|
|
1607
|
+
* Equivalent to `process.cwd()` when not provided.
|
|
1608
|
+
*/
|
|
1609
|
+
cwd?: string | URL;
|
|
1610
|
+
/** ----------------------------------------------------------------
|
|
1611
|
+
* * ***Environment variables passed to the spawned process.***
|
|
1612
|
+
* ----------------------------------------------------------------
|
|
1613
|
+
*
|
|
1614
|
+
* Defaults to `process.env`.
|
|
1615
|
+
*/
|
|
1616
|
+
env?: NodeJS.ProcessEnv;
|
|
1617
|
+
/** ----------------------------------------------------------------
|
|
1618
|
+
* * ***Disable execution inside a system shell.***
|
|
1619
|
+
* ----------------------------------------------------------------
|
|
1620
|
+
*
|
|
1621
|
+
* By default, commands are executed inside a system shell:
|
|
1622
|
+
* - `sh` on Unix-based systems.
|
|
1623
|
+
* - `cmd.exe` on Windows.
|
|
1624
|
+
*
|
|
1625
|
+
* Set this option to `false` to bypass the shell and execute
|
|
1626
|
+
* the command directly.
|
|
1627
|
+
*
|
|
1628
|
+
* This is useful for:
|
|
1629
|
+
* - Strict argument handling.
|
|
1630
|
+
* - Avoiding shell interpretation.
|
|
1631
|
+
*
|
|
1632
|
+
* @default true (shell is enabled)
|
|
1633
|
+
*/
|
|
1634
|
+
shell?: false;
|
|
1635
|
+
/** ----------------------------------------------------------------
|
|
1636
|
+
* * ***Abort signal for cancelling the spawned process.***
|
|
1637
|
+
* ----------------------------------------------------------------
|
|
1638
|
+
*
|
|
1639
|
+
* When the signal is aborted:
|
|
1640
|
+
* - The child process will be terminated using `SIGTERM`.
|
|
1641
|
+
* - The returned promise will be rejected with an abort error.
|
|
1642
|
+
*
|
|
1643
|
+
* If the signal is already aborted before execution,
|
|
1644
|
+
* the command will not be started.
|
|
1645
|
+
*
|
|
1646
|
+
* @default undefined
|
|
1647
|
+
*
|
|
1648
|
+
* @example
|
|
1649
|
+
* ```ts
|
|
1650
|
+
* const controller = new AbortController();
|
|
1651
|
+
* runCommand("pnpm", ["dev"], { signal: controller.signal });
|
|
1652
|
+
* controller.abort();
|
|
1653
|
+
* ```
|
|
1654
|
+
*/
|
|
1655
|
+
signal?: AbortSignal;
|
|
1656
|
+
/** ----------------------------------------------------------------
|
|
1657
|
+
* * ***Maximum execution time before forcefully terminating the process.***
|
|
1658
|
+
* ----------------------------------------------------------------
|
|
1659
|
+
*
|
|
1660
|
+
* When the timeout is reached:
|
|
1661
|
+
* - The child process will be terminated using `SIGTERM`.
|
|
1662
|
+
* - The returned promise will be rejected with a timeout error.
|
|
1663
|
+
*
|
|
1664
|
+
* This is useful for preventing hanging processes
|
|
1665
|
+
* or enforcing execution limits in automation scripts.
|
|
1666
|
+
*
|
|
1667
|
+
* @default undefined (no timeout)
|
|
1668
|
+
*
|
|
1669
|
+
* @note ⚠️ Setting to `0` will cause immediate termination.
|
|
1670
|
+
*/
|
|
1671
|
+
timeout?: number;
|
|
1672
|
+
/** ----------------------------------------------------------------
|
|
1673
|
+
* * ***Forcefully terminate the spawned process (Windows only).***
|
|
1674
|
+
* ----------------------------------------------------------------
|
|
1675
|
+
*
|
|
1676
|
+
* When enabled, the process will be terminated using:
|
|
1677
|
+
* - `taskkill /f /t` on Windows (kills the entire process tree).
|
|
1678
|
+
*
|
|
1679
|
+
* This ensures that all child processes are also terminated,
|
|
1680
|
+
* preventing orphaned or zombie processes.
|
|
1681
|
+
*
|
|
1682
|
+
* - This option is useful for:
|
|
1683
|
+
* - Long-running processes.
|
|
1684
|
+
* - Dev servers or watchers.
|
|
1685
|
+
* - Ensuring clean shutdown in CI environments.
|
|
1686
|
+
*
|
|
1687
|
+
* @default false
|
|
1688
|
+
*/
|
|
1689
|
+
forceKill?: boolean;
|
|
1690
|
+
/** ----------------------------------------------------------------
|
|
1691
|
+
* * ***Enable colored output for logs and error messages.***
|
|
1692
|
+
* ----------------------------------------------------------------
|
|
1693
|
+
*
|
|
1694
|
+
* When enabled:
|
|
1695
|
+
* - Commands will be formatted with colors.
|
|
1696
|
+
* - Error messages will include highlighted command strings.
|
|
1697
|
+
*
|
|
1698
|
+
* This is useful for:
|
|
1699
|
+
* - CLI tools.
|
|
1700
|
+
* - Developer-friendly logs.
|
|
1701
|
+
*
|
|
1702
|
+
* @default true
|
|
1703
|
+
*/
|
|
1704
|
+
useColors?: boolean;
|
|
1705
|
+
} & Omit<SpawnOptions, "cwd" | "env" | "shell" | "stdio" | "argv0" | "timeout">;
|
|
1706
|
+
/** ----------------------------------------------------------------
|
|
1707
|
+
* * ***Represents a command execution failure.***
|
|
1708
|
+
* ----------------------------------------------------------------
|
|
1709
|
+
*
|
|
1710
|
+
* This error is thrown when a spawned process fails during execution
|
|
1711
|
+
* via {@link runCommand | **`runCommand`**}, {@link runCommandCapture | **`runCommandCapture`**} or related utilities.
|
|
1712
|
+
*
|
|
1713
|
+
* It extends the native {@link Error | `Error`} class and provides structured
|
|
1714
|
+
* metadata describing the failure.
|
|
1715
|
+
*
|
|
1716
|
+
* ---
|
|
1717
|
+
*
|
|
1718
|
+
* - *Failure reasons:*
|
|
1719
|
+
* - `"timeout"` ➔ The process exceeded the configured timeout.
|
|
1720
|
+
* - `"abort"` ➔ The process was aborted via an `AbortSignal`.
|
|
1721
|
+
* - `"signal"` ➔ The process was terminated by an OS signal.
|
|
1722
|
+
* - `"non-zero exit code"` ➔ The process exited with a non-zero code.
|
|
1723
|
+
*
|
|
1724
|
+
* ---
|
|
1725
|
+
*
|
|
1726
|
+
* - *Metadata:*
|
|
1727
|
+
* - `reason` ➔ Reason for failure.
|
|
1728
|
+
* - `exitCode` ➔ Exit code (if available).
|
|
1729
|
+
* - `signal` ➔ Termination signal (if any).
|
|
1730
|
+
* - `command` ➔ Executed command (plain string, no colors).
|
|
1731
|
+
*
|
|
1732
|
+
* ---
|
|
1733
|
+
*
|
|
1734
|
+
* - *Behavior:*
|
|
1735
|
+
* - Thrown when a process fails in {@link runCommand | `runCommand`}.
|
|
1736
|
+
* - May also be thrown in {@link runCommandCapture | `runCommandCapture`} for:
|
|
1737
|
+
* - Spawn errors.
|
|
1738
|
+
* - Abort signals.
|
|
1739
|
+
* - Timeouts.
|
|
1740
|
+
* - Signal termination.
|
|
1741
|
+
* - Includes formatted stack output for CLI readability.
|
|
1742
|
+
* - Metadata is available for programmatic handling.
|
|
1743
|
+
*
|
|
1744
|
+
* ----------------------------------------------------------------
|
|
1745
|
+
* @example
|
|
1746
|
+
* ```ts
|
|
1747
|
+
* try {
|
|
1748
|
+
* await runCommand("pnpm", ["build"]);
|
|
1749
|
+
* } catch (err) {
|
|
1750
|
+
* if (err instanceof CommandProcessError) {
|
|
1751
|
+
* console.error("Reason:", err.reason);
|
|
1752
|
+
* console.error("Exit code:", err.exitCode);
|
|
1753
|
+
* }
|
|
1754
|
+
* }
|
|
1755
|
+
* ```
|
|
1756
|
+
*
|
|
1757
|
+
* OR with `isCommandProcessError`.
|
|
1758
|
+
*
|
|
1759
|
+
* @example
|
|
1760
|
+
* ```ts
|
|
1761
|
+
* try {
|
|
1762
|
+
* await runCommand("pnpm", ["build"]);
|
|
1763
|
+
* } catch (err) {
|
|
1764
|
+
* if (isCommandProcessError(err)) {
|
|
1765
|
+
* console.error("Reason:", err.reason);
|
|
1766
|
+
* console.error("Exit code:", err.exitCode);
|
|
1767
|
+
* }
|
|
1768
|
+
* }
|
|
1769
|
+
* ```
|
|
1770
|
+
*
|
|
1771
|
+
* @remarks
|
|
1772
|
+
* - This error is designed for both:
|
|
1773
|
+
* - Human-readable CLI output.
|
|
1774
|
+
* - Programmatic error handling.
|
|
1775
|
+
*
|
|
1776
|
+
* - Metadata properties are non-enumerable to avoid duplicate
|
|
1777
|
+
* output when logged via `console.error`.
|
|
1778
|
+
*/
|
|
1779
|
+
declare class CommandProcessError extends Error {
|
|
1780
|
+
reason: "timeout" | "abort" | "signal" | "non-zero exit code";
|
|
1781
|
+
exitCode?: number;
|
|
1782
|
+
signal?: NodeJS.Signals | null;
|
|
1783
|
+
command: string;
|
|
1784
|
+
constructor(message: string, meta: {
|
|
1785
|
+
reason: CommandProcessError["reason"];
|
|
1786
|
+
exitCode?: number;
|
|
1787
|
+
signal?: NodeJS.Signals | null;
|
|
1788
|
+
command: string;
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
/** ----------------------------------------------------------------
|
|
1792
|
+
* * ***Type guard for `CommandProcessError`.***
|
|
1793
|
+
* ----------------------------------------------------------------
|
|
1794
|
+
*
|
|
1795
|
+
* Utility to check whether a given value is an instance of
|
|
1796
|
+
* {@link CommandProcessError | `CommandProcessError`}.
|
|
1797
|
+
*
|
|
1798
|
+
* Useful when handling unknown errors in `try/catch` blocks.
|
|
1799
|
+
*
|
|
1800
|
+
* ----------------------------------------------------------------
|
|
1801
|
+
* @param err
|
|
1802
|
+
* The unknown error value to check.
|
|
1803
|
+
*
|
|
1804
|
+
* @returns
|
|
1805
|
+
* `true` if the value is a `CommandProcessError`, otherwise `false`.
|
|
1806
|
+
*
|
|
1807
|
+
* ----------------------------------------------------------------
|
|
1808
|
+
* @example
|
|
1809
|
+
* ```ts
|
|
1810
|
+
* try {
|
|
1811
|
+
* await runCommand("pnpm", ["build"]);
|
|
1812
|
+
* } catch (err) {
|
|
1813
|
+
* if (isCommandProcessError(err)) {
|
|
1814
|
+
* console.error(err.reason);
|
|
1815
|
+
* console.error(err.exitCode);
|
|
1816
|
+
* }
|
|
1817
|
+
* }
|
|
1818
|
+
* ```
|
|
1819
|
+
*/
|
|
1820
|
+
declare function isCommandProcessError(err: unknown): err is CommandProcessError;
|
|
1821
|
+
/** ----------------------------------------------------------------
|
|
1822
|
+
* * ***Result returned by {@link runCommandCapture | `runCommandCapture`}.***
|
|
1823
|
+
* ----------------------------------------------------------------
|
|
1824
|
+
*
|
|
1825
|
+
* Represents the captured output and execution status of a command.
|
|
1826
|
+
*
|
|
1827
|
+
* - *Behavior:*
|
|
1828
|
+
* - `stdout` and `stderr` are fully buffered as UTF-8 strings.
|
|
1829
|
+
* - `exitCode` reflects the process exit status.
|
|
1830
|
+
* - `ok` indicates whether the command succeeded (`exitCode === 0`).
|
|
1831
|
+
*/
|
|
1832
|
+
type RunCommandCaptureResult = {
|
|
1833
|
+
/** ----------------------------------------------------------------
|
|
1834
|
+
* * ***Captured standard output.***
|
|
1835
|
+
* ----------------------------------------------------------------
|
|
1836
|
+
*
|
|
1837
|
+
* The complete `stdout` output of the process as a UTF-8 string.
|
|
1838
|
+
*
|
|
1839
|
+
* - Trailing newlines may be trimmed depending on implementation.
|
|
1840
|
+
*/
|
|
1841
|
+
stdout: string;
|
|
1842
|
+
/** ----------------------------------------------------------------
|
|
1843
|
+
* * ***Captured standard error output.***
|
|
1844
|
+
* ----------------------------------------------------------------
|
|
1845
|
+
*
|
|
1846
|
+
* The complete `stderr` output of the process as a UTF-8 string.
|
|
1847
|
+
*
|
|
1848
|
+
* - Useful for debugging or logging failures.
|
|
1849
|
+
*/
|
|
1850
|
+
stderr: string;
|
|
1851
|
+
/** ----------------------------------------------------------------
|
|
1852
|
+
* * ***Process exit code.***
|
|
1853
|
+
* ----------------------------------------------------------------
|
|
1854
|
+
*
|
|
1855
|
+
* The numeric exit code returned by the process.
|
|
1856
|
+
*
|
|
1857
|
+
* - `0` usually indicates success.
|
|
1858
|
+
* - Non-zero values usually indicate failure.
|
|
1859
|
+
*/
|
|
1860
|
+
exitCode: number;
|
|
1861
|
+
/** ----------------------------------------------------------------
|
|
1862
|
+
* * ***Execution success flag.***
|
|
1863
|
+
* ----------------------------------------------------------------
|
|
1864
|
+
*
|
|
1865
|
+
* Indicates whether the command completed successfully.
|
|
1866
|
+
*
|
|
1867
|
+
* Equivalent to:
|
|
1868
|
+
* ```ts
|
|
1869
|
+
* exitCode === 0
|
|
1870
|
+
* ```
|
|
1871
|
+
*/
|
|
1872
|
+
ok: boolean;
|
|
1873
|
+
};
|
|
1874
|
+
/** ----------------------------------------------------------------
|
|
1875
|
+
* * ***Options for executing a shell command via {@link runCommandCapture | **`runCommandCapture`**}.***
|
|
1876
|
+
* ----------------------------------------------------------------
|
|
1877
|
+
*/
|
|
1878
|
+
type RunCommandCaptureOptions = Omit<BaseRunCommandOptions, "stdio">;
|
|
1879
|
+
/** ----------------------------------------------------------------
|
|
1880
|
+
* * ***Execute a command and capture its output.***
|
|
1881
|
+
* ----------------------------------------------------------------
|
|
1882
|
+
*
|
|
1883
|
+
* This utility spawns a child process using
|
|
1884
|
+
* {@link spawn | **`child_process.spawn`**} and buffers its output.
|
|
1885
|
+
*
|
|
1886
|
+
* Unlike {@link runCommand | **`runCommand`**}, this function:
|
|
1887
|
+
* - Captures `stdout` and `stderr` into strings.
|
|
1888
|
+
* - Does **not** stream output to the parent process.
|
|
1889
|
+
* - Always resolves (even for non-zero exit codes).
|
|
1890
|
+
*
|
|
1891
|
+
* - *Behavior:*
|
|
1892
|
+
* - Uses `stdio: "pipe"` (output is buffered).
|
|
1893
|
+
* - Collects `stdout` and `stderr` as UTF-8 strings.
|
|
1894
|
+
* - Resolves when the process exits (regardless of exit code).
|
|
1895
|
+
* - Rejects only on:
|
|
1896
|
+
* - Spawn errors.
|
|
1897
|
+
* - Abort signals.
|
|
1898
|
+
* - Timeouts.
|
|
1899
|
+
* - Process termination by signal.
|
|
1900
|
+
*
|
|
1901
|
+
* - *This function is designed for:*
|
|
1902
|
+
* - Capturing CLI output.
|
|
1903
|
+
* - Running commands programmatically.
|
|
1904
|
+
* - Parsing results (JSON, text, etc.).
|
|
1905
|
+
* - Testing and scripting utilities.
|
|
1906
|
+
*
|
|
1907
|
+
* @param {string} command
|
|
1908
|
+
* The executable or command to run.
|
|
1909
|
+
*
|
|
1910
|
+
* @param {readonly string[]} [args]
|
|
1911
|
+
* Arguments passed to the command.
|
|
1912
|
+
*
|
|
1913
|
+
* @param {RunCommandCaptureOptions} [options]
|
|
1914
|
+
* Optional execution configuration.
|
|
1915
|
+
*
|
|
1916
|
+
* @returns {Promise<RunCommandCaptureResult>}
|
|
1917
|
+
* Resolves with an object containing:
|
|
1918
|
+
* - `stdout` ➔ captured standard output.
|
|
1919
|
+
* - `stderr` ➔ captured standard error.
|
|
1920
|
+
* - `exitCode` ➔ process exit code.
|
|
1921
|
+
* - `ok` ➔ `true` if exit code is `0`.
|
|
1922
|
+
*
|
|
1923
|
+
* ----------------------------------------------------------------
|
|
1924
|
+
* #### Error handling.
|
|
1925
|
+
*
|
|
1926
|
+
* This function does NOT reject on non-zero exit codes.
|
|
1927
|
+
* - Instead, use:
|
|
1928
|
+
* - `result.ok`.
|
|
1929
|
+
* - `result.exitCode`.
|
|
1930
|
+
*
|
|
1931
|
+
* - However, the promise WILL reject for:
|
|
1932
|
+
* - spawn errors.
|
|
1933
|
+
* - abort signals.
|
|
1934
|
+
* - timeouts.
|
|
1935
|
+
* - termination by signal.
|
|
1936
|
+
*
|
|
1937
|
+
* In those cases, the promise is rejected with a
|
|
1938
|
+
* {@link CommandProcessError | **`CommandProcessError`**}.
|
|
1939
|
+
*
|
|
1940
|
+
* - *Error metadata:*
|
|
1941
|
+
* - `reason` ➔ `"timeout" | "abort" | "signal" | "non-zero exit code"`.
|
|
1942
|
+
* - `exitCode` ➔ Exit code (if available).
|
|
1943
|
+
* - `signal` ➔ Termination signal (if any).
|
|
1944
|
+
* - `command` ➔ Executed command (plain string, no colors).
|
|
1945
|
+
*
|
|
1946
|
+
* - *Type narrowing:*
|
|
1947
|
+
* - Use `instanceof CommandProcessError` to safely access metadata.
|
|
1948
|
+
* - Or use {@link isCommandProcessError | **`isCommandProcessError`**} as a type guard.
|
|
1949
|
+
*
|
|
1950
|
+
* - *Notes:*
|
|
1951
|
+
* - `"non-zero exit code"` is NOT treated as an error in this function.
|
|
1952
|
+
* - Metadata is available programmatically (e.g. `err.reason`).
|
|
1953
|
+
* - Metadata is also included in the formatted stack output
|
|
1954
|
+
* for CLI readability.
|
|
1955
|
+
*
|
|
1956
|
+
* @example
|
|
1957
|
+
* ```ts
|
|
1958
|
+
* try {
|
|
1959
|
+
* await runCommandCapture("pnpm", ["build"]);
|
|
1960
|
+
* } catch (err) {
|
|
1961
|
+
* if (err instanceof CommandProcessError) {
|
|
1962
|
+
* console.error("Command failed:", err.reason);
|
|
1963
|
+
* }
|
|
1964
|
+
* }
|
|
1965
|
+
* ```
|
|
1966
|
+
*
|
|
1967
|
+
* @example
|
|
1968
|
+
* ```ts
|
|
1969
|
+
* try {
|
|
1970
|
+
* await runCommandCapture("pnpm", ["dev"]);
|
|
1971
|
+
* } catch (err) {
|
|
1972
|
+
* if (isCommandProcessError(err)) {
|
|
1973
|
+
* console.error(err.reason);
|
|
1974
|
+
* }
|
|
1975
|
+
* }
|
|
1976
|
+
* ```
|
|
1977
|
+
* ----------------------------------------------------------------
|
|
1978
|
+
* @example
|
|
1979
|
+
* ```ts
|
|
1980
|
+
* const result = await runCommandCapture("node", ["--version"]);
|
|
1981
|
+
*
|
|
1982
|
+
* console.log(result.stdout);
|
|
1983
|
+
* ```
|
|
1984
|
+
*
|
|
1985
|
+
* @example
|
|
1986
|
+
* ```ts
|
|
1987
|
+
* const { stdout, ok } = await runCommandCapture("pnpm", ["build"]);
|
|
1988
|
+
*
|
|
1989
|
+
* if (!ok) {
|
|
1990
|
+
* console.error("Build failed");
|
|
1991
|
+
* }
|
|
1992
|
+
* ```
|
|
1993
|
+
*
|
|
1994
|
+
* @example
|
|
1995
|
+
* ```ts
|
|
1996
|
+
* const controller = new AbortController();
|
|
1997
|
+
*
|
|
1998
|
+
* runCommandCapture("pnpm", ["dev"], {
|
|
1999
|
+
* signal: controller.signal
|
|
2000
|
+
* });
|
|
2001
|
+
*
|
|
2002
|
+
* controller.abort();
|
|
2003
|
+
* ```
|
|
2004
|
+
*
|
|
2005
|
+
* @remarks
|
|
2006
|
+
* - **Execution model:**
|
|
2007
|
+
* - Uses {@link spawn | **`spawn`**} to avoid output size limits
|
|
2008
|
+
* imposed by `exec`.
|
|
2009
|
+
*
|
|
2010
|
+
* - **Output handling:**
|
|
2011
|
+
* - Always uses `stdio: "pipe"` (cannot be overridden).
|
|
2012
|
+
* - Output is buffered entirely in memory.
|
|
2013
|
+
*
|
|
2014
|
+
* - **Exit behavior:**
|
|
2015
|
+
* - Does NOT reject on non-zero exit codes.
|
|
2016
|
+
* - Use `result.ok` or `result.exitCode` to handle failures.
|
|
2017
|
+
*
|
|
2018
|
+
* - **Shell execution:**
|
|
2019
|
+
* - Defaults to `shell: true`.
|
|
2020
|
+
* - Same behavior and constraints as {@link runCommand | `runCommand`}.
|
|
2021
|
+
*
|
|
2022
|
+
* - **Abort & timeout:**
|
|
2023
|
+
* - Abort signals and timeouts will terminate the process
|
|
2024
|
+
* and reject the promise.
|
|
2025
|
+
*
|
|
2026
|
+
* - **When NOT to use this utility:**
|
|
2027
|
+
* - When output needs to be streamed in real-time
|
|
2028
|
+
* - When handling very large outputs (risk of high memory usage)
|
|
2029
|
+
*
|
|
2030
|
+
* ***In those cases, use {@link runCommand | `runCommand`}.***
|
|
2031
|
+
*/
|
|
2032
|
+
declare function runCommandCapture(command: string, args: readonly string[]): Promise<RunCommandCaptureResult>;
|
|
2033
|
+
declare function runCommandCapture(command: string, options: RunCommandCaptureOptions): Promise<RunCommandCaptureResult>;
|
|
2034
|
+
declare function runCommandCapture(command: string, args: readonly string[], options: RunCommandCaptureOptions): Promise<RunCommandCaptureResult>;
|
|
2035
|
+
/** ----------------------------------------------------------------
|
|
2036
|
+
* * ***Options for executing a shell command via {@link runCommand | **`runCommand`**}.***
|
|
2037
|
+
* ----------------------------------------------------------------
|
|
2038
|
+
*/
|
|
2039
|
+
type RunCommandOptions = BaseRunCommandOptions;
|
|
2040
|
+
/** ----------------------------------------------------------------
|
|
2041
|
+
* * ***Execute a command and stream output to the current process.***
|
|
2042
|
+
* ----------------------------------------------------------------
|
|
2043
|
+
*
|
|
2044
|
+
* This utility spawns a child process using
|
|
2045
|
+
* {@link spawn | **`child_process.spawn`**}.
|
|
2046
|
+
*
|
|
2047
|
+
* By default, it forwards `stdout` and `stderr` directly to the parent
|
|
2048
|
+
* process using `stdio: "inherit"` (real-time streaming, no buffering).
|
|
2049
|
+
*
|
|
2050
|
+
* - *Behavior:*
|
|
2051
|
+
* - Uses `stdio: "inherit"` by default (can be overridden).
|
|
2052
|
+
* - Does **not** buffer output.
|
|
2053
|
+
* - Resolves only when the process exits with code `0`.
|
|
2054
|
+
* - Rejects if the process exits with a non-zero code,
|
|
2055
|
+
* is terminated by a signal, aborted, or times out.
|
|
2056
|
+
*
|
|
2057
|
+
* - *This function is designed for:*
|
|
2058
|
+
* - Build steps.
|
|
2059
|
+
* - Post-build hooks.
|
|
2060
|
+
* - CLI tooling.
|
|
2061
|
+
* - Long-running tasks (bundlers, compilers, CSS processors).
|
|
2062
|
+
*
|
|
2063
|
+
* @param {string} command
|
|
2064
|
+
* The executable or command to run.
|
|
2065
|
+
*
|
|
2066
|
+
* @param {readonly string[]} [args]
|
|
2067
|
+
* Arguments passed to the command.
|
|
2068
|
+
*
|
|
2069
|
+
* @param {RunCommandOptions} [options]
|
|
2070
|
+
* Optional execution configuration.
|
|
2071
|
+
*
|
|
2072
|
+
* @returns {Promise<ChildProcess>}
|
|
2073
|
+
* Resolves with the spawned {@link ChildProcess | **`ChildProcess`**} instance
|
|
2074
|
+
* **after the process exits successfully (exit code `0`)**.
|
|
2075
|
+
*
|
|
2076
|
+
* ----------------------------------------------------------------
|
|
2077
|
+
* #### Error handling
|
|
2078
|
+
*
|
|
2079
|
+
* When the process fails, the promise is rejected with a
|
|
2080
|
+
* {@link CommandProcessError | **`CommandProcessError`**}.
|
|
2081
|
+
*
|
|
2082
|
+
* - *Error metadata:*
|
|
2083
|
+
* - `reason` ➔ `"timeout" | "abort" | "signal" | "non-zero exit code"`.
|
|
2084
|
+
* - `exitCode` ➔ Exit code (if available).
|
|
2085
|
+
* - `signal` ➔ Termination signal (if any).
|
|
2086
|
+
* - `command` ➔ Executed command (plain string, no colors).
|
|
2087
|
+
*
|
|
2088
|
+
* - *Type narrowing:*
|
|
2089
|
+
* - Use `instanceof CommandProcessError` to safely access metadata.
|
|
2090
|
+
* - Or use {@link isCommandProcessError | **`isCommandProcessError`**} as a type guard.
|
|
2091
|
+
*
|
|
2092
|
+
* - *Notes:*
|
|
2093
|
+
* - Metadata is available programmatically (e.g. `err.reason`).
|
|
2094
|
+
* - Metadata is also included in the formatted stack output
|
|
2095
|
+
* for CLI readability.
|
|
2096
|
+
*
|
|
2097
|
+
* @example
|
|
2098
|
+
* ```ts
|
|
2099
|
+
* try {
|
|
2100
|
+
* await runCommand("pnpm", ["build"]);
|
|
2101
|
+
* } catch (err) {
|
|
2102
|
+
* if (err instanceof CommandProcessError) {
|
|
2103
|
+
* if (err.reason === "non-zero exit code") {
|
|
2104
|
+
* console.error("Build failed with code:", err.exitCode);
|
|
2105
|
+
* }
|
|
2106
|
+
* }
|
|
2107
|
+
* }
|
|
2108
|
+
* ```
|
|
2109
|
+
*
|
|
2110
|
+
* @example
|
|
2111
|
+
* ```ts
|
|
2112
|
+
* try {
|
|
2113
|
+
* await runCommand("pnpm", ["build"]);
|
|
2114
|
+
* } catch (err) {
|
|
2115
|
+
* if (isCommandProcessError(err)) {
|
|
2116
|
+
* console.error(err.reason);
|
|
2117
|
+
* }
|
|
2118
|
+
* }
|
|
2119
|
+
* ```
|
|
2120
|
+
* ----------------------------------------------------------------
|
|
2121
|
+
*
|
|
2122
|
+
* @example
|
|
2123
|
+
* ```ts
|
|
2124
|
+
* await runCommand("pnpm", ["build"]);
|
|
2125
|
+
* ```
|
|
2126
|
+
*
|
|
2127
|
+
* @example
|
|
2128
|
+
* ```ts
|
|
2129
|
+
* const child = await runCommand("node", ["script.js"]);
|
|
2130
|
+
* console.log(child.pid);
|
|
2131
|
+
* ```
|
|
2132
|
+
*
|
|
2133
|
+
* @example
|
|
2134
|
+
* ```ts
|
|
2135
|
+
* const controller = new AbortController();
|
|
2136
|
+
*
|
|
2137
|
+
* runCommand("pnpm", ["dev"], {
|
|
2138
|
+
* signal: controller.signal
|
|
2139
|
+
* });
|
|
2140
|
+
*
|
|
2141
|
+
* controller.abort();
|
|
2142
|
+
* ```
|
|
2143
|
+
*
|
|
2144
|
+
* @example
|
|
2145
|
+
* ```ts
|
|
2146
|
+
* await runCommand("npm", ["run", "build"], {
|
|
2147
|
+
* timeout: 5000
|
|
2148
|
+
* });
|
|
2149
|
+
* ```
|
|
2150
|
+
*
|
|
2151
|
+
* @remarks
|
|
2152
|
+
* - **Execution model:**
|
|
2153
|
+
* - Uses {@link spawn | **`spawn`**} instead of `exec` to avoid
|
|
2154
|
+
* output buffering and support long-running processes.
|
|
2155
|
+
*
|
|
2156
|
+
* - **Output handling:**
|
|
2157
|
+
* - Defaults to `stdio: "inherit"` (streams output to parent).
|
|
2158
|
+
* - If `stdio` is overridden (e.g. `"pipe"`), output will NOT be auto-forwarded.
|
|
2159
|
+
*
|
|
2160
|
+
* - **Shell execution:**
|
|
2161
|
+
* - Defaults to {@link RunCommandOptions.shell | **`shell: true`**}.
|
|
2162
|
+
* - Required on Windows to resolve commands like `pnpm`, `npm`, `git`, etc.
|
|
2163
|
+
* - When `shell: false`, the command must be:
|
|
2164
|
+
* - An absolute path, or
|
|
2165
|
+
* - A directly executable binary.
|
|
2166
|
+
*
|
|
2167
|
+
* - **Abort handling:**
|
|
2168
|
+
* - When `signal` is provided, the process will be terminated
|
|
2169
|
+
* with `SIGTERM` if aborted.
|
|
2170
|
+
*
|
|
2171
|
+
* - **Timeout handling:**
|
|
2172
|
+
* - When `timeout` is set, the process will be terminated
|
|
2173
|
+
* after the specified duration.
|
|
2174
|
+
* - `undefined` ➔ no timeout.
|
|
2175
|
+
* - ⚠️ `0` ➔ immediate termination.
|
|
2176
|
+
*
|
|
2177
|
+
* - **Common errors:**
|
|
2178
|
+
* - **`ENOENT`** ➔ command not found:
|
|
2179
|
+
* - Not installed
|
|
2180
|
+
* - Not in `PATH`
|
|
2181
|
+
* - `shell: false` with non-absolute command
|
|
2182
|
+
*
|
|
2183
|
+
* - **When NOT to use this utility:**
|
|
2184
|
+
* - When you need to capture output programmatically.
|
|
2185
|
+
* - When you need advanced shell features (`|`, `>`, `&&`).
|
|
2186
|
+
*
|
|
2187
|
+
* ***In those cases, consider using `exec` or a dedicated process runner.***
|
|
2188
|
+
*/
|
|
2189
|
+
declare function runCommand(command: string, args: readonly string[]): Promise<ChildProcess>;
|
|
2190
|
+
declare function runCommand(command: string, options: RunCommandOptions): Promise<ChildProcess>;
|
|
2191
|
+
declare function runCommand(command: string, args: readonly string[], options: RunCommandOptions): Promise<ChildProcess>;
|
|
2192
|
+
export { type BaseOptions, type CleanJsArtifactsOptions, type CleanTypesArtifactsOptions, type Collection, CommandProcessError, type CopyFileToDestOptions, type CopyFileToDestParam, DEFAULT_CLEAN_PATTERN_POLICY, DEFAULT_ECI_PATTERN_POLICY, DEFAULT_EFN_PATTERN_POLICY, DEFAULT_GRI_PATTERN_POLICY, DEFAULT_IB_PATTERN_POLICY, DEFAULT_ID_PATTERN_POLICY, DEFAULT_NJBN_PATTERN_POLICY, DEFAULT_SJC_PATTERN_POLICY, type EnsureCssImportOptions, type EnsureFinalNewlineOptions, type GeneratePackageBannerOptions, type GenerateReferenceOptions, type GetPackageJsonOptions, type InjectBannerOptions, type InjectDirectiveOptions, type InternalOptions, type LogLevel, type LoggingOptions, type NormalizeJsBuildNewlinesOptions, type PatternConfig, type PatternOptions, type RunCommandCaptureOptions, type RunCommandCaptureResult, type RunCommandOptions, type StringCollection, type StripJsCommentsOptions, cleanJsBuildArtifacts, cleanTypesBuildArtifacts, commandCftdIdentity, commandCjbaIdentity, commandCtbaIdentity, commandEciIdentity, commandEfnIdentity, commandGriIdentity, commandIbIdentity, commandIdIdentity, commandNjbnIdentity, commandSjcIdentity, copyFileToDest, createCopyFileToDestParameterSet, ensureCssImport, ensureFinalNewline, generatePackageBanner, generateReferenceIndex, getPackageJson, injectBanner, injectDirective, isCommandProcessError, normalizeJsBuildNewlines, resolvedCleanPatternOption, resolvedEciPatternOption, resolvedEfnPatternOption, resolvedGriPatternOption, resolvedIbPatternOption, resolvedIdPatternOption, resolvedNjbnPatternOption, resolvedSjcPatternOption, runCommand, runCommandCapture, stripJsComments };
|
|
2193
|
+
//# sourceMappingURL=index.d.cts.map
|