@gtkx/cli 2.0.0-beta.1 → 2.0.0-beta.3

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 (238) hide show
  1. package/dist/builder.d.ts +1 -0
  2. package/dist/builder.d.ts.map +1 -1
  3. package/dist/builder.js +17 -5
  4. package/dist/builder.js.map +1 -1
  5. package/dist/cli.d.ts +1 -1
  6. package/dist/cli.d.ts.map +1 -1
  7. package/dist/cli.js +9 -1
  8. package/dist/cli.js.map +1 -1
  9. package/dist/codegen/reference.d.ts.map +1 -1
  10. package/dist/codegen/reference.js +1 -0
  11. package/dist/codegen/reference.js.map +1 -1
  12. package/dist/codegen/run-codegen.d.ts +4 -2
  13. package/dist/codegen/run-codegen.d.ts.map +1 -1
  14. package/dist/codegen/run-codegen.js +15 -16
  15. package/dist/codegen/run-codegen.js.map +1 -1
  16. package/dist/codegen/store-resolver.d.ts +2 -1
  17. package/dist/codegen/store-resolver.d.ts.map +1 -1
  18. package/dist/codegen/store-resolver.js +4 -3
  19. package/dist/codegen/store-resolver.js.map +1 -1
  20. package/dist/commands/build.d.ts +5 -0
  21. package/dist/commands/build.d.ts.map +1 -1
  22. package/dist/commands/build.js +83 -10
  23. package/dist/commands/build.js.map +1 -1
  24. package/dist/commands/codegen.d.ts +1 -0
  25. package/dist/commands/codegen.d.ts.map +1 -1
  26. package/dist/commands/codegen.js +6 -5
  27. package/dist/commands/codegen.js.map +1 -1
  28. package/dist/commands/deploy.d.ts +1 -0
  29. package/dist/commands/deploy.d.ts.map +1 -1
  30. package/dist/commands/deploy.js +4 -2
  31. package/dist/commands/deploy.js.map +1 -1
  32. package/dist/commands/dev.d.ts +9 -0
  33. package/dist/commands/dev.d.ts.map +1 -1
  34. package/dist/commands/dev.js +29 -4
  35. package/dist/commands/dev.js.map +1 -1
  36. package/dist/commands/docs.d.ts.map +1 -1
  37. package/dist/commands/docs.js +1 -0
  38. package/dist/commands/docs.js.map +1 -1
  39. package/dist/deploy/freedesktop/metainfo.d.ts.map +1 -1
  40. package/dist/deploy/freedesktop/metainfo.js +41 -2
  41. package/dist/deploy/freedesktop/metainfo.js.map +1 -1
  42. package/dist/deploy/freedesktop/validate.d.ts.map +1 -1
  43. package/dist/deploy/freedesktop/validate.js +10 -4
  44. package/dist/deploy/freedesktop/validate.js.map +1 -1
  45. package/dist/deploy/nfpm/config.d.ts +3 -2
  46. package/dist/deploy/nfpm/config.d.ts.map +1 -1
  47. package/dist/deploy/nfpm/config.js +7 -4
  48. package/dist/deploy/nfpm/config.js.map +1 -1
  49. package/dist/deploy/nfpm/contents.d.ts.map +1 -1
  50. package/dist/deploy/nfpm/contents.js +8 -0
  51. package/dist/deploy/nfpm/contents.js.map +1 -1
  52. package/dist/deploy/node-runtime/elf.d.ts +2 -1
  53. package/dist/deploy/node-runtime/elf.d.ts.map +1 -1
  54. package/dist/deploy/node-runtime/elf.js +32 -5
  55. package/dist/deploy/node-runtime/elf.js.map +1 -1
  56. package/dist/deploy/node-runtime/index.d.ts +2 -1
  57. package/dist/deploy/node-runtime/index.d.ts.map +1 -1
  58. package/dist/deploy/node-runtime/index.js +75 -5
  59. package/dist/deploy/node-runtime/index.js.map +1 -1
  60. package/dist/deploy/notices/node-runtime.js +2 -2
  61. package/dist/deploy/notices/node-runtime.js.map +1 -1
  62. package/dist/deploy/payload/launcher.d.ts.map +1 -1
  63. package/dist/deploy/payload/launcher.js +14 -1
  64. package/dist/deploy/payload/launcher.js.map +1 -1
  65. package/dist/deploy/payload/stage.js +1 -1
  66. package/dist/deploy/payload/stage.js.map +1 -1
  67. package/dist/deploy/run-deploy.d.ts +1 -0
  68. package/dist/deploy/run-deploy.d.ts.map +1 -1
  69. package/dist/deploy/run-deploy.js +100 -14
  70. package/dist/deploy/run-deploy.js.map +1 -1
  71. package/dist/deploy/settings/build-manifest.d.ts +6 -1
  72. package/dist/deploy/settings/build-manifest.d.ts.map +1 -1
  73. package/dist/deploy/settings/build-manifest.js +15 -4
  74. package/dist/deploy/settings/build-manifest.js.map +1 -1
  75. package/dist/deploy/settings/extra-files.d.ts +1 -1
  76. package/dist/deploy/settings/extra-files.d.ts.map +1 -1
  77. package/dist/deploy/settings/extra-files.js +22 -1
  78. package/dist/deploy/settings/extra-files.js.map +1 -1
  79. package/dist/deploy/settings/index.d.ts +1 -0
  80. package/dist/deploy/settings/index.d.ts.map +1 -1
  81. package/dist/deploy/settings/index.js +2 -1
  82. package/dist/deploy/settings/index.js.map +1 -1
  83. package/dist/deploy/settings/paths.d.ts +2 -1
  84. package/dist/deploy/settings/paths.d.ts.map +1 -1
  85. package/dist/deploy/settings/paths.js +113 -5
  86. package/dist/deploy/settings/paths.js.map +1 -1
  87. package/dist/deploy/targets/flatpak-source.d.ts.map +1 -1
  88. package/dist/deploy/targets/flatpak-source.js +11 -2
  89. package/dist/deploy/targets/flatpak-source.js.map +1 -1
  90. package/dist/deploy/targets/nfpm-target.d.ts.map +1 -1
  91. package/dist/deploy/targets/nfpm-target.js +12 -7
  92. package/dist/deploy/targets/nfpm-target.js.map +1 -1
  93. package/dist/deploy/types.d.ts +1 -0
  94. package/dist/deploy/types.d.ts.map +1 -1
  95. package/dist/deploy/types.js.map +1 -1
  96. package/dist/dev/entry-env.d.ts +2 -1
  97. package/dist/dev/entry-env.d.ts.map +1 -1
  98. package/dist/dev/entry-env.js +2 -1
  99. package/dist/dev/entry-env.js.map +1 -1
  100. package/dist/dev/headless.d.ts +3 -0
  101. package/dist/dev/headless.d.ts.map +1 -0
  102. package/dist/dev/headless.js +35 -0
  103. package/dist/dev/headless.js.map +1 -0
  104. package/dist/dev/runner-deps.d.ts +1 -1
  105. package/dist/dev/runner-deps.d.ts.map +1 -1
  106. package/dist/dev/runner-deps.js +3 -3
  107. package/dist/dev/runner-deps.js.map +1 -1
  108. package/dist/dev/runner-main.d.ts.map +1 -1
  109. package/dist/dev/runner-main.js +8 -3
  110. package/dist/dev/runner-main.js.map +1 -1
  111. package/dist/dev/supervisor.d.ts +1 -0
  112. package/dist/dev/supervisor.d.ts.map +1 -1
  113. package/dist/dev/supervisor.js +4 -3
  114. package/dist/dev/supervisor.js.map +1 -1
  115. package/dist/i18n/catalogs.d.ts.map +1 -1
  116. package/dist/i18n/catalogs.js +1 -0
  117. package/dist/i18n/catalogs.js.map +1 -1
  118. package/dist/i18n/source-messages.d.ts.map +1 -1
  119. package/dist/i18n/source-messages.js +960 -8
  120. package/dist/i18n/source-messages.js.map +1 -1
  121. package/dist/internal/build-manifest.d.ts +5 -2
  122. package/dist/internal/build-manifest.d.ts.map +1 -1
  123. package/dist/internal/build-manifest.js +15 -2
  124. package/dist/internal/build-manifest.js.map +1 -1
  125. package/dist/internal/build-output.d.ts +8 -0
  126. package/dist/internal/build-output.d.ts.map +1 -0
  127. package/dist/internal/build-output.js +79 -0
  128. package/dist/internal/build-output.js.map +1 -0
  129. package/dist/internal/docs-elements.d.ts +1 -0
  130. package/dist/internal/docs-elements.d.ts.map +1 -1
  131. package/dist/internal/docs-elements.js +5 -4
  132. package/dist/internal/docs-elements.js.map +1 -1
  133. package/dist/internal/entry-arg.d.ts +4 -1
  134. package/dist/internal/entry-arg.d.ts.map +1 -1
  135. package/dist/internal/entry-arg.js +7 -1
  136. package/dist/internal/entry-arg.js.map +1 -1
  137. package/dist/internal/errors.d.ts +2 -1
  138. package/dist/internal/errors.d.ts.map +1 -1
  139. package/dist/internal/errors.js +1 -1
  140. package/dist/internal/errors.js.map +1 -1
  141. package/dist/internal/output-directory.d.ts +15 -0
  142. package/dist/internal/output-directory.d.ts.map +1 -0
  143. package/dist/internal/output-directory.js +490 -0
  144. package/dist/internal/output-directory.js.map +1 -0
  145. package/dist/internal/parent-process.d.ts +12 -0
  146. package/dist/internal/parent-process.d.ts.map +1 -0
  147. package/dist/internal/parent-process.js +74 -0
  148. package/dist/internal/parent-process.js.map +1 -0
  149. package/dist/internal/prepare-project.d.ts +2 -0
  150. package/dist/internal/prepare-project.d.ts.map +1 -1
  151. package/dist/internal/prepare-project.js +3 -3
  152. package/dist/internal/prepare-project.js.map +1 -1
  153. package/dist/internal/source-imports.js +1 -1
  154. package/dist/internal/source-imports.js.map +1 -1
  155. package/dist/mcp/client.js +2 -2
  156. package/dist/mcp/client.js.map +1 -1
  157. package/dist/vite-plugins/build-manifest.d.ts +5 -1
  158. package/dist/vite-plugins/build-manifest.d.ts.map +1 -1
  159. package/dist/vite-plugins/build-manifest.js +2 -1
  160. package/dist/vite-plugins/build-manifest.js.map +1 -1
  161. package/dist/vite-plugins/ensure-store.d.ts +1 -1
  162. package/dist/vite-plugins/ensure-store.d.ts.map +1 -1
  163. package/dist/vite-plugins/ensure-store.js +2 -2
  164. package/dist/vite-plugins/ensure-store.js.map +1 -1
  165. package/dist/vite-plugins/i18n.d.ts.map +1 -1
  166. package/dist/vite-plugins/i18n.js +58 -6
  167. package/dist/vite-plugins/i18n.js.map +1 -1
  168. package/dist/vite-plugins/index.d.ts +8 -1
  169. package/dist/vite-plugins/index.d.ts.map +1 -1
  170. package/dist/vite-plugins/index.js +6 -2
  171. package/dist/vite-plugins/index.js.map +1 -1
  172. package/dist/vite-plugins/native.d.ts.map +1 -1
  173. package/dist/vite-plugins/native.js +0 -4
  174. package/dist/vite-plugins/native.js.map +1 -1
  175. package/dist/vite-plugins/self-contained.d.ts.map +1 -1
  176. package/dist/vite-plugins/self-contained.js +159 -158
  177. package/dist/vite-plugins/self-contained.js.map +1 -1
  178. package/dist/vite-plugins/settings-worker-env.d.ts +1 -1
  179. package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -1
  180. package/dist/vite-plugins/settings-worker-env.js +2 -2
  181. package/dist/vite-plugins/settings-worker-env.js.map +1 -1
  182. package/dist/vitest-plugin.d.ts +2 -1
  183. package/dist/vitest-plugin.d.ts.map +1 -1
  184. package/dist/vitest-plugin.js +6 -6
  185. package/dist/vitest-plugin.js.map +1 -1
  186. package/package.json +10 -9
  187. package/src/builder.ts +18 -5
  188. package/src/cli.ts +9 -1
  189. package/src/codegen/reference.ts +1 -0
  190. package/src/codegen/run-codegen.ts +17 -19
  191. package/src/codegen/store-resolver.ts +5 -3
  192. package/src/commands/build.ts +13 -2
  193. package/src/commands/codegen.ts +6 -5
  194. package/src/commands/deploy.ts +4 -2
  195. package/src/commands/dev.ts +38 -4
  196. package/src/commands/docs.ts +1 -0
  197. package/src/deploy/freedesktop/metainfo.ts +73 -21
  198. package/src/deploy/freedesktop/validate.ts +12 -4
  199. package/src/deploy/nfpm/config.ts +13 -4
  200. package/src/deploy/nfpm/contents.ts +8 -0
  201. package/src/deploy/node-runtime/elf.ts +43 -5
  202. package/src/deploy/node-runtime/index.ts +107 -6
  203. package/src/deploy/notices/node-runtime.ts +2 -2
  204. package/src/deploy/payload/launcher.ts +20 -1
  205. package/src/deploy/payload/stage.ts +1 -1
  206. package/src/deploy/run-deploy.ts +56 -16
  207. package/src/deploy/settings/build-manifest.ts +28 -3
  208. package/src/deploy/settings/extra-files.ts +26 -2
  209. package/src/deploy/settings/index.ts +3 -1
  210. package/src/deploy/settings/paths.ts +70 -5
  211. package/src/deploy/targets/flatpak-source.ts +13 -2
  212. package/src/deploy/targets/nfpm-target.ts +13 -6
  213. package/src/deploy/types.ts +1 -0
  214. package/src/dev/entry-env.ts +2 -1
  215. package/src/dev/headless.ts +40 -0
  216. package/src/dev/runner-deps.ts +3 -3
  217. package/src/dev/runner-main.ts +10 -3
  218. package/src/dev/supervisor.ts +6 -3
  219. package/src/i18n/catalogs.ts +1 -0
  220. package/src/i18n/source-messages.ts +1429 -28
  221. package/src/internal/build-manifest.ts +25 -1
  222. package/src/internal/build-output.ts +113 -0
  223. package/src/internal/docs-elements.ts +10 -4
  224. package/src/internal/entry-arg.ts +8 -1
  225. package/src/internal/errors.ts +1 -1
  226. package/src/internal/output-directory.ts +699 -0
  227. package/src/internal/parent-process.ts +110 -0
  228. package/src/internal/prepare-project.ts +5 -5
  229. package/src/internal/source-imports.ts +1 -1
  230. package/src/mcp/client.ts +2 -2
  231. package/src/vite-plugins/build-manifest.ts +7 -1
  232. package/src/vite-plugins/ensure-store.ts +2 -2
  233. package/src/vite-plugins/i18n.ts +83 -5
  234. package/src/vite-plugins/index.ts +14 -7
  235. package/src/vite-plugins/native.ts +0 -5
  236. package/src/vite-plugins/self-contained.ts +184 -185
  237. package/src/vite-plugins/settings-worker-env.ts +2 -2
  238. package/src/vitest-plugin.ts +6 -6
