@prozilla-os/dev-tools 1.1.14 → 1.2.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,57 @@
1
+ /**
2
+ * Represents a choice in an {@link interactiveListPrompt}.
3
+ */
4
+ export declare interface InteractiveListChoice {
5
+ /** The name to display in the list. */
6
+ name: string;
7
+ /** The value to return if this is submitted. */
8
+ value: string;
9
+ /** The keyboard shortcut that submits this choice. */
10
+ key: string;
11
+ }
12
+
13
+ /**
14
+ * Configuration for {@link interactiveListPrompt}.
15
+ */
16
+ export declare interface InteractiveListConfig {
17
+ /** The message to display at the top of the list. */
18
+ message: string;
19
+ /** The list of choices. */
20
+ choices: Array<InteractiveListChoice>;
21
+ /** The default value to select. Defaults to the first choice. A value of `null` represents no selection. */
22
+ default?: string | null;
23
+ /** Function that renders the selected choice. */
24
+ renderSelected?: (choice: InteractiveListChoice, index: number) => string;
25
+ /** Functions that renders the unselected choices. */
26
+ renderUnselected?: (choice: InteractiveListChoice, index: number) => string;
27
+ /**
28
+ * Whether to hide the cursor during selection.
29
+ * @default true
30
+ */
31
+ hideCursor?: boolean;
32
+ /**
33
+ * Whether to horizontally align the shortcuts in the list of choices.
34
+ * @default false
35
+ */
36
+ alignShortcuts?: boolean;
37
+ }
38
+
39
+ /**
40
+ * Creates an interactive list of choices that supports selection via arrow keys + enter or via pressing a key associated with a choice.
41
+ *
42
+ * This is based on {@link https://github.com/pgibler/inquirer-interactive-list-prompt pgibler/inquirer-interactive-list-prompt}.
43
+ * @example
44
+ * ```ts
45
+ * const answer = await interactiveListPrompt({
46
+ * message: "Select an option:",
47
+ * choices: [
48
+ * { name: "Option A", value: "A", key: "a" },
49
+ * { name: "Option B", value: "B", key: "b" },
50
+ * { name: "Option C", value: "C", key: "c" },
51
+ * ],
52
+ * });
53
+ * ```
54
+ */
55
+ export declare const interactiveListPrompt: (config: InteractiveListConfig) => Promise<string>;
56
+
57
+ export { }
@@ -0,0 +1,5 @@
1
+ import { i as r } from "./chunks/interactiveListPrompt-CsphCZPx.js";
2
+ export {
3
+ r as interactiveListPrompt
4
+ };
5
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/dist/test.d.ts ADDED
@@ -0,0 +1,202 @@
1
+ import { Assertion } from 'vitest';
2
+ import { InspectionOptions } from '@prozilla-os/shared/logging';
3
+ import { TestAPI } from 'vitest';
4
+
5
+ /**
6
+ * Defines the matching criteria for a test case using an assertion.
7
+ * @see {@link Matcher}
8
+ * @see {@link CustomTestAPI.assert}
9
+ */
10
+ export declare interface AssertionMatcher<R> {
11
+ readonly [MATCH_ASSERTION]: true;
12
+ /** The assertion that defines the matching criteria for this test. */
13
+ readonly assert: (actual: Assertion<R>) => void;
14
+ /** The name of this assertion. */
15
+ readonly name?: string;
16
+ }
17
+
18
+ /**
19
+ * Utility functions built on top of Vitest's API to make writing tests easier.
20
+ * @see {@link extend}
21
+ */
22
+ export declare interface CustomTestAPI {
23
+ /**
24
+ * A shorthand for {@link CustomTestAPI.cases} that tests a function with a single parameter.
25
+ * @param func - The function to test.
26
+ * @param cases - An array of tuples. Each tuple consisting of a parameter and the corresponding matching criteria.
27
+ * @typeParam A - The type of parameter the function accepts.
28
+ * @typeParam R - The type of value the function returns.
29
+ * @example
30
+ * test.simpleCases(isEven, [
31
+ * [0, true],
32
+ * [1, false],
33
+ * [2, true],
34
+ * ]);
35
+ */
36
+ simpleCases: <A = unknown, R = undefined>(func: (arg: A) => R, cases: [A, Matcher<R>][]) => void;
37
+ /**
38
+ * A shorthand for {@link CustomTestAPI.case} that tests a function with a single parameter.
39
+ * @param func - The function to test.
40
+ * @param arg - The parameter to pass to the function.
41
+ * @param matcher - The matching criteria.
42
+ * @typeParam A - The type of parameter the function accepts.
43
+ * @typeParam R - The type of value the function returns.
44
+ */
45
+ simpleCase: <A = unknown, R = undefined>(func: (arg: A) => R, arg: A, matcher: Matcher<R>) => void;
46
+ /**
47
+ * Tests each case in the array by calling the function with the first element of the tuple and checking its behaviour
48
+ * or return value against the matching criteria in the second element.
49
+ *
50
+ * This is a wrapper around {@link TestAPI.each} that handles test naming, function calling and assertions for you,
51
+ * so you can write more parameterized tests with less code.
52
+ * @param func - The function to test.
53
+ * @param cases - An array of tuples. Each tuple consisting of an array of parameters and the corresponding matching criteria.
54
+ * @typeParam A - The types of parameters the function accepts.
55
+ * @typeParam R - The type of value the function returns.
56
+ * @example
57
+ * ```ts
58
+ * test.cases(isEqual, [
59
+ * [[0, 1], false],
60
+ * [[2, 3], false],
61
+ * [[4, 4], true],
62
+ * ]);
63
+ * ```
64
+ * ### Comparison with Vitest
65
+ * Most functions will have simple unit tests like this:
66
+ * ```ts
67
+ * test.each([
68
+ * [1, 1, 2],
69
+ * [1, 2, 3],
70
+ * [2, 1, 3],
71
+ * ])("add(%i, %i) -> %i", (a, b, expected) => {
72
+ * expect(a + b).toBe(expected)
73
+ * })
74
+ * ```
75
+ * This is the same test, but using the `cases` wrapper instead:
76
+ * ```ts
77
+ * test.cases(add, [
78
+ * [[1, 1], 2],
79
+ * [[1, 2], 3],
80
+ * [[2, 1], 3]
81
+ * ]);
82
+ * ```
83
+ */
84
+ cases: <A extends unknown[] = [], R = undefined>(func: (...args: A) => R, cases: [A, Matcher<R>][]) => void;
85
+ /**
86
+ * Tests a single case by calling the function with the given parameters and checking its behaviour
87
+ * or return value against the matching criteria.
88
+ *
89
+ * This is the equivalent of {@link CustomTestAPI.cases}, but for a single test case.
90
+ * @param func - The function to test.
91
+ * @param args - The parameters to pass to the function.
92
+ * @param matcher - The matching criteria.
93
+ * @typeParam A - The types of parameters the function accepts.
94
+ * @typeParam R - The type of value the function returns.
95
+ */
96
+ case: <A extends unknown[] = [], R = undefined>(func: (...args: A) => R, args: A, matcher: Matcher<R>) => void;
97
+ /**
98
+ * Creates matching criteria for a test case that expects an error to be thrown.
99
+ * @param error - The type of error to expect.
100
+ * @param message - The error message to expect.
101
+ * @see {@link CustomTestAPI.cases}
102
+ */
103
+ throws: (error: new (...args: never[]) => Error, message?: string | RegExp) => ErrorMatcher;
104
+ /**
105
+ * Creates matching criteria for a test case where the actual value is verified by the given assertion,
106
+ * instead of simply being compared with an expected return value.
107
+ * @param assert - The function that verifies the actual return value.
108
+ * @param name - The name of the assertion.
109
+ * @see {@link CustomTestAPI.cases}
110
+ */
111
+ assert: <R>(assert: (actual: Assertion<R>) => void, name?: string) => AssertionMatcher<R>;
112
+ /** Creates matching criteria for a test case that expects the actual value to be nullish (`null` or `undefined`). */
113
+ nullish: <R>() => AssertionMatcher<R>;
114
+ /** Creates matching criteria for a test case that expects the actual value to be [`falsy`](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
115
+ falsy: <R>() => AssertionMatcher<R>;
116
+ /** Creates matching criteria for a test case that expects the actual value to be [`truthy`](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
117
+ truthy: <R>() => AssertionMatcher<R>;
118
+ /** Negates the proceding matching criteria for a test case. */
119
+ not: Pick<CustomTestAPI, "nullish" | "falsy" | "truthy">;
120
+ }
121
+
122
+ /**
123
+ * Configuration options for the {@link CustomTestAPI}.
124
+ */
125
+ export declare interface CustomTestConfig {
126
+ /** Options for the formatting of test names. */
127
+ format?: InspectionOptions;
128
+ }
129
+
130
+ /**
131
+ * Defines the matching criteria for a test case that expects the function to throw an error.
132
+ * @see {@link Matcher}
133
+ * @see {@link CustomTestAPI.throws}
134
+ */
135
+ export declare interface ErrorMatcher {
136
+ readonly [MATCH_ERROR]: true;
137
+ /** The type of error the function should throw. */
138
+ readonly error: new (...args: never[]) => Error;
139
+ /** The message the error thrown by the function should have. */
140
+ readonly message?: string | RegExp;
141
+ }
142
+
143
+ /**
144
+ * Extends Vitest's {@link TestAPI} with functions from the {@link CustomTestAPI}.
145
+ * @param test - The Vitest test API.
146
+ * @param config - The configuration options.
147
+ * @returns The extended test API.
148
+ * @example
149
+ * You can call this function in one file and export the result.
150
+ * ```ts
151
+ * // index.ts
152
+ * import { test as base } from "vitest";
153
+ *
154
+ * export const test = extend(base);
155
+ * ```
156
+ * Then import and use it across your test files.
157
+ * ```ts
158
+ * // isEven.test.ts
159
+ * import { test } from "./index";
160
+ *
161
+ * test.simpleCases(isEven, [
162
+ * [0, true],
163
+ * [1, false],
164
+ * [2, true],
165
+ * ]);
166
+ * ```
167
+ * ### With configuration
168
+ * ```ts
169
+ * import { test as base } from "vitest";
170
+ *
171
+ * export const test = extend(base, {
172
+ * format: {
173
+ * colors: false,
174
+ * singleQuotes: true,
175
+ * spaceAfterComma: false,
176
+ * },
177
+ * });
178
+ * ```
179
+ */
180
+ export declare function extend<C = object>(test: TestAPI<C>, config?: CustomTestConfig): ExtendedTestAPI<C>;
181
+
182
+ /**
183
+ * The combination of Vitest's {@link TestAPI} and the {@link CustomTestAPI}.
184
+ */
185
+ export declare type ExtendedTestAPI<ExtraContext = object> = TestAPI<ExtraContext> & CustomTestAPI;
186
+
187
+ declare const MATCH_ASSERTION: unique symbol;
188
+
189
+ declare const MATCH_ERROR: unique symbol;
190
+
191
+ /**
192
+ * Defines the matching criteria for a test case.
193
+ *
194
+ * This can either be a plain return value, in which case the test will fail if the function returns a different value,
195
+ * or more complex criteria that determines whether the test will fail.
196
+ * E.g., an {@link ErrorMatcher} will fail if the function does not throw an error of a certain type and with a certain message.
197
+ * @param R - The type of value the function being tested returns.
198
+ * @see {@link CustomTestAPI.cases}
199
+ */
200
+ export declare type Matcher<R = undefined> = R | ErrorMatcher | AssertionMatcher<R>;
201
+
202
+ export { }
package/dist/test.js ADDED
@@ -0,0 +1,80 @@
1
+ import { expect as c } from "vitest";
2
+ import { Ansi as A, inspect as B, inspectFunction as E, inspectFunctionCall as f } from "@prozilla-os/shared/logging";
3
+ import { mergeDeep as F } from "@prozilla-os/shared/utils";
4
+ const m = /* @__PURE__ */ Symbol("matchError"), p = /* @__PURE__ */ Symbol("matchAssertion"), g = {
5
+ format: {
6
+ plugins: [j()]
7
+ }
8
+ };
9
+ function w(t, s = {}) {
10
+ s = F(g, s);
11
+ const e = (n, r) => M(t, n, r, s), o = (n, r, i) => N(t, n, r, i, s);
12
+ return Object.assign(t, {
13
+ simpleCases: (n, r) => e(n, r.map(([i, h]) => [[i], h])),
14
+ simpleCase: (n, r, i) => o(n, [r], i),
15
+ cases: e,
16
+ case: o,
17
+ throws: O,
18
+ assert: l,
19
+ nullish: S,
20
+ falsy: u,
21
+ truthy: a,
22
+ not: {
23
+ nullish: T,
24
+ falsy: a,
25
+ truthy: u
26
+ }
27
+ });
28
+ }
29
+ function M(t, s, e, o) {
30
+ return t.each(
31
+ e.map(([n, r]) => [
32
+ f(s, n, r, o.format),
33
+ n,
34
+ r
35
+ ])
36
+ )("%s", (n, r, i) => {
37
+ y(s, r, i);
38
+ });
39
+ }
40
+ function N(t, s, e, o, n) {
41
+ return t(f(s, e, o, n.format), () => {
42
+ y(s, e, o);
43
+ });
44
+ }
45
+ function y(t, s, e) {
46
+ if (b(e)) {
47
+ let o;
48
+ try {
49
+ t(...s);
50
+ } catch (n) {
51
+ o = n;
52
+ }
53
+ c(o).toBeInstanceOf(e.error), e.message !== void 0 && c(o.message).toMatch(e.message);
54
+ } else {
55
+ const o = c(t(...s));
56
+ C(e) ? e.assert(o) : e !== null && typeof e == "object" ? o.toStrictEqual(e) : o.toBe(e);
57
+ }
58
+ }
59
+ const O = (t, s) => ({ [m]: !0, error: t, message: s }), l = (t, s) => ({ [p]: !0, assert: t, name: s }), S = () => l((t) => t.toBeNullable(), "to be nullish"), T = () => l((t) => t.not.toBeNullable(), "to not be nullish"), u = () => l((t) => t.toBeFalsy(), "to be falsy"), a = () => l((t) => t.toBeTruthy(), "to be truthy");
60
+ function b(t) {
61
+ return typeof t == "object" && t !== null && m in t;
62
+ }
63
+ function C(t) {
64
+ return typeof t == "object" && t !== null && p in t;
65
+ }
66
+ function j() {
67
+ return {
68
+ name: "test-inspect-plugin",
69
+ first: (t, s) => {
70
+ if (b(t))
71
+ return `to throw ${(s.colors ? A.red(t.error.name) : t.error.name) + (t.message ? ": " + B(t.message, s) : "")}`;
72
+ if (C(t))
73
+ return t.name ?? `to match ${E(t.assert, s)}`;
74
+ }
75
+ };
76
+ }
77
+ export {
78
+ w as extend
79
+ };
80
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sources":["../src/features/test.ts"],"sourcesContent":["import { Assertion, expect, TestAPI } from \"vitest\";\nimport { inspectFunctionCall, InspectionOptions, Ansi, inspect, inspectFunction, InspectionPlugin } from \"@prozilla-os/shared/logging\";\nimport { mergeDeep } from \"@prozilla-os/shared/utils\";\n\nconst MATCH_ERROR = Symbol(\"matchError\");\nconst MATCH_ASSERTION = Symbol(\"matchAssertion\");\n\n/**\n * Defines the matching criteria for a test case that expects the function to throw an error.\n * @see {@link Matcher}\n * @see {@link CustomTestAPI.throws}\n */\nexport interface ErrorMatcher {\n readonly [MATCH_ERROR]: true;\n\t/** The type of error the function should throw. */\n readonly error: new (...args: never[]) => Error;\n\t/** The message the error thrown by the function should have. */\n readonly message?: string | RegExp;\n}\n\n/**\n * Defines the matching criteria for a test case using an assertion.\n * @see {@link Matcher}\n * @see {@link CustomTestAPI.assert}\n */\nexport interface AssertionMatcher<R> {\n readonly [MATCH_ASSERTION]: true;\n\t/** The assertion that defines the matching criteria for this test. */\n readonly assert: (actual: Assertion<R>) => void;\n\t/** The name of this assertion. */\n\treadonly name?: string;\n}\n\n/**\n * Defines the matching criteria for a test case.\n * \n * This can either be a plain return value, in which case the test will fail if the function returns a different value,\n * or more complex criteria that determines whether the test will fail. \n * E.g., an {@link ErrorMatcher} will fail if the function does not throw an error of a certain type and with a certain message.\n * @param R - The type of value the function being tested returns.\n * @see {@link CustomTestAPI.cases}\n */\nexport type Matcher<R = undefined> = R | ErrorMatcher | AssertionMatcher<R>;\n\n/**\n * Configuration options for the {@link CustomTestAPI}.\n */\nexport interface CustomTestConfig {\n\t/** Options for the formatting of test names. */\n\tformat?: InspectionOptions;\n}\n\n/**\n * Utility functions built on top of Vitest's API to make writing tests easier.\n * @see {@link extend}\n */\nexport interface CustomTestAPI {\n\t/**\n\t * A shorthand for {@link CustomTestAPI.cases} that tests a function with a single parameter.\n\t * @param func - The function to test.\n\t * @param cases - An array of tuples. Each tuple consisting of a parameter and the corresponding matching criteria.\n\t * @typeParam A - The type of parameter the function accepts.\n\t * @typeParam R - The type of value the function returns.\n\t * @example\n\t * test.simpleCases(isEven, [\n\t * \t[0, true],\n\t * \t[1, false],\n\t * \t[2, true],\n\t * ]);\n\t */\n\tsimpleCases: <A = unknown, R = undefined>(func: (arg: A) => R, cases: [A, Matcher<R>][]) => void;\n\t/**\n\t * A shorthand for {@link CustomTestAPI.case} that tests a function with a single parameter.\n\t * @param func - The function to test.\n\t * @param arg - The parameter to pass to the function.\n\t * @param matcher - The matching criteria.\n\t * @typeParam A - The type of parameter the function accepts.\n\t * @typeParam R - The type of value the function returns.\n\t */\n\tsimpleCase: <A = unknown, R = undefined>(func: (arg: A) => R, arg: A, matcher: Matcher<R>) => void;\n\t/**\n\t * Tests each case in the array by calling the function with the first element of the tuple and checking its behaviour\n\t * or return value against the matching criteria in the second element.\n\t * \n\t * This is a wrapper around {@link TestAPI.each} that handles test naming, function calling and assertions for you, \n\t * so you can write more parameterized tests with less code.\n\t * @param func - The function to test.\n\t * @param cases - An array of tuples. Each tuple consisting of an array of parameters and the corresponding matching criteria.\n\t * @typeParam A - The types of parameters the function accepts.\n\t * @typeParam R - The type of value the function returns.\n\t * @example\n\t * ```ts\n\t * test.cases(isEqual, [\n\t * \t[[0, 1], false],\n\t * \t[[2, 3], false],\n\t * \t[[4, 4], true],\n\t * ]);\n\t * ```\n\t * ### Comparison with Vitest\n\t * Most functions will have simple unit tests like this:\n\t * ```ts\n\t * test.each([\n\t * \t[1, 1, 2],\n\t * \t[1, 2, 3],\n\t * \t[2, 1, 3],\n\t * ])(\"add(%i, %i) -> %i\", (a, b, expected) => {\n\t * \texpect(a + b).toBe(expected)\n\t * })\n\t * ```\n\t * This is the same test, but using the `cases` wrapper instead:\n\t * ```ts\n\t * test.cases(add, [\n\t * \t[[1, 1], 2],\n\t * \t[[1, 2], 3],\n\t * \t[[2, 1], 3]\n\t * ]);\n\t * ```\n\t */\n\tcases: <A extends unknown[] = [], R = undefined>(func: (...args: A) => R, cases: [A, Matcher<R>][]) => void;\n\t/**\n\t * Tests a single case by calling the function with the given parameters and checking its behaviour\n\t * or return value against the matching criteria.\n\t * \n\t * This is the equivalent of {@link CustomTestAPI.cases}, but for a single test case.\n\t * @param func - The function to test.\n\t * @param args - The parameters to pass to the function.\n\t * @param matcher - The matching criteria.\n\t * @typeParam A - The types of parameters the function accepts.\n\t * @typeParam R - The type of value the function returns.\n\t */\n\tcase: <A extends unknown[] = [], R = undefined>(func: (...args: A) => R, args: A, matcher: Matcher<R>) => void;\n\t/**\n\t * Creates matching criteria for a test case that expects an error to be thrown.\n\t * @param error - The type of error to expect.\n\t * @param message - The error message to expect.\n\t * @see {@link CustomTestAPI.cases}\n\t*/\n\tthrows: (error: new (...args: never[]) => Error, message?: string | RegExp) => ErrorMatcher;\n\t/**\n\t * Creates matching criteria for a test case where the actual value is verified by the given assertion, \n\t * instead of simply being compared with an expected return value.\n\t * @param assert - The function that verifies the actual return value.\n\t * @param name - The name of the assertion.\n\t * @see {@link CustomTestAPI.cases}\n\t*/\n\tassert: <R>(assert: (actual: Assertion<R>) => void, name?: string) => AssertionMatcher<R>;\n\t/** Creates matching criteria for a test case that expects the actual value to be nullish (`null` or `undefined`). */\n\tnullish: <R>() => AssertionMatcher<R>;\n\t/** Creates matching criteria for a test case that expects the actual value to be [`falsy`](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */\n\tfalsy: <R>() => AssertionMatcher<R>;\n\t/** Creates matching criteria for a test case that expects the actual value to be [`truthy`](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */\n\ttruthy: <R>() => AssertionMatcher<R>;\n\t/** Negates the proceding matching criteria for a test case. */\n\tnot: Pick<CustomTestAPI, \"nullish\" | \"falsy\" | \"truthy\">;\n}\n\n/**\n * The combination of Vitest's {@link TestAPI} and the {@link CustomTestAPI}.\n */\nexport type ExtendedTestAPI<ExtraContext = object> = TestAPI<ExtraContext> & CustomTestAPI;\n\nconst DEFAULT_CONFIG: Partial<CustomTestConfig> = {\n\tformat: {\n\t\tplugins: [testInspectPlugin()],\n\t},\n};\n\n/**\n * Extends Vitest's {@link TestAPI} with functions from the {@link CustomTestAPI}.\n * @param test - The Vitest test API.\n * @param config - The configuration options.\n * @returns The extended test API.\n * @example\n * You can call this function in one file and export the result.\n * ```ts\n * // index.ts\n * import { test as base } from \"vitest\";\n * \n * export const test = extend(base);\n * ```\n * Then import and use it across your test files.\n * ```ts\n * // isEven.test.ts\n * import { test } from \"./index\";\n * \n * test.simpleCases(isEven, [\n * \t[0, true],\n * \t[1, false],\n * \t[2, true],\n * ]);\n * ```\n * ### With configuration\n * ```ts\n * import { test as base } from \"vitest\";\n * \n * export const test = extend(base, {\n * \tformat: {\n * \t\tcolors: false,\n * \t\tsingleQuotes: true,\n * \t\tspaceAfterComma: false,\n * \t},\n * });\n * ```\n */\nexport function extend<C = object>(test: TestAPI<C>, config: CustomTestConfig = {}): ExtendedTestAPI<C> {\n\tconfig = mergeDeep<Partial<CustomTestConfig>>(DEFAULT_CONFIG, config);\n\n\tconst testCustomCases: CustomTestAPI[\"cases\"] = (func, cases) => testCases(test, func, cases, config);\n\tconst testCustomCase: CustomTestAPI[\"case\"] = (func, args, expected) => testCase(test, func, args, expected, config);\n\n\treturn Object.assign(test, {\n\t\tsimpleCases: (func, cases) => testCustomCases(func, cases.map(([arg, expected]) => [[arg], expected])),\n\t\tsimpleCase: (func, arg, expected) => testCustomCase(func, [arg], expected),\n\t\tcases: testCustomCases,\n\t\tcase: testCustomCase,\n\t\tthrows,\n\t\tassert,\n\t\tnullish,\n\t\tfalsy,\n\t\ttruthy,\n\t\tnot: {\n\t\t\tnullish: nonNullish,\n\t\t\tfalsy: truthy,\n\t\t\ttruthy: falsy,\n\t\t},\n\t} satisfies CustomTestAPI);\n}\n\nfunction testCases<C = object, A extends unknown[] = [], R = undefined>(test: TestAPI<C>, func: (...args: A) => R, cases: [A, Matcher<R>][], config: Readonly<CustomTestConfig>) {\n\treturn test.each(\n\t\tcases.map(([args, expected]) => [\n\t\t\tinspectFunctionCall(func, args, expected, config.format),\n\t\t\targs,\n\t\t\texpected,\n\t\t])\n\t)(\"%s\", (_title, args, expected) => {\n\t\ttestFunction(func, args, expected);\n\t});\n}\n\nfunction testCase<C = object, A extends unknown[] = [], R = undefined>(test: TestAPI<C>, func: (...args: A) => R, args: A, expected: Matcher<R>, config: Readonly<CustomTestConfig>) {\n\treturn test(inspectFunctionCall(func, args, expected, config.format), () => {\n\t\ttestFunction(func, args, expected);\n\t});\n}\n\nfunction testFunction<A extends unknown[] = [], R = undefined>(func: (...args: A) => R, args: A, matcher: Matcher<R>) {\n\tif (isErrorMatcher(matcher)) {\n\t\tlet caught: unknown;\n\t\ttry {\n\t\t\tfunc(...args);\n\t\t} catch (e) {\n\t\t\tcaught = e;\n\t\t}\n\t\texpect(caught).toBeInstanceOf(matcher.error);\n\t\tif (matcher.message !== undefined)\n\t\t\texpect((caught as Error).message).toMatch(matcher.message);\n\t} else {\n\t\tconst actual = expect(func(...args));\n\t\tif (isAssertionMatcher(matcher)) {\n\t\t\tmatcher.assert(actual);\n\t\t} else if (matcher !== null && typeof matcher === \"object\") { // Object or array\n\t\t\tactual.toStrictEqual(matcher);\n\t\t} else {\n\t\t\tactual.toBe(matcher);\n\t\t}\n\t}\n}\n\nconst throws: CustomTestAPI[\"throws\"] = (error, message) => ({ [MATCH_ERROR]: true, error, message });\nconst assert: CustomTestAPI[\"assert\"] = (assert, name) => ({ [MATCH_ASSERTION]: true, assert, name });\nconst nullish: CustomTestAPI[\"falsy\"] = () => assert((actual) => actual.toBeNullable(), \"to be nullish\");\nconst nonNullish: CustomTestAPI[\"falsy\"] = () => assert((actual) => actual.not.toBeNullable(), \"to not be nullish\");\nconst falsy: CustomTestAPI[\"falsy\"] = () => assert((actual) => actual.toBeFalsy(), \"to be falsy\");\nconst truthy: CustomTestAPI[\"falsy\"] = () => assert((actual) => actual.toBeTruthy(), \"to be truthy\");\n\nfunction isErrorMatcher(value: unknown): value is ErrorMatcher {\n\treturn typeof value === \"object\" && value !== null && MATCH_ERROR in value;\n}\n\nfunction isAssertionMatcher<R>(value: unknown): value is AssertionMatcher<R> {\n\treturn typeof value === \"object\" && value !== null && MATCH_ASSERTION in value;\n}\n\nfunction testInspectPlugin(): InspectionPlugin {\n\treturn {\n\t\tname: \"test-inspect-plugin\",\n\t\tfirst: (value, options) => {\n\t\t\tif (isErrorMatcher(value)) {\n\t\t\t\tconst error = (options.colors ? Ansi.red(value.error.name) : value.error.name) + (value.message ? \": \" + inspect(value.message, options) : \"\");\n\t\t\t\treturn `to throw ${error}`;\n\t\t\t} else if (isAssertionMatcher(value)) {\n\t\t\t\treturn value.name ?? `to match ${inspectFunction(value.assert, options)}`;\n\t\t\t}\n\t\t},\n\t};\n};"],"names":["MATCH_ERROR","MATCH_ASSERTION","DEFAULT_CONFIG","testInspectPlugin","extend","test","config","mergeDeep","testCustomCases","func","cases","testCases","testCustomCase","args","expected","testCase","arg","throws","assert","nullish","falsy","truthy","nonNullish","inspectFunctionCall","_title","testFunction","matcher","isErrorMatcher","caught","e","expect","actual","isAssertionMatcher","error","message","name","value","options","Ansi","inspect","inspectFunction"],"mappings":";;;AAIA,MAAMA,2BAAqB,YAAY,GACjCC,2BAAyB,gBAAgB,GA4JzCC,IAA4C;AAAA,EACjD,QAAQ;AAAA,IACP,SAAS,CAACC,EAAA,CAAmB;AAAA,EAAA;AAE/B;AAuCO,SAASC,EAAmBC,GAAkBC,IAA2B,IAAwB;AACvG,EAAAA,IAASC,EAAqCL,GAAgBI,CAAM;AAEpE,QAAME,IAA0C,CAACC,GAAMC,MAAUC,E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K;AAEvB,eAAO,aADQC,EAAQ,SAASC,EAAK,IAAIF,EAAM,MAAM,IAAI,IAAIA,EAAM,MAAM,SAASA,EAAM,UAAU,OAAOG,EAAQH,EAAM,SAASC,CAAO,IAAI,GACnH;AACzB,UAAWL,EAAmBI,CAAK;AAClC,eAAOA,EAAM,QAAQ,YAAYI,EAAgBJ,EAAM,QAAQC,CAAO,CAAC;AAAA,IAEzE;AAAA,EAAA;AAEF;"}
package/dist/vite.d.ts ADDED
@@ -0,0 +1,123 @@
1
+ import { AppsConfig } from '@prozilla-os/core';
2
+ import { Plugin as Plugin_2 } from 'vite';
3
+ import { PluginOption } from 'vite';
4
+
5
+ /**
6
+ * Vite plugin that automatically adds metadata to ProzillaOS apps.
7
+ */
8
+ export declare function appMetadataPlugin({ entryPath, appClass }: AppMetadataPluginOptions): Plugin_2;
9
+
10
+ /**
11
+ * Options for the {@link appMetadataPlugin}.
12
+ */
13
+ export declare interface AppMetadataPluginOptions {
14
+ /** Path to the app's entry file, relative to the project root. */
15
+ entryPath: string;
16
+ /**
17
+ * Name of the app class.
18
+ * @default "App"
19
+ */
20
+ appClass?: string;
21
+ }
22
+
23
+ /**
24
+ * Vite plugin for building ProzillaOS apps.
25
+ * @example
26
+ * ```ts
27
+ * import { defineConfig } from "vite";
28
+ * import { appPlugin } from "@prozilla-os/dev-tools";
29
+ *
30
+ * export default defineConfig({
31
+ * plugins: [appPlugin({ entryPath: "src/main.ts" })],
32
+ * });
33
+ * ```
34
+ */
35
+ export declare function appPlugin(options: AppPluginOptions): PluginOption[];
36
+
37
+ /**
38
+ * Options for the {@link appPlugin}.
39
+ */
40
+ export declare interface AppPluginOptions {
41
+ /** Path to the app's entry file, relative to the project root. */
42
+ entryPath: string;
43
+ /** CSS class name for the app's root element. */
44
+ appClass?: string;
45
+ /** Path to the TypeScript build config. Defaults to "tsconfig.build.json". */
46
+ tsconfigPath?: string;
47
+ /** Shared package specifiers to mark as external. Auto-discovered from package.json when omitted. */
48
+ sharedPackages?: string[];
49
+ /** Additional external patterns (strings or RegExps) beyond the shared package specifiers. */
50
+ externalPatterns?: (string | RegExp)[];
51
+ }
52
+
53
+ /**
54
+ * Vite plugin that generates an import map in order to support dynamically installing apps into ProzillaOS.
55
+ */
56
+ export declare function importMapPlugin(options?: ImportMapPluginOptions): PluginOption;
57
+
58
+ /**
59
+ * Options for the {@link importMapPlugin}.
60
+ */
61
+ export declare interface ImportMapPluginOptions {
62
+ /** Packages to expose via import map. When omitted, auto-discovered from the project's package.json. */
63
+ sharedPackages?: SharedPackage[];
64
+ /** Dev-mode import map overrides for packages not handled by CommonJS shims. */
65
+ devImports?: Record<string, string>;
66
+ }
67
+
68
+ export declare interface SharedPackage {
69
+ specifier: string;
70
+ chunkName?: string;
71
+ isCommonJS?: boolean;
72
+ }
73
+
74
+ /**
75
+ * Vite plugin that combines `@vitejs/plugin-react-swc`, {@link importMapPlugin} and {@link stageSitePlugin}.
76
+ *
77
+ * This plugin can be used to build a website with ProzillaOS.
78
+ */
79
+ export declare function sitePlugin(options: SitePluginOptions): PluginOption[];
80
+
81
+ /**
82
+ * Options for the {@link sitePlugin}.
83
+ */
84
+ export declare type SitePluginOptions = StageOptions & ImportMapPluginOptions;
85
+
86
+ /**
87
+ * Options for the {@link stageSitePlugin}.
88
+ */
89
+ export declare interface StageOptions {
90
+ appsConfig: AppsConfig;
91
+ /**
92
+ * Favicon of the website.
93
+ */
94
+ favicon: string;
95
+ /**
96
+ * Name of the website.
97
+ * @example "ProzillaOS"
98
+ */
99
+ siteName: string;
100
+ /**
101
+ * Tag line of the website.
102
+ * @example "Web-based Operating System"
103
+ */
104
+ siteTagLine: string;
105
+ /**
106
+ * Domain of the live website.
107
+ *
108
+ * A CNAME file will be generated with this value.
109
+ * @example "os.prozilla.dev"
110
+ */
111
+ domain: string;
112
+ /**
113
+ * Array of image URLs that will be added to the sitemap.
114
+ */
115
+ imageUrls?: string[];
116
+ }
117
+
118
+ /**
119
+ * Vite plugin that prepares the build of a website that uses ProzillaOS.
120
+ */
121
+ export declare function stageSitePlugin(options: StageOptions): Plugin_2;
122
+
123
+ export { }
package/dist/vite.js ADDED
@@ -0,0 +1,9 @@
1
+ import { a as s, b as p, i as t, s as g, c as e } from "./chunks/site-DHHrF1BY.js";
2
+ export {
3
+ s as appMetadataPlugin,
4
+ p as appPlugin,
5
+ t as importMapPlugin,
6
+ g as sitePlugin,
7
+ e as stageSitePlugin
8
+ };
9
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prozilla-os/dev-tools",
3
3
  "description": "A library of tools for the development of ProzillaOS packages.",
