silgi 0.42.4 → 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 -233
  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,105 @@
1
+ import { watchDev } from "../build/dev.mjs";
2
+ import { commonArgs } from "../utils/common.mjs";
3
+ import prepare_default from "./prepare.mjs";
4
+ import consola from "consola";
5
+ import { useSilgiCLI } from "silgi";
6
+ import { version } from "silgi/meta";
7
+ import { defineCommand, runCommand } from "citty";
8
+ import { x } from "tinyexec";
9
+
10
+ //#region src/cli/commands/run.ts
11
+ const command = defineCommand({
12
+ meta: {
13
+ name: "dev",
14
+ description: "Start the development server for the project",
15
+ version
16
+ },
17
+ args: {
18
+ ...commonArgs,
19
+ command: {
20
+ type: "string",
21
+ description: "your application start command",
22
+ required: false
23
+ }
24
+ },
25
+ async run({ args, rawArgs }) {
26
+ await runCommand(prepare_default, { rawArgs: [
27
+ "--commandType",
28
+ "dev",
29
+ "--dev",
30
+ "true"
31
+ ] });
32
+ const silgi = useSilgiCLI();
33
+ const startCommand = args.command || rawArgs[0];
34
+ let childPid = null;
35
+ let hasExited = false;
36
+ let exitTimeout = null;
37
+ const cleanupAndExit = (code = 0) => {
38
+ if (hasExited) return;
39
+ hasExited = true;
40
+ if (exitTimeout) clearTimeout(exitTimeout);
41
+ process.exit(code);
42
+ };
43
+ const handleSignal = async (signal, watcher) => {
44
+ consola.info(`Received ${signal}, terminating process...`);
45
+ if (watcher && typeof watcher.close === "function") try {
46
+ await watcher.close();
47
+ } catch {}
48
+ if (childPid) {
49
+ try {
50
+ process.kill(childPid, signal);
51
+ } catch (err) {
52
+ consola.error(`Failed to kill process: ${err instanceof Error ? err.message : err}`);
53
+ }
54
+ exitTimeout = setTimeout(() => {
55
+ consola.warn("Process did not exit gracefully, forcing termination...");
56
+ try {
57
+ if (childPid) process.kill(childPid, "SIGKILL");
58
+ } catch {}
59
+ cleanupAndExit(1);
60
+ }, 3e3);
61
+ } else cleanupAndExit(0);
62
+ };
63
+ const setupSignalHandlers = (watcher) => {
64
+ [
65
+ "SIGINT",
66
+ "SIGTERM",
67
+ "SIGHUP"
68
+ ].forEach((signal) => {
69
+ process.on(signal, () => {
70
+ handleSignal(signal, watcher);
71
+ });
72
+ });
73
+ };
74
+ try {
75
+ const watcher = await watchDev();
76
+ setupSignalHandlers(watcher);
77
+ consola.info(`Starting command: nr ${startCommand}`);
78
+ const proc = x("nr", [startCommand], { nodeOptions: {
79
+ stdio: "inherit",
80
+ shell: true,
81
+ cwd: process.cwd(),
82
+ killSignal: "SIGINT"
83
+ } });
84
+ if (proc && typeof proc.pid === "number") childPid = proc.pid;
85
+ try {
86
+ await proc;
87
+ consola.success(`Process exited successfully.`);
88
+ cleanupAndExit(0);
89
+ } catch (procError) {
90
+ const exitCode = procError && typeof procError.exitCode === "number" ? procError.exitCode : 1;
91
+ consola.error(`Process exited with code: ${exitCode}`);
92
+ if (silgi.options.debug) consola.withTag("silgi").error("Error while running the command", procError);
93
+ cleanupAndExit(exitCode);
94
+ }
95
+ } catch (error) {
96
+ consola.error(`Failed to start the development server: ${error instanceof Error ? error.message : error}`);
97
+ if (silgi.options.debug) consola.withTag("silgi").error("Error while running the command", error);
98
+ cleanupAndExit(1);
99
+ }
100
+ }
101
+ });
102
+ var run_default = command;
103
+
104
+ //#endregion
105
+ export { run_default as default };
@@ -0,0 +1,48 @@
1
+ import { watchDev } from "../build/dev.mjs";
2
+ import { commonArgs } from "../utils/common.mjs";
3
+ import prepare_default from "./prepare.mjs";
4
+ import consola from "consola";
5
+ import { version } from "silgi/meta";
6
+ import { defineCommand, runCommand } from "citty";
7
+
8
+ //#region src/cli/commands/watch.ts
9
+ const command = defineCommand({
10
+ meta: {
11
+ name: "dev",
12
+ description: "Start the development server for the project",
13
+ version
14
+ },
15
+ args: {
16
+ ...commonArgs,
17
+ preset: {
18
+ type: "string",
19
+ description: "The build preset to use (you can also use `SILGI_PRESET` environment variable)."
20
+ },
21
+ stub: {
22
+ type: "boolean",
23
+ description: "Run in silgi development mode"
24
+ }
25
+ },
26
+ async run() {
27
+ await runCommand(prepare_default, { rawArgs: [
28
+ "--commandType",
29
+ "dev",
30
+ "--dev",
31
+ "true"
32
+ ] });
33
+ const watch = await watchDev();
34
+ process.on("SIGINT", async () => {
35
+ consola.withTag("silgi").info("Shutting down...");
36
+ if (watch) watch.close();
37
+ await watch.close();
38
+ process.exit(0);
39
+ });
40
+ consola.withTag("silgi").success("Prepare completed");
41
+ consola.withTag("silgi").info("Process is still running. Press Ctrl+C to exit.");
42
+ setInterval(() => {}, 1e3);
43
+ }
44
+ });
45
+ var watch_default = command;
46
+
47
+ //#endregion
48
+ export { watch_default as default };
@@ -0,0 +1,117 @@
1
+ import { isDebug, isTest } from "std-env";
2
+
3
+ //#region src/cli/config/defaults.ts
4
+ const SilgiCLIDefaults = {
5
+ debug: isDebug === true ? true : void 0,
6
+ schemaVendor: "zod",
7
+ logLevel: isTest ? 1 : 3,
8
+ appConfig: {},
9
+ appConfigFiles: [],
10
+ commandType: "prepare",
11
+ commands: [],
12
+ runtimeConfig: { silgi: {} },
13
+ storages: [],
14
+ devServer: { watch: [] },
15
+ package: {
16
+ name: "",
17
+ present: "npm-package"
18
+ },
19
+ scanDirs: [],
20
+ build: {
21
+ dir: ".silgi",
22
+ typesDir: "{{ build.dir }}/types",
23
+ templates: []
24
+ },
25
+ output: {
26
+ dir: "{{ rootDir }}/.output",
27
+ serverDir: "{{ output.dir }}/server",
28
+ publicDir: "{{ output.dir }}/public"
29
+ },
30
+ serverDir: "{{ rootDir }}/server",
31
+ clientDir: "{{ rootDir }}/client",
32
+ migrationDir: "{{ rootDir }}/migration",
33
+ silgi: {
34
+ serverDir: "{{ serverDir }}/silgi",
35
+ clientDir: "{{ clientDir }}/silgi",
36
+ publicDir: "{{ silgi.serverDir }}/public",
37
+ utilsDir: "{{ silgi.serverDir }}/utils",
38
+ vfsDir: "{{ silgi.serverDir }}/vfs",
39
+ typesDir: "{{ silgi.serverDir }}/types"
40
+ },
41
+ codegen: { env: { safeList: [["silgi", "version"]] } },
42
+ _modules: [],
43
+ modules: [],
44
+ future: {},
45
+ storage: {},
46
+ devStorage: {},
47
+ stub: false,
48
+ plugins: [],
49
+ imports: {
50
+ exclude: [],
51
+ dirs: [],
52
+ presets: [],
53
+ virtualImports: ["#silgiImports"]
54
+ },
55
+ ignore: [
56
+ "**/*.stories.{js,cts,mts,ts,jsx,tsx}",
57
+ "**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}",
58
+ "**/*.d.{cts,mts,ts}",
59
+ "**/.{pnpm-store,vercel,netlify,output,git,cache,data}",
60
+ ".silgi",
61
+ "**/-*.*"
62
+ ],
63
+ dev: false,
64
+ watchOptions: {
65
+ ignoreInitial: true,
66
+ ignored: [
67
+ "**/node_modules/**",
68
+ "**/.git/**",
69
+ "**/.silgi/**",
70
+ "**/.output/**",
71
+ "**/.vscode/**",
72
+ "**/.idea/**",
73
+ "**/.nuxt/**",
74
+ "**/.gitignore",
75
+ "**/.gitattributes",
76
+ "**/assets/**",
77
+ "**/dist/**",
78
+ "**/build/**",
79
+ "**/coverage/**",
80
+ "**/test/**",
81
+ "**/tests/**",
82
+ "**/tmp/**"
83
+ ]
84
+ },
85
+ typescript: {
86
+ generateTsConfig: true,
87
+ tsconfigPath: ".silgi/types/silgi.tsconfig.json",
88
+ tsConfig: {},
89
+ customConditions: [],
90
+ generateRuntimeConfigTypes: true,
91
+ removeFileExtension: false
92
+ },
93
+ conditions: [],
94
+ nodeModulesDirs: [],
95
+ hooks: {},
96
+ framework: {
97
+ name: "h3",
98
+ version: ""
99
+ },
100
+ extensions: [
101
+ ".js",
102
+ ".jsx",
103
+ ".mjs",
104
+ ".ts",
105
+ ".tsx",
106
+ ".vue"
107
+ ],
108
+ ignoreOptions: void 0,
109
+ apiFul: {},
110
+ installPackages: {
111
+ dependencies: {},
112
+ devDependencies: {}
113
+ }
114
+ };
115
+
116
+ //#endregion
117
+ export { SilgiCLIDefaults };
@@ -1,11 +1,3 @@
1
- import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI } from 'silgi/types';
2
- import { TSConfig } from 'pkg-types';
3
-
4
- declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
5
-
6
- declare function silgiGenerateType(silgi: SilgiCLI): Promise<{
7
- declarations: string[];
8
- tsConfig: TSConfig;
9
- }>;
10
-
11
- export { loadOptions, silgiGenerateType };
1
+ import { loadOptions$1 as loadOptions } from "./loader.mjs";
2
+ import { silgiGenerateType$1 as silgiGenerateType } from "./types.mjs";
3
+ export { loadOptions, silgiGenerateType };
@@ -1,17 +1,4 @@
1
- export { l as loadOptions } from '../loader.mjs';
2
- export { s as silgiGenerateType } from '../types.mjs';
3
- import 'c12';
4
- import 'compatx';
5
- import 'klona/full';
6
- import 'std-env';
7
- import 'consola';
8
- import 'consola/utils';
9
- import 'pathe';
10
- import 'escape-string-regexp';
11
- import 'mlly';
12
- import 'node:fs';
13
- import 'pkg-types';
14
- import 'silgi/kit';
15
- import 'silgi/runtime/meta';
16
- import 'ufo';
17
- import 'defu';
1
+ import { loadOptions } from "./loader.mjs";
2
+ import { silgiGenerateType } from "./types.mjs";
3
+
4
+ export { loadOptions, silgiGenerateType };
@@ -0,0 +1,6 @@
1
+ import { LoadConfigOptions, SilgiCLIConfig, SilgiCLIOptions } from "silgi/types";
2
+
3
+ //#region src/cli/config/loader.d.ts
4
+ declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
5
+ //#endregion
6
+ export { loadOptions as loadOptions$1 };
@@ -0,0 +1,71 @@
1
+ import { SilgiCLIDefaults } from "./defaults.mjs";
2
+ import { fallbackCompatibilityDate, resolveCompatibilityOptions } from "./resolvers/compatibility.mjs";
3
+ import { resolveImportsOptions } from "./resolvers/imports.mjs";
4
+ import { resolvePathOptions } from "./resolvers/paths.mjs";
5
+ import { resolveStorageOptions } from "./resolvers/storage.mjs";
6
+ import { resolveURLOptions } from "./resolvers/url.mjs";
7
+ import { loadConfig, watchConfig } from "c12";
8
+ import { resolveCompatibilityDates } from "compatx";
9
+ import { klona } from "klona/full";
10
+
11
+ //#region src/cli/config/loader.ts
12
+ const configResolvers = [
13
+ resolveCompatibilityOptions,
14
+ resolvePathOptions,
15
+ resolveImportsOptions,
16
+ resolveURLOptions,
17
+ resolveStorageOptions
18
+ ];
19
+ async function loadOptions(configOverrides = {}, opts = {}) {
20
+ const options = await _loadUserConfig(configOverrides, opts);
21
+ for (const resolver of configResolvers) await resolver(options);
22
+ return options;
23
+ }
24
+ async function _loadUserConfig(configOverrides = {}, opts = {}) {
25
+ const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
26
+ if (configOverrides.dev) {}
27
+ configOverrides = klona(configOverrides);
28
+ globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
29
+ let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE;
30
+ const { resolvePreset } = await import("silgi/presets");
31
+ const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
32
+ name: "silgi",
33
+ cwd: configOverrides.rootDir,
34
+ dotenv: configOverrides.dev,
35
+ extend: { extendKey: ["extends", "preset"] },
36
+ overrides: {
37
+ ...configOverrides,
38
+ preset: presetOverride
39
+ },
40
+ async defaultConfig({ configs }) {
41
+ const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
42
+ if (!compatibilityDate) compatibilityDate = getConf("compatibilityDate");
43
+ return { preset: presetOverride || (await resolvePreset("", {
44
+ static: getConf("static"),
45
+ compatibilityDate: compatibilityDate || fallbackCompatibilityDate
46
+ }))?._meta?.name };
47
+ },
48
+ defaults: SilgiCLIDefaults,
49
+ jitiOptions: { alias: { "silgi/config": "silgi/config" } },
50
+ async resolve(id) {
51
+ const preset = await resolvePreset(id, {
52
+ static: configOverrides.static,
53
+ compatibilityDate: compatibilityDate || fallbackCompatibilityDate
54
+ });
55
+ if (preset) return { config: klona(preset) };
56
+ },
57
+ ...opts.c12
58
+ });
59
+ delete globalThis.defineSilgiConfig;
60
+ const options = klona(loadedConfig.config);
61
+ options._config = configOverrides;
62
+ options._c12 = loadedConfig;
63
+ const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
64
+ options.preset = _presetName;
65
+ options.package.present = _presetName;
66
+ options.compatibilityDate = resolveCompatibilityDates(compatibilityDate, options.compatibilityDate);
67
+ return options;
68
+ }
69
+
70
+ //#endregion
71
+ export { loadOptions };
@@ -0,0 +1,71 @@
1
+ import consola from "consola";
2
+ import { relative } from "pathe";
3
+ import { formatDate, resolveCompatibilityDatesFromEnv } from "compatx";
4
+ import { colors } from "consola/utils";
5
+
6
+ //#region src/cli/config/resolvers/compatibility.ts
7
+ const fallbackCompatibilityDate = "2025-02-04";
8
+ async function resolveCompatibilityOptions(options) {
9
+ options.compatibilityDate = resolveCompatibilityDatesFromEnv(options.compatibilityDate);
10
+ if (!options.compatibilityDate.default) options.compatibilityDate.default = await _resolveDefault(options);
11
+ }
12
+ let _fallbackInfoShown = false;
13
+ let _promptedUserToUpdate = false;
14
+ async function _resolveDefault(options) {
15
+ const _todayDate = formatDate(new Date());
16
+ const consola$2 = consola.withTag("silgi");
17
+ consola$2.warn(`No valid compatibility date is specified.`);
18
+ const onFallback = () => {
19
+ if (!_fallbackInfoShown) {
20
+ consola$2.info([
21
+ `Using \`${fallbackCompatibilityDate}\` as fallback.`,
22
+ ` Please specify compatibility date to avoid unwanted behavior changes:`,
23
+ ` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
24
+ ` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
25
+ ``
26
+ ].join("\n"));
27
+ _fallbackInfoShown = true;
28
+ }
29
+ return fallbackCompatibilityDate;
30
+ };
31
+ const shallUpdate = !_promptedUserToUpdate && await consola$2.prompt(`Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`, {
32
+ type: "confirm",
33
+ default: true
34
+ });
35
+ _promptedUserToUpdate = true;
36
+ if (!shallUpdate) return onFallback();
37
+ const { updateConfig } = await import("c12/update");
38
+ const updateResult = await updateConfig({
39
+ configFile: "silgi.config",
40
+ cwd: options.rootDir,
41
+ async onCreate({ configFile }) {
42
+ const shallCreate = await consola$2.prompt(`Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`, {
43
+ type: "confirm",
44
+ default: true
45
+ });
46
+ if (shallCreate !== true) return false;
47
+ return _getDefaultNitroConfig();
48
+ },
49
+ async onUpdate(config) {
50
+ config.compatibilityDate = _todayDate;
51
+ }
52
+ }).catch((error) => {
53
+ consola$2.error(`Failed to update config: ${error.message}`);
54
+ return null;
55
+ });
56
+ if (updateResult?.configFile) {
57
+ consola$2.success(`Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``);
58
+ return _todayDate;
59
+ }
60
+ return onFallback();
61
+ }
62
+ function _getDefaultNitroConfig() {
63
+ return `
64
+ import { defineSilgiConfig } from 'silgi/config'
65
+
66
+ export default defineSilgiConfig({})
67
+ `;
68
+ }
69
+
70
+ //#endregion
71
+ export { fallbackCompatibilityDate, resolveCompatibilityOptions };
@@ -0,0 +1,35 @@
1
+ import { join } from "pathe";
2
+ import escapeRE from "escape-string-regexp";
3
+ import { resolveModuleExportNames } from "mlly";
4
+
5
+ //#region src/cli/config/resolvers/imports.ts
6
+ async function resolveImportsOptions(options) {
7
+ if (options.imports === false) return;
8
+ options.imports.presets ??= [];
9
+ options.imports.presets.push(...getSilgiImportsPreset());
10
+ if (options.preset === "h3") {
11
+ const h3Exports = await resolveModuleExportNames("h3", { url: import.meta.url });
12
+ options.imports.presets ??= [];
13
+ options.imports.presets.push({
14
+ from: "h3",
15
+ imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
16
+ });
17
+ }
18
+ options.imports.dirs ??= [];
19
+ options.imports.dirs.push(...options.scanDirs.map((dir) => join(dir, "utils/**/*")));
20
+ if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
21
+ options.imports.exclude.push(/[/\\]\.git[/\\]/);
22
+ options.imports.exclude.push(options.build.dir);
23
+ const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
24
+ options.imports.exclude.push(scanDirsInNodeModules.length > 0 ? new RegExp(`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`) : /[/\\]node_modules[/\\]/);
25
+ }
26
+ }
27
+ function getSilgiImportsPreset() {
28
+ return [{
29
+ from: "silgi",
30
+ imports: ["useSilgiStorage"]
31
+ }];
32
+ }
33
+
34
+ //#endregion
35
+ export { resolveImportsOptions };
@@ -0,0 +1,98 @@
1
+ import { SilgiCLIDefaults } from "../defaults.mjs";
2
+ import { join, resolve } from "pathe";
3
+ import { resolveSilgiPath } from "silgi/kit";
4
+ import { pkgDir, runtimeDir } from "silgi/runtime/meta";
5
+ import { existsSync } from "node:fs";
6
+ import { findWorkspaceDir, readPackageJSON } from "pkg-types";
7
+
8
+ //#region src/cli/config/resolvers/paths.ts
9
+ async function resolvePathOptions(options) {
10
+ options.rootDir = resolve(options.rootDir || ".");
11
+ options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(() => options.rootDir);
12
+ options.srcDir = resolve(options.srcDir || options.rootDir);
13
+ for (const key of ["srcDir"]) options[key] = resolve(options.rootDir, options[key]);
14
+ options.build.dir = resolve(options.rootDir, options.build.dir);
15
+ options.build.typesDir = resolveSilgiPath(options.build.typesDir || SilgiCLIDefaults.build.typesDir, options, options.rootDir);
16
+ if (options.preset === "npm-package") {
17
+ const packageJsonPath = resolve(options.rootDir, "package.json");
18
+ const packageJson = await readPackageJSON(packageJsonPath);
19
+ if (packageJson.name === void 0) throw new Error("Package name is undefined");
20
+ options.alias ||= {};
21
+ options.alias[packageJson.name] = join(options.rootDir, "src/module");
22
+ options.alias[`${packageJson.name}/runtime`] = join(options.rootDir, "src/runtime");
23
+ options.alias[`${packageJson.name}/data`] = join(options.rootDir, "src/data");
24
+ options.alias[`${packageJson.name}/data/*`] = join(options.rootDir, "src/data/*");
25
+ options.alias[`${packageJson.name}/runtime/*`] = join(options.rootDir, "src/runtime/*");
26
+ options.alias[`${packageJson.name}/types`] = join(options.rootDir, "src/types");
27
+ }
28
+ if (options.stub) options.alias = {
29
+ ...options.alias,
30
+ "silgi/runtime": join(runtimeDir),
31
+ "silgi/runtime/*": join(runtimeDir, "*")
32
+ };
33
+ options.alias = {
34
+ ...options.alias,
35
+ "#server/*": join(options.silgi.serverDir, "/*"),
36
+ "#silgi/*": join(options.build.dir, "/*"),
37
+ "#types/*": join(options.build.typesDir, "/*")
38
+ };
39
+ if (options.preset === "npm-package") options.alias = { ...options.alias };
40
+ if (options.alias && typeof options.alias === "object") {
41
+ ((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
42
+ const paths = options.typescript.tsConfig.compilerOptions.paths;
43
+ for (const [key, value] of Object.entries(options.alias)) if (typeof paths === "object") paths[key] = [value];
44
+ }
45
+ if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
46
+ ((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
47
+ const paths = options.typescript.tsConfig.compilerOptions.paths;
48
+ for (const [key, value] of Object.entries(options.alias)) if (typeof paths === "object") paths[key] = [value];
49
+ }
50
+ options.modulesDir = [resolve(options.rootDir, "node_modules")];
51
+ options.output.dir = resolveSilgiPath(options.output.dir || SilgiCLIDefaults.output.dir, options, options.rootDir);
52
+ options.output.publicDir = resolveSilgiPath(options.output.publicDir || SilgiCLIDefaults.output.publicDir, options, options.rootDir);
53
+ options.output.serverDir = resolveSilgiPath(options.output.serverDir || SilgiCLIDefaults.output.serverDir, options, options.rootDir);
54
+ options.serverDir = resolveSilgiPath(options.serverDir || SilgiCLIDefaults.serverDir, options, options.rootDir);
55
+ options.clientDir = resolveSilgiPath(options.clientDir || SilgiCLIDefaults.clientDir, options, options.rootDir);
56
+ options.silgi.serverDir = resolveSilgiPath(options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir, options, options.rootDir);
57
+ options.silgi.clientDir = resolveSilgiPath(options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir, options, options.rootDir);
58
+ options.silgi.publicDir = resolveSilgiPath(options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir, options, options.rootDir);
59
+ options.silgi.utilsDir = resolveSilgiPath(options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir, options, options.rootDir);
60
+ options.silgi.vfsDir = resolveSilgiPath(options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir, options, options.rootDir);
61
+ options.silgi.typesDir = resolveSilgiPath(options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir, options, options.rootDir);
62
+ options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
63
+ options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
64
+ options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
65
+ options.nodeModulesDirs.push(resolve(pkgDir, ".."));
66
+ options.nodeModulesDirs = [...new Set(options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir)))];
67
+ options.scanDirs.unshift(options.srcDir);
68
+ options.scanDirs = options.scanDirs.map((dir) => resolve(options.srcDir, dir));
69
+ options.scanDirs = [...new Set(options.scanDirs)];
70
+ options.appConfigFiles ??= [];
71
+ options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
72
+ for (const dir of options.scanDirs) {
73
+ const configFile = _tryResolve("app.config", dir);
74
+ if (configFile && !options.appConfigFiles.includes(configFile)) options.appConfigFiles.push(configFile);
75
+ }
76
+ options.watchOptions.ignored ??= [];
77
+ options.watchOptions.ignoreInitial = true;
78
+ if (Array.isArray(options.watchOptions.ignored)) options.watchOptions.ignored.push(`!${join(options.silgi.serverDir, "config")}`, `${join(options.silgi.serverDir, "permission.ts")}`, `${join(options.silgi.serverDir, "core.ts")}`, `${join(options.silgi.serverDir, "meta.ts")}`, `${join(options.silgi.serverDir, "configs.ts")}`, `${join(options.silgi.serverDir, "vfs")}`, `${join(options.silgi.serverDir, "scan.ts")}`);
79
+ options.devServer.watch.push(join(options.serverDir, "services"), join(options.serverDir, "schemas"), join(options.serverDir, "shared"), join(options.serverDir, "utils"), join(options.serverDir, "types"), join(options.silgi.serverDir, "config"), join(options.silgi.serverDir, "modules"), join(options.rootDir, "silgi.config.ts"));
80
+ }
81
+ function _tryResolve(path, base = ".", extensions = [
82
+ "",
83
+ ".js",
84
+ ".ts",
85
+ ".mjs",
86
+ ".cjs",
87
+ ".json"
88
+ ]) {
89
+ path = resolve(base, path);
90
+ if (existsSync(path)) return path;
91
+ for (const ext of extensions) {
92
+ const p = path + ext;
93
+ if (existsSync(p)) return p;
94
+ }
95
+ }
96
+
97
+ //#endregion
98
+ export { resolvePathOptions };
@@ -0,0 +1,23 @@
1
+ import { resolve } from "pathe";
2
+
3
+ //#region src/cli/config/resolvers/storage.ts
4
+ async function resolveStorageOptions(options) {
5
+ const fsMounts = {
6
+ root: resolve(options.rootDir),
7
+ src: resolve(options.srcDir),
8
+ build: resolve(options.build.dir),
9
+ cache: resolve(options.build.dir, "cache")
10
+ };
11
+ for (const p in fsMounts) options.devStorage[p] = options.devStorage[p] || {
12
+ driver: "fs",
13
+ readOnly: p === "root" || p === "src",
14
+ base: fsMounts[p]
15
+ };
16
+ if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) options.devStorage.data = {
17
+ driver: "fs",
18
+ base: resolve(options.rootDir, ".data/kv")
19
+ };
20
+ }
21
+
22
+ //#endregion
23
+ export { resolveStorageOptions };
@@ -0,0 +1,9 @@
1
+ import { withLeadingSlash, withTrailingSlash } from "ufo";
2
+
3
+ //#region src/cli/config/resolvers/url.ts
4
+ async function resolveURLOptions(options) {
5
+ options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
6
+ }
7
+
8
+ //#endregion
9
+ export { resolveURLOptions };
@@ -0,0 +1,14 @@
1
+ import { TSConfig } from "pkg-types";
2
+ import { SilgiCLI } from "silgi/types";
3
+
4
+ //#region src/cli/config/types.d.ts
5
+
6
+ // const EXTENSION_RE = /\b\.\w+$/g
7
+ // Exclude bridge alias types to support Volar
8
+ // const excludedAlias = [/^@vue\/.*$/, /^#internal\/nuxt/]
9
+ declare function silgiGenerateType(silgi: SilgiCLI): Promise<{
10
+ declarations: string[];
11
+ tsConfig: TSConfig;
12
+ }>;
13
+ //#endregion
14
+ export { silgiGenerateType as silgiGenerateType$1 };