@alextheman/utility 4.16.2 → 5.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.
@@ -0,0 +1,28 @@
1
+ import z from "zod";
2
+
3
+ //#region src/internal/getExpectedTgzName.d.ts
4
+ declare function getExpectedTgzName(packagePath: string, packageManager: string): Promise<string>;
5
+ //#endregion
6
+ //#region src/internal/getPackageJsonContents.d.ts
7
+ declare function getPackageJsonContents(directory: string): Promise<Record<string, any> | null>;
8
+ //#endregion
9
+ //#region src/internal/getPackageJsonPath.d.ts
10
+ declare function getPackageJsonPath(directory: string): string;
11
+ //#endregion
12
+ //#region src/internal/parseJsonFromStdout.d.ts
13
+ declare function parseJsonFromStdout(stdout: string): Record<string, unknown>;
14
+ //#endregion
15
+ //#region src/root/types/IsTypeArgumentString.d.ts
16
+ type IsTypeArgumentString<Argument extends string> = Argument;
17
+ //#endregion
18
+ //#region src/root/functions/miscellaneous/sayHello.d.ts
19
+ /**
20
+ * Returns a string representing the lyrics to the package's theme song, Commit To You
21
+ *
22
+ * [Pls listen!](https://www.youtube.com/watch?v=mH-Sg-8EnxM)
23
+ *
24
+ * @returns The lyrics string in markdown format.
25
+ */
26
+ declare function sayHello(): string;
27
+ //#endregion
28
+ export { type IsTypeArgumentString, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, parseJsonFromStdout, sayHello };
@@ -0,0 +1,616 @@
1
+ import { execa } from "execa";
2
+ import z from "zod";
3
+ import path from "node:path";
4
+ import "libsodium-wrappers";
5
+ import { readFile } from "node:fs/promises";
6
+
7
+ //#region src/root/functions/arrayHelpers/fillArray.ts
8
+ /**
9
+ * Creates a new array where each element is the result of the provided callback.
10
+ *
11
+ * If the callback returns at least one Promise, the entire result will be wrapped
12
+ * in a `Promise` and resolved with `Promise.all`. Otherwise, a plain array is returned.
13
+ *
14
+ * @category Array Helpers
15
+ *
16
+ * @template ItemType - The return type of the callback (awaited if any items are a Promise) that becomes the type of the array items.
17
+ *
18
+ * @param callback - A function invoked with the current index. May return a value or a Promise.
19
+ * @param length - The desired length of the resulting array.
20
+ *
21
+ * @returns An array of the callback results, or a Promise resolving to one if the callback is async.
22
+ */
23
+ function fillArray(callback, length = 1) {
24
+ const outputArray = new Array(length).fill(null).map((_, index) => {
25
+ return callback(index);
26
+ });
27
+ if (outputArray.some((item) => {
28
+ return item instanceof Promise;
29
+ })) return Promise.all(outputArray);
30
+ return outputArray;
31
+ }
32
+
33
+ //#endregion
34
+ //#region src/root/functions/arrayHelpers/paralleliseArrays.ts
35
+ /**
36
+ * Creates a new array of tuples, each containing the item at the given index from both arrays.
37
+ *
38
+ * If `secondArray` is shorter than `firstArray`, the second position in the tuple
39
+ * will be `undefined`. Iteration always uses the length of the first array.
40
+ *
41
+ * @category Array Helpers
42
+ *
43
+ * @template FirstArrayItem
44
+ * @template SecondArrayItem
45
+ *
46
+ * @param firstArray - The first array. Each item in this will take up the first tuple spot.
47
+ * @param secondArray - The second array. Each item in this will take up the second tuple spot.
48
+ *
49
+ * @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
50
+ */
51
+ function paralleliseArrays(firstArray, secondArray) {
52
+ const outputArray = [];
53
+ for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
54
+ return outputArray;
55
+ }
56
+
57
+ //#endregion
58
+ //#region src/root/types/DataError.ts
59
+ /**
60
+ * Represents errors you may get that may've been caused by a specific piece of data.
61
+ *
62
+ * @category Types
63
+ *
64
+ * @template DataType - The type of the data that caused the error.
65
+ */
66
+ var DataError = class DataError extends Error {
67
+ code;
68
+ data;
69
+ /**
70
+ * @param data - The data that caused the error.
71
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
72
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
73
+ * @param options - Extra options to pass to super Error constructor.
74
+ */
75
+ constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
76
+ super(message, options);
77
+ if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
78
+ this.name = new.target.name;
79
+ this.code = code;
80
+ this.data = data;
81
+ Object.defineProperty(this, "message", { enumerable: true });
82
+ Object.setPrototypeOf(this, new.target.prototype);
83
+ }
84
+ /**
85
+ * Checks whether the given input may have been caused by a DataError.
86
+ *
87
+ * @param input - The input to check.
88
+ *
89
+ * @returns `true` if the input is a DataError, and `false` otherwise. The type of the input will also be narrowed down to DataError if `true`.
90
+ */
91
+ static check(input) {
92
+ if (input instanceof DataError) return true;
93
+ const data = input;
94
+ return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
95
+ }
96
+ };
97
+
98
+ //#endregion
99
+ //#region src/root/constants/FILE_PATH_REGEX.ts
100
+ const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
101
+
102
+ //#endregion
103
+ //#region src/root/constants/VERSION_NUMBER_REGEX.ts
104
+ const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
105
+
106
+ //#endregion
107
+ //#region src/root/types/VersionNumber.ts
108
+ /**
109
+ * Represents a software version number, considered to be made up of a major, minor, and patch part.
110
+ *
111
+ * @category Types
112
+ */
113
+ var VersionNumber = class VersionNumber {
114
+ static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
115
+ /** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
116
+ major = 0;
117
+ /** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
118
+ minor = 0;
119
+ /** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
120
+ patch = 0;
121
+ /**
122
+ * @param input - The input to create a new instance of `VersionNumber` from.
123
+ */
124
+ constructor(input) {
125
+ if (input instanceof VersionNumber) {
126
+ this.major = input.major;
127
+ this.minor = input.minor;
128
+ this.patch = input.patch;
129
+ } else if (typeof input === "string") {
130
+ if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
131
+ const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
132
+ return parseIntStrict(number);
133
+ });
134
+ this.major = major;
135
+ this.minor = minor;
136
+ this.patch = patch;
137
+ } else if (Array.isArray(input)) {
138
+ if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
139
+ const [major, minor, patch] = input.map((number) => {
140
+ const parsedInteger = parseIntStrict(number?.toString());
141
+ if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
142
+ return parsedInteger;
143
+ });
144
+ this.major = major;
145
+ this.minor = minor;
146
+ this.patch = patch;
147
+ }
148
+ }
149
+ /**
150
+ * Gets the current version type of the current instance of `VersionNumber`.
151
+ *
152
+ * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
153
+ */
154
+ get type() {
155
+ if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
156
+ if (this.patch === 0) return VersionType.MINOR;
157
+ return VersionType.PATCH;
158
+ }
159
+ static formatString(input, options) {
160
+ if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
161
+ return input.startsWith("v") ? input : `v${input}`;
162
+ }
163
+ /**
164
+ * Checks if the provided version numbers have the exact same major, minor, and patch numbers.
165
+ *
166
+ * @param firstVersion - The first version number to compare.
167
+ * @param secondVersion - The second version number to compare.
168
+ *
169
+ * @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
170
+ */
171
+ static isEqual(firstVersion, secondVersion) {
172
+ return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
173
+ }
174
+ /**
175
+ * Get a formatted string representation of the current version number
176
+ *
177
+ * @param options - Options to apply to the string formatting.
178
+ *
179
+ * @returns A formatted string representation of the current version number with the options applied.
180
+ */
181
+ format(options) {
182
+ let baseOutput = `${this.major}`;
183
+ if (!options?.omitMinor) {
184
+ baseOutput += `.${this.minor}`;
185
+ if (!options?.omitPatch) baseOutput += `.${this.patch}`;
186
+ }
187
+ return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
188
+ }
189
+ /**
190
+ * Increments the current version number by the given increment type, returning the result as a new reference in memory.
191
+ *
192
+ * @param incrementType - The type of increment. Can be one of the following:
193
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
194
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
195
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
196
+ * @param incrementAmount - The amount to increment by (defaults to 1).
197
+ *
198
+ * @returns A new instance of `VersionNumber` with the increment applied.
199
+ */
200
+ increment(incrementType, incrementAmount = 1) {
201
+ const incrementBy = parseIntStrict(String(incrementAmount));
202
+ const calculatedRawVersion = {
203
+ major: [
204
+ this.major + incrementBy,
205
+ 0,
206
+ 0
207
+ ],
208
+ minor: [
209
+ this.major,
210
+ this.minor + incrementBy,
211
+ 0
212
+ ],
213
+ patch: [
214
+ this.major,
215
+ this.minor,
216
+ this.patch + incrementBy
217
+ ]
218
+ }[incrementType];
219
+ try {
220
+ return new VersionNumber(calculatedRawVersion);
221
+ } catch (error) {
222
+ if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
223
+ currentVersion: this.toString(),
224
+ calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
225
+ incrementAmount
226
+ }, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
227
+ else throw error;
228
+ }
229
+ }
230
+ /**
231
+ * Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
232
+ *
233
+ * @param hint - Not used as of now, but generally used to help with numeric coercion, I think (which we most likely do not need for version numbers).
234
+ *
235
+ * @returns A stringified representation of the current version number, prefixed with `v`.
236
+ */
237
+ [Symbol.toPrimitive](hint) {
238
+ if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
239
+ return this.toString();
240
+ }
241
+ /**
242
+ * Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
243
+ *
244
+ * @returns A stringified representation of the current version number, prefixed with `v`.
245
+ */
246
+ toJSON() {
247
+ return this.toString();
248
+ }
249
+ /**
250
+ * Get a string representation of the current version number.
251
+ *
252
+ * @returns A stringified representation of the current version number with the prefix.
253
+ */
254
+ toString() {
255
+ const rawString = `${this.major}.${this.minor}.${this.patch}`;
256
+ return VersionNumber.formatString(rawString, { omitPrefix: false });
257
+ }
258
+ };
259
+ const zodVersionNumber = z.union([
260
+ z.string(),
261
+ z.tuple([
262
+ z.number(),
263
+ z.number(),
264
+ z.number()
265
+ ]),
266
+ z.instanceof(VersionNumber)
267
+ ]).transform((rawVersionNumber) => {
268
+ return new VersionNumber(rawVersionNumber);
269
+ });
270
+
271
+ //#endregion
272
+ //#region src/root/functions/parsers/parseIntStrict.ts
273
+ /**
274
+ * Converts a string to an integer and throws an error if it cannot be converted.
275
+ *
276
+ * @category Parsers
277
+ *
278
+ * @param string - A string to convert into a number.
279
+ * @param radix - A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
280
+ *
281
+ * @throws {DataError} If the provided string cannot safely be converted to an integer.
282
+ *
283
+ * @returns The integer parsed from the input string.
284
+ */
285
+ function parseIntStrict(string, radix) {
286
+ const trimmedString = string.trim();
287
+ const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
288
+ if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
289
+ string,
290
+ radix
291
+ } : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
292
+ if (radix && radix < 10 && [...trimmedString].some((character) => {
293
+ return parseInt(character) >= radix;
294
+ })) throw new DataError({
295
+ string,
296
+ radix
297
+ }, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
298
+ const parseIntResult = parseInt(trimmedString, radix);
299
+ if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
300
+ return parseIntResult;
301
+ }
302
+
303
+ //#endregion
304
+ //#region src/root/functions/taggedTemplate/interpolate.ts
305
+ /**
306
+ * Returns the result of interpolating a template string when given the strings and interpolations separately.
307
+ *
308
+ * You can pass a template string directly by doing:
309
+ *
310
+ * ```
311
+ * interpolate`Template string here`;
312
+ * ```
313
+ *
314
+ * In this case, it will be functionally the same as if you just wrote the template string by itself.
315
+ *
316
+ * @category Tagged Template
317
+ *
318
+ * @template InterpolationsType - The type of the interpolations.
319
+ *
320
+ * @param strings - The strings from the template to process.
321
+ * @param interpolations - An array of all interpolations from the template.
322
+ *
323
+ * @returns A new string with the strings and interpolations from the template applied.
324
+ */
325
+ function interpolate(strings, ...interpolations) {
326
+ let result = "";
327
+ for (const [string, interpolation = ""] of paralleliseArrays(strings, interpolations)) result += string + interpolation;
328
+ return result;
329
+ }
330
+
331
+ //#endregion
332
+ //#region src/root/functions/taggedTemplate/normaliseIndents.ts
333
+ function calculateTabSize(line, whitespaceLength) {
334
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
335
+ const trimmedString = line.trimStart();
336
+ if (potentialWhitespacePart.trim() !== "") return 0;
337
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
338
+ return tabSize < 0 ? 0 : tabSize;
339
+ }
340
+ function getWhitespaceLength(lines) {
341
+ const [firstNonEmptyLine] = lines.filter((line) => {
342
+ return line.trim() !== "";
343
+ });
344
+ return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
345
+ }
346
+ function reduceLines(lines, { preserveTabs = true }) {
347
+ const slicedLines = lines.slice(1);
348
+ const isFirstLineEmpty = lines[0].trim() === "";
349
+ const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
350
+ return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
351
+ const tabSize = calculateTabSize(line, whitespaceLength);
352
+ return (preserveTabs ? fillArray(() => {
353
+ return " ";
354
+ }, tabSize).join("") : "") + line.trimStart();
355
+ }).join("\n");
356
+ }
357
+ /**
358
+ * Applies any options if provided, then removes any extraneous indents from a multi-line template string.
359
+ *
360
+ * You can pass a template string directly by doing:
361
+ *
362
+ * ```typescript
363
+ * normaliseIndents`Template string here
364
+ * with a new line
365
+ * and another new line`;
366
+ * ```
367
+ *
368
+ * You may also pass the options first, then invoke the resulting function with a template string:
369
+ *
370
+ * ```typescript
371
+ * normaliseIndents({ preserveTabs: false })`Template string here
372
+ * with a new line
373
+ * and another new line`;
374
+ * ```
375
+ *
376
+ * @category Tagged Template
377
+ *
378
+ * @param first - The strings from the template to process, or the options to apply.
379
+ * @param args - An array of all interpolations from the template.
380
+ *
381
+ * @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
382
+ */
383
+ function normaliseIndents(first, ...args) {
384
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
385
+ const options = first;
386
+ return (strings, ...interpolations) => {
387
+ return normaliseIndents(strings, ...interpolations, options);
388
+ };
389
+ }
390
+ const strings = first;
391
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
392
+ return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
393
+ }
394
+
395
+ //#endregion
396
+ //#region src/root/functions/miscellaneous/sayHello.ts
397
+ /**
398
+ * Returns a string representing the lyrics to the package's theme song, Commit To You
399
+ *
400
+ * [Pls listen!](https://www.youtube.com/watch?v=mH-Sg-8EnxM)
401
+ *
402
+ * @returns The lyrics string in markdown format.
403
+ */
404
+ function sayHello() {
405
+ return normaliseIndents`
406
+ # Commit To You
407
+
408
+ ### Verse 1
409
+
410
+ I know you've been checking me out,
411
+ Shall we take it to the next level now?
412
+ 'Cause I really wanna be there all for you,
413
+ All for you!
414
+ Come on now, let's make a fresh start!
415
+ Pin my number, then you can take me out!
416
+ Can't you see I really do care about you,
417
+ About you!
418
+
419
+ ### Pre-chorus 1
420
+ Although our calendars are imperfect, at best,
421
+ I'd like to organise time with you! (with you!).
422
+ Just tell me when and I'll make it clear,
423
+ All clear for you,
424
+ All clear for you!
425
+ (One, two, three, go!)
426
+
427
+ ### Chorus
428
+ I wanna be of utility, I'll help you on the run!
429
+ I'll be the one here in the back, while you go have some fun!
430
+ Looking out for you tonight, I'll be the one you can rely on!
431
+ Watch you go and watch me pass by,
432
+ I'll be here!
433
+ I'll commit to you!
434
+
435
+ ### Verse 2
436
+ Though sometimes it won't be easy,
437
+ You'll be here to bring out the best in me,
438
+ And I'll hold myself to high standards for you!
439
+ All for you!
440
+ We'll grow as a pair, you and me,
441
+ We'll build up a healthy dependency,
442
+ You can build with me and I'll develop with you!
443
+ I'm with you!
444
+
445
+ ### Pre-chorus 2
446
+ I'll be with you when you're up or you're down,
447
+ We'll deal with all our problems together (together!)
448
+ Just tell me what you want, I'll make it clear,
449
+ All clear for you,
450
+ All clear for you!
451
+ (One, three, one, go!)
452
+
453
+ ### Chorus
454
+ I wanna be of utility, I'll help you on the run!
455
+ (help you on the run!)
456
+ I'll be the one here in the back, while you go have some fun!
457
+ (you go have some fun!)
458
+ Looking out for you tonight, I'll be the one you can rely on!
459
+ Watch you go and watch me pass by,
460
+ I'll be here!
461
+ I'll commit to you!
462
+
463
+ ### Bridge
464
+ Looking into our stack!
465
+ I'll commit to you!
466
+ We've got a lot to unpack!
467
+ I'll commit to you!
468
+ The environment that we're in!
469
+ I'll commit to you!
470
+ Delicate as a string!
471
+ I'll commit to you!
472
+
473
+ But I think you're my type!
474
+ I'll commit to you!
475
+ Oh, this feels all so right!
476
+ I'll commit to you!
477
+ Nothing stopping us now!
478
+ I'll commit to you!
479
+ Let's show them what we're about!
480
+ Two, three, four, go!
481
+
482
+ ### Final Chorus
483
+ I wanna be of utility, I'll help you on the run!
484
+ (help you on the run!)
485
+ I'll be the one here in the back, while you go have some fun!
486
+ (you go have some fun!)
487
+ Looking out for you tonight, I'll be the one you can rely on!
488
+ Watch you go and watch me pass by,
489
+ I'll be here!
490
+ I'll commit to you!
491
+
492
+ I wanna be of utility, I'll help you on the run!
493
+ (I'll commit to you!)
494
+ I'll be the one here in the back, while you go have some fun!
495
+ (I'll commit to you!)
496
+ Looking out for you tonight, I'll be the one you can rely on!
497
+ (I'll commit to you!)
498
+ Watch you go and watch me pass by,
499
+ (I'll commit to you!)
500
+ I'll be here!
501
+
502
+ ### Outro
503
+ I'll commit to you!
504
+ I'll commit to you!
505
+ I'll commit to you!
506
+ `;
507
+ }
508
+
509
+ //#endregion
510
+ //#region src/root/functions/parsers/zod/_parseZodSchema.ts
511
+ function _parseZodSchema(parsedResult, input, onError) {
512
+ if (!parsedResult.success) {
513
+ if (onError) {
514
+ if (onError instanceof Error) throw onError;
515
+ else if (typeof onError === "function") {
516
+ const evaluatedError = onError(parsedResult.error);
517
+ if (evaluatedError instanceof Error) throw evaluatedError;
518
+ }
519
+ }
520
+ const allErrorCodes = {};
521
+ for (const issue of parsedResult.error.issues) {
522
+ const code = issue.code.toUpperCase();
523
+ allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
524
+ }
525
+ throw new DataError({ input }, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
526
+ return secondCount - firstCount;
527
+ }).map(([code, count], _, allErrorCodes) => {
528
+ return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
529
+ }).join(","), `\n\n${z.prettifyError(parsedResult.error)}\n`);
530
+ }
531
+ return parsedResult.data;
532
+ }
533
+
534
+ //#endregion
535
+ //#region src/root/functions/parsers/zod/parseZodSchema.ts
536
+ /**
537
+ * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
538
+ *
539
+ * NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
540
+ *
541
+ * @category Parsers
542
+ *
543
+ * @template SchemaType - The Zod schema type.
544
+ * @template ErrorType - The type of error to throw on invalid data.
545
+ *
546
+ * @param schema - The Zod schema to use in parsing.
547
+ * @param input - The data to parse.
548
+ * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
549
+ *
550
+ * @throws {DataError} If the given data cannot be parsed according to the schema.
551
+ *
552
+ * @returns The parsed data from the Zod schema.
553
+ */
554
+ function parseZodSchema(schema, input, onError) {
555
+ return _parseZodSchema(schema.safeParse(input), input, onError);
556
+ }
557
+
558
+ //#endregion
559
+ //#region src/root/functions/parsers/parseVersionType.ts
560
+ /**
561
+ * Represents the three common software version types.
562
+ *
563
+ * @category Types
564
+ */
565
+ const VersionType = {
566
+ MAJOR: "major",
567
+ MINOR: "minor",
568
+ PATCH: "patch"
569
+ };
570
+
571
+ //#endregion
572
+ //#region src/internal/getExpectedTgzName.ts
573
+ async function getExpectedTgzName(packagePath, packageManager) {
574
+ const { stdout: rawPackedTgzData } = await execa({ cwd: packagePath })`${packageManager} pack --json --dry-run`;
575
+ const packedTgzData = parseJsonFromStdout(rawPackedTgzData);
576
+ const parsedPackedTgzData = parseZodSchema(packageManager === "pnpm" ? z.object({ filename: z.string() }) : z.array(z.object({ filename: z.string() })), packedTgzData, new DataError(packedTgzData, "AMBIGUOUS_EXPECTED_FILE_NAME", "Could not figure out the expected filename."));
577
+ const [normalisedTgzMetadata] = Array.isArray(parsedPackedTgzData) ? parsedPackedTgzData : [parsedPackedTgzData];
578
+ const { filename: expectedTgzFileName } = normalisedTgzMetadata;
579
+ return expectedTgzFileName;
580
+ }
581
+
582
+ //#endregion
583
+ //#region src/internal/getPackageJsonPath.ts
584
+ function getPackageJsonPath(directory) {
585
+ return path.join(...directory.endsWith("package.json") ? [directory] : [directory, "package.json"]);
586
+ }
587
+
588
+ //#endregion
589
+ //#region src/internal/getPackageJsonContents.ts
590
+ async function getPackageJsonContents(directory) {
591
+ try {
592
+ return JSON.parse(await readFile(getPackageJsonPath(directory), "utf-8"));
593
+ } catch (error) {
594
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") return null;
595
+ throw error;
596
+ }
597
+ }
598
+
599
+ //#endregion
600
+ //#region src/internal/parseJsonFromStdout.ts
601
+ function parseJsonFromStdout(stdout) {
602
+ const start = Math.min(...["[", "{"].map((character) => {
603
+ return stdout.indexOf(character);
604
+ }).filter((index) => {
605
+ return index !== -1;
606
+ }));
607
+ if (!Number.isFinite(start)) throw new DataError({ stdout }, "NO_JSON_FOUND_IN_OUTPUT", "No JSON found in output");
608
+ return JSON.parse(stdout.slice(start));
609
+ }
610
+
611
+ //#endregion
612
+ //#region src/internal/sayHello.ts
613
+ var sayHello_default = sayHello;
614
+
615
+ //#endregion
616
+ export { getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, parseJsonFromStdout, sayHello_default as sayHello };