@gtkx/cli 1.0.0-rc.1 → 1.0.0-rc.2

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.
Files changed (286) hide show
  1. package/dist/builder.d.ts +3 -2
  2. package/dist/builder.d.ts.map +1 -1
  3. package/dist/builder.js +2 -1
  4. package/dist/builder.js.map +1 -1
  5. package/dist/cli.d.ts +1 -1
  6. package/dist/cli.d.ts.map +1 -1
  7. package/dist/cli.js +21 -6
  8. package/dist/cli.js.map +1 -1
  9. package/dist/codegen/freshness.d.ts +5 -5
  10. package/dist/codegen/freshness.d.ts.map +1 -1
  11. package/dist/codegen/freshness.js +26 -23
  12. package/dist/codegen/freshness.js.map +1 -1
  13. package/dist/codegen/report.d.ts +2 -1
  14. package/dist/codegen/report.d.ts.map +1 -1
  15. package/dist/codegen/report.js +4 -2
  16. package/dist/codegen/report.js.map +1 -1
  17. package/dist/codegen/run-codegen.d.ts +8 -8
  18. package/dist/codegen/run-codegen.d.ts.map +1 -1
  19. package/dist/codegen/run-codegen.js +72 -43
  20. package/dist/codegen/run-codegen.js.map +1 -1
  21. package/dist/codegen/store-resolver.d.ts +8 -5
  22. package/dist/codegen/store-resolver.d.ts.map +1 -1
  23. package/dist/codegen/store-resolver.js +26 -6
  24. package/dist/codegen/store-resolver.js.map +1 -1
  25. package/dist/commands/build.d.ts +4 -3
  26. package/dist/commands/build.d.ts.map +1 -1
  27. package/dist/commands/build.js +2 -1
  28. package/dist/commands/build.js.map +1 -1
  29. package/dist/commands/codegen.d.ts +2 -1
  30. package/dist/commands/codegen.d.ts.map +1 -1
  31. package/dist/commands/codegen.js +6 -4
  32. package/dist/commands/codegen.js.map +1 -1
  33. package/dist/commands/dev.d.ts +2 -1
  34. package/dist/commands/dev.d.ts.map +1 -1
  35. package/dist/commands/dev.js +2 -1
  36. package/dist/commands/dev.js.map +1 -1
  37. package/dist/commands/docs.d.ts +2 -1
  38. package/dist/commands/docs.d.ts.map +1 -1
  39. package/dist/commands/docs.js +22 -7
  40. package/dist/commands/docs.js.map +1 -1
  41. package/dist/dev/icon-dir.d.ts +2 -1
  42. package/dist/dev/icon-dir.d.ts.map +1 -1
  43. package/dist/dev/icon-dir.js +6 -3
  44. package/dist/dev/icon-dir.js.map +1 -1
  45. package/dist/dev/refresh-tracker.d.ts +5 -4
  46. package/dist/dev/refresh-tracker.d.ts.map +1 -1
  47. package/dist/dev/refresh-tracker.js +6 -5
  48. package/dist/dev/refresh-tracker.js.map +1 -1
  49. package/dist/dev/runner-deps.d.ts +2 -1
  50. package/dist/dev/runner-deps.d.ts.map +1 -1
  51. package/dist/dev/runner-deps.js +20 -4
  52. package/dist/dev/runner-deps.js.map +1 -1
  53. package/dist/dev/runner-main.d.ts +2 -1
  54. package/dist/dev/runner-main.d.ts.map +1 -1
  55. package/dist/dev/runner-main.js +3 -2
  56. package/dist/dev/runner-main.js.map +1 -1
  57. package/dist/dev/runner.d.ts +6 -5
  58. package/dist/dev/runner.d.ts.map +1 -1
  59. package/dist/dev/runner.js +69 -38
  60. package/dist/dev/runner.js.map +1 -1
  61. package/dist/dev/schema-dir.d.ts +2 -1
  62. package/dist/dev/schema-dir.d.ts.map +1 -1
  63. package/dist/dev/schema-dir.js +4 -2
  64. package/dist/dev/schema-dir.js.map +1 -1
  65. package/dist/dev/supervisor.d.ts +7 -6
  66. package/dist/dev/supervisor.d.ts.map +1 -1
  67. package/dist/dev/supervisor.js +107 -67
  68. package/dist/dev/supervisor.js.map +1 -1
  69. package/dist/dev/vite-dev-server.d.ts +3 -3
  70. package/dist/dev/vite-dev-server.d.ts.map +1 -1
  71. package/dist/dev/vite-dev-server.js +2 -1
  72. package/dist/dev/vite-dev-server.js.map +1 -1
  73. package/dist/internal/banner.d.ts +2 -1
  74. package/dist/internal/banner.d.ts.map +1 -1
  75. package/dist/internal/banner.js +2 -1
  76. package/dist/internal/banner.js.map +1 -1
  77. package/dist/internal/data-dir.d.ts +3 -2
  78. package/dist/internal/data-dir.d.ts.map +1 -1
  79. package/dist/internal/data-dir.js +29 -14
  80. package/dist/internal/data-dir.js.map +1 -1
  81. package/dist/internal/entry-arg.d.ts +5 -4
  82. package/dist/internal/entry-arg.d.ts.map +1 -1
  83. package/dist/internal/entry-arg.js +10 -7
  84. package/dist/internal/entry-arg.js.map +1 -1
  85. package/dist/internal/errors.d.ts +3 -2
  86. package/dist/internal/errors.d.ts.map +1 -1
  87. package/dist/internal/errors.js +7 -5
  88. package/dist/internal/errors.js.map +1 -1
  89. package/dist/internal/list-files.d.ts +3 -2
  90. package/dist/internal/list-files.d.ts.map +1 -1
  91. package/dist/internal/list-files.js +5 -3
  92. package/dist/internal/list-files.js.map +1 -1
  93. package/dist/internal/resolve-cli-tool.d.ts +2 -1
  94. package/dist/internal/resolve-cli-tool.d.ts.map +1 -1
  95. package/dist/internal/resolve-cli-tool.js +17 -10
  96. package/dist/internal/resolve-cli-tool.js.map +1 -1
  97. package/dist/internal/staging-dir.d.ts +3 -2
  98. package/dist/internal/staging-dir.d.ts.map +1 -1
  99. package/dist/internal/staging-dir.js +3 -2
  100. package/dist/internal/staging-dir.js.map +1 -1
  101. package/dist/internal/xdg-data-dirs.d.ts +2 -1
  102. package/dist/internal/xdg-data-dirs.d.ts.map +1 -1
  103. package/dist/internal/xdg-data-dirs.js +4 -2
  104. package/dist/internal/xdg-data-dirs.js.map +1 -1
  105. package/dist/mcp/client.d.ts +9 -4
  106. package/dist/mcp/client.d.ts.map +1 -1
  107. package/dist/mcp/client.js +106 -81
  108. package/dist/mcp/client.js.map +1 -1
  109. package/dist/mcp/handlers.d.ts +3 -2
  110. package/dist/mcp/handlers.d.ts.map +1 -1
  111. package/dist/mcp/handlers.js +89 -61
  112. package/dist/mcp/handlers.js.map +1 -1
  113. package/dist/mcp/index.d.ts +2 -2
  114. package/dist/mcp/index.d.ts.map +1 -1
  115. package/dist/mcp/index.js +30 -13
  116. package/dist/mcp/index.js.map +1 -1
  117. package/dist/mcp/serialize-widget.d.ts +3 -3
  118. package/dist/mcp/serialize-widget.d.ts.map +1 -1
  119. package/dist/mcp/serialize-widget.js +9 -6
  120. package/dist/mcp/serialize-widget.js.map +1 -1
  121. package/dist/mcp/testing-loader.d.ts +3 -4
  122. package/dist/mcp/testing-loader.d.ts.map +1 -1
  123. package/dist/mcp/testing-loader.js +43 -21
  124. package/dist/mcp/testing-loader.js.map +1 -1
  125. package/dist/mcp/widget-registry.d.ts +3 -2
  126. package/dist/mcp/widget-registry.d.ts.map +1 -1
  127. package/dist/mcp/widget-registry.js +4 -3
  128. package/dist/mcp/widget-registry.js.map +1 -1
  129. package/dist/refresh-globals.d.ts +2 -0
  130. package/dist/refresh-globals.d.ts.map +1 -0
  131. package/dist/refresh-globals.js +8 -0
  132. package/dist/refresh-globals.js.map +1 -0
  133. package/dist/refresh-runtime.d.ts +5 -11
  134. package/dist/refresh-runtime.d.ts.map +1 -1
  135. package/dist/refresh-runtime.js +16 -14
  136. package/dist/refresh-runtime.js.map +1 -1
  137. package/dist/settings/compile.d.ts +2 -1
  138. package/dist/settings/compile.d.ts.map +1 -1
  139. package/dist/settings/compile.js +6 -4
  140. package/dist/settings/compile.js.map +1 -1
  141. package/dist/settings/parser.d.ts +6 -5
  142. package/dist/settings/parser.d.ts.map +1 -1
  143. package/dist/settings/parser.js +26 -22
  144. package/dist/settings/parser.js.map +1 -1
  145. package/dist/settings/render.d.ts +3 -2
  146. package/dist/settings/render.d.ts.map +1 -1
  147. package/dist/settings/render.js +38 -64
  148. package/dist/settings/render.js.map +1 -1
  149. package/dist/settings/schema.d.ts +8 -8
  150. package/dist/settings/schema.d.ts.map +1 -1
  151. package/dist/settings/schema.js +61 -43
  152. package/dist/settings/schema.js.map +1 -1
  153. package/dist/vite-plugins/asset-extensions.d.ts +4 -3
  154. package/dist/vite-plugins/asset-extensions.d.ts.map +1 -1
  155. package/dist/vite-plugins/asset-extensions.js +4 -3
  156. package/dist/vite-plugins/asset-extensions.js.map +1 -1
  157. package/dist/vite-plugins/built-url.d.ts +2 -1
  158. package/dist/vite-plugins/built-url.d.ts.map +1 -1
  159. package/dist/vite-plugins/built-url.js +19 -13
  160. package/dist/vite-plugins/built-url.js.map +1 -1
  161. package/dist/vite-plugins/css.d.ts +2 -1
  162. package/dist/vite-plugins/css.d.ts.map +1 -1
  163. package/dist/vite-plugins/css.js +23 -15
  164. package/dist/vite-plugins/css.js.map +1 -1
  165. package/dist/vite-plugins/fast-refresh/refresh-filter.d.ts +5 -4
  166. package/dist/vite-plugins/fast-refresh/refresh-filter.d.ts.map +1 -1
  167. package/dist/vite-plugins/fast-refresh/refresh-filter.js +11 -7
  168. package/dist/vite-plugins/fast-refresh/refresh-filter.js.map +1 -1
  169. package/dist/vite-plugins/fast-refresh/swc-refresh.d.ts +4 -3
  170. package/dist/vite-plugins/fast-refresh/swc-refresh.d.ts.map +1 -1
  171. package/dist/vite-plugins/fast-refresh/swc-refresh.js +45 -41
  172. package/dist/vite-plugins/fast-refresh/swc-refresh.js.map +1 -1
  173. package/dist/vite-plugins/icons.d.ts +2 -1
  174. package/dist/vite-plugins/icons.d.ts.map +1 -1
  175. package/dist/vite-plugins/icons.js +24 -20
  176. package/dist/vite-plugins/icons.js.map +1 -1
  177. package/dist/vite-plugins/index.d.ts +2 -1
  178. package/dist/vite-plugins/index.d.ts.map +1 -1
  179. package/dist/vite-plugins/index.js +3 -2
  180. package/dist/vite-plugins/index.js.map +1 -1
  181. package/dist/vite-plugins/native.d.ts +2 -1
  182. package/dist/vite-plugins/native.d.ts.map +1 -1
  183. package/dist/vite-plugins/native.js +6 -4
  184. package/dist/vite-plugins/native.js.map +1 -1
  185. package/dist/vite-plugins/react-compiler.d.ts +3 -2
  186. package/dist/vite-plugins/react-compiler.d.ts.map +1 -1
  187. package/dist/vite-plugins/react-compiler.js +26 -20
  188. package/dist/vite-plugins/react-compiler.js.map +1 -1
  189. package/dist/vite-plugins/react-dom-prebundle.d.ts +2 -1
  190. package/dist/vite-plugins/react-dom-prebundle.d.ts.map +1 -1
  191. package/dist/vite-plugins/react-dom-prebundle.js +2 -1
  192. package/dist/vite-plugins/react-dom-prebundle.js.map +1 -1
  193. package/dist/vite-plugins/resource-init-module.d.ts +2 -1
  194. package/dist/vite-plugins/resource-init-module.d.ts.map +1 -1
  195. package/dist/vite-plugins/resource-init-module.js +39 -38
  196. package/dist/vite-plugins/resource-init-module.js.map +1 -1
  197. package/dist/vite-plugins/resource-shared.d.ts +7 -5
  198. package/dist/vite-plugins/resource-shared.d.ts.map +1 -1
  199. package/dist/vite-plugins/resource-shared.js +17 -10
  200. package/dist/vite-plugins/resource-shared.js.map +1 -1
  201. package/dist/vite-plugins/resources.d.ts +3 -2
  202. package/dist/vite-plugins/resources.d.ts.map +1 -1
  203. package/dist/vite-plugins/resources.js +94 -54
  204. package/dist/vite-plugins/resources.js.map +1 -1
  205. package/dist/vite-plugins/settings-worker-env.d.ts +2 -1
  206. package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -1
  207. package/dist/vite-plugins/settings-worker-env.js +4 -2
  208. package/dist/vite-plugins/settings-worker-env.js.map +1 -1
  209. package/dist/vite-plugins/settings.d.ts +2 -1
  210. package/dist/vite-plugins/settings.d.ts.map +1 -1
  211. package/dist/vite-plugins/settings.js +56 -32
  212. package/dist/vite-plugins/settings.js.map +1 -1
  213. package/dist/vite-plugins/strip-query.d.ts +3 -0
  214. package/dist/vite-plugins/strip-query.d.ts.map +1 -0
  215. package/dist/vite-plugins/strip-query.js +6 -0
  216. package/dist/vite-plugins/strip-query.js.map +1 -0
  217. package/dist/vite-plugins/undeclared-library.d.ts +2 -1
  218. package/dist/vite-plugins/undeclared-library.d.ts.map +1 -1
  219. package/dist/vite-plugins/undeclared-library.js +8 -5
  220. package/dist/vite-plugins/undeclared-library.js.map +1 -1
  221. package/dist/vite-plugins/virtual-module.d.ts +2 -2
  222. package/dist/vite-plugins/virtual-module.d.ts.map +1 -1
  223. package/dist/vite-plugins/virtual-module.js +5 -3
  224. package/dist/vite-plugins/virtual-module.js.map +1 -1
  225. package/dist/vitest-plugin.d.ts.map +1 -1
  226. package/dist/vitest-plugin.js.map +1 -1
  227. package/env.d.ts +21 -61
  228. package/package.json +12 -14
  229. package/src/babel-modules.d.ts +0 -2
  230. package/src/builder.ts +7 -6
  231. package/src/cli.ts +26 -6
  232. package/src/codegen/freshness.ts +38 -25
  233. package/src/codegen/report.ts +10 -2
  234. package/src/codegen/run-codegen.ts +135 -60
  235. package/src/codegen/store-resolver.ts +56 -15
  236. package/src/commands/build.ts +3 -2
  237. package/src/commands/codegen.ts +9 -4
  238. package/src/commands/dev.ts +3 -4
  239. package/src/commands/docs.ts +36 -7
  240. package/src/dev/icon-dir.ts +13 -3
  241. package/src/dev/refresh-tracker.ts +12 -8
  242. package/src/dev/runner-deps.ts +30 -7
  243. package/src/dev/runner-main.ts +4 -3
  244. package/src/dev/runner.ts +100 -41
  245. package/src/dev/schema-dir.ts +7 -2
  246. package/src/dev/supervisor.ts +169 -71
  247. package/src/dev/vite-dev-server.ts +4 -2
  248. package/src/internal/banner.ts +5 -1
  249. package/src/internal/data-dir.ts +47 -16
  250. package/src/internal/entry-arg.ts +16 -8
  251. package/src/internal/errors.ts +15 -7
  252. package/src/internal/list-files.ts +10 -4
  253. package/src/internal/resolve-cli-tool.ts +28 -12
  254. package/src/internal/staging-dir.ts +5 -2
  255. package/src/internal/xdg-data-dirs.ts +8 -2
  256. package/src/mcp/client.ts +143 -85
  257. package/src/mcp/handlers.ts +126 -69
  258. package/src/mcp/index.ts +38 -14
  259. package/src/mcp/serialize-widget.ts +15 -8
  260. package/src/mcp/testing-loader.ts +64 -23
  261. package/src/mcp/widget-registry.ts +11 -5
  262. package/src/refresh-globals.ts +10 -0
  263. package/src/refresh-runtime.ts +20 -16
  264. package/src/settings/compile.ts +7 -4
  265. package/src/settings/parser.ts +69 -30
  266. package/src/settings/render.ts +66 -66
  267. package/src/settings/schema.ts +100 -46
  268. package/src/vite-plugins/asset-extensions.ts +4 -3
  269. package/src/vite-plugins/built-url.ts +30 -15
  270. package/src/vite-plugins/css.ts +35 -20
  271. package/src/vite-plugins/fast-refresh/refresh-filter.ts +18 -10
  272. package/src/vite-plugins/fast-refresh/swc-refresh.ts +60 -47
  273. package/src/vite-plugins/icons.ts +40 -24
  274. package/src/vite-plugins/index.ts +6 -3
  275. package/src/vite-plugins/native.ts +14 -5
  276. package/src/vite-plugins/react-compiler.ts +44 -30
  277. package/src/vite-plugins/react-dom-prebundle.ts +4 -1
  278. package/src/vite-plugins/resource-init-module.ts +41 -38
  279. package/src/vite-plugins/resource-shared.ts +27 -14
  280. package/src/vite-plugins/resources.ts +153 -59
  281. package/src/vite-plugins/settings-worker-env.ts +7 -2
  282. package/src/vite-plugins/settings.ts +107 -42
  283. package/src/vite-plugins/strip-query.ts +7 -0
  284. package/src/vite-plugins/undeclared-library.ts +21 -12
  285. package/src/vite-plugins/virtual-module.ts +9 -2
  286. package/src/vitest-plugin.ts +1 -2
