@gtkx/config 1.0.0 → 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.
- package/README.md +1 -1
- package/dist/config-error.d.ts +2 -1
- package/dist/config-error.d.ts.map +1 -1
- package/dist/config-error.js +16 -4
- package/dist/config-error.js.map +1 -1
- package/dist/config.d.ts +242 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -1
- package/dist/config.js.map +1 -1
- package/dist/deploy.d.ts +237 -0
- package/dist/deploy.d.ts.map +1 -0
- package/dist/deploy.js +232 -0
- package/dist/deploy.js.map +1 -0
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/loader.d.ts +2 -2
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +10 -8
- package/dist/loader.js.map +1 -1
- package/dist/schema-text.d.ts +10 -0
- package/dist/schema-text.d.ts.map +1 -0
- package/dist/schema-text.js +19 -0
- package/dist/schema-text.js.map +1 -0
- package/dist/user-event-signals.d.ts +1 -2
- package/dist/user-event-signals.d.ts.map +1 -1
- package/dist/user-event-signals.js +1 -1
- package/dist/user-event-signals.js.map +1 -1
- package/dist/vite-plugin.d.ts +2 -2
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +1 -1
- package/dist/vite-plugin.js.map +1 -1
- package/package.json +12 -2
- package/src/config-error.ts +23 -4
- package/src/config.ts +11 -3
- package/src/deploy.ts +260 -0
- package/src/internal.ts +1 -0
- package/src/loader.ts +12 -8
- package/src/schema-text.ts +38 -0
- package/src/user-event-signals.ts +1 -1
- package/src/vite-plugin.ts +3 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
const FILE_EXTENSION = /^[^\s./\\*?[\]]+(?:\.[^\s./\\*?[\]]+)*$/;
|
|
4
|
+
const SEGMENT_SEPARATOR = /[/\\]/;
|
|
5
|
+
|
|
6
|
+
const isRelativePath = (value: string): boolean => {
|
|
7
|
+
if (value.length === 0 || value.startsWith("/") || value.includes("\\")) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return value.split(SEGMENT_SEPARATOR).every((part) => part !== "" && part !== "..");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const text = (message: string): z.ZodString => z.string({ error: message }).min(1, { error: message });
|
|
15
|
+
|
|
16
|
+
const textList = (itemNoun: string, listMessage: string): z.ZodArray<z.ZodString> =>
|
|
17
|
+
z.array(text(`must be a non-empty ${itemNoun}`), { error: listMessage });
|
|
18
|
+
|
|
19
|
+
const url = (message: string): z.ZodURL => z.url({ error: message });
|
|
20
|
+
const flag = (message: string): z.ZodBoolean => z.boolean({ error: message });
|
|
21
|
+
|
|
22
|
+
const textRecord = (valueMessage: string, recordMessage: string): z.ZodRecord<z.ZodString, z.ZodString> =>
|
|
23
|
+
z.record(z.string(), text(valueMessage), { error: recordMessage });
|
|
24
|
+
|
|
25
|
+
const fileExtension = (message: string): z.ZodString =>
|
|
26
|
+
z.string({ error: message }).refine((value) => FILE_EXTENSION.test(value), { error: message });
|
|
27
|
+
|
|
28
|
+
const relativePath = (message: string): z.ZodString =>
|
|
29
|
+
z.string({ error: message }).refine((value) => isRelativePath(value), { error: message });
|
|
30
|
+
|
|
31
|
+
const relativePathRecord = (
|
|
32
|
+
keyMessage: string,
|
|
33
|
+
valueMessage: string,
|
|
34
|
+
recordMessage: string,
|
|
35
|
+
): z.ZodRecord<z.ZodString, z.ZodString> =>
|
|
36
|
+
z.record(relativePath(keyMessage), text(valueMessage), { error: recordMessage });
|
|
37
|
+
|
|
38
|
+
export { fileExtension, flag, relativePathRecord, text, textList, textRecord, url };
|
package/src/vite-plugin.ts
CHANGED
|
@@ -32,8 +32,8 @@ const createConfigPlugin = (options: {
|
|
|
32
32
|
name: string;
|
|
33
33
|
/** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
|
|
34
34
|
loadConfig?: ConfigLoader;
|
|
35
|
-
/** Extra Vite configuration contributed from the plugin's `config` hook. */
|
|
36
|
-
config?: () => Omit<UserConfig, "plugins">;
|
|
35
|
+
/** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */
|
|
36
|
+
config?: (config: UserConfig) => Omit<UserConfig, "plugins">;
|
|
37
37
|
}): Plugin => {
|
|
38
38
|
const loadConfig = options.loadConfig ?? createConfigLoader();
|
|
39
39
|
const state: PluginState = { root: undefined };
|
|
@@ -43,7 +43,7 @@ const createConfigPlugin = (options: {
|
|
|
43
43
|
config(config: UserConfig) {
|
|
44
44
|
state.root = config.root ?? state.root;
|
|
45
45
|
|
|
46
|
-
return options.config?.();
|
|
46
|
+
return options.config?.(config);
|
|
47
47
|
},
|
|
48
48
|
resolveId: (id: string) => resolveVirtualId(id),
|
|
49
49
|
load: (id: string) => loadVirtualModule(id, loadConfig, state),
|