@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
@@ -1,41 +1,70 @@
1
- import type { DeployConfig } from "./types.js";
1
+ import type { DeploySettings } from "./types.js";
2
2
 
3
3
  type Relations = {
4
4
  deb: string[];
5
5
  rpm: string[];
6
6
  };
7
7
 
8
- const GLES_SONAME = "libGLESv2.so.2()(64bit)";
8
+ type LibraryPackages = {
9
+ deb: string;
10
+ rpm: string;
11
+ extra: Relations;
12
+ };
13
+
14
+ const SONAME_SUFFIX = "()(64bit)";
15
+ const GLES_SONAME = `libGLESv2.so.2${SONAME_SUFFIX}`;
16
+ const NO_EXTRA: Relations = { deb: [], rpm: [] };
9
17
 
10
18
  const BASE_DEPENDS: Relations = {
11
19
  deb: ["hicolor-icon-theme", "adwaita-icon-theme", "gsettings-desktop-schemas"],
12
20
  rpm: ["hicolor-icon-theme", "adwaita-icon-theme", "gsettings-desktop-schemas"],
13
21
  };
14
22
 
15
- const DEPENDS_BY_LIBRARY: Record<string, Relations> = {
16
- "Adw-1": { deb: ["libadwaita-1-0"], rpm: ["libadwaita"] },
17
- "Gtk-4.0": { deb: ["libgtk-4-1"], rpm: ["gtk4", GLES_SONAME] },
18
- "GtkSource-5": { deb: ["libgtksourceview-5-0"], rpm: ["gtksourceview5"] },
19
- "WebKit-6.0": { deb: ["libwebkitgtk-6.0-4"], rpm: ["webkitgtk6.0"] },
23
+ const DEPENDS_BY_LIBRARY: Record<string, LibraryPackages> = {
24
+ "Adw-1": { deb: "libadwaita-1-0", rpm: "libadwaita", extra: NO_EXTRA },
25
+ "Gtk-4.0": { deb: "libgtk-4-1", rpm: "gtk4", extra: { deb: [], rpm: [GLES_SONAME] } },
20
26
  };
21
27
 
22
- const libraryDepends = (libraries: string[]): Relations => ({
23
- deb: libraries.flatMap((library) => DEPENDS_BY_LIBRARY[library]?.deb ?? []),
24
- rpm: libraries.flatMap((library) => DEPENDS_BY_LIBRARY[library]?.rpm ?? []),
25
- });
28
+ const debRelation = (name: string, minimum: string | undefined): string =>
29
+ minimum === undefined ? name : `${name} (>= ${minimum})`;
30
+
31
+ const rpmRelation = (name: string, minimum: string | undefined): string =>
32
+ minimum === undefined ? name : `${name} >= ${minimum}`;
33
+
34
+ const libraryDepends = (settings: DeploySettings): Relations => {
35
+ const deb: string[] = [];
36
+ const rpm: string[] = [];
37
+
38
+ for (const library of settings.libraries) {
39
+ const packages = DEPENDS_BY_LIBRARY[library];
40
+
41
+ if (packages === undefined) {
42
+ continue;
43
+ }
44
+
45
+ const minimum = settings.minimumLibraryVersions[library];
46
+ deb.push(debRelation(packages.deb, minimum), ...packages.extra.deb);
47
+ rpm.push(rpmRelation(packages.rpm, minimum), ...packages.extra.rpm);
48
+ }
49
+
50
+ return { deb, rpm };
51
+ };
26
52
 
27
- const glibcDepends = (glibcFloor: string | null): Relations =>
28
- glibcFloor === null ? { deb: [], rpm: [] } : { deb: [`libc6 (>= ${glibcFloor})`], rpm: [`glibc >= ${glibcFloor}`] };
53
+ const glibcDepends = (glibcMinimum: string | null): Relations =>
54
+ glibcMinimum === null
55
+ ? { deb: [], rpm: [] }
56
+ : { deb: [debRelation("libc6", glibcMinimum)], rpm: [rpmRelation("glibc", glibcMinimum)] };
29
57
 
30
58
  const dedupe = (entries: string[]): string[] => [...new Set(entries)];
31
59
 
32
- const resolveDepends = (deploy: DeployConfig, libraries: string[], glibcFloor: string | null): Relations => {
33
- const fromLibraries = libraryDepends(libraries);
34
- const fromGlibc = glibcDepends(glibcFloor);
60
+ const resolveDepends = (settings: DeploySettings, glibcMinimum: string | null): Relations => {
61
+ const fromLibraries = libraryDepends(settings);
62
+ const fromGlibc = glibcDepends(glibcMinimum);
63
+ const extra = settings.deploy.depends ?? {};
35
64
 
36
65
  return {
37
- deb: dedupe([...fromLibraries.deb, ...BASE_DEPENDS.deb, ...fromGlibc.deb, ...(deploy.depends?.deb ?? [])]),
38
- rpm: dedupe([...fromLibraries.rpm, ...BASE_DEPENDS.rpm, ...fromGlibc.rpm, ...(deploy.depends?.rpm ?? [])]),
66
+ deb: dedupe([...fromLibraries.deb, ...BASE_DEPENDS.deb, ...fromGlibc.deb, ...(extra.deb ?? [])]),
67
+ rpm: dedupe([...fromLibraries.rpm, ...BASE_DEPENDS.rpm, ...fromGlibc.rpm, ...(extra.rpm ?? [])]),
39
68
  };
40
69
  };
41
70
 
@@ -125,7 +125,7 @@ const descriptionFor = (settings: DeploySettings, packager: NfpmPackager): strin
125
125
  const renderNfpmConfig = (payload: DeployPayload, packager: NfpmPackager): NfpmConfig => {
126
126
  const settings = payload.settings;
127
127
  const isRpm = packager === "rpm";
128
- const depends = resolveDepends(settings.deploy, settings.libraries, payload.node?.glibcFloor ?? null);
128
+ const depends = resolveDepends(settings, payload.node?.glibcMinimum ?? null);
129
129
 
130
130
  return {
131
131
  name: packageNameFor(settings, packager),
@@ -8,7 +8,7 @@ type ElfSection = {
8
8
 
9
9
  type ElfInfo = {
10
10
  needed: string[];
11
- glibcFloor: string | null;
11
+ glibcMinimum: string | null;
12
12
  };
13
13
 
14
14
  type DynamicEntry = {
@@ -117,7 +117,7 @@ const highestVersion = (versions: number[][]): number[] | null => {
117
117
  const formatVersion = (version: number[] | null): string | null =>
118
118
  version === null ? null : `${String(version[0] ?? 0)}.${String(version[1] ?? 0)}`;
119
119
 
120
- const readGlibcFloor = (strings: Buffer): string | null => {
120
+ const readGlibcMinimum = (strings: Buffer): string | null => {
121
121
  const found = strings
122
122
  .toString("latin1")
123
123
  .matchAll(GLIBC_VERSION)
@@ -138,7 +138,7 @@ const readElfInfo = (path: string): ElfInfo => {
138
138
 
139
139
  return {
140
140
  needed: readNeeded(buffer, sectionFor(sections, ".dynamic"), strings),
141
- glibcFloor: readGlibcFloor(strings),
141
+ glibcMinimum: readGlibcMinimum(strings),
142
142
  };
143
143
  };
144
144
 
@@ -78,9 +78,9 @@ const resolveNodeRuntime = async (settings: DeploySettings): Promise<NodeRuntime
78
78
  const staged = await stageFromSource(settings, version, source);
79
79
  const isStripped = node.shouldStrip === false ? false : didStripBinary(staged.path);
80
80
  const elf = readElfInfo(staged.path);
81
- info(`Bundled Node.js v${version} (${megabytes(staged.path)} MiB, glibc >= ${elf.glibcFloor ?? "unknown"})`);
81
+ info(`Bundled Node.js v${version} (${megabytes(staged.path)} MiB, glibc >= ${elf.glibcMinimum ?? "unknown"})`);
82
82
 
83
- return { ...staged, version, glibcFloor: elf.glibcFloor, isStripped };
83
+ return { ...staged, version, glibcMinimum: elf.glibcMinimum, isStripped };
84
84
  };
85
85
 
86
86
  export { resolveNodeRuntime, sourcePathFor };
@@ -1,3 +1,4 @@
1
+ import type { RecordedPackage } from "../../internal/build-manifest.js";
1
2
  import type { DeploySettings, NodeRuntime, NoticeSection } from "../types.js";
2
3
  import { dependencyNotices } from "./dependencies.js";
3
4
  import { gtkxNotices } from "./gtkx.js";
@@ -8,10 +9,11 @@ import { bundledPackages } from "./packages.js";
8
9
  type NoticeRequest = {
9
10
  settings: DeploySettings;
10
11
  node: NodeRuntime | null;
12
+ packages: RecordedPackage[];
11
13
  };
12
14
 
13
- const collectNotices = ({ settings, node }: NoticeRequest): NoticeSection[] => {
14
- const packages = bundledPackages(settings);
15
+ const collectNotices = ({ settings, node, packages: recordedPackages }: NoticeRequest): NoticeSection[] => {
16
+ const packages = bundledPackages(settings, recordedPackages);
15
17
 
16
18
  const sections = [
17
19
  nodeNotices(settings, node),
@@ -1,17 +1,11 @@
1
- import { isRecord, sortStringsBy, warn } from "@gtkx/utils";
2
- import { existsSync, readFileSync, realpathSync } from "node:fs";
1
+ import { sortStringsBy, warn } from "@gtkx/utils";
2
+ import { existsSync, realpathSync } from "node:fs";
3
3
  import { join, resolve } from "node:path";
4
+ import type { RecordedPackage } from "../../internal/build-manifest.js";
4
5
  import type { DeploySettings } from "../types.js";
5
- import { BUNDLED_PACKAGES_FILENAME } from "../../vite-plugins/bundled-packages.js";
6
6
  import { type PackageManifest, readPackageManifest } from "../settings/package-manifest.js";
7
7
  import { copyrightLines, licenseTextIn } from "./text.js";
8
8
 
9
- type RecordedPackage = {
10
- name: string;
11
- version: string | null;
12
- dir: string;
13
- };
14
-
15
9
  type BundledPackage = {
16
10
  name: string;
17
11
  version: string | null;
@@ -36,38 +30,6 @@ const realPath = (path: string): string => {
36
30
  }
37
31
  };
38
32
 
39
- const optionalString = (value: unknown): string | null => (typeof value === "string" ? value : null);
40
-
41
- const recordedPackage = (entry: unknown): RecordedPackage | null => {
42
- if (!isRecord(entry) || typeof entry.name !== "string" || typeof entry.dir !== "string") {
43
- return null;
44
- }
45
-
46
- return { name: entry.name, version: optionalString(entry.version), dir: entry.dir };
47
- };
48
-
49
- const recordedList = (value: unknown): RecordedPackage[] => {
50
- if (!Array.isArray(value)) {
51
- return [];
52
- }
53
-
54
- const entries: unknown[] = value;
55
-
56
- return entries.map((entry) => recordedPackage(entry)).filter((entry) => entry !== null);
57
- };
58
-
59
- const readRecordedPackages = (settings: DeploySettings): RecordedPackage[] => {
60
- const path = join(settings.paths.dist, BUNDLED_PACKAGES_FILENAME);
61
-
62
- if (!existsSync(path)) {
63
- throw new Error(`Cannot deploy: ${path} is missing. Run \`gtkx build\` first.`);
64
- }
65
-
66
- const parsed: unknown = JSON.parse(readFileSync(path, "utf8"));
67
-
68
- return recordedList(isRecord(parsed) ? parsed.packages : null);
69
- };
70
-
71
33
  const authorLine = (manifest: PackageManifest): string[] => {
72
34
  const { name, email } = manifest.author;
73
35
 
@@ -151,10 +113,10 @@ const warnMissing = (entries: BundledPackage[]): void => {
151
113
  );
152
114
  };
153
115
 
154
- const bundledPackages = (settings: DeploySettings): BundledPackage[] => {
116
+ const bundledPackages = (settings: DeploySettings, recorded: RecordedPackage[]): BundledPackage[] => {
155
117
  const root = realPath(settings.paths.root);
156
118
 
157
- const entries = readRecordedPackages(settings)
119
+ const entries = recorded
158
120
  .map((entry) => ({ entry, dir: resolve(settings.paths.dist, entry.dir) }))
159
121
  .filter(({ dir }) => realPath(dir) !== root)
160
122
  .map(({ entry, dir }) => packageIn(entry, dir));
@@ -1,53 +1,82 @@
1
- import { basename, join } from "node:path";
1
+ import { join } from "node:path";
2
2
  import type { DeploySettings, StagedFile } from "../types.js";
3
+ import { relativeIconPath } from "../../internal/icon-path.js";
3
4
  import { listFilesRecursive } from "../../internal/list-files.js";
4
5
  import { copyInto } from "./copy-tree.js";
5
6
 
7
+ type ApplicationIconVariant = {
8
+ effectivePixels: number;
9
+ scalable: boolean;
10
+ };
11
+
6
12
  const ICON_EXTENSIONS = [".svg", ".png", ".xpm"];
7
13
  const SHARE_ICONS = "share/icons";
8
- const SCALABLE_DIR = "hicolor/scalable/apps";
9
- const SIZE_PATTERN = /^(?<width>[1-9]\d{0,3})x(?<height>[1-9]\d{0,3})$/;
10
- const SIZE_SEPARATORS = /[-_.]/;
11
-
12
- const isApplicationIcon = (settings: DeploySettings, rel: string): boolean =>
13
- ICON_EXTENSIONS.some((extension) => basename(rel) === `${settings.applicationId}${extension}`);
14
+ const SIZE_PATTERN = /^(?<width>[1-9]\d{0,3})x(?<height>[1-9]\d{0,3})(?:@(?<scale>[1-9]\d*))?$/;
14
15
 
15
- const getSquareSize = (token: string): number | null => {
16
+ const getSquareSize = (token: string): { pixels: number; scale: number } | null => {
16
17
  const groups = SIZE_PATTERN.exec(token)?.groups;
17
18
 
18
19
  if (groups === undefined || groups.width !== groups.height) {
19
20
  return null;
20
21
  }
21
22
 
22
- return Number(groups.width);
23
+ const pixels = Number(groups.width);
24
+ const scale = Number(groups.scale ?? "1");
25
+
26
+ return Number.isSafeInteger(pixels * scale) ? { pixels, scale } : null;
27
+ };
28
+
29
+ const isIconThemeSize = (segment: string | undefined): boolean =>
30
+ segment === "scalable" || segment === "symbolic" ||
31
+ (segment !== undefined && getSquareSize(segment) !== null);
32
+
33
+ const iconExtension = (applicationId: string, filename: string | undefined): string | undefined =>
34
+ ICON_EXTENSIONS.find((candidate) => filename === `${applicationId}${candidate}`);
35
+
36
+ const isApplicationIconLayout = (segments: (string | undefined)[]): boolean => {
37
+ const [share, icons, theme, size, context] = segments;
38
+
39
+ return share === "share" &&
40
+ icons === "icons" &&
41
+ theme === "hicolor" &&
42
+ context === "apps" &&
43
+ isIconThemeSize(size);
23
44
  };
24
45
 
25
- const firstSquareSize = (tokens: string[]): number | null =>
26
- tokens.map((token) => getSquareSize(token)).find((size) => size !== null) ?? null;
46
+ const classifyApplicationIcon = (applicationId: string, rel: string): ApplicationIconVariant | null => {
47
+ const segments = rel.split(/[\\/]/);
48
+
49
+ if (segments.length !== 6) {
50
+ return null;
51
+ }
27
52
 
28
- const getIconSize = (rel: string): number | null => firstSquareSize(rel.split("/").slice(0, -1));
53
+ const size = segments[3];
54
+ const filename = segments[5];
55
+ const extension = iconExtension(applicationId, filename);
29
56
 
30
- const themeDirFor = (file: string): string => {
31
- if (file.endsWith(".svg")) {
32
- return SCALABLE_DIR;
57
+ if (extension === undefined || !isApplicationIconLayout(segments)) {
58
+ return null;
33
59
  }
34
60
 
35
- const size = firstSquareSize(basename(file).split(SIZE_SEPARATORS));
61
+ const square = size === undefined ? null : getSquareSize(size);
36
62
 
37
- return size === null ? SCALABLE_DIR : `hicolor/${String(size)}x${String(size)}/apps`;
63
+ return {
64
+ effectivePixels: square === null ? 0 : square.pixels * square.scale,
65
+ scalable: extension === ".svg",
66
+ };
38
67
  };
39
68
 
40
- const stageIconTree = (root: string, iconsDir: string): StagedFile[] =>
41
- listFilesRecursive(iconsDir).map((file) => copyInto(root, join(SHARE_ICONS, file.rel), file.absPath));
69
+ const isApplicationIcon = (settings: DeploySettings, rel: string): boolean =>
70
+ classifyApplicationIcon(settings.applicationId, rel) !== null;
42
71
 
43
- const iconPathFor = (settings: DeploySettings, iconFile: string): string => {
44
- const extension = ICON_EXTENSIONS.find((candidate) => iconFile.endsWith(candidate)) ?? ".png";
72
+ const stageIconTree = (root: string, themePath: string): StagedFile[] =>
73
+ listFilesRecursive(themePath).map((file) => copyInto(root, join(SHARE_ICONS, file.rel), file.absPath));
45
74
 
46
- return join(themeDirFor(iconFile), `${settings.applicationId}${extension}`);
47
- };
75
+ const iconPathFor = (settings: DeploySettings, iconPath: string): string =>
76
+ relativeIconPath(settings.applicationId, iconPath);
48
77
 
49
- const stageIconFile = (settings: DeploySettings, root: string, iconFile: string): StagedFile[] =>
50
- [copyInto(root, join(SHARE_ICONS, iconPathFor(settings, iconFile)), iconFile)];
78
+ const stageIconFile = (settings: DeploySettings, root: string, iconPath: string): StagedFile[] =>
79
+ [copyInto(root, join(SHARE_ICONS, iconPathFor(settings, iconPath)), iconPath)];
51
80
 
52
81
  const assertApplicationIcon = (settings: DeploySettings, staged: StagedFile[]): void => {
53
82
  if (staged.some((file) => isApplicationIcon(settings, file.rel))) {
@@ -55,26 +84,27 @@ const assertApplicationIcon = (settings: DeploySettings, staged: StagedFile[]):
55
84
  }
56
85
 
57
86
  throw new Error(
58
- `Cannot deploy without an application icon: no ${settings.applicationId}.svg or ` +
59
- `${settings.applicationId}.png under ${settings.paths.iconsDir ?? "the project's icon directory"}. ` +
87
+ "Cannot deploy without a usable application icon: the configured theme must contain " +
88
+ `${settings.applicationId}.svg, ${settings.applicationId}.png, or ${settings.applicationId}.xpm ` +
89
+ "under hicolor/<size>/apps. " +
60
90
  "The desktop entry names " +
61
91
  `"${settings.applicationId}" as its icon, so the file has to match. ` +
62
- `Add ${settings.paths.dataDir ?? "data"}/icons/hicolor/scalable/apps/${settings.applicationId}.svg, ` +
63
- "or point `deploy.icons` at one.",
92
+ "Set `applicationIcon` to a theme directory containing " +
93
+ `hicolor/scalable/apps/${settings.applicationId}.svg, or point it at a single icon file.`,
64
94
  );
65
95
  };
66
96
 
67
97
  const stageIcons = (settings: DeploySettings, root: string): StagedFile[] => {
68
- const { iconsDir, iconFile } = settings.paths;
98
+ const source = settings.paths.applicationIcon;
69
99
 
70
- if (iconFile !== null) {
71
- return stageIconFile(settings, root, iconFile);
100
+ if (source.kind === "file") {
101
+ return stageIconFile(settings, root, source.path);
72
102
  }
73
103
 
74
- const staged = iconsDir === null ? [] : stageIconTree(root, iconsDir);
104
+ const staged = source.kind === "theme" ? stageIconTree(root, source.path) : [];
75
105
  assertApplicationIcon(settings, staged);
76
106
 
77
107
  return staged;
78
108
  };
79
109
 
80
- export { getIconSize, iconPathFor, stageIcons };
110
+ export { classifyApplicationIcon, iconPathFor, stageIcons, type ApplicationIconVariant };
@@ -2,8 +2,8 @@ import { sortStringsBy } from "@gtkx/utils";
2
2
  import { existsSync, rmSync } from "node:fs";
3
3
  import { join, resolve } from "node:path";
4
4
  import type { DeploySettings, DeployTargetName, NodeRuntime, NoticeSection, StagedFile } from "../types.js";
5
+ import { BUILD_MANIFEST_FILENAME } from "../../internal/build-manifest.js";
5
6
  import { listFilesRecursive } from "../../internal/list-files.js";
6
- import { BUNDLED_PACKAGES_FILENAME } from "../../vite-plugins/bundled-packages.js";
7
7
  import { BUNDLE_FILENAME } from "../../vite-plugins/esm-extension.js";
8
8
  import { renderCopyright } from "../freedesktop/copyright.js";
9
9
  import { renderDbusService } from "../freedesktop/dbus-service.js";
@@ -27,6 +27,7 @@ type StagedMetadata = {
27
27
  };
28
28
 
29
29
  const DIST_ICONS_DIR = "icons";
30
+ const LEGACY_PACKAGES_MANIFEST_FILENAME = "gtkx-packages.json";
30
31
  const NOTICES_FILENAME = "THIRD-PARTY-NOTICES";
31
32
  const NODE_LICENSE_FILENAME = "LICENSE";
32
33
  const SHARE_APPLICATIONS = "share/applications";
@@ -48,7 +49,9 @@ const licenseDirFor = (settings: DeploySettings): string => `${SHARE_LICENSES}/$
48
49
  const licenseDestination = (settings: DeploySettings): string => `${licenseDirFor(settings)}/LICENSE`;
49
50
  const noticesDestination = (settings: DeploySettings): string => `${licenseDirFor(settings)}/${NOTICES_FILENAME}`;
50
51
  const isIconAsset = (rel: string): boolean => rel === DIST_ICONS_DIR || rel.startsWith(`${DIST_ICONS_DIR}/`);
51
- const isBuildMetadata = (rel: string): boolean => rel === BUNDLED_PACKAGES_FILENAME;
52
+
53
+ const isBuildMetadata = (rel: string): boolean =>
54
+ rel === BUILD_MANIFEST_FILENAME || rel === LEGACY_PACKAGES_MANIFEST_FILENAME;
52
55
 
53
56
  const nodeLicenseDestination = (settings: DeploySettings): string =>
54
57
  `${licenseDirFor(settings)}/${NODE_FILENAME}/${NODE_LICENSE_FILENAME}`;
@@ -20,10 +20,11 @@ import { resolveNodeRuntime } from "./node-runtime/index.js";
20
20
  import { collectNotices } from "./notices/collect.js";
21
21
  import { type StagedMetadata, stageOverlays, stagePayload } from "./payload/stage.js";
22
22
  import { DEFAULT_TARGETS, parseTargetList, targetsFor } from "./registry.js";
23
+ import { readBuildManifest } from "./settings/build-manifest.js";
23
24
  import { resolveDeploySettings } from "./settings/index.js";
24
25
  import { readPackageManifest } from "./settings/package-manifest.js";
25
26
  import { missingDeployError } from "./settings/starter.js";
26
- import { finishArgsFor, hasDisplaySocket } from "./targets/flatpak-manifest.js";
27
+ import { finishArgsFor, hasDisplaySocket, runtimeLabelFor } from "./targets/flatpak-manifest.js";
27
28
  import { detectPackageManager } from "./targets/flatpak-sources.js";
28
29
  import {
29
30
  APPSTREAMCLI,
@@ -50,6 +51,8 @@ const BUILD_MODE = "production";
50
51
  const BYTES_PER_MIB = 1024 * 1024;
51
52
  const WEBKIT_LIBRARY = "WebKit-6.0";
52
53
  const NETWORK_ARG = "--share=network";
54
+ const APPIMAGE_TARGET = "appimage";
55
+ const FLATPAK_TARGET = "flatpak";
53
56
 
54
57
  const displayPath = (settings: DeploySettings, path: string): string => relative(settings.paths.root, path);
55
58
  const megabytes = (size: number): string => (size / BYTES_PER_MIB).toFixed(1);
@@ -66,7 +69,7 @@ const renderMetadata = (settings: DeploySettings): StagedMetadata => ({
66
69
  });
67
70
 
68
71
  const isFlathubSubmission = (settings: DeploySettings, targets: DeployTarget[]): boolean =>
69
- settings.deploy.flatpak?.mode === "source" && targets.some((target) => target.name === "flatpak");
72
+ settings.deploy.flatpak?.mode === "source" && targets.some((target) => target.name === FLATPAK_TARGET);
70
73
 
71
74
  const validateMetadata = (settings: DeploySettings, metadata: StagedMetadata, areWarningsFatal: boolean): void => {
72
75
  const dir = settings.paths.metadata;
@@ -104,7 +107,7 @@ const warnMissingNetwork = (settings: DeploySettings, finishArgs: string[]): voi
104
107
  };
105
108
 
106
109
  const warnFlatpakPermissions = (targets: DeployTarget[], settings: DeploySettings): void => {
107
- if (targets.every((target) => target.name !== "flatpak")) {
110
+ if (targets.every((target) => target.name !== FLATPAK_TARGET)) {
108
111
  return;
109
112
  }
110
113
 
@@ -113,10 +116,68 @@ const warnFlatpakPermissions = (targets: DeployTarget[], settings: DeploySetting
113
116
  warnMissingNetwork(settings, finishArgs);
114
117
  };
115
118
 
119
+ const minimumSummary = (settings: DeploySettings): string =>
120
+ settings.libraries
121
+ .filter((library) => settings.minimumLibraryVersions[library] !== undefined)
122
+ .map((library) => `${library} >= ${String(settings.minimumLibraryVersions[library])}`)
123
+ .join(", ");
124
+
125
+ const warnAppImageMinimums = (settings: DeploySettings, summary: string): void => {
126
+ warn(
127
+ `An AppImage cannot declare a dependency, so nothing stops ${settings.name} from starting on a host ` +
128
+ `whose libraries are older than the ones its bindings were generated against (${summary}). ` +
129
+ "Publish that requirement alongside the AppImage, or build on the oldest host you support.",
130
+ );
131
+ };
132
+
133
+ const warnFlatpakMinimums = (settings: DeploySettings, summary: string): void => {
134
+ warn(
135
+ `The flatpak bundles binaries built against ${summary}, but runs them on ` +
136
+ `${runtimeLabelFor(settings)}, whose libraries are whatever that runtime ships. ` +
137
+ 'Set `deploy.flatpak.mode: "source"` to build inside the runtime instead.',
138
+ );
139
+ };
140
+
141
+ const warnUnusedMinimums = (settings: DeploySettings): void => {
142
+ const minimums = settings.deploy.minimumLibraryVersions;
143
+
144
+ if (minimums === undefined) {
145
+ return;
146
+ }
147
+
148
+ const unused = Object.keys(minimums).filter((library) => !settings.libraries.includes(library));
149
+
150
+ if (unused.length === 0) {
151
+ return;
152
+ }
153
+
154
+ warn(
155
+ `\`deploy.minimumLibraryVersions\` names ${unused.join(", ")}, which this project generates no bindings for, ` +
156
+ "so those minimums change nothing.",
157
+ );
158
+ };
159
+
160
+ const isPrebuiltFlatpak = (targets: DeployTarget[], settings: DeploySettings): boolean =>
161
+ targets.some((target) => target.name === FLATPAK_TARGET) && settings.deploy.flatpak?.mode !== "source";
162
+
163
+ const warnLibraryMinimums = (targets: DeployTarget[], settings: DeploySettings): void => {
164
+ const summary = minimumSummary(settings);
165
+
166
+ if (summary.length > 0 && targets.some((target) => target.name === APPIMAGE_TARGET)) {
167
+ warnAppImageMinimums(settings, summary);
168
+ }
169
+
170
+ if (summary.length > 0 && isPrebuiltFlatpak(targets, settings)) {
171
+ warnFlatpakMinimums(settings, summary);
172
+ }
173
+
174
+ warnUnusedMinimums(settings);
175
+ };
176
+
116
177
  const sourceModeTools = (targets: DeployTarget[], settings: DeploySettings): DeployTool[] => {
117
178
  const isFlatpakSource = settings.deploy.flatpak?.mode === "source";
118
179
 
119
- if (!isFlatpakSource || targets.every((target) => target.name !== "flatpak")) {
180
+ if (!isFlatpakSource || targets.every((target) => target.name !== FLATPAK_TARGET)) {
120
181
  return [];
121
182
  }
122
183
 
@@ -124,7 +185,7 @@ const sourceModeTools = (targets: DeployTarget[], settings: DeploySettings): Dep
124
185
  };
125
186
 
126
187
  const isNodeRequired = (targets: DeployTarget[], settings: DeploySettings): boolean =>
127
- !(settings.deploy.flatpak?.mode === "source" && targets.every((target) => target.name === "flatpak"));
188
+ !(settings.deploy.flatpak?.mode === "source" && targets.every((target) => target.name === FLATPAK_TARGET));
128
189
 
129
190
  const runtimeToolsFor = (targets: DeployTarget[], settings: DeploySettings): DeployTool[] => {
130
191
  if (!isNodeRequired(targets, settings)) {
@@ -147,6 +208,7 @@ const preflight = (targets: DeployTarget[], settings: DeploySettings, shouldPrin
147
208
  assertTools(report);
148
209
  warnMissingOptional(report);
149
210
  warnFlatpakPermissions(targets, settings);
211
+ warnLibraryMinimums(targets, settings);
150
212
  };
151
213
 
152
214
  const resolveTargetNames = (options: DeployOptions, settings: DeploySettings): string[] => {
@@ -180,15 +242,28 @@ const buildPayload = async (
180
242
  await buildApp({ entry: options.entry, vite: { root: options.cwd } });
181
243
  }
182
244
 
183
- const node = options.shouldPrintManifests || !isNodeRequired(targets, settings)
184
- ? null
185
- : await resolveNodeRuntime(settings);
245
+ const buildManifest = readBuildManifest(settings);
186
246
 
187
- const stage = stagePayload({ settings, node, metadata });
188
- info(`Staged ${String(stage.length)} files into ${displayPath(settings, settings.paths.stage)}`);
189
- const notices = collectNotices({ settings, node });
247
+ const builtSettings: DeploySettings = {
248
+ ...settings,
249
+ paths: { ...settings.paths, schemaFiles: buildManifest.schemaFiles },
250
+ };
190
251
 
191
- return { settings, node, stage, notices, overlays: stageOverlays(settings, notices) };
252
+ const node = options.shouldPrintManifests || !isNodeRequired(targets, builtSettings)
253
+ ? null
254
+ : await resolveNodeRuntime(builtSettings);
255
+
256
+ const stage = stagePayload({ settings: builtSettings, node, metadata });
257
+ info(`Staged ${String(stage.length)} files into ${displayPath(builtSettings, builtSettings.paths.stage)}`);
258
+ const notices = collectNotices({ settings: builtSettings, node, packages: buildManifest.packages });
259
+
260
+ return {
261
+ settings: builtSettings,
262
+ node,
263
+ stage,
264
+ notices,
265
+ overlays: stageOverlays(builtSettings, notices),
266
+ };
192
267
  };
193
268
 
194
269
  const renderTargetManifests = (