kardalum 0.0.0 → 0.15.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 (219) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +47 -2
  3. package/dist/dev/config.d.ts +31 -0
  4. package/dist/dev/config.js +176 -0
  5. package/dist/dev/docker.d.ts +5 -0
  6. package/dist/dev/docker.js +36 -0
  7. package/dist/dev/index.d.ts +1 -0
  8. package/dist/dev/index.js +37 -0
  9. package/dist/dev/plugin-project.d.ts +2 -0
  10. package/dist/dev/plugin-project.js +41 -0
  11. package/dist/dev/port-preflight.d.ts +9 -0
  12. package/dist/dev/port-preflight.js +51 -0
  13. package/dist/dev/sandbox.d.ts +81 -0
  14. package/dist/dev/sandbox.js +954 -0
  15. package/dist/dev/server-resolution.d.ts +34 -0
  16. package/dist/dev/server-resolution.js +352 -0
  17. package/dist/dev/usage.d.ts +1 -0
  18. package/dist/dev/usage.js +28 -0
  19. package/dist/entrypoint.d.ts +1 -0
  20. package/dist/entrypoint.js +29 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +64 -0
  23. package/dist/plugin/build-federation-bundle.d.ts +29 -0
  24. package/dist/plugin/build-federation-bundle.js +93 -0
  25. package/dist/plugin/build-reference.d.ts +6 -0
  26. package/dist/plugin/build-reference.js +43 -0
  27. package/dist/plugin/build.d.ts +51 -0
  28. package/dist/plugin/build.js +292 -0
  29. package/dist/plugin/bundle-server-manifest.d.ts +27 -0
  30. package/dist/plugin/bundle-server-manifest.js +93 -0
  31. package/dist/plugin/checks/audit.d.ts +2 -0
  32. package/dist/plugin/checks/audit.js +82 -0
  33. package/dist/plugin/checks/bundle-size.d.ts +3 -0
  34. package/dist/plugin/checks/bundle-size.js +21 -0
  35. package/dist/plugin/checks/db-compat.d.ts +3 -0
  36. package/dist/plugin/checks/db-compat.js +15 -0
  37. package/dist/plugin/checks/icon-names.d.ts +3 -0
  38. package/dist/plugin/checks/icon-names.js +143 -0
  39. package/dist/plugin/checks/manifest.d.ts +3 -0
  40. package/dist/plugin/checks/manifest.js +12 -0
  41. package/dist/plugin/checks/package-contract.d.ts +27 -0
  42. package/dist/plugin/checks/package-contract.js +92 -0
  43. package/dist/plugin/checks/sdk-shared-key.d.ts +2 -0
  44. package/dist/plugin/checks/sdk-shared-key.js +99 -0
  45. package/dist/plugin/checks/shared-deps.d.ts +3 -0
  46. package/dist/plugin/checks/shared-deps.js +31 -0
  47. package/dist/plugin/checks/templates.d.ts +53 -0
  48. package/dist/plugin/checks/templates.js +495 -0
  49. package/dist/plugin/checks/typescript-worker.d.ts +2 -0
  50. package/dist/plugin/checks/typescript-worker.js +53 -0
  51. package/dist/plugin/checks/typescript.d.ts +2 -0
  52. package/dist/plugin/checks/typescript.js +41 -0
  53. package/dist/plugin/checks/views.d.ts +3 -0
  54. package/dist/plugin/checks/views.js +49 -0
  55. package/dist/plugin/copy-package-contract.d.ts +46 -0
  56. package/dist/plugin/copy-package-contract.js +61 -0
  57. package/dist/plugin/copy-sample-content.d.ts +50 -0
  58. package/dist/plugin/copy-sample-content.js +70 -0
  59. package/dist/plugin/copy-templates.d.ts +113 -0
  60. package/dist/plugin/copy-templates.js +302 -0
  61. package/dist/plugin/index.d.ts +12 -0
  62. package/dist/plugin/index.js +200 -0
  63. package/dist/plugin/load-manifest.d.ts +18 -0
  64. package/dist/plugin/load-manifest.js +90 -0
  65. package/dist/plugin/pack-starter.d.ts +42 -0
  66. package/dist/plugin/pack-starter.js +128 -0
  67. package/dist/plugin/pack.d.ts +12 -0
  68. package/dist/plugin/pack.js +63 -0
  69. package/dist/plugin/publish.d.ts +28 -0
  70. package/dist/plugin/publish.js +48 -0
  71. package/dist/plugin/types.d.ts +12 -0
  72. package/dist/plugin/types.js +1 -0
  73. package/dist/plugin/usage.d.ts +1 -0
  74. package/dist/plugin/usage.js +30 -0
  75. package/dist/plugin/validate.d.ts +30 -0
  76. package/dist/plugin/validate.js +98 -0
  77. package/dist/plugin/write-manifest-json.d.ts +10 -0
  78. package/dist/plugin/write-manifest-json.js +138 -0
  79. package/docker/compose.yml +39 -0
  80. package/node_modules/@kardalum/api-schemas/LICENSE +202 -0
  81. package/node_modules/@kardalum/api-schemas/README.md +56 -0
  82. package/node_modules/@kardalum/api-schemas/dist/action.schema.d.ts +30 -0
  83. package/node_modules/@kardalum/api-schemas/dist/action.schema.js +88 -0
  84. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +5 -0
  85. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +6 -0
  86. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +75 -0
  87. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +36 -0
  88. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +89 -0
  89. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +60 -0
  90. package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +24 -0
  91. package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +47 -0
  92. package/node_modules/@kardalum/api-schemas/dist/auth.schema.d.ts +38 -0
  93. package/node_modules/@kardalum/api-schemas/dist/auth.schema.js +38 -0
  94. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +537 -0
  95. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +353 -0
  96. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +158 -0
  97. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +139 -0
  98. package/node_modules/@kardalum/api-schemas/dist/content-path.d.ts +125 -0
  99. package/node_modules/@kardalum/api-schemas/dist/content-path.js +256 -0
  100. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +20 -0
  101. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +23 -0
  102. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +151 -0
  103. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +82 -0
  104. package/node_modules/@kardalum/api-schemas/dist/content-version.schema.d.ts +18 -0
  105. package/node_modules/@kardalum/api-schemas/dist/content-version.schema.js +22 -0
  106. package/node_modules/@kardalum/api-schemas/dist/content.schema.d.ts +17 -0
  107. package/node_modules/@kardalum/api-schemas/dist/content.schema.js +20 -0
  108. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +302 -0
  109. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +97 -0
  110. package/node_modules/@kardalum/api-schemas/dist/culture-direction.d.ts +1 -0
  111. package/node_modules/@kardalum/api-schemas/dist/culture-direction.js +9 -0
  112. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +36 -0
  113. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +32 -0
  114. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +9 -0
  115. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +32 -0
  116. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +296 -0
  117. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +138 -0
  118. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.d.ts +121 -0
  119. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.js +147 -0
  120. package/node_modules/@kardalum/api-schemas/dist/health.schema.d.ts +6 -0
  121. package/node_modules/@kardalum/api-schemas/dist/health.schema.js +5 -0
  122. package/node_modules/@kardalum/api-schemas/dist/html-entities.d.ts +4 -0
  123. package/node_modules/@kardalum/api-schemas/dist/html-entities.js +250 -0
  124. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +102 -0
  125. package/node_modules/@kardalum/api-schemas/dist/index.js +58 -0
  126. package/node_modules/@kardalum/api-schemas/dist/licensing.schema.d.ts +15 -0
  127. package/node_modules/@kardalum/api-schemas/dist/licensing.schema.js +14 -0
  128. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +381 -0
  129. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +197 -0
  130. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +167 -0
  131. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +214 -0
  132. package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.d.ts +77 -0
  133. package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.js +53 -0
  134. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +75 -0
  135. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +117 -0
  136. package/node_modules/@kardalum/api-schemas/dist/media-reference.d.ts +27 -0
  137. package/node_modules/@kardalum/api-schemas/dist/media-reference.js +279 -0
  138. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.d.ts +74 -0
  139. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +157 -0
  140. package/node_modules/@kardalum/api-schemas/dist/media.schema.d.ts +80 -0
  141. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +156 -0
  142. package/node_modules/@kardalum/api-schemas/dist/nav.schema.d.ts +23 -0
  143. package/node_modules/@kardalum/api-schemas/dist/nav.schema.js +55 -0
  144. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.d.ts +846 -0
  145. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +356 -0
  146. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +20 -0
  147. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +27 -0
  148. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +169 -0
  149. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +80 -0
  150. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.d.ts +65 -0
  151. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.js +889 -0
  152. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +89 -0
  153. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +134 -0
  154. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +31 -0
  155. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +38 -0
  156. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +369 -0
  157. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +393 -0
  158. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +22 -0
  159. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +87 -0
  160. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +31 -0
  161. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +25 -0
  162. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.d.ts +15 -0
  163. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.js +24 -0
  164. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +306 -0
  165. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +328 -0
  166. package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +79 -0
  167. package/node_modules/@kardalum/api-schemas/dist/render-editing.js +50 -0
  168. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.d.ts +9 -0
  169. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.js +13 -0
  170. package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.d.ts +2 -0
  171. package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.js +16 -0
  172. package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +90 -0
  173. package/node_modules/@kardalum/api-schemas/dist/role.schema.js +69 -0
  174. package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.d.ts +17 -0
  175. package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.js +27 -0
  176. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +108 -0
  177. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +93 -0
  178. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +243 -0
  179. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +296 -0
  180. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +43 -0
  181. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +25 -0
  182. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +30 -0
  183. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.js +19 -0
  184. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +112 -0
  185. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +74 -0
  186. package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +41 -0
  187. package/node_modules/@kardalum/api-schemas/dist/template.schema.js +39 -0
  188. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.d.ts +21 -0
  189. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.js +14 -0
  190. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +89 -0
  191. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +68 -0
  192. package/node_modules/@kardalum/api-schemas/package.json +35 -0
  193. package/node_modules/@kardalum/plugin-package/LICENSE +202 -0
  194. package/node_modules/@kardalum/plugin-package/README.md +71 -0
  195. package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +50 -0
  196. package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +659 -0
  197. package/node_modules/@kardalum/plugin-package/dist/envelope.d.ts +19 -0
  198. package/node_modules/@kardalum/plugin-package/dist/envelope.js +104 -0
  199. package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +37 -0
  200. package/node_modules/@kardalum/plugin-package/dist/extract.js +199 -0
  201. package/node_modules/@kardalum/plugin-package/dist/hash.d.ts +17 -0
  202. package/node_modules/@kardalum/plugin-package/dist/hash.js +69 -0
  203. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +11 -0
  204. package/node_modules/@kardalum/plugin-package/dist/index.js +7 -0
  205. package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +185 -0
  206. package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +236 -0
  207. package/node_modules/@kardalum/plugin-package/dist/package-contract.d.ts +50 -0
  208. package/node_modules/@kardalum/plugin-package/dist/package-contract.js +115 -0
  209. package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +1 -0
  210. package/node_modules/@kardalum/plugin-package/dist/sample-content.js +17 -0
  211. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +45 -0
  212. package/node_modules/@kardalum/plugin-package/dist/types.js +1 -0
  213. package/node_modules/@kardalum/plugin-package/package.json +49 -0
  214. package/node_modules/@kardalum/prisma-variants/LICENSE +202 -0
  215. package/node_modules/@kardalum/prisma-variants/README.md +56 -0
  216. package/node_modules/@kardalum/prisma-variants/dist/index.d.ts +4 -0
  217. package/node_modules/@kardalum/prisma-variants/dist/index.js +40 -0
  218. package/node_modules/@kardalum/prisma-variants/package.json +29 -0
  219. package/package.json +68 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # kardalum
