@alextheman/utility 5.13.1 → 5.14.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/dist/index.cjs +271 -235
- package/dist/index.d.cts +175 -156
- package/dist/index.d.ts +174 -155
- package/dist/index.js +271 -236
- package/dist/internal/index.cjs +311 -41
- package/dist/internal/index.js +311 -41
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -8,6 +8,10 @@ const DependencyGroup = {
|
|
|
8
8
|
DEV_DEPENDENCIES: "devDependencies"
|
|
9
9
|
};
|
|
10
10
|
//#endregion
|
|
11
|
+
//#region src/root/constants/VERSION_NUMBER_REGEX.ts
|
|
12
|
+
const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
|
|
13
|
+
const VERSION_NUMBER_REGEX = RegExp(`^${VERSION_NUMBER_PATTERN}$`);
|
|
14
|
+
//#endregion
|
|
11
15
|
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
12
16
|
/**
|
|
13
17
|
* Creates a new array where each element is the result of the provided callback.
|
|
@@ -208,53 +212,49 @@ var DataError = class DataError extends CodeError {
|
|
|
208
212
|
}
|
|
209
213
|
};
|
|
210
214
|
//#endregion
|
|
211
|
-
//#region src/root/functions/parsers/
|
|
212
|
-
function _parseZodSchema(parsedResult, input, onError) {
|
|
213
|
-
if (!parsedResult.success) {
|
|
214
|
-
if (onError) {
|
|
215
|
-
if (onError instanceof Error) throw onError;
|
|
216
|
-
else if (typeof onError === "function") {
|
|
217
|
-
const evaluatedError = onError(parsedResult.error);
|
|
218
|
-
if (evaluatedError instanceof Error) throw evaluatedError;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const allErrorCodes = {};
|
|
222
|
-
for (const issue of parsedResult.error.issues) {
|
|
223
|
-
const code = issue.code.toUpperCase();
|
|
224
|
-
allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
|
|
225
|
-
}
|
|
226
|
-
throw new DataError({ input }, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
|
|
227
|
-
return secondCount - firstCount;
|
|
228
|
-
}).map(([code, count], _, allErrorCodes) => {
|
|
229
|
-
return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
|
|
230
|
-
}).join(","), `\n\n${z.prettifyError(parsedResult.error)}\n`);
|
|
231
|
-
}
|
|
232
|
-
return parsedResult.data;
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/root/functions/parsers/zod/parseZodSchema.ts
|
|
215
|
+
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
236
216
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
|
|
217
|
+
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
240
218
|
*
|
|
241
219
|
* @category Parsers
|
|
242
220
|
*
|
|
243
|
-
* @
|
|
244
|
-
* @
|
|
245
|
-
*
|
|
246
|
-
* @param schema - The Zod schema to use in parsing.
|
|
247
|
-
* @param input - The data to parse.
|
|
248
|
-
* @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.
|
|
221
|
+
* @param string - A string to convert into a number.
|
|
222
|
+
* @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.
|
|
249
223
|
*
|
|
250
|
-
* @throws {
|
|
224
|
+
* @throws {DataError} If the provided string cannot safely be converted to an integer.
|
|
251
225
|
*
|
|
252
|
-
* @returns The parsed
|
|
226
|
+
* @returns The integer parsed from the input string.
|
|
253
227
|
*/
|
|
254
|
-
function
|
|
255
|
-
|
|
228
|
+
function parseIntStrict(string, radix) {
|
|
229
|
+
const trimmedString = string.trim();
|
|
230
|
+
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
231
|
+
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
232
|
+
string,
|
|
233
|
+
radix
|
|
234
|
+
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
235
|
+
if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
|
|
236
|
+
return parseInt(character) >= radix;
|
|
237
|
+
})) throw new DataError({
|
|
238
|
+
string,
|
|
239
|
+
radix
|
|
240
|
+
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
241
|
+
const parseIntResult = parseInt(trimmedString, radix);
|
|
242
|
+
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
243
|
+
return parseIntResult;
|
|
256
244
|
}
|
|
257
245
|
//#endregion
|
|
246
|
+
//#region src/root/functions/parsers/parseVersionType.ts
|
|
247
|
+
/**
|
|
248
|
+
* Represents the three common software version types.
|
|
249
|
+
*
|
|
250
|
+
* @category Types
|
|
251
|
+
*/
|
|
252
|
+
const VersionType = {
|
|
253
|
+
MAJOR: "major",
|
|
254
|
+
MINOR: "minor",
|
|
255
|
+
PATCH: "patch"
|
|
256
|
+
};
|
|
257
|
+
//#endregion
|
|
258
258
|
//#region src/root/functions/taggedTemplate/interpolate.ts
|
|
259
259
|
/**
|
|
260
260
|
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
@@ -345,6 +345,276 @@ function normaliseIndents(first, ...args) {
|
|
|
345
345
|
return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
|
|
346
346
|
}
|
|
347
347
|
//#endregion
|
|
348
|
+
//#region src/root/types/VersionNumber.ts
|
|
349
|
+
/**
|
|
350
|
+
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
351
|
+
*
|
|
352
|
+
* @category Types
|
|
353
|
+
*/
|
|
354
|
+
var VersionNumber = class VersionNumber {
|
|
355
|
+
static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
|
|
356
|
+
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
357
|
+
major = 0;
|
|
358
|
+
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
359
|
+
minor = 0;
|
|
360
|
+
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
361
|
+
patch = 0;
|
|
362
|
+
/**
|
|
363
|
+
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
364
|
+
*/
|
|
365
|
+
constructor(input) {
|
|
366
|
+
if (input instanceof VersionNumber) {
|
|
367
|
+
this.major = input.major;
|
|
368
|
+
this.minor = input.minor;
|
|
369
|
+
this.patch = input.patch;
|
|
370
|
+
} else if (typeof input === "string") {
|
|
371
|
+
if (!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.`);
|
|
372
|
+
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
373
|
+
return parseIntStrict(number);
|
|
374
|
+
});
|
|
375
|
+
this.major = major;
|
|
376
|
+
this.minor = minor;
|
|
377
|
+
this.patch = patch;
|
|
378
|
+
} else if (Array.isArray(input)) {
|
|
379
|
+
if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
380
|
+
const [major, minor, patch] = input.map((number) => {
|
|
381
|
+
const parsedInteger = parseIntStrict(number?.toString());
|
|
382
|
+
if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
383
|
+
return parsedInteger;
|
|
384
|
+
});
|
|
385
|
+
this.major = major;
|
|
386
|
+
this.minor = minor;
|
|
387
|
+
this.patch = patch;
|
|
388
|
+
} else throw new DataError({ input }, "INVALID_INPUT", normaliseIndents`
|
|
389
|
+
The provided input can not be parsed into a valid version number.
|
|
390
|
+
Expected either a string of format X.Y.Z or vX.Y.Z, a tuple of three numbers, or another \`VersionNumber\` instance.
|
|
391
|
+
`);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Gets the current version type of the current instance of `VersionNumber`.
|
|
395
|
+
*
|
|
396
|
+
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
397
|
+
*/
|
|
398
|
+
get type() {
|
|
399
|
+
if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
|
|
400
|
+
if (this.patch === 0) return VersionType.MINOR;
|
|
401
|
+
return VersionType.PATCH;
|
|
402
|
+
}
|
|
403
|
+
static formatString(input, options) {
|
|
404
|
+
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
405
|
+
return input.startsWith("v") ? input : `v${input}`;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
409
|
+
*
|
|
410
|
+
* @param firstVersion - The first version number to compare.
|
|
411
|
+
* @param secondVersion - The second version number to compare.
|
|
412
|
+
*
|
|
413
|
+
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
414
|
+
*/
|
|
415
|
+
static isEqual(firstVersion, secondVersion) {
|
|
416
|
+
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Get a formatted string representation of the current version number
|
|
420
|
+
*
|
|
421
|
+
* @param options - Options to apply to the string formatting.
|
|
422
|
+
*
|
|
423
|
+
* @returns A formatted string representation of the current version number with the options applied.
|
|
424
|
+
*/
|
|
425
|
+
format(options) {
|
|
426
|
+
let baseOutput = `${this.major}`;
|
|
427
|
+
if (!options?.omitMinor) {
|
|
428
|
+
baseOutput += `.${this.minor}`;
|
|
429
|
+
if (!options?.omitPatch) baseOutput += `.${this.patch}`;
|
|
430
|
+
}
|
|
431
|
+
return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
435
|
+
*
|
|
436
|
+
* @param incrementType - The type of increment. Can be one of the following:
|
|
437
|
+
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
438
|
+
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
439
|
+
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
440
|
+
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
441
|
+
*
|
|
442
|
+
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
443
|
+
*/
|
|
444
|
+
increment(incrementType, incrementAmount = 1) {
|
|
445
|
+
const incrementBy = parseIntStrict(String(incrementAmount));
|
|
446
|
+
const calculatedRawVersion = {
|
|
447
|
+
major: [
|
|
448
|
+
this.major + incrementBy,
|
|
449
|
+
0,
|
|
450
|
+
0
|
|
451
|
+
],
|
|
452
|
+
minor: [
|
|
453
|
+
this.major,
|
|
454
|
+
this.minor + incrementBy,
|
|
455
|
+
0
|
|
456
|
+
],
|
|
457
|
+
patch: [
|
|
458
|
+
this.major,
|
|
459
|
+
this.minor,
|
|
460
|
+
this.patch + incrementBy
|
|
461
|
+
]
|
|
462
|
+
}[incrementType];
|
|
463
|
+
try {
|
|
464
|
+
return new VersionNumber(calculatedRawVersion);
|
|
465
|
+
} catch (error) {
|
|
466
|
+
if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
|
|
467
|
+
currentVersion: this.toString(),
|
|
468
|
+
calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
|
|
469
|
+
incrementAmount
|
|
470
|
+
}, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
|
|
471
|
+
else throw error;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
476
|
+
*
|
|
477
|
+
* @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).
|
|
478
|
+
*
|
|
479
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
480
|
+
*/
|
|
481
|
+
[Symbol.toPrimitive](hint) {
|
|
482
|
+
if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
483
|
+
return this.toString();
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
|
|
487
|
+
*
|
|
488
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
489
|
+
*/
|
|
490
|
+
toJSON() {
|
|
491
|
+
return this.toString();
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Get a string representation of the current version number.
|
|
495
|
+
*
|
|
496
|
+
* @returns A stringified representation of the current version number with the prefix.
|
|
497
|
+
*/
|
|
498
|
+
toString() {
|
|
499
|
+
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
500
|
+
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
const zodVersionNumber = z.union([
|
|
504
|
+
z.string(),
|
|
505
|
+
z.tuple([
|
|
506
|
+
z.number(),
|
|
507
|
+
z.number(),
|
|
508
|
+
z.number()
|
|
509
|
+
]),
|
|
510
|
+
z.instanceof(VersionNumber)
|
|
511
|
+
]).transform((rawVersionNumber) => {
|
|
512
|
+
return new VersionNumber(rawVersionNumber);
|
|
513
|
+
});
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region src/root/zod/_parseZodSchema.ts
|
|
516
|
+
function _parseZodSchema(parsedResult, input, onError) {
|
|
517
|
+
if (!parsedResult.success) {
|
|
518
|
+
if (onError) {
|
|
519
|
+
if (onError instanceof Error) throw onError;
|
|
520
|
+
else if (typeof onError === "function") {
|
|
521
|
+
const evaluatedError = onError(parsedResult.error);
|
|
522
|
+
if (evaluatedError instanceof Error) throw evaluatedError;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
const allErrorCodes = {};
|
|
526
|
+
for (const issue of parsedResult.error.issues) {
|
|
527
|
+
const code = issue.code.toUpperCase();
|
|
528
|
+
allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
|
|
529
|
+
}
|
|
530
|
+
throw new DataError({ input }, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
|
|
531
|
+
return secondCount - firstCount;
|
|
532
|
+
}).map(([code, count], _, allErrorCodes) => {
|
|
533
|
+
return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
|
|
534
|
+
}).join(","), `\n\n${z.prettifyError(parsedResult.error)}\n`);
|
|
535
|
+
}
|
|
536
|
+
return parsedResult.data;
|
|
537
|
+
}
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region src/root/zod/parseZodSchema.ts
|
|
540
|
+
/**
|
|
541
|
+
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
542
|
+
*
|
|
543
|
+
* NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
|
|
544
|
+
*
|
|
545
|
+
* @category Parsers
|
|
546
|
+
*
|
|
547
|
+
* @deprecated Please use `az.with(schema).parse(input)` instead.
|
|
548
|
+
*
|
|
549
|
+
* @template SchemaType - The Zod schema type.
|
|
550
|
+
* @template ErrorType - The type of error to throw on invalid data.
|
|
551
|
+
*
|
|
552
|
+
* @param schema - The Zod schema to use in parsing.
|
|
553
|
+
* @param input - The data to parse.
|
|
554
|
+
* @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.
|
|
555
|
+
*
|
|
556
|
+
* @throws {DataErrorCode} If the given data cannot be parsed according to the schema.
|
|
557
|
+
*
|
|
558
|
+
* @returns The parsed data from the Zod schema.
|
|
559
|
+
*/
|
|
560
|
+
function parseZodSchema(schema, input, onError) {
|
|
561
|
+
return _parseZodSchema(schema.safeParse(input), input, onError);
|
|
562
|
+
}
|
|
563
|
+
//#endregion
|
|
564
|
+
//#region src/root/zod/parseZodSchemaAsync.ts
|
|
565
|
+
/**
|
|
566
|
+
* An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
|
|
567
|
+
*
|
|
568
|
+
* @category Parsers
|
|
569
|
+
*
|
|
570
|
+
* @deprecated Please use `az.with(schema).parseAsync(input)` instead.
|
|
571
|
+
*
|
|
572
|
+
* @template SchemaType - The Zod schema type.
|
|
573
|
+
* @template ErrorType - The type of error to throw on invalid data.
|
|
574
|
+
*
|
|
575
|
+
* @param schema - The Zod schema to use in parsing.
|
|
576
|
+
* @param input - The data to parse.
|
|
577
|
+
* @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.
|
|
578
|
+
*
|
|
579
|
+
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
580
|
+
*
|
|
581
|
+
* @returns The parsed data from the Zod schema.
|
|
582
|
+
*/
|
|
583
|
+
async function parseZodSchemaAsync(schema, input, onError) {
|
|
584
|
+
return _parseZodSchema(await schema.safeParseAsync(input), input, onError);
|
|
585
|
+
}
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region src/root/zod/zodFieldWrapper.ts
|
|
588
|
+
function zodFieldWrapper(schema) {
|
|
589
|
+
return z.string().trim().transform((value) => {
|
|
590
|
+
return value === "" ? null : value;
|
|
591
|
+
}).pipe(schema);
|
|
592
|
+
}
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/root/zod/az.ts
|
|
595
|
+
const az = {
|
|
596
|
+
field: zodFieldWrapper,
|
|
597
|
+
fieldNumber: () => {
|
|
598
|
+
return z.coerce.number();
|
|
599
|
+
},
|
|
600
|
+
versionNumber: () => {
|
|
601
|
+
return zodVersionNumber;
|
|
602
|
+
},
|
|
603
|
+
fieldDate: () => {
|
|
604
|
+
return z.coerce.date();
|
|
605
|
+
},
|
|
606
|
+
with: (schema) => {
|
|
607
|
+
return {
|
|
608
|
+
parse: (input, error) => {
|
|
609
|
+
return parseZodSchema(schema, input, error);
|
|
610
|
+
},
|
|
611
|
+
parseAsync: async (input, error) => {
|
|
612
|
+
return await parseZodSchemaAsync(schema, input, error);
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
//#endregion
|
|
348
618
|
//#region src/internal/getDependenciesFromGroup.ts
|
|
349
619
|
/**
|
|
350
620
|
* Get the dependencies from a given dependency group in `package.json`.
|
|
@@ -358,8 +628,8 @@ function normaliseIndents(first, ...args) {
|
|
|
358
628
|
*/
|
|
359
629
|
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
360
630
|
return {
|
|
361
|
-
dependencies:
|
|
362
|
-
devDependencies:
|
|
631
|
+
dependencies: az.with(z.record(z.string(), z.string())).parse(packageInfo.dependencies ?? {}),
|
|
632
|
+
devDependencies: az.with(z.record(z.string(), z.string())).parse(packageInfo.devDependencies ?? {})
|
|
363
633
|
}[dependencyGroup];
|
|
364
634
|
}
|
|
365
635
|
//#endregion
|
|
@@ -367,7 +637,7 @@ function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
|
367
637
|
async function getExpectedTgzName(packagePath, packageManager) {
|
|
368
638
|
const { stdout: rawPackedTgzData } = await execa({ cwd: packagePath })`${packageManager} pack --json --dry-run`;
|
|
369
639
|
const packedTgzData = parseJsonFromStdout(rawPackedTgzData);
|
|
370
|
-
const parsedPackedTgzData =
|
|
640
|
+
const parsedPackedTgzData = az.with(packageManager === "pnpm" ? z.object({ filename: z.string() }) : z.array(z.object({ filename: z.string() }))).parse(packedTgzData, new DataError(packedTgzData, "AMBIGUOUS_EXPECTED_FILE_NAME", "Could not figure out the expected filename."));
|
|
371
641
|
const [normalisedTgzMetadata] = Array.isArray(parsedPackedTgzData) ? parsedPackedTgzData : [parsedPackedTgzData];
|
|
372
642
|
const { filename: expectedTgzFileName } = normalisedTgzMetadata;
|
|
373
643
|
return expectedTgzFileName;
|