@gtkx/cli 1.2.2 → 1.4.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.
Files changed (234) hide show
  1. package/README.md +6 -4
  2. package/dist/builder.d.ts +0 -1
  3. package/dist/builder.d.ts.map +1 -1
  4. package/dist/builder.js +6 -6
  5. package/dist/builder.js.map +1 -1
  6. package/dist/codegen/freshness.js +1 -1
  7. package/dist/codegen/freshness.js.map +1 -1
  8. package/dist/codegen/run-codegen.d.ts +2 -2
  9. package/dist/codegen/run-codegen.d.ts.map +1 -1
  10. package/dist/codegen/run-codegen.js +28 -9
  11. package/dist/codegen/run-codegen.js.map +1 -1
  12. package/dist/commands/build.d.ts +0 -4
  13. package/dist/commands/build.d.ts.map +1 -1
  14. package/dist/commands/build.js +0 -5
  15. package/dist/commands/build.js.map +1 -1
  16. package/dist/commands/codegen.d.ts.map +1 -1
  17. package/dist/commands/codegen.js +1 -3
  18. package/dist/commands/codegen.js.map +1 -1
  19. package/dist/commands/docs.d.ts.map +1 -1
  20. package/dist/commands/docs.js +3 -0
  21. package/dist/commands/docs.js.map +1 -1
  22. package/dist/deploy/depends.d.ts +2 -2
  23. package/dist/deploy/depends.d.ts.map +1 -1
  24. package/dist/deploy/depends.js +30 -15
  25. package/dist/deploy/depends.js.map +1 -1
  26. package/dist/deploy/nfpm/config.js +1 -1
  27. package/dist/deploy/nfpm/config.js.map +1 -1
  28. package/dist/deploy/node-runtime/elf.d.ts +1 -1
  29. package/dist/deploy/node-runtime/elf.d.ts.map +1 -1
  30. package/dist/deploy/node-runtime/elf.js +2 -2
  31. package/dist/deploy/node-runtime/elf.js.map +1 -1
  32. package/dist/deploy/node-runtime/index.js +2 -2
  33. package/dist/deploy/node-runtime/index.js.map +1 -1
  34. package/dist/deploy/notices/collect.d.ts +3 -1
  35. package/dist/deploy/notices/collect.d.ts.map +1 -1
  36. package/dist/deploy/notices/collect.js +2 -2
  37. package/dist/deploy/notices/collect.js.map +1 -1
  38. package/dist/deploy/notices/packages.d.ts +2 -1
  39. package/dist/deploy/notices/packages.d.ts.map +1 -1
  40. package/dist/deploy/notices/packages.js +4 -27
  41. package/dist/deploy/notices/packages.js.map +1 -1
  42. package/dist/deploy/payload/icons.d.ts +7 -3
  43. package/dist/deploy/payload/icons.d.ts.map +1 -1
  44. package/dist/deploy/payload/icons.js +46 -28
  45. package/dist/deploy/payload/icons.js.map +1 -1
  46. package/dist/deploy/payload/stage.d.ts.map +1 -1
  47. package/dist/deploy/payload/stage.js +3 -2
  48. package/dist/deploy/payload/stage.js.map +1 -1
  49. package/dist/deploy/run-deploy.d.ts.map +1 -1
  50. package/dist/deploy/run-deploy.js +63 -11
  51. package/dist/deploy/run-deploy.js.map +1 -1
  52. package/dist/deploy/settings/build-manifest.d.ts +9 -0
  53. package/dist/deploy/settings/build-manifest.d.ts.map +1 -0
  54. package/dist/deploy/settings/build-manifest.js +80 -0
  55. package/dist/deploy/settings/build-manifest.js.map +1 -0
  56. package/dist/deploy/settings/index.d.ts.map +1 -1
  57. package/dist/deploy/settings/index.js +9 -3
  58. package/dist/deploy/settings/index.js.map +1 -1
  59. package/dist/deploy/settings/libraries.d.ts +8 -0
  60. package/dist/deploy/settings/libraries.d.ts.map +1 -0
  61. package/dist/deploy/settings/libraries.js +39 -0
  62. package/dist/deploy/settings/libraries.js.map +1 -0
  63. package/dist/deploy/settings/paths.d.ts +3 -0
  64. package/dist/deploy/settings/paths.d.ts.map +1 -1
  65. package/dist/deploy/settings/paths.js +6 -32
  66. package/dist/deploy/settings/paths.js.map +1 -1
  67. package/dist/deploy/targets/appimage.d.ts.map +1 -1
  68. package/dist/deploy/targets/appimage.js +19 -13
  69. package/dist/deploy/targets/appimage.js.map +1 -1
  70. package/dist/deploy/targets/flatpak-manifest.d.ts +2 -1
  71. package/dist/deploy/targets/flatpak-manifest.d.ts.map +1 -1
  72. package/dist/deploy/targets/flatpak-manifest.js +5 -1
  73. package/dist/deploy/targets/flatpak-manifest.js.map +1 -1
  74. package/dist/deploy/targets/flatpak-pnpm.js +4 -4
  75. package/dist/deploy/targets/flatpak-pnpm.js.map +1 -1
  76. package/dist/deploy/targets/flatpak-source.d.ts.map +1 -1
  77. package/dist/deploy/targets/flatpak-source.js +9 -6
  78. package/dist/deploy/targets/flatpak-source.js.map +1 -1
  79. package/dist/deploy/types.d.ts +4 -4
  80. package/dist/deploy/types.d.ts.map +1 -1
  81. package/dist/deploy/types.js.map +1 -1
  82. package/dist/dev/icon-dir.d.ts +1 -1
  83. package/dist/dev/icon-dir.d.ts.map +1 -1
  84. package/dist/dev/icon-dir.js +20 -7
  85. package/dist/dev/icon-dir.js.map +1 -1
  86. package/dist/dev/runner-deps.d.ts.map +1 -1
  87. package/dist/dev/runner-deps.js +5 -1
  88. package/dist/dev/runner-deps.js.map +1 -1
  89. package/dist/dev/runner-main.js +4 -4
  90. package/dist/dev/runner-main.js.map +1 -1
  91. package/dist/dev/runner.d.ts +1 -1
  92. package/dist/dev/runner.d.ts.map +1 -1
  93. package/dist/dev/runner.js +1 -1
  94. package/dist/dev/runner.js.map +1 -1
  95. package/dist/dev/schema-dir.d.ts +1 -1
  96. package/dist/dev/schema-dir.d.ts.map +1 -1
  97. package/dist/dev/schema-dir.js +3 -1
  98. package/dist/dev/schema-dir.js.map +1 -1
  99. package/dist/internal/build-manifest.d.ts +20 -0
  100. package/dist/internal/build-manifest.d.ts.map +1 -0
  101. package/dist/internal/build-manifest.js +6 -0
  102. package/dist/internal/build-manifest.js.map +1 -0
  103. package/dist/internal/icon-path.d.ts +13 -0
  104. package/dist/internal/icon-path.d.ts.map +1 -0
  105. package/dist/internal/icon-path.js +86 -0
  106. package/dist/internal/icon-path.js.map +1 -0
  107. package/dist/internal/source-imports.d.ts +8 -0
  108. package/dist/internal/source-imports.d.ts.map +1 -0
  109. package/dist/internal/source-imports.js +144 -0
  110. package/dist/internal/source-imports.js.map +1 -0
  111. package/dist/mcp/widget-properties.d.ts.map +1 -1
  112. package/dist/mcp/widget-properties.js +3 -12
  113. package/dist/mcp/widget-properties.js.map +1 -1
  114. package/dist/settings/render.d.ts +7 -1
  115. package/dist/settings/render.d.ts.map +1 -1
  116. package/dist/settings/render.js +69 -20
  117. package/dist/settings/render.js.map +1 -1
  118. package/dist/settings/schema.d.ts +4 -3
  119. package/dist/settings/schema.d.ts.map +1 -1
  120. package/dist/settings/schema.js +122 -15
  121. package/dist/settings/schema.js.map +1 -1
  122. package/dist/vite-plugins/asset-emitter.d.ts +1 -1
  123. package/dist/vite-plugins/asset-emitter.d.ts.map +1 -1
  124. package/dist/vite-plugins/asset-emitter.js.map +1 -1
  125. package/dist/vite-plugins/asset-extensions.d.ts.map +1 -1
  126. package/dist/vite-plugins/asset-extensions.js +1 -0
  127. package/dist/vite-plugins/asset-extensions.js.map +1 -1
  128. package/dist/vite-plugins/asset-imports.d.ts +2 -1
  129. package/dist/vite-plugins/asset-imports.d.ts.map +1 -1
  130. package/dist/vite-plugins/asset-imports.js +37 -16
  131. package/dist/vite-plugins/asset-imports.js.map +1 -1
  132. package/dist/vite-plugins/asset-specifier.d.ts +13 -1
  133. package/dist/vite-plugins/asset-specifier.d.ts.map +1 -1
  134. package/dist/vite-plugins/asset-specifier.js +39 -1
  135. package/dist/vite-plugins/asset-specifier.js.map +1 -1
  136. package/dist/vite-plugins/build-manifest.d.ts +5 -0
  137. package/dist/vite-plugins/build-manifest.d.ts.map +1 -0
  138. package/dist/vite-plugins/{bundled-packages.js → build-manifest.js} +20 -14
  139. package/dist/vite-plugins/build-manifest.js.map +1 -0
  140. package/dist/vite-plugins/built-url.d.ts +1 -1
  141. package/dist/vite-plugins/built-url.d.ts.map +1 -1
  142. package/dist/vite-plugins/built-url.js +37 -24
  143. package/dist/vite-plugins/built-url.js.map +1 -1
  144. package/dist/vite-plugins/icons.d.ts +2 -1
  145. package/dist/vite-plugins/icons.d.ts.map +1 -1
  146. package/dist/vite-plugins/icons.js +25 -12
  147. package/dist/vite-plugins/icons.js.map +1 -1
  148. package/dist/vite-plugins/index.d.ts +2 -1
  149. package/dist/vite-plugins/index.d.ts.map +1 -1
  150. package/dist/vite-plugins/index.js +7 -5
  151. package/dist/vite-plugins/index.js.map +1 -1
  152. package/dist/vite-plugins/native.d.ts.map +1 -1
  153. package/dist/vite-plugins/native.js +23 -4
  154. package/dist/vite-plugins/native.js.map +1 -1
  155. package/dist/vite-plugins/resource-init-module.d.ts +7 -3
  156. package/dist/vite-plugins/resource-init-module.d.ts.map +1 -1
  157. package/dist/vite-plugins/resource-init-module.js +39 -14
  158. package/dist/vite-plugins/resource-init-module.js.map +1 -1
  159. package/dist/vite-plugins/resource-shared.d.ts +3 -1
  160. package/dist/vite-plugins/resource-shared.d.ts.map +1 -1
  161. package/dist/vite-plugins/resource-shared.js +3 -1
  162. package/dist/vite-plugins/resource-shared.js.map +1 -1
  163. package/dist/vite-plugins/resources.d.ts +1 -1
  164. package/dist/vite-plugins/resources.d.ts.map +1 -1
  165. package/dist/vite-plugins/resources.js +922 -86
  166. package/dist/vite-plugins/resources.js.map +1 -1
  167. package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -1
  168. package/dist/vite-plugins/settings-worker-env.js +6 -3
  169. package/dist/vite-plugins/settings-worker-env.js.map +1 -1
  170. package/dist/vite-plugins/settings.d.ts +3 -1
  171. package/dist/vite-plugins/settings.d.ts.map +1 -1
  172. package/dist/vite-plugins/settings.js +63 -23
  173. package/dist/vite-plugins/settings.js.map +1 -1
  174. package/dist/vite-plugins/store-links.js +1 -1
  175. package/dist/vite-plugins/store-links.js.map +1 -1
  176. package/dist/vite-plugins/undeclared-library.d.ts.map +1 -1
  177. package/dist/vite-plugins/undeclared-library.js +25 -13
  178. package/dist/vite-plugins/undeclared-library.js.map +1 -1
  179. package/env.d.ts +11 -192
  180. package/package.json +14 -14
  181. package/src/builder.ts +6 -7
  182. package/src/codegen/freshness.ts +1 -1
  183. package/src/codegen/run-codegen.ts +33 -10
  184. package/src/commands/build.ts +0 -5
  185. package/src/commands/codegen.ts +1 -3
  186. package/src/commands/docs.ts +3 -0
  187. package/src/deploy/depends.ts +47 -18
  188. package/src/deploy/nfpm/config.ts +1 -1
  189. package/src/deploy/node-runtime/elf.ts +3 -3
  190. package/src/deploy/node-runtime/index.ts +2 -2
  191. package/src/deploy/notices/collect.ts +4 -2
  192. package/src/deploy/notices/packages.ts +5 -43
  193. package/src/deploy/payload/icons.ts +64 -34
  194. package/src/deploy/payload/stage.ts +5 -2
  195. package/src/deploy/run-deploy.ts +87 -12
  196. package/src/deploy/settings/build-manifest.ts +122 -0
  197. package/src/deploy/settings/index.ts +9 -4
  198. package/src/deploy/settings/libraries.ts +57 -0
  199. package/src/deploy/settings/paths.ts +10 -47
  200. package/src/deploy/targets/appimage.ts +32 -15
  201. package/src/deploy/targets/flatpak-manifest.ts +7 -1
  202. package/src/deploy/targets/flatpak-pnpm.ts +4 -4
  203. package/src/deploy/targets/flatpak-source.ts +9 -10
  204. package/src/deploy/types.ts +4 -4
  205. package/src/dev/icon-dir.ts +31 -7
  206. package/src/dev/runner-deps.ts +5 -1
  207. package/src/dev/runner-main.ts +4 -4
  208. package/src/dev/runner.ts +2 -2
  209. package/src/dev/schema-dir.ts +3 -1
  210. package/src/internal/build-manifest.ts +32 -0
  211. package/src/internal/icon-path.ts +127 -0
  212. package/src/internal/source-imports.ts +200 -0
  213. package/src/mcp/widget-properties.ts +3 -14
  214. package/src/settings/render.ts +99 -21
  215. package/src/settings/schema.ts +190 -17
  216. package/src/vite-plugins/asset-emitter.ts +1 -1
  217. package/src/vite-plugins/asset-extensions.ts +1 -0
  218. package/src/vite-plugins/asset-imports.ts +60 -19
  219. package/src/vite-plugins/asset-specifier.ts +73 -1
  220. package/src/vite-plugins/{bundled-packages.ts → build-manifest.ts} +30 -19
  221. package/src/vite-plugins/built-url.ts +49 -28
  222. package/src/vite-plugins/icons.ts +33 -14
  223. package/src/vite-plugins/index.ts +12 -5
  224. package/src/vite-plugins/native.ts +31 -4
  225. package/src/vite-plugins/resource-init-module.ts +44 -15
  226. package/src/vite-plugins/resource-shared.ts +4 -0
  227. package/src/vite-plugins/resources.ts +1459 -100
  228. package/src/vite-plugins/settings-worker-env.ts +7 -3
  229. package/src/vite-plugins/settings.ts +89 -21
  230. package/src/vite-plugins/store-links.ts +1 -1
  231. package/src/vite-plugins/undeclared-library.ts +31 -13
  232. package/dist/vite-plugins/bundled-packages.d.ts +0 -5
  233. package/dist/vite-plugins/bundled-packages.d.ts.map +0 -1
  234. package/dist/vite-plugins/bundled-packages.js.map +0 -1
