silgi 0.42.5 → 0.43.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 (266) hide show
  1. package/dist/_virtual/rolldown_runtime.mjs +11 -0
  2. package/dist/build.d.mts +3 -11
  3. package/dist/build.mjs +4 -48
  4. package/dist/cli/build/build.mjs +17 -0
  5. package/dist/cli/build/dev.d.mts +9 -0
  6. package/dist/cli/build/dev.mjs +59 -0
  7. package/dist/cli/build/prepare.d.mts +6 -0
  8. package/dist/cli/build/prepare.mjs +15 -0
  9. package/dist/cli/commands/commands.mjs +90 -0
  10. package/dist/cli/commands/env.mjs +53 -0
  11. package/dist/cli/commands/init.mjs +84 -0
  12. package/dist/cli/commands/install.mjs +52 -0
  13. package/dist/cli/commands/prepare.mjs +65 -0
  14. package/dist/cli/commands/reset.mjs +46 -0
  15. package/dist/cli/commands/run.mjs +105 -0
  16. package/dist/cli/commands/watch.mjs +48 -0
  17. package/dist/cli/config/defaults.mjs +117 -0
  18. package/dist/cli/config/index.d.mts +3 -11
  19. package/dist/cli/config/index.mjs +4 -17
  20. package/dist/cli/config/loader.d.mts +6 -0
  21. package/dist/cli/config/loader.mjs +71 -0
  22. package/dist/cli/config/resolvers/compatibility.mjs +71 -0
  23. package/dist/cli/config/resolvers/imports.mjs +35 -0
  24. package/dist/cli/config/resolvers/paths.mjs +98 -0
  25. package/dist/cli/config/resolvers/storage.mjs +23 -0
  26. package/dist/cli/config/resolvers/url.mjs +9 -0
  27. package/dist/cli/config/types.d.mts +14 -0
  28. package/dist/cli/config/types.mjs +147 -0
  29. package/dist/cli/core/apiful.mjs +36 -0
  30. package/dist/cli/core/app.mjs +105 -0
  31. package/dist/cli/core/devServer.mjs +10 -0
  32. package/dist/cli/core/env.mjs +68 -0
  33. package/dist/cli/core/installPackage.mjs +60 -0
  34. package/dist/cli/core/runtimeConfig.mjs +70 -0
  35. package/dist/cli/core/scan.mjs +35 -0
  36. package/dist/cli/core/silgi.mjs +111 -0
  37. package/dist/cli/core/templates.mjs +38 -0
  38. package/dist/cli/framework/emptyFramework.mjs +7 -0
  39. package/dist/cli/framework/h3.mjs +55 -0
  40. package/dist/cli/framework/index.mjs +15 -0
  41. package/dist/cli/framework/nitro.mjs +24 -0
  42. package/dist/cli/framework/nuxt.mjs +10 -0
  43. package/dist/cli/index.d.mts +1 -1
  44. package/dist/cli/index.mjs +24 -27
  45. package/dist/cli/module/exportScan.mjs +180 -0
  46. package/dist/cli/module/install.mjs +49 -0
  47. package/dist/cli/module/scan.mjs +195 -0
  48. package/dist/cli/scan/prepareCommands.mjs +40 -0
  49. package/dist/cli/scan/prepareConfigs.mjs +33 -0
  50. package/dist/cli/scan/prepareCoreFile.mjs +118 -0
  51. package/dist/cli/scan/prepareScanFile.mjs +59 -0
  52. package/dist/cli/scan/prepareSchema.mjs +140 -0
  53. package/dist/cli/scan/scanExportFile.mjs +312 -0
  54. package/dist/cli/scan/writeCoreFile.mjs +22 -0
  55. package/dist/cli/scan/writeTypesAndFiles.mjs +72 -0
  56. package/dist/cli/utils/cancel.mjs +14 -0
  57. package/dist/cli/utils/common.mjs +15 -0
  58. package/dist/cli/utils/compatibility.mjs +33 -0
  59. package/dist/cli/utils/debug.mjs +11 -0
  60. package/dist/cli/utils/ignore.mjs +56 -0
  61. package/dist/cli/utils/readScanFile.mjs +58 -0
  62. package/dist/cli/utils/storage.mjs +23 -0
  63. package/dist/core/context.d.mts +30 -0
  64. package/dist/core/context.mjs +32 -0
  65. package/dist/core/createSilgi.d.mts +6 -0
  66. package/dist/core/createSilgi.mjs +152 -0
  67. package/dist/core/error.d.mts +65 -0
  68. package/dist/core/error.mjs +106 -0
  69. package/dist/core/event.d.mts +26 -0
  70. package/dist/core/event.mjs +44 -0
  71. package/dist/core/index.d.mts +24 -316
  72. package/dist/core/index.mjs +27 -1345
  73. package/dist/core/orchestrate.mjs +113 -0
  74. package/dist/core/response.d.mts +20 -0
  75. package/dist/core/response.mjs +105 -0
  76. package/dist/core/silgi.d.mts +19 -0
  77. package/dist/core/silgi.mjs +141 -0
  78. package/dist/core/silgiApp.d.mts +9 -0
  79. package/dist/core/silgiApp.mjs +23 -0
  80. package/dist/core/storage.d.mts +7 -0
  81. package/dist/core/storage.mjs +15 -0
  82. package/dist/core/unctx.d.mts +21 -0
  83. package/dist/core/unctx.mjs +35 -0
  84. package/dist/core/utils/event-stream.d.mts +53 -0
  85. package/dist/core/utils/event-stream.mjs +38 -0
  86. package/dist/core/utils/event.d.mts +8 -0
  87. package/dist/core/utils/event.mjs +12 -0
  88. package/dist/core/utils/internal/event-stream.d.mts +45 -0
  89. package/dist/core/utils/internal/event-stream.mjs +137 -0
  90. package/dist/core/utils/internal/obj.mjs +9 -0
  91. package/dist/core/utils/internal/object.mjs +29 -0
  92. package/dist/core/utils/internal/query.mjs +73 -0
  93. package/dist/core/utils/internal/req.mjs +35 -0
  94. package/dist/core/utils/merge.d.mts +14 -0
  95. package/dist/core/utils/merge.mjs +27 -0
  96. package/dist/{shared/silgi.DTwQEdSr.d.mts → core/utils/middleware.d.mts} +11 -13
  97. package/dist/core/utils/middleware.mjs +12 -0
  98. package/dist/core/utils/request.mjs +35 -0
  99. package/dist/core/utils/resolver.d.mts +7 -0
  100. package/dist/core/utils/resolver.mjs +29 -0
  101. package/dist/core/utils/runtime.d.mts +7 -0
  102. package/dist/core/utils/runtime.mjs +20 -0
  103. package/dist/core/utils/sanitize.mjs +22 -0
  104. package/dist/core/utils/schema.d.mts +34 -0
  105. package/dist/core/utils/schema.mjs +33 -0
  106. package/dist/core/utils/service.d.mts +13 -0
  107. package/dist/core/utils/service.mjs +19 -0
  108. package/dist/core/utils/shared.d.mts +6 -0
  109. package/dist/core/utils/shared.mjs +7 -0
  110. package/dist/core/utils/storage.d.mts +24 -0
  111. package/dist/core/utils/storage.mjs +54 -0
  112. package/dist/index.d.mts +21 -6
  113. package/dist/index.mjs +22 -16
  114. package/dist/kit/add/add-commands.d.mts +6 -0
  115. package/dist/kit/add/add-commands.mjs +12 -0
  116. package/dist/kit/add/add-core-file.d.mts +9 -0
  117. package/dist/kit/add/add-core-file.mjs +11 -0
  118. package/dist/kit/add/add-imports.d.mts +14 -0
  119. package/dist/kit/add/add-imports.mjs +56 -0
  120. package/dist/kit/add/add-npm.d.mts +14 -0
  121. package/dist/kit/add/add-npm.mjs +23 -0
  122. package/dist/kit/define.d.mts +28 -0
  123. package/dist/kit/define.mjs +25 -0
  124. package/dist/kit/errors.d.mts +6 -0
  125. package/dist/kit/errors.mjs +11 -0
  126. package/dist/kit/esm.d.mts +11 -0
  127. package/dist/kit/esm.mjs +21 -0
  128. package/dist/kit/fs.d.mts +7 -0
  129. package/dist/kit/fs.mjs +23 -0
  130. package/dist/kit/function-utils.d.mts +27 -0
  131. package/dist/kit/function-utils.mjs +75 -0
  132. package/dist/kit/gen.d.mts +5 -0
  133. package/dist/kit/gen.mjs +26 -0
  134. package/dist/kit/hash.d.mts +4 -0
  135. package/dist/kit/hash.mjs +10 -0
  136. package/dist/kit/index.d.mts +22 -321
  137. package/dist/kit/index.mjs +23 -1039
  138. package/dist/kit/isFramework.d.mts +6 -0
  139. package/dist/kit/isFramework.mjs +21 -0
  140. package/dist/kit/logger.d.mts +6 -0
  141. package/dist/kit/logger.mjs +10 -0
  142. package/dist/kit/migration.d.mts +113 -0
  143. package/dist/kit/migration.mjs +301 -0
  144. package/dist/kit/module.d.mts +14 -0
  145. package/dist/kit/module.mjs +53 -0
  146. package/dist/kit/path.d.mts +7 -0
  147. package/dist/kit/path.mjs +26 -0
  148. package/dist/kit/preset.d.mts +8 -0
  149. package/dist/kit/preset.mjs +11 -0
  150. package/dist/kit/resolve.d.mts +37 -0
  151. package/dist/kit/resolve.mjs +82 -0
  152. package/dist/kit/template.d.mts +14 -0
  153. package/dist/kit/template.mjs +59 -0
  154. package/dist/kit/useRequest.d.mts +19 -0
  155. package/dist/kit/useRequest.mjs +63 -0
  156. package/dist/kit/utils.d.mts +34 -0
  157. package/dist/kit/utils.mjs +90 -0
  158. package/dist/package.mjs +176 -0
  159. package/dist/presets/_all.gen.d.mts +5 -2
  160. package/dist/presets/_all.gen.mjs +16 -13
  161. package/dist/presets/_resolve.d.mts +10 -6
  162. package/dist/presets/_resolve.mjs +51 -65
  163. package/dist/presets/_types.gen.d.mts +8 -5
  164. package/dist/presets/_types.gen.mjs +5 -1
  165. package/dist/presets/h3/preset.d.mts +5 -2
  166. package/dist/presets/h3/preset.mjs +33 -38
  167. package/dist/presets/hono/preset.d.mts +5 -2
  168. package/dist/presets/hono/preset.mjs +28 -35
  169. package/dist/presets/index.d.mts +3 -2
  170. package/dist/presets/index.mjs +3 -1
  171. package/dist/presets/nitro/preset.d.mts +5 -2
  172. package/dist/presets/nitro/preset.mjs +35 -42
  173. package/dist/presets/npmpackage/preset.d.mts +5 -2
  174. package/dist/presets/npmpackage/preset.mjs +27 -32
  175. package/dist/presets/nuxt/preset.d.mts +5 -2
  176. package/dist/presets/nuxt/preset.mjs +39 -44
  177. package/dist/runtime/index.d.mts +4 -3
  178. package/dist/runtime/index.mjs +5 -3
  179. package/dist/runtime/internal/config.d.mts +11 -7
  180. package/dist/runtime/internal/config.mjs +79 -90
  181. package/dist/runtime/internal/debug.d.mts +6 -3
  182. package/dist/runtime/internal/debug.mjs +9 -4
  183. package/dist/runtime/internal/defu.d.mts +4 -1
  184. package/dist/runtime/internal/defu.mjs +7 -2
  185. package/dist/runtime/internal/index.d.mts +7 -6
  186. package/dist/runtime/internal/index.mjs +8 -20
  187. package/dist/runtime/internal/nitro.d.mts +6 -3
  188. package/dist/runtime/internal/nitro.mjs +29 -37
  189. package/dist/runtime/internal/nuxt.d.mts +12 -8
  190. package/dist/runtime/internal/nuxt.mjs +12 -7
  191. package/dist/runtime/internal/ofetch.d.mts +8 -4
  192. package/dist/runtime/internal/ofetch.mjs +33 -34
  193. package/dist/runtime/internal/plugin.d.mts +7 -3
  194. package/dist/runtime/internal/plugin.mjs +7 -3
  195. package/dist/types/cliConfig.d.mts +288 -0
  196. package/dist/types/cliConfig.mjs +0 -0
  197. package/dist/types/cliHooks.d.mts +154 -0
  198. package/dist/types/cliHooks.mjs +0 -0
  199. package/dist/types/compatibility.d.mts +13 -0
  200. package/dist/types/compatibility.mjs +0 -0
  201. package/dist/types/config.d.mts +46 -0
  202. package/dist/types/config.mjs +0 -0
  203. package/dist/types/dotenv.d.mts +29 -0
  204. package/dist/types/dotenv.mjs +0 -0
  205. package/dist/types/event.d.mts +63 -0
  206. package/dist/types/event.mjs +0 -0
  207. package/dist/types/global.d.mts +24 -0
  208. package/dist/types/global.mjs +0 -0
  209. package/dist/types/helper.d.mts +25 -0
  210. package/dist/types/helper.mjs +0 -0
  211. package/dist/types/hooks.d.mts +37 -0
  212. package/dist/types/hooks.mjs +0 -0
  213. package/dist/types/index.d.mts +26 -1306
  214. package/dist/types/index.mjs +0 -1
  215. package/dist/types/kits.d.mts +32 -0
  216. package/dist/types/kits.mjs +0 -0
  217. package/dist/types/middleware.d.mts +31 -0
  218. package/dist/types/middleware.mjs +0 -0
  219. package/dist/types/module.d.mts +102 -0
  220. package/dist/types/module.mjs +0 -0
  221. package/dist/types/preset.d.mts +20 -0
  222. package/dist/types/preset.mjs +0 -0
  223. package/dist/types/route.d.mts +59 -0
  224. package/dist/types/route.mjs +0 -0
  225. package/dist/types/runtime/index.d.mts +5 -0
  226. package/dist/types/runtime/index.mjs +0 -0
  227. package/dist/types/runtime/nuxt.d.mts +13 -0
  228. package/dist/types/runtime/nuxt.mjs +0 -0
  229. package/dist/types/runtime/ofetch.d.mts +14 -0
  230. package/dist/types/runtime/ofetch.mjs +0 -0
  231. package/dist/types/runtime/plugin.d.mts +8 -0
  232. package/dist/types/runtime/plugin.mjs +0 -0
  233. package/dist/types/runtime/silgi.d.mts +11 -0
  234. package/dist/types/runtime/silgi.mjs +0 -0
  235. package/dist/types/schema.d.mts +86 -0
  236. package/dist/types/schema.mjs +0 -0
  237. package/dist/types/service.d.mts +102 -0
  238. package/dist/types/service.mjs +0 -0
  239. package/dist/types/shared.d.mts +19 -0
  240. package/dist/types/shared.mjs +0 -0
  241. package/dist/types/silgi.d.mts +71 -0
  242. package/dist/types/silgi.mjs +0 -0
  243. package/dist/types/silgiCLI.d.mts +118 -0
  244. package/dist/types/silgiCLI.mjs +0 -0
  245. package/dist/types/standard-schema.d.mts +61 -0
  246. package/dist/types/standard-schema.mjs +0 -0
  247. package/dist/types/storage.d.mts +30 -0
  248. package/dist/types/storage.mjs +0 -0
  249. package/package.json +20 -35
  250. package/dist/_chunks/silgiApp.mjs +0 -25
  251. package/dist/cli/build.mjs +0 -2190
  252. package/dist/cli/common.mjs +0 -13
  253. package/dist/cli/compatibility.mjs +0 -30
  254. package/dist/cli/dev.mjs +0 -67
  255. package/dist/cli/init.mjs +0 -112
  256. package/dist/cli/install.mjs +0 -151
  257. package/dist/cli/loader.mjs +0 -618
  258. package/dist/cli/prepare.mjs +0 -188
  259. package/dist/cli/reset.mjs +0 -55
  260. package/dist/cli/run.mjs +0 -159
  261. package/dist/cli/types.mjs +0 -232
  262. package/dist/cli/watch.mjs +0 -91
  263. package/dist/presets/next/preset.d.mts +0 -3
  264. package/dist/presets/next/preset.mjs +0 -38
  265. package/dist/runtime/internal/next.d.mts +0 -9
  266. package/dist/runtime/internal/next.mjs +0 -22
