nitro 3.0.1-alpha.2 → 3.0.260311-beta

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 (255) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +2 -2
  3. package/dist/THIRD-PARTY-LICENSES.md +1646 -0
  4. package/dist/_build/common.mjs +6977 -2556
  5. package/dist/_build/rolldown.mjs +32 -31
  6. package/dist/_build/rollup.mjs +28 -35
  7. package/dist/_build/vite.build.mjs +10 -8
  8. package/dist/_chunks/nitro.mjs +80 -112
  9. package/dist/_chunks/nitro2.mjs +8 -7
  10. package/dist/_chunks/nitro3.mjs +129 -0
  11. package/dist/_chunks/utils.mjs +42 -24
  12. package/dist/_common.mjs +14 -24
  13. package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -320
  14. package/dist/_libs/_.mjs +3 -0
  15. package/dist/_libs/_2.mjs +2 -0
  16. package/dist/_libs/_3.mjs +3 -0
  17. package/dist/_libs/_4.mjs +2 -0
  18. package/dist/_libs/_5.mjs +3 -0
  19. package/dist/_libs/_6.mjs +4 -0
  20. package/dist/_libs/_7.mjs +5 -0
  21. package/dist/_libs/c12+rc9.mjs +812 -0
  22. package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +52 -36
  23. package/dist/_libs/citty.mjs +10 -12
  24. package/dist/_libs/commondir+is-reference.mjs +60 -49
  25. package/dist/_libs/compatx.mjs +1 -2
  26. package/dist/_libs/esbuild.d.mts +1 -1
  27. package/dist/_libs/escape-string-regexp.mjs +1 -2
  28. package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +2 -2
  29. package/dist/_libs/estree-walker.mjs +1 -4
  30. package/dist/_libs/exsolve.d.mts +1 -0
  31. package/dist/_libs/hasown+resolve+deepmerge.mjs +146 -169
  32. package/dist/_libs/httpxy.d.mts +12 -9
  33. package/dist/_libs/httpxy.mjs +299 -43
  34. package/dist/_libs/js-tokens.d.mts +1 -0
  35. package/dist/_libs/klona.mjs +1 -2
  36. package/dist/_libs/mlly.d.mts +1 -1
  37. package/dist/_libs/nypm+tinyexec.mjs +845 -0
  38. package/dist/_libs/perfect-debounce.mjs +88 -0
  39. package/dist/_libs/plugin-alias.mjs +2 -4
  40. package/dist/_libs/plugin-inject.mjs +2 -6
  41. package/dist/_libs/plugin-json.mjs +2 -4
  42. package/dist/_libs/pluginutils.mjs +5 -11
  43. package/dist/_libs/readdirp+chokidar.mjs +187 -192
  44. package/dist/_libs/remapping.mjs +1 -3
  45. package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -21
  46. package/dist/_libs/rou3.d.mts +3 -2
  47. package/dist/_libs/rou3.mjs +225 -51
  48. package/dist/_libs/std-env.d.mts +10 -2
  49. package/dist/_libs/strip-literal.d.mts +1 -0
  50. package/dist/_libs/tsconfck.mjs +21 -40
  51. package/dist/_libs/ultrahtml.mjs +3 -14
  52. package/dist/_libs/unimport+unplugin.mjs +250 -351
  53. package/dist/_libs/unplugin+unimport.d.mts +7 -10
  54. package/dist/_presets.mjs +389 -432
  55. package/dist/builder.d.mts +5 -4
  56. package/dist/builder.mjs +12 -6
  57. package/dist/cli/_chunks/build.mjs +22 -23
  58. package/dist/cli/_chunks/common.mjs +1 -2
  59. package/dist/cli/_chunks/deploy.mjs +40 -0
  60. package/dist/cli/_chunks/dev.mjs +9 -9
  61. package/dist/cli/_chunks/docs.mjs +30 -0
  62. package/dist/cli/_chunks/list.mjs +4 -6
  63. package/dist/cli/_chunks/prepare.mjs +2 -4
  64. package/dist/cli/_chunks/preview.mjs +51 -0
  65. package/dist/cli/_chunks/run.mjs +7 -9
  66. package/dist/cli/_chunks/task.mjs +1 -3
  67. package/dist/cli/index.mjs +5 -4
  68. package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
  69. package/dist/node_modules/@poppinss/dumper/package.json +1 -1
  70. package/dist/node_modules/croner/dist/croner.js +1 -1
  71. package/dist/node_modules/croner/package.json +11 -1
  72. package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
  73. package/dist/node_modules/youch/build/index.js +204 -351
  74. package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
  75. package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
  76. package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
  77. package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
  78. package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
  79. package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
  80. package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
  81. package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
  82. package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
  83. package/dist/node_modules/youch/package.json +34 -31
  84. package/dist/presets/_nitro/runtime/nitro-dev.mjs +9 -56
  85. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
  86. package/dist/presets/_nitro/runtime/service-worker.mjs +0 -1
  87. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
  88. package/dist/presets/bun/runtime/bun.mjs +4 -3
  89. package/dist/presets/deno/runtime/deno-server.mjs +4 -3
  90. package/dist/presets/netlify/runtime/netlify-edge.mjs +0 -1
  91. package/dist/presets/netlify/runtime/netlify.mjs +1 -1
  92. package/dist/presets/node/runtime/node-cluster.mjs +3 -2
  93. package/dist/presets/node/runtime/node-server.mjs +3 -2
  94. package/dist/presets/stormkit/runtime/stormkit.mjs +0 -1
  95. package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
  96. package/dist/presets/vercel/runtime/vercel.web.mjs +2 -4
  97. package/dist/presets/zephyr/runtime/server.mjs +3 -0
  98. package/dist/runtime/internal/cache.d.mts +0 -4
  99. package/dist/runtime/internal/cache.mjs +32 -256
  100. package/dist/runtime/internal/context.d.mts +3 -1
  101. package/dist/runtime/internal/error/dev.d.mts +5 -4
  102. package/dist/runtime/internal/error/dev.mjs +38 -40
  103. package/dist/runtime/internal/error/hooks.d.mts +1 -1
  104. package/dist/runtime/internal/error/prod.d.mts +2 -5
  105. package/dist/runtime/internal/error/prod.mjs +19 -33
  106. package/dist/runtime/internal/error/utils.d.mts +4 -4
  107. package/dist/runtime/internal/meta.d.mts +1 -1
  108. package/dist/runtime/internal/plugin.d.mts +2 -2
  109. package/dist/runtime/internal/route-rules.d.mts +9 -4
  110. package/dist/runtime/internal/route-rules.mjs +9 -1
  111. package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
  112. package/dist/runtime/internal/routes/dev-tasks.mjs +6 -2
  113. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  114. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
  115. package/dist/runtime/internal/runtime-config.d.mts +1 -1
  116. package/dist/runtime/internal/static.mjs +5 -4
  117. package/dist/runtime/internal/task.d.mts +3 -1
  118. package/dist/runtime/internal/task.mjs +2 -2
  119. package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
  120. package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
  121. package/dist/runtime/meta.mjs +1 -0
  122. package/dist/runtime/nitro.d.mts +2 -0
  123. package/dist/runtime/nitro.mjs +2 -0
  124. package/dist/runtime/virtual/error-handler.mjs +1 -1
  125. package/dist/runtime/virtual/server-assets.d.mts +2 -1
  126. package/dist/runtime/vite.d.mts +1 -1
  127. package/dist/types/index.d.mts +68 -117
  128. package/dist/types/index.mjs +1 -11
  129. package/dist/vite.d.mts +3 -3
  130. package/dist/vite.mjs +236 -233
  131. package/package.json +83 -68
  132. package/skills/nitro/SKILL.md +10 -0
  133. package/skills/nitro/docs/TOC.md +83 -0
  134. package/skills/nitro/docs/_navigation.json +679 -0
  135. package/skills/nitro/docs/config/index.md +1147 -0
  136. package/skills/nitro/docs/deploy/index.md +64 -0
  137. package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
  138. package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
  139. package/skills/nitro/docs/deploy/providers/aws.md +47 -0
  140. package/skills/nitro/docs/deploy/providers/azure.md +72 -0
  141. package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
  142. package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
  143. package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
  144. package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
  145. package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
  146. package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
  147. package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
  148. package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
  149. package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
  150. package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
  151. package/skills/nitro/docs/deploy/providers/iis.md +38 -0
  152. package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
  153. package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
  154. package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
  155. package/skills/nitro/docs/deploy/providers/render.md +37 -0
  156. package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
  157. package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
  158. package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
  159. package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
  160. package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
  161. package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
  162. package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
  163. package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
  164. package/skills/nitro/docs/docs/assets.md +166 -0
  165. package/skills/nitro/docs/docs/cache.md +408 -0
  166. package/skills/nitro/docs/docs/configuration.md +256 -0
  167. package/skills/nitro/docs/docs/database.md +185 -0
  168. package/skills/nitro/docs/docs/index.md +56 -0
  169. package/skills/nitro/docs/docs/lifecycle.md +204 -0
  170. package/skills/nitro/docs/docs/migration.md +215 -0
  171. package/skills/nitro/docs/docs/nightly.md +31 -0
  172. package/skills/nitro/docs/docs/plugins.md +164 -0
  173. package/skills/nitro/docs/docs/quick-start.md +110 -0
  174. package/skills/nitro/docs/docs/renderer.md +322 -0
  175. package/skills/nitro/docs/docs/routing.md +711 -0
  176. package/skills/nitro/docs/docs/server-entry.md +239 -0
  177. package/skills/nitro/docs/docs/storage.md +261 -0
  178. package/skills/nitro/docs/docs/tasks.md +277 -0
  179. package/skills/nitro/docs/examples/api-routes.md +145 -0
  180. package/skills/nitro/docs/examples/auto-imports.md +93 -0
  181. package/skills/nitro/docs/examples/cached-handler.md +81 -0
  182. package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
  183. package/skills/nitro/docs/examples/database.md +157 -0
  184. package/skills/nitro/docs/examples/elysia.md +70 -0
  185. package/skills/nitro/docs/examples/express.md +78 -0
  186. package/skills/nitro/docs/examples/fastify.md +79 -0
  187. package/skills/nitro/docs/examples/hello-world.md +68 -0
  188. package/skills/nitro/docs/examples/hono.md +74 -0
  189. package/skills/nitro/docs/examples/import-alias.md +100 -0
  190. package/skills/nitro/docs/examples/index.md +3 -0
  191. package/skills/nitro/docs/examples/middleware.md +91 -0
  192. package/skills/nitro/docs/examples/mono-jsx.md +68 -0
  193. package/skills/nitro/docs/examples/nano-jsx.md +70 -0
  194. package/skills/nitro/docs/examples/plugins.md +91 -0
  195. package/skills/nitro/docs/examples/renderer.md +113 -0
  196. package/skills/nitro/docs/examples/runtime-config.md +97 -0
  197. package/skills/nitro/docs/examples/server-fetch.md +87 -0
  198. package/skills/nitro/docs/examples/shiki.md +198 -0
  199. package/skills/nitro/docs/examples/virtual-routes.md +74 -0
  200. package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
  201. package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
  202. package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
  203. package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
  204. package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
  205. package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
  206. package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
  207. package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
  208. package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
  209. package/skills/nitro/docs/examples/vite-trpc.md +335 -0
  210. package/skills/nitro/docs/examples/websocket.md +282 -0
  211. package/skills/nitro/docs/index.md +121 -0
  212. package/dist/_libs/confbox.mjs +0 -2509
  213. package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
  214. package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
  215. package/dist/node_modules/hookable/dist/index.mjs +0 -266
  216. package/dist/node_modules/hookable/package.json +0 -52
  217. package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
  218. package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
  219. package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
  220. package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
  221. package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
  222. package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
  223. package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
  224. package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
  225. package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
  226. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
  227. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
  228. package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
  229. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
  230. package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
  231. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
  232. package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
  233. package/dist/presets/azure/runtime/_utils.d.mts +0 -2
  234. package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
  235. package/dist/presets/bun/runtime/bun.d.mts +0 -3
  236. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
  237. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
  238. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
  239. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
  240. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
  241. package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
  242. package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
  243. package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
  244. package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
  245. package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
  246. package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
  247. package/dist/presets/node/runtime/node-server.d.mts +0 -3
  248. package/dist/presets/standard/runtime/server.d.mts +0 -3
  249. package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
  250. package/dist/presets/vercel/runtime/isr.d.mts +0 -2
  251. package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
  252. package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
  253. package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
  254. package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
  255. package/dist/runtime/internal/vite/node-runner.mjs +0 -359