@@ -1,8 +1,8 @@
1
+ import type { ModuleNode, Plugin, ResolvedConfig, UserConfig, ViteDevServer } from "vite";
2
+ import { error, errorMessage, info } from "@gtkx/utils";
1
3
  import { mkdtempSync, readFileSync } from "node:fs";
2
4
  import { tmpdir } from "node:os";
3
5
  import { basename, join } from "node:path";
4
- import { error, errorMessage, info } from "@gtkx/utils";
5
- import type { ModuleNode, Plugin, UserConfig, ViteDevServer } from "vite";
6
6
  import { prependBanner } from "../internal/banner.js";
7
7
  import { resolveDataDir } from "../internal/data-dir.js";
8
8
  import { removeTempDir, withStagingDir } from "../internal/staging-dir.js";
@@ -12,18 +12,6 @@ import { renderRuntimeModule } from "../settings/render.js";
12
12
  import { emitSchemaEnv, prependSchemaDir, SCHEMA_SUFFIX, stageSchema } from "../settings/schema.js";
13
13
  import { createVirtualNamespace } from "./virtual-module.js";
14
14
 
15
- const VIRTUAL_PREFIX = "\0gtkx-settings:";
16
- const { isVirtual, fromVirtualId, resolveToVirtual } = createVirtualNamespace(VIRTUAL_PREFIX);
17
-
18
- const SCHEMA_ENV_BANNER = [
19
- `process.env.GSETTINGS_SCHEMA_DIR = [`,
20
- ` decodeURIComponent(new URL(".", import.meta.url).pathname),`,
21
- ` process.env.GSETTINGS_SCHEMA_DIR,`,
22
- `]`,
23
- ` .filter(Boolean)`,
24
- ` .join(":");`,
25
- ].join("\n");
26
-
27
15
  type PluginState = {
28
16
  schemaDir: string | null;
29
17
  rootDir: string | null;
@@ -39,54 +27,97 @@ type PluginContext = {
39
27
  emitFile: (file: { type: "asset"; fileName: string; source: Buffer }) => void;
40
28
  };
41
29
 
30
+ const VIRTUAL_PREFIX = "\0gtkx-settings:";
31
+ const { isVirtual, fromVirtualId, resolveToVirtual } = createVirtualNamespace(VIRTUAL_PREFIX);
32
+
33
+ const SCHEMA_ENV_BANNER = [
34
+ "process.env.GSETTINGS_SCHEMA_DIR = [",
35
+ " decodeURIComponent(new URL(\".\", import.meta.url).pathname),",
36
+ " process.env.GSETTINGS_SCHEMA_DIR,",
37
+ "]",
38
+ " .filter(Boolean)",
39
+ " .join(\":\");",
40
+ ].join("\n");
41
+
42
42
  const ensureSchemaDir = (state: PluginState): string => {
43
43
  if (!state.schemaDir) {
44
44
  const runnerDir = process.env.GTKX_DEV_SCHEMA_DIR;
45
+
45
46
  if (runnerDir) {
46
47
  state.schemaDir = runnerDir;
48
+
47
49
  return runnerDir;
48
50
  }
51
+
49
52
  const dir = mkdtempSync(join(tmpdir(), "gtkx-schemas-"));
50
53
  state.schemaDir = dir;
51
- const cleanup = (): void => removeTempDir(dir);
54
+
55
+ const cleanup = (): void => {
56
+ removeTempDir(dir);
57
+ };
58
+
52
59
  state.cleanupProcessExit = cleanup;
53
60
  process.once("exit", cleanup);
54
61
  }
62
+
55
63
  return state.schemaDir;
56
64
  };
57
65
 
58
66
  const releaseSchemaDir = (state: PluginState): void => {
59
- if (!state.schemaDir) return;
67
+ if (!state.schemaDir) {
68
+ return;
69
+ }
70
+
60
71
  if (state.cleanupProcessExit) {
61
72
  removeTempDir(state.schemaDir);
62
73
  process.removeListener("exit", state.cleanupProcessExit);
63
74
  state.cleanupProcessExit = null;
64
75
  }
76
+
65
77
  state.schemaDir = null;
66
78
  };
67
79
 
68
80
  const compileSchemaDir = (state: PluginState): void => {
69
- if (!state.schemaDir) return;
81
+ if (!state.schemaDir) {
82
+ return;
83
+ }
84
+
70
85
  compileSchemas(state.schemaDir);
71
86
  process.env.GSETTINGS_SCHEMA_DIR = prependSchemaDir(state.schemaDir, process.env.GSETTINGS_SCHEMA_DIR);
72
87
  };
73
88
 
74
89
  const syncSchemaEnv = (state: PluginState): void => {
75
- if (state.rootDir === null) return;
90
+ if (state.rootDir === null) {
91
+ return;
92
+ }
93
+
76
94
  try {
77
95
  emitSchemaEnv(state.rootDir, state.dataDir);
78
- } catch (cause) {
79
- error(`Failed to generate GSettings schema types: ${errorMessage(cause)}`);
96
+ } catch (error_) {
97
+ error(`Failed to generate GSettings schema types: ${errorMessage(error_)}`);
80
98
  }
81
99
  };
82
100
 
101
+ const applyUserConfig = (state: PluginState, config: UserConfig): void => {
102
+ state.dataDir = resolveDataDir(config.root ?? process.cwd());
103
+ };
104
+
105
+ const applyResolvedConfig = (state: PluginState, config: ResolvedConfig): void => {
106
+ state.isBuild = config.command === "build";
107
+ state.rootDir = typeof config.root === "string" ? config.root : null;
108
+ syncSchemaEnv(state);
109
+ };
110
+
83
111
  const registerSchemaForMode = (state: PluginState, filePath: string, id: string): void => {
84
112
  const fileName = basename(filePath);
113
+
85
114
  if (state.isBuild) {
86
115
  state.buildSchemas.add(filePath);
87
116
  info(`Queued GSettings schema: ${fileName}`);
117
+
88
118
  return;
89
119
  }
120
+
90
121
  state.trackedSchemas.set(filePath, id);
91
122
  const dir = ensureSchemaDir(state);
92
123
  stageSchema(dir, filePath);
@@ -94,74 +125,104 @@ const registerSchemaForMode = (state: PluginState, filePath: string, id: string)
94
125
  info(`Compiled GSettings schema: ${fileName}`);
95
126
  };
96
127
 
97
- const loadSchemaModule = (ctx: PluginContext, state: PluginState, id: string): string => {
128
+ const loadSchemaModule = (ctx: PluginContext, state: PluginState, id: string): string | undefined => {
129
+ if (!isVirtual(id)) {
130
+ return undefined;
131
+ }
132
+
98
133
  const filePath = fromVirtualId(id);
99
- const xml = readFileSync(filePath, "utf-8");
134
+ const xml = readFileSync(filePath, "utf8");
100
135
  const fileName = basename(filePath);
101
-
102
136
  registerSchemaForMode(state, filePath, id);
103
-
104
137
  let parsed: ReturnType<typeof parseSchemaXml>;
138
+
105
139
  try {
106
140
  parsed = parseSchemaXml(xml, fileName);
107
141
  } catch (error) {
108
- if (!(error instanceof SchemaParseError)) throw error;
142
+ if (!(error instanceof SchemaParseError)) {
143
+ throw error;
144
+ }
145
+
109
146
  ctx.error(error.message);
110
147
  }
148
+
111
149
  if (parsed.schemas.length === 0) {
112
150
  ctx.error(`No <schema id="..."> found in ${fileName}`);
113
151
  }
152
+
114
153
  return renderRuntimeModule(parsed);
115
154
  };
116
155
 
117
156
  const emitCompiledSchemas = (ctx: PluginContext, state: PluginState): void => {
118
- if (!state.isBuild || state.buildSchemas.size === 0) return;
157
+ if (!state.isBuild || state.buildSchemas.size === 0) {
158
+ return;
159
+ }
119
160
 
120
161
  const compiled = withStagingDir("schemas-build", (dir) => {
121
162
  for (const filePath of state.buildSchemas) {
122
163
  stageSchema(dir, filePath);
123
164
  }
165
+
124
166
  compileSchemas(dir);
167
+
125
168
  return readFileSync(join(dir, "gschemas.compiled"));
126
169
  });
170
+
127
171
  ctx.emitFile({
128
172
  type: "asset",
129
173
  fileName: "gschemas.compiled",
130
174
  source: compiled,
131
175
  });
132
176
 
133
- info(`Compiled ${state.buildSchemas.size} GSettings schema(s)`);
177
+ info(`Compiled ${String(state.buildSchemas.size)} GSettings schema(s)`);
134
178
  };
135
179
 
136
180
  const handleSchemaHotUpdate = (state: PluginState, file: string, server: ViteDevServer): ModuleNode[] | undefined => {
181
+ if (file.endsWith(SCHEMA_SUFFIX)) {
182
+ syncSchemaEnv(state);
183
+ }
184
+
137
185
  const virtualId = state.trackedSchemas.get(file);
138
- if (!virtualId) return;
186
+
187
+ if (!virtualId) {
188
+ return;
189
+ }
139
190
 
140
191
  const dir = ensureSchemaDir(state);
141
192
  stageSchema(dir, file);
142
193
  compileSchemaDir(state);
143
-
144
194
  info(`Recompiled GSettings schema: ${basename(file)}`);
145
-
146
195
  const mod = server.moduleGraph.getModuleById(virtualId);
196
+
147
197
  if (mod) {
148
198
  server.moduleGraph.invalidateModule(mod);
199
+
149
200
  return [mod];
150
201
  }
202
+
151
203
  return undefined;
152
204
  };
153
205
 
154
206
  const watchSchemaFiles = (state: PluginState, server: ViteDevServer): void => {
155
- server.httpServer?.once("close", () => releaseSchemaDir(state));
156
- server.watcher.once("close", () => releaseSchemaDir(state));
207
+ server.httpServer?.once("close", () => {
208
+ releaseSchemaDir(state);
209
+ });
210
+
211
+ server.watcher.once("close", () => {
212
+ releaseSchemaDir(state);
213
+ });
214
+
157
215
  const refreshSchemaTypes = (file: string): void => {
158
- if (file.endsWith(SCHEMA_SUFFIX)) syncSchemaEnv(state);
216
+ if (file.endsWith(SCHEMA_SUFFIX)) {
217
+ syncSchemaEnv(state);
218
+ }
159
219
  };
220
+
160
221
  server.watcher.on("add", refreshSchemaTypes);
161
222
  server.watcher.on("unlink", refreshSchemaTypes);
162
223
  };
163
224
 
164
- export function gtkxSettings(): Plugin {
225
+ function gtkxSettings(): Plugin {
165
226
  const state: PluginState = {
166
227
  schemaDir: null,
167
228
  rootDir: null,
@@ -177,13 +238,11 @@ export function gtkxSettings(): Plugin {
177
238
  enforce: "pre",
178
239
 
179
240
  config(config: UserConfig) {
180
- state.dataDir = resolveDataDir(config.root ?? process.cwd());
241
+ applyUserConfig(state, config);
181
242
  },
182
243
 
183
244
  configResolved(config) {
184
- state.isBuild = config.command === "build";
185
- state.rootDir = typeof config.root === "string" ? config.root : null;
186
- syncSchemaEnv(state);
245
+ applyResolvedConfig(state, config);
187
246
  },
188
247
 
189
248
  configureServer(server) {
@@ -191,17 +250,22 @@ export function gtkxSettings(): Plugin {
191
250
  },
192
251
 
193
252
  outputOptions(options) {
194
- if (!state.isBuild) return;
253
+ if (!state.isBuild) {
254
+ return;
255
+ }
256
+
195
257
  return prependBanner(options, SCHEMA_ENV_BANNER);
196
258
  },
197
259
 
198
260
  async resolveId(source, importer, options) {
199
- if (!source.endsWith(SCHEMA_SUFFIX)) return;
261
+ if (!source.endsWith(SCHEMA_SUFFIX)) {
262
+ return;
263
+ }
264
+
200
265
  return resolveToVirtual(this, { source, importer, options });
201
266
  },
202
267
 
203
268
  load(id) {
204
- if (!isVirtual(id)) return;
205
269
  return loadSchemaModule(this, state, id);
206
270
  },
207
271
 
@@ -214,8 +278,9 @@ export function gtkxSettings(): Plugin {
214
278
  },
215
279
 
216
280
  handleHotUpdate({ file, server }) {
217
- if (file.endsWith(SCHEMA_SUFFIX)) syncSchemaEnv(state);
218
281
  return handleSchemaHotUpdate(state, file, server);
219
282
  },
220
283
  };
221
284
  }
285
+
286
+ export { gtkxSettings };
@@ -0,0 +1,7 @@
1
+ const stripQuery = (source: string): string => {
2
+ const queryIndex = source.indexOf("?");
3
+
4
+ return queryIndex === -1 ? source : source.slice(0, queryIndex);
5
+ };
6
+
7
+ export { stripQuery };
@@ -1,8 +1,6 @@
1
+ import type { Plugin, UserConfig } from "vite";
1
2
  import { discoverGirNamespaces, resolveGirPath } from "@gtkx/codegen";
2
3
  import { loadConfig } from "@gtkx/config";
3
- import type { Plugin, UserConfig } from "vite";
4
-
5
- const GENERATED_MODULE_PATTERN = /^@gtkx\/(?:gi|jsx)\/([a-z0-9]+)$/;
6
4
 
7
5
  type PluginState = {
8
6
  root: string;
@@ -10,18 +8,21 @@ type PluginState = {
10
8
  girPath: string[] | null;
11
9
  };
12
10
 
11
+ const GENERATED_MODULE_PATTERN = /^@gtkx\/(?:gi|jsx)\/([a-z0-9]+)$/;
12
+
13
13
  const girSearchPaths = async (state: PluginState): Promise<string[]> => {
14
14
  if (state.girPath === null) {
15
15
  const { config } = await loadConfig(state.root, { mode: state.mode });
16
16
  state.girPath = resolveGirPath(config.girPath);
17
17
  }
18
+
18
19
  return state.girPath;
19
20
  };
20
21
 
21
- const namespaceOf = (identifier: string): string => identifier.slice(0, identifier.indexOf("-")).toLowerCase();
22
+ const getNamespace = (identifier: string): string => identifier.slice(0, identifier.indexOf("-")).toLowerCase();
22
23
 
23
24
  const findGirIdentifier = (girPath: string[], namespace: string): string | undefined =>
24
- discoverGirNamespaces(girPath).find((identifier) => namespaceOf(identifier) === namespace);
25
+ discoverGirNamespaces(girPath).find((identifier) => getNamespace(identifier) === namespace);
25
26
 
26
27
  const undeclaredLibraryError = (source: string, namespace: string, girPath: string[]): Error => {
27
28
  const identifier = findGirIdentifier(girPath, namespace);
@@ -29,19 +30,19 @@ const undeclaredLibraryError = (source: string, namespace: string, girPath: stri
29
30
  if (identifier === undefined) {
30
31
  return new Error(
31
32
  `Cannot resolve "${source}": the binding store has no "${namespace}" module, and no GIR data for it ` +
32
- `was found in [${girPath.join(", ")}]. If "${namespace}" is a library, install its ` +
33
- "gobject-introspection data package and add its GIR identifier to `libraries` in gtkx.config.ts. " +
34
- "Otherwise run gtkx codegen to regenerate the store.",
33
+ `was found in [${girPath.join(", ")}]. If "${namespace}" is a library, install its ` +
34
+ "gobject-introspection data package and add its GIR identifier to `libraries` in gtkx.config.ts. " +
35
+ "Otherwise run gtkx codegen to regenerate the store.",
35
36
  );
36
37
  }
37
38
 
38
39
  return new Error(
39
40
  `Cannot resolve "${source}": the "${identifier}" bindings have not been generated. ` +
40
- `Add "${identifier}" to \`libraries\` in gtkx.config.ts, then run gtkx dev or gtkx build again.`,
41
+ `Add "${identifier}" to \`libraries\` in gtkx.config.ts, then run gtkx dev or gtkx build again.`,
41
42
  );
42
43
  };
43
44
 
44
- export function gtkxUndeclaredLibrary(mode?: string): Plugin {
45
+ function gtkxUndeclaredLibrary(mode?: string): Plugin {
45
46
  const state: PluginState = {
46
47
  root: "",
47
48
  mode,
@@ -58,12 +59,20 @@ export function gtkxUndeclaredLibrary(mode?: string): Plugin {
58
59
 
59
60
  async resolveId(source, importer, options) {
60
61
  const namespace = GENERATED_MODULE_PATTERN.exec(source)?.[1];
61
- if (namespace === undefined) return;
62
+
63
+ if (namespace === undefined) {
64
+ return;
65
+ }
62
66
 
63
67
  const resolved = await this.resolve(source, importer, { ...options, skipSelf: true });
64
- if (resolved !== null) return;
68
+
69
+ if (resolved !== null) {
70
+ return;
71
+ }
65
72
 
66
73
  throw undeclaredLibraryError(source, namespace, await girSearchPaths(state));
67
74
  },
68
75
  };
69
76
  }
77
+
78
+ export { gtkxUndeclaredLibrary };
@@ -19,8 +19,9 @@ type VirtualNamespace = {
19
19
  resolveToVirtual: (ctx: VirtualResolveContext, request: VirtualResolveRequest) => Promise<string | undefined>;
20
20
  };
21
21
 
22
- export const createVirtualNamespace = (prefix: string): VirtualNamespace => {
22
+ const createVirtualNamespace = (prefix: string): VirtualNamespace => {
23
23
  const toVirtualId = (realId: string): string => prefix + realId;
24
+
24
25
  return {
25
26
  isVirtual: (id) => id.startsWith(prefix),
26
27
  toVirtualId,
@@ -30,8 +31,14 @@ export const createVirtualNamespace = (prefix: string): VirtualNamespace => {
30
31
  ...request.options,
31
32
  skipSelf: true,
32
33
  });
33
- if (!resolved || resolved.external) return undefined;
34
+
35
+ if (!resolved || resolved.external) {
36
+ return;
37
+ }
38
+
34
39
  return toVirtualId(resolved.id);
35
40
  },
36
41
  };
37
42
  };
43
+
44
+ export { createVirtualNamespace };
@@ -1,5 +1,5 @@
1
- import gtkxVitest from "@gtkx/vitest";
2
1
  import type { Plugin } from "vite";
2
+ import gtkxVitest from "@gtkx/vitest";
3
3
  import { gtkxVitePlugins } from "./vite-plugins/index.js";
4
4
  import { gtkxSettingsWorkerEnv } from "./vite-plugins/settings-worker-env.js";
5
5
 
@@ -10,5 +10,4 @@ import { gtkxSettingsWorkerEnv } from "./vite-plugins/settings-worker-env.js";
10
10
  * @returns The ordered array of Vite plugins to include in a Vitest configuration.
11
11
  */
12
12
  const gtkx = (): Plugin[] => [...gtkxVitePlugins(), gtkxSettingsWorkerEnv(), gtkxVitest()];
13
-
14
13
  export default gtkx;