@alextheman/utility 4.17.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 +111 -258
- package/dist/index.d.cts +124 -258
- package/dist/index.d.ts +124 -258
- package/dist/index.js +111 -251
- package/dist/internal/index.cjs +700 -0
- package/dist/internal/index.d.cts +107 -0
- package/dist/internal/index.d.ts +108 -0
- package/dist/internal/index.js +661 -0
- package/dist/node/index.cjs +594 -0
- package/dist/node/index.d.cts +46 -0
- package/dist/node/index.d.ts +48 -0
- package/dist/node/index.js +562 -0
- package/package.json +13 -3
|
@@ -0,0 +1,107 @@
|
|
|
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;
|
|
10
|
+
//#endregion
|
|
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
|
+
}
|
|
38
|
+
//#endregion
|
|
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];
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
50
|
+
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/root/functions/miscellaneous/sayHello.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
55
|
+
*
|
|
56
|
+
* [Pls listen!](https://www.youtube.com/watch?v=mH-Sg-8EnxM)
|
|
57
|
+
*
|
|
58
|
+
* @returns The lyrics string in markdown format.
|
|
59
|
+
*/
|
|
60
|
+
declare function sayHello(): string;
|
|
61
|
+
//#endregion
|
|
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 };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ExecaMethod } from "execa";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
|
|
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;
|
|
11
|
+
//#endregion
|
|
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
|
+
}
|
|
39
|
+
//#endregion
|
|
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];
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
51
|
+
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/root/functions/miscellaneous/sayHello.d.ts
|
|
54
|
+
/**
|
|
55
|
+
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
56
|
+
*
|
|
57
|
+
* [Pls listen!](https://www.youtube.com/watch?v=mH-Sg-8EnxM)
|
|
58
|
+
*
|
|
59
|
+
* @returns The lyrics string in markdown format.
|
|
60
|
+
*/
|
|
61
|
+
declare function sayHello(): string;
|
|
62
|
+
//#endregion
|
|
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 };
|