@@ -0,0 +1,129 @@
1
+ import { F as prettyPath, ct as join, dt as resolve, m as getBuildInfo } from "../_build/common.mjs";
2
+ import { n as proxyFetch, r as proxyUpgrade } from "../_libs/httpxy.mjs";
3
+ import consola from "consola";
4
+ import { spawn } from "node:child_process";
5
+ //#region src/preview.ts
6
+ async function startPreview(opts) {
7
+ const { outputDir, buildInfo } = await getBuildInfo(opts.rootDir);
8
+ if (!buildInfo) throw new Error("Cannot load nitro build info. Make sure to build first.");
9
+ const info = [
10
+ ["Build Directory:", prettyPath(outputDir)],
11
+ ["Date:", buildInfo.date && new Date(buildInfo.date).toLocaleString()],
12
+ ["Nitro Version:", buildInfo.versions.nitro],
13
+ ["Nitro Preset:", buildInfo.preset],
14
+ buildInfo.framework?.name !== "nitro" && ["Framework:", buildInfo.framework?.name + (buildInfo.framework?.version ? ` (v${buildInfo.framework.version})` : "")]
15
+ ].filter((i) => i && i[1]);
16
+ consola.box({
17
+ title: " [Build Info] ",
18
+ message: info.map((i) => `- ${i[0]} ${i[1]}`).join("\n")
19
+ });
20
+ const dotEnvEntries = await loadPreviewDotEnv(opts.rootDir);
21
+ if (dotEnvEntries.length > 0) consola.box({
22
+ title: " [Environment Variables] ",
23
+ message: [
24
+ "Loaded variables from .env files (preview mode only).",
25
+ "Set platform environment variables for production:",
26
+ ...dotEnvEntries.map(([key, val]) => ` - ${key}`)
27
+ ].join("\n")
28
+ });
29
+ if (buildInfo.preset.includes("cloudflare")) {
30
+ if (!buildInfo.commands?.preview) throw new Error(`No nitro build preview command found for the "${buildInfo.preset}" preset.`);
31
+ return await runPreviewCommand({
32
+ command: buildInfo.commands.preview,
33
+ rootDir: opts.rootDir,
34
+ env: dotEnvEntries
35
+ });
36
+ }
37
+ let fetchHandler = () => Promise.resolve(new Response("Not Found", { status: 404 }));
38
+ if (buildInfo.serverEntry) {
39
+ for (const [key, val] of dotEnvEntries) if (!process.env[key]) process.env[key] = val;
40
+ const { loadServerEntry } = await import("srvx/loader");
41
+ const entry = await loadServerEntry({
42
+ entry: resolve(outputDir, buildInfo.serverEntry),
43
+ ...opts.loader
44
+ });
45
+ if (entry.fetch) fetchHandler = entry.fetch;
46
+ }
47
+ if (buildInfo.publicDir) {
48
+ const { serveStatic } = await import("srvx/static");
49
+ const staticHandler = serveStatic({ dir: join(outputDir, buildInfo.publicDir) });
50
+ const originalFetchHandler = fetchHandler;
51
+ fetchHandler = async (req) => {
52
+ const staticRes = await staticHandler(req, () => void 0);
53
+ if (staticRes) return staticRes;
54
+ return originalFetchHandler(req);
55
+ };
56
+ }
57
+ return {
58
+ fetch: fetchHandler,
59
+ async close() {}
60
+ };
61
+ }
62
+ async function loadPreviewDotEnv(root) {
63
+ const { loadDotenv } = await import("../_libs/_.mjs");
64
+ const env = await loadDotenv({
65
+ cwd: root,
66
+ fileName: [
67
+ ".env.preview",
68
+ ".env.production",
69
+ ".env"
70
+ ]
71
+ });
72
+ return Object.entries(env).filter(([_key, val]) => val);
73
+ }
74
+ async function runPreviewCommand(opts) {
75
+ const [arg0, ...args] = opts.command.split(" ");
76
+ consola.info(`Spawning preview server...`);
77
+ consola.info(opts.command);
78
+ console.log("");
79
+ const { getRandomPort, waitForPort } = await import("get-port-please");
80
+ const randomPort = await getRandomPort();
81
+ const child = spawn(arg0, [
82
+ ...args,
83
+ "--port",
84
+ String(randomPort),
85
+ "--host",
86
+ "localhost"
87
+ ], {
88
+ stdio: "inherit",
89
+ cwd: opts.rootDir,
90
+ env: {
91
+ ...process.env,
92
+ ...Object.fromEntries(opts.env ?? []),
93
+ PORT: String(randomPort)
94
+ }
95
+ });
96
+ const killChild = (signal) => {
97
+ if (child && !child.killed) child.kill(signal);
98
+ };
99
+ for (const sig of ["SIGINT", "SIGHUP"]) process.once(sig, () => {
100
+ killChild(sig);
101
+ });
102
+ child.once("exit", (code) => {
103
+ if (code && code !== 0) consola.error(`[nitro] Preview server exited with code ${code}`);
104
+ });
105
+ await waitForPort(randomPort, {
106
+ retries: 20,
107
+ delay: 500,
108
+ host: "localhost"
109
+ });
110
+ return {
111
+ fetch(req) {
112
+ return proxyFetch({
113
+ port: randomPort,
114
+ host: "localhost"
115
+ }, req);
116
+ },
117
+ async upgrade(req, socket, head, opts) {
118
+ await proxyUpgrade({
119
+ port: randomPort,
120
+ host: "localhost"
121
+ }, req, socket, head, opts);
122
+ },
123
+ async close() {
124
+ killChild("SIGTERM");
125
+ }
126
+ };
127
+ }
128
+ //#endregion
129
+ export { startPreview as t };
@@ -1,13 +1,11 @@
1
- import { i as __toESM, r as __require, t as __commonJSMin } from "../_common.mjs";
2
- import { N as glob, V as a, ct as resolve, nt as dirname, p as runParallel, st as relative } from "../_build/common.mjs";
3
- import fs, { promises } from "node:fs";
1
+ import { r as __require, t as __commonJSMin } from "../_common.mjs";
2
+ import { H as v, M as glob, V as m, at as dirname, dt as resolve, nt as resolveModulePath, p as runParallel, ut as relative } from "../_build/common.mjs";
3
+ import { consola as consola$1 } from "consola";
4
+ import { promises } from "node:fs";
4
5
  import { promisify } from "node:util";
