@gtkx/codegen 1.0.0 → 1.1.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 (316) hide show
  1. package/README.md +1 -1
  2. package/dist/analysis/descriptor-render.d.ts +12 -15
  3. package/dist/analysis/descriptor-render.d.ts.map +1 -1
  4. package/dist/analysis/descriptor-render.js +48 -31
  5. package/dist/analysis/descriptor-render.js.map +1 -1
  6. package/dist/analysis/descriptor.d.ts +16 -7
  7. package/dist/analysis/descriptor.d.ts.map +1 -1
  8. package/dist/analysis/descriptor.js +15 -3
  9. package/dist/analysis/descriptor.js.map +1 -1
  10. package/dist/analysis/inheritance.d.ts +4 -2
  11. package/dist/analysis/inheritance.d.ts.map +1 -1
  12. package/dist/analysis/inheritance.js +80 -38
  13. package/dist/analysis/inheritance.js.map +1 -1
  14. package/dist/analysis/interface-conflicts.d.ts +23 -0
  15. package/dist/analysis/interface-conflicts.d.ts.map +1 -0
  16. package/dist/analysis/interface-conflicts.js +144 -0
  17. package/dist/analysis/interface-conflicts.js.map +1 -0
  18. package/dist/analysis/param-capability.d.ts.map +1 -1
  19. package/dist/analysis/param-capability.js +3 -4
  20. package/dist/analysis/param-capability.js.map +1 -1
  21. package/dist/analysis/param-structure.js +2 -2
  22. package/dist/analysis/param-structure.js.map +1 -1
  23. package/dist/analysis/ts-type.d.ts.map +1 -1
  24. package/dist/analysis/ts-type.js +10 -17
  25. package/dist/analysis/ts-type.js.map +1 -1
  26. package/dist/analysis/type-key.d.ts +5 -0
  27. package/dist/analysis/type-key.d.ts.map +1 -0
  28. package/dist/analysis/type-key.js +9 -0
  29. package/dist/analysis/type-key.js.map +1 -0
  30. package/dist/compile.d.ts +12 -3
  31. package/dist/compile.d.ts.map +1 -1
  32. package/dist/compile.js +73 -24
  33. package/dist/compile.js.map +1 -1
  34. package/dist/docs/api-reference.d.ts.map +1 -1
  35. package/dist/docs/api-reference.js +10 -9
  36. package/dist/docs/api-reference.js.map +1 -1
  37. package/dist/docs/element-page.d.ts.map +1 -1
  38. package/dist/docs/element-page.js +5 -3
  39. package/dist/docs/element-page.js.map +1 -1
  40. package/dist/docs/pipeline.d.ts.map +1 -1
  41. package/dist/docs/pipeline.js +85 -18
  42. package/dist/docs/pipeline.js.map +1 -1
  43. package/dist/docs/render.d.ts +2 -1
  44. package/dist/docs/render.d.ts.map +1 -1
  45. package/dist/docs/render.js +5 -4
  46. package/dist/docs/render.js.map +1 -1
  47. package/dist/docs/symbol-page.d.ts.map +1 -1
  48. package/dist/docs/symbol-page.js +9 -6
  49. package/dist/docs/symbol-page.js.map +1 -1
  50. package/dist/fingerprint.d.ts +12 -1
  51. package/dist/fingerprint.d.ts.map +1 -1
  52. package/dist/fingerprint.js +44 -28
  53. package/dist/fingerprint.js.map +1 -1
  54. package/dist/gi.d.ts.map +1 -1
  55. package/dist/gi.js +1 -0
  56. package/dist/gi.js.map +1 -1
  57. package/dist/gir/ancestry.d.ts +7 -1
  58. package/dist/gir/ancestry.d.ts.map +1 -1
  59. package/dist/gir/ancestry.js +9 -1
  60. package/dist/gir/ancestry.js.map +1 -1
  61. package/dist/gir/annotations.d.ts +1 -2
  62. package/dist/gir/annotations.d.ts.map +1 -1
  63. package/dist/gir/annotations.js +1 -1
  64. package/dist/gir/annotations.js.map +1 -1
  65. package/dist/gir/cursor-overrides.d.ts +8 -0
  66. package/dist/gir/cursor-overrides.d.ts.map +1 -0
  67. package/dist/gir/cursor-overrides.js +6 -0
  68. package/dist/gir/cursor-overrides.js.map +1 -0
  69. package/dist/gir/emittable.d.ts +7 -0
  70. package/dist/gir/emittable.d.ts.map +1 -0
  71. package/dist/gir/emittable.js +3 -0
  72. package/dist/gir/emittable.js.map +1 -0
  73. package/dist/gir/function.d.ts.map +1 -1
  74. package/dist/gir/function.js +28 -2
  75. package/dist/gir/function.js.map +1 -1
  76. package/dist/gir/library.js +1 -1
  77. package/dist/gir/library.js.map +1 -1
  78. package/dist/gir/namespace.d.ts +5 -1
  79. package/dist/gir/namespace.d.ts.map +1 -1
  80. package/dist/gir/namespace.js +4 -2
  81. package/dist/gir/namespace.js.map +1 -1
  82. package/dist/gir/parameter.d.ts +13 -1
  83. package/dist/gir/parameter.d.ts.map +1 -1
  84. package/dist/gir/parameter.js +1 -0
  85. package/dist/gir/parameter.js.map +1 -1
  86. package/dist/gir/parse.d.ts.map +1 -1
  87. package/dist/gir/parse.js +3 -6
  88. package/dist/gir/parse.js.map +1 -1
  89. package/dist/guards.d.ts +16 -0
  90. package/dist/guards.d.ts.map +1 -0
  91. package/dist/guards.js +11 -0
  92. package/dist/guards.js.map +1 -0
  93. package/dist/internal.d.ts +2 -0
  94. package/dist/internal.d.ts.map +1 -1
  95. package/dist/internal.js +2 -0
  96. package/dist/internal.js.map +1 -1
  97. package/dist/json.d.ts +3 -0
  98. package/dist/json.d.ts.map +1 -0
  99. package/dist/json.js +11 -0
  100. package/dist/json.js.map +1 -0
  101. package/dist/khronos/modules.d.ts.map +1 -1
  102. package/dist/khronos/modules.js +22 -7
  103. package/dist/khronos/modules.js.map +1 -1
  104. package/dist/khronos/parse.d.ts.map +1 -1
  105. package/dist/khronos/parse.js +3 -4
  106. package/dist/khronos/parse.js.map +1 -1
  107. package/dist/khronos/pipeline.d.ts +1 -1
  108. package/dist/khronos/pipeline.d.ts.map +1 -1
  109. package/dist/khronos/pipeline.js.map +1 -1
  110. package/dist/khronos/plan.d.ts +1 -7
  111. package/dist/khronos/plan.d.ts.map +1 -1
  112. package/dist/khronos/plan.js +1 -1
  113. package/dist/khronos/plan.js.map +1 -1
  114. package/dist/runner.d.ts +5 -1
  115. package/dist/runner.d.ts.map +1 -1
  116. package/dist/runner.js +16 -0
  117. package/dist/runner.js.map +1 -1
  118. package/dist/staging.d.ts +5 -0
  119. package/dist/staging.d.ts.map +1 -0
  120. package/dist/staging.js +57 -0
  121. package/dist/staging.js.map +1 -0
  122. package/dist/store/compile-store.d.ts.map +1 -1
  123. package/dist/store/compile-store.js +4 -2
  124. package/dist/store/compile-store.js.map +1 -1
  125. package/dist/store/gi/callables.d.ts +7 -2
  126. package/dist/store/gi/callables.d.ts.map +1 -1
  127. package/dist/store/gi/callables.js +25 -30
  128. package/dist/store/gi/callables.js.map +1 -1
  129. package/dist/store/gi/callback.d.ts.map +1 -1
  130. package/dist/store/gi/callback.js +9 -5
  131. package/dist/store/gi/callback.js.map +1 -1
  132. package/dist/store/gi/class.d.ts.map +1 -1
  133. package/dist/store/gi/class.js +59 -38
  134. package/dist/store/gi/class.js.map +1 -1
  135. package/dist/store/gi/companion.d.ts.map +1 -1
  136. package/dist/store/gi/companion.js +6 -6
  137. package/dist/store/gi/companion.js.map +1 -1
  138. package/dist/store/gi/constant.d.ts.map +1 -1
  139. package/dist/store/gi/constant.js +10 -2
  140. package/dist/store/gi/constant.js.map +1 -1
  141. package/dist/store/gi/constructor-props.js +1 -1
  142. package/dist/store/gi/constructor-props.js.map +1 -1
  143. package/dist/store/gi/enum.d.ts.map +1 -1
  144. package/dist/store/gi/enum.js +28 -8
  145. package/dist/store/gi/enum.js.map +1 -1
  146. package/dist/store/gi/function.d.ts +1 -3
  147. package/dist/store/gi/function.d.ts.map +1 -1
  148. package/dist/store/gi/function.js +24 -18
  149. package/dist/store/gi/function.js.map +1 -1
  150. package/dist/store/gi/gtype-binding.d.ts.map +1 -1
  151. package/dist/store/gi/gtype-binding.js +4 -1
  152. package/dist/store/gi/gtype-binding.js.map +1 -1
  153. package/dist/store/gi/interface.d.ts.map +1 -1
  154. package/dist/store/gi/interface.js +32 -17
  155. package/dist/store/gi/interface.js.map +1 -1
  156. package/dist/store/gi/method.d.ts +7 -6
  157. package/dist/store/gi/method.d.ts.map +1 -1
  158. package/dist/store/gi/method.js +13 -21
  159. package/dist/store/gi/method.js.map +1 -1
  160. package/dist/store/gi/param-marshal.d.ts +3 -2
  161. package/dist/store/gi/param-marshal.d.ts.map +1 -1
  162. package/dist/store/gi/param-marshal.js +50 -5
  163. package/dist/store/gi/param-marshal.js.map +1 -1
  164. package/dist/store/gi/pipeline.d.ts.map +1 -1
  165. package/dist/store/gi/pipeline.js +21 -10
  166. package/dist/store/gi/pipeline.js.map +1 -1
  167. package/dist/store/gi/properties.d.ts +2 -1
  168. package/dist/store/gi/properties.d.ts.map +1 -1
  169. package/dist/store/gi/properties.js +6 -3
  170. package/dist/store/gi/properties.js.map +1 -1
  171. package/dist/store/gi/property-accessor.d.ts +10 -5
  172. package/dist/store/gi/property-accessor.d.ts.map +1 -1
  173. package/dist/store/gi/property-accessor.js +95 -44
  174. package/dist/store/gi/property-accessor.js.map +1 -1
  175. package/dist/store/gi/record-constructor.d.ts +8 -1
  176. package/dist/store/gi/record-constructor.d.ts.map +1 -1
  177. package/dist/store/gi/record-constructor.js +31 -10
  178. package/dist/store/gi/record-constructor.js.map +1 -1
  179. package/dist/store/gi/record-field-accessor.d.ts.map +1 -1
  180. package/dist/store/gi/record-field-accessor.js +5 -1
  181. package/dist/store/gi/record-field-accessor.js.map +1 -1
  182. package/dist/store/gi/record-layout.d.ts +6 -1
  183. package/dist/store/gi/record-layout.d.ts.map +1 -1
  184. package/dist/store/gi/record-layout.js +8 -1
  185. package/dist/store/gi/record-layout.js.map +1 -1
  186. package/dist/store/gi/record.d.ts.map +1 -1
  187. package/dist/store/gi/record.js +19 -8
  188. package/dist/store/gi/record.js.map +1 -1
  189. package/dist/store/gi/registration.js +2 -2
  190. package/dist/store/gi/registration.js.map +1 -1
  191. package/dist/store/gi/signal.d.ts +2 -1
  192. package/dist/store/gi/signal.d.ts.map +1 -1
  193. package/dist/store/gi/signal.js +30 -24
  194. package/dist/store/gi/signal.js.map +1 -1
  195. package/dist/store/gi/value-marshalable.d.ts.map +1 -1
  196. package/dist/store/gi/value-marshalable.js +2 -1
  197. package/dist/store/gi/value-marshalable.js.map +1 -1
  198. package/dist/store/gi/vtable.d.ts +4 -1
  199. package/dist/store/gi/vtable.d.ts.map +1 -1
  200. package/dist/store/gi/vtable.js +60 -17
  201. package/dist/store/gi/vtable.js.map +1 -1
  202. package/dist/store/gi-store.d.ts +1 -0
  203. package/dist/store/gi-store.d.ts.map +1 -1
  204. package/dist/store/gi-store.js +15 -20
  205. package/dist/store/gi-store.js.map +1 -1
  206. package/dist/store/jsx/generated-elements.d.ts +2 -1
  207. package/dist/store/jsx/generated-elements.d.ts.map +1 -1
  208. package/dist/store/jsx/generated-elements.js +13 -7
  209. package/dist/store/jsx/generated-elements.js.map +1 -1
  210. package/dist/store/jsx/jsx.js +3 -3
  211. package/dist/store/jsx/jsx.js.map +1 -1
  212. package/dist/store/jsx/metadata.d.ts.map +1 -1
  213. package/dist/store/jsx/metadata.js +3 -1
  214. package/dist/store/jsx/metadata.js.map +1 -1
  215. package/dist/store/jsx-store.d.ts.map +1 -1
  216. package/dist/store/jsx-store.js +3 -3
  217. package/dist/store/jsx-store.js.map +1 -1
  218. package/dist/store/resolve-store.d.ts +14 -3
  219. package/dist/store/resolve-store.d.ts.map +1 -1
  220. package/dist/store/resolve-store.js +98 -15
  221. package/dist/store/resolve-store.js.map +1 -1
  222. package/dist/store/store-fs.d.ts +9 -6
  223. package/dist/store/store-fs.d.ts.map +1 -1
  224. package/dist/store/store-fs.js +59 -25
  225. package/dist/store/store-fs.js.map +1 -1
  226. package/dist/store/store-links.d.ts +3 -0
  227. package/dist/store/store-links.d.ts.map +1 -0
  228. package/dist/store/store-links.js +39 -0
  229. package/dist/store/store-links.js.map +1 -0
  230. package/dist/writer/comparison-context.d.ts +4 -0
  231. package/dist/writer/comparison-context.d.ts.map +1 -0
  232. package/dist/writer/comparison-context.js +13 -0
  233. package/dist/writer/comparison-context.js.map +1 -0
  234. package/dist/writer/context.d.ts +3 -3
  235. package/dist/writer/context.d.ts.map +1 -1
  236. package/dist/writer/context.js +11 -6
  237. package/dist/writer/context.js.map +1 -1
  238. package/dist/writer/module.d.ts +13 -5
  239. package/dist/writer/module.d.ts.map +1 -1
  240. package/dist/writer/module.js +68 -11
  241. package/dist/writer/module.js.map +1 -1
  242. package/dist/xml.d.ts +7 -1
  243. package/dist/xml.d.ts.map +1 -1
  244. package/dist/xml.js +43 -1
  245. package/dist/xml.js.map +1 -1
  246. package/package.json +14 -3
  247. package/src/analysis/descriptor-render.ts +90 -45
  248. package/src/analysis/descriptor.ts +35 -8
  249. package/src/analysis/inheritance.ts +134 -44
  250. package/src/analysis/interface-conflicts.ts +237 -0
  251. package/src/analysis/param-capability.ts +3 -6
  252. package/src/analysis/param-structure.ts +2 -2
  253. package/src/analysis/ts-type.ts +13 -17
  254. package/src/analysis/type-key.ts +14 -0
  255. package/src/compile.ts +110 -26
  256. package/src/docs/api-reference.ts +10 -9
  257. package/src/docs/element-page.ts +5 -2
  258. package/src/docs/pipeline.ts +129 -19
  259. package/src/docs/render.ts +7 -3
  260. package/src/docs/symbol-page.ts +12 -7
  261. package/src/fingerprint.ts +86 -31
  262. package/src/gi.ts +1 -0
  263. package/src/gir/ancestry.ts +17 -1
  264. package/src/gir/annotations.ts +1 -1
  265. package/src/gir/cursor-overrides.ts +12 -0
  266. package/src/gir/emittable.ts +8 -0
  267. package/src/gir/function.ts +45 -9
  268. package/src/gir/library.ts +1 -1
  269. package/src/gir/namespace.ts +8 -2
  270. package/src/gir/parameter.ts +15 -0
  271. package/src/gir/parse.ts +5 -7
  272. package/src/guards.ts +23 -0
  273. package/src/internal.ts +2 -0
  274. package/src/json.ts +11 -0
  275. package/src/khronos/modules.ts +25 -9
  276. package/src/khronos/parse.ts +3 -4
  277. package/src/khronos/pipeline.ts +1 -1
  278. package/src/khronos/plan.ts +0 -1
  279. package/src/runner.ts +19 -1
  280. package/src/staging.ts +69 -0
  281. package/src/store/compile-store.ts +6 -4
  282. package/src/store/gi/callables.ts +41 -33
  283. package/src/store/gi/callback.ts +9 -9
  284. package/src/store/gi/class.ts +79 -48
  285. package/src/store/gi/companion.ts +7 -6
  286. package/src/store/gi/constant.ts +12 -2
  287. package/src/store/gi/constructor-props.ts +1 -1
  288. package/src/store/gi/enum.ts +35 -21
  289. package/src/store/gi/function.ts +30 -24
  290. package/src/store/gi/gtype-binding.ts +7 -2
  291. package/src/store/gi/interface.ts +37 -18
  292. package/src/store/gi/method.ts +28 -29
  293. package/src/store/gi/param-marshal.ts +77 -6
  294. package/src/store/gi/pipeline.ts +25 -15
  295. package/src/store/gi/properties.ts +8 -4
  296. package/src/store/gi/property-accessor.ts +156 -73
  297. package/src/store/gi/record-constructor.ts +50 -18
  298. package/src/store/gi/record-field-accessor.ts +8 -1
  299. package/src/store/gi/record-layout.ts +11 -1
  300. package/src/store/gi/record.ts +20 -12
  301. package/src/store/gi/registration.ts +2 -2
  302. package/src/store/gi/signal.ts +36 -38
  303. package/src/store/gi/value-marshalable.ts +3 -1
  304. package/src/store/gi/vtable.ts +97 -20
  305. package/src/store/gi-store.ts +26 -31
  306. package/src/store/jsx/generated-elements.ts +17 -8
  307. package/src/store/jsx/jsx.ts +3 -3
  308. package/src/store/jsx/metadata.ts +4 -1
  309. package/src/store/jsx-store.ts +3 -3
  310. package/src/store/resolve-store.ts +133 -18
  311. package/src/store/store-fs.ts +87 -34
  312. package/src/store/store-links.ts +49 -0
  313. package/src/writer/comparison-context.ts +18 -0
  314. package/src/writer/context.ts +12 -6
  315. package/src/writer/module.ts +101 -14
  316. package/src/xml.ts +61 -1