2
2
 
3
- Reserved for Kardalum, a free CMS with a typed plugin marketplace. The first release is coming; until then this package installs nothing.
3
+ The command line for [Kardalum](https://kardalum.com), the free CMS that
4
+ never loses your data. It is a plugin author's tool: `kardalum dev` runs a
5
+ local Kardalum sandbox with your plugin loaded into it, and `kardalum plugin`
6
+ validates, builds, packs and publishes the plugin.
4
7
 
5
- https://kardalum.com
8
+ ## Install
9
+
10
+ Needs Node.js 22.12 or later. A plugin scaffolded with
11
+ `npm create kardalum-plugin@latest` has it already; to add it to an existing
12
+ plugin:
13
+
14
+ ```sh
15
+ npm install --save-dev kardalum
16
+ ```
17
+
18
+ ## Commands
19
+
20
+ ```sh
21
+ npx kardalum dev start # a local CMS with this plugin installed
22
+ npx kardalum plugin validate # the checks the marketplace review runs
23
+ npx kardalum plugin build # build the plugin into dist/
24
+ npx kardalum plugin pack # build and zip the installable package
25
+ npx kardalum plugin publish --token $KARDALUM_PUBLISH_TOKEN
26
+ ```
27
+
28
+ `kardalum dev start` installs `@kardalum/server` from npm the first time
29
+ (into `~/.kardalum/dev/server/<version>/`, cached after that), runs it on
30
+ SQLite, completes setup for you, and prints the admin's address with a login
31
+ and password. It runs your plugin's server hooks and routes as well as its
32
+ views. `--server-port` and `--plugin-port` move the ports (defaults `3100` and
33
+ `5273`), and `--server-version` pins the server.
34
+
35
+ `kardalum plugin bundle-server` bundles only a plugin's server half, which
36
+ the sandbox uses itself. `publish` sends to `https://marketplace.kardalum.com`
37
+ unless `--registry` or `$KARDALUM_REGISTRY_URL` names another marketplace.
38
+ `kardalum --help`, `kardalum dev --help` and `kardalum plugin --help` list
39
+ every option.
40
+
41
+ ## Docs
42
+
43
+ The CLI reference and the plugin guide are at
44
+ [docs.kardalum.com](https://docs.kardalum.com/v1/reference/cli/).
45
+
46
+ ## Support
47
+
48
+ Kardalum's source is not public. Questions and bug reports:
49
+ [kardalum-devkit](https://github.com/kardalum/kardalum-devkit).
50
+ Licensed Apache-2.0.
@@ -0,0 +1,31 @@
1
+ export declare class SandboxError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ declare const DIALECTS: readonly ["sqlite", "postgres", "mysql"];
5
+ export type SandboxDialect = (typeof DIALECTS)[number];
6
+ export type KardalumDevMode = "checkout" | "standalone";
7
+ export interface SandboxConfig {
8
+ dialect: SandboxDialect;
9
+ mode: KardalumDevMode;
10
+ repoRoot: string;
11
+ cwd: string;
12
+ stateDir: string;
13
+ serverPort: number;
14
+ adminPort: number;
15
+ pluginPort: number;
16
+ serverVersion?: string;
17
+ contentDatabaseUrl: string;
18
+ prismaDatabaseUrl: string;
19
+ prismaClientDir: string;
20
+ composeService: "postgres-sandbox" | "mysql-sandbox" | null;
21
+ adminEmail: string;
22
+ adminPassword: string;
23
+ readyTimeoutMs: number;
24
+ }
25
+ export declare function fwd(path: string): string;
26
+ export declare function detectMode(repoRoot: string): KardalumDevMode;
27
+ export declare function kardalumDevHome(env?: NodeJS.ProcessEnv): string;
28
+ export declare function sandboxKey(projectPath: string): string;
29
+ export declare function standaloneStateDir(projectPath: string, home?: string): string;
30
+ export declare function resolveSandboxConfig(argv: string[], cwd: string, env?: NodeJS.ProcessEnv): SandboxConfig;
31
+ export {};
@@ -0,0 +1,176 @@
1
+ import { parseArgs } from "node:util";
2
+ import { createHash } from "node:crypto";
3
+ import { existsSync } from "node:fs";
4
+ import { homedir } from "node:os";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ export class SandboxError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "SandboxError";
11
+ }
12
+ }
13
+ const DIALECTS = ["sqlite", "postgres", "mysql"];
14
+ // Forward slashes everywhere: Prisma file: URLs and generator output
15
+ // paths both accept them on Windows, and they keep tests platform-stable.
16
+ // Exported so other modules (server-resolution.ts) normalize paths the
17
+ // same way before they reach a user-facing error message or console.warn
18
+ // — join() re-introduces backslashes on win32 even when its inputs are
19
+ // already forward-slashed, so this must be applied at each message site,
20
+ // not just once when a path is first computed.
21
+ export function fwd(path) {
22
+ return path.replaceAll("\\", "/");
23
+ }
24
+ const CONTENT_URLS = {
25
+ sqlite: (stateDir) => `file:${stateDir}/content.db`,
26
+ postgres: () => "postgres://kardalum:kardalum@localhost:5435/kardalum_sandbox",
27
+ mysql: () => "mysql://kardalum:kardalum@localhost:3308/kardalum_sandbox",
28
+ };
29
+ const COMPOSE_SERVICES = {
30
+ sqlite: null,
31
+ postgres: "postgres-sandbox",
32
+ mysql: "mysql-sandbox",
33
+ };
34
+ const USAGE = "Usage: kardalum dev start [--db sqlite|postgres|mysql] [--server-port <n>] " +
35
+ "[--plugin-port <n>] [--server-version <version>]";
36
+ // Cold first boot compiles the whole server off tsx while vite cold-starts
37
+ // the admin — on a slow disk (OneDrive-synced checkouts especially) 60s
38
+ // was genuinely not enough (2026-08-25 fresh-clone finding #3).
39
+ const DEFAULT_READY_TIMEOUT_MS = 180_000;
40
+ // apps/server/package.json relative to repoRoot — the same checkout
41
+ // probe kardalum dev has always used (formerly a checkout assertion in
42
+ // sandbox.ts, which failed loudly when it was missing; S187 deleted that
43
+ // function — standalone is not an error state, just the other mode).
44
+ export function detectMode(repoRoot) {
45
+ return existsSync(join(repoRoot, "apps", "server", "package.json")) ? "checkout" : "standalone";
46
+ }
47
+ // Where standalone mode caches its installed @kardalum/server (see
48
+ // resolveServerInstall in server-resolution.ts): KARDALUM_DEV_HOME if set,
49
+ // else ~/.kardalum/dev. Exported so server-resolution.ts (and anything else
50
+ // that needs the same state dir) doesn't re-derive this independently.
51
+ export function kardalumDevHome(env = process.env) {
52
+ const override = env.KARDALUM_DEV_HOME?.trim();
53
+ return fwd(override ? override : join(homedir(), ".kardalum", "dev"));
54
+ }
55
+ // S187: standalone's state dir lives under kardalumDevHome(), keyed by a
56
+ // short hash of the plugin project's own absolute path — not `cwd`
57
+ // itself, which would need escaping/truncation to become a directory
58
+ // name and could collide across drives/casings that hash identically
59
+ // once normalized. `fwd()`-normalize the input first so the same project
60
+ // path hashes the same regardless of which slash style produced it (a
61
+ // raw win32 backslash path vs. one already forward-slashed).
62
+ //
63
+ // Not cryptographically motivated — collisions just mean two unrelated
64
+ // plugin projects would share a sandbox, which is implausible at the
65
+ // hex-10 (40-bit) length used here for a single developer's machine, and
66
+ // cheap to tell apart in `~/.kardalum/dev/sandboxes/` if it ever happened.
67
+ export function sandboxKey(projectPath) {
68
+ return createHash("sha256").update(fwd(projectPath)).digest("hex").slice(0, 10);
69
+ }
70
+ export function standaloneStateDir(projectPath, home = kardalumDevHome()) {
71
+ return fwd(join(home, "sandboxes", sandboxKey(projectPath)));
72
+ }
73
+ function resolveReadyTimeoutMs(env) {
74
+ const raw = env.KARDALUM_DEV_READY_TIMEOUT_MS?.trim();
75
+ if (!raw)
76
+ return DEFAULT_READY_TIMEOUT_MS;
77
+ const parsed = Number(raw);
78
+ if (!Number.isInteger(parsed) || parsed <= 0) {
79
+ throw new SandboxError(`KARDALUM_DEV_READY_TIMEOUT_MS must be a positive integer number of milliseconds, got "${raw}".`);
80
+ }
81
+ return parsed;
82
+ }
83
+ const DEFAULT_SERVER_PORT = 3100;
84
+ const DEFAULT_PLUGIN_PORT = 5273;
85
+ // Shared by --server-port/--plugin-port(/--admin-port). Not reused for
86
+ // --db (a closed enum, not a number) or KARDALUM_DEV_READY_TIMEOUT_MS
87
+ // (resolveReadyTimeoutMs has its own message shape and allows the env-var
88
+ // spelling of the same "positive integer" rule).
89
+ function parsePort(flagName, raw, fallback) {
90
+ if (raw === undefined)
91
+ return fallback;
92
+ const parsed = Number(raw);
93
+ if (!Number.isInteger(parsed) || parsed <= 0 || parsed > 65535) {
94
+ throw new SandboxError(`--${flagName} must be a positive integer port number (1-65535), got "${raw}".`);
95
+ }
96
+ return parsed;
97
+ }
98
+ export function resolveSandboxConfig(argv, cwd, env = process.env) {
99
+ let values;
100
+ let positionals;
101
+ try {
102
+ ({ values, positionals } = parseArgs({
103
+ args: argv,
104
+ allowPositionals: true,
105
+ options: {
106
+ db: { type: "string" },
107
+ "server-port": { type: "string" },
108
+ "plugin-port": { type: "string" },
109
+ "server-version": { type: "string" },
110
+ // S187 deprecated alias for --plugin-port. Accepted (not
111
+ // rejected) so an existing `--admin-port` invocation keeps
112
+ // working, just with a one-line notice and the value routed to
113
+ // pluginPort below.
114
+ "admin-port": { type: "string" },
115
+ },
116
+ }));
117
+ }
118
+ catch (err) {
119
+ const reason = err instanceof Error ? err.message : String(err);
120
+ throw new SandboxError(`${USAGE}: ${reason}`);
121
+ }
122
+ if (positionals[0] !== "start" || positionals.length !== 1) {
123
+ throw new SandboxError(`${USAGE}: "start" is the only command.`);
124
+ }
125
+ const dialect = (values.db ?? "sqlite");
126
+ if (!DIALECTS.includes(dialect)) {
127
+ throw new SandboxError(`Unknown --db "${values.db}". Valid values: sqlite, postgres, mysql.`);
128
+ }
129
+ const serverPort = parsePort("server-port", values["server-port"], DEFAULT_SERVER_PORT);
130
+ // --admin-port is the pre-S187 flag name; --plugin-port is preferred.
131
+ // Exactly one deprecation line, printed only when --admin-port was
132
+ // actually passed (not merely because it happens to equal the
133
+ // default) — an explicit --plugin-port still wins if both are given.
134
+ if (values["admin-port"] !== undefined) {
135
+ console.warn("[kardalum dev] --admin-port is deprecated; use --plugin-port instead.");
136
+ }
137
+ const pluginPortRaw = values["plugin-port"] ?? values["admin-port"];
138
+ const pluginPort = parsePort("plugin-port", pluginPortRaw, DEFAULT_PLUGIN_PORT);
139
+ // standalone mode preflights both as separate ports (assertPortsFree
140
+ // in sandbox.ts) — a developer who passes the same number for both would
141
+ // otherwise get a confusing "port already in use" failure pointing at
142
+ // itself, rather than a clear rejection here.
143
+ if (serverPort === pluginPort) {
144
+ throw new SandboxError(`--server-port and --plugin-port must be different (both were ${serverPort}).`);
145
+ }
146
+ // packages/cli/src/dev/config.ts (or dist/dev/config.js) → four levels up
147
+ // is the repo root. One short lands on packages/, which has no
148
+ // apps/server, so detectMode would quietly answer "standalone".
149
+ const repoRoot = fwd(resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", ".."));
150
+ const mode = detectMode(repoRoot);
151
+ const normalizedCwd = fwd(cwd);
152
+ // Checkout mode's state dir stays exactly `<cwd>/.kardalum-dev`, as it
153
+ // always has. Standalone has no monorepo checkout to root itself
154
+ // against, so its state lives under kardalumDevHome() instead, keyed by
155
+ // the plugin project's own path (standaloneStateDir/sandboxKey above)
156
+ // — two different plugin projects get two independent sandboxes.
157
+ const stateDir = mode === "standalone" ? standaloneStateDir(normalizedCwd, kardalumDevHome(env)) : fwd(join(cwd, ".kardalum-dev"));
158
+ return {
159
+ dialect,
160
+ mode,
161
+ repoRoot,
162
+ cwd: normalizedCwd,
163
+ stateDir,
164
+ serverPort,
165
+ adminPort: 5273,
166
+ pluginPort,
167
+ serverVersion: values["server-version"],
168
+ contentDatabaseUrl: CONTENT_URLS[dialect](stateDir),
169
+ prismaDatabaseUrl: `file:${stateDir}/prisma.db`,
170
+ prismaClientDir: `${stateDir}/prisma-client`,
171
+ composeService: COMPOSE_SERVICES[dialect],
172
+ adminEmail: "admin@kardalum.com",
173
+ adminPassword: "kardalum",
174
+ readyTimeoutMs: resolveReadyTimeoutMs(env),
175
+ };
176
+ }
@@ -0,0 +1,5 @@
1
+ import { type SandboxConfig } from "./config.js";
2
+ export declare function composeFile(): string;
3
+ export declare function assertDockerAvailable(dialect: string): void;
4
+ export declare function composeUp(config: SandboxConfig): void;
5
+ export declare function composeStop(config: SandboxConfig): void;
@@ -0,0 +1,36 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { fileURLToPath } from "node:url";
3
+ import { SandboxError } from "./config.js";
4
+ // All docker interaction is synchronous — each step must finish before
5
+ // the next starts, and none is long-running (compose --wait blocks until
6
+ // the healthcheck passes). shell:true throughout: Windows resolves
7
+ // docker/pnpm through .cmd shims.
8
+ // packages/cli/docker/compose.yml, resolved from this package's own root
9
+ // (dist/dev/docker.js, or src/dev/docker.ts under the tests, is two folders
10
+ // below it) rather than from the checkout: the file ships in the package's
11
+ // `files`, so the path holds wherever the CLI is installed.
12
+ export function composeFile() {
13
+ return fileURLToPath(new URL("../../docker/compose.yml", import.meta.url));
14
+ }
15
+ export function assertDockerAvailable(dialect) {
16
+ const result = spawnSync("docker", ["info"], { shell: true, stdio: "ignore" });
17
+ if (result.status !== 0) {
18
+ throw new SandboxError(`Docker is required for --db=${dialect}. Start Docker Desktop (or the docker daemon) and retry.`);
19
+ }
20
+ }
21
+ export function composeUp(config) {
22
+ if (!config.composeService)
23
+ return;
24
+ const result = spawnSync("docker", ["compose", "-p", "kardalum-dev", "-f", composeFile(), "up", "-d", "--wait", config.composeService], { shell: true, stdio: "inherit" });
25
+ if (result.status !== 0) {
26
+ throw new SandboxError(`docker compose up failed for ${config.composeService} (see output above).`);
27
+ }
28
+ }
29
+ export function composeStop(config) {
30
+ if (!config.composeService)
31
+ return;
32
+ spawnSync("docker", ["compose", "-p", "kardalum-dev", "-f", composeFile(), "stop", config.composeService], {
33
+ shell: true,
34
+ stdio: "ignore",
35
+ });
36
+ }
@@ -0,0 +1 @@
1
+ export declare function run(argv: string[]): Promise<number>;
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { SandboxError, resolveSandboxConfig } from "./config.js";
3
+ import { startSandbox } from "./sandbox.js";
4
+ import { USAGE } from "./usage.js";
5
+ // `kardalum dev`: the dispatcher (../index.ts) hands this main every
6
+ // argument after `dev`. The process wrapper (exitCode, never exit()) lives
7
+ // there too, since this file is no longer an entry point of its own.
8
+ // dist/dev/index.js (and src/dev/ under the tests) sit two folders below
9
+ // the package root.
10
+ function readVersion() {
11
+ const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
12
+ return pkg.version;
13
+ }
14
+ export async function run(argv) {
15
+ if (argv.includes("-h") || argv.includes("--help")) {
16
+ console.log(USAGE);
17
+ return 0;
18
+ }
19
+ if (argv.includes("-V") || argv.includes("--version")) {
20
+ console.log(readVersion());
21
+ return 0;
22
+ }
23
+ try {
24
+ const config = resolveSandboxConfig(argv, process.cwd());
25
+ await startSandbox(config);
26
+ return 0;
27
+ }
28
+ catch (error) {
29
+ if (error instanceof SandboxError) {
30
+ console.error(`[kardalum dev] ${error.message}`);
31
+ return 1;
32
+ }
33
+ const reason = error instanceof Error ? error.message : String(error);
34
+ console.error(`[kardalum dev] ${reason}`);
35
+ return 1;
36
+ }
37
+ }
@@ -0,0 +1,2 @@
1
+ export declare function detectPluginProject(cwd: string): boolean;
2
+ export declare function detectTemplateBearingProject(cwd: string): boolean;
@@ -0,0 +1,41 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ // Implicit detection (no CLI flag): a directory counts as a plugin
4
+ // project when it depends on @kardalum/plugin-sdk and has its own Vite
5
+ // config: the same two facts every create-kardalum-plugin scaffold and
6
+ // hand-built plugin (google-maps) share.
7
+ export function detectPluginProject(cwd) {
8
+ const packageJsonPath = join(cwd, "package.json");
9
+ if (!existsSync(packageJsonPath))
10
+ return false;
11
+ if (!existsSync(join(cwd, "vite.config.ts")))
12
+ return false;
13
+ try {
14
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
15
+ return Boolean(pkg.dependencies?.["@kardalum/plugin-sdk"]);
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ // S196 Task 8: a plugin ships its render templates and static assets as a
22
+ // `templates/` and/or `public/` directory sitting right next to `src/`
23
+ // (the same two dirs the manifest's templates/assets contributions point
24
+ // at, and the scaffold generates). kardalum dev uses THIS, not the plugin's
25
+ // declared `type` (which would mean importing and running the manifest
26
+ // module just to make a sandbox-wiring decision), to decide whether to
27
+ // redirect KARDALUM_TEMPLATES_DIR/KARDALUM_PUBLIC_DIR at the plugin project's
28
+ // own dirs. A plugin project that has authored only one of the two (e.g.
29
+ // templates/ but no public/ yet) still counts: the caller mkdir's
30
+ // whichever is missing.
31
+ //
32
+ // S268 Task 6: reading the directories, rather than the `template` and
33
+ // `bundle` listing labels, is now the only correct way to ask. Any
34
+ // plugin may declare templates or assets, so a plugin listed as
35
+ // `utility` can ship a site and must get the same sandbox wiring.
36
+ // create-kardalum-plugin's scaffoldRendersASite asks the same question of
37
+ // the files it just wrote, so the CLI's closing hint and this cannot
38
+ // disagree.
39
+ export function detectTemplateBearingProject(cwd) {
40
+ return existsSync(join(cwd, "templates")) || existsSync(join(cwd, "public"));
41
+ }
@@ -0,0 +1,9 @@
1
+ export declare class PortInUseError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare function isPortFree(port: number): Promise<boolean>;
5
+ export declare function describePortOwner(port: number): string | null;
6
+ export declare function assertPortsFree(ports: Array<{
7
+ name: string;
8
+ port: number;
9
+ }>): Promise<void>;
@@ -0,0 +1,51 @@
1
+ import { createServer } from "node:net";
2
+ import { execFileSync } from "node:child_process";
3
+ // S180 postmortem: a stale tsx-watch server held :3100 while its parent
4
+ // task had already died, and the sandbox's URL-based readiness check was
5
+ // fooled into treating the imposter as the real server coming up. Failing
6
+ // fast here — before anything is spawned or composed — turns that into a clear error
7
+ // instead of a confusing hang.
8
+ export class PortInUseError extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "PortInUseError";
12
+ }
13
+ }
14
+ export function isPortFree(port) {
15
+ return new Promise((resolve) => {
16
+ const probe = createServer();
17
+ probe.once("error", () => resolve(false));
18
+ probe.listen(port, "127.0.0.1", () => probe.close(() => resolve(true)));
19
+ });
20
+ }
21
+ // Best effort, never throws: "PID 1234: node" or null.
22
+ export function describePortOwner(port) {
23
+ try {
24
+ if (process.platform === "win32") {
25
+ const out = execFileSync("netstat", ["-ano"], { encoding: "utf8" });
26
+ const line = out.split(/\r?\n/).find((l) => l.includes(`:${port} `) && /LISTENING/.test(l));
27
+ const pid = line?.trim().split(/\s+/).pop();
28
+ if (!pid)
29
+ return null;
30
+ const task = execFileSync("tasklist", ["/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"], { encoding: "utf8" });
31
+ const image = task.split(",")[0]?.replace(/"/g, "").trim();
32
+ return image ? `PID ${pid}: ${image}` : `PID ${pid}`;
33
+ }
34
+ const pid = execFileSync("lsof", ["-t", `-iTCP:${port}`, "-sTCP:LISTEN"], { encoding: "utf8" }).trim().split("\n")[0];
35
+ if (!pid)
36
+ return null;
37
+ const cmd = execFileSync("ps", ["-o", "comm=", "-p", pid], { encoding: "utf8" }).trim();
38
+ return cmd ? `PID ${pid}: ${cmd}` : `PID ${pid}`;
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
44
+ export async function assertPortsFree(ports) {
45
+ for (const { name, port } of ports) {
46
+ if (await isPortFree(port))
47
+ continue;
48
+ const owner = describePortOwner(port);
49
+ throw new PortInUseError(`${name}: port ${port} is already in use${owner ? ` (${owner})` : ""}, stop that process before starting the sandbox`);
50
+ }
51
+ }