4
- "version": "1.1.14",
4
+ "version": "1.2.0",
5
5
  "homepage": "https://os.prozilla.dev",
6
6
  "author": {
7
7
  "name": "Prozilla",
@@ -12,6 +12,25 @@
12
12
  "type": "module",
13
13
  "main": "dist/main.js",
14
14
  "types": "dist/main.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/main.d.ts",
18
+ "default": "./dist/main.js"
19
+ },
20
+ "./test": {
21
+ "types": "./dist/test.d.ts",
22
+ "default": "./dist/test.js"
23
+ },
24
+ "./vite": {
25
+ "types": "./dist/vite.d.ts",
26
+ "default": "./dist/vite.js"
27
+ },
28
+ "./prompts": {
29
+ "types": "./dist/prompts.d.ts",
30
+ "default": "./dist/prompts.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
15
34
  "repository": {
16
35
  "type": "git",
17
36
  "url": "git+https://github.com/prozilla-os/ProzillaOS.git",
@@ -19,20 +38,22 @@
19
38
  },
20
39
  "license": "MIT",
21
40
  "dependencies": {
22
- "@vitejs/plugin-react-swc": "^3.7.0",
41
+ "@inquirer/core": "^11.2.1",
42
+ "@vitejs/plugin-react-swc": "^3.11.0",
23
43
  "magic-string": "^0.30.21",
24
- "vite": "^7.3.1",
25
- "vite-plugin-css-injected-by-js": "^3.5.1",
44
+ "vite": "^7.3.2",
45
+ "vite-plugin-css-injected-by-js": "^3.5.2",
26
46
  "vite-plugin-dts": "^4.5.4",
27
- "vitest": "^4.0.18",
28
- "@prozilla-os/core": "2.0.2",
29
- "@prozilla-os/shared": "1.3.0"
47
+ "vitest": "^4.1.5",
48
+ "@prozilla-os/shared": "1.5.0",
49
+ "@prozilla-os/core": "3.0.0"
30
50
  },
31
51
  "devDependencies": {
32
- "@types/node": "^20.14.5",
33
- "@types/react": "^18.3.27",
34
- "rollup": "^4.57.1",
35
- "typescript": "^5.5.4"
52
+ "@types/node": "^20.19.39",
53
+ "@types/react": "^18.3.28",
54
+ "rollup": "^4.60.3",
55
+ "typescript": "^5.9.3",
56
+ "vite-plugin-externalize-deps": "^0.10.0"
36
57
  },
37
58
  "files": [
38
59
  "dist"
@@ -42,6 +63,8 @@
42
63
  "access": "public"
43
64
  },
44
65
  "scripts": {
45
- "build": "tsc && vite build"
66
+ "build": "tsc && vite build",
67
+ "test": "vitest",
68
+ "lint": "pnpm eslint ."
46
69
  }
47
70
  }