5
6
  import { colors } from "consola/utils";
6
7
  import zlib from "node:zlib";
7
- import "node:stream";
8
-
9
- //#region node_modules/.pnpm/duplexer@0.1.2/node_modules/duplexer/index.js
10
- var require_duplexer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8
+ (/* @__PURE__ */ __commonJSMin(((exports, module) => {
11
9
  var Stream = __require("stream");
12
10
  var writeMethods = [
13
11
  "write",
@@ -53,8 +51,8 @@ var require_duplexer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
53
51
  }
54
52
  }
55
53
  function proxyStream(methodName) {
56
- reader.on(methodName, reemit$1);
57
- function reemit$1() {
54
+ reader.on(methodName, reemit);
55
+ function reemit() {
58
56
  var args = slice.call(arguments);
59
57
  args.unshift(methodName);
60
58
  stream.emit.apply(stream, args);
@@ -71,11 +69,7 @@ var require_duplexer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
71
69
  stream.emit("error", err);
72
70
  }
73
71
  }
74
- }));
75
-
76
- //#endregion
77
- //#region node_modules/.pnpm/gzip-size@7.0.0/node_modules/gzip-size/index.js
78
- var import_duplexer = /* @__PURE__ */ __toESM(require_duplexer(), 1);
72
+ })))();
79
73
  const getOptions = (options) => ({
80
74
  level: 9,
81
75
  ...options
@@ -85,7 +79,6 @@ async function gzipSize(input, options) {
85
79
  if (!input) return 0;
86
80
  return (await gzip(input, getOptions(options))).length;
87
81
  }
88
-
89
82
  //#endregion
90
83
  //#region node_modules/.pnpm/pretty-bytes@7.1.0/node_modules/pretty-bytes/index.js
91
84
  const BYTE_UNITS = [
@@ -200,11 +193,10 @@ function prettyBytes(number, options) {
200
193
  }
201
194
  return applyFixedWidth(result, options.fixedWidth);
202
195
  }
203
-
204
196
  //#endregion
205
197
  //#region src/utils/fs-tree.ts
206
198
  async function generateFSTree(dir, options = {}) {
207
- if (a) return;
199
+ if (v) return;
208
200
  const files = await glob("**/*.*", {
209
201
  cwd: dir,
210
202
  ignore: ["*.map"]
@@ -214,23 +206,23 @@ async function generateFSTree(dir, options = {}) {
214
206
  const path = resolve(dir, file);
215
207
  const src = await promises.readFile(path);
216
208
  const size = src.byteLength;
217
- const gzip$1 = options.compressedSizes ? await gzipSize(src) : 0;
209
+ const gzip = options.compressedSizes ? await gzipSize(src) : 0;
218
210
  items.push({
219
211
  file,
220
212
  path,
221
213
  size,
222
- gzip: gzip$1
214
+ gzip
223
215
  });
224
216
  }, { concurrency: 10 });
225
- items.sort((a$1, b) => a$1.path.localeCompare(b.path));
217
+ items.sort((a, b) => a.path.localeCompare(b.path));
226
218
  let totalSize = 0;
227
219
  let totalGzip = 0;
228
220
  let totalNodeModulesSize = 0;
229
221
  let totalNodeModulesGzip = 0;
230
222
  let treeText = "";
231
223
  for (const [index, item] of items.entries()) {
232
- let dir$1 = dirname(item.file);
233
- if (dir$1 === ".") dir$1 = "";
224
+ let dir = dirname(item.file);
225
+ if (dir === ".") dir = "";
234
226
  const rpath = relative(process.cwd(), item.path);
235
227
  const treeChar = index === items.length - 1 ? "└─" : "├─";
236
228
  if (item.file.includes("node_modules")) {
@@ -249,6 +241,32 @@ async function generateFSTree(dir, options = {}) {
249
241
  treeText += "\n";
250
242
  return treeText;
251
243
  }
252
-
253
244
  //#endregion
254
- export { generateFSTree as t };
245
+ //#region src/utils/dep.ts
246
+ async function importDep(opts, _retry) {
247
+ const resolved = resolveModulePath(opts.id, {
248
+ from: [opts.dir, import.meta.url],
249
+ cache: _retry ? false : true,
250
+ try: true
251
+ });
252
+ if (resolved) return await import(resolved);
253
+ let shouldInstall;
254
+ if (_retry || v) shouldInstall = false;
255
+ else if (m) {
256
+ consola$1.info(`\`${opts.id}\` is required for ${opts.reason}. Installing automatically in CI environment...`);
257
+ shouldInstall = true;
258
+ } else shouldInstall = await consola$1.prompt(`\`${opts.id}\` is required for ${opts.reason}, but it is not installed. Would you like to install it?`, {
259
+ type: "confirm",
260
+ default: true,
261
+ cancel: "undefined"
262
+ });
263
+ if (!shouldInstall) throw new Error(`\`${opts.id}\` is not installed. Please add it to your dependencies for ${opts.reason}.`);
264
+ const start = Date.now();
265
+ consola$1.start(`Installing \`${opts.id}\` in \`${opts.dir}\`...`);
266
+ const { addDevDependency } = await import("../_libs/_5.mjs");
267
+ await addDevDependency(opts.id, { cwd: opts.dir });
268
+ consola$1.success(`Installed \`${opts.id}\` in ${opts.dir} (${Date.now() - start}ms).`);
269
+ return importDep(opts, true);
270
+ }
271
+ //#endregion
272
+ export { generateFSTree as n, importDep as t };
package/dist/_common.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
-
3
- //#region rolldown:runtime
2
+ //#region \0rolldown/runtime.js
4
3
  var __create = Object.create;
5
4
  var __defProp = Object.defineProperty;
6
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -8,30 +7,22 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
8
7
  var __getProtoOf = Object.getPrototypeOf;
9
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
9
  var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
11
- var __exportAll = (all, symbols) => {
10
+ var __exportAll = (all, no_symbols) => {
12
11
  let target = {};
13
- for (var name in all) {
14
- __defProp(target, name, {
15
- get: all[name],
16
- enumerable: true
17
- });
18
- }
19
- if (symbols) {
20
- __defProp(target, Symbol.toStringTag, { value: "Module" });
21
- }
12
+ for (var name in all) __defProp(target, name, {
13
+ get: all[name],
14
+ enumerable: true
15
+ });
16
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
22
17
  return target;
23
18
  };
24
19
  var __copyProps = (to, from, except, desc) => {
25
- if (from && typeof from === "object" || typeof from === "function") {
26
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
27
- key = keys[i];
28
- if (!__hasOwnProp.call(to, key) && key !== except) {
29
- __defProp(to, key, {
30
- get: ((k) => from[k]).bind(null, key),
31
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
32
- });
33
- }
34
- }
20
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
21
+ key = keys[i];
22
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
23
+ get: ((k) => from[k]).bind(null, key),
24
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
25
+ });
35
26
  }
36
27
  return to;
37
28
  };
@@ -40,6 +31,5 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
40
31
  enumerable: true
41
32
  }) : target, mod));
42
33
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
43
-
44
34
  //#endregion
45
- export { __toESM as i, __exportAll as n, __require as r, __commonJSMin as t };
35
+ export { __toESM as i, __exportAll as n, __require as r, __commonJSMin as t };