@@ -0,0 +1,7 @@
1
+ //#region src/cli/framework/emptyFramework.ts
2
+ async function emptyFramework(silgi) {
3
+ if (silgi.options.preset === "npm-package" || !silgi.options.preset) {}
4
+ }
5
+
6
+ //#endregion
7
+ export { emptyFramework };
@@ -0,0 +1,55 @@
1
+ import { addCoreFile, addTemplate, isPresents } from "silgi/kit";
2
+
3
+ //#region src/cli/framework/h3.ts
4
+ async function h3Framework(silgi, skip = false) {
5
+ if (!isPresents(["h3"]) && skip === false) return;
6
+ silgi.hook("before:schema.ts", (data) => {
7
+ data.addImportItemType([{
8
+ imports: [{ name: "H3Event" }],
9
+ specifier: "h3"
10
+ }, {
11
+ imports: [{ name: "NitroApp" }],
12
+ specifier: "nitropack/types"
13
+ }]);
14
+ });
15
+ silgi.hook("prepare:types", (opts) => {
16
+ addTemplate({
17
+ filename: "types/h3.d.ts",
18
+ where: ".silgi",
19
+ getContents: () => {
20
+ return [
21
+ "import type { SilgiRuntimeContext } from 'silgi/types'",
22
+ "",
23
+ "declare module \"h3\" {",
24
+ " interface H3EventContext extends SilgiRuntimeContext {}",
25
+ "}",
26
+ ""
27
+ ].join("\n");
28
+ }
29
+ });
30
+ opts.references.push({ path: "./h3.d.ts" });
31
+ });
32
+ addCoreFile({ before: ({ silgiConfigs }) => {
33
+ silgiConfigs.push({ captureError: `(silgi, error, context = {}) => {
34
+ const promise = silgi.hooks
35
+ .callHookParallel('error', silgi, error, context)
36
+ .catch((error_) => {
37
+ console.error('Error while capturing another error', error_)
38
+ })
39
+
40
+ if (context.event && isEvent(context.event)) {
41
+ const errors = context.event.context.nitro?.errors
42
+ if (errors) {
43
+ errors.push({ error, context })
44
+ }
45
+ if (context.event.waitUntil) {
46
+ context.event.waitUntil(promise)
47
+ }
48
+ }
49
+ }` });
50
+ } });
51
+ if (silgi.options.imports !== false) silgi.options.imports.presets ??= [];
52
+ }
53
+
54
+ //#endregion
55
+ export { h3Framework };
@@ -0,0 +1,15 @@
1
+ import { emptyFramework } from "./emptyFramework.mjs";
2
+ import { h3Framework } from "./h3.mjs";
3
+ import { nitroFramework } from "./nitro.mjs";
4
+ import { nuxtFramework } from "./nuxt.mjs";
5
+
6
+ //#region src/cli/framework/index.ts
7
+ const frameworkSetup = [
8
+ emptyFramework,
9
+ h3Framework,
10
+ nitroFramework,
11
+ nuxtFramework
12
+ ];
13
+
14
+ //#endregion
15
+ export { frameworkSetup };
@@ -0,0 +1,24 @@
1
+ import { h3Framework } from "./h3.mjs";
2
+ import { join } from "pathe";
3
+ import { isPresents } from "silgi/kit";
4
+ import { runtimeDir } from "silgi/runtime/meta";
5
+
6
+ //#region src/cli/framework/nitro.ts
7
+ async function nitroFramework(silgi, skip = false) {
8
+ if (!isPresents(["nitro"]) && skip === false) return;
9
+ silgi.hook("before:schema.ts", (data) => {
10
+ data.addImportItemType({
11
+ imports: [{ name: "NitroApp" }],
12
+ specifier: "nitropack/types"
13
+ });
14
+ });
15
+ silgi.options.plugins.push({
16
+ packageImport: "silgi/runtime/internal/nitro",
17
+ path: join(runtimeDir, "internal/nitro")
18
+ });
19
+ if (silgi.options.imports !== false) silgi.options.imports.presets ??= [];
20
+ await h3Framework(silgi, true);
21
+ }
22
+
23
+ //#endregion
24
+ export { nitroFramework };
@@ -0,0 +1,10 @@
1
+ import { nitroFramework } from "./nitro.mjs";
2
+
3
+ //#region src/cli/framework/nuxt.ts
4
+ async function nuxtFramework(silgi, skip = false) {
5
+ if (silgi.options.preset !== "nuxt" && skip === false) return;
6
+ await nitroFramework(silgi, true);
7
+ }
8
+
9
+ //#endregion
10
+ export { nuxtFramework };
@@ -1 +1 @@
1
-
1
+ export { };
@@ -1,32 +1,29 @@
1
1
  #!/usr/bin/env node
