@buildplease/core 1.0.0
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/src/index.cjs +1 -0
- package/dist/src/index.d.cts +2296 -0
- package/dist/src/index.d.ts +2296 -0
- package/dist/src/index.js +1 -0
- package/dist/src-node/index.cjs +2 -0
- package/dist/src-node/index.d.cts +454 -0
- package/dist/src-node/index.d.mts +454 -0
- package/dist/src-node/index.mjs +2 -0
- package/dist/src-node-test/index.cjs +2 -0
- package/dist/src-node-test/index.d.cts +99 -0
- package/dist/src-node-test/index.d.mts +99 -0
- package/dist/src-node-test/index.mjs +2 -0
- package/package.json +77 -0
- package/resources/index.ts +1 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { Container } from "inversify";
|
|
2
|
+
import { Bindings, Level, Logger as Logger$1 } from "pino";
|
|
3
|
+
import z from "zod";
|
|
4
|
+
import { PrettyOptions } from "pino-pretty";
|
|
5
|
+
//#region src-node/bundling/dependency-bundling-policy.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A module matcher used by dependency bundling policies.
|
|
8
|
+
*
|
|
9
|
+
* Matchers are intentionally generic so the produced policy can be mapped to
|
|
10
|
+
* different bundlers without coupling this API to one build tool.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* 'zod'
|
|
15
|
+
* /^zod(?:\/.*)?$/
|
|
16
|
+
* /^@buildplease\/core(?:\/.*)?$/
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type DependencyBundlingMatcher = string | RegExp;
|
|
20
|
+
/**
|
|
21
|
+
* Minimal package manifest shape required to create a dependency bundling policy.
|
|
22
|
+
*
|
|
23
|
+
* The helper intentionally depends only on standard package manifest dependency
|
|
24
|
+
* fields, not on a framework-specific package model.
|
|
25
|
+
*/
|
|
26
|
+
type DependencyBundlingPackageJSON = {
|
|
27
|
+
/**
|
|
28
|
+
* Runtime dependencies declared by the package.
|
|
29
|
+
*/
|
|
30
|
+
dependencies?: Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Peer dependencies owned by the consuming application/package.
|
|
33
|
+
*/
|
|
34
|
+
peerDependencies?: Record<string, string>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Describes how package dependencies should be handled by a bundler.
|
|
38
|
+
*
|
|
39
|
+
* This type is bundler-agnostic. Concrete build tools should map it to their
|
|
40
|
+
* own configuration shape.
|
|
41
|
+
*
|
|
42
|
+
* @example tsdown
|
|
43
|
+
* ```ts
|
|
44
|
+
* deps: {
|
|
45
|
+
* neverBundle: policy.external,
|
|
46
|
+
* alwaysBundle: policy.bundle,
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example Generic module bundler
|
|
51
|
+
* ```ts
|
|
52
|
+
* external: policy.external
|
|
53
|
+
* noExternal: policy.bundle
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
type DependencyBundlingPolicy = {
|
|
57
|
+
/**
|
|
58
|
+
* Dependencies or module ids that must stay external.
|
|
59
|
+
*
|
|
60
|
+
* External dependencies are not bundled into the generated output. The emitted
|
|
61
|
+
* file keeps them as runtime imports/requires, so the consuming application or
|
|
62
|
+
* package manager remains responsible for providing them.
|
|
63
|
+
*/
|
|
64
|
+
external: DependencyBundlingMatcher[];
|
|
65
|
+
/**
|
|
66
|
+
* Dependencies or module ids that must be bundled.
|
|
67
|
+
*
|
|
68
|
+
* Bundled dependencies are forced into the generated output even when the
|
|
69
|
+
* bundler would normally externalize them.
|
|
70
|
+
*
|
|
71
|
+
* Use this only for packages that would otherwise stay external but must be
|
|
72
|
+
* shipped inside the generated artifact. Imported dev dependencies already
|
|
73
|
+
* bundle by default in tsdown and do not need to be forced here.
|
|
74
|
+
*/
|
|
75
|
+
bundle: DependencyBundlingMatcher[];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Options for creating a dependency bundling policy from a package manifest.
|
|
79
|
+
*/
|
|
80
|
+
type MakeDependencyBundlingPolicyOptions = {
|
|
81
|
+
/**
|
|
82
|
+
* Dependency/module ids that must be bundled into the output.
|
|
83
|
+
*
|
|
84
|
+
* Use this only when manifest classification would otherwise externalize a
|
|
85
|
+
* package that must be shipped inside the generated artifact. Imported dev
|
|
86
|
+
* dependencies already bundle by default in tsdown.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* bundle: ['some-runtime-dependency']
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
bundle?: readonly string[];
|
|
94
|
+
/**
|
|
95
|
+
* Additional dependency/module ids that must stay external.
|
|
96
|
+
*
|
|
97
|
+
* Use this for optional dependencies, dynamic imports, virtual modules, native
|
|
98
|
+
* packages, or runtime-provided modules that are not declared in the package
|
|
99
|
+
* manifest.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* external: ['pino/file', '#imports']
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
external?: readonly string[];
|
|
107
|
+
/**
|
|
108
|
+
* Whether `peerDependencies` should be externalized.
|
|
109
|
+
*
|
|
110
|
+
* Peer dependencies should normally stay external because they are owned by the
|
|
111
|
+
* consuming application/package. Bundling them can create duplicate runtime
|
|
112
|
+
* instances and broken shared contracts.
|
|
113
|
+
*
|
|
114
|
+
* @defaultValue `true`
|
|
115
|
+
*/
|
|
116
|
+
includePeers?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether `dependencies` should be externalized.
|
|
119
|
+
*
|
|
120
|
+
* Libraries should normally keep dependencies external to avoid shipping
|
|
121
|
+
* duplicate copies into consumers. Apps or CLIs may choose to bundle selected
|
|
122
|
+
* dependencies for a more self-contained output.
|
|
123
|
+
*
|
|
124
|
+
* @defaultValue `true`
|
|
125
|
+
*/
|
|
126
|
+
includeDependencies?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Whether generated package matchers should also match subpath imports.
|
|
129
|
+
*
|
|
130
|
+
* When enabled, a package such as `zod` also matches imports like `zod/v4` using
|
|
131
|
+
* a regular expression matcher.
|
|
132
|
+
*
|
|
133
|
+
* @defaultValue `true`
|
|
134
|
+
*/
|
|
135
|
+
includeSubpaths?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Whether Node.js built-in modules should be externalized.
|
|
138
|
+
*
|
|
139
|
+
* Enable this for Node.js outputs. Disable it for browser-only outputs so
|
|
140
|
+
* accidental imports such as `node:fs` fail during bundling instead of being
|
|
141
|
+
* silently preserved.
|
|
142
|
+
*
|
|
143
|
+
* @defaultValue `true`
|
|
144
|
+
*/
|
|
145
|
+
includeNodeBuiltins?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Whether peer dependencies may be forced into the bundle.
|
|
148
|
+
*
|
|
149
|
+
* This is disabled by default because bundling peer dependencies usually
|
|
150
|
+
* violates the package contract. Enable only for intentionally standalone
|
|
151
|
+
* artifacts where duplicate peer instances are acceptable.
|
|
152
|
+
*
|
|
153
|
+
* @defaultValue `false`
|
|
154
|
+
*/
|
|
155
|
+
allowPeerBundling?: boolean;
|
|
156
|
+
};
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src-node/bundling/make-dependency-bundling-policy.d.ts
|
|
159
|
+
declare function makeDependencyBundlingPolicy(pkg: DependencyBundlingPackageJSON, opts?: MakeDependencyBundlingPolicyOptions): DependencyBundlingPolicy;
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src-node/console/console-options.d.ts
|
|
162
|
+
interface ConsoleOptions {
|
|
163
|
+
readonly enabled?: boolean;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src-node/console/console.d.ts
|
|
167
|
+
interface ConsolePanelRow {
|
|
168
|
+
readonly label: string;
|
|
169
|
+
readonly value: string | number;
|
|
170
|
+
}
|
|
171
|
+
declare class Console {
|
|
172
|
+
private readonly instance;
|
|
173
|
+
constructor(options?: ConsoleOptions);
|
|
174
|
+
title(product: string, command: string, rows?: readonly ConsolePanelRow[]): void;
|
|
175
|
+
panel(title: string, rows: readonly ConsolePanelRow[], badge?: string | number): void;
|
|
176
|
+
step(label: string, message: string): string;
|
|
177
|
+
duration(ms: number): string;
|
|
178
|
+
emptyLine(): void;
|
|
179
|
+
log(message?: unknown, ...args: unknown[]): void;
|
|
180
|
+
info(message?: unknown, ...args: unknown[]): void;
|
|
181
|
+
start(message?: unknown, ...args: unknown[]): void;
|
|
182
|
+
success(message?: unknown, ...args: unknown[]): void;
|
|
183
|
+
warn(message?: unknown, ...args: unknown[]): void;
|
|
184
|
+
error(message?: unknown, ...args: unknown[]): void;
|
|
185
|
+
debug(message?: unknown, ...args: unknown[]): void;
|
|
186
|
+
private printPanel;
|
|
187
|
+
private formatPanel;
|
|
188
|
+
private formatPanelTop;
|
|
189
|
+
private formatPanelBottom;
|
|
190
|
+
private formatPanelRow;
|
|
191
|
+
private getPanelWidth;
|
|
192
|
+
private getTitleWidth;
|
|
193
|
+
private getRowsWidth;
|
|
194
|
+
private getRowWidth;
|
|
195
|
+
private visibleLength;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src-node/logger/log-flag.d.ts
|
|
199
|
+
declare enum LogFlag {
|
|
200
|
+
Critical = "CRITICAL",
|
|
201
|
+
Serious = "SERIOUS",
|
|
202
|
+
Important = "IMPORTANT",
|
|
203
|
+
Notice = "NOTICE",
|
|
204
|
+
Routine = "ROUTINE"
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src-node/logger/log-options.d.ts
|
|
208
|
+
interface LogOptions {
|
|
209
|
+
readonly flag?: LogFlag;
|
|
210
|
+
readonly details?: unknown;
|
|
211
|
+
readonly error?: unknown;
|
|
212
|
+
readonly metadata?: unknown;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src-node/logger/logger-options.d.ts
|
|
216
|
+
interface BaseLoggerTransportOptions {
|
|
217
|
+
readonly level?: Level;
|
|
218
|
+
}
|
|
219
|
+
interface LoggerConsoleTransportOptions extends BaseLoggerTransportOptions {
|
|
220
|
+
readonly type: 'console';
|
|
221
|
+
readonly target: 'pino-pretty';
|
|
222
|
+
readonly pretty?: PrettyOptions;
|
|
223
|
+
}
|
|
224
|
+
interface LoggerFileTransportOptions extends BaseLoggerTransportOptions {
|
|
225
|
+
readonly type: 'file';
|
|
226
|
+
readonly path: string;
|
|
227
|
+
}
|
|
228
|
+
type LoggerTransportOptions = LoggerConsoleTransportOptions | LoggerFileTransportOptions;
|
|
229
|
+
type LoggerOptions = {
|
|
230
|
+
readonly enabled: false;
|
|
231
|
+
readonly debug?: boolean;
|
|
232
|
+
readonly transports?: never;
|
|
233
|
+
} | {
|
|
234
|
+
readonly enabled: true;
|
|
235
|
+
readonly debug?: boolean;
|
|
236
|
+
readonly transports: readonly [LoggerTransportOptions, ...LoggerTransportOptions[]];
|
|
237
|
+
};
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src-node/logger/logger.d.ts
|
|
240
|
+
interface Logger {
|
|
241
|
+
readonly instance: Logger$1;
|
|
242
|
+
info(title: string, options?: LogOptions): void;
|
|
243
|
+
debug(title: string, options?: LogOptions): void;
|
|
244
|
+
trace(title: string, options?: LogOptions): void;
|
|
245
|
+
warn(title: string, options?: LogOptions): void;
|
|
246
|
+
error(title: string, options?: LogOptions): void;
|
|
247
|
+
fatal(title: string, options?: LogOptions): void;
|
|
248
|
+
child(bindings: Bindings): Logger$1;
|
|
249
|
+
}
|
|
250
|
+
declare class LoggerImpl implements Logger {
|
|
251
|
+
private readonly options;
|
|
252
|
+
readonly instance: Logger$1;
|
|
253
|
+
constructor(options: LoggerOptions);
|
|
254
|
+
info(title: string, options?: LogOptions): void;
|
|
255
|
+
debug(title: string, options?: LogOptions): void;
|
|
256
|
+
trace(title: string, options?: LogOptions): void;
|
|
257
|
+
warn(title: string, options?: LogOptions): void;
|
|
258
|
+
error(title: string, options?: LogOptions): void;
|
|
259
|
+
fatal(title: string, options?: LogOptions): void;
|
|
260
|
+
child(bindings: Bindings): Logger$1;
|
|
261
|
+
private log;
|
|
262
|
+
private formatLogOptions;
|
|
263
|
+
private formatUnknown;
|
|
264
|
+
private makeInstance;
|
|
265
|
+
private makeTransportTargets;
|
|
266
|
+
private makeConsoleTransportTarget;
|
|
267
|
+
private makeFileTransportTarget;
|
|
268
|
+
private makeTransportLevel;
|
|
269
|
+
private makeGlobalLogLevel;
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/di/assembly.d.ts
|
|
273
|
+
type AssemblyContainer = Container;
|
|
274
|
+
interface Assembly {
|
|
275
|
+
assemble(container: AssemblyContainer): void;
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src-node/di/core-node-assembly.d.ts
|
|
279
|
+
interface CoreNodeAssemblyOptions {
|
|
280
|
+
readonly logger?: LoggerOptions;
|
|
281
|
+
}
|
|
282
|
+
declare function coreNodeAssembly(options?: CoreNodeAssemblyOptions): Assembly[];
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src-node/environment/environment-variable.d.ts
|
|
285
|
+
declare function optionalEnvironmentVariable(name: string): string | undefined;
|
|
286
|
+
declare function requiredEnvironmentVariable(name: string): string;
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src-node/file/file-sync.d.ts
|
|
289
|
+
/**
|
|
290
|
+
* Resolve `relative` against `base`, unless `relative` is already absolute,
|
|
291
|
+
* in which case just normalize and return it.
|
|
292
|
+
*
|
|
293
|
+
* @param {string} base
|
|
294
|
+
* A `file://` URL or filesystem path to serve as the base.
|
|
295
|
+
* @param {string} relative
|
|
296
|
+
* A relative path (e.g. `./foo` or `../bar`) or an absolute filesystem path.
|
|
297
|
+
* @returns {string}
|
|
298
|
+
* The resulting absolute (normalized) filesystem path.
|
|
299
|
+
* @throws {Error}
|
|
300
|
+
* If `base` is a non-file URL or cannot be parsed.
|
|
301
|
+
*/
|
|
302
|
+
declare function resolvePath(base: string, relative: string): string;
|
|
303
|
+
/**
|
|
304
|
+
* Remove or clean a file or directory.
|
|
305
|
+
*
|
|
306
|
+
* @param {string} target
|
|
307
|
+
* File or directory path (relative or absolute).
|
|
308
|
+
* @param {object} [opts]
|
|
309
|
+
* Removal options.
|
|
310
|
+
* @param {boolean} [opts.recursive=true]
|
|
311
|
+
* Recurse into subdirectories when deleting a directory.
|
|
312
|
+
* @param {boolean} [opts.force=true]
|
|
313
|
+
* Ignore “not found” errors.
|
|
314
|
+
* @param {boolean} [opts.cleanOnly=false]
|
|
315
|
+
* When true:
|
|
316
|
+
* - For a directory: delete its contents but leave the directory itself.
|
|
317
|
+
* - For a file: truncate it without deleting the file.
|
|
318
|
+
* @returns {void}
|
|
319
|
+
*/
|
|
320
|
+
declare function removePath(target: string, opts?: {
|
|
321
|
+
recursive?: boolean;
|
|
322
|
+
force?: boolean;
|
|
323
|
+
cleanOnly?: boolean;
|
|
324
|
+
}): void;
|
|
325
|
+
/**
|
|
326
|
+
* Ensures the directory for a given path exists.
|
|
327
|
+
*
|
|
328
|
+
* @param {string} targetPath
|
|
329
|
+
* File or directory path (relative or absolute).
|
|
330
|
+
* @returns {string}
|
|
331
|
+
* The absolute, resolved path.
|
|
332
|
+
* @throws {Error}
|
|
333
|
+
* If the target directory does not exist.
|
|
334
|
+
*/
|
|
335
|
+
declare function ensureDirectory(targetPath: string): string;
|
|
336
|
+
/**
|
|
337
|
+
* Creates a directory if it doesn't exist.
|
|
338
|
+
*
|
|
339
|
+
* @param {string} dirPath
|
|
340
|
+
* The path to the directory (relative or absolute).
|
|
341
|
+
* @returns {string}
|
|
342
|
+
* The absolute path to the created directory.
|
|
343
|
+
* @throws {Error}
|
|
344
|
+
* If the path is invalid or a file already exists at that path.
|
|
345
|
+
*/
|
|
346
|
+
declare function createDirectory(dirPath: string): string;
|
|
347
|
+
/**
|
|
348
|
+
* Creates a file if it doesn't exist, and optionally seeds/appends content.
|
|
349
|
+
* Also ensures its parent directory exists.
|
|
350
|
+
*
|
|
351
|
+
* @param {string} filePath
|
|
352
|
+
* Path to the file (relative or absolute).
|
|
353
|
+
* @param {string} [content='']
|
|
354
|
+
* Optional string to write into the file (appended if it already exists).
|
|
355
|
+
* @returns {string}
|
|
356
|
+
* The absolute path to the created file.
|
|
357
|
+
* @throws {Error}
|
|
358
|
+
* If the path exists but is not a file, or if writing fails.
|
|
359
|
+
*/
|
|
360
|
+
declare function createFile(filePath: string, content?: string): string;
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src-node/file/file-async.d.ts
|
|
363
|
+
/**
|
|
364
|
+
* Remove or clean a file or directory.
|
|
365
|
+
*
|
|
366
|
+
* @async
|
|
367
|
+
* @param target - File or directory path (relative or absolute).
|
|
368
|
+
* @param opts - Removal options.
|
|
369
|
+
* @param [opts.recursive=true] - Recurse into subdirectories when deleting a directory.
|
|
370
|
+
* @param [opts.force=true] - Ignore “not found” errors (i.e. don’t throw if the path doesn’t exist).
|
|
371
|
+
* @param [opts.cleanOnly=false] - If true:
|
|
372
|
+
* - For a directory: delete its contents but leave the directory itself.
|
|
373
|
+
* - For a file: truncate it (empty its contents) without deleting the file.
|
|
374
|
+
*/
|
|
375
|
+
declare function removePathAsync(target: string, opts?: {
|
|
376
|
+
recursive?: boolean;
|
|
377
|
+
force?: boolean;
|
|
378
|
+
cleanOnly?: boolean;
|
|
379
|
+
}): Promise<void>;
|
|
380
|
+
/**
|
|
381
|
+
* Ensures the directory for a given path exists.
|
|
382
|
+
*
|
|
383
|
+
* @async
|
|
384
|
+
* @param targetPath - File or directory path.
|
|
385
|
+
* @returns Absolute resolved path.
|
|
386
|
+
* @throws {Error} If the target directory does not exist.
|
|
387
|
+
*/
|
|
388
|
+
declare function ensureDirectoryAsync(targetPath: string): Promise<string>;
|
|
389
|
+
/**
|
|
390
|
+
* Creates a directory if it doesn't exist.
|
|
391
|
+
*
|
|
392
|
+
* @async
|
|
393
|
+
* @param dirPath - The path to the directory.
|
|
394
|
+
* @returns Absolute path to the created directory.
|
|
395
|
+
* @throws {Error} If the directory cannot be created or path is invalid.
|
|
396
|
+
*/
|
|
397
|
+
declare function createDirectoryAsync(dirPath: string): Promise<string>;
|
|
398
|
+
/**
|
|
399
|
+
* Creates a file if it doesn't exist, and optionally seeds/appends content.
|
|
400
|
+
* Also ensures its parent directory exists.
|
|
401
|
+
*
|
|
402
|
+
* @async
|
|
403
|
+
* @param filePath - Path to the file (relative or absolute).
|
|
404
|
+
* @param content - Optional string to write into the file (appended if exists).
|
|
405
|
+
* @returns Absolute path to the created file.
|
|
406
|
+
* @throws If the path exists but is not a file, or writing fails.
|
|
407
|
+
*/
|
|
408
|
+
declare function createFileAsync(filePath: string, content?: string): Promise<string>;
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src-node/package-json/package-json.d.ts
|
|
411
|
+
interface PackageNameModel {
|
|
412
|
+
readonly original: string;
|
|
413
|
+
readonly prefix: string | undefined;
|
|
414
|
+
readonly base: string;
|
|
415
|
+
readonly kebab: string;
|
|
416
|
+
readonly snake: string;
|
|
417
|
+
readonly camel: string;
|
|
418
|
+
readonly pascal: string;
|
|
419
|
+
}
|
|
420
|
+
declare const PackageNameSchema: z.ZodPipe<z.ZodString, z.ZodTransform<PackageNameModel, string>>;
|
|
421
|
+
type PackageJSONModel = z.output<typeof PackageJSONSchema>;
|
|
422
|
+
declare const PackageJSONSchema: z.ZodObject<{
|
|
423
|
+
name: z.ZodPipe<z.ZodString, z.ZodTransform<PackageNameModel, string>>;
|
|
424
|
+
version: z.ZodString;
|
|
425
|
+
private: z.ZodOptional<z.ZodBoolean>;
|
|
426
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
427
|
+
module: "module";
|
|
428
|
+
commonjs: "commonjs";
|
|
429
|
+
}>>;
|
|
430
|
+
dependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
431
|
+
peerDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
432
|
+
devDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
433
|
+
}, z.core.$loose>;
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src-node/package-json/load-package.d.ts
|
|
436
|
+
/**
|
|
437
|
+
* Loads and validates a `package.json` file from the given filesystem path.
|
|
438
|
+
*
|
|
439
|
+
* Node-only utility. Intended for build-time, CLI, or server runtime usage.
|
|
440
|
+
*
|
|
441
|
+
* @param path
|
|
442
|
+
* Absolute or relative path to a `package.json` file.
|
|
443
|
+
*
|
|
444
|
+
* @returns
|
|
445
|
+
* Parsed and validated {@link PackageJSONModel}.
|
|
446
|
+
*
|
|
447
|
+
* @throws
|
|
448
|
+
* - If the file cannot be read.
|
|
449
|
+
* - If the file is not valid JSON.
|
|
450
|
+
* - If the contents do not match {@link PackageJSONSchema}.
|
|
451
|
+
*/
|
|
452
|
+
declare function loadPackageJSON(path: string): PackageJSONModel;
|
|
453
|
+
//#endregion
|
|
454
|
+
export { BaseLoggerTransportOptions, Console, ConsoleOptions, ConsolePanelRow, CoreNodeAssemblyOptions, DependencyBundlingMatcher, DependencyBundlingPackageJSON, DependencyBundlingPolicy, LogFlag, LogOptions, Logger, LoggerConsoleTransportOptions, LoggerFileTransportOptions, LoggerImpl, LoggerOptions, LoggerTransportOptions, MakeDependencyBundlingPolicyOptions, PackageJSONModel, PackageJSONSchema, PackageNameModel, PackageNameSchema, coreNodeAssembly, createDirectory, createDirectoryAsync, createFile, createFileAsync, ensureDirectory, ensureDirectoryAsync, loadPackageJSON, makeDependencyBundlingPolicy, optionalEnvironmentVariable, removePath, removePathAsync, requiredEnvironmentVariable, resolvePath };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{builtinModules as e}from"node:module";import{createConsola as t}from"consola";import{colors as n}from"consola/utils";import{injectable as r}from"inversify";import{add as i,addDays as a,addHours as o,addMilliseconds as s,addMinutes as c,addMonths as l,addSeconds as u,addWeeks as d,addYears as f,compareAsc as p,differenceInDays as ee,differenceInHours as te,differenceInMilliseconds as ne,differenceInMinutes as re,differenceInMonths as ie,differenceInSeconds as ae,differenceInWeeks as oe,differenceInYears as se,endOfDay as ce,endOfMonth as m,endOfWeek as le,endOfYear as ue,format as de,formatISO as fe,fromUnixTime as pe,getDate as me,getDay as he,getHours as ge,getMinutes as _e,getMonth as ve,getSeconds as ye,getUnixTime as be,getYear as xe,isAfter as Se,isBefore as Ce,isEqual as we,isSameDay as Te,isValid as h,parseISO as Ee,setDate as De,setDay as Oe,setHours as ke,setMinutes as Ae,setMonth as je,setSeconds as Me,setYear as Ne,startOfDay as Pe,startOfMonth as g,startOfWeek as _,startOfYear as v,sub as y,subDays as Fe,subHours as Ie,subMilliseconds as Le,subMinutes as Re,subMonths as ze,subSeconds as Be,subWeeks as Ve,subYears as He}from"date-fns";import{formatInTimeZone as Ue,fromZonedTime as We,getTimezoneOffset as Ge,toZonedTime as Ke}from"date-fns-tz";import b from"ms";import x from"node:path";import S,{promises as C}from"node:fs";import{fileURLToPath as qe}from"node:url";import w from"pino";import T from"zod";var E=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Ye=Object.getOwnPropertyNames,Xe=Object.prototype.hasOwnProperty,D=(e,t)=>{let n={};for(var r in e)E(n,r,{get:e[r],enumerable:!0});return t||E(n,Symbol.toStringTag,{value:`Module`}),n},O=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=Ye(t),a=0,o=i.length,s;a<o;a++)s=i[a],!Xe.call(e,s)&&s!==n&&E(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=Je(t,s))||r.enumerable});return e},k=(e,t,n)=>(O(e,t,`default`),n&&O(n,t,`default`));function Ze(e,t={}){let n=t.includePeers??!0,r=t.includeDependencies??!0,i=t.includeSubpaths??!0,a=t.includeNodeBuiltins??!0,o=t.allowPeerBundling??!1,s=Object.keys(e.peerDependencies??{}),c=Object.keys(e.dependencies??{}),l=j(t.bundle??[]),u=j(t.external??[]);rt(u,l),at(l),o||it(s,l);let d=new Set(l.map(N)),f=n?s.filter(e=>!d.has(e)):[],p=r?c.filter(e=>!d.has(e)):[];return{external:M([...a?Qe():[],...A([...f,...p,...u],i)]),bundle:M(A(l,i))}}function Qe(){let t=j(e.map(P)),n=t.map(e=>`node:${e}`);return M([...t,...n,/^node:/])}function A(e,t){return t?e.map(e=>$e(e)):[...e]}function $e(e){return tt(e)?e:RegExp(`^${nt(e)}(?:/.*)?$`)}function j(e){return Array.from(new Set(e))}function M(e){let t=new Set,n=[];for(let r of e){let e=et(r);t.has(e)||(t.add(e),n.push(r))}return n}function et(e){return typeof e==`string`?`string:${e}`:`regexp:${e.source}/${e.flags}`}function N(e){if(e.startsWith(`@`)){let[t,n]=e.split(`/`);return t&&n?`${t}/${n}`:e}let[t]=e.split(`/`);return t??e}function P(e){return e.startsWith(`node:`)?e.slice(5):e}function tt(e){return e.includes(`*`)||e.startsWith(`^`)||e.endsWith(`$`)}function nt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function rt(e,t){let n=new Set(e.map(N)),r=t.filter(e=>n.has(N(e)));if(r.length!==0)throw Error(`Packages cannot be both external and bundled: ${r.join(`, `)}`)}function it(e,t){let n=new Set(e),r=t.filter(e=>n.has(N(e)));if(r.length!==0)throw Error(`Peer dependencies must stay external and cannot be bundled by default: ${r.join(`, `)}`)}function at(t){let n=new Set(e.map(P)),r=t.filter(e=>ot(e,n));if(r.length!==0)throw Error(`Node.js built-in modules cannot be bundled: ${r.join(`, `)}`)}function ot(e,t){let n=P(e),[r]=n.split(`/`);return r?t.has(r):t.has(n)}const st=/\u001B\[[0-9;]*m/g;var ct=class{instance;constructor(e={}){this.instance=t({level:e.enabled===!1?-999:999,formatOptions:{colors:!0,date:!1}})}title(e,t,r=[]){this.printPanel({title:`${e} ${t}`.trim(),renderedTitle:`${n.cyan(n.bold(e))}${t?` ${n.dim(t)}`:``}`,rows:r,formatValue:n.green})}panel(e,t,r){this.printPanel({title:r===void 0?e:`${e} ${r}`,renderedTitle:`${n.cyan(n.bold(e))}${r===void 0?``:` ${n.green(String(r))}`}`,rows:t,formatValue:n.dim})}step(e,t){return`${n.cyan(e.padEnd(10,` `))}${t}`}duration(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(2)}s`}emptyLine(){this.instance.log(``)}log(e,...t){this.instance.log(e,...t)}info(e,...t){this.instance.info(e,...t)}start(e,...t){this.instance.start(e,...t)}success(e,...t){this.instance.success(e,...t)}warn(e,...t){this.instance.warn(e,...t)}error(e,...t){this.instance.error(e,...t)}debug(e,...t){this.instance.debug(e,...t)}printPanel(e){this.instance.log(this.formatPanel(e))}formatPanel(e){let t=this.getPanelWidth(e);return[this.formatPanelTop(e.renderedTitle,t),...e.rows.map(n=>this.formatPanelRow(n,t,e.formatValue)),this.formatPanelBottom(t)].join(`
|
|
2
|
+
`)}formatPanelTop(e,t){let r=Math.max(1,t-this.visibleLength(e)-5);return`${n.dim(`╭─`)} ${e} ${n.dim(`─`.repeat(r))}${n.dim(`╮`)}`}formatPanelBottom(e){return`${n.dim(`╰`)}${n.dim(`─`.repeat(e-2))}${n.dim(`╯`)}`}formatPanelRow(e,t,r){let i=e.label.padEnd(14,` `),a=String(e.value),o=this.visibleLength(i)+this.visibleLength(a)+4,s=Math.max(0,t-o);return`${n.dim(`│`)} ${n.blue(i)}${r(a)}${` `.repeat(s)} ${n.dim(`│`)}`}getPanelWidth(e){return Math.max(48,this.getTitleWidth(e),this.getRowsWidth(e.rows))}getTitleWidth(e){return this.visibleLength(e.title)+6}getRowsWidth(e){return Math.max(0,...e.map(e=>this.getRowWidth(e)))}getRowWidth(e){return 14+this.visibleLength(String(e.value))+4}visibleLength(e){return e.replace(st,``).length}};const F=`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}.Core.DI`,I={DI:{Formatter:{UnitController:Symbol.for(`${F}.Formatter.UnitController`)},Logger:Symbol.for(`${F}.Logger`)}};function lt(e){return e instanceof Error}function L(e,t={}){if(e==null)return{};let{filterNull:n=!0,filterUndefined:r=!0,filterEmptyString:i=!1,filterEmptyObject:a=!1,filterEmptyArray:o=!1}=t;return Object.keys(e).reduce((s,c)=>{let l=e[c];return R(l)&&Object.getPrototypeOf(l)===null&&(l=void 0),ut(l)&&(l=L(l,t)),n&&l===null||r&&l===void 0||i&&l===``||a&&z(l)||o&&Array.isArray(l)&&l.length===0||(s[c]=l),s},{})}function R(e){return typeof e==`object`&&!!e}function z(e){return R(e)&&Object.keys(e).length===0}function ut(e){return R(e)&&Object.getPrototypeOf(e)===Object.prototype}function dt(e){return e==null||[`string`,`number`,`boolean`,`bigint`,`symbol`].includes(typeof e)}Array.prototype.isEmpty=function(){return this==null||this.length===0},String.prototype.capitalized=function(){let e=this==null?``:this.toString();return e.trim()?e.charAt(0).toUpperCase()+e.slice(1):``};var ft=class{streetLine1;streetLine2;postalCode;state;city;country;countryCode;constructor(e){this.streetLine1=e.streetLine1,this.streetLine2=e.streetLine2,this.postalCode=e.postalCode,this.state=e.state,this.city=e.city,this.country=e.country,this.countryCode=e.countryCode}toJSON(){return L({streetLine1:this.streetLine1,streetLine2:this.streetLine2,postalCode:this.postalCode,city:this.city,state:this.state,country:this.country,countryCode:this.countryCode},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}formatted(){let e=(e,t)=>e.map(e=>e?.trim()).filter(e=>e&&e.length>0).join(t).trim(),t=this.streetLine1;return e([t,e([this.postalCode,this.city],` `),e([this.country],`, `)],`, `)}},pt=class{email;fb;ig;phone;web;constructor({email:e,fb:t,ig:n,phone:r,web:i}){this.email=e,this.fb=t,this.ig=n,this.phone=r,this.web=i}toJSON(){return L({email:this.email,fb:this.fb,ig:this.ig,phone:this.phone,web:this.web},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},B=D({DateFormat:()=>H,DateTime:()=>V});import*as mt from"date-fns";k(B,mt);var V=class e{date;constructor(e){if(!e){this.date=new Date;return}if(e instanceof Date){if(!h(e))throw Error(`Invalid date object`);this.date=e;return}let t=Ee(e);if(!h(t))throw Error(`Invalid date string`);this.date=t}static fromUnixTimestamp(t,n){return new e(pe(t,n))}static now(){return new e(new Date)}toJSON(){return this.toISOString()}toDate(){return this.date}toUnixTimestamp(){return be(this.date)}getTime(){return this.date.getTime()}toISOString(){return fe(this.date)}format(e,t){return de(this.date,e,t)}addingDuration(t){return new e(i(this.date,t))}addingMilliseconds(t){return new e(s(this.date,t))}addingSeconds(t){return new e(u(this.date,t))}addingMinutes(t){return new e(c(this.date,t))}addingHours(t){return new e(o(this.date,t))}addingDays(t){return new e(a(this.date,t))}addingWeeks(t){return new e(d(this.date,t))}addingMonths(t){return new e(l(this.date,t))}addingYears(t){return new e(f(this.date,t))}subtractingDuration(t){return new e(y(this.date,t))}subtractingMilliseconds(t){return new e(Le(this.date,t))}subtractingSeconds(t){return new e(Be(this.date,t))}subtractingMinutes(t){return new e(Re(this.date,t))}subtractingHours(t){return new e(Ie(this.date,t))}subtractingDays(t){return new e(Fe(this.date,t))}subtractingWeeks(t){return new e(Ve(this.date,t))}subtractingMonths(t){return new e(ze(this.date,t))}subtractingYears(t){return new e(He(this.date,t))}differenceInMilliseconds(e){return ne(this.date,e.date)}differenceInSeconds(e){return ae(this.date,e.date)}differenceInMinutes(e){return re(this.date,e.date)}differenceInHours(e){return te(this.date,e.date)}differenceInDays(e){return ee(this.date,e.date)}differenceInWeeks(e){return oe(this.date,e.date)}differenceInMonths(e){return ie(this.date,e.date)}differenceInYears(e){return se(this.date,e.date)}isEqualTo(e){return we(this.date,e.date)}isBefore(e){return Ce(this.date,e.date)}isAfter(e){return Se(this.date,e.date)}compareTo(e){return p(this.date,e.date)}isSameDayAs(e){return Te(this.date,e.date)}startOfDay(){return new e(Pe(this.date))}endOfDay(){return new e(ce(this.date))}startOfWeek(){return new e(_(this.date))}endOfWeek(){return new e(le(this.date))}startOfMonth(){return new e(g(this.date))}endOfMonth(){return new e(m(this.date))}startOfYear(){return new e(v(this.date))}endOfYear(){return new e(ue(this.date))}get dayOfMonth(){return me(this.date)}get dayOfWeek(){return he(this.date)}get month(){return ve(this.date)}get year(){return xe(this.date)}get hours(){return ge(this.date)}get minutes(){return _e(this.date)}get seconds(){return ye(this.date)}settingDayOfMonth(t){return new e(De(this.date,t))}settingDayOfWeek(t){return new e(Oe(this.date,t))}settingMonth(t){return new e(je(this.date,t))}settingYear(t){return new e(Ne(this.date,t))}settingHours(t){return new e(ke(this.date,t))}settingMinutes(t){return new e(Ae(this.date,t))}settingSeconds(t){return new e(Me(this.date,t))}};let H=function(e){return e.ISO_DATE=`yyyy-MM-dd`,e.ISO_DATETIME=`yyyy-MM-dd'T'HH:mm:ssXXX`,e.MM_DD_YYYY=`MM/dd/yyyy`,e.FULL_MONTH_DAY_YEAR=`MMMM d, yyyy`,e.ABBR_MONTH_DAY_YEAR=`MMM d, yyyy`,e.RFC_3339=`yyyy-MM-dd'T'HH:mm:ss.SSSxxx`,e.ALT_RSS=`d MMM yyyy HH:mm:ss ZZZ`,e.RSS=`EEE, d MMM yyyy HH:mm:ss ZZZ`,e.HTTP_HEADER=`EEE, dd MMM yyyy HH:mm:ss zzz`,e.STANDARD=`EEE MMM dd HH:mm:ss Z yyyy`,e.EXTENDED=`eee dd-MMM-yyyy GG HH:mm:ss.SSS zzz`,e}({});var ht=class e{utc;timeZone;constructor(e,t){this.timeZone=e,this.utc=t??new Date}static fromUtc(t,n){return new e(n,t)}static fromLocalIso(t,n){let r=We(t,n);return new e(n,r)}format(e,t){return Ue(this.utc,this.timeZone,e,t)}toLocalIsoMinutes(e){return this.format(`yyyy-MM-dd'T'HH:mm`,e)}toLocalIsoSeconds(e){return this.format(`yyyy-MM-dd'T'HH:mm:ss`,e)}toISOString(){return this.utc.toISOString()}toUnixTimestamp(){return Math.floor(this.utc.getTime()/1e3)}toZonedDate(){return Ke(this.utc,this.timeZone)}timezoneOffsetMs(e){return Ge(this.timeZone,e??this.utc)}},gt=class{value;constructor([e,t]){if(e<-180||e>180)throw Error(`Longitude must be between -180 and 180.`);if(t<-90||t>90)throw Error(`Latitude must be between -90 and 90.`);this.value=[e,t]}get longitude(){return this.value[0]}get latitude(){return this.value[1]}toJSON(){return this.value}},_t=class{type=`Point`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.toJSON(),...this.bbox&&{bbox:this.bbox}}}},vt=class{type=`MultiPoint`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},yt=class{type=`LineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.toJSON()),...this.bbox&&{bbox:this.bbox}}}},bt=class{type=`MultiLineString`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},xt=class{type=`Polygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.toJSON())),...this.bbox&&{bbox:this.bbox}}}},St=class{type=`MultiPolygon`;coordinates;bbox;constructor(e,t){this.coordinates=e,this.bbox=t}toJSON(){return{type:this.type,coordinates:this.coordinates.map(e=>e.map(e=>e.map(e=>e.toJSON()))),...this.bbox&&{bbox:this.bbox}}}};let Ct=function(e){return e.Point=`Point`,e.MultiPoint=`MultiPoint`,e.LineString=`LineString`,e.MultiLineString=`MultiLineString`,e.Polygon=`Polygon`,e.MultiPolygon=`MultiPolygon`,e}({});function U(e){return Error(`Invalid ObjectId value: ${String(e)}`)}var wt=class e{value;constructor(e){if(e==null)throw U(e);let t=e.trim();if(t.length===0)throw U(e);this.value=t,Object.freeze(this)}get asString(){return this.value}equals(t){return this.value===e.from(t).value}compare(t){let n=e.from(t).value;return this.value===n?0:this.value<n?-1:1}hash(){return this.value}toJSON(){return this.value}toString(){return this.value}[Symbol.toPrimitive](){return this.value}static from(t){return t instanceof e?t:new e(t)}static isValid(e){return typeof e==`string`&&e.trim().length>0}static toValueSet(t){let n=new Set;for(let r of t)n.add(e.from(r).value);return n}},Tt=class{day;intervals;constructor(e,t){this.day=e,this.intervals=t}toJSON(){return L({day:this.day,intervals:this.intervals},{filterNull:!0,filterUndefined:!0,filterEmptyString:!0})}},Et=class{_milliseconds;_long;constructor(e,t){if(this._long=t?.long===!0,e==null)throw Error(`Invalid interval format: ${e}`);if(typeof e==`number`)this._milliseconds=e;else{let t=b(e);if(t===void 0)throw Error(`Invalid interval format: ${e}`);this._milliseconds=t}}get milliseconds(){return this._milliseconds}get seconds(){return Math.floor(this._milliseconds/1e3)}get minutes(){return Math.floor(this._milliseconds/6e4)}get hours(){return Math.floor(this._milliseconds/36e5)}get days(){return Math.floor(this._milliseconds/864e5)}get weeks(){return Math.floor(this._milliseconds/6048e5)}get formatted(){return b(this._milliseconds,{long:this._long})}toString(){return b(this._milliseconds,{long:this._long})}toObject(){return{milliseconds:this._milliseconds,seconds:this.seconds,minutes:this.minutes,hours:this.hours,days:this.days,weeks:this.weeks}}};let Dt=function(e){return e.Byte=`B`,e.Kilobyte=`KB`,e.Megabyte=`MB`,e.Gigabyte=`GB`,e.Terabyte=`TB`,e}({}),Ot=function(e){return e.Millimeter=`mm`,e.Centimeter=`cm`,e.Meter=`m`,e.Kilometer=`km`,e}({}),kt=function(e){return e.Milligram=`mg`,e.Gram=`g`,e.Kilogram=`kg`,e.Tonne=`t`,e}({});k(D({Address:()=>ft,ByteUnit:()=>Dt,Contacts:()=>pt,Coordinates:()=>gt,DateFormat:()=>H,DateTime:()=>V,DistanceUnit:()=>Ot,GeoJsonType:()=>Ct,LineString:()=>yt,MultiLineString:()=>bt,MultiPoint:()=>vt,MultiPolygon:()=>St,ObjectId:()=>wt,OpeningHour:()=>Tt,Point:()=>_t,Polygon:()=>xt,TimeInterval:()=>Et,WeightUnit:()=>kt,ZonedDateTime:()=>ht}),B);function At(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class{formatBytes(e,t){let{inputUnit:n=`B`,outputUnit:r=`auto`,decimals:i=1}=t??{},a=e=>e===`B`?1:e===`KB`?1024:e===`MB`?1048576:e===`GB`?1073741824:1099511627776,o=e*a(n),s=r===`auto`?(()=>{for(let e of[`TB`,`GB`,`MB`,`KB`])if(o/a(e)>=1)return e;return`B`})():r,c=o/a(s),l=10**i;return{value:Math.round(c*l)/l,unit:s,bytes:o}}};W=At([r()],W);var jt=class{assemble(e){e.bind(I.DI.Formatter.UnitController).to(W)}};function Mt(){return[new jt]}let Nt=function(e){return e.Critical=`CRITICAL`,e.Serious=`SERIOUS`,e.Important=`IMPORTANT`,e.Notice=`NOTICE`,e.Routine=`ROUTINE`,e}({});function G(e,t){if(x.isAbsolute(t))return x.normalize(t);let n;try{let t=new URL(e);if(t.protocol!==`file:`)throw Error(`Unsupported URL protocol "${t.protocol}"`);n=x.dirname(qe(t))}catch{n=e}return x.resolve(n,t)}function Pt(e,t={}){let n=G(process.cwd(),e);if(!S.existsSync(n))return;let r=S.statSync(n),{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){for(let e of S.readdirSync(n))S.rmSync(x.join(n,e),{recursive:i,force:a});return}if(o&&r.isFile()){S.truncateSync(n,0);return}S.rmSync(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}function K(e){let t=G(process.cwd(),e),n=S.existsSync(t)&&S.statSync(t).isDirectory()?t:x.dirname(t);if(!S.existsSync(n))throw Error(`Directory "${n}" does not exist.`);return t}function Ft(e){let t=G(process.cwd(),e);x.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path.`);try{if(!S.existsSync(t))S.mkdirSync(t,{recursive:!0});else if(!S.statSync(t).isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}function It(e,t=``){let n=G(process.cwd(),e);K(x.dirname(n));let r=Lt(n);if(!r)S.writeFileSync(n,t,{encoding:`utf8`,flag:`w`});else{if(!r.isFile())throw Error(`"${n}" exists but is not a file.`);t&&S.writeFileSync(n,t,{encoding:`utf8`,flag:`a`})}return n}function Lt(e){try{return S.statSync(e)}catch{return}}async function Rt(e,t={}){let n=G(process.cwd(),e),r;try{r=await C.stat(n)}catch(e){if((t.force??!0)&&e.code===`ENOENT`)return;throw e}let{recursive:i=!0,force:a=!0,cleanOnly:o=!1}=t;if(o&&r.isDirectory()){let e=await C.readdir(n);for(let t of e)await C.rm(x.join(n,t),{recursive:i,force:a});return}if(o&&r.isFile()){await C.truncate(n,0);return}await C.rm(n,{recursive:r.isDirectory()?i:!1,force:a,maxRetries:3,retryDelay:100})}async function q(e){let t=G(process.cwd(),e),n;try{n=await C.stat(t)}catch{}let r=n?.isDirectory()?t:x.dirname(t);try{if(!(await C.stat(r)).isDirectory())throw Error(`"${r}" exists but is not a directory.`)}catch(e){throw e.code===`ENOENT`?Error(`Directory "${r}" does not exist.`):e}return t}async function zt(e){let t=G(process.cwd(),e);x.extname(e)&&console.warn(`[createDirectory] Warning: "${e}" looks like a file path (has extension).`);try{let e;try{e=await C.stat(t)}catch{}if(!e)await C.mkdir(t,{recursive:!0});else if(!e.isDirectory())throw Error(`"${t}" exists but is not a directory.`);return t}catch(e){throw Error(`Failed to create directory "${t}": ${e.message}`)}}async function Bt(e,t=``){let n=G(process.cwd(),e);await q(x.dirname(n));try{let e=await Vt(n);if(!e)await C.writeFile(n,t,{encoding:`utf8`,flag:`w`});else{if(!e.isFile())throw Error(`"${n}" exists but is not a file.`);t&&await C.writeFile(n,t,{encoding:`utf8`,flag:`a`})}return n}catch(e){throw Error(`Failed to create file "${n}": ${e.message}`)}}async function Vt(e){try{return await C.stat(e)}catch(e){if(e.code===`ENOENT`)return;throw e}}const J={filterNull:!0,filterUndefined:!0,filterEmptyString:!0,filterEmptyArray:!0,filterEmptyObject:!0};var Y=class{options;instance;constructor(e){this.options=e,this.instance=this.makeInstance()}info(e,t){this.log(`info`,e,t)}debug(e,t){this.log(`debug`,e,t)}trace(e,t){this.log(`trace`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}fatal(e,t){this.log(`fatal`,e,t)}child(e){return this.instance.child(e)}log(e,t,n){this.instance[e]({msg:t,...this.formatLogOptions(n)})}formatLogOptions(e){return e?L({flag:e.flag,details:this.formatUnknown(e.details),error:this.formatUnknown(e.error),metadata:this.formatUnknown(e.metadata)},J):{}}formatUnknown(e){if(lt(e)){let t={type:e.constructor.name,message:e.message};this.options.debug&&e.stack&&(t.stack=e.stack);for(let n of Object.keys(e))n in t||(t[n]=e[n]);let n=L(t,J);return z(n)?void 0:n}if(Buffer.isBuffer(e))return`[Buffer]`;if(e&&typeof e.pipe==`function`)return`[Stream]`;if(R(e))try{let t=JSON.stringify(e);if(t===void 0)return;let n=JSON.parse(t);if(Array.isArray(n))return n.length>0?n:void 0;if(R(n)){let e=L(n,J);return z(e)?void 0:e}return n}catch{return{type:`NonSerializableObject`}}return dt(e)?e:String(e)}makeInstance(){if(!this.options.enabled)return w({enabled:!1,timestamp:!0});let e=this.options.transports,t={level:this.makeGlobalLogLevel(e),enabled:!0,timestamp:!0,transport:{targets:this.makeTransportTargets(e)}};return w(t)}makeTransportTargets(e){if(e.filter(e=>e.type===`console`).length>1)throw Error(`[Logger] Multiple console transports are not supported.`);return e.map(e=>{switch(e.type){case`console`:return this.makeConsoleTransportTarget(e);case`file`:return this.makeFileTransportTarget(e)}})}makeConsoleTransportTarget(e){return{target:`pino-pretty`,level:this.makeTransportLevel(e.level),options:e.pretty}}makeFileTransportTarget(e){let t=this.makeTransportLevel(e.level),n=x.isAbsolute(e.path)?x.normalize(e.path):G(process.cwd(),e.path);return K(x.dirname(n)),{target:`pino/file`,level:t,options:{destination:n}}}makeTransportLevel(e){return this.options.debug?`trace`:e??`info`}makeGlobalLogLevel(e){if(this.options.debug)return`trace`;let t=e.at(0);if(!t)return`info`;let n={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},r=this.makeTransportLevel(t.level);for(let t of e.slice(1)){let e=this.makeTransportLevel(t.level);n[e]<n[r]&&(r=e)}return r}},Ht=class{options;constructor(e){this.options=e}assemble(e){e.bind(I.DI.Logger).toConstantValue(new Y(this.options))}};function Ut(e={}){let t=e.logger??{enabled:!1};return[...Mt(),new Ht(t)]}function X(e){return process.env[e]?.trim()||void 0}function Wt(e){let t=X(e);if(!t)throw Error(`Missing required environment variable: ${e}`);return t}const Z=T.string().trim().min(1).transform(e=>{let{prefix:t,base:n}=Gt(e),r=Kt(n);return{original:e,prefix:t,base:n,kebab:qt(r),snake:Jt(r),camel:Yt(r),pascal:Xt(r)}}),Q=T.looseObject({name:Z,version:T.string().trim().min(1),private:T.boolean().optional(),type:T.enum([`module`,`commonjs`]).optional(),dependencies:T.record(T.string(),T.string()).default({}),peerDependencies:T.record(T.string(),T.string()).default({}),devDependencies:T.record(T.string(),T.string()).default({})});function Gt(e){let t=/^@([^/]+)\/(.+)$/.exec(e);return t&&t[2]?{prefix:t[1],base:t[2]}:{base:e}}function Kt(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[^a-zA-Z0-9]+/g,` `).trim().toLowerCase();return t?t.split(/\s+/):[]}function qt(e){return e.join(`-`)}function Jt(e){return e.join(`_`)}function Yt(e){if(e.length===0)return``;let[t,...n]=e;return t+n.map($).join(``)}function Xt(e){return e.map($).join(``)}function $(e){return e.length===0?``:e.charAt(0).toUpperCase()+e.slice(1)}function Zt(e){let t,n;try{t=S.readFileSync(e,`utf8`)}catch(t){throw Error(`Failed to read package.json at ${e}`,{cause:t})}try{n=JSON.parse(t)}catch(t){throw Error(`Failed to parse package.json at ${e}`,{cause:t})}try{return Q.parse(n)}catch(t){throw Error(`Invalid package.json at ${e}`,{cause:t})}}export{ct as Console,Nt as LogFlag,Y as LoggerImpl,Q as PackageJSONSchema,Z as PackageNameSchema,Ut as coreNodeAssembly,Ft as createDirectory,zt as createDirectoryAsync,It as createFile,Bt as createFileAsync,K as ensureDirectory,q as ensureDirectoryAsync,Zt as loadPackageJSON,Ze as makeDependencyBundlingPolicy,X as optionalEnvironmentVariable,Pt as removePath,Rt as removePathAsync,Wt as requiredEnvironmentVariable,G as resolvePath};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("consola"),l=require("consola/utils"),u=require("node:path");u=s(u,1);let d=require("node:fs");d=s(d,1);let f=require("node:url"),p=require("pino");p=s(p,1);const m=/\u001B\[[0-9;]*m/g;var h=class{instance;constructor(e={}){this.instance=(0,c.createConsola)({level:e.enabled===!1?-999:999,formatOptions:{colors:!0,date:!1}})}title(e,t,n=[]){this.printPanel({title:`${e} ${t}`.trim(),renderedTitle:`${l.colors.cyan(l.colors.bold(e))}${t?` ${l.colors.dim(t)}`:``}`,rows:n,formatValue:l.colors.green})}panel(e,t,n){this.printPanel({title:n===void 0?e:`${e} ${n}`,renderedTitle:`${l.colors.cyan(l.colors.bold(e))}${n===void 0?``:` ${l.colors.green(String(n))}`}`,rows:t,formatValue:l.colors.dim})}step(e,t){return`${l.colors.cyan(e.padEnd(10,` `))}${t}`}duration(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(2)}s`}emptyLine(){this.instance.log(``)}log(e,...t){this.instance.log(e,...t)}info(e,...t){this.instance.info(e,...t)}start(e,...t){this.instance.start(e,...t)}success(e,...t){this.instance.success(e,...t)}warn(e,...t){this.instance.warn(e,...t)}error(e,...t){this.instance.error(e,...t)}debug(e,...t){this.instance.debug(e,...t)}printPanel(e){this.instance.log(this.formatPanel(e))}formatPanel(e){let t=this.getPanelWidth(e);return[this.formatPanelTop(e.renderedTitle,t),...e.rows.map(n=>this.formatPanelRow(n,t,e.formatValue)),this.formatPanelBottom(t)].join(`
|
|
2
|
+
`)}formatPanelTop(e,t){let n=Math.max(1,t-this.visibleLength(e)-5);return`${l.colors.dim(`╭─`)} ${e} ${l.colors.dim(`─`.repeat(n))}${l.colors.dim(`╮`)}`}formatPanelBottom(e){return`${l.colors.dim(`╰`)}${l.colors.dim(`─`.repeat(e-2))}${l.colors.dim(`╯`)}`}formatPanelRow(e,t,n){let r=e.label.padEnd(14,` `),i=String(e.value),a=this.visibleLength(r)+this.visibleLength(i)+4,o=Math.max(0,t-a);return`${l.colors.dim(`│`)} ${l.colors.blue(r)}${n(i)}${` `.repeat(o)} ${l.colors.dim(`│`)}`}getPanelWidth(e){return Math.max(48,this.getTitleWidth(e),this.getRowsWidth(e.rows))}getTitleWidth(e){return this.visibleLength(e.title)+6}getRowsWidth(e){return Math.max(0,...e.map(e=>this.getRowWidth(e)))}getRowWidth(e){return 14+this.visibleLength(String(e.value))+4}visibleLength(e){return e.replace(m,``).length}};function g(){return new h({enabled:!1})}function _(e,t){if(u.default.isAbsolute(t))return u.default.normalize(t);let n;try{let t=new URL(e);if(t.protocol!==`file:`)throw Error(`Unsupported URL protocol "${t.protocol}"`);n=u.default.dirname((0,f.fileURLToPath)(t))}catch{n=e}return u.default.resolve(n,t)}function v(e){let t=_(process.cwd(),e),n=d.default.existsSync(t)&&d.default.statSync(t).isDirectory()?t:u.default.dirname(t);if(!d.default.existsSync(n))throw Error(`Directory "${n}" does not exist.`);return t}function y(e){return e instanceof Error}function b(e,t={}){if(e==null)return{};let{filterNull:n=!0,filterUndefined:r=!0,filterEmptyString:i=!1,filterEmptyObject:a=!1,filterEmptyArray:o=!1}=t;return Object.keys(e).reduce((s,c)=>{let l=e[c];return x(l)&&Object.getPrototypeOf(l)===null&&(l=void 0),C(l)&&(l=b(l,t)),n&&l===null||r&&l===void 0||i&&l===``||a&&S(l)||o&&Array.isArray(l)&&l.length===0||(s[c]=l),s},{})}function x(e){return typeof e==`object`&&!!e}function S(e){return x(e)&&Object.keys(e).length===0}function C(e){return x(e)&&Object.getPrototypeOf(e)===Object.prototype}function w(e){return e==null||[`string`,`number`,`boolean`,`bigint`,`symbol`].includes(typeof e)}Array.prototype.isEmpty=function(){return this==null||this.length===0},String.prototype.capitalized=function(){let e=this==null?``:this.toString();return e.trim()?e.charAt(0).toUpperCase()+e.slice(1):``};const T={filterNull:!0,filterUndefined:!0,filterEmptyString:!0,filterEmptyArray:!0,filterEmptyObject:!0};var E=class{options;instance;constructor(e){this.options=e,this.instance=this.makeInstance()}info(e,t){this.log(`info`,e,t)}debug(e,t){this.log(`debug`,e,t)}trace(e,t){this.log(`trace`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}fatal(e,t){this.log(`fatal`,e,t)}child(e){return this.instance.child(e)}log(e,t,n){this.instance[e]({msg:t,...this.formatLogOptions(n)})}formatLogOptions(e){return e?b({flag:e.flag,details:this.formatUnknown(e.details),error:this.formatUnknown(e.error),metadata:this.formatUnknown(e.metadata)},T):{}}formatUnknown(e){if(y(e)){let t={type:e.constructor.name,message:e.message};this.options.debug&&e.stack&&(t.stack=e.stack);for(let n of Object.keys(e))n in t||(t[n]=e[n]);let n=b(t,T);return S(n)?void 0:n}if(Buffer.isBuffer(e))return`[Buffer]`;if(e&&typeof e.pipe==`function`)return`[Stream]`;if(x(e))try{let t=JSON.stringify(e);if(t===void 0)return;let n=JSON.parse(t);if(Array.isArray(n))return n.length>0?n:void 0;if(x(n)){let e=b(n,T);return S(e)?void 0:e}return n}catch{return{type:`NonSerializableObject`}}return w(e)?e:String(e)}makeInstance(){if(!this.options.enabled)return(0,p.default)({enabled:!1,timestamp:!0});let e=this.options.transports,t={level:this.makeGlobalLogLevel(e),enabled:!0,timestamp:!0,transport:{targets:this.makeTransportTargets(e)}};return(0,p.default)(t)}makeTransportTargets(e){if(e.filter(e=>e.type===`console`).length>1)throw Error(`[Logger] Multiple console transports are not supported.`);return e.map(e=>{switch(e.type){case`console`:return this.makeConsoleTransportTarget(e);case`file`:return this.makeFileTransportTarget(e)}})}makeConsoleTransportTarget(e){return{target:`pino-pretty`,level:this.makeTransportLevel(e.level),options:e.pretty}}makeFileTransportTarget(e){let t=this.makeTransportLevel(e.level),n=u.default.isAbsolute(e.path)?u.default.normalize(e.path):_(process.cwd(),e.path);return v(u.default.dirname(n)),{target:`pino/file`,level:t,options:{destination:n}}}makeTransportLevel(e){return this.options.debug?`trace`:e??`info`}makeGlobalLogLevel(e){if(this.options.debug)return`trace`;let t=e.at(0);if(!t)return`info`;let n={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},r=this.makeTransportLevel(t.level);for(let t of e.slice(1)){let e=this.makeTransportLevel(t.level);n[e]<n[r]&&(r=e)}return r}};function D(e={enabled:!1}){return new E(e)}exports.makeConsoleFixture=g,exports.makeLoggerFixture=D;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Bindings, Level, Logger } from "pino";
|
|
2
|
+
import { PrettyOptions } from "pino-pretty";
|
|
3
|
+
//#region src-node/console/console-options.d.ts
|
|
4
|
+
interface ConsoleOptions {
|
|
5
|
+
readonly enabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src-node/console/console.d.ts
|
|
9
|
+
interface ConsolePanelRow {
|
|
10
|
+
readonly label: string;
|
|
11
|
+
readonly value: string | number;
|
|
12
|
+
}
|
|
13
|
+
declare class Console {
|
|
14
|
+
private readonly instance;
|
|
15
|
+
constructor(options?: ConsoleOptions);
|
|
16
|
+
title(product: string, command: string, rows?: readonly ConsolePanelRow[]): void;
|
|
17
|
+
panel(title: string, rows: readonly ConsolePanelRow[], badge?: string | number): void;
|
|
18
|
+
step(label: string, message: string): string;
|
|
19
|
+
duration(ms: number): string;
|
|
20
|
+
emptyLine(): void;
|
|
21
|
+
log(message?: unknown, ...args: unknown[]): void;
|
|
22
|
+
info(message?: unknown, ...args: unknown[]): void;
|
|
23
|
+
start(message?: unknown, ...args: unknown[]): void;
|
|
24
|
+
success(message?: unknown, ...args: unknown[]): void;
|
|
25
|
+
warn(message?: unknown, ...args: unknown[]): void;
|
|
26
|
+
error(message?: unknown, ...args: unknown[]): void;
|
|
27
|
+
debug(message?: unknown, ...args: unknown[]): void;
|
|
28
|
+
private printPanel;
|
|
29
|
+
private formatPanel;
|
|
30
|
+
private formatPanelTop;
|
|
31
|
+
private formatPanelBottom;
|
|
32
|
+
private formatPanelRow;
|
|
33
|
+
private getPanelWidth;
|
|
34
|
+
private getTitleWidth;
|
|
35
|
+
private getRowsWidth;
|
|
36
|
+
private getRowWidth;
|
|
37
|
+
private visibleLength;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src-node-test/console.d.ts
|
|
41
|
+
declare function makeConsoleFixture(): Console;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src-node/logger/log-flag.d.ts
|
|
44
|
+
declare enum LogFlag {
|
|
45
|
+
Critical = "CRITICAL",
|
|
46
|
+
Serious = "SERIOUS",
|
|
47
|
+
Important = "IMPORTANT",
|
|
48
|
+
Notice = "NOTICE",
|
|
49
|
+
Routine = "ROUTINE"
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src-node/logger/log-options.d.ts
|
|
53
|
+
interface LogOptions {
|
|
54
|
+
readonly flag?: LogFlag;
|
|
55
|
+
readonly details?: unknown;
|
|
56
|
+
readonly error?: unknown;
|
|
57
|
+
readonly metadata?: unknown;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src-node/logger/logger-options.d.ts
|
|
61
|
+
interface BaseLoggerTransportOptions {
|
|
62
|
+
readonly level?: Level;
|
|
63
|
+
}
|
|
64
|
+
interface LoggerConsoleTransportOptions extends BaseLoggerTransportOptions {
|
|
65
|
+
readonly type: 'console';
|
|
66
|
+
readonly target: 'pino-pretty';
|
|
67
|
+
readonly pretty?: PrettyOptions;
|
|
68
|
+
}
|
|
69
|
+
interface LoggerFileTransportOptions extends BaseLoggerTransportOptions {
|
|
70
|
+
readonly type: 'file';
|
|
71
|
+
readonly path: string;
|
|
72
|
+
}
|
|
73
|
+
type LoggerTransportOptions = LoggerConsoleTransportOptions | LoggerFileTransportOptions;
|
|
74
|
+
type LoggerOptions = {
|
|
75
|
+
readonly enabled: false;
|
|
76
|
+
readonly debug?: boolean;
|
|
77
|
+
readonly transports?: never;
|
|
78
|
+
} | {
|
|
79
|
+
readonly enabled: true;
|
|
80
|
+
readonly debug?: boolean;
|
|
81
|
+
readonly transports: readonly [LoggerTransportOptions, ...LoggerTransportOptions[]];
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src-node/logger/logger.d.ts
|
|
85
|
+
interface Logger$1 {
|
|
86
|
+
readonly instance: Logger;
|
|
87
|
+
info(title: string, options?: LogOptions): void;
|
|
88
|
+
debug(title: string, options?: LogOptions): void;
|
|
89
|
+
trace(title: string, options?: LogOptions): void;
|
|
90
|
+
warn(title: string, options?: LogOptions): void;
|
|
91
|
+
error(title: string, options?: LogOptions): void;
|
|
92
|
+
fatal(title: string, options?: LogOptions): void;
|
|
93
|
+
child(bindings: Bindings): Logger;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src-node-test/logger.d.ts
|
|
97
|
+
declare function makeLoggerFixture(options?: LoggerOptions): Logger$1;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { makeConsoleFixture, makeLoggerFixture };
|