@alextheman/utility 5.0.0 → 5.0.1
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 +19 -19
- package/dist/index.d.cts +20 -18
- package/dist/index.d.ts +20 -18
- package/dist/index.js +19 -19
- package/dist/internal/index.cjs +51 -1
- package/dist/internal/index.d.cts +91 -10
- package/dist/internal/index.d.ts +90 -10
- package/dist/internal/index.js +47 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -615,6 +615,25 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
615
615
|
return firstDate.getDate() === secondDate.getDate();
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
+
//#endregion
|
|
619
|
+
//#region src/internal/getDependenciesFromGroup.ts
|
|
620
|
+
/**
|
|
621
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
622
|
+
*
|
|
623
|
+
* @category Miscellaneous
|
|
624
|
+
*
|
|
625
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
626
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
627
|
+
*
|
|
628
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
629
|
+
*/
|
|
630
|
+
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
631
|
+
return {
|
|
632
|
+
dependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.dependencies ?? {}),
|
|
633
|
+
devDependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.devDependencies ?? {})
|
|
634
|
+
}[dependencyGroup];
|
|
635
|
+
}
|
|
636
|
+
|
|
618
637
|
//#endregion
|
|
619
638
|
//#region src/root/functions/miscellaneous/convertFileToBase64.ts
|
|
620
639
|
/**
|
|
@@ -714,25 +733,6 @@ function createFormData(data, options = {
|
|
|
714
733
|
return formData;
|
|
715
734
|
}
|
|
716
735
|
|
|
717
|
-
//#endregion
|
|
718
|
-
//#region src/root/functions/miscellaneous/getDependenciesFromGroup.ts
|
|
719
|
-
/**
|
|
720
|
-
* Get the dependencies from a given dependency group in `package.json`.
|
|
721
|
-
*
|
|
722
|
-
* @category Miscellaneous
|
|
723
|
-
*
|
|
724
|
-
* @param packageInfo - The data coming from `package.json`.
|
|
725
|
-
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
726
|
-
*
|
|
727
|
-
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
728
|
-
*/
|
|
729
|
-
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
730
|
-
return {
|
|
731
|
-
dependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.dependencies ?? {}),
|
|
732
|
-
devDependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.devDependencies ?? {})
|
|
733
|
-
}[dependencyGroup];
|
|
734
|
-
}
|
|
735
|
-
|
|
736
736
|
//#endregion
|
|
737
737
|
//#region src/root/functions/miscellaneous/isOrdered.ts
|
|
738
738
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -190,6 +190,26 @@ declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
|
|
|
190
190
|
*/
|
|
191
191
|
declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
192
192
|
//#endregion
|
|
193
|
+
//#region src/internal/DependencyGroup.d.ts
|
|
194
|
+
declare const DependencyGroup: {
|
|
195
|
+
readonly DEPENDENCIES: "dependencies";
|
|
196
|
+
readonly DEV_DEPENDENCIES: "devDependencies";
|
|
197
|
+
};
|
|
198
|
+
type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/internal/getDependenciesFromGroup.d.ts
|
|
201
|
+
/**
|
|
202
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
203
|
+
*
|
|
204
|
+
* @category Miscellaneous
|
|
205
|
+
*
|
|
206
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
207
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
208
|
+
*
|
|
209
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
210
|
+
*/
|
|
211
|
+
declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
|
|
212
|
+
//#endregion
|
|
193
213
|
//#region src/root/functions/miscellaneous/convertFileToBase64.d.ts
|
|
194
214
|
/**
|
|
195
215
|
* Asynchronously converts a file to a base 64 string
|
|
@@ -498,24 +518,6 @@ type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefin
|
|
|
498
518
|
*/
|
|
499
519
|
declare function createFormData<DataType extends Record<RecordKey, unknown>>(data: DataType, options?: CreateFormDataOptions<keyof DataType>): FormData;
|
|
500
520
|
//#endregion
|
|
501
|
-
//#region src/root/functions/miscellaneous/getDependenciesFromGroup.d.ts
|
|
502
|
-
declare const DependencyGroup: {
|
|
503
|
-
readonly DEPENDENCIES: "dependencies";
|
|
504
|
-
readonly DEV_DEPENDENCIES: "devDependencies";
|
|
505
|
-
};
|
|
506
|
-
type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
|
|
507
|
-
/**
|
|
508
|
-
* Get the dependencies from a given dependency group in `package.json`.
|
|
509
|
-
*
|
|
510
|
-
* @category Miscellaneous
|
|
511
|
-
*
|
|
512
|
-
* @param packageInfo - The data coming from `package.json`.
|
|
513
|
-
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
514
|
-
*
|
|
515
|
-
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
516
|
-
*/
|
|
517
|
-
declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
|
|
518
|
-
//#endregion
|
|
519
521
|
//#region src/root/functions/miscellaneous/getRandomNumber.d.ts
|
|
520
522
|
/**
|
|
521
523
|
* Gets a random number between the given bounds.
|
package/dist/index.d.ts
CHANGED
|
@@ -190,6 +190,26 @@ declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
|
|
|
190
190
|
*/
|
|
191
191
|
declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
192
192
|
//#endregion
|
|
193
|
+
//#region src/internal/DependencyGroup.d.ts
|
|
194
|
+
declare const DependencyGroup: {
|
|
195
|
+
readonly DEPENDENCIES: "dependencies";
|
|
196
|
+
readonly DEV_DEPENDENCIES: "devDependencies";
|
|
197
|
+
};
|
|
198
|
+
type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/internal/getDependenciesFromGroup.d.ts
|
|
201
|
+
/**
|
|
202
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
203
|
+
*
|
|
204
|
+
* @category Miscellaneous
|
|
205
|
+
*
|
|
206
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
207
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
208
|
+
*
|
|
209
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
210
|
+
*/
|
|
211
|
+
declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
|
|
212
|
+
//#endregion
|
|
193
213
|
//#region src/root/functions/miscellaneous/convertFileToBase64.d.ts
|
|
194
214
|
/**
|
|
195
215
|
* Asynchronously converts a file to a base 64 string
|
|
@@ -498,24 +518,6 @@ type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefin
|
|
|
498
518
|
*/
|
|
499
519
|
declare function createFormData<DataType extends Record<RecordKey, unknown>>(data: DataType, options?: CreateFormDataOptions<keyof DataType>): FormData;
|
|
500
520
|
//#endregion
|
|
501
|
-
//#region src/root/functions/miscellaneous/getDependenciesFromGroup.d.ts
|
|
502
|
-
declare const DependencyGroup: {
|
|
503
|
-
readonly DEPENDENCIES: "dependencies";
|
|
504
|
-
readonly DEV_DEPENDENCIES: "devDependencies";
|
|
505
|
-
};
|
|
506
|
-
type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
|
|
507
|
-
/**
|
|
508
|
-
* Get the dependencies from a given dependency group in `package.json`.
|
|
509
|
-
*
|
|
510
|
-
* @category Miscellaneous
|
|
511
|
-
*
|
|
512
|
-
* @param packageInfo - The data coming from `package.json`.
|
|
513
|
-
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
514
|
-
*
|
|
515
|
-
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
516
|
-
*/
|
|
517
|
-
declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
|
|
518
|
-
//#endregion
|
|
519
521
|
//#region src/root/functions/miscellaneous/getRandomNumber.d.ts
|
|
520
522
|
/**
|
|
521
523
|
* Gets a random number between the given bounds.
|
package/dist/index.js
CHANGED
|
@@ -584,6 +584,25 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
584
584
|
return firstDate.getDate() === secondDate.getDate();
|
|
585
585
|
}
|
|
586
586
|
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/internal/getDependenciesFromGroup.ts
|
|
589
|
+
/**
|
|
590
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
591
|
+
*
|
|
592
|
+
* @category Miscellaneous
|
|
593
|
+
*
|
|
594
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
595
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
596
|
+
*
|
|
597
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
598
|
+
*/
|
|
599
|
+
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
600
|
+
return {
|
|
601
|
+
dependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.dependencies ?? {}),
|
|
602
|
+
devDependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.devDependencies ?? {})
|
|
603
|
+
}[dependencyGroup];
|
|
604
|
+
}
|
|
605
|
+
|
|
587
606
|
//#endregion
|
|
588
607
|
//#region src/root/functions/miscellaneous/convertFileToBase64.ts
|
|
589
608
|
/**
|
|
@@ -683,25 +702,6 @@ function createFormData(data, options = {
|
|
|
683
702
|
return formData;
|
|
684
703
|
}
|
|
685
704
|
|
|
686
|
-
//#endregion
|
|
687
|
-
//#region src/root/functions/miscellaneous/getDependenciesFromGroup.ts
|
|
688
|
-
/**
|
|
689
|
-
* Get the dependencies from a given dependency group in `package.json`.
|
|
690
|
-
*
|
|
691
|
-
* @category Miscellaneous
|
|
692
|
-
*
|
|
693
|
-
* @param packageInfo - The data coming from `package.json`.
|
|
694
|
-
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
695
|
-
*
|
|
696
|
-
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
697
|
-
*/
|
|
698
|
-
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
699
|
-
return {
|
|
700
|
-
dependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.dependencies ?? {}),
|
|
701
|
-
devDependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.devDependencies ?? {})
|
|
702
|
-
}[dependencyGroup];
|
|
703
|
-
}
|
|
704
|
-
|
|
705
705
|
//#endregion
|
|
706
706
|
//#region src/root/functions/miscellaneous/isOrdered.ts
|
|
707
707
|
/**
|
package/dist/internal/index.cjs
CHANGED
|
@@ -34,6 +34,13 @@ node_path = __toESM(node_path);
|
|
|
34
34
|
require("libsodium-wrappers");
|
|
35
35
|
let node_fs_promises = require("node:fs/promises");
|
|
36
36
|
|
|
37
|
+
//#region src/internal/DependencyGroup.ts
|
|
38
|
+
const DependencyGroup = {
|
|
39
|
+
DEPENDENCIES: "dependencies",
|
|
40
|
+
DEV_DEPENDENCIES: "devDependencies"
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
37
44
|
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
38
45
|
/**
|
|
39
46
|
* Creates a new array where each element is the result of the provided callback.
|
|
@@ -626,6 +633,27 @@ async function getPackageJsonContents(directory) {
|
|
|
626
633
|
}
|
|
627
634
|
}
|
|
628
635
|
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region src/internal/ModuleType.ts
|
|
638
|
+
const ModuleType = {
|
|
639
|
+
COMMON_JS: "commonjs",
|
|
640
|
+
ES_MODULES: "module",
|
|
641
|
+
TYPESCRIPT: "typescript"
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region src/internal/packageJsonNotFoundError.ts
|
|
646
|
+
function packageJsonNotFoundError(packagePath) {
|
|
647
|
+
return new DataError({ packagePath: getPackageJsonPath(packagePath) }, "PACKAGE_JSON_NOT_FOUND", "Could not find package.json in directory.");
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region src/internal/PackageManager.ts
|
|
652
|
+
const PackageManager = {
|
|
653
|
+
NPM: "npm",
|
|
654
|
+
PNPM: "pnpm"
|
|
655
|
+
};
|
|
656
|
+
|
|
629
657
|
//#endregion
|
|
630
658
|
//#region src/internal/parseJsonFromStdout.ts
|
|
631
659
|
function parseJsonFromStdout(stdout) {
|
|
@@ -643,8 +671,30 @@ function parseJsonFromStdout(stdout) {
|
|
|
643
671
|
var sayHello_default = sayHello;
|
|
644
672
|
|
|
645
673
|
//#endregion
|
|
674
|
+
//#region src/internal/setupPackageEndToEnd.ts
|
|
675
|
+
async function setupPackageEndToEnd(temporaryPath, packageManager, moduleType, options) {
|
|
676
|
+
const { dependencyGroup = "dependencies" } = options ?? {};
|
|
677
|
+
await (0, execa.execa)({ cwd: process.cwd() })`${packageManager} pack --pack-destination ${temporaryPath}`;
|
|
678
|
+
const tgzFileName = await getExpectedTgzName(process.cwd(), packageManager);
|
|
679
|
+
const runCommandInTempDirectory = (0, execa.execa)({ cwd: temporaryPath });
|
|
680
|
+
if (packageManager === PackageManager.NPM) await runCommandInTempDirectory`npm init -y`;
|
|
681
|
+
else await runCommandInTempDirectory`pnpm init`;
|
|
682
|
+
const packageInfo = await getPackageJsonContents(temporaryPath);
|
|
683
|
+
if (packageInfo === null) throw packageJsonNotFoundError(temporaryPath);
|
|
684
|
+
packageInfo.type = moduleType === ModuleType.TYPESCRIPT ? ModuleType.ES_MODULES : moduleType;
|
|
685
|
+
await (0, node_fs_promises.writeFile)(node_path.default.join(temporaryPath, "package.json"), JSON.stringify(packageInfo, null, 2));
|
|
686
|
+
await runCommandInTempDirectory`${packageManager} install ${dependencyGroup === "devDependencies" ? "--save-dev" : "--save-prod"} ${node_path.default.join(temporaryPath, tgzFileName)}`;
|
|
687
|
+
return runCommandInTempDirectory;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
//#endregion
|
|
691
|
+
exports.DependencyGroup = DependencyGroup;
|
|
692
|
+
exports.ModuleType = ModuleType;
|
|
693
|
+
exports.PackageManager = PackageManager;
|
|
646
694
|
exports.getExpectedTgzName = getExpectedTgzName;
|
|
647
695
|
exports.getPackageJsonContents = getPackageJsonContents;
|
|
648
696
|
exports.getPackageJsonPath = getPackageJsonPath;
|
|
697
|
+
exports.packageJsonNotFoundError = packageJsonNotFoundError;
|
|
649
698
|
exports.parseJsonFromStdout = parseJsonFromStdout;
|
|
650
|
-
exports.sayHello = sayHello_default;
|
|
699
|
+
exports.sayHello = sayHello_default;
|
|
700
|
+
exports.setupPackageEndToEnd = setupPackageEndToEnd;
|
|
@@ -1,14 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//#
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ExecaMethod } from "execa";
|
|
2
|
+
|
|
3
|
+
//#region src/root/types/RecordKey.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Represents the native Record's possible key type.
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
*/
|
|
9
|
+
type RecordKey = string | number | symbol;
|
|
6
10
|
//#endregion
|
|
7
|
-
//#region src/
|
|
8
|
-
|
|
11
|
+
//#region src/root/types/DataError.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
14
|
+
*
|
|
15
|
+
* @category Types
|
|
16
|
+
*
|
|
17
|
+
* @template DataType - The type of the data that caused the error.
|
|
18
|
+
*/
|
|
19
|
+
declare class DataError<DataType extends Record<RecordKey, unknown> = Record<RecordKey, unknown>> extends Error {
|
|
20
|
+
code: string;
|
|
21
|
+
data: DataType;
|
|
22
|
+
/**
|
|
23
|
+
* @param data - The data that caused the error.
|
|
24
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
25
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
26
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
27
|
+
*/
|
|
28
|
+
constructor(data: DataType, code?: string, message?: string, options?: ErrorOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
31
|
+
*
|
|
32
|
+
* @param input - The input to check.
|
|
33
|
+
*
|
|
34
|
+
* @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`.
|
|
35
|
+
*/
|
|
36
|
+
static check<DataType extends Record<RecordKey, unknown> = Record<RecordKey, unknown>>(input: unknown): input is DataError<DataType>;
|
|
37
|
+
}
|
|
9
38
|
//#endregion
|
|
10
|
-
//#region src/
|
|
11
|
-
|
|
39
|
+
//#region src/root/types/CreateEnumType.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
42
|
+
*
|
|
43
|
+
* @category Types
|
|
44
|
+
*
|
|
45
|
+
* @template ObjectType - The type of the object to get the value types for.
|
|
46
|
+
*/
|
|
47
|
+
type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
|
|
12
48
|
//#endregion
|
|
13
49
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
14
50
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
@@ -23,4 +59,49 @@ type IsTypeArgumentString<Argument extends string> = Argument;
|
|
|
23
59
|
*/
|
|
24
60
|
declare function sayHello(): string;
|
|
25
61
|
//#endregion
|
|
26
|
-
|
|
62
|
+
//#region src/internal/DependencyGroup.d.ts
|
|
63
|
+
declare const DependencyGroup: {
|
|
64
|
+
readonly DEPENDENCIES: "dependencies";
|
|
65
|
+
readonly DEV_DEPENDENCIES: "devDependencies";
|
|
66
|
+
};
|
|
67
|
+
type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/internal/getExpectedTgzName.d.ts
|
|
70
|
+
declare function getExpectedTgzName(packagePath: string, packageManager: string): Promise<string>;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/internal/getPackageJsonContents.d.ts
|
|
73
|
+
declare function getPackageJsonContents(directory: string): Promise<Record<string, any> | null>;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/internal/getPackageJsonPath.d.ts
|
|
76
|
+
declare function getPackageJsonPath(directory: string): string;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/internal/ModuleType.d.ts
|
|
79
|
+
declare const ModuleType: {
|
|
80
|
+
readonly COMMON_JS: "commonjs";
|
|
81
|
+
readonly ES_MODULES: "module";
|
|
82
|
+
readonly TYPESCRIPT: "typescript";
|
|
83
|
+
};
|
|
84
|
+
type ModuleType = CreateEnumType<typeof ModuleType>;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/internal/packageJsonNotFoundError.d.ts
|
|
87
|
+
declare function packageJsonNotFoundError(packagePath: string): DataError;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/internal/PackageManager.d.ts
|
|
90
|
+
declare const PackageManager: {
|
|
91
|
+
readonly NPM: "npm";
|
|
92
|
+
readonly PNPM: "pnpm";
|
|
93
|
+
};
|
|
94
|
+
type PackageManager = CreateEnumType<typeof PackageManager>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/internal/parseJsonFromStdout.d.ts
|
|
97
|
+
declare function parseJsonFromStdout(stdout: string): Record<string, unknown>;
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/internal/setupPackageEndToEnd.d.ts
|
|
100
|
+
interface SetupPackageEndToEndOptions {
|
|
101
|
+
dependencyGroup?: DependencyGroup;
|
|
102
|
+
}
|
|
103
|
+
declare function setupPackageEndToEnd(temporaryPath: string, packageManager: PackageManager, moduleType: ModuleType, options?: SetupPackageEndToEndOptions): Promise<ExecaMethod<{
|
|
104
|
+
cwd: string;
|
|
105
|
+
}>>;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { DependencyGroup, type IsTypeArgumentString, ModuleType, PackageManager, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello, setupPackageEndToEnd };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
|
+
import { ExecaMethod } from "execa";
|
|
1
2
|
import z from "zod";
|
|
2
3
|
|
|
3
|
-
//#region src/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
//#region src/root/types/RecordKey.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Represents the native Record's possible key type.
|
|
7
|
+
*
|
|
8
|
+
* @category Types
|
|
9
|
+
*/
|
|
10
|
+
type RecordKey = string | number | symbol;
|
|
8
11
|
//#endregion
|
|
9
|
-
//#region src/
|
|
10
|
-
|
|
12
|
+
//#region src/root/types/DataError.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
15
|
+
*
|
|
16
|
+
* @category Types
|
|
17
|
+
*
|
|
18
|
+
* @template DataType - The type of the data that caused the error.
|
|
19
|
+
*/
|
|
20
|
+
declare class DataError<DataType extends Record<RecordKey, unknown> = Record<RecordKey, unknown>> extends Error {
|
|
21
|
+
code: string;
|
|
22
|
+
data: DataType;
|
|
23
|
+
/**
|
|
24
|
+
* @param data - The data that caused the error.
|
|
25
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
26
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
27
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
28
|
+
*/
|
|
29
|
+
constructor(data: DataType, code?: string, message?: string, options?: ErrorOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
32
|
+
*
|
|
33
|
+
* @param input - The input to check.
|
|
34
|
+
*
|
|
35
|
+
* @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`.
|
|
36
|
+
*/
|
|
37
|
+
static check<DataType extends Record<RecordKey, unknown> = Record<RecordKey, unknown>>(input: unknown): input is DataError<DataType>;
|
|
38
|
+
}
|
|
11
39
|
//#endregion
|
|
12
|
-
//#region src/
|
|
13
|
-
|
|
40
|
+
//#region src/root/types/CreateEnumType.d.ts
|
|
41
|
+
/**
|
|
42
|
+
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
43
|
+
*
|
|
44
|
+
* @category Types
|
|
45
|
+
*
|
|
46
|
+
* @template ObjectType - The type of the object to get the value types for.
|
|
47
|
+
*/
|
|
48
|
+
type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
|
|
14
49
|
//#endregion
|
|
15
50
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
16
51
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
@@ -25,4 +60,49 @@ type IsTypeArgumentString<Argument extends string> = Argument;
|
|
|
25
60
|
*/
|
|
26
61
|
declare function sayHello(): string;
|
|
27
62
|
//#endregion
|
|
28
|
-
|
|
63
|
+
//#region src/internal/DependencyGroup.d.ts
|
|
64
|
+
declare const DependencyGroup: {
|
|
65
|
+
readonly DEPENDENCIES: "dependencies";
|
|
66
|
+
readonly DEV_DEPENDENCIES: "devDependencies";
|
|
67
|
+
};
|
|
68
|
+
type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/internal/getExpectedTgzName.d.ts
|
|
71
|
+
declare function getExpectedTgzName(packagePath: string, packageManager: string): Promise<string>;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/internal/getPackageJsonContents.d.ts
|
|
74
|
+
declare function getPackageJsonContents(directory: string): Promise<Record<string, any> | null>;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/internal/getPackageJsonPath.d.ts
|
|
77
|
+
declare function getPackageJsonPath(directory: string): string;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/internal/ModuleType.d.ts
|
|
80
|
+
declare const ModuleType: {
|
|
81
|
+
readonly COMMON_JS: "commonjs";
|
|
82
|
+
readonly ES_MODULES: "module";
|
|
83
|
+
readonly TYPESCRIPT: "typescript";
|
|
84
|
+
};
|
|
85
|
+
type ModuleType = CreateEnumType<typeof ModuleType>;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/internal/packageJsonNotFoundError.d.ts
|
|
88
|
+
declare function packageJsonNotFoundError(packagePath: string): DataError;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/internal/PackageManager.d.ts
|
|
91
|
+
declare const PackageManager: {
|
|
92
|
+
readonly NPM: "npm";
|
|
93
|
+
readonly PNPM: "pnpm";
|
|
94
|
+
};
|
|
95
|
+
type PackageManager = CreateEnumType<typeof PackageManager>;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/internal/parseJsonFromStdout.d.ts
|
|
98
|
+
declare function parseJsonFromStdout(stdout: string): Record<string, unknown>;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/internal/setupPackageEndToEnd.d.ts
|
|
101
|
+
interface SetupPackageEndToEndOptions {
|
|
102
|
+
dependencyGroup?: DependencyGroup;
|
|
103
|
+
}
|
|
104
|
+
declare function setupPackageEndToEnd(temporaryPath: string, packageManager: PackageManager, moduleType: ModuleType, options?: SetupPackageEndToEndOptions): Promise<ExecaMethod<{
|
|
105
|
+
cwd: string;
|
|
106
|
+
}>>;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { DependencyGroup, type IsTypeArgumentString, ModuleType, PackageManager, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello, setupPackageEndToEnd };
|
package/dist/internal/index.js
CHANGED
|
@@ -2,8 +2,15 @@ import { execa } from "execa";
|
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import "libsodium-wrappers";
|
|
5
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
6
6
|
|
|
7
|
+
//#region src/internal/DependencyGroup.ts
|
|
8
|
+
const DependencyGroup = {
|
|
9
|
+
DEPENDENCIES: "dependencies",
|
|
10
|
+
DEV_DEPENDENCIES: "devDependencies"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
7
14
|
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
8
15
|
/**
|
|
9
16
|
* Creates a new array where each element is the result of the provided callback.
|
|
@@ -596,6 +603,27 @@ async function getPackageJsonContents(directory) {
|
|
|
596
603
|
}
|
|
597
604
|
}
|
|
598
605
|
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/internal/ModuleType.ts
|
|
608
|
+
const ModuleType = {
|
|
609
|
+
COMMON_JS: "commonjs",
|
|
610
|
+
ES_MODULES: "module",
|
|
611
|
+
TYPESCRIPT: "typescript"
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region src/internal/packageJsonNotFoundError.ts
|
|
616
|
+
function packageJsonNotFoundError(packagePath) {
|
|
617
|
+
return new DataError({ packagePath: getPackageJsonPath(packagePath) }, "PACKAGE_JSON_NOT_FOUND", "Could not find package.json in directory.");
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region src/internal/PackageManager.ts
|
|
622
|
+
const PackageManager = {
|
|
623
|
+
NPM: "npm",
|
|
624
|
+
PNPM: "pnpm"
|
|
625
|
+
};
|
|
626
|
+
|
|
599
627
|
//#endregion
|
|
600
628
|
//#region src/internal/parseJsonFromStdout.ts
|
|
601
629
|
function parseJsonFromStdout(stdout) {
|
|
@@ -613,4 +641,21 @@ function parseJsonFromStdout(stdout) {
|
|
|
613
641
|
var sayHello_default = sayHello;
|
|
614
642
|
|
|
615
643
|
//#endregion
|
|
616
|
-
|
|
644
|
+
//#region src/internal/setupPackageEndToEnd.ts
|
|
645
|
+
async function setupPackageEndToEnd(temporaryPath, packageManager, moduleType, options) {
|
|
646
|
+
const { dependencyGroup = "dependencies" } = options ?? {};
|
|
647
|
+
await execa({ cwd: process.cwd() })`${packageManager} pack --pack-destination ${temporaryPath}`;
|
|
648
|
+
const tgzFileName = await getExpectedTgzName(process.cwd(), packageManager);
|
|
649
|
+
const runCommandInTempDirectory = execa({ cwd: temporaryPath });
|
|
650
|
+
if (packageManager === PackageManager.NPM) await runCommandInTempDirectory`npm init -y`;
|
|
651
|
+
else await runCommandInTempDirectory`pnpm init`;
|
|
652
|
+
const packageInfo = await getPackageJsonContents(temporaryPath);
|
|
653
|
+
if (packageInfo === null) throw packageJsonNotFoundError(temporaryPath);
|
|
654
|
+
packageInfo.type = moduleType === ModuleType.TYPESCRIPT ? ModuleType.ES_MODULES : moduleType;
|
|
655
|
+
await writeFile(path.join(temporaryPath, "package.json"), JSON.stringify(packageInfo, null, 2));
|
|
656
|
+
await runCommandInTempDirectory`${packageManager} install ${dependencyGroup === "devDependencies" ? "--save-dev" : "--save-prod"} ${path.join(temporaryPath, tgzFileName)}`;
|
|
657
|
+
return runCommandInTempDirectory;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
//#endregion
|
|
661
|
+
export { DependencyGroup, ModuleType, PackageManager, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello_default as sayHello, setupPackageEndToEnd };
|