2
- import { defineCommand, runMain } from 'citty';
3
-
4
- const version = "0.42.5";
5
- const packageJson = {
6
- version: version};
2
+ import { package_default } from "../package.mjs";
3
+ import { defineCommand, runMain } from "citty";
7
4
 
5
+ //#region src/cli/index.ts
8
6
  const main = defineCommand({
9
- meta: {
10
- name: "Silgi",
11
- version: packageJson.version,
12
- description: "Silgi CLI"
13
- },
14
- args: {
15
- version: {
16
- alias: "v",
17
- description: "Show version"
18
- }
19
- },
20
- subCommands: {
21
- prepare: () => import('./prepare.mjs').then(function (n) { return n.p; }).then((m) => m.default),
22
- init: () => import('./init.mjs').then((m) => m.default),
23
- commands: () => import('./prepare.mjs').then(function (n) { return n.b; }).then((m) => m.default),
24
- install: () => import('./install.mjs').then((m) => m.default),
25
- watch: () => import('./watch.mjs').then((m) => m.default),
26
- reset: () => import('./reset.mjs').then((m) => m.default),
27
- run: () => import('./run.mjs').then((m) => m.default)
28
- },
29
- run() {
30
- }
7
+ meta: {
8
+ name: "Silgi",
9
+ version: package_default.version,
10
+ description: "Silgi CLI"
11
+ },
12
+ args: { version: {
13
+ alias: "v",
14
+ description: "Show version"
15
+ } },
16
+ subCommands: {
17
+ prepare: () => import("./commands/prepare.mjs").then((m) => m.default),
18
+ init: () => import("./commands/init.mjs").then((m) => m.default),
19
+ commands: () => import("./commands/commands.mjs").then((m) => m.default),
20
+ install: () => import("./commands/install.mjs").then((m) => m.default),
21
+ watch: () => import("./commands/watch.mjs").then((m) => m.default),
22
+ reset: () => import("./commands/reset.mjs").then((m) => m.default),
23
+ run: () => import("./commands/run.mjs").then((m) => m.default)
24
+ },
25
+ run() {}
31
26
  });
