@gtkx/config 1.0.0-rc.3 → 1.0.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 +8 -9
- package/dist/config.d.ts +28 -24
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +12 -10
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +3 -2
- 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 +18 -14
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +4 -4
- package/dist/loader.js.map +1 -1
- package/dist/user-event-signals.d.ts.map +1 -1
- package/dist/user-event-signals.js +0 -6
- package/dist/user-event-signals.js.map +1 -1
- package/dist/virtual.d.ts +1 -5
- package/dist/virtual.d.ts.map +1 -1
- package/dist/virtual.js +1 -5
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts +6 -6
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +2 -5
- package/dist/vite-plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/config.ts +32 -29
- package/src/index.ts +4 -8
- package/src/internal.ts +4 -3
- package/src/loader.ts +18 -14
- package/src/user-event-signals.ts +0 -6
- package/src/virtual.ts +3 -7
- package/src/vite-plugin.ts +9 -7
package/README.md
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
The React framework for Linux.<br />
|
|
9
|
-
|
|
9
|
+
Write native Linux applications with React and TypeScript.
|
|
10
|
+
Built on the GNOME stack and standard web tooling.
|
|
10
11
|
</p>
|
|
11
12
|
|
|
12
13
|
<p align="center">
|
|
@@ -20,15 +21,13 @@
|
|
|
20
21
|
|
|
21
22
|
<p align="center">
|
|
22
23
|
<a href="https://gtkx.dev">Homepage</a> ·
|
|
23
|
-
<a href="https://gtkx.dev/guide/
|
|
24
|
+
<a href="https://gtkx.dev/guide/getting-started">Documentation</a> ·
|
|
24
25
|
<a href="https://github.com/gtkx-org/gtkx/tree/main/examples">Examples</a> ·
|
|
25
26
|
<a href="https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md">Contributing</a>
|
|
26
27
|
</p>
|
|
27
28
|
|
|
28
29
|
---
|
|
29
30
|
|
|
30
|
-
GTKX generates fully typed bindings for the entire GTK4 and Adwaita surface directly from GObject-Introspection. On top of those bindings you get the React programming model: components and hooks driving GObject instances, with Fast Refresh while you develop.
|
|
31
|
-
|
|
32
31
|
<p align="center">
|
|
33
32
|
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/examples/tutorial/assets/screenshot.png" alt="The Tasks app: an Adwaita window with a sidebar of smart views and colored lists on the left, and a boxed task list on the right." />
|
|
34
33
|
</p>
|
|
@@ -109,7 +108,7 @@ React Native and similar frameworks hide the native toolkit so one API can run e
|
|
|
109
108
|
|
|
110
109
|
### Why Node.js, and why generated bindings
|
|
111
110
|
|
|
112
|
-
GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [
|
|
111
|
+
GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [Why GTKX guide](https://gtkx.dev/guide/why-gtkx) covers what running on Node.js means day to day.
|
|
113
112
|
|
|
114
113
|
GTKX generates the TypeScript types and the native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. Codegen covers the whole GTK4 and Adwaita surface.
|
|
115
114
|
|
|
@@ -122,10 +121,10 @@ GTKX is Linux-only and needs Node.js 24 or later. See [Requirements](#requiremen
|
|
|
122
121
|
Scaffold a new app with the `create-gtkx` initializer:
|
|
123
122
|
|
|
124
123
|
```sh
|
|
125
|
-
npm create gtkx
|
|
124
|
+
npm create gtkx
|
|
126
125
|
```
|
|
127
126
|
|
|
128
|
-
The same command works with other package managers: `pnpm create gtkx
|
|
127
|
+
The same command works with other package managers: `pnpm create gtkx` or `yarn create gtkx`.
|
|
129
128
|
|
|
130
129
|
Then run your new app:
|
|
131
130
|
|
|
@@ -146,7 +145,7 @@ The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tu
|
|
|
146
145
|
|
|
147
146
|
GTKX is Linux-only. You need:
|
|
148
147
|
|
|
149
|
-
- Linux with the GTK4 (4.20 or later), Adwaita (1.8 or later)
|
|
148
|
+
- Linux with the GTK4 (4.20 or later) and GLib development libraries, plus Adwaita (1.8 or later) once your project binds `Adw-1`
|
|
150
149
|
- Node.js 24 or later
|
|
151
150
|
|
|
152
151
|
The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
|
|
@@ -162,7 +161,7 @@ Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
|
|
|
162
161
|
|
|
163
162
|
## Status
|
|
164
163
|
|
|
165
|
-
GTKX 1.0 is
|
|
164
|
+
GTKX 1.0 is released.
|
|
166
165
|
|
|
167
166
|
## Contributing
|
|
168
167
|
|
package/dist/config.d.ts
CHANGED
|
@@ -1,48 +1,53 @@
|
|
|
1
1
|
import { type DefineConfig } from "c12";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
/** Accepted `reactCompiler.compilationMode` values, choosing which functions the compiler processes. */
|
|
3
4
|
type ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];
|
|
5
|
+
/** Accepted `reactCompiler.panicThreshold` values, choosing which compiler diagnostics fail the build. */
|
|
4
6
|
type ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];
|
|
7
|
+
/** Object form of the `reactCompiler` config key, forwarded as-is to `babel-plugin-react-compiler`. */
|
|
5
8
|
type ReactCompilerOptions = {
|
|
9
|
+
/** Which functions the compiler processes; left to the compiler's own default when omitted. */
|
|
6
10
|
compilationMode?: ReactCompilerCompilationMode;
|
|
11
|
+
/** Which compiler diagnostics fail the build; left to the compiler's own default when omitted. */
|
|
7
12
|
panicThreshold?: ReactCompilerPanicThreshold;
|
|
8
13
|
};
|
|
9
14
|
/**
|
|
10
|
-
* React Compiler options
|
|
11
|
-
*
|
|
15
|
+
* The React Compiler options the build hands to `babel-plugin-react-compiler`, with the React version
|
|
16
|
+
* GTKX targets filled in.
|
|
12
17
|
*/
|
|
13
18
|
type ResolvedReactCompilerOptions = ReactCompilerOptions & {
|
|
19
|
+
/** React major version the compiler emits for. */
|
|
14
20
|
target: "19";
|
|
15
21
|
};
|
|
16
22
|
/**
|
|
17
|
-
* User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* per-element component wrappers and omitted props keyed by GLib type name, the
|
|
21
|
-
* React Compiler and codegen settings, additional user event signals to suppress
|
|
22
|
-
* during React commits, and extra GIR records to treat as class structs.
|
|
23
|
+
* User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`: the GIR libraries
|
|
24
|
+
* to bind and where to find them, the GApplication id, per-element configuration, and the React
|
|
25
|
+
* Compiler, codegen, and user event signal settings.
|
|
23
26
|
*/
|
|
24
27
|
type Config = z.infer<typeof configSchema>;
|
|
25
|
-
/** A `{ module, export }` reference to a named export, as element config entries carry it. */
|
|
26
28
|
type ModuleExport = z.infer<typeof moduleExportSchema>;
|
|
27
|
-
/**
|
|
28
|
-
* Configuration reduced to the values needed at runtime: the GApplication
|
|
29
|
-
* identifier, the resolved React Compiler options (`null` when disabled), the
|
|
30
|
-
* user event signals suppressed while a React commit is in progress, and the
|
|
31
|
-
* module path holding per-element configuration (`null` when unset).
|
|
32
|
-
*/
|
|
29
|
+
/** Configuration reduced to the values the app runtime and the build need, with paths already resolved. */
|
|
33
30
|
type ResolvedConfig = {
|
|
31
|
+
/** The GApplication identifier the app registers under. */
|
|
34
32
|
applicationId: string;
|
|
33
|
+
/** React Compiler options for the build, or `null` when the compiler is disabled. */
|
|
35
34
|
reactCompiler: ResolvedReactCompilerOptions | null;
|
|
35
|
+
/** Signal names, keyed by GLib type name, that stay suppressed while a React commit runs. */
|
|
36
36
|
userEventSignals: Record<string, string[]>;
|
|
37
|
+
/** Path of the module exporting per-element configs, or `null` when none is configured. */
|
|
37
38
|
elements: string | null;
|
|
39
|
+
/** GLib type names of the elements marked `isLazy`, whose GObject their parent container creates. */
|
|
38
40
|
lazyElements: string[];
|
|
39
41
|
};
|
|
42
|
+
/** Compilation modes `babel-plugin-react-compiler` accepts. */
|
|
40
43
|
declare const COMPILATION_MODES: readonly ["infer", "syntax", "annotation", "all"];
|
|
44
|
+
/** Panic thresholds `babel-plugin-react-compiler` accepts. */
|
|
41
45
|
declare const PANIC_THRESHOLDS: readonly ["none", "critical_errors", "all_errors"];
|
|
42
46
|
declare const moduleExportSchema: z.ZodObject<{
|
|
43
47
|
module: z.ZodString;
|
|
44
48
|
export: z.ZodString;
|
|
45
49
|
}, z.core.$strip>;
|
|
50
|
+
/** Schema every `gtkx.config.ts` is validated against, and the source of the {@link Config} type. */
|
|
46
51
|
declare const configSchema: z.ZodObject<{
|
|
47
52
|
libraries: z.ZodOptional<z.ZodCustom<string[] | "*", string[] | "*">>;
|
|
48
53
|
girPath: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -61,29 +66,28 @@ declare const configSchema: z.ZodObject<{
|
|
|
61
66
|
module: z.ZodString;
|
|
62
67
|
export: z.ZodString;
|
|
63
68
|
}, z.core.$strip>>;
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
isLazy: z.ZodOptional<z.ZodBoolean>;
|
|
70
|
+
omittedProps: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
66
71
|
}, z.core.$strip>>>;
|
|
67
72
|
}, z.core.$strip>>;
|
|
68
73
|
}, z.core.$strip>;
|
|
69
74
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
75
|
+
* Returns the given configuration unchanged, typed as {@link Config}, so `gtkx.config.ts` gets
|
|
76
|
+
* autocompletion and type checking.
|
|
72
77
|
*/
|
|
73
78
|
declare const defineConfig: DefineConfig<Config>;
|
|
74
79
|
declare const isValidApplicationId: (applicationId: string) => boolean;
|
|
75
80
|
declare const resolveReactCompilerOptions: (setting: Config["reactCompiler"]) => ResolvedReactCompilerOptions | null;
|
|
76
81
|
declare const validateConfig: (config: Config) => void;
|
|
77
82
|
/**
|
|
78
|
-
* Deep-merges two configurations
|
|
79
|
-
*
|
|
80
|
-
* @param override The higher-priority configuration whose values win on conflict.
|
|
83
|
+
* Deep-merges two configurations. `override` wins over `base` on conflicting scalar and object keys, while
|
|
84
|
+
* arrays are concatenated with the `override` entries first.
|
|
81
85
|
*/
|
|
82
86
|
declare const mergeConfig: (base: Config, override: Config) => Config;
|
|
83
87
|
declare const resolveLazyElements: (elements: Config["elements"]) => string[];
|
|
84
88
|
declare const resolveElementComponents: (elements: Config["elements"]) => Record<string, ModuleExport>;
|
|
85
89
|
declare const resolveElementProps: (elements: Config["elements"]) => Record<string, ModuleExport>;
|
|
86
|
-
declare const
|
|
90
|
+
declare const resolveOmittedProps: (elements: Config["elements"]) => Record<string, string[]>;
|
|
87
91
|
declare const resolveConfig: (config: Config, root?: string) => ResolvedConfig;
|
|
88
|
-
export { defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveElementComponents, resolveElementProps,
|
|
92
|
+
export { defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveElementComponents, resolveElementProps, resolveOmittedProps, resolveConfig, type ResolvedReactCompilerOptions, type Config, type ResolvedConfig, };
|
|
89
93
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;AAG5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,KAAK,4BAA4B,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AACvE,KAAK,2BAA2B,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,KAAK,oBAAoB,GAAG;IACxB,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAC/C,cAAc,CAAC,EAAE,2BAA2B,CAAC;CAChD,CAAC;AAEF;;;GAGG;AACH,KAAK,4BAA4B,GAAG,oBAAoB,GAAG;IACvD,MAAM,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;AAG5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,wGAAwG;AACxG,KAAK,4BAA4B,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AACvE,0GAA0G;AAC1G,KAAK,2BAA2B,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,uGAAuG;AACvG,KAAK,oBAAoB,GAAG;IACxB,+FAA+F;IAC/F,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAC/C,kGAAkG;IAClG,cAAc,CAAC,EAAE,2BAA2B,CAAC;CAChD,CAAC;AAEF;;;GAGG;AACH,KAAK,4BAA4B,GAAG,oBAAoB,GAAG;IACvD,kDAAkD;IAClD,MAAM,EAAE,IAAI,CAAC;CAChB,CAAC;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AAC;AAc/B,QAAA,MAAM,wBAAwB,GAAI,UAAU,MAAM,CAAC,UAAU,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAChC,CAAC;AAE7D,QAAA,MAAM,mBAAmB,GAAI,UAAU,MAAM,CAAC,UAAU,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAC/B,CAAC;AAEzD,QAAA,MAAM,mBAAmB,GAAI,UAAU,MAAM,CAAC,UAAU,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CACpB,CAAC;AAEhE,QAAA,MAAM,aAAa,GAAI,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,cAMrD,CAAC;AAEH,OAAO,EACH,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,KAAK,4BAA4B,EACjC,KAAK,MAAM,EACX,KAAK,cAAc,GACtB,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -8,7 +8,9 @@ const LIBRARIES_WILDCARD = "*";
|
|
|
8
8
|
const GIR_LIBRARY_PATTERN = /^[A-Za-z][A-Za-z0-9]*-\d+(?:\.\d+)*$/;
|
|
9
9
|
const APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)+$/;
|
|
10
10
|
const APPLICATION_ID_MAX_LENGTH = 255;
|
|
11
|
+
/** Compilation modes `babel-plugin-react-compiler` accepts. */
|
|
11
12
|
const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"];
|
|
13
|
+
/** Panic thresholds `babel-plugin-react-compiler` accepts. */
|
|
12
14
|
const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"];
|
|
13
15
|
const REACT_COMPILER_TARGET = "19";
|
|
14
16
|
const COMPILATION_MODE_SET = new Set(COMPILATION_MODES);
|
|
@@ -63,8 +65,8 @@ const moduleExportSchema = z.object({
|
|
|
63
65
|
const elementConfigSchema = z.object({
|
|
64
66
|
component: moduleExportSchema.optional(),
|
|
65
67
|
props: moduleExportSchema.optional(),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
isLazy: z.boolean({ error: "must be a boolean" }).optional(),
|
|
69
|
+
omittedProps: z
|
|
68
70
|
.array(z.string({ error: "must be a non-empty property name" }).min(1, {
|
|
69
71
|
error: "must be a non-empty property name",
|
|
70
72
|
}), { error: "must be an array of property names" })
|
|
@@ -77,6 +79,7 @@ const elementsSchema = z.object({
|
|
|
77
79
|
.optional(),
|
|
78
80
|
config: z.record(z.string(), elementConfigSchema).optional(),
|
|
79
81
|
});
|
|
82
|
+
/** Schema every `gtkx.config.ts` is validated against, and the source of the {@link Config} type. */
|
|
80
83
|
const configSchema = z.object({
|
|
81
84
|
libraries: librariesSchema.optional(),
|
|
82
85
|
girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
|
|
@@ -87,8 +90,8 @@ const configSchema = z.object({
|
|
|
87
90
|
elements: elementsSchema.optional(),
|
|
88
91
|
});
|
|
89
92
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
93
|
+
* Returns the given configuration unchanged, typed as {@link Config}, so `gtkx.config.ts` gets
|
|
94
|
+
* autocompletion and type checking.
|
|
92
95
|
*/
|
|
93
96
|
const defineConfig = createDefineConfig();
|
|
94
97
|
const libraryEntryIssues = (value, index, entry) => {
|
|
@@ -125,9 +128,8 @@ const validateConfig = (config) => {
|
|
|
125
128
|
}
|
|
126
129
|
};
|
|
127
130
|
/**
|
|
128
|
-
* Deep-merges two configurations
|
|
129
|
-
*
|
|
130
|
-
* @param override The higher-priority configuration whose values win on conflict.
|
|
131
|
+
* Deep-merges two configurations. `override` wins over `base` on conflicting scalar and object keys, while
|
|
132
|
+
* arrays are concatenated with the `override` entries first.
|
|
131
133
|
*/
|
|
132
134
|
const mergeConfig = (base, override) => defu(override, base);
|
|
133
135
|
const resolveElementsModule = (behaviors, root) => {
|
|
@@ -137,7 +139,7 @@ const resolveElementsModule = (behaviors, root) => {
|
|
|
137
139
|
return root === undefined ? behaviors : resolve(root, behaviors);
|
|
138
140
|
};
|
|
139
141
|
const resolveLazyElements = (elements) => Object.entries(elements?.config ?? {})
|
|
140
|
-
.filter(([, entry]) => entry.
|
|
142
|
+
.filter(([, entry]) => entry.isLazy === true)
|
|
141
143
|
.map(([type]) => type);
|
|
142
144
|
const elementEntryValues = (elements, pick) => Object.fromEntries(Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {
|
|
143
145
|
const value = pick(entry);
|
|
@@ -145,7 +147,7 @@ const elementEntryValues = (elements, pick) => Object.fromEntries(Object.entries
|
|
|
145
147
|
}));
|
|
146
148
|
const resolveElementComponents = (elements) => elementEntryValues(elements, (entry) => entry.component);
|
|
147
149
|
const resolveElementProps = (elements) => elementEntryValues(elements, (entry) => entry.props);
|
|
148
|
-
const
|
|
150
|
+
const resolveOmittedProps = (elements) => elementEntryValues(elements, (entry) => entry.omittedProps);
|
|
149
151
|
const resolveConfig = (config, root) => ({
|
|
150
152
|
applicationId: config.applicationId,
|
|
151
153
|
reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
|
|
@@ -153,5 +155,5 @@ const resolveConfig = (config, root) => ({
|
|
|
153
155
|
elements: resolveElementsModule(config.elements?.behaviors, root),
|
|
154
156
|
lazyElements: resolveLazyElements(config.elements),
|
|
155
157
|
});
|
|
156
|
-
export { defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveElementComponents, resolveElementProps,
|
|
158
|
+
export { defineConfig, isValidApplicationId, resolveReactCompilerOptions, validateConfig, mergeConfig, resolveLazyElements, resolveElementComponents, resolveElementProps, resolveOmittedProps, resolveConfig, };
|
|
157
159
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["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AAC,MAAM,CAAC,gBAAgB,CAAC;IAClE,QAAQ,EAAE,qBAAqB,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC;IACjE,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC;CACrD,CAAC,CAAC;AAEH,OAAO,EACH,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GAKhB,CAAC","sourcesContent":["import { createDefineConfig, type DefineConfig } from \"c12\";\nimport { defu } from \"defu\";\nimport { resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport { configError, isRecord, rawIssue } from \"./config-error.js\";\nimport { resolveUserEventSignals } from \"./user-event-signals.js\";\n\ntype ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];\ntype ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];\n\ntype ReactCompilerOptions = {\n compilationMode?: ReactCompilerCompilationMode;\n panicThreshold?: ReactCompilerPanicThreshold;\n};\n\n/**\n * React Compiler options resolved for the build, with the compilation target\n * fixed to React 19.\n */\ntype ResolvedReactCompilerOptions = ReactCompilerOptions & {\n target: \"19\";\n};\n\n/**\n * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:\n * the GIR libraries to bind, extra `.gir` search paths, the GApplication id,\n * a module of per-element configuration (lazy flags and custom behaviors),\n * per-element component wrappers and omitted props keyed by GLib type name, the\n * React Compiler and codegen settings, additional user event signals to suppress\n * during React commits, and extra GIR records to treat as class structs.\n */\ntype Config = z.infer<typeof configSchema>;\n/** A `{ module, export }` reference to a named export, as element config entries carry it. */\ntype ModuleExport = z.infer<typeof moduleExportSchema>;\ntype ElementConfigEntry = z.infer<typeof elementConfigSchema>;\n\n/**\n * Configuration reduced to the values needed at runtime: the GApplication\n * identifier, the resolved React Compiler options (`null` when disabled), the\n * user event signals suppressed while a React commit is in progress, and the\n * module path holding per-element configuration (`null` when unset).\n */\ntype ResolvedConfig = {\n applicationId: string;\n reactCompiler: ResolvedReactCompilerOptions | null;\n userEventSignals: Record<string, string[]>;\n elements: string | null;\n lazyElements: string[];\n};\n\nconst LIBRARIES_WILDCARD = \"*\";\nconst GIR_LIBRARY_PATTERN = /^[A-Za-z][A-Za-z0-9]*-\\d+(?:\\.\\d+)*$/;\nconst APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\\.[A-Za-z_][A-Za-z0-9_-]*)+$/;\nconst APPLICATION_ID_MAX_LENGTH = 255;\nconst COMPILATION_MODES = [\"infer\", \"syntax\", \"annotation\", \"all\"] as const;\nconst PANIC_THRESHOLDS = [\"none\", \"critical_errors\", \"all_errors\"] as const;\nconst REACT_COMPILER_TARGET = \"19\";\nconst COMPILATION_MODE_SET: Set<string> = new Set(COMPILATION_MODES);\nconst PANIC_THRESHOLD_SET: Set<string> = new Set(PANIC_THRESHOLDS);\n\nconst librariesSchema = z.custom<typeof LIBRARIES_WILDCARD | string[]>().check((ctx) => {\n const value = ctx.value;\n\n if (value === LIBRARIES_WILDCARD) {\n return;\n }\n\n if (!Array.isArray(value) || value.length === 0) {\n ctx.issues.push(rawIssue(value, [], `must be \"${LIBRARIES_WILDCARD}\", a non-empty string array, or omitted`));\n\n return;\n }\n\n for (const [index, entry] of value.entries()) {\n ctx.issues.push(...libraryEntryIssues(value, index, entry));\n }\n});\n\nconst applicationIdSchema = z.custom<string>().check((ctx) => {\n const value = ctx.value;\n\n if (typeof value !== \"string\" || !isValidApplicationId(value)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`applicationId\\` \"${value}\", must satisfy g_application_id_is_valid ` +\n '(e.g. \"org.example.MyApp\")',\n true,\n ),\n );\n }\n});\n\nconst reactCompilerSchema = z.custom<boolean | ReactCompilerOptions>().check((ctx) => {\n const value = ctx.value;\n\n if (typeof value === \"boolean\") {\n return;\n }\n\n if (!isRecord(value)) {\n ctx.issues.push(rawIssue(value, [], \"must be a boolean or an options object\"));\n\n return;\n }\n\n const compilationMode = value.compilationMode;\n\n if (!isValidReactCompilerOption(compilationMode, COMPILATION_MODE_SET)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.compilationMode\\` \"${String(compilationMode)}\", ` +\n `must be one of ${COMPILATION_MODES.join(\", \")}`,\n true,\n ),\n );\n }\n\n const panicThreshold = value.panicThreshold;\n\n if (!isValidReactCompilerOption(panicThreshold, PANIC_THRESHOLD_SET)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.panicThreshold\\` \"${String(panicThreshold)}\", ` +\n `must be one of ${PANIC_THRESHOLDS.join(\", \")}`,\n true,\n ),\n );\n }\n});\n\nconst userEventSignalsSchema = z.record(\n z.string(),\n z.array(\n z.string({ error: \"must be a non-empty signal name\" }).min(1, { error: \"must be a non-empty signal name\" }),\n {\n error: \"must be an array of signal names\",\n },\n ),\n { error: \"must be a record of GLib type names to signal name arrays\" },\n);\n\nconst moduleExportSchema = z.object(\n {\n module: z.string({ error: \"must be a module specifier\" }).min(1, { error: \"must be a module specifier\" }),\n export: z.string({ error: \"must be an export name\" }).min(1, { error: \"must be an export name\" }),\n },\n { error: \"must be a { module, export } object\" },\n);\n\nconst elementConfigSchema = z.object({\n component: moduleExportSchema.optional(),\n props: moduleExportSchema.optional(),\n lazy: z.boolean({ error: \"must be a boolean\" }).optional(),\n omitProps: z\n .array(\n z.string({ error: \"must be a non-empty property name\" }).min(1, {\n error: \"must be a non-empty property name\",\n }),\n { error: \"must be an array of property names\" },\n )\n .optional(),\n});\n\nconst elementsSchema = z.object({\n behaviors: z\n .string({ error: \"must be a path to a module exporting element behaviors\" })\n .min(1, { error: \"must be a path to a module exporting element behaviors\" })\n .optional(),\n config: z.record(z.string(), elementConfigSchema).optional(),\n});\n\nconst configSchema = z.object({\n libraries: librariesSchema.optional(),\n girPath: z.array(z.string(), { error: \"must be an array of strings if provided\" }).optional(),\n applicationId: applicationIdSchema,\n reactCompiler: reactCompilerSchema.optional(),\n codegen: z.boolean({ error: \"must be a boolean\" }).optional(),\n userEventSignals: userEventSignalsSchema.optional(),\n elements: elementsSchema.optional(),\n});\n\n/**\n * Identity helper that returns the given configuration typed as {@link Config},\n * enabling editor autocompletion and type checking in `gtkx.config.ts`.\n */\nconst defineConfig: DefineConfig<Config> = createDefineConfig<Config>();\n\nconst libraryEntryIssues = (value: unknown[], index: number, entry: unknown): ReturnType<typeof rawIssue>[] => {\n if (typeof entry === \"string\" && GIR_LIBRARY_PATTERN.test(entry)) {\n return [];\n }\n\n if (entry === LIBRARIES_WILDCARD) {\n const message =\n `to generate every library, set \\`libraries: \"${LIBRARIES_WILDCARD}\"\\` as a bare string, ` +\n \"not an array entry\";\n\n return [rawIssue(value, [index], message, true)];\n }\n\n const message =\n `invalid library identifier \"${String(entry)}\", must be of the form \"Name-Version\" ` +\n '(e.g. \"Gtk-4.0\")';\n\n return [rawIssue(value, [index], message, true)];\n};\n\nconst isValidApplicationId = (applicationId: string): boolean => {\n if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {\n return false;\n }\n\n return APPLICATION_ID_PATTERN.test(applicationId);\n};\n\nconst resolveReactCompilerOptions = (setting: Config[\"reactCompiler\"]): ResolvedReactCompilerOptions | null => {\n if (setting === false) {\n return null;\n }\n\n const overrides = setting === undefined || setting === true ? {} : setting;\n\n return { ...overrides, target: REACT_COMPILER_TARGET };\n};\n\nconst isValidReactCompilerOption = (value: unknown, allowed: Set<string>): boolean =>\n value === undefined || (typeof value === \"string\" && allowed.has(value));\n\nconst validateConfig = (config: Config): void => {\n const result = configSchema.safeParse(config);\n\n if (!result.success) {\n throw configError(result.error);\n }\n};\n\n/**\n * Deep-merges two configurations, with `override` taking precedence over `base`.\n * @param base The lower-priority configuration.\n * @param override The higher-priority configuration whose values win on conflict.\n */\nconst mergeConfig = (base: Config, override: Config): Config => defu(override, base);\n\nconst resolveElementsModule = (behaviors: string | undefined, root: string | undefined): string | null => {\n if (behaviors === undefined) {\n return null;\n }\n\n return root === undefined ? behaviors : resolve(root, behaviors);\n};\n\nconst resolveLazyElements = (elements: Config[\"elements\"]): string[] =>\n Object.entries(elements?.config ?? {})\n .filter(([, entry]) => entry.lazy === true)\n .map(([type]) => type);\n\nconst elementEntryValues = <T>(\n elements: Config[\"elements\"],\n pick: (entry: ElementConfigEntry) => T | undefined,\n): Record<string, T> =>\n Object.fromEntries(\n Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {\n const value = pick(entry);\n\n return value === undefined ? [] : [[type, value] as const];\n }),\n );\n\nconst resolveElementComponents = (elements: Config[\"elements\"]): Record<string, ModuleExport> =>\n elementEntryValues(elements, (entry) => entry.component);\n\nconst resolveElementProps = (elements: Config[\"elements\"]): Record<string, ModuleExport> =>\n elementEntryValues(elements, (entry) => entry.props);\n\nconst resolveOmitProps = (elements: Config[\"elements\"]): Record<string, string[]> =>\n elementEntryValues(elements, (entry) => entry.omitProps);\n\nconst resolveConfig = (config: Config, root?: string): ResolvedConfig => ({\n applicationId: config.applicationId,\n reactCompiler: resolveReactCompilerOptions(config.reactCompiler),\n userEventSignals: resolveUserEventSignals(config.userEventSignals),\n elements: resolveElementsModule(config.elements?.behaviors, root),\n lazyElements: resolveLazyElements(config.elements),\n});\n\nexport {\n defineConfig,\n isValidApplicationId,\n resolveReactCompilerOptions,\n validateConfig,\n mergeConfig,\n resolveLazyElements,\n resolveElementComponents,\n resolveElementProps,\n resolveOmitProps,\n resolveConfig,\n type ResolvedReactCompilerOptions,\n type Config,\n type ModuleExport,\n type ResolvedConfig,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAqB,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,M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;IACjE,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC;CACrD,CAAC,CAAC;AAEH,OAAO,EACH,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,GAIhB,CAAC","sourcesContent":["import { createDefineConfig, type DefineConfig } from \"c12\";\nimport { defu } from \"defu\";\nimport { resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport { configError, isRecord, rawIssue } from \"./config-error.ts\";\nimport { resolveUserEventSignals } from \"./user-event-signals.ts\";\n\n/** Accepted `reactCompiler.compilationMode` values, choosing which functions the compiler processes. */\ntype ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];\n/** Accepted `reactCompiler.panicThreshold` values, choosing which compiler diagnostics fail the build. */\ntype ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];\n\n/** Object form of the `reactCompiler` config key, forwarded as-is to `babel-plugin-react-compiler`. */\ntype ReactCompilerOptions = {\n /** Which functions the compiler processes; left to the compiler's own default when omitted. */\n compilationMode?: ReactCompilerCompilationMode;\n /** Which compiler diagnostics fail the build; left to the compiler's own default when omitted. */\n panicThreshold?: ReactCompilerPanicThreshold;\n};\n\n/**\n * The React Compiler options the build hands to `babel-plugin-react-compiler`, with the React version\n * GTKX targets filled in.\n */\ntype ResolvedReactCompilerOptions = ReactCompilerOptions & {\n /** React major version the compiler emits for. */\n target: \"19\";\n};\n\n/**\n * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`: the GIR libraries\n * to bind and where to find them, the GApplication id, per-element configuration, and the React\n * Compiler, codegen, and user event signal settings.\n */\ntype Config = z.infer<typeof configSchema>;\ntype ModuleExport = z.infer<typeof moduleExportSchema>;\ntype ElementConfigEntry = z.infer<typeof elementConfigSchema>;\n\n/** Configuration reduced to the values the app runtime and the build need, with paths already resolved. */\ntype ResolvedConfig = {\n /** The GApplication identifier the app registers under. */\n applicationId: string;\n /** React Compiler options for the build, or `null` when the compiler is disabled. */\n reactCompiler: ResolvedReactCompilerOptions | null;\n /** Signal names, keyed by GLib type name, that stay suppressed while a React commit runs. */\n userEventSignals: Record<string, string[]>;\n /** Path of the module exporting per-element configs, or `null` when none is configured. */\n elements: string | null;\n /** GLib type names of the elements marked `isLazy`, whose GObject their parent container creates. */\n lazyElements: string[];\n};\n\nconst LIBRARIES_WILDCARD = \"*\";\nconst GIR_LIBRARY_PATTERN = /^[A-Za-z][A-Za-z0-9]*-\\d+(?:\\.\\d+)*$/;\nconst APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\\.[A-Za-z_][A-Za-z0-9_-]*)+$/;\nconst APPLICATION_ID_MAX_LENGTH = 255;\n/** Compilation modes `babel-plugin-react-compiler` accepts. */\nconst COMPILATION_MODES = [\"infer\", \"syntax\", \"annotation\", \"all\"] as const;\n/** Panic thresholds `babel-plugin-react-compiler` accepts. */\nconst PANIC_THRESHOLDS = [\"none\", \"critical_errors\", \"all_errors\"] as const;\nconst REACT_COMPILER_TARGET = \"19\";\nconst COMPILATION_MODE_SET: Set<string> = new Set(COMPILATION_MODES);\nconst PANIC_THRESHOLD_SET: Set<string> = new Set(PANIC_THRESHOLDS);\n\nconst librariesSchema = z.custom<typeof LIBRARIES_WILDCARD | string[]>().check((ctx) => {\n const value = ctx.value;\n\n if (value === LIBRARIES_WILDCARD) {\n return;\n }\n\n if (!Array.isArray(value) || value.length === 0) {\n ctx.issues.push(rawIssue(value, [], `must be \"${LIBRARIES_WILDCARD}\", a non-empty string array, or omitted`));\n\n return;\n }\n\n for (const [index, entry] of value.entries()) {\n ctx.issues.push(...libraryEntryIssues(value, index, entry));\n }\n});\n\nconst applicationIdSchema = z.custom<string>().check((ctx) => {\n const value = ctx.value;\n\n if (typeof value !== \"string\" || !isValidApplicationId(value)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`applicationId\\` \"${value}\", must satisfy g_application_id_is_valid ` +\n '(e.g. \"org.example.MyApp\")',\n true,\n ),\n );\n }\n});\n\nconst reactCompilerSchema = z.custom<boolean | ReactCompilerOptions>().check((ctx) => {\n const value = ctx.value;\n\n if (typeof value === \"boolean\") {\n return;\n }\n\n if (!isRecord(value)) {\n ctx.issues.push(rawIssue(value, [], \"must be a boolean or an options object\"));\n\n return;\n }\n\n const compilationMode = value.compilationMode;\n\n if (!isValidReactCompilerOption(compilationMode, COMPILATION_MODE_SET)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.compilationMode\\` \"${String(compilationMode)}\", ` +\n `must be one of ${COMPILATION_MODES.join(\", \")}`,\n true,\n ),\n );\n }\n\n const panicThreshold = value.panicThreshold;\n\n if (!isValidReactCompilerOption(panicThreshold, PANIC_THRESHOLD_SET)) {\n ctx.issues.push(\n rawIssue(\n value,\n [],\n `invalid \\`reactCompiler.panicThreshold\\` \"${String(panicThreshold)}\", ` +\n `must be one of ${PANIC_THRESHOLDS.join(\", \")}`,\n true,\n ),\n );\n }\n});\n\nconst userEventSignalsSchema = z.record(\n z.string(),\n z.array(\n z.string({ error: \"must be a non-empty signal name\" }).min(1, { error: \"must be a non-empty signal name\" }),\n {\n error: \"must be an array of signal names\",\n },\n ),\n { error: \"must be a record of GLib type names to signal name arrays\" },\n);\n\nconst moduleExportSchema = z.object(\n {\n module: z.string({ error: \"must be a module specifier\" }).min(1, { error: \"must be a module specifier\" }),\n export: z.string({ error: \"must be an export name\" }).min(1, { error: \"must be an export name\" }),\n },\n { error: \"must be a { module, export } object\" },\n);\n\nconst elementConfigSchema = z.object({\n component: moduleExportSchema.optional(),\n props: moduleExportSchema.optional(),\n isLazy: z.boolean({ error: \"must be a boolean\" }).optional(),\n omittedProps: z\n .array(\n z.string({ error: \"must be a non-empty property name\" }).min(1, {\n error: \"must be a non-empty property name\",\n }),\n { error: \"must be an array of property names\" },\n )\n .optional(),\n});\n\nconst elementsSchema = z.object({\n behaviors: z\n .string({ error: \"must be a path to a module exporting element behaviors\" })\n .min(1, { error: \"must be a path to a module exporting element behaviors\" })\n .optional(),\n config: z.record(z.string(), elementConfigSchema).optional(),\n});\n\n/** Schema every `gtkx.config.ts` is validated against, and the source of the {@link Config} type. */\nconst configSchema = z.object({\n libraries: librariesSchema.optional(),\n girPath: z.array(z.string(), { error: \"must be an array of strings if provided\" }).optional(),\n applicationId: applicationIdSchema,\n reactCompiler: reactCompilerSchema.optional(),\n codegen: z.boolean({ error: \"must be a boolean\" }).optional(),\n userEventSignals: userEventSignalsSchema.optional(),\n elements: elementsSchema.optional(),\n});\n\n/**\n * Returns the given configuration unchanged, typed as {@link Config}, so `gtkx.config.ts` gets\n * autocompletion and type checking.\n */\nconst defineConfig: DefineConfig<Config> = createDefineConfig<Config>();\n\nconst libraryEntryIssues = (value: unknown[], index: number, entry: unknown): ReturnType<typeof rawIssue>[] => {\n if (typeof entry === \"string\" && GIR_LIBRARY_PATTERN.test(entry)) {\n return [];\n }\n\n if (entry === LIBRARIES_WILDCARD) {\n const message =\n `to generate every library, set \\`libraries: \"${LIBRARIES_WILDCARD}\"\\` as a bare string, ` +\n \"not an array entry\";\n\n return [rawIssue(value, [index], message, true)];\n }\n\n const message =\n `invalid library identifier \"${String(entry)}\", must be of the form \"Name-Version\" ` +\n '(e.g. \"Gtk-4.0\")';\n\n return [rawIssue(value, [index], message, true)];\n};\n\nconst isValidApplicationId = (applicationId: string): boolean => {\n if (applicationId.length === 0 || applicationId.length > APPLICATION_ID_MAX_LENGTH) {\n return false;\n }\n\n return APPLICATION_ID_PATTERN.test(applicationId);\n};\n\nconst resolveReactCompilerOptions = (setting: Config[\"reactCompiler\"]): ResolvedReactCompilerOptions | null => {\n if (setting === false) {\n return null;\n }\n\n const overrides = setting === undefined || setting === true ? {} : setting;\n\n return { ...overrides, target: REACT_COMPILER_TARGET };\n};\n\nconst isValidReactCompilerOption = (value: unknown, allowed: Set<string>): boolean =>\n value === undefined || (typeof value === \"string\" && allowed.has(value));\n\nconst validateConfig = (config: Config): void => {\n const result = configSchema.safeParse(config);\n\n if (!result.success) {\n throw configError(result.error);\n }\n};\n\n/**\n * Deep-merges two configurations. `override` wins over `base` on conflicting scalar and object keys, while\n * arrays are concatenated with the `override` entries first.\n */\nconst mergeConfig = (base: Config, override: Config): Config => defu(override, base);\n\nconst resolveElementsModule = (behaviors: string | undefined, root: string | undefined): string | null => {\n if (behaviors === undefined) {\n return null;\n }\n\n return root === undefined ? behaviors : resolve(root, behaviors);\n};\n\nconst resolveLazyElements = (elements: Config[\"elements\"]): string[] =>\n Object.entries(elements?.config ?? {})\n .filter(([, entry]) => entry.isLazy === true)\n .map(([type]) => type);\n\nconst elementEntryValues = <T>(\n elements: Config[\"elements\"],\n pick: (entry: ElementConfigEntry) => T | undefined,\n): Record<string, T> =>\n Object.fromEntries(\n Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {\n const value = pick(entry);\n\n return value === undefined ? [] : [[type, value] as const];\n }),\n );\n\nconst resolveElementComponents = (elements: Config[\"elements\"]): Record<string, ModuleExport> =>\n elementEntryValues(elements, (entry) => entry.component);\n\nconst resolveElementProps = (elements: Config[\"elements\"]): Record<string, ModuleExport> =>\n elementEntryValues(elements, (entry) => entry.props);\n\nconst resolveOmittedProps = (elements: Config[\"elements\"]): Record<string, string[]> =>\n elementEntryValues(elements, (entry) => entry.omittedProps);\n\nconst resolveConfig = (config: Config, root?: string): ResolvedConfig => ({\n applicationId: config.applicationId,\n reactCompiler: resolveReactCompilerOptions(config.reactCompiler),\n userEventSignals: resolveUserEventSignals(config.userEventSignals),\n elements: resolveElementsModule(config.elements?.behaviors, root),\n lazyElements: resolveLazyElements(config.elements),\n});\n\nexport {\n defineConfig,\n isValidApplicationId,\n resolveReactCompilerOptions,\n validateConfig,\n mergeConfig,\n resolveLazyElements,\n resolveElementComponents,\n resolveElementProps,\n resolveOmittedProps,\n resolveConfig,\n type ResolvedReactCompilerOptions,\n type Config,\n type ResolvedConfig,\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export { type
|
|
1
|
+
/** @public */
|
|
2
|
+
export { type Config, defineConfig, mergeConfig, type ResolvedConfig } from "./config.ts";
|
|
3
|
+
/** @public */
|
|
4
|
+
export { type ConfigLoader, type LoadedConfig, loadConfig } from "./loader.ts";
|
|
3
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1F,cAAc;AACd,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAe,YAAY,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAC;AAC1F,cAAc;AACd,OAAO,EAAwC,UAAU,EAAE,MAAM,aAAa,CAAC","sourcesContent":["/** @public */\nexport { type Config, defineConfig, mergeConfig, type ResolvedConfig } from \"./config.ts\";\n/** @public */\nexport { type ConfigLoader, type LoadedConfig, loadConfig } from \"./loader.ts\";\n"]}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export type { ResolvedReactCompilerOptions } from "./config.ts";
|
|
2
|
+
export { isValidApplicationId, resolveElementComponents, resolveElementProps, resolveLazyElements, resolveOmittedProps, } from "./config.ts";
|
|
3
|
+
export { createConfigLoader } from "./loader.ts";
|
|
3
4
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { isValidApplicationId, resolveElementComponents, resolveElementProps, resolveLazyElements,
|
|
1
|
+
export { isValidApplicationId, resolveElementComponents, resolveElementProps, resolveLazyElements, resolveOmittedProps, } from "./config.js";
|
|
2
2
|
export { createConfigLoader } from "./loader.js";
|
|
3
3
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AACA,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export type { ResolvedReactCompilerOptions } from \"./config.ts\";\nexport {\n isValidApplicationId,\n resolveElementComponents,\n resolveElementProps,\n resolveLazyElements,\n resolveOmittedProps,\n} from \"./config.ts\";\nexport { createConfigLoader } from \"./loader.ts\";\n"]}
|
package/dist/loader.d.ts
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
import { type Config, type ResolvedConfig } from "./config.
|
|
2
|
-
/**
|
|
3
|
-
* Result of loading a `gtkx.config.ts` file: the parsed configuration, the
|
|
4
|
-
* resolved config file path, and the project root it was loaded from.
|
|
5
|
-
*/
|
|
1
|
+
import { type Config, type ResolvedConfig } from "./config.ts";
|
|
2
|
+
/** Result of loading a project's `gtkx.config.ts` file. */
|
|
6
3
|
type LoadedConfig = {
|
|
4
|
+
/** The parsed and validated configuration. */
|
|
7
5
|
config: Config;
|
|
6
|
+
/** Absolute path of the configuration file that was loaded. */
|
|
8
7
|
configFile: string;
|
|
8
|
+
/** Absolute path of the project root the configuration was resolved against. */
|
|
9
9
|
root: string;
|
|
10
10
|
};
|
|
11
|
+
/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */
|
|
11
12
|
type LoadConfigOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* Environment name such as `development`: the config's matching `$<mode>` block is layered over the
|
|
15
|
+
* top-level values, and the name is passed to a config authored as a function.
|
|
16
|
+
*/
|
|
12
17
|
mode?: string | undefined;
|
|
13
18
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Caching accessor for a project's configuration: `load` yields the validated authored config together with
|
|
16
|
-
* its file path, and `resolve` yields the projection an app needs at runtime.
|
|
17
|
-
*/
|
|
19
|
+
/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */
|
|
18
20
|
type ConfigLoader = {
|
|
21
|
+
/** Loads the configuration file the given directory resolves to, as {@link loadConfig} does. */
|
|
19
22
|
load: (cwd: string) => Promise<LoadedConfig>;
|
|
23
|
+
/** Loads the configuration for the given directory and reduces it to what the build and the app need. */
|
|
20
24
|
resolve: (cwd: string) => Promise<ResolvedConfig>;
|
|
21
25
|
};
|
|
22
26
|
/**
|
|
23
|
-
* Loads and validates the `gtkx.config.ts` file for a project
|
|
24
|
-
*
|
|
25
|
-
* @param
|
|
26
|
-
* @
|
|
27
|
+
* Loads and validates the `gtkx.config.ts` file for a project.
|
|
28
|
+
* @param cwd Directory the configuration file is looked up in.
|
|
29
|
+
* @param options Loading options, such as the environment mode whose overrides are applied.
|
|
30
|
+
* @throws When the configuration fails validation, or when no configuration file is found.
|
|
27
31
|
*/
|
|
28
32
|
declare const loadConfig: (cwd: string, options?: LoadConfigOptions) => Promise<LoadedConfig>;
|
|
29
33
|
declare const createConfigLoader: (options?: LoadConfigOptions) => ConfigLoader;
|
|
30
|
-
export { loadConfig, createConfigLoader, type LoadedConfig, type
|
|
34
|
+
export { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader };
|
|
31
35
|
//# sourceMappingURL=loader.d.ts.map
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAiB,KAAK,cAAc,EAAkB,MAAM,aAAa,CAAC;AAE9F
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAiB,KAAK,cAAc,EAAkB,MAAM,aAAa,CAAC;AAE9F,2DAA2D;AAC3D,KAAK,YAAY,GAAG;IAChB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,+FAA+F;AAC/F,KAAK,iBAAiB,GAAG;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF,sGAAsG;AACtG,KAAK,YAAY,GAAG;IAChB,gGAAgG;IAChG,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7C,yGAAyG;IACzG,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,UAAU,GAAU,KAAK,MAAM,EAAE,UAAS,iBAAsB,KAAG,OAAO,CAAC,YAAY,CAwB5F,CAAC;AAEF,QAAA,MAAM,kBAAkB,GAAI,UAAS,iBAAsB,KAAG,YAiB7D,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,CAAC"}
|
package/dist/loader.js
CHANGED
|
@@ -4,10 +4,10 @@ import { existsSync } from "node:fs";
|
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { resolveConfig, validateConfig } from "./config.js";
|
|
6
6
|
/**
|
|
7
|
-
* Loads and validates the `gtkx.config.ts` file for a project
|
|
8
|
-
*
|
|
9
|
-
* @param
|
|
10
|
-
* @
|
|
7
|
+
* Loads and validates the `gtkx.config.ts` file for a project.
|
|
8
|
+
* @param cwd Directory the configuration file is looked up in.
|
|
9
|
+
* @param options Loading options, such as the environment mode whose overrides are applied.
|
|
10
|
+
* @throws When the configuration fails validation, or when no configuration file is found.
|
|
11
11
|
*/
|
|
12
12
|
const loadConfig = async (cwd, options = {}) => {
|
|
13
13
|
const result = await loadConfigFile({
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;A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AC;QACpE,MAAM,IAAI,KAAK,CAAC,wDAAwD,GAAG,EAAE,CAAC,CAAC;IACnF,CAAC;IAED,OAAO;QACH,MAAM;QACN,UAAU;QACV,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG;KAC1B,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,UAA6B,EAAE,EAAgB,EAAE;IACzE,MAAM,MAAM,GAAuC,IAAI,GAAG,EAAE,CAAC;IAC7D,MAAM,QAAQ,GAAyC,IAAI,GAAG,EAAE,CAAC;IAEjE,MAAM,IAAI,GAAG,CAAC,GAAW,EAAyB,EAAE,CAChD,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAE3E,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAA2B,EAAE;QAC9D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtD,OAAO,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,OAAO;QACH,IAAI;QACJ,OAAO,EAAE,CAAC,GAAW,EAA2B,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC;KACpG,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAwC,CAAC","sourcesContent":["import { getOrInsert } from \"@gtkx/utils\";\nimport { loadConfig as loadConfigFile } from \"c12\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { type Config, resolveConfig, type ResolvedConfig, validateConfig } from \"./config.ts\";\n\n/** Result of loading a project's `gtkx.config.ts` file. */\ntype LoadedConfig = {\n /** The parsed and validated configuration. */\n config: Config;\n /** Absolute path of the configuration file that was loaded. */\n configFile: string;\n /** Absolute path of the project root the configuration was resolved against. */\n root: string;\n};\n\n/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */\ntype LoadConfigOptions = {\n /**\n * Environment name such as `development`: the config's matching `$<mode>` block is layered over the\n * top-level values, and the name is passed to a config authored as a function.\n */\n mode?: string | undefined;\n};\n\n/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */\ntype ConfigLoader = {\n /** Loads the configuration file the given directory resolves to, as {@link loadConfig} does. */\n load: (cwd: string) => Promise<LoadedConfig>;\n /** Loads the configuration for the given directory and reduces it to what the build and the app need. */\n resolve: (cwd: string) => Promise<ResolvedConfig>;\n};\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project.\n * @param cwd Directory the configuration file is looked up in.\n * @param options Loading options, such as the environment mode whose overrides are applied.\n * @throws When the configuration fails validation, or when no configuration file is found.\n */\nconst loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {\n const result = await loadConfigFile<Config>({\n name: \"gtkx\",\n cwd,\n rcFile: false,\n globalRc: false,\n packageJson: false,\n context: { mode: options.mode },\n ...((options.mode !== undefined) && { envName: options.mode }),\n });\n\n const config = result.config;\n const configFile = result.configFile;\n validateConfig(config);\n\n if (configFile === undefined || !existsSync(resolve(cwd, configFile))) {\n throw new Error(`gtkx.config.ts: no configuration file was found from ${cwd}`);\n }\n\n return {\n config,\n configFile,\n root: result.cwd ?? cwd,\n };\n};\n\nconst createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {\n const loaded: Map<string, Promise<LoadedConfig>> = new Map();\n const resolved: Map<string, Promise<ResolvedConfig>> = new Map();\n\n const load = (cwd: string): Promise<LoadedConfig> =>\n getOrInsert(loaded, resolve(cwd), (root) => loadConfig(root, options));\n\n const resolveAt = async (root: string): Promise<ResolvedConfig> => {\n const { config, root: configRoot } = await load(root);\n\n return resolveConfig(config, configRoot);\n };\n\n return {\n load,\n resolve: (cwd: string): Promise<ResolvedConfig> => getOrInsert(resolved, resolve(cwd), resolveAt),\n };\n};\n\nexport { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-event-signals.d.ts","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"user-event-signals.d.ts","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAqCxD,CAAC;AAEF,QAAA,MAAM,uBAAuB,GAAI,WAAW,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CASzG,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -6,15 +6,11 @@ const DEFAULT_USER_EVENT_SIGNALS = {
|
|
|
6
6
|
AdwTabView: ["close-page", "page-attached", "page-detached", "page-reordered"],
|
|
7
7
|
GObject: ["notify"],
|
|
8
8
|
GtkAdjustment: ["changed", "value-changed"],
|
|
9
|
-
GtkAppChooserButton: ["changed"],
|
|
10
|
-
GtkAppChooserWidget: ["application-selected"],
|
|
11
9
|
GtkCalendar: ["day-selected"],
|
|
12
10
|
GtkCheckButton: ["toggled"],
|
|
13
|
-
GtkComboBox: ["changed"],
|
|
14
11
|
GtkEditable: ["changed", "delete-text", "insert-text"],
|
|
15
12
|
GtkEntryBuffer: ["deleted-text", "inserted-text"],
|
|
16
13
|
GtkFlowBox: ["selected-children-changed"],
|
|
17
|
-
GtkIconView: ["selection-changed"],
|
|
18
14
|
GtkListBox: ["row-selected", "selected-rows-changed"],
|
|
19
15
|
GtkNotebook: ["page-added", "page-removed", "page-reordered", "switch-page"],
|
|
20
16
|
GtkPopover: ["closed"],
|
|
@@ -38,8 +34,6 @@ const DEFAULT_USER_EVENT_SIGNALS = {
|
|
|
38
34
|
"remove-tag",
|
|
39
35
|
],
|
|
40
36
|
GtkToggleButton: ["toggled"],
|
|
41
|
-
GtkTreeSelection: ["changed"],
|
|
42
|
-
GtkTreeView: ["columns-changed", "cursor-changed", "row-collapsed", "row-expanded"],
|
|
43
37
|
GtkWidget: ["state-flags-changed"],
|
|
44
38
|
};
|
|
45
39
|
const resolveUserEventSignals = (overrides) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-event-signals.js","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAAA,MAAM,0BAA0B,GAA6B;IACzD,cAAc,EAAE,CAAC,UAAU,CAAC;IAC5B,WAAW,EAAE,CAAC,cAAc,CAAC;IAC7B,SAAS,EAAE,CAAC,QAAQ,CAAC;IACrB,iBAAiB,EAAE,CAAC,QAAQ,CAAC;IAC7B,UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,CAAC;IAC9E,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,aAAa,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC;IAC3C,
|
|
1
|
+
{"version":3,"file":"user-event-signals.js","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAAA,MAAM,0BAA0B,GAA6B;IACzD,cAAc,EAAE,CAAC,UAAU,CAAC;IAC5B,WAAW,EAAE,CAAC,cAAc,CAAC;IAC7B,SAAS,EAAE,CAAC,QAAQ,CAAC;IACrB,iBAAiB,EAAE,CAAC,QAAQ,CAAC;IAC7B,UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,CAAC;IAC9E,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,aAAa,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC;IAC3C,WAAW,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QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,CAAC","sourcesContent":["const DEFAULT_USER_EVENT_SIGNALS: Record<string, string[]> = {\n AdwAlertDialog: [\"response\"],\n AdwCarousel: [\"page-changed\"],\n AdwDialog: [\"closed\"],\n AdwNavigationView: [\"pushed\"],\n AdwTabView: [\"close-page\", \"page-attached\", \"page-detached\", \"page-reordered\"],\n GObject: [\"notify\"],\n GtkAdjustment: [\"changed\", \"value-changed\"],\n GtkCalendar: [\"day-selected\"],\n GtkCheckButton: [\"toggled\"],\n GtkEditable: [\"changed\", \"delete-text\", \"insert-text\"],\n GtkEntryBuffer: [\"deleted-text\", \"inserted-text\"],\n GtkFlowBox: [\"selected-children-changed\"],\n GtkListBox: [\"row-selected\", \"selected-rows-changed\"],\n GtkNotebook: [\"page-added\", \"page-removed\", \"page-reordered\", \"switch-page\"],\n GtkPopover: [\"closed\"],\n GtkRange: [\"value-changed\"],\n GtkScaleButton: [\"value-changed\"],\n GtkScrolledWindow: [\"edge-reached\"],\n GtkSearchEntry: [\"search-changed\"],\n GtkSelectionModel: [\"selection-changed\"],\n GtkSpinButton: [\"value-changed\"],\n GtkSwitch: [\"state-set\"],\n GtkTextBuffer: [\n \"apply-tag\",\n \"changed\",\n \"delete-range\",\n \"insert-child-anchor\",\n \"insert-paintable\",\n \"insert-text\",\n \"mark-deleted\",\n \"mark-set\",\n \"modified-changed\",\n \"remove-tag\",\n ],\n GtkToggleButton: [\"toggled\"],\n GtkWidget: [\"state-flags-changed\"],\n};\n\nconst resolveUserEventSignals = (overrides: Record<string, string[]> | undefined): Record<string, string[]> => {\n const resolved: Record<string, string[]> = { ...DEFAULT_USER_EVENT_SIGNALS };\n const overrideEntries = Object.entries(overrides ?? {});\n\n for (const [typeName, signals] of overrideEntries) {\n resolved[typeName] = [...new Set([...(resolved[typeName] ?? []), ...signals])];\n }\n\n return resolved;\n};\n\nexport { DEFAULT_USER_EVENT_SIGNALS, resolveUserEventSignals };\n"]}
|
package/dist/virtual.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import type { ResolvedConfig } from "./config.
|
|
1
|
+
import type { ResolvedConfig } from "./config.ts";
|
|
2
2
|
declare const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
|
|
3
3
|
declare const RESOLVED_GTKX_CONFIG_VIRTUAL_ID = "\0virtual:gtkx-config";
|
|
4
|
-
/**
|
|
5
|
-
* The runtime element config is the app's static per-element config (currently its lazy flags) merged
|
|
6
|
-
* with its behaviors module, so a single `elements` map is registered.
|
|
7
|
-
*/
|
|
8
4
|
declare const renderConfigModule: (config: ResolvedConfig) => string;
|
|
9
5
|
export { GTKX_CONFIG_VIRTUAL_ID, RESOLVED_GTKX_CONFIG_VIRTUAL_ID, renderConfigModule };
|
|
10
6
|
//# sourceMappingURL=virtual.d.ts.map
|
package/dist/virtual.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,QAAA,MAAM,sBAAsB,wBAAwB,CAAC;AACrD,QAAA,MAAM,+BAA+B,0BAAgC,CAAC;AAMtE
|
|
1
|
+
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,QAAA,MAAM,sBAAsB,wBAAwB,CAAC;AACrD,QAAA,MAAM,+BAA+B,0BAAgC,CAAC;AAMtE,QAAA,MAAM,kBAAkB,GAAI,QAAQ,cAAc,KAAG,MAoBpD,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/virtual.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
|
|
2
2
|
const RESOLVED_GTKX_CONFIG_VIRTUAL_ID = `\0${GTKX_CONFIG_VIRTUAL_ID}`;
|
|
3
3
|
const METADATA_SPECIFIER = "@gtkx/jsx/metadata";
|
|
4
|
-
const lazyElementConfig = (lazyElements) => Object.fromEntries(lazyElements.map((type) => [type, {
|
|
5
|
-
/**
|
|
6
|
-
* The runtime element config is the app's static per-element config (currently its lazy flags) merged
|
|
7
|
-
* with its behaviors module, so a single `elements` map is registered.
|
|
8
|
-
*/
|
|
4
|
+
const lazyElementConfig = (lazyElements) => Object.fromEntries(lazyElements.map((type) => [type, { isLazy: true }]));
|
|
9
5
|
const renderConfigModule = (config) => {
|
|
10
6
|
const lazyJson = JSON.stringify(lazyElementConfig(config.lazyElements));
|
|
11
7
|
const behaviorImports = config.elements === null
|
package/dist/virtual.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual.js","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAEA,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AACrD,MAAM,+BAA+B,GAAG,KAAK,sBAAsB,EAAE,CAAC;AACtE,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEhD,MAAM,iBAAiB,GAAG,CAAC,YAAsB,
|
|
1
|
+
{"version":3,"file":"virtual.js","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAEA,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AACrD,MAAM,+BAA+B,GAAG,KAAK,sBAAsB,EAAE,CAAC;AACtE,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEhD,MAAM,iBAAiB,GAAG,CAAC,YAAsB,EAAuC,EAAE,CACtF,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAE7E,MAAM,kBAAkB,GAAG,CAAC,MAAsB,EAAU,EAAE;IAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IAExE,MAAM,eAAe,GACjB,MAAM,CAAC,QAAQ,KAAK,IAAI;QACpB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC;YACM,6DAA6D;YAC7D,kCAAkC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG;SACvE,CAAC;IAEd,OAAO;QACH,GAAG,eAAe;QAClB,iBAAiB,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,GAAG;QACtD,gCAAgC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG;QACvE,mCAAmC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG;QAC7E,MAAM,CAAC,QAAQ,KAAK,IAAI;YACpB,CAAC,CAAC,2BAA2B,QAAQ,GAAG;YACxC,CAAC,CAAC,mEAAmE,QAAQ,IAAI;KACxF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import type { ResolvedConfig } from \"./config.ts\";\n\nconst GTKX_CONFIG_VIRTUAL_ID = \"virtual:gtkx-config\";\nconst RESOLVED_GTKX_CONFIG_VIRTUAL_ID = `\\0${GTKX_CONFIG_VIRTUAL_ID}`;\nconst METADATA_SPECIFIER = \"@gtkx/jsx/metadata\";\n\nconst lazyElementConfig = (lazyElements: string[]): Record<string, { isLazy: boolean }> =>\n Object.fromEntries(lazyElements.map((type) => [type, { isLazy: true }]));\n\nconst renderConfigModule = (config: ResolvedConfig): string => {\n const lazyJson = JSON.stringify(lazyElementConfig(config.lazyElements));\n\n const behaviorImports =\n config.elements === null\n ? []\n : [\n \"import { mergeElementConfigs } from \\\"@gtkx/react/config\\\";\",\n `import __elementBehaviors from ${JSON.stringify(config.elements)};`,\n ];\n\n return [\n ...behaviorImports,\n `export * from ${JSON.stringify(METADATA_SPECIFIER)};`,\n `export const applicationId = ${JSON.stringify(config.applicationId)};`,\n `export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,\n config.elements === null\n ? `export const elements = ${lazyJson};`\n : `export const elements = mergeElementConfigs(__elementBehaviors, ${lazyJson});`,\n ].join(\"\\n\");\n};\n\nexport { GTKX_CONFIG_VIRTUAL_ID, RESOLVED_GTKX_CONFIG_VIRTUAL_ID, renderConfigModule };\n"]}
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
|
-
import { type ConfigLoader } from "./loader.
|
|
2
|
+
import { type ConfigLoader } from "./loader.ts";
|
|
3
3
|
/**
|
|
4
|
-
* Creates
|
|
5
|
-
*
|
|
6
|
-
* project's configuration.
|
|
7
|
-
* @param options Plugin name, an optional custom {@link ConfigLoader}, and an
|
|
8
|
-
* optional hook returning extra Vite user config.
|
|
4
|
+
* Creates a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved
|
|
5
|
+
* `gtkx.config.ts`.
|
|
9
6
|
*/
|
|
10
7
|
declare const createConfigPlugin: (options: {
|
|
8
|
+
/** Name the plugin is registered under in Vite. */
|
|
11
9
|
name: string;
|
|
10
|
+
/** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
|
|
12
11
|
loadConfig?: ConfigLoader;
|
|
12
|
+
/** Extra Vite configuration contributed from the plugin's `config` hook. */
|
|
13
13
|
config?: () => Omit<UserConfig, "plugins">;
|
|
14
14
|
}) => Plugin;
|
|
15
15
|
export default createConfigPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,aAAa,CAAC;AAwBpE;;;GAGG;AACH,QAAA,MAAM,kBAAkB,GAAI,SAAS;IACjC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;CAC9C,KAAG,MAcH,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
package/dist/vite-plugin.js
CHANGED
|
@@ -8,11 +8,8 @@ const loadVirtualModule = async (id, loadConfig, state) => {
|
|
|
8
8
|
return renderConfigModule(await loadConfig.resolve(state.root ?? process.cwd()));
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Creates
|
|
12
|
-
*
|
|
13
|
-
* project's configuration.
|
|
14
|
-
* @param options Plugin name, an optional custom {@link ConfigLoader}, and an
|
|
15
|
-
* optional hook returning extra Vite user config.
|
|
11
|
+
* Creates a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved
|
|
12
|
+
* `gtkx.config.ts`.
|
|
16
13
|
*/
|
|
17
14
|
const createConfigPlugin = (options) => {
|
|
18
15
|
const loadConfig = options.loadConfig ?? createConfigLoader();
|
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAQ3G,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAiB,EAAE,CACnD,EAAE,KAAK,sBAAsB,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,IAAI,CAAC;AAE3E,MAAM,iBAAiB,GAAG,KAAK,EAC3B,EAAU,EACV,UAAwB,EACxB,KAAkB,EACS,EAAE;IAC7B,IAAI,EAAE,KAAK,+BAA+B,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,OAAO,kBAAkB,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AACrF,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,kBAAkB,GAAG,CAAC,OAO3B,EAAU,EAAE;IACT,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,kBAAkB,EAAE,CAAC;IAC9D,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAE/C,OAAO;QACH,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,MAAM,CAAC,MAAkB;YACrB,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;YAEvC,OAAO,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAC9B,CAAC;QACD,SAAS,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC/C,IAAI,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC;KACjE,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import type { Plugin, UserConfig } from \"vite\";\nimport { type ConfigLoader, createConfigLoader } from \"./loader.ts\";\nimport { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from \"./virtual.ts\";\n\n/** State the plugin carries from Vite's `config` hook to the virtual module it serves. */\ntype PluginState = {\n /** Project root taken from Vite's `config` hook, undefined when the user config leaves it unset. */\n root: string | undefined;\n};\n\nconst resolveVirtualId = (id: string): string | null =>\n id === GTKX_CONFIG_VIRTUAL_ID ? RESOLVED_GTKX_CONFIG_VIRTUAL_ID : null;\n\nconst loadVirtualModule = async (\n id: string,\n loadConfig: ConfigLoader,\n state: PluginState,\n): Promise<string | undefined> => {\n if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {\n return undefined;\n }\n\n return renderConfigModule(await loadConfig.resolve(state.root ?? process.cwd()));\n};\n\n/**\n * Creates a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved\n * `gtkx.config.ts`.\n */\nconst createConfigPlugin = (options: {\n /** Name the plugin is registered under in Vite. */\n name: string;\n /** Loader the configuration is resolved through, defaulting to a fresh caching loader. */\n loadConfig?: ConfigLoader;\n /** Extra Vite configuration contributed from the plugin's `config` hook. */\n config?: () => Omit<UserConfig, \"plugins\">;\n}): Plugin => {\n const loadConfig = options.loadConfig ?? createConfigLoader();\n const state: PluginState = { root: undefined };\n\n return {\n name: options.name,\n config(config: UserConfig) {\n state.root = config.root ?? state.root;\n\n return options.config?.();\n },\n resolveId: (id: string) => resolveVirtualId(id),\n load: (id: string) => loadVirtualModule(id, loadConfig, state),\n };\n};\n\nexport default createConfigPlugin;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/config",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "gtkx.config.ts schema, loader, and the element-prop mapping language shared across the GTKX toolchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"c12": "^3.3.4",
|
|
52
52
|
"defu": "^6.1.7",
|
|
53
|
-
"vite": "^8.1
|
|
53
|
+
"vite": "^8.2.1",
|
|
54
54
|
"zod": "^4.4.3",
|
|
55
|
-
"@gtkx/utils": "1.0.0
|
|
55
|
+
"@gtkx/utils": "1.0.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"release": "tsx ../../scripts/release-package.ts"
|
package/src/config.ts
CHANGED
|
@@ -2,49 +2,51 @@ import { createDefineConfig, type DefineConfig } from "c12";
|
|
|
2
2
|
import { defu } from "defu";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { configError, isRecord, rawIssue } from "./config-error.
|
|
6
|
-
import { resolveUserEventSignals } from "./user-event-signals.
|
|
5
|
+
import { configError, isRecord, rawIssue } from "./config-error.ts";
|
|
6
|
+
import { resolveUserEventSignals } from "./user-event-signals.ts";
|
|
7
7
|
|
|
8
|
+
/** Accepted `reactCompiler.compilationMode` values, choosing which functions the compiler processes. */
|
|
8
9
|
type ReactCompilerCompilationMode = (typeof COMPILATION_MODES)[number];
|
|
10
|
+
/** Accepted `reactCompiler.panicThreshold` values, choosing which compiler diagnostics fail the build. */
|
|
9
11
|
type ReactCompilerPanicThreshold = (typeof PANIC_THRESHOLDS)[number];
|
|
10
12
|
|
|
13
|
+
/** Object form of the `reactCompiler` config key, forwarded as-is to `babel-plugin-react-compiler`. */
|
|
11
14
|
type ReactCompilerOptions = {
|
|
15
|
+
/** Which functions the compiler processes; left to the compiler's own default when omitted. */
|
|
12
16
|
compilationMode?: ReactCompilerCompilationMode;
|
|
17
|
+
/** Which compiler diagnostics fail the build; left to the compiler's own default when omitted. */
|
|
13
18
|
panicThreshold?: ReactCompilerPanicThreshold;
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
|
-
* React Compiler options
|
|
18
|
-
*
|
|
22
|
+
* The React Compiler options the build hands to `babel-plugin-react-compiler`, with the React version
|
|
23
|
+
* GTKX targets filled in.
|
|
19
24
|
*/
|
|
20
25
|
type ResolvedReactCompilerOptions = ReactCompilerOptions & {
|
|
26
|
+
/** React major version the compiler emits for. */
|
|
21
27
|
target: "19";
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
|
-
* User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`:
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* per-element component wrappers and omitted props keyed by GLib type name, the
|
|
29
|
-
* React Compiler and codegen settings, additional user event signals to suppress
|
|
30
|
-
* during React commits, and extra GIR records to treat as class structs.
|
|
31
|
+
* User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`: the GIR libraries
|
|
32
|
+
* to bind and where to find them, the GApplication id, per-element configuration, and the React
|
|
33
|
+
* Compiler, codegen, and user event signal settings.
|
|
31
34
|
*/
|
|
32
35
|
type Config = z.infer<typeof configSchema>;
|
|
33
|
-
/** A `{ module, export }` reference to a named export, as element config entries carry it. */
|
|
34
36
|
type ModuleExport = z.infer<typeof moduleExportSchema>;
|
|
35
37
|
type ElementConfigEntry = z.infer<typeof elementConfigSchema>;
|
|
36
38
|
|
|
37
|
-
/**
|
|
38
|
-
* Configuration reduced to the values needed at runtime: the GApplication
|
|
39
|
-
* identifier, the resolved React Compiler options (`null` when disabled), the
|
|
40
|
-
* user event signals suppressed while a React commit is in progress, and the
|
|
41
|
-
* module path holding per-element configuration (`null` when unset).
|
|
42
|
-
*/
|
|
39
|
+
/** Configuration reduced to the values the app runtime and the build need, with paths already resolved. */
|
|
43
40
|
type ResolvedConfig = {
|
|
41
|
+
/** The GApplication identifier the app registers under. */
|
|
44
42
|
applicationId: string;
|
|
43
|
+
/** React Compiler options for the build, or `null` when the compiler is disabled. */
|
|
45
44
|
reactCompiler: ResolvedReactCompilerOptions | null;
|
|
45
|
+
/** Signal names, keyed by GLib type name, that stay suppressed while a React commit runs. */
|
|
46
46
|
userEventSignals: Record<string, string[]>;
|
|
47
|
+
/** Path of the module exporting per-element configs, or `null` when none is configured. */
|
|
47
48
|
elements: string | null;
|
|
49
|
+
/** GLib type names of the elements marked `isLazy`, whose GObject their parent container creates. */
|
|
48
50
|
lazyElements: string[];
|
|
49
51
|
};
|
|
50
52
|
|
|
@@ -52,7 +54,9 @@ const LIBRARIES_WILDCARD = "*";
|
|
|
52
54
|
const GIR_LIBRARY_PATTERN = /^[A-Za-z][A-Za-z0-9]*-\d+(?:\.\d+)*$/;
|
|
53
55
|
const APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)+$/;
|
|
54
56
|
const APPLICATION_ID_MAX_LENGTH = 255;
|
|
57
|
+
/** Compilation modes `babel-plugin-react-compiler` accepts. */
|
|
55
58
|
const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
|
|
59
|
+
/** Panic thresholds `babel-plugin-react-compiler` accepts. */
|
|
56
60
|
const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"] as const;
|
|
57
61
|
const REACT_COMPILER_TARGET = "19";
|
|
58
62
|
const COMPILATION_MODE_SET: Set<string> = new Set(COMPILATION_MODES);
|
|
@@ -156,8 +160,8 @@ const moduleExportSchema = z.object(
|
|
|
156
160
|
const elementConfigSchema = z.object({
|
|
157
161
|
component: moduleExportSchema.optional(),
|
|
158
162
|
props: moduleExportSchema.optional(),
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
isLazy: z.boolean({ error: "must be a boolean" }).optional(),
|
|
164
|
+
omittedProps: z
|
|
161
165
|
.array(
|
|
162
166
|
z.string({ error: "must be a non-empty property name" }).min(1, {
|
|
163
167
|
error: "must be a non-empty property name",
|
|
@@ -175,6 +179,7 @@ const elementsSchema = z.object({
|
|
|
175
179
|
config: z.record(z.string(), elementConfigSchema).optional(),
|
|
176
180
|
});
|
|
177
181
|
|
|
182
|
+
/** Schema every `gtkx.config.ts` is validated against, and the source of the {@link Config} type. */
|
|
178
183
|
const configSchema = z.object({
|
|
179
184
|
libraries: librariesSchema.optional(),
|
|
180
185
|
girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
|
|
@@ -186,8 +191,8 @@ const configSchema = z.object({
|
|
|
186
191
|
});
|
|
187
192
|
|
|
188
193
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
194
|
+
* Returns the given configuration unchanged, typed as {@link Config}, so `gtkx.config.ts` gets
|
|
195
|
+
* autocompletion and type checking.
|
|
191
196
|
*/
|
|
192
197
|
const defineConfig: DefineConfig<Config> = createDefineConfig<Config>();
|
|
193
198
|
|
|
@@ -241,9 +246,8 @@ const validateConfig = (config: Config): void => {
|
|
|
241
246
|
};
|
|
242
247
|
|
|
243
248
|
/**
|
|
244
|
-
* Deep-merges two configurations
|
|
245
|
-
*
|
|
246
|
-
* @param override The higher-priority configuration whose values win on conflict.
|
|
249
|
+
* Deep-merges two configurations. `override` wins over `base` on conflicting scalar and object keys, while
|
|
250
|
+
* arrays are concatenated with the `override` entries first.
|
|
247
251
|
*/
|
|
248
252
|
const mergeConfig = (base: Config, override: Config): Config => defu(override, base);
|
|
249
253
|
|
|
@@ -257,7 +261,7 @@ const resolveElementsModule = (behaviors: string | undefined, root: string | und
|
|
|
257
261
|
|
|
258
262
|
const resolveLazyElements = (elements: Config["elements"]): string[] =>
|
|
259
263
|
Object.entries(elements?.config ?? {})
|
|
260
|
-
.filter(([, entry]) => entry.
|
|
264
|
+
.filter(([, entry]) => entry.isLazy === true)
|
|
261
265
|
.map(([type]) => type);
|
|
262
266
|
|
|
263
267
|
const elementEntryValues = <T>(
|
|
@@ -278,8 +282,8 @@ const resolveElementComponents = (elements: Config["elements"]): Record<string,
|
|
|
278
282
|
const resolveElementProps = (elements: Config["elements"]): Record<string, ModuleExport> =>
|
|
279
283
|
elementEntryValues(elements, (entry) => entry.props);
|
|
280
284
|
|
|
281
|
-
const
|
|
282
|
-
elementEntryValues(elements, (entry) => entry.
|
|
285
|
+
const resolveOmittedProps = (elements: Config["elements"]): Record<string, string[]> =>
|
|
286
|
+
elementEntryValues(elements, (entry) => entry.omittedProps);
|
|
283
287
|
|
|
284
288
|
const resolveConfig = (config: Config, root?: string): ResolvedConfig => ({
|
|
285
289
|
applicationId: config.applicationId,
|
|
@@ -298,10 +302,9 @@ export {
|
|
|
298
302
|
resolveLazyElements,
|
|
299
303
|
resolveElementComponents,
|
|
300
304
|
resolveElementProps,
|
|
301
|
-
|
|
305
|
+
resolveOmittedProps,
|
|
302
306
|
resolveConfig,
|
|
303
307
|
type ResolvedReactCompilerOptions,
|
|
304
308
|
type Config,
|
|
305
|
-
type ModuleExport,
|
|
306
309
|
type ResolvedConfig,
|
|
307
310
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type ResolvedConfig,
|
|
6
|
-
type ResolvedReactCompilerOptions,
|
|
7
|
-
} from "./config.js";
|
|
8
|
-
export { type LoadedConfig, loadConfig } from "./loader.js";
|
|
1
|
+
/** @public */
|
|
2
|
+
export { type Config, defineConfig, mergeConfig, type ResolvedConfig } from "./config.ts";
|
|
3
|
+
/** @public */
|
|
4
|
+
export { type ConfigLoader, type LoadedConfig, loadConfig } from "./loader.ts";
|
package/src/internal.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export type { ResolvedReactCompilerOptions } from "./config.ts";
|
|
1
2
|
export {
|
|
2
3
|
isValidApplicationId,
|
|
3
4
|
resolveElementComponents,
|
|
4
5
|
resolveElementProps,
|
|
5
6
|
resolveLazyElements,
|
|
6
|
-
|
|
7
|
-
} from "./config.
|
|
8
|
-
export {
|
|
7
|
+
resolveOmittedProps,
|
|
8
|
+
} from "./config.ts";
|
|
9
|
+
export { createConfigLoader } from "./loader.ts";
|
package/src/loader.ts
CHANGED
|
@@ -2,36 +2,40 @@ import { getOrInsert } from "@gtkx/utils";
|
|
|
2
2
|
import { loadConfig as loadConfigFile } from "c12";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
|
-
import { type Config, resolveConfig, type ResolvedConfig, validateConfig } from "./config.
|
|
5
|
+
import { type Config, resolveConfig, type ResolvedConfig, validateConfig } from "./config.ts";
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Result of loading a `gtkx.config.ts` file: the parsed configuration, the
|
|
9
|
-
* resolved config file path, and the project root it was loaded from.
|
|
10
|
-
*/
|
|
7
|
+
/** Result of loading a project's `gtkx.config.ts` file. */
|
|
11
8
|
type LoadedConfig = {
|
|
9
|
+
/** The parsed and validated configuration. */
|
|
12
10
|
config: Config;
|
|
11
|
+
/** Absolute path of the configuration file that was loaded. */
|
|
13
12
|
configFile: string;
|
|
13
|
+
/** Absolute path of the project root the configuration was resolved against. */
|
|
14
14
|
root: string;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */
|
|
17
18
|
type LoadConfigOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Environment name such as `development`: the config's matching `$<mode>` block is layered over the
|
|
21
|
+
* top-level values, and the name is passed to a config authored as a function.
|
|
22
|
+
*/
|
|
18
23
|
mode?: string | undefined;
|
|
19
24
|
};
|
|
20
25
|
|
|
21
|
-
/**
|
|
22
|
-
* Caching accessor for a project's configuration: `load` yields the validated authored config together with
|
|
23
|
-
* its file path, and `resolve` yields the projection an app needs at runtime.
|
|
24
|
-
*/
|
|
26
|
+
/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */
|
|
25
27
|
type ConfigLoader = {
|
|
28
|
+
/** Loads the configuration file the given directory resolves to, as {@link loadConfig} does. */
|
|
26
29
|
load: (cwd: string) => Promise<LoadedConfig>;
|
|
30
|
+
/** Loads the configuration for the given directory and reduces it to what the build and the app need. */
|
|
27
31
|
resolve: (cwd: string) => Promise<ResolvedConfig>;
|
|
28
32
|
};
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
|
-
* Loads and validates the `gtkx.config.ts` file for a project
|
|
32
|
-
*
|
|
33
|
-
* @param
|
|
34
|
-
* @
|
|
35
|
+
* Loads and validates the `gtkx.config.ts` file for a project.
|
|
36
|
+
* @param cwd Directory the configuration file is looked up in.
|
|
37
|
+
* @param options Loading options, such as the environment mode whose overrides are applied.
|
|
38
|
+
* @throws When the configuration fails validation, or when no configuration file is found.
|
|
35
39
|
*/
|
|
36
40
|
const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {
|
|
37
41
|
const result = await loadConfigFile<Config>({
|
|
@@ -78,4 +82,4 @@ const createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {
|
|
|
78
82
|
};
|
|
79
83
|
};
|
|
80
84
|
|
|
81
|
-
export { loadConfig, createConfigLoader, type LoadedConfig, type
|
|
85
|
+
export { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader };
|
|
@@ -6,15 +6,11 @@ const DEFAULT_USER_EVENT_SIGNALS: Record<string, string[]> = {
|
|
|
6
6
|
AdwTabView: ["close-page", "page-attached", "page-detached", "page-reordered"],
|
|
7
7
|
GObject: ["notify"],
|
|
8
8
|
GtkAdjustment: ["changed", "value-changed"],
|
|
9
|
-
GtkAppChooserButton: ["changed"],
|
|
10
|
-
GtkAppChooserWidget: ["application-selected"],
|
|
11
9
|
GtkCalendar: ["day-selected"],
|
|
12
10
|
GtkCheckButton: ["toggled"],
|
|
13
|
-
GtkComboBox: ["changed"],
|
|
14
11
|
GtkEditable: ["changed", "delete-text", "insert-text"],
|
|
15
12
|
GtkEntryBuffer: ["deleted-text", "inserted-text"],
|
|
16
13
|
GtkFlowBox: ["selected-children-changed"],
|
|
17
|
-
GtkIconView: ["selection-changed"],
|
|
18
14
|
GtkListBox: ["row-selected", "selected-rows-changed"],
|
|
19
15
|
GtkNotebook: ["page-added", "page-removed", "page-reordered", "switch-page"],
|
|
20
16
|
GtkPopover: ["closed"],
|
|
@@ -38,8 +34,6 @@ const DEFAULT_USER_EVENT_SIGNALS: Record<string, string[]> = {
|
|
|
38
34
|
"remove-tag",
|
|
39
35
|
],
|
|
40
36
|
GtkToggleButton: ["toggled"],
|
|
41
|
-
GtkTreeSelection: ["changed"],
|
|
42
|
-
GtkTreeView: ["columns-changed", "cursor-changed", "row-collapsed", "row-expanded"],
|
|
43
37
|
GtkWidget: ["state-flags-changed"],
|
|
44
38
|
};
|
|
45
39
|
|
package/src/virtual.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import type { ResolvedConfig } from "./config.
|
|
1
|
+
import type { ResolvedConfig } from "./config.ts";
|
|
2
2
|
|
|
3
3
|
const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
|
|
4
4
|
const RESOLVED_GTKX_CONFIG_VIRTUAL_ID = `\0${GTKX_CONFIG_VIRTUAL_ID}`;
|
|
5
5
|
const METADATA_SPECIFIER = "@gtkx/jsx/metadata";
|
|
6
6
|
|
|
7
|
-
const lazyElementConfig = (lazyElements: string[]): Record<string, {
|
|
8
|
-
Object.fromEntries(lazyElements.map((type) => [type, {
|
|
7
|
+
const lazyElementConfig = (lazyElements: string[]): Record<string, { isLazy: boolean }> =>
|
|
8
|
+
Object.fromEntries(lazyElements.map((type) => [type, { isLazy: true }]));
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* The runtime element config is the app's static per-element config (currently its lazy flags) merged
|
|
12
|
-
* with its behaviors module, so a single `elements` map is registered.
|
|
13
|
-
*/
|
|
14
10
|
const renderConfigModule = (config: ResolvedConfig): string => {
|
|
15
11
|
const lazyJson = JSON.stringify(lazyElementConfig(config.lazyElements));
|
|
16
12
|
|
package/src/vite-plugin.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
|
-
import { type ConfigLoader, createConfigLoader } from "./loader.
|
|
3
|
-
import { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from "./virtual.
|
|
2
|
+
import { type ConfigLoader, createConfigLoader } from "./loader.ts";
|
|
3
|
+
import { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from "./virtual.ts";
|
|
4
4
|
|
|
5
|
+
/** State the plugin carries from Vite's `config` hook to the virtual module it serves. */
|
|
5
6
|
type PluginState = {
|
|
7
|
+
/** Project root taken from Vite's `config` hook, undefined when the user config leaves it unset. */
|
|
6
8
|
root: string | undefined;
|
|
7
9
|
};
|
|
8
10
|
|
|
@@ -22,15 +24,15 @@ const loadVirtualModule = async (
|
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
* Creates
|
|
26
|
-
*
|
|
27
|
-
* project's configuration.
|
|
28
|
-
* @param options Plugin name, an optional custom {@link ConfigLoader}, and an
|
|
29
|
-
* optional hook returning extra Vite user config.
|
|
27
|
+
* Creates a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved
|
|
28
|
+
* `gtkx.config.ts`.
|
|
30
29
|
*/
|
|
31
30
|
const createConfigPlugin = (options: {
|
|
31
|
+
/** Name the plugin is registered under in Vite. */
|
|
32
32
|
name: string;
|
|
33
|
+
/** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
|
|
33
34
|
loadConfig?: ConfigLoader;
|
|
35
|
+
/** Extra Vite configuration contributed from the plugin's `config` hook. */
|
|
34
36
|
config?: () => Omit<UserConfig, "plugins">;
|
|
35
37
|
}): Plugin => {
|
|
36
38
|
const loadConfig = options.loadConfig ?? createConfigLoader();
|