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
@@ -1,188 +0,0 @@
1
- import { defineCommand, runCommand } from 'citty';
2
- import { resolve } from 'pathe';
3
- import { readPackageJSON } from 'pkg-types';
4
- import { version } from 'silgi/meta';
5
- import { p as prepareEnv, c as createSilgiCLI, b as build } from './build.mjs';
6
- import { c as commonArgs } from './common.mjs';
7
- import { execSync } from 'node:child_process';
8
- import * as p from '@clack/prompts';
9
- import { isCancel, cancel } from '@clack/prompts';
10
- import { consola } from 'consola';
11
- import { createJiti } from 'dev-jiti';
12
- import { useSilgiCLI } from 'silgi';
13
- import { a as silgiCLIIClose } from '../_chunks/silgiApp.mjs';
14
- import { l as loadOptions } from './loader.mjs';
15
-
16
- function cancelOnCancel({
17
- value,
18
- message = "Cancelled",
19
- onBeforeExit,
20
- exitCode = 0
21
- } = {}) {
22
- const handleCancel = () => {
23
- cancel(message);
24
- onBeforeExit?.();
25
- process.exit(exitCode);
26
- };
27
- if (!value || isCancel(value))
28
- handleCancel();
29
- }
30
-
31
- const command$1 = defineCommand({
32
- meta: {
33
- name: "run",
34
- description: "Run a command from the CLI",
35
- version: version
36
- },
37
- args: {
38
- ...commonArgs,
39
- preset: {
40
- type: "string",
41
- description: "The build preset to use (you can also use `SILGI_PRESET` environment variable)."
42
- },
43
- tag: {
44
- type: "string"
45
- },
46
- prepare: {
47
- type: "boolean",
48
- description: "Run in silgi development mode",
49
- default: true
50
- }
51
- },
52
- async run({ args }) {
53
- if (args.prepare) {
54
- await runCommand(command, {
55
- rawArgs: ["--commandType", "commands"]
56
- });
57
- }
58
- const silgi = useSilgiCLI();
59
- if (!silgi) {
60
- throw new Error("Silgi is not initialized");
61
- }
62
- const commands = silgi.options.commands;
63
- const tags = args.tag?.split(",").map((t) => t.trim());
64
- const silgiConfig = await loadOptions({});
65
- await prepareEnv(silgiConfig);
66
- let selectedCommands = [];
67
- if (tags?.length) {
68
- selectedCommands = commands.filter((cmd) => cmd.tags?.some((tag) => tags.includes(tag))).filter((cmd) => cmd.when !== false);
69
- } else {
70
- selectedCommands = commands.filter((cmd) => cmd.when !== false);
71
- }
72
- if (!selectedCommands.length) {
73
- return;
74
- }
75
- const multiSelect = await p.groupMultiselect({
76
- message: "Select commands to run",
77
- required: true,
78
- options: {
79
- ...selectedCommands.sort((a, b) => (a.order || Infinity) - (b.order || Infinity)).reduce((acc, cmd) => {
80
- if (!acc[cmd.group || ""]) {
81
- acc[cmd.group || ""] = [];
82
- }
83
- acc[cmd.group || ""].push({
84
- label: cmd.name,
85
- value: cmd,
86
- hint: cmd.description
87
- });
88
- return acc;
89
- }, {})
90
- }
91
- });
92
- cancelOnCancel({ value: multiSelect });
93
- selectedCommands = multiSelect;
94
- const spinner = p.spinner({
95
- indicator: "dots"
96
- });
97
- for (const cmd of selectedCommands) {
98
- const data = cmd.getContents({ app: silgi });
99
- spinner.start(`[${cmd.group}] ${cmd.name}...`);
100
- if (cmd.type === "command") {
101
- execSync(data, { stdio: "inherit" });
102
- }
103
- if (cmd.type === "function") {
104
- const jiti = createJiti(import.meta.url, {
105
- alias: silgiConfig.alias
106
- });
107
- let cleanHandler = cmd.getContents({ app: silgi }).replace(/\n/g, "");
108
- cleanHandler = `import { silgiCLICtx } from 'silgi'
109
- ${cleanHandler}
110
- `;
111
- await jiti.evalModule(cleanHandler, {
112
- filename: import.meta.url,
113
- async: true,
114
- conditions: silgiConfig.conditions,
115
- forceTranspile: true
116
- });
117
- }
118
- spinner.stop();
119
- consola.success(`[${cmd.group}] ${cmd.name} done`);
120
- }
121
- await silgiCLIIClose();
122
- }
123
- });
124
-
125
- const commands = {
126
- __proto__: null,
127
- default: command$1
128
- };
129
-
130
- const command = defineCommand({
131
- meta: {
132
- name: "prepare",
133
- description: "Generate types for the project",
134
- version: version
135
- },
136
- args: {
137
- ...commonArgs,
138
- preset: {
139
- type: "string",
140
- description: "The build preset to use (you can also use `SILGI_PRESET` environment variable)."
141
- },
142
- stub: {
143
- type: "boolean",
144
- description: "Run in silgi development mode"
145
- },
146
- dev: {
147
- type: "boolean",
148
- description: "Run in silgi development mode"
149
- },
150
- env: {
151
- type: "string",
152
- description: "The environment to use"
153
- },
154
- commandType: {
155
- type: "string",
156
- description: "The command type to run"
157
- }
158
- },
159
- async run({ args }) {
160
- const rootDir = resolve(args.dir || args._dir || ".");
161
- const packageJson = await readPackageJSON(rootDir);
162
- const packageName = packageJson.name || "";
163
- const silgi = await createSilgiCLI({
164
- rootDir,
165
- dev: args.dev || args.stub,
166
- stub: args.stub,
167
- preset: args.preset,
168
- commandType: args.commandType || "prepare",
169
- activeEnvironment: args.env,
170
- package: {
171
- name: packageName
172
- }
173
- });
174
- await build(silgi);
175
- if (args.commandType !== "commands") {
176
- await runCommand(command$1, {
177
- rawArgs: ["--tag", "init", "--prepare", "false"]
178
- });
179
- }
180
- }
181
- });
182
-
183
- const prepare = {
184
- __proto__: null,
185
- default: command
186
- };
187
-
188
- export { command as a, commands as b, cancelOnCancel as c, prepare as p };
@@ -1,55 +0,0 @@
1
- import fsp from 'node:fs/promises';
2
- import { defineCommand } from 'citty';
3
- import consola from 'consola';
4
- import { resolve, join } from 'pathe';
5
- import { version } from 'silgi/meta';
6
- import { l as loadOptions } from './loader.mjs';
7
- import { c as commonArgs } from './common.mjs';
8
- import 'c12';
9
- import 'compatx';
10
- import 'klona/full';
11
- import 'std-env';
12
- import 'consola/utils';
13
- import 'escape-string-regexp';
14
- import 'mlly';
15
- import 'node:fs';
16
- import 'pkg-types';
17
- import 'silgi/kit';
18
- import 'silgi/runtime/meta';
19
- import 'ufo';
20
-
21
- const command = defineCommand({
22
- meta: {
23
- name: "prepare",
24
- description: "Generate types for the project",
25
- version: version
26
- },
27
- args: {
28
- ...commonArgs
29
- },
30
- async run({ args }) {
31
- const rootDir = resolve(args.dir || args._dir || ".");
32
- const options = await loadOptions({
33
- rootDir
34
- }, {});
35
- const serverDir = options.silgi.serverDir;
36
- const vfs = join(serverDir, "vfs");
37
- const configs = join(serverDir, "configs.ts");
38
- const core = join(serverDir, "core.ts");
39
- const scan = join(serverDir, "scan.ts");
40
- const meta = join(serverDir, "meta.ts");
41
- const silgiDir = options.build.dir;
42
- for (const file of [vfs, configs, core, scan, silgiDir, meta]) {
43
- try {
44
- await fsp.rm(file, {
45
- force: true,
46
- recursive: true
47
- });
48
- consola.success(`Removed ${file.replace(rootDir, "")}`);
49
- } catch {
50
- }
51
- }
52
- }
53
- });
54
-
55
- export { command as default };
package/dist/cli/run.mjs DELETED
@@ -1,159 +0,0 @@
1
- import { defineCommand, runCommand } from 'citty';
2
- import consola from 'consola';
3
- import { useSilgiCLI } from 'silgi';
4
- import { version } from 'silgi/meta';
5
- import { x } from 'tinyexec';
6
- import { w as watchDev } from './dev.mjs';
7
- import { c as commonArgs } from './common.mjs';
8
- import { a as command$1 } from './prepare.mjs';
9
- import 'chokidar';
10
- import 'pathe';
11
- import 'perfect-debounce';
12
- import '../_chunks/silgiApp.mjs';
13
- import 'unctx';
14
- import './build.mjs';
15
- import 'hookable';
16
- import 'silgi/kit';
17
- import 'silgi/runtime';
18
- import 'silgi/runtime/meta';
19
- import 'unimport';
20
- import '@clack/prompts';
21
- import 'node:fs';
22
- import 'dotenv';
23
- import 'knitwork';
24
- import 'node:path';
25
- import 'mlly';
26
- import 'dev-jiti';
27
- import './compatibility.mjs';
28
- import 'semver/functions/satisfies.js';
29
- import 'node:url';
30
- import 'defu';
31
- import 'exsolve';
32
- import 'ufo';
33
- import 'node:fs/promises';
34
- import 'micromatch';
35
- import 'oxc-parser';
36
- import 'tinyglobby';
37
- import 'ignore';
38
- import 'scule';
39
- import 'klona';
40
- import 'unstorage';
41
- import './loader.mjs';
42
- import 'c12';
43
- import 'compatx';
44
- import 'klona/full';
45
- import 'std-env';
46
- import 'consola/utils';
47
- import 'escape-string-regexp';
48
- import 'pkg-types';
49
- import 'apiful/openapi';
50
- import 'pathe/utils';
51
- import 'untyped';
52
- import './types.mjs';
53
- import 'node:child_process';
54
-
55
- const command = defineCommand({
56
- meta: {
57
- name: "dev",
58
- description: "Start the development server for the project",
59
- version: version
60
- },
61
- args: {
62
- ...commonArgs,
63
- command: {
64
- type: "string",
65
- description: "your application start command",
66
- required: false
67
- }
68
- },
69
- async run({ args, rawArgs }) {
70
- await runCommand(command$1, {
71
- rawArgs: ["--commandType", "dev", "--dev", "true"]
72
- });
73
- const silgi = useSilgiCLI();
74
- const startCommand = args.command || rawArgs[0];
75
- let childPid = null;
76
- let hasExited = false;
77
- let exitTimeout = null;
78
- const cleanupAndExit = (code = 0) => {
79
- if (hasExited)
80
- return;
81
- hasExited = true;
82
- if (exitTimeout)
83
- clearTimeout(exitTimeout);
84
- process.exit(code);
85
- };
86
- const handleSignal = async (signal, watcher) => {
87
- consola.info(`Received ${signal}, terminating process...`);
88
- if (watcher && typeof watcher.close === "function") {
89
- try {
90
- await watcher.close();
91
- } catch {
92
- }
93
- }
94
- if (childPid) {
95
- try {
96
- process.kill(childPid, signal);
97
- } catch (err) {
98
- consola.error(`Failed to kill process: ${err instanceof Error ? err.message : err}`);
99
- }
100
- exitTimeout = setTimeout(() => {
101
- consola.warn("Process did not exit gracefully, forcing termination...");
102
- try {
103
- if (childPid)
104
- process.kill(childPid, "SIGKILL");
105
- } catch {
106
- }
107
- cleanupAndExit(1);
108
- }, 3e3);
109
- } else {
110
- cleanupAndExit(0);
111
- }
112
- };
113
- const setupSignalHandlers = (watcher) => {
114
- ["SIGINT", "SIGTERM", "SIGHUP"].forEach((signal) => {
115
- process.on(signal, () => {
116
- handleSignal(signal, watcher);
117
- });
118
- });
119
- };
120
- try {
121
- const watcher = await watchDev();
122
- setupSignalHandlers(watcher);
123
- consola.info(`Starting command: nr ${startCommand}`);
124
- const proc = x(
125
- "nr",
126
- [startCommand],
127
- {
128
- nodeOptions: {
129
- stdio: "inherit",
130
- shell: true,
131
- cwd: process.cwd(),
132
- killSignal: "SIGINT"
133
- }
134
- }
135
- );
136
- if (proc && typeof proc.pid === "number") {
137
- childPid = proc.pid;
138
- }
139
- try {
140
- await proc;
141
- consola.success(`Process exited successfully.`);
142
- cleanupAndExit(0);
143
- } catch (procError) {
144
- const exitCode = procError && typeof procError.exitCode === "number" ? procError.exitCode : 1;
145
- consola.error(`Process exited with code: ${exitCode}`);
146
- if (silgi.options.debug)
147
- consola.withTag("silgi").error("Error while running the command", procError);
148
- cleanupAndExit(exitCode);
149
- }
150
- } catch (error) {
151
- consola.error(`Failed to start the development server: ${error instanceof Error ? error.message : error}`);
152
- if (silgi.options.debug)
153
- consola.withTag("silgi").error("Error while running the command", error);
154
- cleanupAndExit(1);
155
- }
156
- }
157
- });
158
-
159
- export { command as default };
@@ -1,233 +0,0 @@
1
- import { promises, lstatSync } from 'node:fs';
2
- import { defu } from 'defu';
3
- import { resolve, dirname, join, isAbsolute, relative } from 'pathe';
4
- import { readPackageJSON } from 'pkg-types';
5
- import { relativeWithDot, resolveSilgiModule, isPresents } from 'silgi/kit';
6
- import { withTrailingSlash } from 'ufo';
7
-
8
- function getDirectory(p) {
9
- try {
10
- return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
11
- } catch {
12
- }
13
- return p;
14
- }
15
- function renderAttrs(obj) {
16
- const attrs = [];
17
- for (const key in obj) {
18
- attrs.push(renderAttr(key, obj[key]));
19
- }
20
- return attrs.join(" ");
21
- }
22
- function renderAttr(key, value) {
23
- return value ? `${key}="${value}"` : "";
24
- }
25
- async function silgiGenerateType(silgi) {
26
- const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
27
- const tsConfigPath = resolve(
28
- silgi.options.rootDir,
29
- silgi.options.typescript.tsconfigPath
30
- );
31
- const tsconfigDir = dirname(tsConfigPath);
32
- const include = /* @__PURE__ */ new Set([
33
- relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-config.d.ts")).replace(
34
- /^(?=[^.])/,
35
- "./"
36
- ),
37
- join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
38
- ...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
39
- ]);
40
- const exclude = /* @__PURE__ */ new Set([
41
- // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
42
- relativeWithDot(tsconfigDir, "node_modules"),
43
- relativeWithDot(tsconfigDir, "dist")
44
- ]);
45
- for (const dir of silgi.options.modulesDir) {
46
- exclude.add(relativeWithDot(silgi.options.build.dir, dir));
47
- }
48
- const moduleEntryPaths = [];
49
- for (const m of silgi.scanModules) {
50
- if (m.entryPath) {
51
- moduleEntryPaths.push(getDirectory(m.entryPath));
52
- }
53
- }
54
- const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
55
- for (const path of modulePaths) {
56
- const relative2 = relativeWithDot(tsconfigDir, path);
57
- include.add(join(relative2, "runtime"));
58
- exclude.add(join(relative2, "runtime/server"));
59
- include.add(join(relative2, "dist/runtime"));
60
- exclude.add(join(relative2, "dist/runtime/server"));
61
- }
62
- let tsConfig = silgi.options.typescript?.tsConfig || {};
63
- const defaultConfig = defu(tsConfig, {
64
- compilerOptions: {
65
- /* Base options: */
66
- esModuleInterop: true,
67
- allowSyntheticDefaultImports: true,
68
- skipLibCheck: true,
69
- allowImportingTsExtensions: true,
70
- baseUrl: "./",
71
- /* Target options: */
72
- target: "ESNext",
73
- allowJs: true,
74
- resolveJsonModule: true,
75
- moduleDetection: "force",
76
- isolatedModules: true,
77
- verbatimModuleSyntax: true,
78
- strict: true,
79
- noUncheckedIndexedAccess: true,
80
- noImplicitOverride: true,
81
- forceConsistentCasingInFileNames: true,
82
- noEmit: true,
83
- /* If NOT transpiling with TypeScript: */
84
- module: "Preserve",
85
- moduleResolution: "bundler",
86
- useDefineForClassFields: true,
87
- noImplicitThis: true,
88
- jsx: "preserve",
89
- customConditions: silgi.options.typescript.customConditions,
90
- paths: {
91
- // '#silgiImports': [
92
- // relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, 'silgi-imports')),
93
- // ],
94
- // ...(silgi.scanModules.reduce((acc: Record<string, string[]>, m) => {
95
- // if (m.entryPath) {
96
- // acc[m.meta.name!] = [relativeWithDot(tsconfigDir, m.entryPath)]
97
- // }
98
- // return acc
99
- // }, {})),
100
- // ...(silgi.scanModules.reduce((acc, m) => {
101
- // if (m.entryPath) {
102
- // const directory = getDirectory(m.entryPath)
103
- // // eslint-disable-next-line ts/ban-ts-comment
104
- // // @ts-ignore
105
- // acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`]
106
- // }
107
- // return acc
108
- // }, {})),
109
- }
110
- },
111
- include: [...include],
112
- exclude: [...exclude]
113
- });
114
- tsConfig = defaultConfig;
115
- if (isPresents(["hono"])) {
116
- tsConfig = defu(defaultConfig, {
117
- compilerOptions: {
118
- jsx: "react-jsx",
119
- jsxImportSource: "hono/jsx"
120
- }
121
- });
122
- }
123
- if (isPresents(["npm-package"])) {
124
- tsConfig = defu(tsConfig, {
125
- compilerOptions: {
126
- target: "es2022",
127
- lib: ["es2022", "webworker", "dom.iterable"],
128
- moduleDetection: "force",
129
- /* If NOT transpiling with TypeScript: */
130
- module: "preserve",
131
- paths: {},
132
- resolveJsonModule: true,
133
- allowJs: true,
134
- /* Strictness */
135
- strict: true,
136
- noImplicitOverride: true,
137
- noEmit: true,
138
- allowSyntheticDefaultImports: true,
139
- /* Base options: */
140
- esModuleInterop: false,
141
- forceConsistentCasingInFileNames: true,
142
- isolatedModules: true,
143
- verbatimModuleSyntax: true,
144
- skipLibCheck: true
145
- },
146
- // include: ['src', 'test', './moduleTypes.d.ts'],
147
- // exclude: ['dist', 'examples', 'playground', 'test/fixture'],
148
- include: [...include],
149
- exclude: [...exclude]
150
- });
151
- }
152
- if (isPresents(["next"])) {
153
- tsConfig = defu(tsConfig, {
154
- compilerOptions: {
155
- incremental: true,
156
- plugins: [
157
- { name: "next" }
158
- ],
159
- paths: {
160
- "@/*": [
161
- relativeWithDot(tsconfigDir, join(silgi.options.rootDir, "src", "*"))
162
- ]
163
- },
164
- lib: [
165
- "dom",
166
- "dom.iterable",
167
- "esnext"
168
- ],
169
- strictNullChecks: true
170
- },
171
- include: [
172
- relativeWithDot(tsconfigDir, join(silgi.options.rootDir, "next-env.d.ts")),
173
- relativeWithDot(tsconfigDir, join(silgi.options.rootDir, "**", "*.ts")),
174
- relativeWithDot(tsconfigDir, join(silgi.options.rootDir, "**", "*.tsx")),
175
- relativeWithDot(tsconfigDir, join(silgi.options.rootDir, ".next", "types", "**", "*.ts"))
176
- ]
177
- });
178
- }
179
- tsConfig.compilerOptions ||= {};
180
- tsConfig.compilerOptions.paths ||= {};
181
- tsConfig.include ||= [];
182
- for (const alias in tsConfig.compilerOptions.paths) {
183
- const paths = tsConfig.compilerOptions.paths[alias];
184
- tsConfig.compilerOptions.paths[alias] = await Promise.all(
185
- paths.map(async (path) => {
186
- if (!isAbsolute(path)) {
187
- return path;
188
- }
189
- const stats = await promises.stat(path).catch(
190
- () => null
191
- /* file does not exist */
192
- );
193
- return relativeWithDot(
194
- tsconfigDir,
195
- stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
196
- );
197
- })
198
- );
199
- }
200
- const references = [];
201
- await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
202
- if (typeof id !== "string") {
203
- return;
204
- }
205
- if (id === "./src" && silgi.options.preset === "npm-package") {
206
- id = resolve(silgi.options.rootDir);
207
- }
208
- const pkg = await readPackageJSON(id, { url: silgi.options.rootDir }).catch(() => null);
209
- references.push({ types: pkg?.name || id });
210
- }));
211
- const declarations = [];
212
- await silgi.callHook("prepare:types", { references, declarations, tsConfig });
213
- tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
214
- tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
215
- const _declarations = [
216
- ...references.map((ref) => {
217
- if ("path" in ref && isAbsolute(ref.path)) {
218
- ref.path = relative(silgi.options.build.dir, ref.path);
219
- }
220
- return `/// <reference ${renderAttrs(ref)} />`;
221
- }),
222
- ...declarations,
223
- "",
224
- "export {}",
225
- ""
226
- ];
227
- return {
228
- declarations: _declarations,
229
- tsConfig
230
- };
231
- }
232
-
233
- export { silgiGenerateType as s };