@@ -0,0 +1,144 @@
1
+ import { isRecord, sortStringsBy } from "@gtkx/utils";
2
+ import { readdirSync, readFileSync } from "node:fs";
3
+ import { extname, join } from "node:path";
4
+ import { parseSync } from "vite";
5
+ const SOURCE_LANGUAGES = new Map([
6
+ [".cjs", "jsx"],
7
+ [".cts", "ts"],
8
+ [".js", "jsx"],
9
+ [".jsx", "jsx"],
10
+ [".mjs", "jsx"],
11
+ [".mts", "ts"],
12
+ [".ts", "ts"],
13
+ [".tsx", "tsx"],
14
+ ]);
15
+ const EXCLUDED_DIRECTORIES = new Set([
16
+ ".git",
17
+ ".gtkx",
18
+ "build",
19
+ "coverage",
20
+ "dist",
21
+ "node_modules",
22
+ "out-tsc",
23
+ ]);
24
+ const sourceLanguage = (path) => {
25
+ if (path.endsWith(".d.ts") || path.endsWith(".d.cts") || path.endsWith(".d.mts")) {
26
+ return undefined;
27
+ }
28
+ return SOURCE_LANGUAGES.get(extname(path).toLowerCase());
29
+ };
30
+ const collectSourceEntry = (dir, entry, found) => {
31
+ const path = join(dir, entry.name);
32
+ if (entry.isDirectory()) {
33
+ if (!EXCLUDED_DIRECTORIES.has(entry.name)) {
34
+ sourceFilesIn(path, found);
35
+ }
36
+ return;
37
+ }
38
+ if (entry.isFile() && sourceLanguage(path) !== undefined) {
39
+ found.push(path);
40
+ }
41
+ };
42
+ const sourceFilesIn = (dir, found) => {
43
+ let entries;
44
+ try {
45
+ entries = readdirSync(dir, { withFileTypes: true });
46
+ }
47
+ catch {
48
+ return;
49
+ }
50
+ for (const entry of entries) {
51
+ collectSourceEntry(dir, entry, found);
52
+ }
53
+ };
54
+ const staticImportSources = (module) => [
55
+ ...module.staticImports.map((statement) => statement.moduleRequest.value),
56
+ ...module.staticExports.flatMap((statement) => statement.entries
57
+ .map((entry) => entry.moduleRequest?.value)
58
+ .filter((source) => source !== undefined)),
59
+ ];
60
+ const staticRuntimeImportSources = (module) => [
61
+ ...module.staticImports
62
+ .filter((statement) => statement.entries.length === 0 || statement.entries.some((entry) => !entry.isType))
63
+ .map((statement) => statement.moduleRequest.value),
64
+ ...module.staticExports.flatMap((statement) => statement.entries
65
+ .filter((entry) => !entry.isType)
66
+ .map((entry) => entry.moduleRequest?.value)
67
+ .filter((source) => source !== undefined)),
68
+ ];
69
+ const templateImportSource = (node) => {
70
+ if (!Array.isArray(node.expressions) || node.expressions.length > 0 || !Array.isArray(node.quasis)) {
71
+ return null;
72
+ }
73
+ const quasis = node.quasis;
74
+ const first = quasis[0];
75
+ if (!isRecord(first) || !isRecord(first.value)) {
76
+ return null;
77
+ }
78
+ return typeof first.value.cooked === "string" ? first.value.cooked : null;
79
+ };
80
+ const literalImportSource = (node) => {
81
+ if (!isRecord(node)) {
82
+ return null;
83
+ }
84
+ if (node.type === "Literal") {
85
+ return typeof node.value === "string" ? node.value : null;
86
+ }
87
+ return node.type === "TemplateLiteral" ? templateImportSource(node) : null;
88
+ };
89
+ const collectDynamicImportArray = (nodes, found) => {
90
+ for (const child of nodes) {
91
+ collectDynamicImportSources(child, found);
92
+ }
93
+ };
94
+ const collectDynamicImportRecord = (node, found) => {
95
+ if (node.type === "ImportExpression") {
96
+ const source = literalImportSource(node.source);
97
+ if (source !== null) {
98
+ found.push(source);
99
+ }
100
+ return;
101
+ }
102
+ collectDynamicImportArray(Object.values(node), found);
103
+ };
104
+ const collectDynamicImportSources = (node, found) => {
105
+ if (Array.isArray(node)) {
106
+ collectDynamicImportArray(node, found);
107
+ return;
108
+ }
109
+ if (!isRecord(node)) {
110
+ return;
111
+ }
112
+ collectDynamicImportRecord(node, found);
113
+ };
114
+ const parseImportsInWith = (path, staticSources) => {
115
+ const lang = sourceLanguage(path);
116
+ if (lang === undefined) {
117
+ return [];
118
+ }
119
+ let parsed;
120
+ try {
121
+ parsed = parseSync(path, readFileSync(path, "utf8"), { lang });
122
+ }
123
+ catch {
124
+ return null;
125
+ }
126
+ if (parsed.errors.length > 0) {
127
+ return null;
128
+ }
129
+ const sources = staticSources(parsed.module);
130
+ collectDynamicImportSources(parsed.program, sources);
131
+ return [...new Set(sources)].map((source) => ({ importer: path, source }));
132
+ };
133
+ const parseImportsIn = (path) => parseImportsInWith(path, staticImportSources);
134
+ const parseRuntimeImportsIn = (path) => parseImportsInWith(path, staticRuntimeImportSources);
135
+ const importsIn = (path) => parseImportsIn(path) ?? [];
136
+ const importKey = (entry) => `${entry.importer}\0${entry.source}`;
137
+ const discoverSourceImports = (dir) => {
138
+ const files = [];
139
+ sourceFilesIn(dir, files);
140
+ const imports = files.flatMap((path) => importsIn(path));
141
+ return sortStringsBy(imports, importKey);
142
+ };
143
+ export { discoverSourceImports, parseRuntimeImportsIn };
144
+ //# sourceMappingURL=source-imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-imports.js","sourceRoot":"","sources":["../../src/internal/source-imports.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAe,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAUjC,MAAM,gBAAgB,GAAgC,IAAI,GAAG,CAAC;IAC1D,CAAC,MAAM,EAAE,KAAK,CAAC;IACf,CAAC,MAAM,EAAE,IAAI,CAAC;IACd,CAAC,KAAK,EAAE,KAAK,CAA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AAC,GAAW,EAAkB,EAAE;IAC1D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAEzD,OAAO,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAqB,CAAC","sourcesContent":["import type { ParseResult, ParserOptions } from \"vite\";\nimport { isRecord, sortStringsBy } from \"@gtkx/utils\";\nimport { type Dirent, readdirSync, readFileSync } from \"node:fs\";\nimport { extname, join } from \"node:path\";\nimport { parseSync } from \"vite\";\n\ntype SourceImport = {\n importer: string;\n source: string;\n};\n\ntype SourceLanguage = NonNullable<ParserOptions[\"lang\"]>;\ntype ParsedModule = ParseResult[\"module\"];\n\nconst SOURCE_LANGUAGES: Map<string, SourceLanguage> = new Map([\n [\".cjs\", \"jsx\"],\n [\".cts\", \"ts\"],\n [\".js\", \"jsx\"],\n [\".jsx\", \"jsx\"],\n [\".mjs\", \"jsx\"],\n [\".mts\", \"ts\"],\n [\".ts\", \"ts\"],\n [\".tsx\", \"tsx\"],\n]);\n\nconst EXCLUDED_DIRECTORIES: Set<string> = new Set([\n \".git\",\n \".gtkx\",\n \"build\",\n \"coverage\",\n \"dist\",\n \"node_modules\",\n \"out-tsc\",\n]);\n\nconst sourceLanguage = (path: string): SourceLanguage | undefined => {\n if (path.endsWith(\".d.ts\") || path.endsWith(\".d.cts\") || path.endsWith(\".d.mts\")) {\n return undefined;\n }\n\n return SOURCE_LANGUAGES.get(extname(path).toLowerCase());\n};\n\nconst collectSourceEntry = (dir: string, entry: Dirent, found: string[]): void => {\n const path = join(dir, entry.name);\n\n if (entry.isDirectory()) {\n if (!EXCLUDED_DIRECTORIES.has(entry.name)) {\n sourceFilesIn(path, found);\n }\n\n return;\n }\n\n if (entry.isFile() && sourceLanguage(path) !== undefined) {\n found.push(path);\n }\n};\n\nconst sourceFilesIn = (dir: string, found: string[]): void => {\n let entries: Dirent[];\n\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n collectSourceEntry(dir, entry, found);\n }\n};\n\nconst staticImportSources = (module: ParsedModule): string[] => [\n ...module.staticImports.map((statement) => statement.moduleRequest.value),\n ...module.staticExports.flatMap((statement) =>\n statement.entries\n .map((entry) => entry.moduleRequest?.value)\n .filter((source): source is string => source !== undefined),\n ),\n];\n\nconst staticRuntimeImportSources = (module: ParsedModule): string[] => [\n ...module.staticImports\n .filter((statement) => statement.entries.length === 0 || statement.entries.some((entry) => !entry.isType))\n .map((statement) => statement.moduleRequest.value),\n ...module.staticExports.flatMap((statement) =>\n statement.entries\n .filter((entry) => !entry.isType)\n .map((entry) => entry.moduleRequest?.value)\n .filter((source): source is string => source !== undefined),\n ),\n];\n\nconst templateImportSource = (node: Record<string, unknown>): string | null => {\n if (!Array.isArray(node.expressions) || node.expressions.length > 0 || !Array.isArray(node.quasis)) {\n return null;\n }\n\n const quasis: unknown[] = node.quasis;\n const first: unknown = quasis[0];\n\n if (!isRecord(first) || !isRecord(first.value)) {\n return null;\n }\n\n return typeof first.value.cooked === \"string\" ? first.value.cooked : null;\n};\n\nconst literalImportSource = (node: unknown): string | null => {\n if (!isRecord(node)) {\n return null;\n }\n\n if (node.type === \"Literal\") {\n return typeof node.value === \"string\" ? node.value : null;\n }\n\n return node.type === \"TemplateLiteral\" ? templateImportSource(node) : null;\n};\n\nconst collectDynamicImportArray = (nodes: unknown[], found: string[]): void => {\n for (const child of nodes) {\n collectDynamicImportSources(child, found);\n }\n};\n\nconst collectDynamicImportRecord = (node: Record<string, unknown>, found: string[]): void => {\n if (node.type === \"ImportExpression\") {\n const source = literalImportSource(node.source);\n\n if (source !== null) {\n found.push(source);\n }\n\n return;\n }\n\n collectDynamicImportArray(Object.values(node), found);\n};\n\nconst collectDynamicImportSources = (node: unknown, found: string[]): void => {\n if (Array.isArray(node)) {\n collectDynamicImportArray(node, found);\n\n return;\n }\n\n if (!isRecord(node)) {\n return;\n }\n\n collectDynamicImportRecord(node, found);\n};\n\nconst parseImportsInWith = (\n path: string,\n staticSources: (module: ParsedModule) => string[],\n): SourceImport[] | null => {\n const lang = sourceLanguage(path);\n\n if (lang === undefined) {\n return [];\n }\n\n let parsed: ParseResult;\n\n try {\n parsed = parseSync(path, readFileSync(path, \"utf8\"), { lang });\n } catch {\n return null;\n }\n\n if (parsed.errors.length > 0) {\n return null;\n }\n\n const sources = staticSources(parsed.module);\n collectDynamicImportSources(parsed.program, sources);\n\n return [...new Set(sources)].map((source) => ({ importer: path, source }));\n};\n\nconst parseImportsIn = (path: string): SourceImport[] | null => parseImportsInWith(path, staticImportSources);\n\nconst parseRuntimeImportsIn = (path: string): SourceImport[] | null =>\n parseImportsInWith(path, staticRuntimeImportSources);\n\nconst importsIn = (path: string): SourceImport[] => parseImportsIn(path) ?? [];\nconst importKey = (entry: SourceImport): string => `${entry.importer}\\0${entry.source}`;\n\nconst discoverSourceImports = (dir: string): SourceImport[] => {\n const files: string[] = [];\n sourceFilesIn(dir, files);\n const imports = files.flatMap((path) => importsIn(path));\n\n return sortStringsBy(imports, importKey);\n};\n\nexport { discoverSourceImports, parseRuntimeImportsIn, type SourceImport };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"widget-properties.d.ts","sourceRoot":"","sources":["../../src/mcp/widget-properties.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAyB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAapF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAyH3D,iBAAS,oBAAoB,CACzB,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,EAAE,cAAc,GACzB,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAUpC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"widget-properties.d.ts","sourceRoot":"","sources":["../../src/mcp/widget-properties.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAyB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAcpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA6G3D,iBAAS,oBAAoB,CACzB,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,EAAE,cAAc,GACzB,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAUpC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import * as GObject from "@gtkx/gi/gobject";
2
2
  import * as Gtk from "@gtkx/gi/gtk";