32
27
  runMain(main);
28
+
29
+ //#endregion
@@ -0,0 +1,180 @@
1
+ import { hash, relativeWithDot } from "silgi/kit";
2
+ import { promises } from "node:fs";
3
+ import { findExports, findTypeExports } from "mlly";
4
+ import { dirname, join } from "node:path";
5
+
6
+ //#region src/cli/module/exportScan.ts
7
+ async function registerModuleExportScan(silgi) {
8
+ silgi.hook("before:schema.ts", async (options) => {
9
+ for (const module of silgi.scanModules) {
10
+ const moduleReExports = [];
11
+ if (!module.entryPath) continue;
12
+ const path = module.meta._packageName ? join(dirname(module.entryPath), "types/index.d.mts") : join(dirname(module.entryPath), "types/index.ts");
13
+ const moduleTypes = await promises.readFile(path, "utf8").catch(() => "");
14
+ const normalisedModuleTypes = moduleTypes.replace(/export\s*\{.*?\}/gs, (match) => match.replace(/\b(type|interface)\b/g, ""));
15
+ for (const e of findTypeExports(normalisedModuleTypes)) moduleReExports.push(e);
16
+ for (const e of findExports(normalisedModuleTypes)) moduleReExports.push(e);
17
+ const hasTypeExport = (name) => moduleReExports.find((exp) => exp.names?.includes(name));
18
+ const configKey = module.meta.configKey;
19
+ const moduleName = module.meta.name || module.meta._packageName;
20
+ const specifier = module.meta._packageName ? moduleName : relativeWithDot(silgi.options.build.typesDir, join(dirname(module.entryPath), "types/index"));
21
+ if (hasTypeExport("ModuleOptions")) {
22
+ const importName = hash(`${configKey}ModuleOptions`);
23
+ options.addImportItemType({
24
+ imports: [{
25
+ as: importName,
26
+ name: "ModuleOptions"
27
+ }],
28
+ specifier
29
+ });
30
+ options.options.push({
31
+ key: configKey,
32
+ value: importName
33
+ });
34
+ }
35
+ if (hasTypeExport("ModuleRuntimeOptions")) {
36
+ const importName = hash(`${configKey}ModuleRuntimeOptions`);
37
+ options.addImportItemType({
38
+ imports: [{
39
+ as: importName,
40
+ name: "ModuleRuntimeOptions"
41
+ }],
42
+ specifier
43
+ });
44
+ options.runtimeOptions.push({
45
+ key: configKey,
46
+ value: importName
47
+ });
48
+ }
49
+ if (hasTypeExport("ModuleRuntimeShareds")) {
50
+ const importName = hash(`${configKey}ModuleRuntimeShareds`);
51
+ options.addImportItemType({
52
+ imports: [{
53
+ as: importName,
54
+ name: "ModuleRuntimeShareds"
55
+ }],
56
+ specifier
57
+ });
58
+ options.shareds.push({
59
+ key: configKey,
60
+ value: importName
61
+ });
62
+ }
63
+ if (hasTypeExport("ModuleEvents")) {
64
+ const importName = hash(`${configKey}ModuleEvents`);
65
+ options.addImportItemType({
66
+ imports: [{
67
+ as: importName,
68
+ name: "ModuleEvents"
69
+ }],
70
+ specifier
71
+ });
72
+ options.events.push({
73
+ key: configKey,
74
+ value: importName
75
+ });
76
+ }
77
+ if (hasTypeExport("ModuleRuntimeContexts")) {
78
+ const importName = hash(`${configKey}ModuleRuntimeContexts`);
79
+ options.addImportItemType({
80
+ imports: [{
81
+ as: importName,
82
+ name: "ModuleRuntimeContexts"
83
+ }],
84
+ specifier
85
+ });
86
+ options.contexts.push({
87
+ key: configKey,
88
+ value: importName
89
+ });
90
+ }
91
+ if (hasTypeExport("ModuleHooks")) {
92
+ const importName = hash(`${configKey}ModuleHooks`);
93
+ options.addImportItemType({
94
+ imports: [{
95
+ as: importName,
96
+ name: "ModuleHooks"
97
+ }],
98
+ specifier
99
+ });
100
+ options.hooks.push({
101
+ key: configKey,
102
+ value: importName
103
+ });
104
+ }
105
+ if (hasTypeExport("ModuleRuntimeHooks")) {
106
+ const importName = hash(`${configKey}RuntimeHooks`);
107
+ options.addImportItemType({
108
+ imports: [{
109
+ as: importName,
110
+ name: "ModuleRuntimeHooks"
111
+ }],
112
+ specifier
113
+ });
114
+ options.runtimeHooks.push({
115
+ key: configKey,
116
+ value: importName
117
+ });
118
+ }
119
+ if (hasTypeExport("SetupModuleOption")) {
120
+ const importName = hash(`${configKey}SetupModuleOption`);
121
+ options.addImportItemType({
122
+ imports: [{
123
+ as: importName,
124
+ name: "SetupModuleOption"
125
+ }],
126
+ specifier
127
+ });
128
+ options.setupModuleOption.push({
129
+ key: configKey,
130
+ value: importName
131
+ });
132
+ }
133
+ if (hasTypeExport("ModuleRuntimeMethods")) {
134
+ const importName = hash(`${configKey}ModuleRuntimeMethods`);
135
+ options.addImportItemType({
136
+ imports: [{
137
+ as: importName,
138
+ name: "ModuleRuntimeMethods"
139
+ }],
140
+ specifier
141
+ });
142
+ options.methods.push({
143
+ key: configKey,
144
+ value: importName
145
+ });
146
+ }
147
+ if (hasTypeExport("RouteRules")) {
148
+ const importName = hash(`${configKey}RouteRules`);
149
+ options.addImportItemType({
150
+ imports: [{
151
+ as: importName,
152
+ name: "RouteRules"
153
+ }],
154
+ specifier
155
+ });
156
+ options.routeRules.push({
157
+ key: configKey,
158
+ value: importName
159
+ });
160
+ }
161
+ if (hasTypeExport("MetaData")) {
162
+ const importName = hash(`${configKey}MetaData`);
163
+ options.addImportItemType({
164
+ imports: [{
165
+ as: importName,
166
+ name: "MetaData"
167
+ }],
168
+ specifier
169
+ });
170
+ options.metaDatas.push({
171
+ key: configKey,
172
+ value: importName
173
+ });
174
+ }
175
+ }
176
+ });
177
+ }
178
+
179
+ //#endregion
180
+ export { registerModuleExportScan };
@@ -0,0 +1,49 @@
1
+ import { hasInstalledModule$1 as hasInstalledModule } from "../utils/compatibility.mjs";
2
+ import { useSilgiCLI } from "silgi";
3
+ import { createJiti } from "dev-jiti";
4
+
5
+ //#region src/cli/module/install.ts
6
+ async function loadSilgiModuleInstance(silgiModule) {
7
+ if (typeof silgiModule === "string") throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
8
+ if (typeof silgiModule !== "function") throw new TypeError(`Nuxt module should be a function: ${silgiModule}`);
9
+ return { silgiModule };
10
+ }
11
+ async function installModules(silgi, prepare = false) {
12
+ silgi.options.isPreparingModules = prepare;
13
+ const jiti = createJiti(silgi.options.rootDir, {
14
+ alias: silgi.options.alias,
15
+ fsCache: true,
16
+ moduleCache: true
17
+ });
18
+ for (const module of silgi.scanModules) {
19
+ if (hasInstalledModule(module.meta.configKey) && !silgi.options.dev) silgi.logger.info(`Module ${module.meta.configKey} installed`);
20
+ try {
21
+ const silgiModule = module.entryPath !== void 0 ? await jiti.import(module.entryPath, {
22
+ default: true,
23
+ conditions: silgi.options.conditions
24
+ }) : module.module;
25
+ if (silgiModule.name !== "silgiNormalizedModule") {
26
+ silgi.scanModules = silgi.scanModules.filter((m) => m.entryPath !== module.entryPath);
27
+ continue;
28
+ }
29
+ await installModule(silgiModule, silgi, prepare);
30
+ } catch (err) {
31
+ silgi.logger.error(err);
32
+ }
33
+ }
34
+ silgi.options.isPreparingModules = false;
35
+ }
36
+ /** Installs a module on a Nuxt instance. */
37
+ async function installModule(moduleToInstall, silgi = useSilgiCLI(), inlineOptions, prepare = false) {
38
+ const { silgiModule } = await loadSilgiModuleInstance(moduleToInstall);
39
+ const res = await silgiModule(inlineOptions || {}, silgi) ?? {};
40
+ if (res === false) return false;
41
+ const metaData = await silgiModule.getMeta?.();
42
+ if (prepare) return metaData;
43
+ const installedModule = silgi.scanModules.find((m) => m.meta.configKey === metaData?.configKey);
44
+ if (installedModule) installedModule.installed = true;
45
+ else throw new Error(`Module ${metaData?.name} not found`);
46
+ }
47
+
48
+ //#endregion
49
+ export { installModules };
@@ -0,0 +1,195 @@
1
+ import { scanSilgiExports } from "../scan/scanExportFile.mjs";
2
+ import { consola as consola$1 } from "consola";
3
+ import { resolve } from "pathe";
4
+ import { directoryToURL, isPresents, resolveAlias } from "silgi/kit";
5
+ import { scanExports } from "unimport";
6
+ import { existsSync, promises } from "node:fs";
7
+ import { isRelative } from "ufo";
8
+ import { defu } from "defu";
9
+ import { createJiti } from "dev-jiti";
10
+ import { fileURLToPath } from "node:url";
11
+ import { resolveModuleURL } from "exsolve";
12
+
13
+ //#region src/cli/module/scan.ts
14
+ const MissingModuleMatcher = /Cannot find module\s+['"]?([^'")\s]+)['"]?/i;
15
+ async function _resolveSilgiModule(silgiModule, silgi) {
16
+ let resolvedModulePath;
17
+ let buildTimeModuleMeta = {};
18
+ const jiti = createJiti(silgi.options.rootDir, {
19
+ alias: silgi.options.alias,
20
+ fsCache: true,
21
+ moduleCache: true
22
+ });
23
+ if (typeof silgiModule === "string") {
24
+ silgiModule = resolveAlias(silgiModule, silgi.options.alias);
25
+ if (isRelative(silgiModule)) silgiModule = resolve(silgi.options.rootDir, silgiModule);
26
+ try {
27
+ const src = resolveModuleURL(silgiModule, {
28
+ from: silgi.options.modulesDir.map((m) => directoryToURL(m.replace(/\/node_modules\/?$/, "/"))),
29
+ suffixes: [
30
+ "silgi",
31
+ "silgi/index",
32
+ "module",
33
+ "module/index",
34
+ "",
35
+ "index"
36
+ ],
37
+ extensions: [
38
+ ".js",
39
+ ".mjs",
40
+ ".cjs",
41
+ ".ts",
42
+ ".mts",
43
+ ".cts"
44
+ ]
45
+ });
46
+ resolvedModulePath = fileURLToPath(src);
47
+ const resolvedSilgiModule = await jiti.import(src, { default: true });
48
+ if (typeof resolvedSilgiModule !== "function") throw new TypeError(`Nuxt module should be a function: ${silgiModule}.`);
49
+ silgiModule = await jiti.import(src, {
50
+ default: true,
51
+ conditions: silgi.options.conditions
52
+ });
53
+ const moduleMetadataPath = new URL("module.json", src);
54
+ if (existsSync(moduleMetadataPath)) buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
55
+ else if (typeof silgiModule === "function") {
56
+ const meta = await silgiModule.getMeta?.();
57
+ const _exports = await scanExports(resolvedModulePath, true);
58
+ buildTimeModuleMeta = {
59
+ ...meta,
60
+ exports: _exports.map(({ from,...rest }) => rest)
61
+ };
62
+ }
63
+ if (!isPresents(["npm-package"])) {
64
+ const runtimeFolder = new URL("runtime", src);
65
+ await scanSilgiExports(runtimeFolder.pathname, buildTimeModuleMeta._packageName);
66
+ }
67
+ } catch (error) {
68
+ const code = error.code;
69
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
70
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND") {
71
+ const module = MissingModuleMatcher.exec(error.message)?.[1];
72
+ if (module && !module.includes(silgiModule)) throw new TypeError(`Error while importing module \`${silgiModule}\`: ${error}`);
73
+ }
74
+ }
75
+ }
76
+ if (!buildTimeModuleMeta) throw new Error(`Module ${silgiModule} is not a valid Silgi module`);
77
+ if (typeof silgiModule === "function") {
78
+ if (!buildTimeModuleMeta.configKey) {
79
+ const meta = await silgiModule.getMeta?.();
80
+ buildTimeModuleMeta = {
81
+ ...meta,
82
+ exports: []
83
+ };
84
+ }
85
+ if (silgi.scanModules.some((m) => m.meta?.configKey === buildTimeModuleMeta.configKey)) throw new Error(`Module with key \`${buildTimeModuleMeta.configKey}\` already exists`);
86
+ const options = await silgiModule.getOptions?.() || {};
87
+ if (options) silgi.options._c12.config[buildTimeModuleMeta.configKey] = defu(silgi.options._c12.config[buildTimeModuleMeta.configKey] || {}, options || {});
88
+ else throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
89
+ silgi.scanModules.push({
90
+ meta: buildTimeModuleMeta,
91
+ entryPath: resolvedModulePath || void 0,
92
+ installed: false,
93
+ options,
94
+ module: silgiModule
95
+ });
96
+ }
97
+ }
98
+ async function scanModules(silgi) {
99
+ const _modules = [...silgi.options._modules, ...silgi.options.modules];
100
+ for await (const mod of _modules) await _resolveSilgiModule(mod, silgi);
101
+ const moduleMap = new Map(silgi.scanModules.map((m) => [m.meta?.configKey, m]));
102
+ const graphData = createDependencyGraph(silgi.scanModules);
103
+ const sortedKeys = topologicalSort(graphData);
104
+ const modules = sortedKeys.map((key) => moduleMap.get(key)).filter((module) => Boolean(module));
105
+ silgi.scanModules = modules;
106
+ }
107
+ function createDependencyGraph(modules) {
108
+ const graph = new Map();
109
+ const inDegree = new Map();
110
+ modules.forEach((module) => {
111
+ const key = module.meta?.configKey;
112
+ if (key) {
113
+ graph.set(key, new Set());
114
+ inDegree.set(key, 0);
115
+ }
116
+ });
117
+ modules.forEach((module) => {
118
+ const key = module.meta?.configKey;
119
+ if (!key) return;
120
+ const requiredDeps = module.meta?.requiredDependencies || [];
121
+ const beforeDeps = module.meta?.beforeDependencies || [];
122
+ const afterDeps = module.meta?.afterDependencies || [];
123
+ const processedDeps = new Set();
124
+ requiredDeps.forEach((dep) => {
125
+ if (!graph.has(dep)) throw new Error(`Required dependency "${dep}" for module "${key}" is missing`);
126
+ graph.get(dep)?.add(key);
127
+ inDegree.set(key, (inDegree.get(key) || 0) + 1);
128
+ processedDeps.add(dep);
129
+ });
130
+ beforeDeps.forEach((dep) => {
131
+ if (!graph.has(dep)) return;
132
+ graph.get(key)?.add(dep);
133
+ inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
134
+ });
135
+ afterDeps.forEach((dep) => {
136
+ if (processedDeps.has(dep)) return;
137
+ if (!graph.has(dep)) return;
138
+ graph.get(dep)?.add(key);
139
+ inDegree.set(key, (inDegree.get(key) || 0) + 1);
140
+ });
141
+ });
142
+ return {
143
+ graph,
144
+ inDegree
145
+ };
146
+ }
147
+ function findCyclicDependencies(graph) {
148
+ const visited = new Set();
149
+ const recursionStack = new Set();
150
+ const cycles = [];
151
+ function dfs(node, path = []) {
152
+ visited.add(node);
153
+ recursionStack.add(node);
154
+ path.push(node);
155
+ for (const neighbor of graph.get(node) || []) if (recursionStack.has(neighbor)) {
156
+ const cycleStart = path.indexOf(neighbor);
157
+ if (cycleStart !== -1) cycles.push([...path.slice(cycleStart), neighbor]);
158
+ } else if (!visited.has(neighbor)) dfs(neighbor, [...path]);
159
+ recursionStack.delete(node);
160
+ path.pop();
161
+ }
162
+ for (const node of graph.keys()) if (!visited.has(node)) dfs(node, []);
163
+ return cycles;
164
+ }
165
+ function topologicalSort(graphData) {
166
+ const { graph, inDegree } = graphData;
167
+ const order = [];
168
+ const queue = [];
169
+ for (const [node, degree] of inDegree.entries()) if (degree === 0) queue.push(node);
170
+ if (queue.length === 0) {}
171
+ while (queue.length > 0) {
172
+ const node = queue.shift();
173
+ order.push(node);
174
+ const neighbors = Array.from(graph.get(node) || []);
175
+ for (const neighbor of neighbors) {
176
+ const newDegree = (inDegree.get(neighbor) || 0) - 1;
177
+ inDegree.set(neighbor, newDegree);
178
+ if (newDegree === 0) queue.push(neighbor);
179
+ }
180
+ }
181
+ if (order.length !== graph.size) {
182
+ const cycles = findCyclicDependencies(graph);
183
+ if (cycles.length > 0) {
184
+ const cycleStr = cycles.map((cycle) => ` ${cycle.join(" -> ")}`).join("\n");
185
+ throw new Error(`Circular dependencies detected:\n${cycleStr}`);
186
+ } else {
187
+ const unresolvedModules = Array.from(graph.keys()).filter((key) => !order.includes(key));
188
+ throw new Error(`Unable to resolve dependencies for modules: ${unresolvedModules.join(", ")}`);
189
+ }
190
+ }
191
+ return order;
192
+ }
193
+
194
+ //#endregion
195
+ export { scanModules };
@@ -0,0 +1,40 @@
1
+ import { useSilgiCLI } from "../../core/silgiApp.mjs";
2
+ import { debugMode } from "../utils/debug.mjs";
3
+ import { addTemplate } from "silgi/kit";
4
+ import { genAugmentation } from "knitwork";
5
+
6
+ //#region src/cli/scan/prepareCommands.ts
7
+ async function prepareCommands(silgi = useSilgiCLI()) {
8
+ const commands = [];
9
+ await silgi.callHook("prepare:commands", commands);
10
+ if (debugMode("command")) addTemplate({
11
+ filename: "cli.json",
12
+ where: ".silgi",
13
+ write: true,
14
+ getContents: () => JSON.stringify(commands, null, 2)
15
+ });
16
+ silgi.hook("prepare:types", async ({ references }) => {
17
+ const allTags = commands.reduce((acc, commandGroup) => {
18
+ Object.values(commandGroup).forEach((command) => {
19
+ if (command.tags) command.tags.forEach((tag) => acc.add(tag));
20
+ });
21
+ return acc;
22
+ }, new Set());
23
+ const data = [
24
+ genAugmentation("silgi/types", { SilgiCommands: { ...Object.fromEntries(Array.from(allTags.values()).map((tag) => [tag, "string"])) } }),
25
+ "",
26
+ "export {}"
27
+ ];
28
+ addTemplate({
29
+ filename: "types/commands.d.ts",
30
+ write: true,
31
+ where: ".silgi",
32
+ getContents: () => data.join("\n")
33
+ });
34
+ references.push({ path: "./commands.d.ts" });
35
+ });
36
+ silgi.options.commands = commands;
37
+ }
38
+
39
+ //#endregion
40
+ export { prepareCommands };
@@ -0,0 +1,33 @@
1
+ import { useCLIRuntimeConfig } from "../core/runtimeConfig.mjs";
2
+ import { resolve } from "pathe";
3
+ import { useSilgiCLI } from "silgi";
4
+ import { baseHeaderBannerComment, genEnsureSafeVar, writeFile } from "silgi/kit";
5
+ import { genObjectFromRawEntries } from "knitwork";
6
+
7
+ //#region src/cli/scan/prepareConfigs.ts
8
+ async function prepareConfigs(silgi = useSilgiCLI()) {
9
+ useCLIRuntimeConfig();
10
+ const _data = { runtimeConfig: {} };
11
+ for (const module of silgi.scanModules) if (module.meta.cliToRuntimeOptionsKeys && module.meta.cliToRuntimeOptionsKeys?.length > 0) for (const key of module.meta.cliToRuntimeOptionsKeys) _data[module.meta.configKey] = {
12
+ ..._data[module.meta.configKey],
13
+ [key]: module.options[key]
14
+ };
15
+ else _data[module.meta.configKey] = {};
16
+ await silgi.callHook("prepare:configs.ts", _data);
17
+ const importData = [
18
+ "import type { SilgiRuntimeOptions, SilgiRuntimeConfig, SilgiOptions } from 'silgi/types'",
19
+ "import { useRuntimeConfig } from 'silgi/runtime'",
20
+ "",
21
+ `export const runtimeConfig: SilgiRuntimeConfig = ${genObjectFromRawEntries(Object.entries(_data.runtimeConfig).map(([key, value]) => [key, genEnsureSafeVar(value)]), "")}`,
22
+ "",
23
+ "export const localConfig = useRuntimeConfig(undefined, runtimeConfig)",
24
+ ""
25
+ ];
26
+ delete _data.runtimeConfig;
27
+ importData.push(`export const cliConfigs: Partial<SilgiRuntimeOptions & SilgiOptions> = ${genObjectFromRawEntries(Object.entries(_data).map(([key, value]) => [key, genEnsureSafeVar(value)]))}`);
28
+ importData.unshift(...baseHeaderBannerComment);
29
+ await writeFile(resolve(silgi.options.silgi.serverDir, "configs.ts"), importData.join("\n"));
30
+ }
31
+
32
+ //#endregion
33
+ export { prepareConfigs };