@@ -1,17 +1,26 @@
1
1
  import { existsSync, readFileSync, realpathSync } from "node:fs";
2
- import { dirname, join, parse } from "node:path";
2
+ import { dirname, join, parse, relative, sep } from "node:path";
3
+ import { sweepStagingDirs } from "../staging.js";
3
4
  const STORE_DIR = ".gtkx";
4
5
  const SCOPE = "@gtkx";
6
+ const STORE_NAMES = ["gi", "jsx"];
7
+ const STORE_CONSUMERS = [
8
+ "@gtkx/cli",
9
+ "@gtkx/components",
10
+ "@gtkx/css",
11
+ "@gtkx/react",
12
+ "@gtkx/testing",
13
+ ];
5
14
  const readManifest = (path) => JSON.parse(readFileSync(path, "utf8"));
6
15
  const subexportNames = (packageDir) => Object.keys(readManifest(join(packageDir, "package.json")).exports ?? {})
7
16
  .filter((key) => key.startsWith("./") && key !== "./package.json")
8
17
  .map((key) => key.slice(2));
9
- const loadPackage = (manifest) => {
18
+ const loadPackage = (manifest, nodeModules) => {
10
19
  if (!existsSync(manifest)) {
11
20
  return null;
12
21
  }
13
22
  const real = realpathSync(manifest);
14
- return { dir: dirname(real), version: readManifest(real).version ?? "0.0.0" };
23
+ return { dir: dirname(real), nodeModules, version: readManifest(real).version ?? "0.0.0" };
15
24
  };
16
25
  const nodeModulesChain = function* (projectRoot) {
17
26
  const { root } = parse(projectRoot);
@@ -24,42 +33,116 @@ const nodeModulesChain = function* (projectRoot) {
24
33
  };
25
34
  const resolvePackage = (projectRoot, packageName) => {
26
35
  for (const nodeModules of nodeModulesChain(projectRoot)) {
27
- const found = loadPackage(join(nodeModules, packageName, "package.json"));
36
+ const found = loadPackage(join(nodeModules, packageName, "package.json"), nodeModules);
28
37
  if (found !== null) {
29
38
  return found;
30
39
  }
31
40
  }
32
- return loadPackage(join(projectRoot, "packages", packageName.replace(/^@[^/]+\//, ""), "package.json"));
41
+ const unscoped = packageName.replace(/^@[^/]+\//, "");
42
+ return loadPackage(join(projectRoot, "packages", unscoped, "package.json"), join(projectRoot, "node_modules"));
33
43
  };
44
+ const isWithin = (parent, child) => {
45
+ const path = relative(parent, child);
46
+ return path === "" || (path !== ".." && !path.startsWith(`..${sep}`));
47
+ };
48
+ const canImport = (fromNodeModules, targetNodeModules) => isWithin(dirname(targetNodeModules), dirname(fromNodeModules));
34
49
  const storeOptions = (nodeModules, name, version) => ({
35
50
  storeDir: join(nodeModules, STORE_DIR, name),
36
51
  linkDir: join(nodeModules, SCOPE, name),
37
52
  version,
38
53
  });
54
+ const resolveRuntime = (projectRoot) => {
55
+ const runtime = resolvePackage(projectRoot, "@gtkx/runtime");
56
+ if (runtime === null) {
57
+ throw new Error(`Cannot resolve @gtkx/runtime from ${projectRoot}; is it installed?`);
58
+ }
59
+ return runtime;
60
+ };
61
+ const storeNodeModules = (runtime, react) => {
62
+ if (react !== null && canImport(react.nodeModules, runtime.nodeModules)) {
63
+ return react.nodeModules;
64
+ }
65
+ return runtime.nodeModules;
66
+ };
67
+ const findUnreachableConsumer = (projectRoot, nodeModules) => {
68
+ for (const name of STORE_CONSUMERS) {
69
+ const consumer = resolvePackage(projectRoot, name);
70
+ if (consumer !== null && !canImport(consumer.nodeModules, nodeModules)) {
71
+ return { name, nodeModules: consumer.nodeModules };
72
+ }
73
+ }
74
+ return null;
75
+ };
76
+ const unreachableConsumerMessage = (consumer, nodeModules) => `Cannot write the generated store to ${nodeModules}: ${consumer.name} is installed in ` +
77
+ `${consumer.nodeModules}, above it, so that copy can never import the generated @gtkx/gi. Install every ` +
78
+ "@gtkx package in one node_modules, then run gtkx codegen again.";
79
+ const checkConsumers = (projectRoot, nodeModules) => {
80
+ const consumer = findUnreachableConsumer(projectRoot, nodeModules);
81
+ if (consumer !== null) {
82
+ throw new Error(unreachableConsumerMessage(consumer, nodeModules));
83
+ }
84
+ };
85
+ const jsxOptions = (react, nodeModules) => react === null ? null : storeOptions(nodeModules, "jsx", react.version);
86
+ const getReactSubexports = (react) => react === null ? [] : subexportNames(react.dir);
87
+ const storePaths = (nodeModules) => STORE_NAMES.flatMap((name) => [join(nodeModules, STORE_DIR, name), join(nodeModules, SCOPE, name)]);
88
+ const findStoreNodeModules = (projectRoot) => {
89
+ const runtime = resolvePackage(projectRoot, "@gtkx/runtime");
90
+ if (runtime === null) {
91
+ return null;
92
+ }
93
+ return storeNodeModules(runtime, resolvePackage(projectRoot, "@gtkx/react"));
94
+ };
95
+ const getShadowingStorePaths = (projectRoot) => {
96
+ const nodeModules = join(projectRoot, "node_modules");
97
+ const anchored = findStoreNodeModules(projectRoot);
98
+ if (anchored === null || anchored === nodeModules) {
99
+ return [];
100
+ }
101
+ return storePaths(nodeModules);
102
+ };
103
+ const stagingRoots = (projectRoot) => {
104
+ const nodeModules = join(projectRoot, "node_modules");
105
+ const anchored = findStoreNodeModules(projectRoot);
106
+ return anchored === null || anchored === nodeModules ? [nodeModules] : [nodeModules, anchored];
107
+ };
108
+ const sweepProjectStaging = (projectRoot) => {
109
+ for (const nodeModules of stagingRoots(projectRoot)) {
110
+ for (const name of STORE_NAMES) {
111
+ sweepStagingDirs(join(nodeModules, STORE_DIR, name));
112
+ }
113
+ }
114
+ };
39
115
  /**
40
116
  * Resolves where a project's `@gtkx/gi` and `@gtkx/jsx` stores belong, from the project root alone. The
41
117
  * result supplies every `runCodegen` input except `libraries` and `girPath`, so a caller that has
42
118
  * already resolved those can spread it straight into the call.
43
119
  *
120
+ * Both stores go in one `node_modules`, found by walking the project's `node_modules` chain upwards:
121
+ * the one `@gtkx/react` resolves from, or `@gtkx/runtime`'s when no React is installed. That is the
122
+ * project's own directory when it installs those packages itself, and the workspace root when npm or
123
+ * yarn hoisted them there. Keeping the pair together is what lets the jsx store import the gi store, and
124
+ * anchoring them where the `@gtkx` packages sit is what lets `@gtkx/react`, the CLI, and the project's
125
+ * sources all reach the bindings. A package manager that hoists therefore gives every project sharing
126
+ * that `node_modules` one shared store.
127
+ *
44
128
  * Store versions come from the installed `@gtkx/runtime` and `@gtkx/react`, so a dependency upgrade
45
129
  * invalidates the stores. Pass explicit `gi` or `jsx` options to `runCodegen` to override any of it.
46
130
  *
47
- * @param projectRoot Directory holding the project's `package.json` and `node_modules`.
131
+ * @param projectRoot Directory holding the project's `package.json`, whose `node_modules` chain is walked.
48
132
  * @returns The store locations and the React subexports that shape the jsx store.
49
- * @throws If `@gtkx/runtime` cannot be resolved from the project.
133
+ * @throws If `@gtkx/runtime` cannot be resolved from the project, or a `@gtkx` package that imports the
134
+ * bindings is installed above the `node_modules` the stores would go in, since it could not reach them.
50
135
  */
51
136
  const resolveStore = (projectRoot) => {
52
- const runtime = resolvePackage(projectRoot, "@gtkx/runtime");
53
- if (runtime === null) {
54
- throw new Error(`Cannot resolve @gtkx/runtime from ${projectRoot}; is it installed?`);
55
- }
137
+ const runtime = resolveRuntime(projectRoot);
56
138
  const react = resolvePackage(projectRoot, "@gtkx/react");
57
- const nodeModules = join(projectRoot, "node_modules");
139
+ const nodeModules = storeNodeModules(runtime, react);
140
+ checkConsumers(projectRoot, nodeModules);
58
141
  return {
59
142
  gi: storeOptions(nodeModules, "gi", runtime.version),
60
- jsx: react === null ? null : storeOptions(nodeModules, "jsx", react.version),
61
- reactSubexports: react === null ? [] : subexportNames(react.dir),
143
+ jsx: jsxOptions(react, nodeModules),
144
+ reactSubexports: getReactSubexports(react),
62
145
  };
63
146
  };
64
- export { resolveStore };
147
+ export { getShadowingStorePaths, resolveStore, sweepProjectStaging };
65
148
  //# sourceMappingURL=resolve-store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-store.js","sourceRoot":"","sources":["../../src/store/resolve-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAkBjD,MAAM,SAAS,GAAG,OAAO,CAAC;AAC1B,MAAM,KAAK,GAAG,OAAO,CAAC;AAEtB,MAAM,YAAY,GAAG,CAAC,IAAY,EAA2D,EAAE,CAC3F,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAA4D,CAAC;AAEtG,MAAM,cAAc,GAAG,CAAC,UAAkB,EAAY,EAAE,CACpD,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;KACpE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,gBAAgB,CAAC;KACjE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpC,M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WAAmB,EAAE,IAAY,EAAE,OAAe,EAAgB,EAAE,CAAC,CAAC;IACxF,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC;IAC5C,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC;IACvC,OAAO;CACV,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAiB,EAAE;IACxD,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAE7D,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,qCAAqC,WAAW,oBAAoB,CAAC,CAAC;IAC1F,CAAC;IAED,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IAEtD,OAAO;QACH,EAAE,EAAE,YAAY,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC;QACpD,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;QAC5E,eAAe,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC;KACnE,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EAAE,YAAY,EAAsB,CAAC","sourcesContent":["import { existsSync, readFileSync, realpathSync } from \"node:fs\";\nimport { dirname, join, parse } from \"node:path\";\nimport type { StoreOptions } from \"./store-fs.js\";\n\n/**\n * Where a project's generated stores live, ready to spread into `runCodegen`. `jsx` is null when the\n * project has no `@gtkx/react` installed, in which case only the `@gtkx/gi` store can be generated.\n */\ntype ResolvedStore = {\n /** Where the `@gtkx/gi` store goes, versioned by the installed `@gtkx/runtime`. */\n gi: StoreOptions;\n /** Where the `@gtkx/jsx` store goes, versioned by the installed `@gtkx/react`; null when it is absent. */\n jsx: StoreOptions | null;\n /** Subexport names of the installed `@gtkx/react`, empty when it is absent. */\n reactSubexports: string[];\n};\n\ntype ResolvedPackage = { dir: string; version: string };\n\nconst STORE_DIR = \".gtkx\";\nconst SCOPE = \"@gtkx\";\n\nconst readManifest = (path: string): { version?: string; exports?: Record<string, unknown> } =>\n JSON.parse(readFileSync(path, \"utf8\")) as { version?: string; exports?: Record<string, unknown> };\n\nconst subexportNames = (packageDir: string): string[] =>\n Object.keys(readManifest(join(packageDir, \"package.json\")).exports ?? {})\n .filter((key) => key.startsWith(\"./\") && key !== \"./package.json\")\n .map((key) => key.slice(2));\n\nconst loadPackage = (manifest: string): ResolvedPackage | null => {\n if (!existsSync(manifest)) {\n return null;\n }\n\n const real = realpathSync(manifest);\n\n return { dir: dirname(real), version: readManifest(real).version ?? \"0.0.0\" };\n};\n\nconst nodeModulesChain = function* (projectRoot: string): Generator<string> {\n const { root } = parse(projectRoot);\n let current = projectRoot;\n\n while (current !== root) {\n yield join(current, \"node_modules\");\n current = dirname(current);\n }\n\n yield join(root, \"node_modules\");\n};\n\nconst resolvePackage = (projectRoot: string, packageName: string): ResolvedPackage | null => {\n for (const nodeModules of nodeModulesChain(projectRoot)) {\n const found = loadPackage(join(nodeModules, packageName, \"package.json\"));\n\n if (found !== null) {\n return found;\n }\n }\n\n return loadPackage(join(projectRoot, \"packages\", packageName.replace(/^@[^/]+\\//, \"\"), \"package.json\"));\n};\n\nconst storeOptions = (nodeModules: string, name: string, version: string): StoreOptions => ({\n storeDir: join(nodeModules, STORE_DIR, name),\n linkDir: join(nodeModules, SCOPE, name),\n version,\n});\n\n/**\n * Resolves where a project's `@gtkx/gi` and `@gtkx/jsx` stores belong, from the project root alone. The\n * result supplies every `runCodegen` input except `libraries` and `girPath`, so a caller that has\n * already resolved those can spread it straight into the call.\n *\n * Store versions come from the installed `@gtkx/runtime` and `@gtkx/react`, so a dependency upgrade\n * invalidates the stores. Pass explicit `gi` or `jsx` options to `runCodegen` to override any of it.\n *\n * @param projectRoot Directory holding the project's `package.json` and `node_modules`.\n * @returns The store locations and the React subexports that shape the jsx store.\n * @throws If `@gtkx/runtime` cannot be resolved from the project.\n */\nconst resolveStore = (projectRoot: string): ResolvedStore => {\n const runtime = resolvePackage(projectRoot, \"@gtkx/runtime\");\n\n if (runtime === null) {\n throw new Error(`Cannot resolve @gtkx/runtime from ${projectRoot}; is it installed?`);\n }\n\n const react = resolvePackage(projectRoot, \"@gtkx/react\");\n const nodeModules = join(projectRoot, \"node_modules\");\n\n return {\n gi: storeOptions(nodeModules, \"gi\", runtime.version),\n jsx: react === null ? null : storeOptions(nodeModules, \"jsx\", react.version),\n reactSubexports: react === null ? [] : subexportNames(react.dir),\n };\n};\n\nexport { resolveStore, type ResolvedStore };\n"]}
1
+ {"version":3,"file":"resolve-store.js","sourceRoot":"","sources":["../../src/store/resolve-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAkBjD,MAAM,SAAS,GAAG,OAAO,CAAC;AAC1B,MAAM,KAAK,GAAG,OAAO,CAAC;AACtB,MAAM,WAAW,GAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAE5C,MAAM,eAAe,GAAa;IAC9B,WAAW;IACX,kBAAkB;IAClB,WAAW;IACX,aAAa;IACb,eAAe;CAClB,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,IAAY,EAA2D,EAAE,CAC3F,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IA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ACpD,GAAG,EAAE,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC;QACnC,eAAe,EAAE,kBAAkB,CAAC,KAAK,CAAC;KAC7C,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,mBAAmB,EAAsB,CAAC","sourcesContent":["import { existsSync, readFileSync, realpathSync } from \"node:fs\";\nimport { dirname, join, parse, relative, sep } from \"node:path\";\nimport type { StoreOptions } from \"./store-fs.js\";\nimport { sweepStagingDirs } from \"../staging.js\";\n\n/**\n * Where a project's generated stores live, ready to spread into `runCodegen`. `jsx` is null when the\n * project has no `@gtkx/react` installed, in which case only the `@gtkx/gi` store can be generated.\n */\ntype ResolvedStore = {\n /** Where the `@gtkx/gi` store goes, versioned by the installed `@gtkx/runtime`. */\n gi: StoreOptions;\n /** Where the `@gtkx/jsx` store goes, versioned by the installed `@gtkx/react`; null when it is absent. */\n jsx: StoreOptions | null;\n /** Subexport names of the installed `@gtkx/react`, empty when it is absent. */\n reactSubexports: string[];\n};\n\ntype ResolvedPackage = { dir: string; nodeModules: string; version: string };\ntype StoreConsumer = { name: string; nodeModules: string };\n\nconst STORE_DIR = \".gtkx\";\nconst SCOPE = \"@gtkx\";\nconst STORE_NAMES: string[] = [\"gi\", \"jsx\"];\n\nconst STORE_CONSUMERS: string[] = [\n \"@gtkx/cli\",\n \"@gtkx/components\",\n \"@gtkx/css\",\n \"@gtkx/react\",\n \"@gtkx/testing\",\n];\n\nconst readManifest = (path: string): { version?: string; exports?: Record<string, unknown> } =>\n JSON.parse(readFileSync(path, \"utf8\")) as { version?: string; exports?: Record<string, unknown> };\n\nconst subexportNames = (packageDir: string): string[] =>\n Object.keys(readManifest(join(packageDir, \"package.json\")).exports ?? {})\n .filter((key) => key.startsWith(\"./\") && key !== \"./package.json\")\n .map((key) => key.slice(2));\n\nconst loadPackage = (manifest: string, nodeModules: string): ResolvedPackage | null => {\n if (!existsSync(manifest)) {\n return null;\n }\n\n const real = realpathSync(manifest);\n\n return { dir: dirname(real), nodeModules, version: readManifest(real).version ?? \"0.0.0\" };\n};\n\nconst nodeModulesChain = function* (projectRoot: string): Generator<string> {\n const { root } = parse(projectRoot);\n let current = projectRoot;\n\n while (current !== root) {\n yield join(current, \"node_modules\");\n current = dirname(current);\n }\n\n yield join(root, \"node_modules\");\n};\n\nconst resolvePackage = (projectRoot: string, packageName: string): ResolvedPackage | null => {\n for (const nodeModules of nodeModulesChain(projectRoot)) {\n const found = loadPackage(join(nodeModules, packageName, \"package.json\"), nodeModules);\n\n if (found !== null) {\n return found;\n }\n }\n\n const unscoped = packageName.replace(/^@[^/]+\\//, \"\");\n\n return loadPackage(join(projectRoot, \"packages\", unscoped, \"package.json\"), join(projectRoot, \"node_modules\"));\n};\n\nconst isWithin = (parent: string, child: string): boolean => {\n const path = relative(parent, child);\n\n return path === \"\" || (path !== \"..\" && !path.startsWith(`..${sep}`));\n};\n\nconst canImport = (fromNodeModules: string, targetNodeModules: string): boolean =>\n isWithin(dirname(targetNodeModules), dirname(fromNodeModules));\n\nconst storeOptions = (nodeModules: string, name: string, version: string): StoreOptions => ({\n storeDir: join(nodeModules, STORE_DIR, name),\n linkDir: join(nodeModules, SCOPE, name),\n version,\n});\n\nconst resolveRuntime = (projectRoot: string): ResolvedPackage => {\n const runtime = resolvePackage(projectRoot, \"@gtkx/runtime\");\n\n if (runtime === null) {\n throw new Error(`Cannot resolve @gtkx/runtime from ${projectRoot}; is it installed?`);\n }\n\n return runtime;\n};\n\nconst storeNodeModules = (runtime: ResolvedPackage, react: ResolvedPackage | null): string => {\n if (react !== null && canImport(react.nodeModules, runtime.nodeModules)) {\n return react.nodeModules;\n }\n\n return runtime.nodeModules;\n};\n\nconst findUnreachableConsumer = (projectRoot: string, nodeModules: string): StoreConsumer | null => {\n for (const name of STORE_CONSUMERS) {\n const consumer = resolvePackage(projectRoot, name);\n\n if (consumer !== null && !canImport(consumer.nodeModules, nodeModules)) {\n return { name, nodeModules: consumer.nodeModules };\n }\n }\n\n return null;\n};\n\nconst unreachableConsumerMessage = (consumer: StoreConsumer, nodeModules: string): string =>\n `Cannot write the generated store to ${nodeModules}: ${consumer.name} is installed in ` +\n `${consumer.nodeModules}, above it, so that copy can never import the generated @gtkx/gi. Install every ` +\n \"@gtkx package in one node_modules, then run gtkx codegen again.\";\n\nconst checkConsumers = (projectRoot: string, nodeModules: string): void => {\n const consumer = findUnreachableConsumer(projectRoot, nodeModules);\n\n if (consumer !== null) {\n throw new Error(unreachableConsumerMessage(consumer, nodeModules));\n }\n};\n\nconst jsxOptions = (react: ResolvedPackage | null, nodeModules: string): StoreOptions | null =>\n react === null ? null : storeOptions(nodeModules, \"jsx\", react.version);\n\nconst getReactSubexports = (react: ResolvedPackage | null): string[] =>\n react === null ? [] : subexportNames(react.dir);\n\nconst storePaths = (nodeModules: string): string[] =>\n STORE_NAMES.flatMap((name) => [join(nodeModules, STORE_DIR, name), join(nodeModules, SCOPE, name)]);\n\nconst findStoreNodeModules = (projectRoot: string): string | null => {\n const runtime = resolvePackage(projectRoot, \"@gtkx/runtime\");\n\n if (runtime === null) {\n return null;\n }\n\n return storeNodeModules(runtime, resolvePackage(projectRoot, \"@gtkx/react\"));\n};\n\nconst getShadowingStorePaths = (projectRoot: string): string[] => {\n const nodeModules = join(projectRoot, \"node_modules\");\n const anchored = findStoreNodeModules(projectRoot);\n\n if (anchored === null || anchored === nodeModules) {\n return [];\n }\n\n return storePaths(nodeModules);\n};\n\nconst stagingRoots = (projectRoot: string): string[] => {\n const nodeModules = join(projectRoot, \"node_modules\");\n const anchored = findStoreNodeModules(projectRoot);\n\n return anchored === null || anchored === nodeModules ? [nodeModules] : [nodeModules, anchored];\n};\n\nconst sweepProjectStaging = (projectRoot: string): void => {\n for (const nodeModules of stagingRoots(projectRoot)) {\n for (const name of STORE_NAMES) {\n sweepStagingDirs(join(nodeModules, STORE_DIR, name));\n }\n }\n};\n\n/**\n * Resolves where a project's `@gtkx/gi` and `@gtkx/jsx` stores belong, from the project root alone. The\n * result supplies every `runCodegen` input except `libraries` and `girPath`, so a caller that has\n * already resolved those can spread it straight into the call.\n *\n * Both stores go in one `node_modules`, found by walking the project's `node_modules` chain upwards:\n * the one `@gtkx/react` resolves from, or `@gtkx/runtime`'s when no React is installed. That is the\n * project's own directory when it installs those packages itself, and the workspace root when npm or\n * yarn hoisted them there. Keeping the pair together is what lets the jsx store import the gi store, and\n * anchoring them where the `@gtkx` packages sit is what lets `@gtkx/react`, the CLI, and the project's\n * sources all reach the bindings. A package manager that hoists therefore gives every project sharing\n * that `node_modules` one shared store.\n *\n * Store versions come from the installed `@gtkx/runtime` and `@gtkx/react`, so a dependency upgrade\n * invalidates the stores. Pass explicit `gi` or `jsx` options to `runCodegen` to override any of it.\n *\n * @param projectRoot Directory holding the project's `package.json`, whose `node_modules` chain is walked.\n * @returns The store locations and the React subexports that shape the jsx store.\n * @throws If `@gtkx/runtime` cannot be resolved from the project, or a `@gtkx` package that imports the\n * bindings is installed above the `node_modules` the stores would go in, since it could not reach them.\n */\nconst resolveStore = (projectRoot: string): ResolvedStore => {\n const runtime = resolveRuntime(projectRoot);\n const react = resolvePackage(projectRoot, \"@gtkx/react\");\n const nodeModules = storeNodeModules(runtime, react);\n checkConsumers(projectRoot, nodeModules);\n\n return {\n gi: storeOptions(nodeModules, \"gi\", runtime.version),\n jsx: jsxOptions(react, nodeModules),\n reactSubexports: getReactSubexports(react),\n };\n};\n\nexport { getShadowingStorePaths, resolveStore, sweepProjectStaging, type ResolvedStore };\n"]}
@@ -1,3 +1,4 @@
1
+ import { type SourceModule } from "../compile.js";
1
2
  /** Where one generated store is written and how it is reached. */
2
3
  type StoreOptions = {
3
4
  /** Directory the generated package is written to, replaced atomically on each run. */
@@ -7,10 +8,7 @@ type StoreOptions = {
7
8
  /** Version stamped on the store's `package.json`, taken from the dependency the store is generated for. */
8
9
  version: string;
9
10
  };
10
- type StoreFile = {
11
- fileName: string;
12
- source: string;
13
- };
11
+ type StoreLink = Pick<StoreOptions, "storeDir" | "linkDir">;
14
12
  type Manifest = {
15
13
  name: string;
16
14
  type: "module";
@@ -32,7 +30,7 @@ type RawFile = {
32
30
  type WriteStoreParams = {
33
31
  storeDir: string;
34
32
  linkDir: string;
35
- files: StoreFile[];
33
+ files: SourceModule[];
36
34
  manifest: Manifest;
37
35
  rawFiles?: RawFile[];
38
36
  requiresEnvReference?: boolean;
@@ -41,7 +39,12 @@ declare const subpathExport: (stem: string) => {
41
39
  types: string;
42
40
  default: string;
43
41
  };
42
+ declare const namespaceBarrel: (directory: string) => {
43
+ fileName: string;
44
+ source: string;
45
+ };
44
46
  declare const buildManifest: (input: ManifestInput) => Manifest;
45
47
  declare const writeStore: (params: WriteStoreParams) => void;
46
- export { subpathExport, buildManifest, writeStore, type StoreOptions, type RawFile };
48
+ declare const ensureStoreLink: (link: StoreLink) => void;
49
+ export { subpathExport, buildManifest, ensureStoreLink, namespaceBarrel, writeStore, type StoreOptions, type RawFile, };
47
50
  //# sourceMappingURL=store-fs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-fs.d.ts","sourceRoot":"","sources":["../../src/store/store-fs.ts"],"names":[],"mappings":"AAIA,kEAAkE;AAClE,KAAK,YAAY,GAAG;IAChB,sFAAsF;IACtF,QAAQ,EAAE,MAAM,CAAC;IACjB,uGAAuG;IACvG,OAAO,EAAE,MAAM,CAAC;IAChB,2GAA2G;IAC3G,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,SAAS,GAAG;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,QAAQ,GAAG;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,IAAI,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gBAAgB,CAAC,EAAE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A;CAG7E,CAAC;AAEH,QAAA,MAAM,aAAa,GAAI,OAAO,aAAa,KAAG,QAc7C,CAAC;AAEF,QAAA,MAAM,UAAU,GAAI,QAAQ,gBAAgB,KAAG,IAa9C,CAAC;AA0DF,QAAA,MAAM,eAAe,GAAI,MAAM,SAAS,KAAG,IAM1C,CAAC;AAkBF,OAAO,EACH,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,UAAU,EACV,KAAK,YAAY,EACjB,KAAK,OAAO,GACf,CAAC"}
@@ -1,11 +1,19 @@
1
- import { chmodSync, existsSync, mkdirSync, mkdtempSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
1
+ import { errorMessage } from "@gtkx/utils";
2
+ import { chmodSync, existsSync, mkdirSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync, } from "node:fs";
2
3
  import { dirname, join, relative } from "node:path";
4
+ import { keepFailedProject } from "../compile.js";
5
+ import { createStagingDir } from "../staging.js";
3
6
  import { compileStore } from "./compile-store.js";
4
7
  const STORE_DIR_MODE = 0o755;
8
+ const FAILED_STORE_SUFFIX = ".failed";
5
9
  const subpathExport = (stem) => ({
6
10
  types: `./${stem}.d.ts`,
7
11
  default: `./${stem}.js`,
8
12
  });
13
+ const namespaceBarrel = (directory) => ({
14
+ fileName: `${directory}/index.ts`,
15
+ source: `export * from "./${directory}.js";\n`,
16
+ });
9
17
  const buildManifest = (input) => {
10
18
  const manifest = {
11
19
  name: input.name,
@@ -21,25 +29,31 @@ const buildManifest = (input) => {
21
29
  };
22
30
  const writeStore = (params) => {
23
31
  const tmp = createTempStore(params.storeDir);
32
+ const keepAt = `${params.storeDir}${FAILED_STORE_SUFFIX}`;
24
33
  try {
25
- for (const file of params.files) {
26
- writeSourceFile(tmp, file.fileName, file.source);
27
- }
28
- compileStore({
29
- storeDir: tmp,
30
- files: params.files,
31
- packageName: params.manifest.name,
32
- ...(params.requiresEnvReference !== undefined && { requiresEnvReference: params.requiresEnvReference }),
33
- });
34
- writePackageJson(tmp, params.manifest);
35
- const rawFiles = params.rawFiles ?? [];
36
- for (const raw of rawFiles) {
37
- writeFileSync(join(tmp, raw.relativePath), raw.content);
38
- }
39
- swapStore(tmp, params.storeDir, params.linkDir);
34
+ buildTempStore(tmp, params);
35
+ swapStore(tmp, params.storeDir);
36
+ ensureStoreLink(params);
37
+ }
38
+ catch (error) {
39
+ throw keepFailedProject({ projectDir: tmp, keepAt, error });
40
+ }
41
+ rmSync(keepAt, { recursive: true, force: true });
42
+ };
43
+ const buildTempStore = (tmp, params) => {
44
+ for (const file of params.files) {
45
+ writeSourceFile(tmp, file.fileName, file.source);
40
46
  }
41
- finally {
42
- rmSync(tmp, { recursive: true, force: true });
47
+ compileStore({
48
+ storeDir: tmp,
49
+ files: params.files,
50
+ packageName: params.manifest.name,
51
+ ...(params.requiresEnvReference !== undefined && { requiresEnvReference: params.requiresEnvReference }),
52
+ });
53
+ writePackageJson(tmp, params.manifest);
54
+ const rawFiles = params.rawFiles ?? [];
55
+ for (const raw of rawFiles) {
56
+ writeFileSync(join(tmp, raw.relativePath), raw.content);
43
57
  }
44
58
  };
45
59
  const writeSourceFile = (storeDir, fileName, source) => {
@@ -55,7 +69,7 @@ const symlinkRelative = (linkPath, realTarget) => {
55
69
  const writePackageJson = (storeDir, manifest) => {
56
70
  writeFileSync(join(storeDir, "package.json"), `${JSON.stringify(manifest, null, 2)}\n`);
57
71
  };
58
- const swapStore = (tmp, storeDir, visibleLink) => {
72
+ const swapStore = (tmp, storeDir) => {
59
73
  const previous = `${storeDir}.old`;
60
74
  rmSync(previous, { recursive: true, force: true });
61
75
  if (existsSync(storeDir)) {
@@ -63,13 +77,33 @@ const swapStore = (tmp, storeDir, visibleLink) => {
63
77
  }
64
78
  renameSync(tmp, storeDir);
65
79
  rmSync(previous, { recursive: true, force: true });
66
- symlinkRelative(visibleLink, storeDir);
67
80
  };
81
+ const isStoreLinked = (link) => {
82
+ try {
83
+ return realpathSync(link.linkDir) === realpathSync(link.storeDir);
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ };
89
+ const ensureStoreLink = (link) => {
90
+ if (!existsSync(join(link.storeDir, "package.json")) || isStoreLinked(link)) {
91
+ return;
92
+ }
93
+ symlinkRelative(link.linkDir, link.storeDir);
94
+ };
95
+ const storeWriteMessage = (storeDir, error) => `Cannot write the generated store to ${storeDir}: ${errorMessage(error)}. ` +
96
+ "Codegen writes the store into the node_modules the @gtkx packages resolve from, " +
97
+ `so ${dirname(storeDir)} has to be writable.`;
68
98
  const createTempStore = (storeDir) => {
69
- mkdirSync(dirname(storeDir), { recursive: true });
70
- const tmp = mkdtempSync(`${storeDir}.tmp-`);
71
- chmodSync(tmp, STORE_DIR_MODE);
72
- return tmp;
99
+ try {
100
+ const tmp = createStagingDir(storeDir);
101
+ chmodSync(tmp, STORE_DIR_MODE);
102
+ return tmp;
103
+ }
104
+ catch (error) {
105
+ throw new Error(storeWriteMessage(storeDir, error), { cause: error });
106
+ }
73
107
  };
74
- export { subpathExport, buildManifest, writeStore };
108
+ export { subpathExport, buildManifest, ensureStoreLink, namespaceBarrel, writeStore, };
75
109
  //# sourceMappingURL=store-fs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-fs.js","sourceRoot":"","sources":["../../src/store/store-fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA4ClD,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,aAAa,GAAG,CAAC,IAAY,EAAsC,EAAE,CAAC,CAAC;IACzE,KAAK,EAAE,KAAK,IAAI,OAAO;IACvB,OAAO,EAAE,KAAK,IAAI,KA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C;AAEF,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,QAAgB,EAAE,WAAmB,EAAQ,EAAE;IAC3E,MAAM,QAAQ,GAAG,GAAG,QAAQ,MAAM,CAAC;IACnC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAEnD,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvB,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC1B,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,eAAe,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAU,EAAE;IACjD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC;IAC5C,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAE/B,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAmC,CAAC","sourcesContent":["import { chmodSync, existsSync, mkdirSync, mkdtempSync, renameSync, rmSync, symlinkSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport { compileStore } from \"./compile-store.js\";\n\n/** Where one generated store is written and how it is reached. */\ntype StoreOptions = {\n /** Directory the generated package is written to, replaced atomically on each run. */\n storeDir: string;\n /** Path the store is symlinked at, which is the specifier's resolution target under `node_modules`. */\n linkDir: string;\n /** Version stamped on the store's `package.json`, taken from the dependency the store is generated for. */\n version: string;\n};\n\ntype StoreFile = {\n fileName: string;\n source: string;\n};\n\ntype Manifest = {\n name: string;\n type: \"module\";\n version: string;\n sideEffects: true;\n exports: Record<string, unknown>;\n peerDependencies?: Record<string, string>;\n};\n\ntype ManifestInput = {\n name: string;\n version: string;\n exports: Record<string, unknown>;\n peerDependencies?: Record<string, string>;\n};\n\ntype RawFile = { relativePath: string; content: string };\n\ntype WriteStoreParams = {\n storeDir: string;\n linkDir: string;\n files: StoreFile[];\n manifest: Manifest;\n rawFiles?: RawFile[];\n requiresEnvReference?: boolean;\n};\n\nconst STORE_DIR_MODE = 0o755;\n\nconst subpathExport = (stem: string): { types: string; default: string } => ({\n types: `./${stem}.d.ts`,\n default: `./${stem}.js`,\n});\n\nconst buildManifest = (input: ManifestInput): Manifest => {\n const manifest: Manifest = {\n name: input.name,\n type: \"module\",\n version: input.version,\n sideEffects: true,\n exports: { \"./package.json\": \"./package.json\", ...input.exports },\n };\n\n if (input.peerDependencies) {\n manifest.peerDependencies = input.peerDependencies;\n }\n\n return manifest;\n};\n\nconst writeStore = (params: WriteStoreParams): void => {\n const tmp = createTempStore(params.storeDir);\n\n try {\n for (const file of params.files) {\n writeSourceFile(tmp, file.fileName, file.source);\n }\n\n compileStore({\n storeDir: tmp,\n files: params.files,\n packageName: params.manifest.name,\n ...(params.requiresEnvReference !== undefined && { requiresEnvReference: params.requiresEnvReference }),\n });\n\n writePackageJson(tmp, params.manifest);\n const rawFiles = params.rawFiles ?? [];\n\n for (const raw of rawFiles) {\n writeFileSync(join(tmp, raw.relativePath), raw.content);\n }\n\n swapStore(tmp, params.storeDir, params.linkDir);\n } finally {\n rmSync(tmp, { recursive: true, force: true });\n }\n};\n\nconst writeSourceFile = (storeDir: string, fileName: string, source: string): void => {\n const filePath = join(storeDir, fileName);\n mkdirSync(dirname(filePath), { recursive: true });\n writeFileSync(filePath, source);\n};\n\nconst symlinkRelative = (linkPath: string, realTarget: string): void => {\n mkdirSync(dirname(linkPath), { recursive: true });\n rmSync(linkPath, { recursive: true, force: true });\n symlinkSync(relative(dirname(linkPath), realTarget), linkPath, \"dir\");\n};\n\nconst writePackageJson = (storeDir: string, manifest: Manifest): void => {\n writeFileSync(join(storeDir, \"package.json\"), `${JSON.stringify(manifest, null, 2)}\\n`);\n};\n\nconst swapStore = (tmp: string, storeDir: string, visibleLink: string): void => {\n const previous = `${storeDir}.old`;\n rmSync(previous, { recursive: true, force: true });\n\n if (existsSync(storeDir)) {\n renameSync(storeDir, previous);\n }\n\n renameSync(tmp, storeDir);\n rmSync(previous, { recursive: true, force: true });\n symlinkRelative(visibleLink, storeDir);\n};\n\nconst createTempStore = (storeDir: string): string => {\n mkdirSync(dirname(storeDir), { recursive: true });\n const tmp = mkdtempSync(`${storeDir}.tmp-`);\n chmodSync(tmp, STORE_DIR_MODE);\n\n return tmp;\n};\n\nexport { subpathExport, buildManifest, writeStore, type StoreOptions, type RawFile };\n"]}
1
+ {"version":3,"file":"store-fs.js","sourceRoot":"","sources":["../../src/store/store-fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACH,SAAS,EACT,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,MAAM,EACN,WAAW,EACX,aAAa,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAqB,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAyClD,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAEtC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAsC,EAAE,CAAC,CAAC;IACzE,KAAK,EAAE,KAAK,IAAI,OAAO;IACvB,OAAO,E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AAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,IAAe,EAAQ,EAAE;IAC9C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1E,OAAO;IACX,CAAC;IAED,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAE,KAAc,EAAU,EAAE,CACnE,uCAAuC,QAAQ,KAAK,YAAY,CAAC,KAAK,CAAC,IAAI;IAC3E,kFAAkF;IAClF,MAAM,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC;AAElD,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAU,EAAE;IACjD,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACvC,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAE/B,OAAO,GAAG,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1E,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EACH,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,UAAU,GAGb,CAAC","sourcesContent":["import { errorMessage } from \"@gtkx/utils\";\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n realpathSync,\n renameSync,\n rmSync,\n symlinkSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport { keepFailedProject, type SourceModule } from \"../compile.js\";\nimport { createStagingDir } from \"../staging.js\";\nimport { compileStore } from \"./compile-store.js\";\n\n/** Where one generated store is written and how it is reached. */\ntype StoreOptions = {\n /** Directory the generated package is written to, replaced atomically on each run. */\n storeDir: string;\n /** Path the store is symlinked at, which is the specifier's resolution target under `node_modules`. */\n linkDir: string;\n /** Version stamped on the store's `package.json`, taken from the dependency the store is generated for. */\n version: string;\n};\n\ntype StoreLink = Pick<StoreOptions, \"storeDir\" | \"linkDir\">;\n\ntype Manifest = {\n name: string;\n type: \"module\";\n version: string;\n sideEffects: true;\n exports: Record<string, unknown>;\n peerDependencies?: Record<string, string>;\n};\n\ntype ManifestInput = {\n name: string;\n version: string;\n exports: Record<string, unknown>;\n peerDependencies?: Record<string, string>;\n};\n\ntype RawFile = { relativePath: string; content: string };\n\ntype WriteStoreParams = {\n storeDir: string;\n linkDir: string;\n files: SourceModule[];\n manifest: Manifest;\n rawFiles?: RawFile[];\n requiresEnvReference?: boolean;\n};\n\nconst STORE_DIR_MODE = 0o755;\nconst FAILED_STORE_SUFFIX = \".failed\";\n\nconst subpathExport = (stem: string): { types: string; default: string } => ({\n types: `./${stem}.d.ts`,\n default: `./${stem}.js`,\n});\n\nconst namespaceBarrel = (directory: string): { fileName: string; source: string } => ({\n fileName: `${directory}/index.ts`,\n source: `export * from \"./${directory}.js\";\\n`,\n});\n\nconst buildManifest = (input: ManifestInput): Manifest => {\n const manifest: Manifest = {\n name: input.name,\n type: \"module\",\n version: input.version,\n sideEffects: true,\n exports: { \"./package.json\": \"./package.json\", ...input.exports },\n };\n\n if (input.peerDependencies) {\n manifest.peerDependencies = input.peerDependencies;\n }\n\n return manifest;\n};\n\nconst writeStore = (params: WriteStoreParams): void => {\n const tmp = createTempStore(params.storeDir);\n const keepAt = `${params.storeDir}${FAILED_STORE_SUFFIX}`;\n\n try {\n buildTempStore(tmp, params);\n swapStore(tmp, params.storeDir);\n ensureStoreLink(params);\n } catch (error) {\n throw keepFailedProject({ projectDir: tmp, keepAt, error });\n }\n\n rmSync(keepAt, { recursive: true, force: true });\n};\n\nconst buildTempStore = (tmp: string, params: WriteStoreParams): void => {\n for (const file of params.files) {\n writeSourceFile(tmp, file.fileName, file.source);\n }\n\n compileStore({\n storeDir: tmp,\n files: params.files,\n packageName: params.manifest.name,\n ...(params.requiresEnvReference !== undefined && { requiresEnvReference: params.requiresEnvReference }),\n });\n\n writePackageJson(tmp, params.manifest);\n const rawFiles = params.rawFiles ?? [];\n\n for (const raw of rawFiles) {\n writeFileSync(join(tmp, raw.relativePath), raw.content);\n }\n};\n\nconst writeSourceFile = (storeDir: string, fileName: string, source: string): void => {\n const filePath = join(storeDir, fileName);\n mkdirSync(dirname(filePath), { recursive: true });\n writeFileSync(filePath, source);\n};\n\nconst symlinkRelative = (linkPath: string, realTarget: string): void => {\n mkdirSync(dirname(linkPath), { recursive: true });\n rmSync(linkPath, { recursive: true, force: true });\n symlinkSync(relative(dirname(linkPath), realTarget), linkPath, \"dir\");\n};\n\nconst writePackageJson = (storeDir: string, manifest: Manifest): void => {\n writeFileSync(join(storeDir, \"package.json\"), `${JSON.stringify(manifest, null, 2)}\\n`);\n};\n\nconst swapStore = (tmp: string, storeDir: string): void => {\n const previous = `${storeDir}.old`;\n rmSync(previous, { recursive: true, force: true });\n\n if (existsSync(storeDir)) {\n renameSync(storeDir, previous);\n }\n\n renameSync(tmp, storeDir);\n rmSync(previous, { recursive: true, force: true });\n};\n\nconst isStoreLinked = (link: StoreLink): boolean => {\n try {\n return realpathSync(link.linkDir) === realpathSync(link.storeDir);\n } catch {\n return false;\n }\n};\n\nconst ensureStoreLink = (link: StoreLink): void => {\n if (!existsSync(join(link.storeDir, \"package.json\")) || isStoreLinked(link)) {\n return;\n }\n\n symlinkRelative(link.linkDir, link.storeDir);\n};\n\nconst storeWriteMessage = (storeDir: string, error: unknown): string =>\n `Cannot write the generated store to ${storeDir}: ${errorMessage(error)}. ` +\n \"Codegen writes the store into the node_modules the @gtkx packages resolve from, \" +\n `so ${dirname(storeDir)} has to be writable.`;\n\nconst createTempStore = (storeDir: string): string => {\n try {\n const tmp = createStagingDir(storeDir);\n chmodSync(tmp, STORE_DIR_MODE);\n\n return tmp;\n } catch (error) {\n throw new Error(storeWriteMessage(storeDir, error), { cause: error });\n }\n};\n\nexport {\n subpathExport,\n buildManifest,\n ensureStoreLink,\n namespaceBarrel,\n writeStore,\n type StoreOptions,\n type RawFile,\n};\n"]}
@@ -0,0 +1,3 @@
1
+ declare const ensureStoreLinks: (projectRoot: string) => void;
2
+ export { ensureStoreLinks };
3
+ //# sourceMappingURL=store-links.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-links.d.ts","sourceRoot":"","sources":["../../src/store/store-links.ts"],"names":[],"mappings":"AAkCA,QAAA,MAAM,gBAAgB,GAAI,aAAa,MAAM,KAAG,IAY/C,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { resolveStore } from "./resolve-store.js";
4
+ import { ensureStoreLink } from "./store-fs.js";
5
+ const resolvedStores = new Map();
6
+ const resolveStoreOrNull = (projectRoot) => {
7
+ try {
8
+ return resolveStore(projectRoot);
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ };
14
+ const isStoreDirPresent = (store) => existsSync(join(store.gi.storeDir, "package.json"));
15
+ const storeFor = (projectRoot) => {
16
+ const cached = resolvedStores.get(projectRoot);
17
+ if (cached !== undefined && isStoreDirPresent(cached)) {
18
+ return cached;
19
+ }
20
+ const resolved = resolveStoreOrNull(projectRoot);
21
+ resolvedStores.delete(projectRoot);
22
+ if (resolved !== null) {
23
+ resolvedStores.set(projectRoot, resolved);
24
+ }
25
+ return resolved;
26
+ };
27
+ const ensureStoreLinks = (projectRoot) => {
28
+ const store = storeFor(projectRoot);
29
+ if (store === null) {
30
+ return;
31
+ }
32
+ for (const unit of [store.gi, store.jsx]) {
33
+ if (unit !== null) {
34
+ ensureStoreLink(unit);
35
+ }
36
+ }
37
+ };
38
+ export { ensureStoreLinks };
39
+ //# sourceMappingURL=store-links.js.map
@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,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;IAEpC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,OAAO;IACX,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACvC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAChB,eAAe,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { type ResolvedStore, resolveStore } from \"./resolve-store.js\";\nimport { ensureStoreLink } from \"./store-fs.js\";\n\nconst resolvedStores: Map<string, ResolvedStore> = new Map();\n\nconst resolveStoreOrNull = (projectRoot: string): ResolvedStore | null => {\n try {\n return resolveStore(projectRoot);\n } catch {\n return null;\n }\n};\n\nconst isStoreDirPresent = (store: ResolvedStore): boolean => existsSync(join(store.gi.storeDir, \"package.json\"));\n\nconst storeFor = (projectRoot: string): ResolvedStore | null => {\n const cached = resolvedStores.get(projectRoot);\n\n if (cached !== undefined && isStoreDirPresent(cached)) {\n return cached;\n }\n\n const resolved = resolveStoreOrNull(projectRoot);\n resolvedStores.delete(projectRoot);\n\n if (resolved !== null) {\n resolvedStores.set(projectRoot, resolved);\n }\n\n return resolved;\n};\n\nconst ensureStoreLinks = (projectRoot: string): void => {\n const store = storeFor(projectRoot);\n\n if (store === null) {\n return;\n }\n\n for (const unit of [store.gi, store.jsx]) {\n if (unit !== null) {\n ensureStoreLink(unit);\n }\n }\n};\n\nexport { ensureStoreLinks };\n"]}
@@ -0,0 +1,4 @@
1
+ import { ModuleContext } from "./context.js";
2
+ declare const comparisonContextFor: (context: ModuleContext) => ModuleContext;
3
+ export { comparisonContextFor };
4
+ //# sourceMappingURL=comparison-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparison-context.d.ts","sourceRoot":"","sources":["../../src/writer/comparison-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,QAAA,MAAM,oBAAoB,GAAI,SAAS,aAAa,KAAG,aAWtD,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { ModuleContext } from "./context.js";
2
+ const COMPARISON_CONTEXTS = new WeakMap();
3
+ const comparisonContextFor = (context) => {
4
+ const existing = COMPARISON_CONTEXTS.get(context);
5
+ if (existing !== undefined) {
6
+ return existing;
7
+ }
8
+ const created = new ModuleContext(context.namespace, context.library);
9
+ COMPARISON_CONTEXTS.set(context, created);
10
+ return created;
11
+ };
12
+ export { comparisonContextFor };
13
+ //# sourceMappingURL=comparison-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparison-context.js","sourceRoot":"","sources":["../../src/writer/comparison-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,mBAAmB,GAA0C,IAAI,OAAO,EAAE,CAAC;AAEjF,MAAM,oBAAoB,GAAG,CAAC,OAAsB,EAAiB,EAAE;IACnE,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAElD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,mBAAmB,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE1C,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import { ModuleContext } from \"./context.js\";\n\nconst COMPARISON_CONTEXTS: WeakMap<ModuleContext, ModuleContext> = new WeakMap();\n\nconst comparisonContextFor = (context: ModuleContext): ModuleContext => {\n const existing = COMPARISON_CONTEXTS.get(context);\n\n if (existing !== undefined) {\n return existing;\n }\n\n const created = new ModuleContext(context.namespace, context.library);\n COMPARISON_CONTEXTS.set(context, created);\n\n return created;\n};\n\nexport { comparisonContextFor };\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { Library } from "../gir/library.js";
2
2
  import type { GirNamespace } from "../gir/namespace.js";
3
- import { type DeclaredType, ModuleBuilder } from "./module.js";
3
+ import { type Declaration, ModuleBuilder } from "./module.js";
4
4
  declare class ModuleContext {
5
5
  module: ModuleBuilder;
6
6
  namespace: GirNamespace;
@@ -11,8 +11,8 @@ declare class ModuleContext {
11
11
  hoistDescriptor(expression: string): string;
12
12
  addGObjectBootstrapImports(): void;
13
13
  addCrossNamespaceImport(namespaceName: string): string;
14
- declaredType(owner: string, name?: string): DeclaredType;
15
- qualify(namespaceName: string, typeName: string): string;
14
+ declare(declaration: Declaration): void;
15
+ qualify(namespaceName: string, name: string): string;
16
16
  }
17
17
  export { ModuleContext };
18
18
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/writer/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,cAAM,aAAa;IACR,MAAM,EAAE,aAAa,CAAuB;IAC5C,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;gBAEZ,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO;IAKrD,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIpC,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxC,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAI3C,0BAA0B,IAAI,IAAI;IAalC,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAkBtD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAc,GAAG,YAAY;IAI/D,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;CAO3D;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/writer/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D,cAAM,aAAa;IACR,MAAM,EAAE,aAAa,CAAuB;IAC5C,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;gBAEZ,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO;IAKrD,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIpC,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxC,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAI3C,0BAA0B,IAAI,IAAI;IAalC,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAkBtD,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAUvC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;CAOvD;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -39,14 +39,19 @@ class ModuleContext {
39
39
  this.module.imports.addNamespace(path, namespaceName);
40
40
  return namespaceName;
41
41
  }
42
- declaredType(owner, name = owner) {
43
- return { name, owner: `${this.namespace.name}.${owner}` };
44
- }
45
- qualify(namespaceName, typeName) {
42
+ declare(declaration) {
43
+ const { name, code, owner } = declaration;
44
+ this.module.appendDeclaration({
45
+ name,
46
+ code,
47
+ owner: owner === undefined ? undefined : `${this.namespace.name}.${owner}`,
48
+ });
49
+ }
50
+ qualify(namespaceName, name) {
46
51
  if (namespaceName === this.namespace.name) {
47
- return typeName;
52
+ return name;
48
53
  }
49
- return `${this.addCrossNamespaceImport(namespaceName)}.${typeName}`;
54
+ return `${this.addCrossNamespaceImport(namespaceName)}.${name}`;
50
55
  }
51
56
  }
52
57
  export { ModuleContext };
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/writer/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,aAAa;IACR,MAAM,GAAkB,IAAI,aAAa,EAAE,CAAC;IAC5C,SAAS,CAAe;IACxB,OAAO,CAAU;IAExB,YAAY,SAAuB,EAAE,OAAgB;QACjD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,gBAAgB,CAAC,IAAY;QACzB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,oBAAoB,CAAC,IAAY;QAC7B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,eAAe,CAAC,UAAkB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IAED,0BAA0B;QACtB,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACpC,OAAO;QACX,C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IAAI,QAAQ,EAAE,CAAC;IACxE,CAAC;CACJ;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import type { Library } from \"../gir/library.js\";\nimport type { GirNamespace } from \"../gir/namespace.js\";\nimport { type DeclaredType, ModuleBuilder } from \"./module.js\";\n\nclass ModuleContext {\n public module: ModuleBuilder = new ModuleBuilder();\n public namespace: GirNamespace;\n public library: Library;\n\n constructor(namespace: GirNamespace, library: Library) {\n this.namespace = namespace;\n this.library = library;\n }\n\n addRuntimeImport(name: string): void {\n this.module.imports.addNamed(\"@gtkx/runtime\", name);\n }\n\n addRuntimeTypeImport(name: string): void {\n this.module.imports.addNamed(\"@gtkx/runtime\", name, true);\n }\n\n hoistDescriptor(expression: string): string {\n return this.module.hoistDescriptor(expression);\n }\n\n addGObjectBootstrapImports(): void {\n if (this.namespace.name === \"GObject\") {\n return;\n }\n\n if (this.namespace.name === \"GLib\") {\n return;\n }\n\n this.module.imports.addSideEffect(\"../gobject/overrides/object.js\");\n this.module.imports.addSideEffect(\"../gobject/overrides/value.js\");\n }\n\n addCrossNamespaceImport(namespaceName: string): string {\n if (namespaceName === this.namespace.name) {\n return namespaceName;\n }\n\n const directory = namespaceName.toLowerCase();\n const isFoundational = directory === \"gobject\" || directory === \"glib\";\n const path = isFoundational ? `../${directory}/${directory}.js` : `../${directory}/index.js`;\n\n if (!isFoundational) {\n this.module.imports.addSideEffect(path);\n }\n\n this.module.imports.addNamespace(path, namespaceName);\n\n return namespaceName;\n }\n\n declaredType(owner: string, name: string = owner): DeclaredType {\n return { name, owner: `${this.namespace.name}.${owner}` };\n }\n\n qualify(namespaceName: string, typeName: string): string {\n if (namespaceName === this.namespace.name) {\n return typeName;\n }\n\n return `${this.addCrossNamespaceImport(namespaceName)}.${typeName}`;\n }\n}\n\nexport { ModuleContext };\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/writer/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,aAAa,EAAE,M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,GAAG,cAAc,CAAC,CAAC,CAAC,MAAM,SAAS,IAAI,SAAS,KAAK,CAAC,CAAC,CAAC,MAAM,SAAS,WAAW,CAAC;QAE7F,IAAI,CAAC,cAAc,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAEtD,OAAO,aAAa,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,WAAwB;QAC5B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC;QAE1C,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAC1B,IAAI;YACJ,IAAI;YACJ,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,KAAK,EAAE;SAC7E,CAAC,CAAC;IACP,CAAC;IAED,OAAO,CAAC,aAAqB,EAAE,IAAY;QACvC,IAAI,aAAa,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,uBAAuB,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC;IACpE,CAAC;CACJ;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import type { Library } from \"../gir/library.js\";\nimport type { GirNamespace } from \"../gir/namespace.js\";\nimport { type Declaration, ModuleBuilder } from \"./module.js\";\n\nclass ModuleContext {\n public module: ModuleBuilder = new ModuleBuilder();\n public namespace: GirNamespace;\n public library: Library;\n\n constructor(namespace: GirNamespace, library: Library) {\n this.namespace = namespace;\n this.library = library;\n }\n\n addRuntimeImport(name: string): void {\n this.module.imports.addNamed(\"@gtkx/runtime\", name);\n }\n\n addRuntimeTypeImport(name: string): void {\n this.module.imports.addNamed(\"@gtkx/runtime\", name, true);\n }\n\n hoistDescriptor(expression: string): string {\n return this.module.hoistDescriptor(expression);\n }\n\n addGObjectBootstrapImports(): void {\n if (this.namespace.name === \"GObject\") {\n return;\n }\n\n if (this.namespace.name === \"GLib\") {\n return;\n }\n\n this.module.imports.addSideEffect(\"../gobject/overrides/object.js\");\n this.module.imports.addSideEffect(\"../gobject/overrides/value.js\");\n }\n\n addCrossNamespaceImport(namespaceName: string): string {\n if (namespaceName === this.namespace.name) {\n return namespaceName;\n }\n\n const directory = namespaceName.toLowerCase();\n const isFoundational = directory === \"gobject\" || directory === \"glib\";\n const path = isFoundational ? `../${directory}/${directory}.js` : `../${directory}/index.js`;\n\n if (!isFoundational) {\n this.module.imports.addSideEffect(path);\n }\n\n this.module.imports.addNamespace(path, namespaceName);\n\n return namespaceName;\n }\n\n declare(declaration: Declaration): void {\n const { name, code, owner } = declaration;\n\n this.module.appendDeclaration({\n name,\n code,\n owner: owner === undefined ? undefined : `${this.namespace.name}.${owner}`,\n });\n }\n\n qualify(namespaceName: string, name: string): string {\n if (namespaceName === this.namespace.name) {\n return name;\n }\n\n return `${this.addCrossNamespaceImport(namespaceName)}.${name}`;\n }\n}\n\nexport { ModuleContext };\n"]}
@@ -1,22 +1,30 @@
1
1
  import { ImportsBuilder } from "./imports.js";
2
- type DeclaredType = {
2
+ type Declaration = {
3
3
  name: string;
4
- owner: string;
4
+ code: string;
5
+ owner?: string | undefined;
5
6
  };
6
7
  declare class ModuleBuilder {
7
8
  private bindings;
8
9
  private bindingNames;
9
10
  private hoistedDescriptors;
11
+ private claimedSpaces;
10
12
  private declarations;
13
+ private declaredNames;
11
14
  private declaredTypes;
12
15
  private registrations;
16
+ private requiredNames;
13
17
  imports: ImportsBuilder;
18
+ private claimSpace;
19
+ private claimExportedName;
14
20
  private claimTypeName;
21
+ private verifyRegistrations;
15
22
  appendBinding(code: string, name?: string): void;
16
23
  hoistDescriptor(expression: string): string;
17
- appendDeclaration(code: string, declared?: DeclaredType): void;
18
- appendRegistration(code: string): void;
24
+ appendDeclaration(declaration: Declaration): void;
25
+ hasExports(): boolean;
26
+ appendRegistration(code: string, requires?: string[]): void;
19
27
  toSource(): string;
20
28
  }
21
- export { type DeclaredType, ModuleBuilder };
29
+ export { type Declaration, ModuleBuilder };
22
30
  //# sourceMappingURL=module.d.ts.map