@gtkx/cli 1.4.0 → 1.6.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 (206) hide show
  1. package/README.md +1 -1
  2. package/dist/builder.d.ts +1 -0
  3. package/dist/builder.d.ts.map +1 -1
  4. package/dist/builder.js +2 -2
  5. package/dist/builder.js.map +1 -1
  6. package/dist/cli.js +4 -0
  7. package/dist/cli.js.map +1 -1
  8. package/dist/codegen/freshness.d.ts.map +1 -1
  9. package/dist/codegen/freshness.js +2 -1
  10. package/dist/codegen/freshness.js.map +1 -1
  11. package/dist/codegen/reference.d.ts +17 -0
  12. package/dist/codegen/reference.d.ts.map +1 -0
  13. package/dist/codegen/reference.js +37 -0
  14. package/dist/codegen/reference.js.map +1 -0
  15. package/dist/codegen/report.d.ts.map +1 -1
  16. package/dist/codegen/report.js +17 -3
  17. package/dist/codegen/report.js.map +1 -1
  18. package/dist/codegen/run-codegen.d.ts +4 -0
  19. package/dist/codegen/run-codegen.d.ts.map +1 -1
  20. package/dist/codegen/run-codegen.js +93 -27
  21. package/dist/codegen/run-codegen.js.map +1 -1
  22. package/dist/commands/codegen.js +1 -1
  23. package/dist/commands/codegen.js.map +1 -1
  24. package/dist/commands/docs.d.ts.map +1 -1
  25. package/dist/commands/docs.js +10 -16
  26. package/dist/commands/docs.js.map +1 -1
  27. package/dist/commands/mcp.d.ts +13 -0
  28. package/dist/commands/mcp.d.ts.map +1 -0
  29. package/dist/commands/mcp.js +68 -0
  30. package/dist/commands/mcp.js.map +1 -0
  31. package/dist/deploy/freedesktop/localize.d.ts +6 -0
  32. package/dist/deploy/freedesktop/localize.d.ts.map +1 -0
  33. package/dist/deploy/freedesktop/localize.js +107 -0
  34. package/dist/deploy/freedesktop/localize.js.map +1 -0
  35. package/dist/deploy/install-hints.d.ts.map +1 -1
  36. package/dist/deploy/install-hints.js +5 -0
  37. package/dist/deploy/install-hints.js.map +1 -1
  38. package/dist/deploy/notices/gtkx.js +1 -1
  39. package/dist/deploy/notices/gtkx.js.map +1 -1
  40. package/dist/deploy/notices/libraries.d.ts.map +1 -1
  41. package/dist/deploy/notices/libraries.js +2 -1
  42. package/dist/deploy/notices/libraries.js.map +1 -1
  43. package/dist/deploy/payload/launcher.d.ts.map +1 -1
  44. package/dist/deploy/payload/launcher.js +2 -0
  45. package/dist/deploy/payload/launcher.js.map +1 -1
  46. package/dist/deploy/payload/stage.d.ts +1 -1
  47. package/dist/deploy/payload/stage.d.ts.map +1 -1
  48. package/dist/deploy/payload/stage.js +20 -11
  49. package/dist/deploy/payload/stage.js.map +1 -1
  50. package/dist/deploy/run-deploy.d.ts.map +1 -1
  51. package/dist/deploy/run-deploy.js +87 -15
  52. package/dist/deploy/run-deploy.js.map +1 -1
  53. package/dist/deploy/settings/libraries.d.ts.map +1 -1
  54. package/dist/deploy/settings/libraries.js +7 -9
  55. package/dist/deploy/settings/libraries.js.map +1 -1
  56. package/dist/deploy/targets/flatpak-source.d.ts.map +1 -1
  57. package/dist/deploy/targets/flatpak-source.js +21 -10
  58. package/dist/deploy/targets/flatpak-source.js.map +1 -1
  59. package/dist/deploy/tools.d.ts +6 -1
  60. package/dist/deploy/tools.d.ts.map +1 -1
  61. package/dist/deploy/tools.js +27 -4
  62. package/dist/deploy/tools.js.map +1 -1
  63. package/dist/dev/locale-dir.d.ts +3 -0
  64. package/dist/dev/locale-dir.d.ts.map +1 -0
  65. package/dist/dev/locale-dir.js +17 -0
  66. package/dist/dev/locale-dir.js.map +1 -0
  67. package/dist/dev/runner-main.d.ts.map +1 -1
  68. package/dist/dev/runner-main.js +4 -1
  69. package/dist/dev/runner-main.js.map +1 -1
  70. package/dist/dev/runner.d.ts.map +1 -1
  71. package/dist/dev/runner.js +6 -0
  72. package/dist/dev/runner.js.map +1 -1
  73. package/dist/dev/vite-dev-server.d.ts +1 -0
  74. package/dist/dev/vite-dev-server.d.ts.map +1 -1
  75. package/dist/dev/vite-dev-server.js.map +1 -1
  76. package/dist/i18n/binding-extractor.d.ts +30 -0
  77. package/dist/i18n/binding-extractor.d.ts.map +1 -0
  78. package/dist/i18n/binding-extractor.js +1324 -0
  79. package/dist/i18n/binding-extractor.js.map +1 -0
  80. package/dist/i18n/catalog-template.d.ts +3 -0
  81. package/dist/i18n/catalog-template.d.ts.map +1 -0
  82. package/dist/i18n/catalog-template.js +18 -0
  83. package/dist/i18n/catalog-template.js.map +1 -0
  84. package/dist/i18n/catalogs.d.ts +21 -0
  85. package/dist/i18n/catalogs.d.ts.map +1 -0
  86. package/dist/i18n/catalogs.js +139 -0
  87. package/dist/i18n/catalogs.js.map +1 -0
  88. package/dist/i18n/extractor-plugin.d.ts +8 -0
  89. package/dist/i18n/extractor-plugin.d.ts.map +1 -0
  90. package/dist/i18n/extractor-plugin.js +247 -0
  91. package/dist/i18n/extractor-plugin.js.map +1 -0
  92. package/dist/i18n/metadata-templates.d.ts +11 -0
  93. package/dist/i18n/metadata-templates.d.ts.map +1 -0
  94. package/dist/i18n/metadata-templates.js +11 -0
  95. package/dist/i18n/metadata-templates.js.map +1 -0
  96. package/dist/i18n/source-messages.d.ts +23 -0
  97. package/dist/i18n/source-messages.d.ts.map +1 -0
  98. package/dist/i18n/source-messages.js +403 -0
  99. package/dist/i18n/source-messages.js.map +1 -0
  100. package/dist/i18n/types.d.ts +10 -0
  101. package/dist/i18n/types.d.ts.map +1 -0
  102. package/dist/i18n/types.js +108 -0
  103. package/dist/i18n/types.js.map +1 -0
  104. package/dist/internal/agent-rules.d.ts +7 -0
  105. package/dist/internal/agent-rules.d.ts.map +1 -0
  106. package/dist/internal/agent-rules.js +106 -0
  107. package/dist/internal/agent-rules.js.map +1 -0
  108. package/dist/internal/docs-elements.d.ts +8 -0
  109. package/dist/internal/docs-elements.d.ts.map +1 -0
  110. package/dist/internal/docs-elements.js +12 -0
  111. package/dist/internal/docs-elements.js.map +1 -0
  112. package/dist/internal/source-imports.d.ts +5 -1
  113. package/dist/internal/source-imports.d.ts.map +1 -1
  114. package/dist/internal/source-imports.js +25 -47
  115. package/dist/internal/source-imports.js.map +1 -1
  116. package/dist/mcp/client-config.d.ts +22 -0
  117. package/dist/mcp/client-config.d.ts.map +1 -0
  118. package/dist/mcp/client-config.js +94 -0
  119. package/dist/mcp/client-config.js.map +1 -0
  120. package/dist/mcp/client.d.ts +0 -1
  121. package/dist/mcp/client.d.ts.map +1 -1
  122. package/dist/mcp/client.js +11 -39
  123. package/dist/mcp/client.js.map +1 -1
  124. package/dist/mcp/handlers.d.ts +2 -1
  125. package/dist/mcp/handlers.d.ts.map +1 -1
  126. package/dist/mcp/handlers.js.map +1 -1
  127. package/dist/settings/render.d.ts +4 -1
  128. package/dist/settings/render.d.ts.map +1 -1
  129. package/dist/settings/render.js +11 -2
  130. package/dist/settings/render.js.map +1 -1
  131. package/dist/settings/schema.d.ts.map +1 -1
  132. package/dist/settings/schema.js +3 -1
  133. package/dist/settings/schema.js.map +1 -1
  134. package/dist/vite-plugins/animated.d.ts +5 -0
  135. package/dist/vite-plugins/animated.d.ts.map +1 -0
  136. package/dist/vite-plugins/animated.js +325 -0
  137. package/dist/vite-plugins/animated.js.map +1 -0
  138. package/dist/vite-plugins/asset-imports.d.ts.map +1 -1
  139. package/dist/vite-plugins/asset-imports.js +4 -14
  140. package/dist/vite-plugins/asset-imports.js.map +1 -1
  141. package/dist/vite-plugins/i18n.d.ts +5 -0
  142. package/dist/vite-plugins/i18n.d.ts.map +1 -0
  143. package/dist/vite-plugins/i18n.js +88 -0
  144. package/dist/vite-plugins/i18n.js.map +1 -0
  145. package/dist/vite-plugins/index.d.ts +1 -1
  146. package/dist/vite-plugins/index.d.ts.map +1 -1
  147. package/dist/vite-plugins/index.js +5 -1
  148. package/dist/vite-plugins/index.js.map +1 -1
  149. package/dist/vite-plugins/resources.d.ts.map +1 -1
  150. package/dist/vite-plugins/resources.js +12 -57
  151. package/dist/vite-plugins/resources.js.map +1 -1
  152. package/dist/vite-plugins/self-contained.d.ts.map +1 -1
  153. package/dist/vite-plugins/self-contained.js +128 -135
  154. package/dist/vite-plugins/self-contained.js.map +1 -1
  155. package/dist/vite-plugins/settings-worker-env.js +2 -2
  156. package/dist/vite-plugins/settings-worker-env.js.map +1 -1
  157. package/dist/vite-plugins/settings.d.ts.map +1 -1
  158. package/dist/vite-plugins/settings.js +2 -1
  159. package/dist/vite-plugins/settings.js.map +1 -1
  160. package/package.json +11 -9
  161. package/src/builder.ts +3 -2
  162. package/src/cli.ts +5 -0
  163. package/src/codegen/freshness.ts +2 -1
  164. package/src/codegen/reference.ts +59 -0
  165. package/src/codegen/report.ts +18 -3
  166. package/src/codegen/run-codegen.ts +134 -31
  167. package/src/commands/codegen.ts +1 -1
  168. package/src/commands/docs.ts +10 -28
  169. package/src/commands/mcp.ts +81 -0
  170. package/src/deploy/freedesktop/localize.ts +144 -0
  171. package/src/deploy/install-hints.ts +5 -0
  172. package/src/deploy/notices/gtkx.ts +1 -1
  173. package/src/deploy/notices/libraries.ts +2 -1
  174. package/src/deploy/payload/launcher.ts +2 -0
  175. package/src/deploy/payload/stage.ts +35 -10
  176. package/src/deploy/run-deploy.ts +128 -13
  177. package/src/deploy/settings/libraries.ts +7 -10
  178. package/src/deploy/targets/flatpak-source.ts +33 -10
  179. package/src/deploy/tools.ts +36 -3
  180. package/src/dev/locale-dir.ts +22 -0
  181. package/src/dev/runner-main.ts +4 -1
  182. package/src/dev/runner.ts +8 -0
  183. package/src/dev/vite-dev-server.ts +1 -0
  184. package/src/i18n/binding-extractor.ts +1969 -0
  185. package/src/i18n/catalog-template.ts +24 -0
  186. package/src/i18n/catalogs.ts +216 -0
  187. package/src/i18n/extractor-plugin.ts +413 -0
  188. package/src/i18n/metadata-templates.ts +29 -0
  189. package/src/i18n/source-messages.ts +608 -0
  190. package/src/i18n/types.ts +154 -0
  191. package/src/internal/agent-rules.ts +135 -0
  192. package/src/internal/docs-elements.ts +21 -0
  193. package/src/internal/source-imports.ts +31 -60
  194. package/src/mcp/client-config.ts +130 -0
  195. package/src/mcp/client.ts +17 -44
  196. package/src/mcp/handlers.ts +7 -6
  197. package/src/settings/render.ts +16 -2
  198. package/src/settings/schema.ts +3 -1
  199. package/src/vite-plugins/animated.ts +486 -0
  200. package/src/vite-plugins/asset-imports.ts +5 -17
  201. package/src/vite-plugins/i18n.ts +146 -0
  202. package/src/vite-plugins/index.ts +5 -0
  203. package/src/vite-plugins/resources.ts +12 -74
  204. package/src/vite-plugins/self-contained.ts +150 -169
  205. package/src/vite-plugins/settings-worker-env.ts +2 -2
  206. package/src/vite-plugins/settings.ts +2 -1