3
3
  import { propertyNotFoundError } from "@gtkx/mcp/internal";
4
- import { getHandle, getInstanceType, TYPE_ENUM, TYPE_FLAGS, typeIsA, typeName, } from "@gtkx/runtime";
4
+ import { getHandle, getInstanceType, isReadableProperty, TYPE_ENUM, TYPE_FLAGS, typeIsA, typeName, } from "@gtkx/runtime";
5
5
  import { fromValue, getValueType } from "@gtkx/runtime/internal";
6
- import { camelCase, errorMessage, kebabCase } from "@gtkx/utils";
6
+ import { errorMessage, kebabCase } from "@gtkx/utils";
7
7
  const SCALAR_TYPES = new Set(["string", "number", "boolean"]);
8
8
  const canonicalName = (name) => kebabCase(name).replaceAll("_", "-");
9
9
  const widgetTypeName = (widget) => typeName(getInstanceType(widget)) ?? widget.constructor.name;
@@ -18,15 +18,6 @@ function prototypesFor(widget) {
18
18
  }
19
19
  return prototypes;
20
20
  }
21
- function getAccessor(widget, member) {
22
- for (const prototype of prototypesFor(widget)) {
23
- const descriptor = Object.getOwnPropertyDescriptor(prototype, member);
24
- if (descriptor !== undefined) {
25
- return descriptor;
26
- }
27
- }
28
- return undefined;
29
- }
30
21
  function getReadableNames(prototype) {
31
22
  const descriptors = Object.entries(Object.getOwnPropertyDescriptors(prototype));
32
23
  return descriptors.filter(([, descriptor]) => descriptor.get !== undefined).map(([member]) => kebabCase(member));
@@ -36,7 +27,7 @@ function readablePropertyNames(widget) {
36
27
  return [...new Set(names)].toSorted(byName);
37
28
  }
38
29
  const requireReadableProperty = (widget, property) => {
39
- if (getAccessor(widget, camelCase(property))?.get !== undefined) {
30
+ if (isReadableProperty(getInstanceType(widget), property)) {
40
31
  return;
41
32
  }
42
33
  throw propertyNotFoundError(widgetTypeName(widget), property, readablePropertyNames(widget));
@@ -1 +1 @@
1
- {"version":3,"file":"widget-properties.js","sourceRoot":"","sources":["../../src/mcp/widget-properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAA2B,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAEH,SAAS,EACT,eAAe,EAEf,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMjE,MAAM,YAAY,GAAgB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3E,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrF,MAAM,cAAc,GAAG,CAAC,MAAkB,EAAU,EAAE,CAAC,QAAQ,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BAAoB,EAAE,CAAC","sourcesContent":["import * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { propertyNotFoundError, type SerializedProperty } from \"@gtkx/mcp/internal\";\nimport {\n type ExternalObject,\n getHandle,\n getInstanceType,\n type Handle,\n TYPE_ENUM,\n TYPE_FLAGS,\n typeIsA,\n typeName,\n} from \"@gtkx/runtime\";\nimport { fromValue, getValueType } from \"@gtkx/runtime/internal\";\nimport { camelCase, errorMessage, kebabCase } from \"@gtkx/utils\";\nimport type { WidgetRegistry } from \"./widget-registry.js\";\n\ntype PropertyRepresentation = Omit<SerializedProperty, \"type\">;\ntype NativeProperty = { type: bigint; handle: ExternalObject<Handle> };\n\nconst SCALAR_TYPES: Set<string> = new Set([\"string\", \"number\", \"boolean\"]);\n\nconst canonicalName = (name: string): string => kebabCase(name).replaceAll(\"_\", \"-\");\nconst widgetTypeName = (widget: Gtk.Widget): string => typeName(getInstanceType(widget)) ?? widget.constructor.name;\nconst byName = (left: string, right: string): number => left.localeCompare(right);\n\nconst isScalar = (value: unknown): value is string | number | boolean | null =>\n value === null || SCALAR_TYPES.has(typeof value);\n\nfunction prototypesFor(widget: Gtk.Widget): object[] {\n const prototypes: object[] = [];\n let prototype = Object.getPrototypeOf(widget) as object | null;\n\n while (prototype !== null && prototype !== Object.prototype) {\n prototypes.push(prototype);\n prototype = Object.getPrototypeOf(prototype) as object | null;\n }\n\n return prototypes;\n}\n\nfunction getAccessor(widget: Gtk.Widget, member: string): PropertyDescriptor | undefined {\n for (const prototype of prototypesFor(widget)) {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, member);\n\n if (descriptor !== undefined) {\n return descriptor;\n }\n }\n\n return undefined;\n}\n\nfunction getReadableNames(prototype: object): string[] {\n const descriptors = Object.entries(Object.getOwnPropertyDescriptors(prototype));\n\n return descriptors.filter(([, descriptor]) => descriptor.get !== undefined).map(([member]) => kebabCase(member));\n}\n\nfunction readablePropertyNames(widget: Gtk.Widget): string[] {\n const names = prototypesFor(widget).flatMap((prototype) => getReadableNames(prototype));\n\n return [...new Set(names)].toSorted(byName);\n}\n\nconst requireReadableProperty = (widget: Gtk.Widget, property: string): void => {\n if (getAccessor(widget, camelCase(property))?.get !== undefined) {\n return;\n }\n\n throw propertyNotFoundError(widgetTypeName(widget), property, readablePropertyNames(widget));\n};\n\nfunction readNativeProperty(widget: Gtk.Widget, property: string): NativeProperty {\n const value = new GObject.Value();\n widget.getProperty(property, value);\n const handle = getHandle(value);\n\n return { type: getValueType(handle), handle };\n}\n\nfunction describeObjectValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (typeof value !== \"object\" || value === null) {\n return { value: String(value) };\n }\n\n const name = typeName(getInstanceType(value)) ?? value.constructor.name;\n\n if (!(value instanceof Gtk.Widget)) {\n return { value: name };\n }\n\n registry.register(value);\n\n return { value: name, widgetId: registry.getOrCreateId(value) };\n}\n\nfunction representValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (isScalar(value)) {\n return { value };\n }\n\n if (typeof value === \"bigint\") {\n return { value: value.toString() };\n }\n\n if (Array.isArray(value)) {\n return { value: value.map(String) };\n }\n\n return describeObjectValue(value, registry);\n}\n\nfunction representNativeProperty(native: NativeProperty, registry: WidgetRegistry): PropertyRepresentation {\n if (typeIsA(native.type, TYPE_ENUM)) {\n return { value: GObject.enumToString(native.type, Number(fromValue(native.handle))) };\n }\n\n if (typeIsA(native.type, TYPE_FLAGS)) {\n return { value: GObject.flagsToString(native.type, Number(fromValue(native.handle))) };\n }\n\n return representValue(fromValue(native.handle), registry);\n}\n\nfunction serializeProperty(widget: Gtk.Widget, property: string, registry: WidgetRegistry): SerializedProperty {\n const native = readNativeProperty(widget, property);\n const type = typeName(native.type) ?? String(native.type);\n\n try {\n return { type, ...representNativeProperty(native, registry) };\n } catch (error) {\n return { type, value: null, note: `cannot be represented over MCP: ${errorMessage(error)}` };\n }\n}\n\nfunction readWidgetProperties(\n widget: Gtk.Widget,\n properties: string[],\n registry: WidgetRegistry,\n): Record<string, SerializedProperty> {\n const values: Record<string, SerializedProperty> = {};\n\n for (const name of properties) {\n const property = canonicalName(name);\n requireReadableProperty(widget, property);\n values[property] = serializeProperty(widget, property, registry);\n }\n\n return values;\n}\n\nexport { readWidgetProperties };\n"]}
1
+ {"version":3,"file":"widget-properties.js","sourceRoot":"","sources":["../../src/mcp/widget-properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAA2B,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAEH,SAAS,EACT,eAAe,EAEf,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMtD,MAAM,YAAY,GAAgB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3E,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrF,MAAM,cAAc,GAAG,CAAC,MAAkB,EAAU,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;AACpH,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAElF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA6C,EAAE,CAC3E,KAAK,KAAK,IAAI,IAAI,YAAY,CAAC,GAAG,CAAC,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AC;IAClE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,mCAAmC,YAAY,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;IACjG,CAAC;AACL,CAAC;AAED,SAAS,oBAAoB,CACzB,MAAkB,EAClB,UAAoB,EACpB,QAAwB;IAExB,MAAM,MAAM,GAAuC,EAAE,CAAC;IAEtD,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QACrC,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC1C,MAAM,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { propertyNotFoundError, type SerializedProperty } from \"@gtkx/mcp/internal\";\nimport {\n type ExternalObject,\n getHandle,\n getInstanceType,\n type Handle,\n isReadableProperty,\n TYPE_ENUM,\n TYPE_FLAGS,\n typeIsA,\n typeName,\n} from \"@gtkx/runtime\";\nimport { fromValue, getValueType } from \"@gtkx/runtime/internal\";\nimport { errorMessage, kebabCase } from \"@gtkx/utils\";\nimport type { WidgetRegistry } from \"./widget-registry.js\";\n\ntype PropertyRepresentation = Omit<SerializedProperty, \"type\">;\ntype NativeProperty = { type: bigint; handle: ExternalObject<Handle> };\n\nconst SCALAR_TYPES: Set<string> = new Set([\"string\", \"number\", \"boolean\"]);\n\nconst canonicalName = (name: string): string => kebabCase(name).replaceAll(\"_\", \"-\");\nconst widgetTypeName = (widget: Gtk.Widget): string => typeName(getInstanceType(widget)) ?? widget.constructor.name;\nconst byName = (left: string, right: string): number => left.localeCompare(right);\n\nconst isScalar = (value: unknown): value is string | number | boolean | null =>\n value === null || SCALAR_TYPES.has(typeof value);\n\nfunction prototypesFor(widget: Gtk.Widget): object[] {\n const prototypes: object[] = [];\n let prototype = Object.getPrototypeOf(widget) as object | null;\n\n while (prototype !== null && prototype !== Object.prototype) {\n prototypes.push(prototype);\n prototype = Object.getPrototypeOf(prototype) as object | null;\n }\n\n return prototypes;\n}\n\nfunction getReadableNames(prototype: object): string[] {\n const descriptors = Object.entries(Object.getOwnPropertyDescriptors(prototype));\n\n return descriptors.filter(([, descriptor]) => descriptor.get !== undefined).map(([member]) => kebabCase(member));\n}\n\nfunction readablePropertyNames(widget: Gtk.Widget): string[] {\n const names = prototypesFor(widget).flatMap((prototype) => getReadableNames(prototype));\n\n return [...new Set(names)].toSorted(byName);\n}\n\nconst requireReadableProperty = (widget: Gtk.Widget, property: string): void => {\n if (isReadableProperty(getInstanceType(widget), property)) {\n return;\n }\n\n throw propertyNotFoundError(widgetTypeName(widget), property, readablePropertyNames(widget));\n};\n\nfunction readNativeProperty(widget: Gtk.Widget, property: string): NativeProperty {\n const value = new GObject.Value();\n widget.getProperty(property, value);\n const handle = getHandle(value);\n\n return { type: getValueType(handle), handle };\n}\n\nfunction describeObjectValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (typeof value !== \"object\" || value === null) {\n return { value: String(value) };\n }\n\n const name = typeName(getInstanceType(value)) ?? value.constructor.name;\n\n if (!(value instanceof Gtk.Widget)) {\n return { value: name };\n }\n\n registry.register(value);\n\n return { value: name, widgetId: registry.getOrCreateId(value) };\n}\n\nfunction representValue(value: unknown, registry: WidgetRegistry): PropertyRepresentation {\n if (isScalar(value)) {\n return { value };\n }\n\n if (typeof value === \"bigint\") {\n return { value: value.toString() };\n }\n\n if (Array.isArray(value)) {\n return { value: value.map(String) };\n }\n\n return describeObjectValue(value, registry);\n}\n\nfunction representNativeProperty(native: NativeProperty, registry: WidgetRegistry): PropertyRepresentation {\n if (typeIsA(native.type, TYPE_ENUM)) {\n return { value: GObject.enumToString(native.type, Number(fromValue(native.handle))) };\n }\n\n if (typeIsA(native.type, TYPE_FLAGS)) {\n return { value: GObject.flagsToString(native.type, Number(fromValue(native.handle))) };\n }\n\n return representValue(fromValue(native.handle), registry);\n}\n\nfunction serializeProperty(widget: Gtk.Widget, property: string, registry: WidgetRegistry): SerializedProperty {\n const native = readNativeProperty(widget, property);\n const type = typeName(native.type) ?? String(native.type);\n\n try {\n return { type, ...representNativeProperty(native, registry) };\n } catch (error) {\n return { type, value: null, note: `cannot be represented over MCP: ${errorMessage(error)}` };\n }\n}\n\nfunction readWidgetProperties(\n widget: Gtk.Widget,\n properties: string[],\n registry: WidgetRegistry,\n): Record<string, SerializedProperty> {\n const values: Record<string, SerializedProperty> = {};\n\n for (const name of properties) {\n const property = canonicalName(name);\n requireReadableProperty(widget, property);\n values[property] = serializeProperty(widget, property, registry);\n }\n\n return values;\n}\n\nexport { readWidgetProperties };\n"]}
@@ -1,5 +1,11 @@
1
1
  import type { ParsedSchemaFile } from "./parser.js";
2
+ type EnvAssetDeclarations = {
3
+ blocked: string[];
4
+ icons: string[];
5
+ legacy: string[];
6
+ resources: string[];
7
+ };
2
8
  declare const renderRuntimeModule: (file: ParsedSchemaFile) => string;
3
- declare const renderEnvModule: (files: ParsedSchemaFile[]) => string;
9
+ declare const renderEnvModule: (files: ParsedSchemaFile[], assetDeclarations?: EnvAssetDeclarations) => string;
4
10
  export { renderRuntimeModule, renderEnvModule };
5
11
  //# sourceMappingURL=render.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2B,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAoC7E,QAAA,MAAM,mBAAmB,GAAI,MAAM,gBAAgB,KAAG,MAyBrD,CAAC;AA8FF,QAAA,MAAM,eAAe,GAAI,OAAO,gBAAgB,EAAE,KAAG,MAQpD,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA2B,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAO7E,KAAK,oBAAoB,GAAG;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AA6DF,QAAA,MAAM,mBAAmB,GAAI,MAAM,gBAAgB,KAAG,MA0BrD,CAAC;AA6HF,QAAA,MAAM,eAAe,GACjB,OAAO,gBAAgB,EAAE,EACzB,oBAAoB,oBAAoB,KACzC,MAcF,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC"}
@@ -1,13 +1,28 @@
1
- import { upperFirst } from "@gtkx/utils";
1
+ import { camelCase, sanitizeIdentifier, upperFirst } from "@gtkx/utils";
2
2
  const GTKX_ENV_MODULE_HEADER = `/**
3
- * GSettings schema modules generated by GTKX from the project's
4
- * \`.gschema.xml\` files. Regenerated by \`gtkx codegen\`, \`gtkx dev\`, and
5
- * \`gtkx build\`; do not edit.
3
+ * Project import declarations generated by GTKX. Regenerated by
4
+ * \`gtkx codegen\`, \`gtkx dev\`, and \`gtkx build\`; do not edit.
6
5
  */`;
7
6
  const ENUM_KIND = "enum";
8
7
  const FLAGS_KIND = "flags";
8
+ const ID_SEPARATOR = /[._]/;
9
+ const NAME_SEPARATOR = "_";
9
10
  const toJsStringLiteral = (value) => JSON.stringify(value).replaceAll("\u{2028}", String.raw `\u2028`).replaceAll("\u{2029}", String.raw `\u2029`);
10
- const getExportName = (schemaId) => schemaId.replaceAll(".", "_");
11
+ const getExportName = (schemaId) => sanitizeIdentifier(schemaId.split(ID_SEPARATOR).map((part) => camelCase(part)).join(NAME_SEPARATOR));
12
+ const collisionError = (file, taken, schemaId, name) => new Error(`${file.fileName} declares ${taken} and ${schemaId}, which both export \`${name}\`. ` +
13
+ "Rename one of the schema ids so that every schema in the file gets an export of its own.");
14
+ const getNamedSchemas = (file) => {
15
+ const owners = new Map();
16
+ return file.schemas.map((schema) => {
17
+ const exportName = getExportName(schema.id);
18
+ const taken = owners.get(exportName);
19
+ if (taken !== undefined) {
20
+ throw collisionError(file, taken, schema.id, exportName);
21
+ }
22
+ owners.set(exportName, schema.id);
23
+ return { schema, exportName };
24
+ });
25
+ };
11
26
  const runtimeKindForKey = (key) => {
12
27
  if (key.enumId !== null) {
13
28
  return ENUM_KIND;
@@ -23,21 +38,22 @@ const getRuntimeKeys = (schema) => {
23
38
  };
24
39
  const renderRuntimeModule = (file) => {
25
40
  const lines = [];
26
- for (const [index, schema] of file.schemas.entries()) {
41
+ const named = getNamedSchemas(file);
42
+ for (const [index, { schema, exportName }] of named.entries()) {
27
43
  const keysName = `keys_${String(index)}`;
28
44
  const id = toJsStringLiteral(schema.id);
29
45
  lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);
30
46
  if (schema.path === null) {
31
- lines.push(`export const ${getExportName(schema.id)} = { id: ${id}, keys: ${keysName}, ` +
47
+ lines.push(`export const ${exportName} = { id: ${id}, keys: ${keysName}, ` +
32
48
  `at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`);
33
49
  }
34
50
  else {
35
- lines.push(`export const ${getExportName(schema.id)} = { id: ${id}, path: null, keys: ${keysName} };`);
51
+ lines.push(`export const ${exportName} = { id: ${id}, path: null, keys: ${keysName} };`);
36
52
  }
37
53
  }
38
- const first = file.schemas[0];
54
+ const first = named[0];
39
55
  if (first !== undefined) {
40
- lines.push(`export default ${getExportName(first.id)};`);
56
+ lines.push(`export default ${first.exportName};`);
41
57
  }
42
58
  return lines.join("\n");
43
59
  };
@@ -73,8 +89,7 @@ const boundRefTypeLines = (interfaceName, indent) => [
73
89
  `${indent}path: string | null;`,
74
90
  `${indent}keys: ${interfaceName};`,
75
91
  ];
76
- const renderSchemaConst = (schema, interfaceName) => {
77
- const exportName = getExportName(schema.id);
92
+ const renderSchemaConst = ({ schema, exportName }, interfaceName) => {
78
93
  if (schema.path !== null) {
79
94
  return [
80
95
  ` const ${exportName}: {`,
@@ -94,15 +109,15 @@ const renderSchemaConst = (schema, interfaceName) => {
94
109
  ];
95
110
  };
96
111
  const renderFileModule = (file, usedNames) => {
97
- const lines = [`declare module "${file.fileName}" {`];
112
+ const lines = [`declare module ${toJsStringLiteral(file.fileName)} {`];
98
113
  const exportNames = [];
99
- for (const [index, schema] of file.schemas.entries()) {
114
+ for (const [index, named] of getNamedSchemas(file).entries()) {
100
115
  if (index > 0) {
101
116
  lines.push("");
102
117
  }
103
- const interfaceName = allocateInterfaceName(schema.id, usedNames);
104
- lines.push(...renderKeysType(interfaceName, schema), "", ...renderSchemaConst(schema, interfaceName));
105
- exportNames.push(getExportName(schema.id));
118
+ const interfaceName = allocateInterfaceName(named.schema.id, usedNames);
119
+ lines.push(...renderKeysType(interfaceName, named.schema), "", ...renderSchemaConst(named, interfaceName));
120
+ exportNames.push(named.exportName);
106
121
  }
107
122
  const [firstExport] = exportNames;
108
123
  if (firstExport !== undefined) {
@@ -111,12 +126,46 @@ const renderFileModule = (file, usedNames) => {
111
126
  lines.push("}");
112
127
  return lines;
113
128
  };
114
- const renderEnvModule = (files) => {
129
+ const renderResourceModule = (specifier) => [
130
+ `declare module ${toJsStringLiteral(specifier)} {`,
131
+ " const path: string;",
132
+ " export { path };",
133
+ " export default path;",
134
+ "}",
135
+ ].join("\n");
136
+ const renderIconModule = (specifier) => [
137
+ `declare module ${toJsStringLiteral(specifier)} {`,
138
+ " const iconName: string;",
139
+ " export default iconName;",
140
+ "}",
141
+ ].join("\n");
142
+ const renderLegacyAssetModule = (specifier) => [
143
+ `declare module ${toJsStringLiteral(specifier)} {`,
144
+ " const resourceUri: string;",
145
+ " const path: string;",
146
+ " export { path };",
147
+ " export default resourceUri;",
148
+ "}",
149
+ ].join("\n");
150
+ const renderBlockedAssetModule = (specifier) => [
151
+ `declare module ${toJsStringLiteral(specifier)} {`,
152
+ " const assetImportRequiresResourceOrUrlQuery: {",
153
+ " readonly __gtkxAssetImportRequiresResourceOrUrlQuery: unique symbol;",
154
+ " };",
155
+ " export default assetImportRequiresResourceOrUrlQuery;",
156
+ "}",
157
+ ].join("\n");
158
+ const renderEnvModule = (files, assetDeclarations) => {
159
+ const assets = assetDeclarations ?? { blocked: [], icons: [], legacy: [], resources: [] };
115
160
  const usedNames = new Set();
116
- const blocks = files
161
+ const schemas = files
117
162
  .filter((file) => file.schemas.length > 0)
118
163
  .map((file) => renderFileModule(file, usedNames).join("\n"));
119
- return `${[GTKX_ENV_MODULE_HEADER, ...blocks].join("\n\n")}\n`;
164
+ const blocked = assets.blocked.map((specifier) => renderBlockedAssetModule(specifier));
165
+ const icons = assets.icons.map((specifier) => renderIconModule(specifier));
166
+ const legacy = assets.legacy.map((specifier) => renderLegacyAssetModule(specifier));
167
+ const resources = assets.resources.map((specifier) => renderResourceModule(specifier));
168
+ return `${[GTKX_ENV_MODULE_HEADER, ...blocked, ...icons, ...legacy, ...resources, ...schemas].join("\n\n")}\n`;
120
169
  };
121
170
  export { renderRuntimeModule, renderEnvModule };
122
171
  //# sourceMappingURL=render.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/settings/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,sBAAsB,GAAG;;;;IAI3B,CAAC;AAEL,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,MAAM,UAAU,GAAG,OAAO,CAAC;AAE3B,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAU,EAAE,CAChD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC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AAC,WAAW,CAAC,GAAG,WAAW,CAAC;IAElC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,gBAAgB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,sBAAsB,WAAW,GAAG,CAAC,CAAC;IACtG,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,KAAyB,EAAU,EAAE;IAC1D,MAAM,SAAS,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEzC,MAAM,MAAM,GAAG,KAAK;SACf,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;SACzC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjE,OAAO,GAAG,CAAC,sBAAsB,EAAE,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;AACnE,CAAC,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { upperFirst } from \"@gtkx/utils\";\nimport type { ParsedKey, ParsedSchema, ParsedSchemaFile } from \"./parser.js\";\n\nconst GTKX_ENV_MODULE_HEADER = `/**\n * GSettings schema modules generated by GTKX from the project's\n * \\`.gschema.xml\\` files. Regenerated by \\`gtkx codegen\\`, \\`gtkx dev\\`, and\n * \\`gtkx build\\`; do not edit.\n */`;\n\nconst ENUM_KIND = \"enum\";\nconst FLAGS_KIND = \"flags\";\n\nconst toJsStringLiteral = (value: string): string =>\n JSON.stringify(value).replaceAll(\"\\u{2028}\", String.raw`\\u2028`).replaceAll(\"\\u{2029}\", String.raw`\\u2029`);\n\nconst getExportName = (schemaId: string): string => schemaId.replaceAll(\".\", \"_\");\n\nconst runtimeKindForKey = (key: ParsedKey): string => {\n if (key.enumId !== null) {\n return ENUM_KIND;\n }\n\n if (key.flagsId !== null) {\n return FLAGS_KIND;\n }\n\n return key.variantType ?? \"\";\n};\n\nconst getRuntimeKeys = (schema: ParsedSchema): string => {\n const entries = schema.keys.map(\n (key) => `${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))}`,\n );\n\n return `{ ${entries.join(\", \")} }`;\n};\n\nconst renderRuntimeModule = (file: ParsedSchemaFile): string => {\n const lines: string[] = [];\n\n for (const [index, schema] of file.schemas.entries()) {\n const keysName = `keys_${String(index)}`;\n const id = toJsStringLiteral(schema.id);\n lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);\n\n if (schema.path === null) {\n lines.push(\n `export const ${getExportName(schema.id)} = { id: ${id}, keys: ${keysName}, ` +\n `at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`,\n );\n } else {\n lines.push(`export const ${getExportName(schema.id)} = { id: ${id}, path: null, keys: ${keysName} };`);\n }\n }\n\n const first = file.schemas[0];\n\n if (first !== undefined) {\n lines.push(`export default ${getExportName(first.id)};`);\n }\n\n return lines.join(\"\\n\");\n};\n\nconst sanitizeSummary = (summary: string): string => summary.replaceAll(\"*/\", String.raw`*\\/`);\n\nconst allocateInterfaceName = (schemaId: string, usedNames: Set<string>): string => {\n const base = `${schemaId\n .split(/[^a-zA-Z0-9]+/)\n .filter((part) => part.length > 0)\n .map((part) => upperFirst(part))\n .join(\"\")}Keys`;\n\n let name = base;\n let suffix = 2;\n\n while (usedNames.has(name)) {\n name = `${base}${String(suffix)}`;\n suffix += 1;\n }\n\n usedNames.add(name);\n\n return name;\n};\n\nconst renderKeysType = (name: string, schema: ParsedSchema): string[] => {\n const lines = [` type ${name} = {`];\n\n for (const key of schema.keys) {\n if (key.summary !== null) {\n lines.push(` /** ${sanitizeSummary(key.summary)} */`);\n }\n\n lines.push(` ${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))};`);\n }\n\n lines.push(\" };\");\n\n return lines;\n};\n\nconst boundRefTypeLines = (interfaceName: string, indent: string): string[] => [\n `${indent}id: string;`,\n `${indent}path: string | null;`,\n `${indent}keys: ${interfaceName};`,\n];\n\nconst renderSchemaConst = (schema: ParsedSchema, interfaceName: string): string[] => {\n const exportName = getExportName(schema.id);\n\n if (schema.path !== null) {\n return [\n ` const ${exportName}: {`,\n ` id: ${toJsStringLiteral(schema.id)};`,\n ...boundRefTypeLines(interfaceName, \" \".repeat(8)).slice(1),\n \" };\",\n ];\n }\n\n return [\n ` const ${exportName}: {`,\n ` id: ${JSON.stringify(schema.id)};`,\n ` keys: ${interfaceName};`,\n \" at(path: string): {\",\n ...boundRefTypeLines(interfaceName, \" \".repeat(12)),\n \" };\",\n \" };\",\n ];\n};\n\nconst renderFileModule = (file: ParsedSchemaFile, usedNames: Set<string>): string[] => {\n const lines = [`declare module \"${file.fileName}\" {`];\n const exportNames: string[] = [];\n\n for (const [index, schema] of file.schemas.entries()) {\n if (index > 0) {\n lines.push(\"\");\n }\n\n const interfaceName = allocateInterfaceName(schema.id, usedNames);\n lines.push(...renderKeysType(interfaceName, schema), \"\", ...renderSchemaConst(schema, interfaceName));\n exportNames.push(getExportName(schema.id));\n }\n\n const [firstExport] = exportNames;\n\n if (firstExport !== undefined) {\n lines.push(\"\", ` export { ${exportNames.join(\", \")} };`, ` export default ${firstExport};`);\n }\n\n lines.push(\"}\");\n\n return lines;\n};\n\nconst renderEnvModule = (files: ParsedSchemaFile[]): string => {\n const usedNames: Set<string> = new Set();\n\n const blocks = files\n .filter((file) => file.schemas.length > 0)\n .map((file) => renderFileModule(file, usedNames).join(\"\\n\"));\n\n return `${[GTKX_ENV_MODULE_HEADER, ...blocks].join(\"\\n\\n\")}\\n`;\n};\n\nexport { renderRuntimeModule, renderEnvModule };\n"]}
1
+ {"version":3,"file":"render.js","sourceR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CAAC,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { camelCase, sanitizeIdentifier, upperFirst } from \"@gtkx/utils\";\nimport type { ParsedKey, ParsedSchema, ParsedSchemaFile } from \"./parser.js\";\n\ntype NamedSchema = {\n schema: ParsedSchema;\n exportName: string;\n};\n\ntype EnvAssetDeclarations = {\n blocked: string[];\n icons: string[];\n legacy: string[];\n resources: string[];\n};\n\nconst GTKX_ENV_MODULE_HEADER = `/**\n * Project import declarations generated by GTKX. Regenerated by\n * \\`gtkx codegen\\`, \\`gtkx dev\\`, and \\`gtkx build\\`; do not edit.\n */`;\n\nconst ENUM_KIND = \"enum\";\nconst FLAGS_KIND = \"flags\";\nconst ID_SEPARATOR = /[._]/;\nconst NAME_SEPARATOR = \"_\";\n\nconst toJsStringLiteral = (value: string): string =>\n JSON.stringify(value).replaceAll(\"\\u{2028}\", String.raw`\\u2028`).replaceAll(\"\\u{2029}\", String.raw`\\u2029`);\n\nconst getExportName = (schemaId: string): string =>\n sanitizeIdentifier(schemaId.split(ID_SEPARATOR).map((part) => camelCase(part)).join(NAME_SEPARATOR));\n\nconst collisionError = (file: ParsedSchemaFile, taken: string, schemaId: string, name: string): Error =>\n new Error(\n `${file.fileName} declares ${taken} and ${schemaId}, which both export \\`${name}\\`. ` +\n \"Rename one of the schema ids so that every schema in the file gets an export of its own.\",\n );\n\nconst getNamedSchemas = (file: ParsedSchemaFile): NamedSchema[] => {\n const owners: Map<string, string> = new Map();\n\n return file.schemas.map((schema) => {\n const exportName = getExportName(schema.id);\n const taken = owners.get(exportName);\n\n if (taken !== undefined) {\n throw collisionError(file, taken, schema.id, exportName);\n }\n\n owners.set(exportName, schema.id);\n\n return { schema, exportName };\n });\n};\n\nconst runtimeKindForKey = (key: ParsedKey): string => {\n if (key.enumId !== null) {\n return ENUM_KIND;\n }\n\n if (key.flagsId !== null) {\n return FLAGS_KIND;\n }\n\n return key.variantType ?? \"\";\n};\n\nconst getRuntimeKeys = (schema: ParsedSchema): string => {\n const entries = schema.keys.map(\n (key) => `${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))}`,\n );\n\n return `{ ${entries.join(\", \")} }`;\n};\n\nconst renderRuntimeModule = (file: ParsedSchemaFile): string => {\n const lines: string[] = [];\n const named = getNamedSchemas(file);\n\n for (const [index, { schema, exportName }] of named.entries()) {\n const keysName = `keys_${String(index)}`;\n const id = toJsStringLiteral(schema.id);\n lines.push(`const ${keysName} = ${getRuntimeKeys(schema)};`);\n\n if (schema.path === null) {\n lines.push(\n `export const ${exportName} = { id: ${id}, keys: ${keysName}, ` +\n `at: (path) => ({ id: ${id}, path, keys: ${keysName} }) };`,\n );\n } else {\n lines.push(`export const ${exportName} = { id: ${id}, path: null, keys: ${keysName} };`);\n }\n }\n\n const first = named[0];\n\n if (first !== undefined) {\n lines.push(`export default ${first.exportName};`);\n }\n\n return lines.join(\"\\n\");\n};\n\nconst sanitizeSummary = (summary: string): string => summary.replaceAll(\"*/\", String.raw`*\\/`);\n\nconst allocateInterfaceName = (schemaId: string, usedNames: Set<string>): string => {\n const base = `${schemaId\n .split(/[^a-zA-Z0-9]+/)\n .filter((part) => part.length > 0)\n .map((part) => upperFirst(part))\n .join(\"\")}Keys`;\n\n let name = base;\n let suffix = 2;\n\n while (usedNames.has(name)) {\n name = `${base}${String(suffix)}`;\n suffix += 1;\n }\n\n usedNames.add(name);\n\n return name;\n};\n\nconst renderKeysType = (name: string, schema: ParsedSchema): string[] => {\n const lines = [` type ${name} = {`];\n\n for (const key of schema.keys) {\n if (key.summary !== null) {\n lines.push(` /** ${sanitizeSummary(key.summary)} */`);\n }\n\n lines.push(` ${toJsStringLiteral(key.name)}: ${toJsStringLiteral(runtimeKindForKey(key))};`);\n }\n\n lines.push(\" };\");\n\n return lines;\n};\n\nconst boundRefTypeLines = (interfaceName: string, indent: string): string[] => [\n `${indent}id: string;`,\n `${indent}path: string | null;`,\n `${indent}keys: ${interfaceName};`,\n];\n\nconst renderSchemaConst = ({ schema, exportName }: NamedSchema, interfaceName: string): string[] => {\n if (schema.path !== null) {\n return [\n ` const ${exportName}: {`,\n ` id: ${toJsStringLiteral(schema.id)};`,\n ...boundRefTypeLines(interfaceName, \" \".repeat(8)).slice(1),\n \" };\",\n ];\n }\n\n return [\n ` const ${exportName}: {`,\n ` id: ${JSON.stringify(schema.id)};`,\n ` keys: ${interfaceName};`,\n \" at(path: string): {\",\n ...boundRefTypeLines(interfaceName, \" \".repeat(12)),\n \" };\",\n \" };\",\n ];\n};\n\nconst renderFileModule = (file: ParsedSchemaFile, usedNames: Set<string>): string[] => {\n const lines = [`declare module ${toJsStringLiteral(file.fileName)} {`];\n const exportNames: string[] = [];\n\n for (const [index, named] of getNamedSchemas(file).entries()) {\n if (index > 0) {\n lines.push(\"\");\n }\n\n const interfaceName = allocateInterfaceName(named.schema.id, usedNames);\n lines.push(...renderKeysType(interfaceName, named.schema), \"\", ...renderSchemaConst(named, interfaceName));\n exportNames.push(named.exportName);\n }\n\n const [firstExport] = exportNames;\n\n if (firstExport !== undefined) {\n lines.push(\"\", ` export { ${exportNames.join(\", \")} };`, ` export default ${firstExport};`);\n }\n\n lines.push(\"}\");\n\n return lines;\n};\n\nconst renderResourceModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const path: string;\",\n \" export { path };\",\n \" export default path;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderIconModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const iconName: string;\",\n \" export default iconName;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderLegacyAssetModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const resourceUri: string;\",\n \" const path: string;\",\n \" export { path };\",\n \" export default resourceUri;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderBlockedAssetModule = (specifier: string): string => [\n `declare module ${toJsStringLiteral(specifier)} {`,\n \" const assetImportRequiresResourceOrUrlQuery: {\",\n \" readonly __gtkxAssetImportRequiresResourceOrUrlQuery: unique symbol;\",\n \" };\",\n \" export default assetImportRequiresResourceOrUrlQuery;\",\n \"}\",\n].join(\"\\n\");\n\nconst renderEnvModule = (\n files: ParsedSchemaFile[],\n assetDeclarations?: EnvAssetDeclarations,\n): string => {\n const assets = assetDeclarations ?? { blocked: [], icons: [], legacy: [], resources: [] };\n const usedNames: Set<string> = new Set();\n\n const schemas = files\n .filter((file) => file.schemas.length > 0)\n .map((file) => renderFileModule(file, usedNames).join(\"\\n\"));\n\n const blocked = assets.blocked.map((specifier) => renderBlockedAssetModule(specifier));\n const icons = assets.icons.map((specifier) => renderIconModule(specifier));\n const legacy = assets.legacy.map((specifier) => renderLegacyAssetModule(specifier));\n const resources = assets.resources.map((specifier) => renderResourceModule(specifier));\n\n return `${[GTKX_ENV_MODULE_HEADER, ...blocked, ...icons, ...legacy, ...resources, ...schemas].join(\"\\n\\n\")}\\n`;\n};\n\nexport { renderRuntimeModule, renderEnvModule };\n"]}
@@ -5,8 +5,9 @@ type SchemaEnvResult = {
5
5
  declare const SCHEMA_SUFFIX = ".gschema.xml";
6
6
  declare const prependSchemaDir: (dir: string, existing: string | undefined) => string;
7
7
  declare const stageSchema: (dir: string, filePath: string) => void;
8
- declare const findSchemaFiles: (dataDir: string) => string[];
8
+ declare const projectRelativeSchemaPath: (root: string, filePath: string) => string | null;
9
+ declare const assertUniqueSchemaBasenames: (schemaFiles: string[]) => void;
9
10
  declare const stageAndCompileProjectSchemas: (root: string, dataDir: string | null) => string | null;
10
- declare const emitSchemaEnv: (rootDir: string, dataDir: string | null) => SchemaEnvResult;
11
- export { SCHEMA_SUFFIX, prependSchemaDir, stageSchema, findSchemaFiles, stageAndCompileProjectSchemas, emitSchemaEnv, };
11
+ declare const emitSchemaEnv: (rootDir: string, dataDir: string | null, isV2ResourceImports?: boolean) => SchemaEnvResult;
12
+ export { SCHEMA_SUFFIX, prependSchemaDir, stageSchema, assertUniqueSchemaBasenames, projectRelativeSchemaPath, stageAndCompileProjectSchemas, emitSchemaEnv, };
12
13
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/settings/schema.ts"],"names":[],"mappings":"AAWA,KAAK,eAAe,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,QAAA,MAAM,aAAa,iBAAiB,CAAC;AAGrC,QAAA,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,GAAG,SAAS,KAAG,MAUrE,CAAC;AAKF,QAAA,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,KAAG,IAEpD,CAAC;AA6BF,QAAA,MAAM,eAAe,GAAI,SAAS,MAAM,KAAG,MAAM,EAKhD,CAAC;AAEF,QAAA,MAAM,6BAA6B,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAwBtF,CAAC;AAqDF,QAAA,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,GAAG,IAAI,KAAG,eAShE,CAAC;AAEF,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,6BAA6B,EAC7B,aAAa,GAChB,CAAC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/settings/schema.ts"],"names":[],"mappings":"AA4BA,KAAK,eAAe,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,QAAA,MAAM,aAAa,iBAAiB,CAAC;AAMrC,QAAA,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,GAAG,SAAS,KAAG,MAUrE,CAAC;AAKF,QAAA,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,UAAU,MAAM,KAAG,IAEpD,CAAC;AAIF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