@@ -1,3 +1,5 @@
1
+ import { createHash } from "node:crypto";
2
+
1
3
  type RecordedPackage = {
2
4
  name: string;
3
5
  version: string | null;
@@ -7,6 +9,8 @@ type RecordedPackage = {
7
9
  type BuildManifest = {
8
10
  generator: typeof BUILD_MANIFEST_GENERATOR;
9
11
  formatVersion: typeof BUILD_MANIFEST_FORMAT_VERSION;
12
+ configFile: string;
13
+ configDigest: string;
10
14
  schemas: string[];
11
15
  packages: RecordedPackage[];
12
16
  };
@@ -17,7 +21,26 @@ type BuildManifestCollector = {
17
21
 
18
22
  const BUILD_MANIFEST_FILENAME = "gtkx-schemas.json";
19
23
  const BUILD_MANIFEST_GENERATOR = "gtkx-build";
20
- const BUILD_MANIFEST_FORMAT_VERSION = 1;
24
+ const BUILD_MANIFEST_FORMAT_VERSION = 2;
25
+
26
+ const canonicalConfig = (value: unknown): unknown => {
27
+ if (Array.isArray(value)) {
28
+ return value.map((entry) => canonicalConfig(entry));
29
+ }
30
+
31
+ if (typeof value !== "object" || value === null) {
32
+ return value;
33
+ }
34
+
35
+ return Object.fromEntries(
36
+ Object.entries(value)
37
+ .toSorted(([left], [right]) => left.localeCompare(right))
38
+ .map(([key, entry]) => [key, canonicalConfig(entry)]),
39
+ );
40
+ };
41
+
42
+ const configDigest = (config: unknown): string =>
43
+ createHash("sha256").update(JSON.stringify(canonicalConfig(config))).digest("hex");
21
44
 
22
45
  const createBuildManifestCollector = (): BuildManifestCollector => ({ schemas: [] });
23
46
 
@@ -25,6 +48,7 @@ export {
25
48
  BUILD_MANIFEST_FILENAME,
26
49
  BUILD_MANIFEST_FORMAT_VERSION,
27
50
  BUILD_MANIFEST_GENERATOR,
51
+ configDigest,
28
52
  createBuildManifestCollector,
29
53
  type BuildManifest,
30
54
  type BuildManifestCollector,
@@ -0,0 +1,113 @@
1
+ import { isPathInside, isRecord } from "@gtkx/utils";
2
+ import { lstatSync, readdirSync } from "node:fs";
3
+ import { dirname, join, relative, resolve, sep } from "node:path";
4
+ import {
5
+ BUILD_MANIFEST_FILENAME,
6
+ BUILD_MANIFEST_GENERATOR,
7
+ } from "./build-manifest.js";
8
+ import {
9
+ type OutputDirectoryTransaction,
10
+ prepareOutputDirectory,
11
+ readRegularFile,
12
+ } from "./output-directory.js";
13
+
14
+ const DEFAULT_BUILD_OUT_DIR = "dist";
15
+ const PRESERVED_BUILD_ENTRIES: ReadonlySet<string> = new Set([".git"]);
16
+
17
+ type PreparedBuildOutDir = Disposable & { commit: () => void; path: string };
18
+
19
+ const hasSymlinkComponent = (root: string, target: string): boolean => {
20
+ let current = root;
21
+
22
+ for (const segment of relative(root, target).split(sep)) {
23
+ current = join(current, segment);
24
+
25
+ if (lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink() === true) {
26
+ return true;
27
+ }
28
+ }
29
+
30
+ return false;
31
+ };
32
+
33
+ const isGtkxBuildDirectory = (path: string): boolean => {
34
+ const manifest = join(path, BUILD_MANIFEST_FILENAME);
35
+ const contents = readRegularFile(manifest);
36
+
37
+ try {
38
+ const parsed: unknown = contents === null ? null : JSON.parse(contents);
39
+
40
+ return isRecord(parsed) && parsed.generator === BUILD_MANIFEST_GENERATOR;
41
+ } catch {
42
+ return false;
43
+ }
44
+ };
45
+
46
+ const isReusableBuildDirectory = (path: string): boolean => {
47
+ const stats = lstatSync(path, { throwIfNoEntry: false });
48
+
49
+ if (stats === undefined) {
50
+ return true;
51
+ }
52
+
53
+ return stats.isDirectory() && (readdirSync(path).length === 0 || isGtkxBuildDirectory(path));
54
+ };
55
+
56
+ const buildOutputError = (root: string): Error =>
57
+ new Error(`Build output must be an empty directory or an earlier GTKX build below the project root ${root}`);
58
+
59
+ const hasGtkxBuildAncestor = (root: string, outDir: string): boolean => {
60
+ let ancestor = dirname(outDir);
61
+
62
+ while (isPathInside(root, ancestor)) {
63
+ if (isGtkxBuildDirectory(ancestor)) {
64
+ return true;
65
+ }
66
+
67
+ ancestor = dirname(ancestor);
68
+ }
69
+
70
+ return false;
71
+ };
72
+
73
+ const assertSafeBuildLocation = (root: string, outDir: string): void => {
74
+ if (!isPathInside(root, outDir) || hasSymlinkComponent(root, outDir) || hasGtkxBuildAncestor(root, outDir)) {
75
+ throw buildOutputError(root);
76
+ }
77
+ };
78
+
79
+ const resolveBuildOutDir = (root: string, configured?: string): string => {
80
+ const selected = configured ?? DEFAULT_BUILD_OUT_DIR;
81
+ const outDir = resolve(root, selected);
82
+
83
+ assertSafeBuildLocation(root, outDir);
84
+
85
+ if (!isReusableBuildDirectory(outDir)) {
86
+ throw buildOutputError(root);
87
+ }
88
+
89
+ return outDir;
90
+ };
91
+
92
+ const prepareBuildOutDir = (root: string, outDir: string): PreparedBuildOutDir => {
93
+ assertSafeBuildLocation(root, outDir);
94
+ const prepared = prepareOutputDirectory(root, outDir, isReusableBuildDirectory);
95
+
96
+ if (prepared.status === "unsafe") {
97
+ throw buildOutputError(root);
98
+ }
99
+
100
+ const transaction: OutputDirectoryTransaction = prepared.transaction;
101
+
102
+ return {
103
+ path: transaction.path,
104
+ commit: () => {
105
+ transaction.commit(PRESERVED_BUILD_ENTRIES, isGtkxBuildDirectory);
106
+ },
107
+ [Symbol.dispose]: () => {
108
+ transaction[Symbol.dispose]();
109
+ },
110
+ };
111
+ };
112
+
113
+ export { prepareBuildOutDir, resolveBuildOutDir };
@@ -1,21 +1,27 @@
1
- import { type ElementProps, type OmittedProps, readBuiltinElements, resolveStore } from "@gtkx/codegen";
1
+ import {
2
+ type ElementProps,
3
+ type OmittedProps,
4
+ resolveStore,
5
+ } from "@gtkx/codegen";
6
+ import { readBuiltinElementsForDocs } from "@gtkx/codegen/internal";
2
7
  import { existsSync } from "node:fs";
3
8
 
4
9
  type DocsElements = {
5
10
  props: ElementProps;
6
11
  omittedProps: OmittedProps;
12
+ acceptedChildTypes: Record<string, string[]>;
7
13
  };
8
14
 
9
15
  const resolveDocsElements = async (cwd: string): Promise<DocsElements> => {
10
16
  const { gi } = resolveStore(cwd);
11
17
 
12
18
  if (!existsSync(gi.storeDir)) {
13
- return { props: {}, omittedProps: {} };
19
+ return { props: {}, omittedProps: {}, acceptedChildTypes: {} };
14
20
  }
15
21
 
16
- const { props, omittedProps } = await readBuiltinElements();
22
+ const { props, omittedProps, acceptedChildTypes } = await readBuiltinElementsForDocs();
17
23
 
18
- return { props, omittedProps };
24
+ return { props, omittedProps, acceptedChildTypes };
19
25
  };
20
26
 
21
27
  export { resolveDocsElements };
@@ -14,6 +14,13 @@ const cwdArg: { cwd: StringArgDef } = {
14
14
  },
15
15
  };
16
16
 
17
+ const configArg: { config: StringArgDef } = {
18
+ config: {
19
+ type: "string",
20
+ description: "Project-relative configuration file (default: gtkx.config.*)",
21
+ },
22
+ };
23
+
17
24
  const entryArg: { entry: PositionalArgDef; cwd: StringArgDef } = {
18
25
  entry: {
19
26
  type: "positional",
@@ -57,4 +64,4 @@ const resolveGivenEntry = (cwd: string, entry: string): string => {
57
64
  const resolveEntry = (cwd: string, entry: string | undefined): string =>
58
65
  entry ? resolveGivenEntry(cwd, entry) : resolveDefaultEntry(cwd);
59
66
 
60
- export { cwdArg, entryArg, resolveCwd, resolveEntry };
67
+ export { configArg, cwdArg, entryArg, resolveCwd, resolveEntry };
@@ -33,4 +33,4 @@ const withErrorBoundary = <T extends ArgsDef>(command: CommandDef<T>): CommandDe
33
33
  };
34
34
  };
35
35
 
36
- export { withErrorBoundary };
36
+ export { printError, withErrorBoundary };