@@ -1,198 +1,191 @@
1
- import { isRecord } from "@gtkx/utils";
2
1
  import { isBuiltin } from "node:module";
3
2
  import { posix } from "node:path";
4
- import { parseSync } from "vite";
3
+ import { parseSync, Visitor } from "vite";
5
4
  const REQUIRE_FACTORY = "createRequire";
6
5
  const REQUIRE_BINDING = "require";
7
6
  const RESOLVE_PROPERTY = "resolve";
8
7
  const MODULE_BUILTIN = "node:module";
9
8
  const OUTPUT_DIRECTORY = ".";
10
9
  const RELATIVE_SPECIFIER = /^\.\.?(?:\/|$)/;
11
- const DECLARATION_KEYS = ["id", "local", "param", "params"];
12
- const SOURCE_STATEMENTS = new Set([
13
- "ExportAllDeclaration",
14
- "ExportNamedDeclaration",
15
- "ImportDeclaration",
16
- "ImportExpression",
17
- ]);
18
- const isAstNode = (value) => isRecord(value) && typeof value.type === "string";
19
- const nodeType = (node) => (typeof node.type === "string" ? node.type : "");
20
- const nodeName = (node) => node !== null && typeof node.name === "string" ? node.name : null;
21
- const childNode = (node, key) => {
22
- const value = node[key];
23
- return isAstNode(value) ? value : null;
24
- };
25
- const childNodes = (node, key) => {
26
- const value = node[key];
27
- if (!Array.isArray(value)) {
28
- return [];
29
- }
30
- const entries = value;
31
- return entries.filter(isAstNode);
32
- };
33
- const childValues = (value) => {
34
- if (Array.isArray(value)) {
35
- const entries = value;
36
- return entries;
37
- }
38
- if (!isAstNode(value)) {
39
- return [];
40
- }
41
- return Object.values(value).filter((child) => typeof child === "object" && child !== null);
42
- };
43
- const visitNode = (value, visit) => {
44
- if (isAstNode(value)) {
45
- visit(value);
46
- }
47
- };
48
- const walk = (root, visit) => {
49
- const stack = [root];
50
- while (stack.length > 0) {
51
- const current = stack.pop();
52
- visitNode(current, visit);
53
- for (const value of childValues(current)) {
54
- stack.push(value);
55
- }
56
- }
57
- };
58
- const countName = (declarations, node) => {
59
- const name = nodeName(node);
10
+ const exportName = (name) => (name.type === "Identifier" ? name.name : null);
11
+ const referenceName = (node) => (node.type === "Identifier" ? node.name : null);
12
+ const countName = (declarations, name) => {
60
13
  if (name !== null) {
61
14
  declarations.set(name, (declarations.get(name) ?? 0) + 1);
62
15
  }
63
16
  };
64
- const countDeclarations = (node, declarations) => {
65
- for (const key of DECLARATION_KEYS) {
66
- walk(node[key], (declared) => {
67
- countName(declarations, declared);
68
- });
17
+ const boundPattern = (item) => {
18
+ if (item === null) {
19
+ return null;
20
+ }
21
+ if (item.type === "Property") {
22
+ return item.value;
23
+ }
24
+ if (item.type === "RestElement") {
25
+ return item.argument;
26
+ }
27
+ return item.type === "TSParameterProperty" ? item.parameter : item;
28
+ };
29
+ const countPatterns = (declarations, items) => {
30
+ for (const item of items) {
31
+ countPattern(declarations, boundPattern(item));
69
32
  }
70
33
  };
34
+ const countPattern = (declarations, pattern) => {
35
+ if (pattern === null) {
36
+ return;
37
+ }
38
+ if (pattern.type === "Identifier") {
39
+ countName(declarations, pattern.name);
40
+ return;
41
+ }
42
+ if (pattern.type === "AssignmentPattern") {
43
+ countPattern(declarations, pattern.left);
44
+ return;
45
+ }
46
+ countPatterns(declarations, pattern.type === "ObjectPattern" ? pattern.properties : pattern.elements);
47
+ };
48
+ const countFunction = (declarations, node) => {
49
+ countPattern(declarations, node.id);
50
+ countPatterns(declarations, node.params);
51
+ };
52
+ const declarationVisitor = (declarations) => ({
53
+ ArrowFunctionExpression: (node) => {
54
+ countFunction(declarations, node);
55
+ },
56
+ CatchClause: (node) => {
57
+ countPattern(declarations, node.param);
58
+ },
59
+ ClassDeclaration: (node) => {
60
+ countPattern(declarations, node.id);
61
+ },
62
+ ClassExpression: (node) => {
63
+ countPattern(declarations, node.id);
64
+ },
65
+ ExportSpecifier: (node) => {
66
+ countName(declarations, exportName(node.local));
67
+ },
68
+ FunctionDeclaration: (node) => {
69
+ countFunction(declarations, node);
70
+ },
71
+ FunctionExpression: (node) => {
72
+ countFunction(declarations, node);
73
+ },
74
+ ImportDefaultSpecifier: (node) => {
75
+ countPattern(declarations, node.local);
76
+ },
77
+ ImportNamespaceSpecifier: (node) => {
78
+ countPattern(declarations, node.local);
79
+ },
80
+ ImportSpecifier: (node) => {
81
+ countPattern(declarations, node.local);
82
+ },
83
+ VariableDeclarator: (node) => {
84
+ countPattern(declarations, node.id);
85
+ },
86
+ });
71
87
  const isUnshadowed = (name, bindings) => (bindings.declarations.get(name) ?? 0) <= 1;
72
88
  const templateString = (node) => {
73
- if (childNodes(node, "expressions").length > 0) {
74
- return null;
75
- }
76
- const [quasi] = childNodes(node, "quasis");
77
- const value = quasi === undefined ? null : quasi.value;
78
- return isRecord(value) && typeof value.cooked === "string" ? value.cooked : null;
89
+ const [quasi] = node.quasis;
90
+ return quasi === undefined || node.expressions.length > 0 ? null : quasi.value.cooked;
79
91
  };
80
92
  const literalString = (node) => {
81
- if (node === null) {
82
- return null;
83
- }
84
- if (nodeType(node) === "Literal") {
85
- return typeof node.value === "string" ? node.value : null;
93
+ if (node?.type === "TemplateLiteral") {
94
+ return templateString(node);
86
95
  }
87
- return nodeType(node) === "TemplateLiteral" ? templateString(node) : null;
96
+ return node?.type === "Literal" && typeof node.value === "string" ? node.value : null;
88
97
  };
89
98
  const isMetaUrl = (node, bindings) => {
90
- if (nodeType(node) === "MemberExpression") {
91
- const object = childNode(node, "object");
92
- return object !== null && nodeType(object) === "MetaProperty";
99
+ if (node.type === "MemberExpression") {
100
+ return node.object.type === "MetaProperty";
93
101
  }
94
- const name = nodeName(node);
102
+ const name = referenceName(node);
95
103
  return name !== null && bindings.urls.has(name) && isUnshadowed(name, bindings);
96
104
  };
97
- const hasMetaUrl = (node, bindings) => childNodes(node, "arguments").some((argument) => isMetaUrl(argument, bindings));
105
+ const hasMetaUrl = (node, bindings) => node.arguments.some((argument) => isMetaUrl(argument, bindings));
98
106
  const isRequireName = (name, bindings) => name !== null && (name === REQUIRE_BINDING || bindings.requires.has(name)) && isUnshadowed(name, bindings);
99
107
  const isFactoryName = (name, bindings) => name !== null && (name === REQUIRE_FACTORY || bindings.factories.has(name)) && isUnshadowed(name, bindings);
100
- const isRequireFactory = (node, bindings) => {
101
- if (nodeType(node) !== "CallExpression") {
102
- return false;
103
- }
104
- return isFactoryName(nodeName(childNode(node, "callee")), bindings) || hasMetaUrl(node, bindings);
105
- };
106
- const isResolveTarget = (object, bindings) => nodeType(object) === "MetaProperty" ||
107
- isRequireName(nodeName(object), bindings) ||
108
+ const isRequireFactory = (node, bindings) => node.type === "CallExpression" &&
109
+ (isFactoryName(referenceName(node.callee), bindings) || hasMetaUrl(node, bindings));
110
+ const isResolveTarget = (object, bindings) => object.type === "MetaProperty" ||
111
+ isRequireName(referenceName(object), bindings) ||
108
112
  isRequireFactory(object, bindings);
109
- const isResolveMember = (callee, bindings) => {
110
- if (nodeType(callee) !== "MemberExpression" || callee.computed === true) {
111
- return false;
112
- }
113
- if (nodeName(childNode(callee, "property")) !== RESOLVE_PROPERTY) {
114
- return false;
115
- }
116
- const object = childNode(callee, "object");
117
- return object !== null && isResolveTarget(object, bindings);
118
- };
119
- const isResolvingCall = (call, bindings) => {
120
- if (hasMetaUrl(call, bindings)) {
121
- return true;
122
- }
123
- const callee = childNode(call, "callee");
124
- if (callee === null) {
125
- return false;
126
- }
127
- return (isRequireName(nodeName(callee), bindings) ||
128
- isRequireFactory(callee, bindings) ||
129
- isResolveMember(callee, bindings));
130
- };
113
+ const isResolveMember = (callee, bindings) => callee.type === "MemberExpression" &&
114
+ !callee.computed &&
115
+ callee.property.type === "Identifier" &&
116
+ callee.property.name === RESOLVE_PROPERTY &&
117
+ isResolveTarget(callee.object, bindings);
118
+ const isResolvingCall = (call, bindings) => hasMetaUrl(call, bindings) ||
119
+ isRequireName(referenceName(call.callee), bindings) ||
120
+ isRequireFactory(call.callee, bindings) ||
121
+ isResolveMember(call.callee, bindings);
131
122
  const collectFactories = (node, bindings) => {
132
- if (literalString(childNode(node, "source")) !== MODULE_BUILTIN) {
123
+ if (node.source.value !== MODULE_BUILTIN) {
133
124
  return;
134
125
  }
135
- for (const specifier of childNodes(node, "specifiers")) {
136
- const local = nodeName(childNode(specifier, "local"));
137
- if (local !== null && nodeName(childNode(specifier, "imported")) === REQUIRE_FACTORY) {
138
- bindings.factories.add(local);
126
+ for (const specifier of node.specifiers) {
127
+ if (specifier.type === "ImportSpecifier" && exportName(specifier.imported) === REQUIRE_FACTORY) {
128
+ bindings.factories.add(specifier.local.name);
139
129
  }
140
130
  }
141
131
  };
142
132
  const collectBinding = (node, bindings) => {
143
- const name = nodeName(childNode(node, "id"));
144
- const init = childNode(node, "init");
145
- if (name === null || init === null) {
133
+ const { id, init } = node;
134
+ if (init === null || id.type !== "Identifier") {
146
135
  return;
147
136
  }
148
137
  if (isMetaUrl(init, bindings)) {
149
- bindings.urls.add(name);
138
+ bindings.urls.add(id.name);
150
139
  }
151
140
  if (isRequireFactory(init, bindings)) {
152
- bindings.requires.add(name);
141
+ bindings.requires.add(id.name);
153
142
  }
154
143
  };
155
- const hasStringArgument = (call) => childNodes(call, "arguments").some((argument) => literalString(argument) !== null);
156
- const collectSource = (scan, node, type) => {
157
- if (!SOURCE_STATEMENTS.has(type)) {
158
- return;
159
- }
160
- const source = literalString(childNode(node, "source"));
144
+ const collectSource = (scan, source) => {
161
145
  if (source !== null) {
162
146
  scan.sources.push(source);
163
147
  }
164
148
  };
165
- const collectCall = (scan, node, type) => {
166
- if (type === "CallExpression" && hasStringArgument(node)) {
149
+ const collectCall = (scan, node) => {
150
+ if (node.arguments.some((argument) => literalString(argument) !== null)) {
167
151
  scan.calls.push(node);
168
152
  }
169
153
  };
170
- const scanNode = (scan, node) => {
171
- const type = nodeType(node);
172
- countDeclarations(node, scan.bindings.declarations);
173
- if (type === "ImportDeclaration") {
154
+ const scanVisitor = (scan) => ({
155
+ CallExpression: (node) => {
156
+ collectCall(scan, node);
157
+ },
158
+ ExportAllDeclaration: (node) => {
159
+ collectSource(scan, node.source.value);
160
+ },
161
+ ExportNamedDeclaration: (node) => {
162
+ collectSource(scan, node.source?.value ?? null);
163
+ },
164
+ ImportDeclaration: (node) => {
174
165
  collectFactories(node, scan.bindings);
175
- }
176
- else if (type === "VariableDeclarator") {
166
+ collectSource(scan, node.source.value);
167
+ },
168
+ ImportExpression: (node) => {
169
+ collectSource(scan, literalString(node.source));
170
+ },
171
+ VariableDeclarator: (node) => {
177
172
  collectBinding(node, scan.bindings);
178
- }
179
- collectSource(scan, node, type);
180
- collectCall(scan, node, type);
181
- };
173
+ },
174
+ });
182
175
  const scanChunk = (chunk) => {
183
176
  const scan = {
184
177
  bindings: { declarations: new Map(), factories: new Set(), requires: new Set(), urls: new Set() },
185
178
  calls: [],
186
179
  sources: [],
187
180
  };
188
- walk(parseSync(chunk.fileName, chunk.code).program, (node) => {
189
- scanNode(scan, node);
190
- });
181
+ const { program } = parseSync(chunk.fileName, chunk.code);
182
+ new Visitor(declarationVisitor(scan.bindings.declarations)).visit(program);
183
+ new Visitor(scanVisitor(scan)).visit(program);
191
184
  return scan;
192
185
  };
193
186
  const callSpecifiers = (scan) => scan.calls
194
187
  .filter((call) => isResolvingCall(call, scan.bindings))
195
- .flatMap((call) => childNodes(call, "arguments"))
188
+ .flatMap((call) => call.arguments)
196
189
  .map((argument) => literalString(argument))
197
190
  .filter((specifier) => specifier !== null);
198
191
  const isReachable = (specifier, directory, emitted) => {
@@ -1 +1 @@
1
- {"version":3,"file":"self-contained.js","sourceRoot":"","sources":["../../src/vite-plugins/self-contained.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EA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C,MAAM,CAAC,CAAC,CAAC;YAE7C,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC1B,mBAAmB,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;gBACnF,CAAC;YACL,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import type { Plugin } from \"vite\";\nimport { isRecord } from \"@gtkx/utils\";\nimport { isBuiltin } from \"node:module\";\nimport { posix } from \"node:path\";\nimport { parseSync } from \"vite\";\n\ntype AstNode = Record<string, unknown>;\n\ntype Bindings = {\n declarations: Map<string, number>;\n factories: Set<string>;\n requires: Set<string>;\n urls: Set<string>;\n};\n\ntype Scan = {\n bindings: Bindings;\n calls: AstNode[];\n sources: string[];\n};\n\ntype Chunk = {\n fileName: string;\n code: string;\n};\n\nconst REQUIRE_FACTORY = \"createRequire\";\nconst REQUIRE_BINDING = \"require\";\nconst RESOLVE_PROPERTY = \"resolve\";\nconst MODULE_BUILTIN = \"node:module\";\nconst OUTPUT_DIRECTORY = \".\";\nconst RELATIVE_SPECIFIER = /^\\.\\.?(?:\\/|$)/;\nconst DECLARATION_KEYS = [\"id\", \"local\", \"param\", \"params\"];\n\nconst SOURCE_STATEMENTS = new Set([\n \"ExportAllDeclaration\",\n \"ExportNamedDeclaration\",\n \"ImportDeclaration\",\n \"ImportExpression\",\n]);\n\nconst isAstNode = (value: unknown): value is AstNode => isRecord(value) && typeof value.type === \"string\";\nconst nodeType = (node: AstNode): string => (typeof node.type === \"string\" ? node.type : \"\");\n\nconst nodeName = (node: AstNode | null): string | null =>\n node !== null && typeof node.name === \"string\" ? node.name : null;\n\nconst childNode = (node: AstNode, key: string): AstNode | null => {\n const value = node[key];\n\n return isAstNode(value) ? value : null;\n};\n\nconst childNodes = (node: AstNode, key: string): AstNode[] => {\n const value = node[key];\n\n if (!Array.isArray(value)) {\n return [];\n }\n\n const entries: unknown[] = value;\n\n return entries.filter(isAstNode);\n};\n\nconst childValues = (value: unknown): unknown[] => {\n if (Array.isArray(value)) {\n const entries: unknown[] = value;\n\n return entries;\n }\n\n if (!isAstNode(value)) {\n return [];\n }\n\n return Object.values(value).filter((child) => typeof child === \"object\" && child !== null);\n};\n\nconst visitNode = (value: unknown, visit: (node: AstNode) => void): void => {\n if (isAstNode(value)) {\n visit(value);\n }\n};\n\nconst walk = (root: unknown, visit: (node: AstNode) => void): void => {\n const stack: unknown[] = [root];\n\n while (stack.length > 0) {\n const current = stack.pop();\n visitNode(current, visit);\n\n for (const value of childValues(current)) {\n stack.push(value);\n }\n }\n};\n\nconst countName = (declarations: Map<string, number>, node: AstNode): void => {\n const name = nodeName(node);\n\n if (name !== null) {\n declarations.set(name, (declarations.get(name) ?? 0) + 1);\n }\n};\n\nconst countDeclarations = (node: AstNode, declarations: Map<string, number>): void => {\n for (const key of DECLARATION_KEYS) {\n walk(node[key], (declared) => {\n countName(declarations, declared);\n });\n }\n};\n\nconst isUnshadowed = (name: string, bindings: Bindings): boolean => (bindings.declarations.get(name) ?? 0) <= 1;\n\nconst templateString = (node: AstNode): string | null => {\n if (childNodes(node, \"expressions\").length > 0) {\n return null;\n }\n\n const [quasi] = childNodes(node, \"quasis\");\n const value = quasi === undefined ? null : quasi.value;\n\n return isRecord(value) && typeof value.cooked === \"string\" ? value.cooked : null;\n};\n\nconst literalString = (node: AstNode | null): string | null => {\n if (node === null) {\n return null;\n }\n\n if (nodeType(node) === \"Literal\") {\n return typeof node.value === \"string\" ? node.value : null;\n }\n\n return nodeType(node) === \"TemplateLiteral\" ? templateString(node) : null;\n};\n\nconst isMetaUrl = (node: AstNode, bindings: Bindings): boolean => {\n if (nodeType(node) === \"MemberExpression\") {\n const object = childNode(node, \"object\");\n\n return object !== null && nodeType(object) === \"MetaProperty\";\n }\n\n const name = nodeName(node);\n\n return name !== null && bindings.urls.has(name) && isUnshadowed(name, bindings);\n};\n\nconst hasMetaUrl = (node: AstNode, bindings: Bindings): boolean =>\n childNodes(node, \"arguments\").some((argument) => isMetaUrl(argument, bindings));\n\nconst isRequireName = (name: string | null, bindings: Bindings): boolean =>\n name !== null && (name === REQUIRE_BINDING || bindings.requires.has(name)) && isUnshadowed(name, bindings);\n\nconst isFactoryName = (name: string | null, bindings: Bindings): boolean =>\n name !== null && (name === REQUIRE_FACTORY || bindings.factories.has(name)) && isUnshadowed(name, bindings);\n\nconst isRequireFactory = (node: AstNode, bindings: Bindings): boolean => {\n if (nodeType(node) !== \"CallExpression\") {\n return false;\n }\n\n return isFactoryName(nodeName(childNode(node, \"callee\")), bindings) || hasMetaUrl(node, bindings);\n};\n\nconst isResolveTarget = (object: AstNode, bindings: Bindings): boolean =>\n nodeType(object) === \"MetaProperty\" ||\n isRequireName(nodeName(object), bindings) ||\n isRequireFactory(object, bindings);\n\nconst isResolveMember = (callee: AstNode, bindings: Bindings): boolean => {\n if (nodeType(callee) !== \"MemberExpression\" || callee.computed === true) {\n return false;\n }\n\n if (nodeName(childNode(callee, \"property\")) !== RESOLVE_PROPERTY) {\n return false;\n }\n\n const object = childNode(callee, \"object\");\n\n return object !== null && isResolveTarget(object, bindings);\n};\n\nconst isResolvingCall = (call: AstNode, bindings: Bindings): boolean => {\n if (hasMetaUrl(call, bindings)) {\n return true;\n }\n\n const callee = childNode(call, \"callee\");\n\n if (callee === null) {\n return false;\n }\n\n return (\n isRequireName(nodeName(callee), bindings) ||\n isRequireFactory(callee, bindings) ||\n isResolveMember(callee, bindings)\n );\n};\n\nconst collectFactories = (node: AstNode, bindings: Bindings): void => {\n if (literalString(childNode(node, \"source\")) !== MODULE_BUILTIN) {\n return;\n }\n\n for (const specifier of childNodes(node, \"specifiers\")) {\n const local = nodeName(childNode(specifier, \"local\"));\n\n if (local !== null && nodeName(childNode(specifier, \"imported\")) === REQUIRE_FACTORY) {\n bindings.factories.add(local);\n }\n }\n};\n\nconst collectBinding = (node: AstNode, bindings: Bindings): void => {\n const name = nodeName(childNode(node, \"id\"));\n const init = childNode(node, \"init\");\n\n if (name === null || init === null) {\n return;\n }\n\n if (isMetaUrl(init, bindings)) {\n bindings.urls.add(name);\n }\n\n if (isRequireFactory(init, bindings)) {\n bindings.requires.add(name);\n }\n};\n\nconst hasStringArgument = (call: AstNode): boolean =>\n childNodes(call, \"arguments\").some((argument) => literalString(argument) !== null);\n\nconst collectSource = (scan: Scan, node: AstNode, type: string): void => {\n if (!SOURCE_STATEMENTS.has(type)) {\n return;\n }\n\n const source = literalString(childNode(node, \"source\"));\n\n if (source !== null) {\n scan.sources.push(source);\n }\n};\n\nconst collectCall = (scan: Scan, node: AstNode, type: string): void => {\n if (type === \"CallExpression\" && hasStringArgument(node)) {\n scan.calls.push(node);\n }\n};\n\nconst scanNode = (scan: Scan, node: AstNode): void => {\n const type = nodeType(node);\n countDeclarations(node, scan.bindings.declarations);\n\n if (type === \"ImportDeclaration\") {\n collectFactories(node, scan.bindings);\n } else if (type === \"VariableDeclarator\") {\n collectBinding(node, scan.bindings);\n }\n\n collectSource(scan, node, type);\n collectCall(scan, node, type);\n};\n\nconst scanChunk = (chunk: Chunk): Scan => {\n const scan: Scan = {\n bindings: { declarations: new Map(), factories: new Set(), requires: new Set(), urls: new Set() },\n calls: [],\n sources: [],\n };\n\n walk(parseSync(chunk.fileName, chunk.code).program, (node) => {\n scanNode(scan, node);\n });\n\n return scan;\n};\n\nconst callSpecifiers = (scan: Scan): string[] =>\n scan.calls\n .filter((call) => isResolvingCall(call, scan.bindings))\n .flatMap((call) => childNodes(call, \"arguments\"))\n .map((argument) => literalString(argument))\n .filter((specifier) => specifier !== null);\n\nconst isReachable = (specifier: string, directory: string, emitted: Set<string>): boolean => {\n if (isBuiltin(specifier)) {\n return true;\n }\n\n if (!RELATIVE_SPECIFIER.test(specifier)) {\n return false;\n }\n\n const target = posix.normalize(posix.join(directory, specifier));\n\n return target === OUTPUT_DIRECTORY || emitted.has(target);\n};\n\nconst unreachableSpecifiers = (chunk: Chunk, emitted: Set<string>): string[] => {\n const scan = scanChunk(chunk);\n const directory = posix.dirname(chunk.fileName);\n\n return new Set([...scan.sources, ...callSpecifiers(scan)])\n .values()\n .filter((specifier) => !isReachable(specifier, directory, emitted))\n .toArray()\n .toSorted((left, right) => left.localeCompare(right));\n};\n\nconst assertSelfContained = (chunk: Chunk, emitted: Set<string>): void => {\n const specifiers = unreachableSpecifiers(chunk, emitted);\n\n if (specifiers.length === 0) {\n return;\n }\n\n throw new Error(\n [\n `${chunk.fileName} resolves ${specifiers.join(\", \")} at runtime,`,\n \"so the built app only starts where that resolution succeeds from wherever it was installed.\",\n \"The artifact may resolve node: builtins and the files the build emits beside it, nothing else:\",\n \"bundle the module, emit the file, or read the data at build time.\",\n ].join(\" \"),\n );\n};\n\nfunction gtkxSelfContained(): Plugin {\n return {\n name: \"gtkx:self-contained\",\n apply: \"build\",\n\n generateBundle(_options, bundle) {\n const emitted = new Set(Object.keys(bundle));\n\n for (const output of Object.values(bundle)) {\n if (output.type === \"chunk\") {\n assertSelfContained({ fileName: output.fileName, code: output.code }, emitted);\n }\n }\n },\n };\n}\n\nexport { gtkxSelfContained };\n"]}
1
+ {"version":3,"file":"self-contained.js","sourceRoot":"","sources":["../../src/vite-plugins/self-contained.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AA4B1C,MAAM,eAAe,GAAG,eAAe,CAAC;AACxC,MAAM,eAAe,GAAG,SAAS,CAAC;AAClC,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACnC,MAAM,cAAc,GAAG,aAAa,CAAC;AACrC,MAAM,g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UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc;QACjE,6FAA6F;QAC7F,gGAAgG;QAChG,mEAAmE;KACtE,CAAC,IAAI,CAAC,GAAG,CAAC,CACd,CAAC;AACN,CAAC,CAAC;AAEF,SAAS,iBAAiB;IACtB,OAAO;QACH,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,OAAO;QAEd,cAAc,CAAC,QAAQ,EAAE,MAAM;YAC3B,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAE7C,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC1B,mBAAmB,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;gBACnF,CAAC;YACL,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import type { ESTree, Plugin, VisitorObject } from \"vite\";\nimport { isBuiltin } from \"node:module\";\nimport { posix } from \"node:path\";\nimport { parseSync, Visitor } from \"vite\";\n\ntype Bindings = {\n declarations: Map<string, number>;\n factories: Set<string>;\n requires: Set<string>;\n urls: Set<string>;\n};\n\ntype Scan = {\n bindings: Bindings;\n calls: ESTree.CallExpression[];\n sources: string[];\n};\n\ntype Chunk = {\n fileName: string;\n code: string;\n};\n\ntype PatternItem =\n | ESTree.BindingPattern |\n ESTree.BindingProperty |\n ESTree.BindingRestElement |\n ESTree.FormalParameterRest |\n ESTree.TSParameterProperty |\n null;\n\nconst REQUIRE_FACTORY = \"createRequire\";\nconst REQUIRE_BINDING = \"require\";\nconst RESOLVE_PROPERTY = \"resolve\";\nconst MODULE_BUILTIN = \"node:module\";\nconst OUTPUT_DIRECTORY = \".\";\nconst RELATIVE_SPECIFIER = /^\\.\\.?(?:\\/|$)/;\n\nconst exportName = (name: ESTree.ModuleExportName): string | null => (name.type === \"Identifier\" ? name.name : null);\nconst referenceName = (node: ESTree.Argument): string | null => (node.type === \"Identifier\" ? node.name : null);\n\nconst countName = (declarations: Map<string, number>, name: string | null): void => {\n if (name !== null) {\n declarations.set(name, (declarations.get(name) ?? 0) + 1);\n }\n};\n\nconst boundPattern = (item: PatternItem): ESTree.BindingPattern | null => {\n if (item === null) {\n return null;\n }\n\n if (item.type === \"Property\") {\n return item.value;\n }\n\n if (item.type === \"RestElement\") {\n return item.argument;\n }\n\n return item.type === \"TSParameterProperty\" ? item.parameter : item;\n};\n\nconst countPatterns = (declarations: Map<string, number>, items: PatternItem[]): void => {\n for (const item of items) {\n countPattern(declarations, boundPattern(item));\n }\n};\n\nconst countPattern = (declarations: Map<string, number>, pattern: ESTree.BindingPattern | null): void => {\n if (pattern === null) {\n return;\n }\n\n if (pattern.type === \"Identifier\") {\n countName(declarations, pattern.name);\n\n return;\n }\n\n if (pattern.type === \"AssignmentPattern\") {\n countPattern(declarations, pattern.left);\n\n return;\n }\n\n countPatterns(declarations, pattern.type === \"ObjectPattern\" ? pattern.properties : pattern.elements);\n};\n\nconst countFunction = (\n declarations: Map<string, number>,\n node: ESTree.ArrowFunctionExpression | ESTree.Function,\n): void => {\n countPattern(declarations, node.id);\n countPatterns(declarations, node.params);\n};\n\nconst declarationVisitor = (declarations: Map<string, number>): VisitorObject => ({\n ArrowFunctionExpression: (node) => {\n countFunction(declarations, node);\n },\n CatchClause: (node) => {\n countPattern(declarations, node.param);\n },\n ClassDeclaration: (node) => {\n countPattern(declarations, node.id);\n },\n ClassExpression: (node) => {\n countPattern(declarations, node.id);\n },\n ExportSpecifier: (node) => {\n countName(declarations, exportName(node.local));\n },\n FunctionDeclaration: (node) => {\n countFunction(declarations, node);\n },\n FunctionExpression: (node) => {\n countFunction(declarations, node);\n },\n ImportDefaultSpecifier: (node) => {\n countPattern(declarations, node.local);\n },\n ImportNamespaceSpecifier: (node) => {\n countPattern(declarations, node.local);\n },\n ImportSpecifier: (node) => {\n countPattern(declarations, node.local);\n },\n VariableDeclarator: (node) => {\n countPattern(declarations, node.id);\n },\n});\n\nconst isUnshadowed = (name: string, bindings: Bindings): boolean => (bindings.declarations.get(name) ?? 0) <= 1;\n\nconst templateString = (node: ESTree.TemplateLiteral): string | null => {\n const [quasi] = node.quasis;\n\n return quasi === undefined || node.expressions.length > 0 ? null : quasi.value.cooked;\n};\n\nconst literalString = (node: ESTree.Argument | null): string | null => {\n if (node?.type === \"TemplateLiteral\") {\n return templateString(node);\n }\n\n return node?.type === \"Literal\" && typeof node.value === \"string\" ? node.value : null;\n};\n\nconst isMetaUrl = (node: ESTree.Argument, bindings: Bindings): boolean => {\n if (node.type === \"MemberExpression\") {\n return node.object.type === \"MetaProperty\";\n }\n\n const name = referenceName(node);\n\n return name !== null && bindings.urls.has(name) && isUnshadowed(name, bindings);\n};\n\nconst hasMetaUrl = (node: ESTree.CallExpression, bindings: Bindings): boolean =>\n node.arguments.some((argument) => isMetaUrl(argument, bindings));\n\nconst isRequireName = (name: string | null, bindings: Bindings): boolean =>\n name !== null && (name === REQUIRE_BINDING || bindings.requires.has(name)) && isUnshadowed(name, bindings);\n\nconst isFactoryName = (name: string | null, bindings: Bindings): boolean =>\n name !== null && (name === REQUIRE_FACTORY || bindings.factories.has(name)) && isUnshadowed(name, bindings);\n\nconst isRequireFactory = (node: ESTree.Argument, bindings: Bindings): boolean =>\n node.type === \"CallExpression\" &&\n (isFactoryName(referenceName(node.callee), bindings) || hasMetaUrl(node, bindings));\n\nconst isResolveTarget = (object: ESTree.Expression, bindings: Bindings): boolean =>\n object.type === \"MetaProperty\" ||\n isRequireName(referenceName(object), bindings) ||\n isRequireFactory(object, bindings);\n\nconst isResolveMember = (callee: ESTree.Expression, bindings: Bindings): boolean =>\n callee.type === \"MemberExpression\" &&\n !callee.computed &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === RESOLVE_PROPERTY &&\n isResolveTarget(callee.object, bindings);\n\nconst isResolvingCall = (call: ESTree.CallExpression, bindings: Bindings): boolean =>\n hasMetaUrl(call, bindings) ||\n isRequireName(referenceName(call.callee), bindings) ||\n isRequireFactory(call.callee, bindings) ||\n isResolveMember(call.callee, bindings);\n\nconst collectFactories = (node: ESTree.ImportDeclaration, bindings: Bindings): void => {\n if (node.source.value !== MODULE_BUILTIN) {\n return;\n }\n\n for (const specifier of node.specifiers) {\n if (specifier.type === \"ImportSpecifier\" && exportName(specifier.imported) === REQUIRE_FACTORY) {\n bindings.factories.add(specifier.local.name);\n }\n }\n};\n\nconst collectBinding = (node: ESTree.VariableDeclarator, bindings: Bindings): void => {\n const { id, init } = node;\n\n if (init === null || id.type !== \"Identifier\") {\n return;\n }\n\n if (isMetaUrl(init, bindings)) {\n bindings.urls.add(id.name);\n }\n\n if (isRequireFactory(init, bindings)) {\n bindings.requires.add(id.name);\n }\n};\n\nconst collectSource = (scan: Scan, source: string | null): void => {\n if (source !== null) {\n scan.sources.push(source);\n }\n};\n\nconst collectCall = (scan: Scan, node: ESTree.CallExpression): void => {\n if (node.arguments.some((argument) => literalString(argument) !== null)) {\n scan.calls.push(node);\n }\n};\n\nconst scanVisitor = (scan: Scan): VisitorObject => ({\n CallExpression: (node) => {\n collectCall(scan, node);\n },\n ExportAllDeclaration: (node) => {\n collectSource(scan, node.source.value);\n },\n ExportNamedDeclaration: (node) => {\n collectSource(scan, node.source?.value ?? null);\n },\n ImportDeclaration: (node) => {\n collectFactories(node, scan.bindings);\n collectSource(scan, node.source.value);\n },\n ImportExpression: (node) => {\n collectSource(scan, literalString(node.source));\n },\n VariableDeclarator: (node) => {\n collectBinding(node, scan.bindings);\n },\n});\n\nconst scanChunk = (chunk: Chunk): Scan => {\n const scan: Scan = {\n bindings: { declarations: new Map(), factories: new Set(), requires: new Set(), urls: new Set() },\n calls: [],\n sources: [],\n };\n\n const { program } = parseSync(chunk.fileName, chunk.code);\n new Visitor(declarationVisitor(scan.bindings.declarations)).visit(program);\n new Visitor(scanVisitor(scan)).visit(program);\n\n return scan;\n};\n\nconst callSpecifiers = (scan: Scan): string[] =>\n scan.calls\n .filter((call) => isResolvingCall(call, scan.bindings))\n .flatMap((call) => call.arguments)\n .map((argument) => literalString(argument))\n .filter((specifier) => specifier !== null);\n\nconst isReachable = (specifier: string, directory: string, emitted: Set<string>): boolean => {\n if (isBuiltin(specifier)) {\n return true;\n }\n\n if (!RELATIVE_SPECIFIER.test(specifier)) {\n return false;\n }\n\n const target = posix.normalize(posix.join(directory, specifier));\n\n return target === OUTPUT_DIRECTORY || emitted.has(target);\n};\n\nconst unreachableSpecifiers = (chunk: Chunk, emitted: Set<string>): string[] => {\n const scan = scanChunk(chunk);\n const directory = posix.dirname(chunk.fileName);\n\n return new Set([...scan.sources, ...callSpecifiers(scan)])\n .values()\n .filter((specifier) => !isReachable(specifier, directory, emitted))\n .toArray()\n .toSorted((left, right) => left.localeCompare(right));\n};\n\nconst assertSelfContained = (chunk: Chunk, emitted: Set<string>): void => {\n const specifiers = unreachableSpecifiers(chunk, emitted);\n\n if (specifiers.length === 0) {\n return;\n }\n\n throw new Error(\n [\n `${chunk.fileName} resolves ${specifiers.join(\", \")} at runtime,`,\n \"so the built app only starts where that resolution succeeds from wherever it was installed.\",\n \"The artifact may resolve node: builtins and the files the build emits beside it, nothing else:\",\n \"bundle the module, emit the file, or read the data at build time.\",\n ].join(\" \"),\n );\n};\n\nfunction gtkxSelfContained(): Plugin {\n return {\n name: \"gtkx:self-contained\",\n apply: \"build\",\n\n generateBundle(_options, bundle) {\n const emitted = new Set(Object.keys(bundle));\n\n for (const output of Object.values(bundle)) {\n if (output.type === \"chunk\") {\n assertSelfContained({ fileName: output.fileName, code: output.code }, emitted);\n }\n }\n },\n };\n}\n\nexport { gtkxSelfContained };\n"]}
@@ -1,4 +1,4 @@
1
- import { createConfigLoader } from "@gtkx/config/internal";
1
+ import { createConfigLoader, resolveFuture } from "@gtkx/config/internal";
2
2
  import { resolveDataDir } from "../internal/data-dir.js";
3
3
  import { prependSchemaDir, stageAndCompileProjectSchemas } from "../settings/schema.js";
4
4
  function gtkxSettingsWorkerEnv() {
@@ -8,7 +8,7 @@ function gtkxSettingsWorkerEnv() {
8
8
  enforce: "pre",
9
9
  async config(config) {
10
10
  const loaded = await loadConfig.load(config.root ?? process.cwd());
11
- const dataDir = loaded.config.future?.v2ResourceImports === true ? null : resolveDataDir(loaded.root);
11
+ const dataDir = resolveFuture(loaded.config.future).isResourceImported ? null : resolveDataDir(loaded.root);
12
12
  const dir = stageAndCompileProjectSchemas(loaded.root, dataDir);
13
13
  if (dir === null) {
14
14
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"settings-worker-env.js","sourceRoot":"","sources":["../../src/vite-plugins/settings-worker-env.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAExF,SAAS,qBAAqB;IAC1B,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;IAExC,OAAO;QACH,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE,KAAK;QAEd,KAAK,CAAC,MAAM,CAAC,MAAkB;YAC3B,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YACnE,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtG,MAAM,GAAG,GAAG,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAEhE,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBACf,OAAO;YACX,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,GAAG,CAAC;YAEtC,OAAO;gBACH,IAAI,EAAE;oBACF,GAAG,EAAE,EAAE,oBAAoB,EAAE,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE;iBACzF;aACJ,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import type { UserConfig } from \"vite\";\nimport type { Plugin } from \"vitest/config\";\nimport { createConfigLoader } from \"@gtkx/config/internal\";\nimport { resolveDataDir } from \"../internal/data-dir.js\";\nimport { prependSchemaDir, stageAndCompileProjectSchemas } from \"../settings/schema.js\";\n\nfunction gtkxSettingsWorkerEnv(): Plugin {\n const loadConfig = createConfigLoader();\n\n return {\n name: \"gtkx:settings-worker-env\",\n enforce: \"pre\",\n\n async config(config: UserConfig) {\n const loaded = await loadConfig.load(config.root ?? process.cwd());\n const dataDir = loaded.config.future?.v2ResourceImports === true ? null : resolveDataDir(loaded.root);\n const dir = stageAndCompileProjectSchemas(loaded.root, dataDir);\n\n if (dir === null) {\n return;\n }\n\n process.env.GTKX_DEV_SCHEMA_DIR = dir;\n\n return {\n test: {\n env: { GSETTINGS_SCHEMA_DIR: prependSchemaDir(dir, process.env.GSETTINGS_SCHEMA_DIR) },\n },\n };\n },\n };\n}\n\nexport { gtkxSettingsWorkerEnv };\n"]}
1
+ {"version":3,"file":"settings-worker-env.js","sourceRoot":"","sources":["../../src/vite-plugins/settings-worker-env.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAExF,SAAS,qBAAqB;IAC1B,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;IAExC,OAAO;QACH,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE,KAAK;QAEd,KAAK,CAAC,MAAM,CAAC,MAAkB;YAC3B,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YACnE,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC5G,MAAM,GAAG,GAAG,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAEhE,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBACf,OAAO;YACX,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,GAAG,CAAC;YAEtC,OAAO;gBACH,IAAI,EAAE;oBACF,GAAG,EAAE,EAAE,oBAAoB,EAAE,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE;iBACzF;aACJ,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import type { UserConfig } from \"vite\";\nimport type { Plugin } from \"vitest/config\";\nimport { createConfigLoader, resolveFuture } from \"@gtkx/config/internal\";\nimport { resolveDataDir } from \"../internal/data-dir.js\";\nimport { prependSchemaDir, stageAndCompileProjectSchemas } from \"../settings/schema.js\";\n\nfunction gtkxSettingsWorkerEnv(): Plugin {\n const loadConfig = createConfigLoader();\n\n return {\n name: \"gtkx:settings-worker-env\",\n enforce: \"pre\",\n\n async config(config: UserConfig) {\n const loaded = await loadConfig.load(config.root ?? process.cwd());\n const dataDir = resolveFuture(loaded.config.future).isResourceImported ? null : resolveDataDir(loaded.root);\n const dir = stageAndCompileProjectSchemas(loaded.root, dataDir);\n\n if (dir === null) {\n return;\n }\n\n process.env.GTKX_DEV_SCHEMA_DIR = dir;\n\n return {\n test: {\n env: { GSETTINGS_SCHEMA_DIR: prependSchemaDir(dir, process.env.GSETTINGS_SCHEMA_DIR) },\n },\n };\n },\n };\n}\n\nexport { gtkxSettingsWorkerEnv };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/vite-plugins/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAc,MAAM,EAA6C,MAAM,MAAM,CAAC;AAI1F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAkQ5E,iBAAS,YAAY,CAAC,UAAU,EAAE,YAAY,EAAE,aAAa,CAAC,EAAE,sBAAsB,GAAG,MAAM,CA6D9F;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/vite-plugins/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAc,MAAM,EAA6C,MAAM,MAAM,CAAC;AAK1F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAkQ5E,iBAAS,YAAY,CAAC,UAAU,EAAE,YAAY,EAAE,aAAa,CAAC,EAAE,sBAAsB,GAAG,MAAM,CA6D9F;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { resolveFuture } from "@gtkx/config/internal";
1
2
  import { error, errorMessage, info, sortStrings } from "@gtkx/utils";
2
3
  import { readFileSync } from "node:fs";
3
4
  import { basename, join } from "node:path";
@@ -65,7 +66,7 @@ const scheduleSchemaEnvSync = (state) => {
65
66
  };
66
67
  const applyUserConfig = async (state, config, loadConfig) => {
67
68
  const loaded = await loadConfig.load(config.root ?? process.cwd());
68
- state.isV2ResourceImports = loaded.config.future?.v2ResourceImports === true;
69
+ state.isV2ResourceImports = resolveFuture(loaded.config.future).isResourceImported;
69
70
  state.dataDir = state.isV2ResourceImports ? null : resolveDataDir(loaded.root);
70
71
  };
71
72
  const applyResolvedConfig = (state, config) => {
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/vite-plugins/settings.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAA2B,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/G,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACH,2BAA2B,EAC3B,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,aAAa,EACb,WAAW,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAiB7D,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAC1C,MAAM,qBAAqB,GAAG,SAAS,CAAC;AACxC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAC3C,MAAM,sBAAs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AC;QAED,QAAQ;YACJ,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;QACjD,CAAC;QAED,WAAW;YACP,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAC3B,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QAED,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;YAC5B,OAAO,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import type { ConfigLoader } from \"@gtkx/config\";\nimport type { ModuleNode, Plugin, ResolvedConfig, UserConfig, ViteDevServer } from \"vite\";\nimport { error, errorMessage, info, sortStrings } from \"@gtkx/utils\";\nimport { readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport type { BuildManifestCollector } from \"../internal/build-manifest.js\";\nimport type { AssetEmitter } from \"./asset-emitter.js\";\nimport { prependBanner } from \"../internal/banner.js\";\nimport { resolveDataDir } from \"../internal/data-dir.js\";\nimport { createRetainedStagingDir, type RetainedStagingDir, withStagingDir } from \"../internal/staging-dir.js\";\nimport { compileSchemas } from \"../settings/compile.js\";\nimport { parseSchemaXml, SchemaParseError } from \"../settings/parser.js\";\nimport { renderRuntimeModule } from \"../settings/render.js\";\nimport {\n assertUniqueSchemaBasenames,\n emitSchemaEnv,\n prependSchemaDir,\n projectRelativeSchemaPath,\n SCHEMA_SUFFIX,\n stageSchema,\n} from \"../settings/schema.js\";\nimport { createVirtualNamespace } from \"./virtual-module.js\";\n\ntype PluginState = {\n schemaDir: RetainedStagingDir;\n rootDir: string | null;\n dataDir: string | null;\n isV2ResourceImports: boolean;\n isBuild: boolean;\n schemaEnvTimer: ReturnType<typeof setTimeout> | null;\n trackedSchemas: Map<string, string>;\n buildSchemas: Set<string>;\n};\n\ntype PluginContext = AssetEmitter & {\n error: (message: string) => never;\n};\n\nconst VIRTUAL_PREFIX = \"\\0gtkx-settings:\";\nconst SCHEMA_STAGING_PREFIX = \"schemas\";\nconst SOURCE_MODULE_RE = /\\.[cm]?[jt]sx?$/;\nconst SCHEMA_ENV_DEBOUNCE_MS = 50;\nconst { isVirtual, fromVirtualId, resolveToVirtual } = createVirtualNamespace(VIRTUAL_PREFIX);\n\nconst SCHEMA_ENV_BANNER = [\n \"process.env.GSETTINGS_SCHEMA_DIR = [\",\n \" decodeURIComponent(new URL(\\\".\\\", import.meta.url).pathname),\",\n \" process.env.GSETTINGS_SCHEMA_DIR,\",\n \"]\",\n \" .filter(Boolean)\",\n \" .join(\\\":\\\");\",\n].join(\"\\n\");\n\nconst ensureSchemaDir = (state: PluginState): string => {\n const existing = state.schemaDir.getPath();\n\n if (existing !== null) {\n return existing;\n }\n\n const runnerDir = process.env.GTKX_DEV_SCHEMA_DIR;\n\n return runnerDir ? state.schemaDir.adopt(runnerDir) : state.schemaDir.retain();\n};\n\nconst compileSchemaDir = (state: PluginState): void => {\n const dir = state.schemaDir.getPath();\n\n if (dir === null) {\n return;\n }\n\n compileSchemas(dir);\n process.env.GSETTINGS_SCHEMA_DIR = prependSchemaDir(dir, process.env.GSETTINGS_SCHEMA_DIR);\n};\n\nconst syncSchemaEnv = (state: PluginState): void => {\n if (state.rootDir === null) {\n return;\n }\n\n try {\n emitSchemaEnv(state.rootDir, state.dataDir, state.isV2ResourceImports);\n } catch (error_) {\n error(`Failed to generate GSettings schema types: ${errorMessage(error_)}`);\n }\n};\n\nconst cancelSchemaEnvSync = (state: PluginState): void => {\n if (state.schemaEnvTimer === null) {\n return;\n }\n\n clearTimeout(state.schemaEnvTimer);\n state.schemaEnvTimer = null;\n};\n\nconst scheduleSchemaEnvSync = (state: PluginState): void => {\n cancelSchemaEnvSync(state);\n\n state.schemaEnvTimer = setTimeout(() => {\n state.schemaEnvTimer = null;\n syncSchemaEnv(state);\n }, SCHEMA_ENV_DEBOUNCE_MS);\n};\n\nconst applyUserConfig = async (state: PluginState, config: UserConfig, loadConfig: ConfigLoader): Promise<void> => {\n const loaded = await loadConfig.load(config.root ?? process.cwd());\n state.isV2ResourceImports = loaded.config.future?.v2ResourceImports === true;\n state.dataDir = state.isV2ResourceImports ? null : resolveDataDir(loaded.root);\n};\n\nconst applyResolvedConfig = (state: PluginState, config: ResolvedConfig): void => {\n state.isBuild = config.command === \"build\";\n state.rootDir = typeof config.root === \"string\" ? config.root : null;\n syncSchemaEnv(state);\n};\n\nconst registerSchemaForMode = (state: PluginState, filePath: string, id: string): void => {\n const fileName = basename(filePath);\n\n if (state.isBuild) {\n state.buildSchemas.add(filePath);\n info(`Queued GSettings schema: ${fileName}`);\n\n return;\n }\n\n state.trackedSchemas.set(filePath, id);\n const dir = ensureSchemaDir(state);\n stageSchema(dir, filePath);\n compileSchemaDir(state);\n info(`Compiled GSettings schema: ${fileName}`);\n};\n\nconst loadSchemaModule = (ctx: PluginContext, state: PluginState, id: string): string | undefined => {\n if (!isVirtual(id)) {\n return undefined;\n }\n\n const filePath = fromVirtualId(id);\n const xml = readFileSync(filePath, \"utf8\");\n const fileName = basename(filePath);\n registerSchemaForMode(state, filePath, id);\n let parsed: ReturnType<typeof parseSchemaXml>;\n\n try {\n parsed = parseSchemaXml(xml, fileName);\n } catch (error) {\n if (!(error instanceof SchemaParseError)) {\n throw error;\n }\n\n ctx.error(error.message);\n }\n\n if (parsed.schemas.length === 0) {\n ctx.error(`No <schema id=\"...\"> found in ${fileName}`);\n }\n\n return renderRuntimeModule(parsed);\n};\n\nconst compileBuildSchemas = (schemaFiles: string[]): Buffer =>\n withStagingDir(\"schemas-build\", (dir) => {\n for (const filePath of schemaFiles) {\n stageSchema(dir, filePath);\n }\n\n compileSchemas(dir);\n\n return readFileSync(join(dir, \"gschemas.compiled\"));\n });\n\nconst buildSchemaPaths = (rootDir: string, schemaFiles: string[]): string[] =>\n schemaFiles.map((filePath) => {\n const rel = projectRelativeSchemaPath(rootDir, filePath);\n\n if (rel === null) {\n throw new Error(`Cannot package the GSettings schema ${filePath}: it is outside ${rootDir}`);\n }\n\n return rel;\n });\n\nconst emitBuildSchemas = (\n ctx: PluginContext,\n state: PluginState,\n buildManifest: BuildManifestCollector | undefined,\n): void => {\n if (!state.isBuild || state.rootDir === null) {\n return;\n }\n\n const rootDir = state.rootDir;\n const schemaFiles = sortStrings(state.buildSchemas);\n assertUniqueSchemaBasenames(schemaFiles);\n const schemas = buildSchemaPaths(rootDir, schemaFiles);\n\n if (buildManifest !== undefined) {\n buildManifest.schemas = schemas;\n }\n\n if (schemaFiles.length === 0) {\n return;\n }\n\n const compiled = compileBuildSchemas(schemaFiles);\n\n ctx.emitFile({\n type: \"asset\",\n fileName: \"gschemas.compiled\",\n source: compiled,\n });\n\n info(`Compiled ${String(schemaFiles.length)} GSettings schema(s)`);\n};\n\nconst handleSchemaHotUpdate = (state: PluginState, file: string, server: ViteDevServer): ModuleNode[] | undefined => {\n if (file.endsWith(SCHEMA_SUFFIX) || SOURCE_MODULE_RE.test(file)) {\n scheduleSchemaEnvSync(state);\n }\n\n const virtualId = state.trackedSchemas.get(file);\n\n if (!virtualId) {\n return;\n }\n\n const dir = ensureSchemaDir(state);\n stageSchema(dir, file);\n compileSchemaDir(state);\n info(`Recompiled GSettings schema: ${basename(file)}`);\n const mod = server.moduleGraph.getModuleById(virtualId);\n\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n\n return [mod];\n }\n\n return undefined;\n};\n\nconst watchSchemaFiles = (state: PluginState, server: ViteDevServer): void => {\n const onClose = (): void => {\n cancelSchemaEnvSync(state);\n state.schemaDir.release();\n };\n\n server.httpServer?.once(\"close\", onClose);\n server.watcher.once(\"close\", onClose);\n\n const refreshSchemaTypes = (file: string): void => {\n if (file.endsWith(SCHEMA_SUFFIX) || SOURCE_MODULE_RE.test(file)) {\n scheduleSchemaEnvSync(state);\n }\n };\n\n server.watcher.on(\"add\", refreshSchemaTypes);\n server.watcher.on(\"unlink\", refreshSchemaTypes);\n};\n\nfunction gtkxSettings(loadConfig: ConfigLoader, buildManifest?: BuildManifestCollector): Plugin {\n const state: PluginState = {\n schemaDir: createRetainedStagingDir(SCHEMA_STAGING_PREFIX),\n rootDir: null,\n dataDir: null,\n isV2ResourceImports: false,\n isBuild: false,\n schemaEnvTimer: null,\n trackedSchemas: new Map(),\n buildSchemas: new Set(),\n };\n\n return {\n name: \"gtkx:settings\",\n enforce: \"pre\",\n\n async config(config: UserConfig) {\n await applyUserConfig(state, config, loadConfig);\n },\n\n configResolved(config) {\n applyResolvedConfig(state, config);\n },\n\n configureServer(server) {\n watchSchemaFiles(state, server);\n },\n\n outputOptions(options) {\n if (!state.isBuild) {\n return;\n }\n\n return prependBanner(options, SCHEMA_ENV_BANNER);\n },\n\n async resolveId(source, importer, options) {\n if (!source.endsWith(SCHEMA_SUFFIX)) {\n return;\n }\n\n return resolveToVirtual(this, { source, importer, options });\n },\n\n load(id) {\n return loadSchemaModule(this, state, id);\n },\n\n buildEnd() {\n emitBuildSchemas(this, state, buildManifest);\n },\n\n closeBundle() {\n cancelSchemaEnvSync(state);\n state.schemaDir.release();\n },\n\n handleHotUpdate({ file, server }) {\n return handleSchemaHotUpdate(state, file, server);\n },\n };\n}\n\nexport { gtkxSettings };\n"]}
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/vite-plugins/settings.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EA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AC;QAED,aAAa,CAAC,OAAO;YACjB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACjB,OAAO;YACX,CAAC;YAED,OAAO,aAAa,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QACrD,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO;YACrC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;gBAClC,OAAO;YACX,CAAC;YAED,OAAO,gBAAgB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,CAAC,EAAE;YACH,OAAO,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7C,CAAC;QAED,QAAQ;YACJ,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;QACjD,CAAC;QAED,WAAW;YACP,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAC3B,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QAED,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;YAC5B,OAAO,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import type { ConfigLoader } from \"@gtkx/config\";\nimport type { ModuleNode, Plugin, ResolvedConfig, UserConfig, ViteDevServer } from \"vite\";\nimport { resolveFuture } from \"@gtkx/config/internal\";\nimport { error, errorMessage, info, sortStrings } from \"@gtkx/utils\";\nimport { readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport type { BuildManifestCollector } from \"../internal/build-manifest.js\";\nimport type { AssetEmitter } from \"./asset-emitter.js\";\nimport { prependBanner } from \"../internal/banner.js\";\nimport { resolveDataDir } from \"../internal/data-dir.js\";\nimport { createRetainedStagingDir, type RetainedStagingDir, withStagingDir } from \"../internal/staging-dir.js\";\nimport { compileSchemas } from \"../settings/compile.js\";\nimport { parseSchemaXml, SchemaParseError } from \"../settings/parser.js\";\nimport { renderRuntimeModule } from \"../settings/render.js\";\nimport {\n assertUniqueSchemaBasenames,\n emitSchemaEnv,\n prependSchemaDir,\n projectRelativeSchemaPath,\n SCHEMA_SUFFIX,\n stageSchema,\n} from \"../settings/schema.js\";\nimport { createVirtualNamespace } from \"./virtual-module.js\";\n\ntype PluginState = {\n schemaDir: RetainedStagingDir;\n rootDir: string | null;\n dataDir: string | null;\n isV2ResourceImports: boolean;\n isBuild: boolean;\n schemaEnvTimer: ReturnType<typeof setTimeout> | null;\n trackedSchemas: Map<string, string>;\n buildSchemas: Set<string>;\n};\n\ntype PluginContext = AssetEmitter & {\n error: (message: string) => never;\n};\n\nconst VIRTUAL_PREFIX = \"\\0gtkx-settings:\";\nconst SCHEMA_STAGING_PREFIX = \"schemas\";\nconst SOURCE_MODULE_RE = /\\.[cm]?[jt]sx?$/;\nconst SCHEMA_ENV_DEBOUNCE_MS = 50;\nconst { isVirtual, fromVirtualId, resolveToVirtual } = createVirtualNamespace(VIRTUAL_PREFIX);\n\nconst SCHEMA_ENV_BANNER = [\n \"process.env.GSETTINGS_SCHEMA_DIR = [\",\n \" decodeURIComponent(new URL(\\\".\\\", import.meta.url).pathname),\",\n \" process.env.GSETTINGS_SCHEMA_DIR,\",\n \"]\",\n \" .filter(Boolean)\",\n \" .join(\\\":\\\");\",\n].join(\"\\n\");\n\nconst ensureSchemaDir = (state: PluginState): string => {\n const existing = state.schemaDir.getPath();\n\n if (existing !== null) {\n return existing;\n }\n\n const runnerDir = process.env.GTKX_DEV_SCHEMA_DIR;\n\n return runnerDir ? state.schemaDir.adopt(runnerDir) : state.schemaDir.retain();\n};\n\nconst compileSchemaDir = (state: PluginState): void => {\n const dir = state.schemaDir.getPath();\n\n if (dir === null) {\n return;\n }\n\n compileSchemas(dir);\n process.env.GSETTINGS_SCHEMA_DIR = prependSchemaDir(dir, process.env.GSETTINGS_SCHEMA_DIR);\n};\n\nconst syncSchemaEnv = (state: PluginState): void => {\n if (state.rootDir === null) {\n return;\n }\n\n try {\n emitSchemaEnv(state.rootDir, state.dataDir, state.isV2ResourceImports);\n } catch (error_) {\n error(`Failed to generate GSettings schema types: ${errorMessage(error_)}`);\n }\n};\n\nconst cancelSchemaEnvSync = (state: PluginState): void => {\n if (state.schemaEnvTimer === null) {\n return;\n }\n\n clearTimeout(state.schemaEnvTimer);\n state.schemaEnvTimer = null;\n};\n\nconst scheduleSchemaEnvSync = (state: PluginState): void => {\n cancelSchemaEnvSync(state);\n\n state.schemaEnvTimer = setTimeout(() => {\n state.schemaEnvTimer = null;\n syncSchemaEnv(state);\n }, SCHEMA_ENV_DEBOUNCE_MS);\n};\n\nconst applyUserConfig = async (state: PluginState, config: UserConfig, loadConfig: ConfigLoader): Promise<void> => {\n const loaded = await loadConfig.load(config.root ?? process.cwd());\n state.isV2ResourceImports = resolveFuture(loaded.config.future).isResourceImported;\n state.dataDir = state.isV2ResourceImports ? null : resolveDataDir(loaded.root);\n};\n\nconst applyResolvedConfig = (state: PluginState, config: ResolvedConfig): void => {\n state.isBuild = config.command === \"build\";\n state.rootDir = typeof config.root === \"string\" ? config.root : null;\n syncSchemaEnv(state);\n};\n\nconst registerSchemaForMode = (state: PluginState, filePath: string, id: string): void => {\n const fileName = basename(filePath);\n\n if (state.isBuild) {\n state.buildSchemas.add(filePath);\n info(`Queued GSettings schema: ${fileName}`);\n\n return;\n }\n\n state.trackedSchemas.set(filePath, id);\n const dir = ensureSchemaDir(state);\n stageSchema(dir, filePath);\n compileSchemaDir(state);\n info(`Compiled GSettings schema: ${fileName}`);\n};\n\nconst loadSchemaModule = (ctx: PluginContext, state: PluginState, id: string): string | undefined => {\n if (!isVirtual(id)) {\n return undefined;\n }\n\n const filePath = fromVirtualId(id);\n const xml = readFileSync(filePath, \"utf8\");\n const fileName = basename(filePath);\n registerSchemaForMode(state, filePath, id);\n let parsed: ReturnType<typeof parseSchemaXml>;\n\n try {\n parsed = parseSchemaXml(xml, fileName);\n } catch (error) {\n if (!(error instanceof SchemaParseError)) {\n throw error;\n }\n\n ctx.error(error.message);\n }\n\n if (parsed.schemas.length === 0) {\n ctx.error(`No <schema id=\"...\"> found in ${fileName}`);\n }\n\n return renderRuntimeModule(parsed);\n};\n\nconst compileBuildSchemas = (schemaFiles: string[]): Buffer =>\n withStagingDir(\"schemas-build\", (dir) => {\n for (const filePath of schemaFiles) {\n stageSchema(dir, filePath);\n }\n\n compileSchemas(dir);\n\n return readFileSync(join(dir, \"gschemas.compiled\"));\n });\n\nconst buildSchemaPaths = (rootDir: string, schemaFiles: string[]): string[] =>\n schemaFiles.map((filePath) => {\n const rel = projectRelativeSchemaPath(rootDir, filePath);\n\n if (rel === null) {\n throw new Error(`Cannot package the GSettings schema ${filePath}: it is outside ${rootDir}`);\n }\n\n return rel;\n });\n\nconst emitBuildSchemas = (\n ctx: PluginContext,\n state: PluginState,\n buildManifest: BuildManifestCollector | undefined,\n): void => {\n if (!state.isBuild || state.rootDir === null) {\n return;\n }\n\n const rootDir = state.rootDir;\n const schemaFiles = sortStrings(state.buildSchemas);\n assertUniqueSchemaBasenames(schemaFiles);\n const schemas = buildSchemaPaths(rootDir, schemaFiles);\n\n if (buildManifest !== undefined) {\n buildManifest.schemas = schemas;\n }\n\n if (schemaFiles.length === 0) {\n return;\n }\n\n const compiled = compileBuildSchemas(schemaFiles);\n\n ctx.emitFile({\n type: \"asset\",\n fileName: \"gschemas.compiled\",\n source: compiled,\n });\n\n info(`Compiled ${String(schemaFiles.length)} GSettings schema(s)`);\n};\n\nconst handleSchemaHotUpdate = (state: PluginState, file: string, server: ViteDevServer): ModuleNode[] | undefined => {\n if (file.endsWith(SCHEMA_SUFFIX) || SOURCE_MODULE_RE.test(file)) {\n scheduleSchemaEnvSync(state);\n }\n\n const virtualId = state.trackedSchemas.get(file);\n\n if (!virtualId) {\n return;\n }\n\n const dir = ensureSchemaDir(state);\n stageSchema(dir, file);\n compileSchemaDir(state);\n info(`Recompiled GSettings schema: ${basename(file)}`);\n const mod = server.moduleGraph.getModuleById(virtualId);\n\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n\n return [mod];\n }\n\n return undefined;\n};\n\nconst watchSchemaFiles = (state: PluginState, server: ViteDevServer): void => {\n const onClose = (): void => {\n cancelSchemaEnvSync(state);\n state.schemaDir.release();\n };\n\n server.httpServer?.once(\"close\", onClose);\n server.watcher.once(\"close\", onClose);\n\n const refreshSchemaTypes = (file: string): void => {\n if (file.endsWith(SCHEMA_SUFFIX) || SOURCE_MODULE_RE.test(file)) {\n scheduleSchemaEnvSync(state);\n }\n };\n\n server.watcher.on(\"add\", refreshSchemaTypes);\n server.watcher.on(\"unlink\", refreshSchemaTypes);\n};\n\nfunction gtkxSettings(loadConfig: ConfigLoader, buildManifest?: BuildManifestCollector): Plugin {\n const state: PluginState = {\n schemaDir: createRetainedStagingDir(SCHEMA_STAGING_PREFIX),\n rootDir: null,\n dataDir: null,\n isV2ResourceImports: false,\n isBuild: false,\n schemaEnvTimer: null,\n trackedSchemas: new Map(),\n buildSchemas: new Set(),\n };\n\n return {\n name: \"gtkx:settings\",\n enforce: \"pre\",\n\n async config(config: UserConfig) {\n await applyUserConfig(state, config, loadConfig);\n },\n\n configResolved(config) {\n applyResolvedConfig(state, config);\n },\n\n configureServer(server) {\n watchSchemaFiles(state, server);\n },\n\n outputOptions(options) {\n if (!state.isBuild) {\n return;\n }\n\n return prependBanner(options, SCHEMA_ENV_BANNER);\n },\n\n async resolveId(source, importer, options) {\n if (!source.endsWith(SCHEMA_SUFFIX)) {\n return;\n }\n\n return resolveToVirtual(this, { source, importer, options });\n },\n\n load(id) {\n return loadSchemaModule(this, state, id);\n },\n\n buildEnd() {\n emitBuildSchemas(this, state, buildManifest);\n },\n\n closeBundle() {\n cancelSchemaEnvSync(state);\n state.schemaDir.release();\n },\n\n handleHotUpdate({ file, server }) {\n return handleSchemaHotUpdate(state, file, server);\n },\n };\n}\n\nexport { gtkxSettings };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/cli",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "GTK app toolchain for React: scaffold, dev server, build, docs.",
5
5
  "keywords": [
6
6
  "gtkx",
@@ -70,22 +70,24 @@
70
70
  "babel-plugin-react-compiler": "^1.0.0",
71
71
  "citty": "^0.2.2",
72
72
  "fast-xml-parser": "^5.11.0",
73
+ "i18next-cli": "1.71.3",
73
74
  "react-refresh": "^0.18.0",
74
75
  "vite": "^8.2.2",
75
76
  "yaml": "^2.9.0",
76
- "@gtkx/codegen": "1.4.0",
77
- "@gtkx/config": "1.4.0",
78
- "@gtkx/mcp": "1.4.0",
79
- "@gtkx/utils": "1.4.0",
80
- "@gtkx/runtime": "1.4.0",
81
- "@gtkx/vitest": "1.4.0",
82
- "create-gtkx": "1.4.0"
77
+ "@gtkx/codegen": "1.6.0",
78
+ "@gtkx/config": "1.6.0",
79
+ "@gtkx/runtime": "1.6.0",
80
+ "@gtkx/mcp": "1.6.0",
81
+ "@gtkx/utils": "1.6.0",
82
+ "create-gtkx": "1.6.0",
83
+ "@gtkx/vitest": "1.6.0"
83
84
  },
84
85
  "devDependencies": {
85
86
  "@types/babel__core": "^7.20.5",
86
87
  "@types/react-refresh": "^0.14.7",
87
88
  "vitest": "^4.1.11",
88
- "@gtkx/testing": "1.4.0"
89
+ "@gtkx/animated": "1.6.0",
90
+ "@gtkx/testing": "1.6.0"
89
91
  },
90
92
  "peerDependencies": {
91
93
  "react": "^19"