nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-121649-98b56dfe

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 (334) hide show
  1. package/dist/_build/common.mjs +763 -0
  2. package/dist/_build/rolldown.mjs +216 -0
  3. package/dist/_build/rollup.mjs +359 -0
  4. package/dist/_build/vite.build.mjs +67 -0
  5. package/dist/_build/vite.plugin.mjs +747 -0
  6. package/dist/_chunks/B-7HiF0V.mjs +1303 -0
  7. package/dist/_chunks/B3asVbT4.mjs +151 -0
  8. package/dist/_chunks/B5ooyfLk.mjs +372 -0
  9. package/dist/_chunks/DXMHy5ca.mjs +43 -0
  10. package/dist/_dev.d.mts +12 -0
  11. package/dist/_dev.mjs +675 -0
  12. package/dist/_libs/acorn.mjs +5034 -0
  13. package/dist/_libs/c12.mjs +2798 -0
  14. package/dist/_libs/chokidar.mjs +1560 -0
  15. package/dist/_libs/citty.mjs +333 -0
  16. package/dist/_libs/commondir.mjs +22 -0
  17. package/dist/_libs/compatx.mjs +46 -0
  18. package/dist/_libs/confbox.mjs +2920 -0
  19. package/dist/_libs/debug.mjs +848 -0
  20. package/dist/_libs/deepmerge.mjs +86 -0
  21. package/dist/_libs/depd.mjs +314 -0
  22. package/dist/_libs/dot-prop.mjs +138 -0
  23. package/dist/_libs/duplexer.mjs +71 -0
  24. package/dist/_libs/ee-first.mjs +68 -0
  25. package/dist/_libs/encodeurl.mjs +49 -0
  26. package/dist/_libs/escape-html.mjs +58 -0
  27. package/dist/_libs/escape-string-regexp.mjs +8 -0
  28. package/dist/_libs/estree-walker.mjs +330 -0
  29. package/dist/_libs/etag.mjs +75 -0
  30. package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
  31. package/dist/_libs/fresh.mjs +85 -0
  32. package/dist/_libs/function-bind.mjs +63 -0
  33. package/dist/_libs/gen-mapping.mjs +612 -0
  34. package/dist/_libs/giget.mjs +19076 -0
  35. package/dist/_libs/gzip-size.mjs +21 -0
  36. package/dist/_libs/hasown.mjs +14 -0
  37. package/dist/_libs/http-errors.mjs +436 -0
  38. package/dist/_libs/httpxy.mjs +410 -0
  39. package/dist/_libs/is-core-module.mjs +220 -0
  40. package/dist/_libs/is-module.mjs +13 -0
  41. package/dist/_libs/is-reference.mjs +32 -0
  42. package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
  43. package/dist/_libs/klona.mjs +90 -0
  44. package/dist/_libs/knitwork.mjs +124 -0
  45. package/dist/_libs/local-pkg.mjs +1686 -0
  46. package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
  47. package/dist/_libs/mime-db.mjs +7642 -0
  48. package/dist/_libs/mime-types.mjs +162 -0
  49. package/dist/_libs/mime.mjs +1391 -0
  50. package/dist/_libs/node-fetch-native.mjs +173 -0
  51. package/dist/_libs/on-finished.mjs +170 -0
  52. package/dist/_libs/parseurl.mjs +103 -0
  53. package/dist/_libs/path-parse.mjs +47 -0
  54. package/dist/_libs/pathe.mjs +41 -0
  55. package/dist/_libs/picomatch.mjs +1673 -0
  56. package/dist/_libs/plugin-alias.mjs +64 -0
  57. package/dist/_libs/plugin-commonjs.mjs +1489 -0
  58. package/dist/_libs/plugin-inject.mjs +135 -0
  59. package/dist/_libs/plugin-json.mjs +36 -0
  60. package/dist/_libs/plugin-node-resolve.mjs +1553 -0
  61. package/dist/_libs/plugin-replace.mjs +104 -0
  62. package/dist/_libs/pretty-bytes.mjs +116 -0
  63. package/dist/_libs/range-parser.mjs +102 -0
  64. package/dist/_libs/remapping.mjs +117 -0
  65. package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
  66. package/dist/_libs/send.mjs +857 -0
  67. package/dist/_libs/serve-static.mjs +124 -0
  68. package/dist/_libs/std-env.mjs +158 -0
  69. package/dist/_libs/strip-literal.mjs +51 -0
  70. package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
  71. package/dist/_libs/ultrahtml.mjs +138 -0
  72. package/dist/_libs/unimport.mjs +3520 -0
  73. package/dist/_libs/untyped.mjs +271 -0
  74. package/dist/_libs/unwasm.mjs +5825 -0
  75. package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
  76. package/dist/_presets.mjs +1723 -0
  77. package/dist/builder.d.mts +37 -35
  78. package/dist/builder.mjs +45 -117
  79. package/dist/cli/_chunks/build.mjs +43 -0
  80. package/dist/cli/_chunks/common.mjs +15 -0
  81. package/dist/cli/_chunks/detect-acorn.mjs +12 -0
  82. package/dist/cli/_chunks/dev.mjs +79 -0
  83. package/dist/cli/_chunks/dist.mjs +3 -0
  84. package/dist/cli/_chunks/dist2.mjs +4 -0
  85. package/dist/cli/_chunks/esm.mjs +3 -0
  86. package/dist/cli/_chunks/json5.mjs +4 -0
  87. package/dist/cli/_chunks/jsonc.mjs +4 -0
  88. package/dist/cli/_chunks/list.mjs +27 -0
  89. package/dist/cli/_chunks/multipart-parser.mjs +6 -0
  90. package/dist/cli/_chunks/prepare.mjs +19 -0
  91. package/dist/cli/_chunks/run.mjs +55 -0
  92. package/dist/cli/_chunks/task.mjs +16 -0
  93. package/dist/cli/_chunks/toml.mjs +4 -0
  94. package/dist/cli/_chunks/yaml.mjs +4 -0
  95. package/dist/cli/index.d.mts +1 -1
  96. package/dist/cli/index.mjs +19 -18
  97. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
  98. package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
  99. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
  100. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
  101. package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
  102. package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
  103. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
  104. package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
  105. package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
  106. package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
  107. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
  108. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
  109. package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
  110. package/dist/presets/azure/runtime/_utils.mjs +43 -43
  111. package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
  112. package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
  113. package/dist/presets/bun/runtime/bun.d.mts +1 -0
  114. package/dist/presets/bun/runtime/bun.mjs +18 -17
  115. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
  116. package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
  117. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
  118. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
  119. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
  120. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
  121. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
  122. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
  123. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
  124. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
  125. package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
  126. package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
  127. package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
  128. package/dist/presets/deno/runtime/deno-server.mjs +31 -39
  129. package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
  130. package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
  131. package/dist/presets/netlify/runtime/netlify.mjs +11 -17
  132. package/dist/presets/node/runtime/node-cluster.mjs +49 -48
  133. package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
  134. package/dist/presets/node/runtime/node-middleware.mjs +7 -6
  135. package/dist/presets/node/runtime/node-server.mjs +33 -23
  136. package/dist/presets/standard/runtime/server.d.mts +1 -3
  137. package/dist/presets/standard/runtime/server.mjs +1 -3
  138. package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
  139. package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
  140. package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
  141. package/dist/presets/vercel/runtime/vercel.mjs +15 -14
  142. package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
  143. package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
  144. package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
  145. package/dist/runtime/index.d.mts +12 -1
  146. package/dist/runtime/index.mjs +12 -7
  147. package/dist/runtime/internal/app.mjs +175 -162
  148. package/dist/runtime/internal/cache.d.mts +10 -4
  149. package/dist/runtime/internal/cache.mjs +247 -216
  150. package/dist/runtime/internal/context.d.mts +9 -9
  151. package/dist/runtime/internal/context.mjs +17 -10
  152. package/dist/runtime/internal/database.mjs +8 -10
  153. package/dist/runtime/internal/error/dev.d.mts +5 -4
  154. package/dist/runtime/internal/error/dev.mjs +106 -105
  155. package/dist/runtime/internal/error/prod.d.mts +2 -2
  156. package/dist/runtime/internal/error/prod.mjs +48 -52
  157. package/dist/runtime/internal/error/utils.d.mts +4 -4
  158. package/dist/runtime/internal/error/utils.mjs +1 -1
  159. package/dist/runtime/internal/index.d.mts +2 -0
  160. package/dist/runtime/internal/index.mjs +2 -0
  161. package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
  162. package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
  163. package/dist/runtime/internal/meta.d.mts +1 -1
  164. package/dist/runtime/internal/meta.mjs +1 -1
  165. package/dist/runtime/internal/plugin.d.mts +2 -2
  166. package/dist/runtime/internal/plugin.mjs +1 -1
  167. package/dist/runtime/internal/renderer.mjs +39 -31
  168. package/dist/runtime/internal/route-rules.d.mts +8 -8
  169. package/dist/runtime/internal/route-rules.mjs +53 -51
  170. package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
  171. package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
  172. package/dist/runtime/internal/routes/openapi.d.mts +1 -0
  173. package/dist/runtime/internal/routes/openapi.mjs +81 -87
  174. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  175. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
  176. package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
  177. package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
  178. package/dist/runtime/internal/routes/scalar.d.mts +1 -0
  179. package/dist/runtime/internal/routes/scalar.mjs +22 -23
  180. package/dist/runtime/internal/routes/swagger.d.mts +1 -0
  181. package/dist/runtime/internal/routes/swagger.mjs +9 -11
  182. package/dist/runtime/internal/runtime-config.d.mts +4 -4
  183. package/dist/runtime/internal/runtime-config.mjs +40 -35
  184. package/dist/runtime/internal/shutdown.d.mts +2 -7
  185. package/dist/runtime/internal/shutdown.mjs +30 -29
  186. package/dist/runtime/internal/static.mjs +63 -74
  187. package/dist/runtime/internal/storage.mjs +2 -2
  188. package/dist/runtime/internal/task.d.mts +6 -6
  189. package/dist/runtime/internal/task.mjs +56 -59
  190. package/dist/runtime/internal/utils.d.mts +1 -1
  191. package/dist/runtime/internal/utils.mjs +4 -10
  192. package/dist/types/index.d.mts +2566 -3851
  193. package/dist/types/index.mjs +1 -1
  194. package/dist/vite.d.mts +56 -52
  195. package/dist/vite.mjs +55 -132
  196. package/package.json +10 -10
  197. package/dist/_build/build.mjs +0 -368
  198. package/dist/_build/build2.mjs +0 -556
  199. package/dist/_build/info.mjs +0 -1002
  200. package/dist/_build/prepare.mjs +0 -1511
  201. package/dist/_build/snapshot.mjs +0 -185
  202. package/dist/_build/vite.mjs +0 -959
  203. package/dist/_build/vite2.mjs +0 -149
  204. package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
  205. package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
  206. package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
  207. package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
  208. package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
  209. package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
  210. package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
  211. package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
  212. package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
  213. package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
  214. package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
  215. package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
  216. package/dist/_chunks/_deps/acorn.mjs +0 -6225
  217. package/dist/_chunks/_deps/c12.mjs +0 -510
  218. package/dist/_chunks/_deps/chokidar.mjs +0 -1428
  219. package/dist/_chunks/_deps/citty.mjs +0 -460
  220. package/dist/_chunks/_deps/commondir.mjs +0 -77
  221. package/dist/_chunks/_deps/compatx.mjs +0 -76
  222. package/dist/_chunks/_deps/confbox.mjs +0 -300
  223. package/dist/_chunks/_deps/debug.mjs +0 -885
  224. package/dist/_chunks/_deps/deepmerge.mjs +0 -147
  225. package/dist/_chunks/_deps/depd.mjs +0 -550
  226. package/dist/_chunks/_deps/dot-prop.mjs +0 -282
  227. package/dist/_chunks/_deps/dotenv.mjs +0 -555
  228. package/dist/_chunks/_deps/duplexer.mjs +0 -1
  229. package/dist/_chunks/_deps/ee-first.mjs +0 -104
  230. package/dist/_chunks/_deps/encodeurl.mjs +0 -69
  231. package/dist/_chunks/_deps/escape-html.mjs +0 -87
  232. package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
  233. package/dist/_chunks/_deps/estree-walker.mjs +0 -433
  234. package/dist/_chunks/_deps/etag.mjs +0 -147
  235. package/dist/_chunks/_deps/exsolve.mjs +0 -1416
  236. package/dist/_chunks/_deps/fresh.mjs +0 -145
  237. package/dist/_chunks/_deps/function-bind.mjs +0 -106
  238. package/dist/_chunks/_deps/giget.mjs +0 -451
  239. package/dist/_chunks/_deps/gzip-size.mjs +0 -19
  240. package/dist/_chunks/_deps/hasown.mjs +0 -19
  241. package/dist/_chunks/_deps/http-errors.mjs +0 -307
  242. package/dist/_chunks/_deps/httpxy.mjs +0 -580
  243. package/dist/_chunks/_deps/inherits.mjs +0 -57
  244. package/dist/_chunks/_deps/is-core-module.mjs +0 -596
  245. package/dist/_chunks/_deps/is-module.mjs +0 -25
  246. package/dist/_chunks/_deps/is-reference.mjs +0 -31
  247. package/dist/_chunks/_deps/klona.mjs +0 -137
  248. package/dist/_chunks/_deps/knitwork.mjs +0 -172
  249. package/dist/_chunks/_deps/local-pkg.mjs +0 -163
  250. package/dist/_chunks/_deps/mime-db.mjs +0 -11685
  251. package/dist/_chunks/_deps/mime-types.mjs +0 -287
  252. package/dist/_chunks/_deps/mime.mjs +0 -1172
  253. package/dist/_chunks/_deps/mlly.mjs +0 -2413
  254. package/dist/_chunks/_deps/ms.mjs +0 -172
  255. package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
  256. package/dist/_chunks/_deps/nypm.mjs +0 -219
  257. package/dist/_chunks/_deps/on-finished.mjs +0 -246
  258. package/dist/_chunks/_deps/parseurl.mjs +0 -168
  259. package/dist/_chunks/_deps/path-parse.mjs +0 -85
  260. package/dist/_chunks/_deps/pathe.mjs +0 -251
  261. package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
  262. package/dist/_chunks/_deps/picomatch.mjs +0 -2144
  263. package/dist/_chunks/_deps/pkg-types.mjs +0 -247
  264. package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
  265. package/dist/_chunks/_deps/quansync.mjs +0 -99
  266. package/dist/_chunks/_deps/range-parser.mjs +0 -171
  267. package/dist/_chunks/_deps/rc9.mjs +0 -219
  268. package/dist/_chunks/_deps/readdirp.mjs +0 -245
  269. package/dist/_chunks/_deps/resolve.mjs +0 -1260
  270. package/dist/_chunks/_deps/send.mjs +0 -1022
  271. package/dist/_chunks/_deps/serve-static.mjs +0 -228
  272. package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
  273. package/dist/_chunks/_deps/statuses.mjs +0 -457
  274. package/dist/_chunks/_deps/std-env.mjs +0 -3
  275. package/dist/_chunks/_deps/strip-literal.mjs +0 -67
  276. package/dist/_chunks/_deps/supports-color.mjs +0 -44
  277. package/dist/_chunks/_deps/tinyexec.mjs +0 -552
  278. package/dist/_chunks/_deps/toidentifier.mjs +0 -41
  279. package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
  280. package/dist/_chunks/_deps/unimport.mjs +0 -2267
  281. package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
  282. package/dist/_chunks/_deps/unplugin.mjs +0 -1294
  283. package/dist/_chunks/_deps/untyped.mjs +0 -375
  284. package/dist/_chunks/_deps/unwasm.mjs +0 -6959
  285. package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
  286. package/dist/_chunks/_presets/_all.mjs +0 -59
  287. package/dist/_chunks/_presets/_nitro.mjs +0 -74
  288. package/dist/_chunks/_presets/_resolve.mjs +0 -64
  289. package/dist/_chunks/_presets/_static.mjs +0 -69
  290. package/dist/_chunks/_presets/_types.mjs +0 -3
  291. package/dist/_chunks/_presets/_utils.mjs +0 -31
  292. package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
  293. package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
  294. package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
  295. package/dist/_chunks/_presets/azure.mjs +0 -162
  296. package/dist/_chunks/_presets/bun.mjs +0 -19
  297. package/dist/_chunks/_presets/cleavr.mjs +0 -15
  298. package/dist/_chunks/_presets/cloudflare.mjs +0 -608
  299. package/dist/_chunks/_presets/deno.mjs +0 -196
  300. package/dist/_chunks/_presets/digitalocean.mjs +0 -14
  301. package/dist/_chunks/_presets/firebase.mjs +0 -47
  302. package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
  303. package/dist/_chunks/_presets/genezio.mjs +0 -13
  304. package/dist/_chunks/_presets/heroku.mjs +0 -14
  305. package/dist/_chunks/_presets/iis.mjs +0 -194
  306. package/dist/_chunks/_presets/index.mjs +0 -62
  307. package/dist/_chunks/_presets/koyeb.mjs +0 -14
  308. package/dist/_chunks/_presets/netlify.mjs +0 -241
  309. package/dist/_chunks/_presets/node.mjs +0 -54
  310. package/dist/_chunks/_presets/platform.mjs +0 -14
  311. package/dist/_chunks/_presets/render.mjs +0 -14
  312. package/dist/_chunks/_presets/standard.mjs +0 -23
  313. package/dist/_chunks/_presets/stormkit.mjs +0 -18
  314. package/dist/_chunks/_presets/vercel.mjs +0 -375
  315. package/dist/_chunks/_presets/winterjs.mjs +0 -22
  316. package/dist/_chunks/_presets/zeabur.mjs +0 -69
  317. package/dist/_chunks/_presets/zerops.mjs +0 -27
  318. package/dist/_chunks/app.mjs +0 -600
  319. package/dist/_chunks/builder.mjs +0 -648
  320. package/dist/_chunks/server.mjs +0 -256
  321. package/dist/_cli/build.mjs +0 -49
  322. package/dist/_cli/common.mjs +0 -13
  323. package/dist/_cli/dev.mjs +0 -121
  324. package/dist/_cli/index.mjs +0 -16
  325. package/dist/_cli/list.mjs +0 -33
  326. package/dist/_cli/prepare.mjs +0 -23
  327. package/dist/_cli/run.mjs +0 -59
  328. package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
  329. package/dist/runtime/internal/empty.d.mts +0 -0
  330. package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
  331. package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
  332. package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
  333. package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
  334. /package/lib/{indexd.mts → index.d.mts} +0 -0
@@ -1,1294 +0,0 @@
1
- import path, { resolve, isAbsolute, normalize, dirname, basename, extname } from 'node:path';
2
- import { p as pm } from './picomatch.mjs';
3
- import { P as Parser } from './acorn.mjs';
4
- import { Buffer } from 'node:buffer';
5
- import fs from 'node:fs';
6
- import { createRequire } from 'node:module';
7
- import process$1 from 'node:process';
8
- import { r as remapping } from './@jridgewell/remapping.mjs';
9
- import * as querystring from 'node:querystring';
10
- import { fileURLToPath } from 'node:url';
11
- import { V as VirtualModulesPlugin } from './webpack-virtual-modules.mjs';
12
-
13
- //#region src/utils/general.ts
14
- function toArray(array) {
15
- array = array || [];
16
- if (Array.isArray(array)) return array;
17
- return [array];
18
- }
19
-
20
- //#endregion
21
- //#region src/utils/filter.ts
22
- const BACKSLASH_REGEX = /\\/g;
23
- function normalize$1(path$1) {
24
- return path$1.replace(BACKSLASH_REGEX, "/");
25
- }
26
- const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
27
- function isAbsolute$1(path$1) {
28
- return ABSOLUTE_PATH_REGEX.test(path$1);
29
- }
30
- function getMatcherString(glob, cwd) {
31
- if (glob.startsWith("**") || isAbsolute$1(glob)) return normalize$1(glob);
32
- const resolved = resolve(cwd, glob);
33
- return normalize$1(resolved);
34
- }
35
- function patternToIdFilter(pattern) {
36
- if (pattern instanceof RegExp) return (id) => {
37
- const normalizedId = normalize$1(id);
38
- const result = pattern.test(normalizedId);
39
- pattern.lastIndex = 0;
40
- return result;
41
- };
42
- const cwd = process.cwd();
43
- const glob = getMatcherString(pattern, cwd);
44
- const matcher = pm(glob, { dot: true });
45
- return (id) => {
46
- const normalizedId = normalize$1(id);
47
- return matcher(normalizedId);
48
- };
49
- }
50
- function patternToCodeFilter(pattern) {
51
- if (pattern instanceof RegExp) return (code) => {
52
- const result = pattern.test(code);
53
- pattern.lastIndex = 0;
54
- return result;
55
- };
56
- return (code) => code.includes(pattern);
57
- }
58
- function createFilter(exclude, include) {
59
- if (!exclude && !include) return;
60
- return (input) => {
61
- if (exclude?.some((filter) => filter(input))) return false;
62
- if (include?.some((filter) => filter(input))) return true;
63
- return !(include && include.length > 0);
64
- };
65
- }
66
- function normalizeFilter(filter) {
67
- if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
68
- if (Array.isArray(filter)) return { include: filter };
69
- return {
70
- exclude: filter.exclude ? toArray(filter.exclude) : void 0,
71
- include: filter.include ? toArray(filter.include) : void 0
72
- };
73
- }
74
- function createIdFilter(filter) {
75
- if (!filter) return;
76
- const { exclude, include } = normalizeFilter(filter);
77
- const excludeFilter = exclude?.map(patternToIdFilter);
78
- const includeFilter = include?.map(patternToIdFilter);
79
- return createFilter(excludeFilter, includeFilter);
80
- }
81
- function createCodeFilter(filter) {
82
- if (!filter) return;
83
- const { exclude, include } = normalizeFilter(filter);
84
- const excludeFilter = exclude?.map(patternToCodeFilter);
85
- const includeFilter = include?.map(patternToCodeFilter);
86
- return createFilter(excludeFilter, includeFilter);
87
- }
88
- function createFilterForId(filter) {
89
- const filterFunction = createIdFilter(filter);
90
- return filterFunction ? (id) => !!filterFunction(id) : void 0;
91
- }
92
- function createFilterForTransform(idFilter, codeFilter) {
93
- if (!idFilter && !codeFilter) return;
94
- const idFilterFunction = createIdFilter(idFilter);
95
- const codeFilterFunction = createCodeFilter(codeFilter);
96
- return (id, code) => {
97
- let fallback = true;
98
- if (idFilterFunction) fallback &&= idFilterFunction(id);
99
- if (!fallback) return false;
100
- if (codeFilterFunction) fallback &&= codeFilterFunction(code);
101
- return fallback;
102
- };
103
- }
104
- function normalizeObjectHook(name, hook) {
105
- let handler;
106
- let filter;
107
- if (typeof hook === "function") handler = hook;
108
- else {
109
- handler = hook.handler;
110
- const hookFilter = hook.filter;
111
- if (name === "resolveId" || name === "load") filter = createFilterForId(hookFilter?.id);
112
- else filter = createFilterForTransform(hookFilter?.id, hookFilter?.code);
113
- }
114
- return {
115
- handler,
116
- filter: filter || (() => true)
117
- };
118
- }
119
-
120
- //#endregion
121
- //#region src/utils/context.ts
122
- function parse(code, opts = {}) {
123
- return Parser.parse(code, {
124
- sourceType: "module",
125
- ecmaVersion: "latest",
126
- locations: true,
127
- ...opts
128
- });
129
- }
130
-
131
- //#region src/utils/webpack-like.ts
132
- function transformUse(data, plugin, transformLoader) {
133
- if (data.resource == null) return [];
134
- const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || ""));
135
- if (plugin.transformInclude && !plugin.transformInclude(id)) return [];
136
- const { filter } = normalizeObjectHook("load", plugin.transform);
137
- if (!filter(id)) return [];
138
- return [{
139
- loader: transformLoader,
140
- options: { plugin },
141
- ident: plugin.name
142
- }];
143
- }
144
- /**
145
- * Normalizes a given path when it's absolute. Normalizing means returning a new path by converting
146
- * the input path to the native os format. This is useful in cases where we want to normalize
147
- * the `id` argument of a hook. Any absolute ids should be in the default format
148
- * of the operating system. Any relative imports or node_module imports should remain
149
- * untouched.
150
- *
151
- * @param path - Path to normalize.
152
- * @returns a new normalized path.
153
- */
154
- function normalizeAbsolutePath(path$1) {
155
- if (isAbsolute(path$1)) return normalize(path$1);
156
- else return path$1;
157
- }
158
-
159
- //#region src/rspack/context.ts
160
- function createBuildContext$1(compiler, compilation, loaderContext) {
161
- return {
162
- getNativeBuildContext() {
163
- return {
164
- framework: "rspack",
165
- compiler,
166
- compilation,
167
- loaderContext
168
- };
169
- },
170
- addWatchFile(file) {
171
- const cwd = process.cwd();
172
- compilation.fileDependencies.add(resolve(cwd, file));
173
- },
174
- getWatchFiles() {
175
- return Array.from(compilation.fileDependencies);
176
- },
177
- parse,
178
- emitFile(emittedFile) {
179
- const outFileName = emittedFile.fileName || emittedFile.name;
180
- if (emittedFile.source && outFileName) {
181
- const { sources } = compilation.compiler.webpack;
182
- compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)));
183
- }
184
- }
185
- };
186
- }
187
- function normalizeMessage$1(error) {
188
- const err = new Error(typeof error === "string" ? error : error.message);
189
- if (typeof error === "object") {
190
- err.stack = error.stack;
191
- err.cause = error.meta;
192
- }
193
- return err;
194
- }
195
-
196
- //#region src/rspack/utils.ts
197
- function encodeVirtualModuleId(id, plugin) {
198
- return resolve(plugin.__virtualModulePrefix, encodeURIComponent(id));
199
- }
200
- function decodeVirtualModuleId(encoded, _plugin) {
201
- return decodeURIComponent(basename(encoded));
202
- }
203
- function isVirtualModuleId(encoded, plugin) {
204
- return dirname(encoded) === plugin.__virtualModulePrefix;
205
- }
206
- var FakeVirtualModulesPlugin = class FakeVirtualModulesPlugin {
207
- name = "FakeVirtualModulesPlugin";
208
- static counters = /* @__PURE__ */ new Map();
209
- static initCleanup = false;
210
- constructor(plugin) {
211
- this.plugin = plugin;
212
- if (!FakeVirtualModulesPlugin.initCleanup) {
213
- FakeVirtualModulesPlugin.initCleanup = true;
214
- process.once("exit", () => {
215
- FakeVirtualModulesPlugin.counters.forEach((_, dir) => {
216
- fs.rmSync(dir, {
217
- recursive: true,
218
- force: true
219
- });
220
- });
221
- });
222
- }
223
- }
224
- apply(compiler) {
225
- const dir = this.plugin.__virtualModulePrefix;
226
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
227
- const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0;
228
- FakeVirtualModulesPlugin.counters.set(dir, counter + 1);
229
- compiler.hooks.shutdown.tap(this.name, () => {
230
- const counter$1 = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1;
231
- if (counter$1 === 0) {
232
- FakeVirtualModulesPlugin.counters.delete(dir);
233
- fs.rmSync(dir, {
234
- recursive: true,
235
- force: true
236
- });
237
- } else FakeVirtualModulesPlugin.counters.set(dir, counter$1);
238
- });
239
- }
240
- async writeModule(file) {
241
- return fs.promises.writeFile(file, "");
242
- }
243
- };
244
-
245
- //#region src/webpack/context.ts
246
- function contextOptionsFromCompilation(compilation) {
247
- return {
248
- addWatchFile(file) {
249
- (compilation.fileDependencies ?? compilation.compilationDependencies).add(file);
250
- },
251
- getWatchFiles() {
252
- return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies);
253
- }
254
- };
255
- }
256
- const require = createRequire(import.meta.url);
257
- function getSource(fileSource) {
258
- const webpack = require("webpack");
259
- return new webpack.sources.RawSource(typeof fileSource === "string" ? fileSource : Buffer.from(fileSource.buffer));
260
- }
261
- function createBuildContext(options, compiler, compilation, loaderContext) {
262
- return {
263
- parse,
264
- addWatchFile(id) {
265
- options.addWatchFile(resolve(process$1.cwd(), id));
266
- },
267
- emitFile(emittedFile) {
268
- const outFileName = emittedFile.fileName || emittedFile.name;
269
- if (emittedFile.source && outFileName) {
270
- if (!compilation) throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
271
- compilation.emitAsset(outFileName, getSource(emittedFile.source));
272
- }
273
- },
274
- getWatchFiles() {
275
- return options.getWatchFiles();
276
- },
277
- getNativeBuildContext() {
278
- return {
279
- framework: "webpack",
280
- compiler,
281
- compilation,
282
- loaderContext
283
- };
284
- }
285
- };
286
- }
287
- function normalizeMessage(error) {
288
- const err = new Error(typeof error === "string" ? error : error.message);
289
- if (typeof error === "object") {
290
- err.stack = error.stack;
291
- err.cause = error.meta;
292
- }
293
- return err;
294
- }
295
-
296
- //#region src/esbuild/utils.ts
297
- const ExtToLoader = {
298
- ".js": "js",
299
- ".mjs": "js",
300
- ".cjs": "js",
301
- ".jsx": "jsx",
302
- ".ts": "ts",
303
- ".cts": "ts",
304
- ".mts": "ts",
305
- ".tsx": "tsx",
306
- ".css": "css",
307
- ".less": "css",
308
- ".stylus": "css",
309
- ".scss": "css",
310
- ".sass": "css",
311
- ".json": "json",
312
- ".txt": "text"
313
- };
314
- function guessLoader(code, id) {
315
- return ExtToLoader[path.extname(id).toLowerCase()] || "js";
316
- }
317
- function unwrapLoader(loader, code, id) {
318
- if (typeof loader === "function") return loader(code, id);
319
- return loader;
320
- }
321
- function fixSourceMap(map) {
322
- if (!Object.prototype.hasOwnProperty.call(map, "toString")) Object.defineProperty(map, "toString", {
323
- enumerable: false,
324
- value: function toString() {
325
- return JSON.stringify(this);
326
- }
327
- });
328
- if (!Object.prototype.hasOwnProperty.call(map, "toUrl")) Object.defineProperty(map, "toUrl", {
329
- enumerable: false,
330
- value: function toUrl() {
331
- return `data:application/json;charset=utf-8;base64,${Buffer.from(this.toString()).toString("base64")}`;
332
- }
333
- });
334
- return map;
335
- }
336
- const nullSourceMap = {
337
- names: [],
338
- sources: [],
339
- mappings: "",
340
- version: 3
341
- };
342
- function combineSourcemaps(filename, sourcemapList) {
343
- sourcemapList = sourcemapList.filter((m) => m.sources);
344
- if (sourcemapList.length === 0 || sourcemapList.every((m) => m.sources.length === 0)) return { ...nullSourceMap };
345
- let map;
346
- let mapIndex = 1;
347
- const useArrayInterface = sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === void 0;
348
- if (useArrayInterface) map = remapping(sourcemapList, () => null);
349
- else map = remapping(sourcemapList[0], (sourcefile) => {
350
- if (sourcefile === filename && sourcemapList[mapIndex]) return sourcemapList[mapIndex++];
351
- else return { ...nullSourceMap };
352
- });
353
- if (!map.file) delete map.file;
354
- return map;
355
- }
356
- function createBuildContext$2(build) {
357
- const watchFiles = [];
358
- const { initialOptions } = build;
359
- return {
360
- parse,
361
- addWatchFile() {
362
- throw new Error("unplugin/esbuild: addWatchFile outside supported hooks (resolveId, load, transform)");
363
- },
364
- emitFile(emittedFile) {
365
- const outFileName = emittedFile.fileName || emittedFile.name;
366
- if (initialOptions.outdir && emittedFile.source && outFileName) {
367
- const outPath = path.resolve(initialOptions.outdir, outFileName);
368
- const outDir = path.dirname(outPath);
369
- if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
370
- fs.writeFileSync(outPath, emittedFile.source);
371
- }
372
- },
373
- getWatchFiles() {
374
- return watchFiles;
375
- },
376
- getNativeBuildContext() {
377
- return {
378
- framework: "esbuild",
379
- build
380
- };
381
- }
382
- };
383
- }
384
- function createPluginContext(context) {
385
- const errors = [];
386
- const warnings = [];
387
- const pluginContext = {
388
- error(message) {
389
- errors.push(normalizeMessage$2(message));
390
- },
391
- warn(message) {
392
- warnings.push(normalizeMessage$2(message));
393
- }
394
- };
395
- const mixedContext = {
396
- ...context,
397
- ...pluginContext,
398
- addWatchFile(id) {
399
- context.getWatchFiles().push(id);
400
- }
401
- };
402
- return {
403
- errors,
404
- warnings,
405
- mixedContext
406
- };
407
- }
408
- function normalizeMessage$2(message) {
409
- if (typeof message === "string") message = { message };
410
- return {
411
- id: message.id,
412
- pluginName: message.plugin,
413
- text: message.message,
414
- location: message.loc ? {
415
- file: message.loc.file,
416
- line: message.loc.line,
417
- column: message.loc.column
418
- } : null,
419
- detail: message.meta,
420
- notes: []
421
- };
422
- }
423
- function processCodeWithSourceMap(map, code) {
424
- if (map) {
425
- if (!map.sourcesContent || map.sourcesContent.length === 0) map.sourcesContent = [code];
426
- map = fixSourceMap(map);
427
- code += `\n//# sourceMappingURL=${map.toUrl()}`;
428
- }
429
- return code;
430
- }
431
-
432
- //#endregion
433
- //#region src/esbuild/index.ts
434
- function getEsbuildPlugin(factory) {
435
- return (userOptions) => {
436
- const meta = { framework: "esbuild" };
437
- const plugins = toArray(factory(userOptions, meta));
438
- const setupPlugins = async (build) => {
439
- const setup = buildSetup();
440
- const loaders = [];
441
- for (const plugin of plugins) {
442
- const loader = {};
443
- await setup(plugin)({
444
- ...build,
445
- onLoad(_options, callback) {
446
- loader.options = _options;
447
- loader.onLoadCb = callback;
448
- },
449
- onTransform(_options, callback) {
450
- loader.options ||= _options;
451
- loader.onTransformCb = callback;
452
- }
453
- }, build);
454
- if (loader.onLoadCb || loader.onTransformCb) loaders.push(loader);
455
- }
456
- if (loaders.length) build.onLoad(loaders.length === 1 ? loaders[0].options : { filter: /.*/ }, async (args) => {
457
- function checkFilter(options) {
458
- return loaders.length === 1 || !options?.filter || options.filter.test(args.path);
459
- }
460
- let result;
461
- for (const { options, onLoadCb } of loaders) {
462
- if (!checkFilter(options)) continue;
463
- if (onLoadCb) result = await onLoadCb(args);
464
- if (result?.contents) break;
465
- }
466
- let fsContentsCache;
467
- for (const { options, onTransformCb } of loaders) {
468
- if (!checkFilter(options)) continue;
469
- if (onTransformCb) {
470
- const newArgs = {
471
- ...result,
472
- ...args,
473
- async getContents() {
474
- if (result?.contents) return result.contents;
475
- if (fsContentsCache) return fsContentsCache;
476
- return fsContentsCache = await fs.promises.readFile(args.path, "utf8");
477
- }
478
- };
479
- const _result = await onTransformCb(newArgs);
480
- if (_result?.contents) result = _result;
481
- }
482
- }
483
- if (result?.contents) return result;
484
- });
485
- };
486
- return {
487
- name: (plugins.length === 1 ? plugins[0].name : meta.esbuildHostName) ?? `unplugin-host:${plugins.map((p) => p.name).join(":")}`,
488
- setup: setupPlugins
489
- };
490
- };
491
- }
492
- function buildSetup() {
493
- return (plugin) => {
494
- return (build, rawBuild) => {
495
- const context = createBuildContext$2(rawBuild);
496
- const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build;
497
- const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/;
498
- const onLoadFilter = plugin.esbuild?.onLoadFilter ?? /.*/;
499
- const loader = plugin.esbuild?.loader ?? guessLoader;
500
- plugin.esbuild?.config?.call(context, initialOptions);
501
- if (plugin.buildStart) onStart(() => plugin.buildStart.call(context));
502
- if (plugin.buildEnd || plugin.writeBundle) onEnd(async () => {
503
- if (plugin.buildEnd) await plugin.buildEnd.call(context);
504
- if (plugin.writeBundle) await plugin.writeBundle();
505
- });
506
- if (plugin.resolveId) onResolve({ filter: onResolveFilter }, async (args) => {
507
- const id = args.path;
508
- if (initialOptions.external?.includes(id)) return;
509
- const { handler, filter } = normalizeObjectHook("resolveId", plugin.resolveId);
510
- if (!filter(id)) return;
511
- const { errors, warnings, mixedContext } = createPluginContext(context);
512
- const isEntry = args.kind === "entry-point";
513
- const result = await handler.call(mixedContext, id, isEntry ? void 0 : args.importer, { isEntry });
514
- if (typeof result === "string") return {
515
- path: result,
516
- namespace: plugin.name,
517
- errors,
518
- warnings,
519
- watchFiles: mixedContext.getWatchFiles()
520
- };
521
- else if (typeof result === "object" && result !== null) return {
522
- path: result.id,
523
- external: result.external,
524
- namespace: plugin.name,
525
- errors,
526
- warnings,
527
- watchFiles: mixedContext.getWatchFiles()
528
- };
529
- });
530
- if (plugin.load) onLoad({ filter: onLoadFilter }, async (args) => {
531
- const { handler, filter } = normalizeObjectHook("load", plugin.load);
532
- const id = args.path + (args.suffix || "");
533
- if (plugin.loadInclude && !plugin.loadInclude(id)) return;
534
- if (!filter(id)) return;
535
- const { errors, warnings, mixedContext } = createPluginContext(context);
536
- let code;
537
- let map;
538
- const result = await handler.call(mixedContext, id);
539
- if (typeof result === "string") code = result;
540
- else if (typeof result === "object" && result !== null) {
541
- code = result.code;
542
- map = result.map;
543
- }
544
- if (code === void 0) return null;
545
- if (map) code = processCodeWithSourceMap(map, code);
546
- const resolveDir = path.dirname(args.path);
547
- return {
548
- contents: code,
549
- errors,
550
- warnings,
551
- watchFiles: mixedContext.getWatchFiles(),
552
- loader: unwrapLoader(loader, code, args.path),
553
- resolveDir
554
- };
555
- });
556
- if (plugin.transform) onTransform({ filter: onLoadFilter }, async (args) => {
557
- const { handler, filter } = normalizeObjectHook("transform", plugin.transform);
558
- const id = args.path + (args.suffix || "");
559
- if (plugin.transformInclude && !plugin.transformInclude(id)) return;
560
- let code = await args.getContents();
561
- if (!filter(id, code)) return;
562
- const { mixedContext, errors, warnings } = createPluginContext(context);
563
- const resolveDir = path.dirname(args.path);
564
- let map;
565
- const result = await handler.call(mixedContext, code, id);
566
- if (typeof result === "string") code = result;
567
- else if (typeof result === "object" && result !== null) {
568
- code = result.code;
569
- if (map && result.map) map = combineSourcemaps(args.path, [result.map === "string" ? JSON.parse(result.map) : result.map, map]);
570
- else if (typeof result.map === "string") map = JSON.parse(result.map);
571
- else map = result.map;
572
- }
573
- if (code) {
574
- if (map) code = processCodeWithSourceMap(map, code);
575
- return {
576
- contents: code,
577
- errors,
578
- warnings,
579
- watchFiles: mixedContext.getWatchFiles(),
580
- loader: unwrapLoader(loader, code, args.path),
581
- resolveDir
582
- };
583
- }
584
- });
585
- if (plugin.esbuild?.setup) return plugin.esbuild.setup(rawBuild);
586
- };
587
- };
588
- }
589
-
590
- //#endregion
591
- //#region src/farm/context.ts
592
- function createFarmContext(context, currentResolveId) {
593
- return {
594
- parse,
595
- addWatchFile(id) {
596
- context.addWatchFile(id, currentResolveId || id);
597
- },
598
- emitFile(emittedFile) {
599
- const outFileName = emittedFile.fileName || emittedFile.name;
600
- if (emittedFile.source && outFileName) context.emitFile({
601
- resolvedPath: outFileName,
602
- name: outFileName,
603
- content: [...Buffer.from(emittedFile.source)],
604
- resourceType: extname(outFileName)
605
- });
606
- },
607
- getWatchFiles() {
608
- return context.getWatchFiles();
609
- },
610
- getNativeBuildContext() {
611
- return {
612
- framework: "farm",
613
- context
614
- };
615
- }
616
- };
617
- }
618
- function unpluginContext(context) {
619
- return {
620
- error: (error) => context.error(typeof error === "string" ? new Error(error) : error),
621
- warn: (error) => context.warn(typeof error === "string" ? new Error(error) : error)
622
- };
623
- }
624
-
625
- //#endregion
626
- //#region src/farm/utils.ts
627
- function convertEnforceToPriority(value) {
628
- const defaultPriority = 100;
629
- const enforceToPriority = {
630
- pre: 102,
631
- post: 98
632
- };
633
- return enforceToPriority[value] !== void 0 ? enforceToPriority[value] : defaultPriority;
634
- }
635
- function convertWatchEventChange(value) {
636
- const watchEventChange = {
637
- Added: "create",
638
- Updated: "update",
639
- Removed: "delete"
640
- };
641
- return watchEventChange[value];
642
- }
643
- function isString(variable) {
644
- return typeof variable === "string";
645
- }
646
- function isObject(variable) {
647
- return typeof variable === "object" && variable !== null;
648
- }
649
- function customParseQueryString(url) {
650
- if (!url) return [];
651
- const queryString = url.split("?")[1];
652
- const parsedParams = querystring.parse(queryString);
653
- const paramsArray = [];
654
- for (const key in parsedParams) paramsArray.push([key, parsedParams[key]]);
655
- return paramsArray;
656
- }
657
- function encodeStr(str) {
658
- const len = str.length;
659
- if (len === 0) return str;
660
- const firstNullIndex = str.indexOf("\0");
661
- if (firstNullIndex === -1) return str;
662
- const result = Array.from({ length: len + countNulls(str, firstNullIndex) });
663
- let pos = 0;
664
- for (let i = 0; i < firstNullIndex; i++) result[pos++] = str[i];
665
- for (let i = firstNullIndex; i < len; i++) {
666
- const char = str[i];
667
- if (char === "\0") {
668
- result[pos++] = "\\";
669
- result[pos++] = "0";
670
- } else result[pos++] = char;
671
- }
672
- return path.posix.normalize(result.join(""));
673
- }
674
- function decodeStr(str) {
675
- const len = str.length;
676
- if (len === 0) return str;
677
- const firstIndex = str.indexOf("\\0");
678
- if (firstIndex === -1) return str;
679
- const result = Array.from({ length: len - countBackslashZeros(str, firstIndex) });
680
- let pos = 0;
681
- for (let i$1 = 0; i$1 < firstIndex; i$1++) result[pos++] = str[i$1];
682
- let i = firstIndex;
683
- while (i < len) if (str[i] === "\\" && str[i + 1] === "0") {
684
- result[pos++] = "\0";
685
- i += 2;
686
- } else result[pos++] = str[i++];
687
- return path.posix.normalize(result.join(""));
688
- }
689
- function getContentValue(content) {
690
- if (content === null || content === void 0) throw new Error("Content cannot be null or undefined");
691
- const strContent = typeof content === "string" ? content : content.code || "";
692
- return encodeStr(strContent);
693
- }
694
- function countNulls(str, startIndex) {
695
- let count = 0;
696
- const len = str.length;
697
- for (let i = startIndex; i < len; i++) if (str[i] === "\0") count++;
698
- return count;
699
- }
700
- function countBackslashZeros(str, startIndex) {
701
- let count = 0;
702
- const len = str.length;
703
- for (let i = startIndex; i < len - 1; i++) if (str[i] === "\\" && str[i + 1] === "0") {
704
- count++;
705
- i++;
706
- }
707
- return count;
708
- }
709
- function removeQuery(pathe) {
710
- const queryIndex = pathe.indexOf("?");
711
- if (queryIndex !== -1) return path.posix.normalize(pathe.slice(0, queryIndex));
712
- return path.posix.normalize(pathe);
713
- }
714
- function isStartsWithSlash(str) {
715
- return str?.startsWith("/");
716
- }
717
- function appendQuery(id, query) {
718
- if (!query.length) return id;
719
- return `${id}?${stringifyQuery(query)}`;
720
- }
721
- function stringifyQuery(query) {
722
- if (!query.length) return "";
723
- let queryStr = "";
724
- for (const [key, value] of query) queryStr += `${key}${value ? `=${value}` : ""}&`;
725
- return `${queryStr.slice(0, -1)}`;
726
- }
727
- const CSS_LANGS_RES = [
728
- [/\.(less)(?:$|\?)/, "less"],
729
- [/\.(scss|sass)(?:$|\?)/, "sass"],
730
- [/\.(styl|stylus)(?:$|\?)/, "stylus"],
731
- [/\.(css)(?:$|\?)/, "css"]
732
- ];
733
- const JS_LANGS_RES = [
734
- [/\.(js|mjs|cjs)(?:$|\?)/, "js"],
735
- [/\.(jsx)(?:$|\?)/, "jsx"],
736
- [/\.(ts|cts|mts)(?:$|\?)/, "ts"],
737
- [/\.(tsx)(?:$|\?)/, "tsx"]
738
- ];
739
- function getCssModuleType(id) {
740
- for (const [reg, lang] of CSS_LANGS_RES) if (reg.test(id)) return lang;
741
- return null;
742
- }
743
- function getJsModuleType(id) {
744
- for (const [reg, lang] of JS_LANGS_RES) if (reg.test(id)) return lang;
745
- return null;
746
- }
747
- function formatLoadModuleType(id) {
748
- const cssModuleType = getCssModuleType(id);
749
- if (cssModuleType) return cssModuleType;
750
- const jsModuleType = getJsModuleType(id);
751
- if (jsModuleType) return jsModuleType;
752
- return "js";
753
- }
754
- function formatTransformModuleType(id) {
755
- return formatLoadModuleType(id);
756
- }
757
-
758
- //#endregion
759
- //#region src/farm/index.ts
760
- function getFarmPlugin(factory) {
761
- return ((userOptions) => {
762
- const meta = { framework: "farm" };
763
- const rawPlugins = toArray(factory(userOptions, meta));
764
- const plugins = rawPlugins.map((rawPlugin) => {
765
- const plugin = toFarmPlugin(rawPlugin, userOptions);
766
- if (rawPlugin.farm) Object.assign(plugin, rawPlugin.farm);
767
- return plugin;
768
- });
769
- return plugins.length === 1 ? plugins[0] : plugins;
770
- });
771
- }
772
- function toFarmPlugin(plugin, options) {
773
- const farmPlugin = {
774
- name: plugin.name,
775
- priority: convertEnforceToPriority(plugin.enforce)
776
- };
777
- if (plugin.farm) Object.keys(plugin.farm).forEach((key) => {
778
- const value = plugin.farm[key];
779
- if (value) Reflect.set(farmPlugin, key, value);
780
- });
781
- if (plugin.buildStart) {
782
- const _buildStart = plugin.buildStart;
783
- farmPlugin.buildStart = { async executor(_, context) {
784
- await _buildStart.call(createFarmContext(context));
785
- } };
786
- }
787
- if (plugin.resolveId) {
788
- const _resolveId = plugin.resolveId;
789
- let filters = [];
790
- if (options) filters = options?.filters ?? [];
791
- farmPlugin.resolve = {
792
- filters: {
793
- sources: filters.length ? filters : [".*"],
794
- importers: [".*"]
795
- },
796
- async executor(params, context) {
797
- const resolvedIdPath = path.resolve(params.importer ?? "");
798
- const id = decodeStr(params.source);
799
- const { handler, filter } = normalizeObjectHook("resolveId", _resolveId);
800
- if (!filter(id)) return null;
801
- let isEntry = false;
802
- if (isObject(params.kind) && "entry" in params.kind) {
803
- const kindWithEntry = params.kind;
804
- isEntry = kindWithEntry.entry === "index";
805
- }
806
- const farmContext = createFarmContext(context, resolvedIdPath);
807
- const resolveIdResult = await handler.call(Object.assign(unpluginContext(context), farmContext), id, resolvedIdPath ?? null, { isEntry });
808
- if (isString(resolveIdResult)) return {
809
- resolvedPath: removeQuery(encodeStr(resolveIdResult)),
810
- query: customParseQueryString(resolveIdResult),
811
- sideEffects: true,
812
- external: false,
813
- meta: {}
814
- };
815
- if (isObject(resolveIdResult)) return {
816
- resolvedPath: removeQuery(encodeStr(resolveIdResult?.id)),
817
- query: customParseQueryString(resolveIdResult?.id),
818
- sideEffects: false,
819
- external: Boolean(resolveIdResult?.external),
820
- meta: {}
821
- };
822
- if (!isStartsWithSlash(params.source)) return null;
823
- }
824
- };
825
- }
826
- if (plugin.load) {
827
- const _load = plugin.load;
828
- farmPlugin.load = {
829
- filters: { resolvedPaths: [".*"] },
830
- async executor(params, context) {
831
- const resolvedPath = decodeStr(params.resolvedPath);
832
- const id = appendQuery(resolvedPath, params.query);
833
- const loader = formatTransformModuleType(id);
834
- if (plugin.loadInclude && !plugin.loadInclude?.(id)) return null;
835
- const { handler, filter } = normalizeObjectHook("load", _load);
836
- if (!filter(id)) return null;
837
- const farmContext = createFarmContext(context, id);
838
- const content = await handler.call(Object.assign(unpluginContext(context), farmContext), id);
839
- const loadFarmResult = {
840
- content: getContentValue(content),
841
- moduleType: loader
842
- };
843
- return loadFarmResult;
844
- }
845
- };
846
- }
847
- if (plugin.transform) {
848
- const _transform = plugin.transform;
849
- farmPlugin.transform = {
850
- filters: {
851
- resolvedPaths: [".*"],
852
- moduleTypes: [".*"]
853
- },
854
- async executor(params, context) {
855
- const resolvedPath = decodeStr(params.resolvedPath);
856
- const id = appendQuery(resolvedPath, params.query);
857
- const loader = formatTransformModuleType(id);
858
- if (plugin.transformInclude && !plugin.transformInclude(id)) return null;
859
- const { handler, filter } = normalizeObjectHook("transform", _transform);
860
- if (!filter(id, params.content)) return null;
861
- const farmContext = createFarmContext(context, id);
862
- const resource = await handler.call(Object.assign(unpluginContext(context), farmContext), params.content, id);
863
- if (resource && typeof resource !== "string") {
864
- const transformFarmResult = {
865
- content: getContentValue(resource),
866
- moduleType: loader,
867
- sourceMap: typeof resource.map === "object" && resource.map !== null ? JSON.stringify(resource.map) : void 0
868
- };
869
- return transformFarmResult;
870
- }
871
- }
872
- };
873
- }
874
- if (plugin.watchChange) {
875
- const _watchChange = plugin.watchChange;
876
- farmPlugin.updateModules = { async executor(param, context) {
877
- const updatePathContent = param.paths[0];
878
- const ModifiedPath = updatePathContent[0];
879
- const eventChange = convertWatchEventChange(updatePathContent[1]);
880
- await _watchChange.call(createFarmContext(context), ModifiedPath, { event: eventChange });
881
- } };
882
- }
883
- if (plugin.buildEnd) {
884
- const _buildEnd = plugin.buildEnd;
885
- farmPlugin.buildEnd = { async executor(_, context) {
886
- await _buildEnd.call(createFarmContext(context));
887
- } };
888
- }
889
- if (plugin.writeBundle) {
890
- const _writeBundle = plugin.writeBundle;
891
- farmPlugin.finish = { async executor() {
892
- await _writeBundle();
893
- } };
894
- }
895
- return farmPlugin;
896
- }
897
-
898
- //#endregion
899
- //#region src/rollup/index.ts
900
- function getRollupPlugin(factory) {
901
- return ((userOptions) => {
902
- const meta = { framework: "rollup" };
903
- const rawPlugins = toArray(factory(userOptions, meta));
904
- const plugins = rawPlugins.map((plugin) => toRollupPlugin(plugin, "rollup"));
905
- return plugins.length === 1 ? plugins[0] : plugins;
906
- });
907
- }
908
- function toRollupPlugin(plugin, key) {
909
- const nativeFilter = key === "rolldown";
910
- if (plugin.resolveId && !nativeFilter && typeof plugin.resolveId === "object" && plugin.resolveId.filter) {
911
- const resolveIdHook = plugin.resolveId;
912
- const { handler, filter } = normalizeObjectHook("load", resolveIdHook);
913
- replaceHookHandler("resolveId", resolveIdHook, function(...args) {
914
- const [id] = args;
915
- const supportFilter = supportNativeFilter(this, key);
916
- if (!supportFilter && !filter(id)) return;
917
- return handler.apply(this, args);
918
- });
919
- }
920
- if (plugin.load && (plugin.loadInclude || !nativeFilter && typeof plugin.load === "object" && plugin.load.filter)) {
921
- const loadHook = plugin.load;
922
- const { handler, filter } = normalizeObjectHook("load", loadHook);
923
- replaceHookHandler("load", loadHook, function(...args) {
924
- const [id] = args;
925
- if (plugin.loadInclude && !plugin.loadInclude(id)) return;
926
- const supportFilter = supportNativeFilter(this, key);
927
- if (!supportFilter && !filter(id)) return;
928
- return handler.apply(this, args);
929
- });
930
- }
931
- if (plugin.transform && (plugin.transformInclude || !nativeFilter && typeof plugin.transform === "object" && plugin.transform.filter)) {
932
- const transformHook = plugin.transform;
933
- const { handler, filter } = normalizeObjectHook("transform", transformHook);
934
- replaceHookHandler("transform", transformHook, function(...args) {
935
- const [code, id] = args;
936
- if (plugin.transformInclude && !plugin.transformInclude(id)) return;
937
- const supportFilter = supportNativeFilter(this, key);
938
- if (!supportFilter && !filter(id, code)) return;
939
- return handler.apply(this, args);
940
- });
941
- }
942
- if (plugin[key]) Object.assign(plugin, plugin[key]);
943
- return plugin;
944
- function replaceHookHandler(name, hook, handler) {
945
- if (typeof hook === "function") plugin[name] = handler;
946
- else hook.handler = handler;
947
- }
948
- }
949
- function supportNativeFilter(context, framework) {
950
- if (framework === "unloader") return false;
951
- if (framework === "vite") return !!context?.meta?.viteVersion;
952
- if (framework === "rolldown") return true;
953
- const rollupVersion = context?.meta?.rollupVersion;
954
- if (!rollupVersion) return false;
955
- const [major, minor] = rollupVersion.split(".");
956
- return Number(major) > 4 || Number(major) === 4 && Number(minor) >= 40;
957
- }
958
-
959
- //#endregion
960
- //#region src/rolldown/index.ts
961
- function getRolldownPlugin(factory) {
962
- return ((userOptions) => {
963
- const meta = { framework: "rolldown" };
964
- const rawPlugins = toArray(factory(userOptions, meta));
965
- const plugins = rawPlugins.map((rawPlugin) => {
966
- const plugin = toRollupPlugin(rawPlugin, "rolldown");
967
- return plugin;
968
- });
969
- return plugins.length === 1 ? plugins[0] : plugins;
970
- });
971
- }
972
-
973
- //#endregion
974
- //#region node_modules/.pnpm/tsdown@0.14.1_publint@0.3.5_typescript@5.9.2_unplugin-unused@0.5.2_vue-tsc@3.0.6_typescript@5.9.2_/node_modules/tsdown/esm-shims.js
975
- const getFilename = () => fileURLToPath(import.meta.url);
976
- const getDirname = () => path.dirname(getFilename());
977
- const __dirname = /* @__PURE__ */ getDirname();
978
-
979
- //#endregion
980
- //#region src/rspack/index.ts
981
- const TRANSFORM_LOADER$1 = resolve(__dirname, "rspack/loaders/transform");
982
- const LOAD_LOADER$1 = resolve(__dirname, "rspack/loaders/load");
983
- function getRspackPlugin(factory) {
984
- return (userOptions) => {
985
- return { apply(compiler) {
986
- const VIRTUAL_MODULE_PREFIX = resolve(compiler.options.context ?? process.cwd(), "node_modules/.virtual", process.pid.toString());
987
- const meta = {
988
- framework: "rspack",
989
- rspack: { compiler }
990
- };
991
- const rawPlugins = toArray(factory(userOptions, meta));
992
- for (const rawPlugin of rawPlugins) {
993
- const plugin = Object.assign(rawPlugin, {
994
- __unpluginMeta: meta,
995
- __virtualModulePrefix: VIRTUAL_MODULE_PREFIX
996
- });
997
- const externalModules = /* @__PURE__ */ new Set();
998
- if (plugin.resolveId) {
999
- const createPlugin = (plugin$1) => {
1000
- if (compiler.rspack.experiments.VirtualModulesPlugin) return new compiler.rspack.experiments.VirtualModulesPlugin();
1001
- return new FakeVirtualModulesPlugin(plugin$1);
1002
- };
1003
- const vfs = createPlugin(plugin);
1004
- vfs.apply(compiler);
1005
- const vfsModules = /* @__PURE__ */ new Map();
1006
- plugin.__vfsModules = vfsModules;
1007
- plugin.__vfs = vfs;
1008
- compiler.hooks.compilation.tap(plugin.name, (compilation, { normalModuleFactory }) => {
1009
- normalModuleFactory.hooks.resolve.tapPromise(plugin.name, async (resolveData) => {
1010
- const id = normalizeAbsolutePath(resolveData.request);
1011
- const requestContext = resolveData.contextInfo;
1012
- let importer = requestContext.issuer !== "" ? requestContext.issuer : void 0;
1013
- const isEntry = requestContext.issuer === "";
1014
- if (importer?.startsWith(plugin.__virtualModulePrefix)) importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
1015
- const context = createBuildContext$1(compiler, compilation);
1016
- let error;
1017
- const pluginContext = {
1018
- error(msg) {
1019
- if (error == null) error = normalizeMessage$1(msg);
1020
- else console.error(`unplugin/rspack: multiple errors returned from resolveId hook: ${msg}`);
1021
- },
1022
- warn(msg) {
1023
- console.warn(`unplugin/rspack: warning from resolveId hook: ${msg}`);
1024
- }
1025
- };
1026
- const { handler, filter } = normalizeObjectHook("resolveId", plugin.resolveId);
1027
- if (!filter(id)) return;
1028
- const resolveIdResult = await handler.call({
1029
- ...context,
1030
- ...pluginContext
1031
- }, id, importer, { isEntry });
1032
- if (error != null) throw error;
1033
- if (resolveIdResult == null) return;
1034
- let resolved = typeof resolveIdResult === "string" ? resolveIdResult : resolveIdResult.id;
1035
- const isExternal = typeof resolveIdResult === "string" ? false : resolveIdResult.external === true;
1036
- if (isExternal) externalModules.add(resolved);
1037
- let isVirtual = true;
1038
- try {
1039
- (compiler.inputFileSystem?.statSync ?? fs.statSync)(resolved);
1040
- isVirtual = false;
1041
- } catch {
1042
- isVirtual = !isVirtualModuleId(resolved, plugin);
1043
- }
1044
- if (isVirtual) {
1045
- const encodedVirtualPath = encodeVirtualModuleId(resolved, plugin);
1046
- if (!vfsModules.has(resolved)) {
1047
- const fsPromise = Promise.resolve(vfs.writeModule(encodedVirtualPath, ""));
1048
- vfsModules.set(resolved, fsPromise);
1049
- await fsPromise;
1050
- } else await vfsModules.get(resolved);
1051
- resolved = encodedVirtualPath;
1052
- }
1053
- resolveData.request = resolved;
1054
- });
1055
- });
1056
- }
1057
- if (plugin.load) compiler.options.module.rules.unshift({
1058
- enforce: plugin.enforce,
1059
- include(id) {
1060
- if (isVirtualModuleId(id, plugin)) id = decodeVirtualModuleId(id);
1061
- if (plugin.loadInclude && !plugin.loadInclude(id)) return false;
1062
- const { filter } = normalizeObjectHook("load", plugin.load);
1063
- if (!filter(id)) return false;
1064
- return !externalModules.has(id);
1065
- },
1066
- use: [{
1067
- loader: LOAD_LOADER$1,
1068
- options: { plugin }
1069
- }],
1070
- type: "javascript/auto"
1071
- });
1072
- if (plugin.transform) compiler.options.module.rules.unshift({
1073
- enforce: plugin.enforce,
1074
- use(data) {
1075
- return transformUse(data, plugin, TRANSFORM_LOADER$1);
1076
- }
1077
- });
1078
- if (plugin.rspack) plugin.rspack(compiler);
1079
- if (plugin.watchChange || plugin.buildStart) compiler.hooks.make.tapPromise(plugin.name, async (compilation) => {
1080
- const context = createBuildContext$1(compiler, compilation);
1081
- if (plugin.watchChange && (compiler.modifiedFiles || compiler.removedFiles)) {
1082
- const promises = [];
1083
- if (compiler.modifiedFiles) compiler.modifiedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "update" }))));
1084
- if (compiler.removedFiles) compiler.removedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "delete" }))));
1085
- await Promise.all(promises);
1086
- }
1087
- if (plugin.buildStart) return await plugin.buildStart.call(context);
1088
- });
1089
- if (plugin.buildEnd) compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => {
1090
- await plugin.buildEnd.call(createBuildContext$1(compiler, compilation));
1091
- });
1092
- if (plugin.writeBundle) compiler.hooks.afterEmit.tapPromise(plugin.name, async () => {
1093
- await plugin.writeBundle();
1094
- });
1095
- }
1096
- } };
1097
- };
1098
- }
1099
-
1100
- //#endregion
1101
- //#region src/unloader/index.ts
1102
- function getUnloaderPlugin(factory) {
1103
- return ((userOptions) => {
1104
- const meta = { framework: "unloader" };
1105
- const rawPlugins = toArray(factory(userOptions, meta));
1106
- const plugins = rawPlugins.map((rawPlugin) => {
1107
- const plugin = toRollupPlugin(rawPlugin, "unloader");
1108
- return plugin;
1109
- });
1110
- return plugins.length === 1 ? plugins[0] : plugins;
1111
- });
1112
- }
1113
-
1114
- //#endregion
1115
- //#region src/vite/index.ts
1116
- function getVitePlugin(factory) {
1117
- return ((userOptions) => {
1118
- const meta = { framework: "vite" };
1119
- const rawPlugins = toArray(factory(userOptions, meta));
1120
- const plugins = rawPlugins.map((rawPlugin) => {
1121
- const plugin = toRollupPlugin(rawPlugin, "vite");
1122
- return plugin;
1123
- });
1124
- return plugins.length === 1 ? plugins[0] : plugins;
1125
- });
1126
- }
1127
-
1128
- //#endregion
1129
- //#region src/webpack/index.ts
1130
- const TRANSFORM_LOADER = resolve(__dirname, "webpack/loaders/transform");
1131
- const LOAD_LOADER = resolve(__dirname, "webpack/loaders/load");
1132
- function getWebpackPlugin(factory) {
1133
- return (userOptions) => {
1134
- return { apply(compiler) {
1135
- const VIRTUAL_MODULE_PREFIX = resolve(compiler.options.context ?? process$1.cwd(), "_virtual_");
1136
- const meta = {
1137
- framework: "webpack",
1138
- webpack: { compiler }
1139
- };
1140
- const rawPlugins = toArray(factory(userOptions, meta));
1141
- for (const rawPlugin of rawPlugins) {
1142
- const plugin = Object.assign(rawPlugin, {
1143
- __unpluginMeta: meta,
1144
- __virtualModulePrefix: VIRTUAL_MODULE_PREFIX
1145
- });
1146
- const externalModules = /* @__PURE__ */ new Set();
1147
- if (plugin.resolveId) {
1148
- let vfs = compiler.options.plugins.find((i) => i instanceof VirtualModulesPlugin);
1149
- if (!vfs) {
1150
- vfs = new VirtualModulesPlugin();
1151
- compiler.options.plugins.push(vfs);
1152
- }
1153
- const vfsModules = /* @__PURE__ */ new Set();
1154
- plugin.__vfsModules = vfsModules;
1155
- plugin.__vfs = vfs;
1156
- const resolverPlugin = { apply(resolver) {
1157
- const target = resolver.ensureHook("resolve");
1158
- resolver.getHook("resolve").tapAsync(plugin.name, async (request, resolveContext, callback) => {
1159
- if (!request.request) return callback();
1160
- if (normalizeAbsolutePath(request.request).startsWith(plugin.__virtualModulePrefix)) return callback();
1161
- const id = normalizeAbsolutePath(request.request);
1162
- const requestContext = request.context;
1163
- let importer = requestContext.issuer !== "" ? requestContext.issuer : void 0;
1164
- const isEntry = requestContext.issuer === "";
1165
- if (importer?.startsWith(plugin.__virtualModulePrefix)) importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
1166
- const fileDependencies = /* @__PURE__ */ new Set();
1167
- const context = createBuildContext({
1168
- addWatchFile(file) {
1169
- fileDependencies.add(file);
1170
- resolveContext.fileDependencies?.add(file);
1171
- },
1172
- getWatchFiles() {
1173
- return Array.from(fileDependencies);
1174
- }
1175
- }, compiler);
1176
- let error;
1177
- const pluginContext = {
1178
- error(msg) {
1179
- if (error == null) error = normalizeMessage(msg);
1180
- else console.error(`unplugin/webpack: multiple errors returned from resolveId hook: ${msg}`);
1181
- },
1182
- warn(msg) {
1183
- console.warn(`unplugin/webpack: warning from resolveId hook: ${msg}`);
1184
- }
1185
- };
1186
- const { handler, filter } = normalizeObjectHook("resolveId", plugin.resolveId);
1187
- if (!filter(id)) return callback();
1188
- const resolveIdResult = await handler.call({
1189
- ...context,
1190
- ...pluginContext
1191
- }, id, importer, { isEntry });
1192
- if (error != null) return callback(error);
1193
- if (resolveIdResult == null) return callback();
1194
- let resolved = typeof resolveIdResult === "string" ? resolveIdResult : resolveIdResult.id;
1195
- const isExternal = typeof resolveIdResult === "string" ? false : resolveIdResult.external === true;
1196
- if (isExternal) externalModules.add(resolved);
1197
- if (!fs.existsSync(resolved)) {
1198
- resolved = normalizeAbsolutePath(plugin.__virtualModulePrefix + encodeURIComponent(resolved));
1199
- if (!vfsModules.has(resolved)) {
1200
- plugin.__vfs.writeModule(resolved, "");
1201
- vfsModules.add(resolved);
1202
- }
1203
- }
1204
- const newRequest = {
1205
- ...request,
1206
- request: resolved
1207
- };
1208
- resolver.doResolve(target, newRequest, null, resolveContext, callback);
1209
- });
1210
- } };
1211
- compiler.options.resolve.plugins = compiler.options.resolve.plugins || [];
1212
- compiler.options.resolve.plugins.push(resolverPlugin);
1213
- }
1214
- if (plugin.load) compiler.options.module.rules.unshift({
1215
- include(id) {
1216
- return shouldLoad(id, plugin, externalModules);
1217
- },
1218
- enforce: plugin.enforce,
1219
- use: [{
1220
- loader: LOAD_LOADER,
1221
- options: { plugin }
1222
- }],
1223
- type: "javascript/auto"
1224
- });
1225
- if (plugin.transform) compiler.options.module.rules.unshift({
1226
- enforce: plugin.enforce,
1227
- use(data) {
1228
- return transformUse(data, plugin, TRANSFORM_LOADER);
1229
- }
1230
- });
1231
- if (plugin.webpack) plugin.webpack(compiler);
1232
- if (plugin.watchChange || plugin.buildStart) compiler.hooks.make.tapPromise(plugin.name, async (compilation) => {
1233
- const context = createBuildContext(contextOptionsFromCompilation(compilation), compiler, compilation);
1234
- if (plugin.watchChange && (compiler.modifiedFiles || compiler.removedFiles)) {
1235
- const promises = [];
1236
- if (compiler.modifiedFiles) compiler.modifiedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "update" }))));
1237
- if (compiler.removedFiles) compiler.removedFiles.forEach((file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "delete" }))));
1238
- await Promise.all(promises);
1239
- }
1240
- if (plugin.buildStart) return await plugin.buildStart.call(context);
1241
- });
1242
- if (plugin.buildEnd) compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => {
1243
- await plugin.buildEnd.call(createBuildContext(contextOptionsFromCompilation(compilation), compiler, compilation));
1244
- });
1245
- if (plugin.writeBundle) compiler.hooks.afterEmit.tapPromise(plugin.name, async () => {
1246
- await plugin.writeBundle();
1247
- });
1248
- }
1249
- } };
1250
- };
1251
- }
1252
- function shouldLoad(id, plugin, externalModules) {
1253
- if (id.startsWith(plugin.__virtualModulePrefix)) id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
1254
- if (plugin.loadInclude && !plugin.loadInclude(id)) return false;
1255
- const { filter } = normalizeObjectHook("load", plugin.load);
1256
- if (!filter(id)) return false;
1257
- return !externalModules.has(id);
1258
- }
1259
-
1260
- //#endregion
1261
- //#region src/define.ts
1262
- function createUnplugin(factory) {
1263
- return {
1264
- get esbuild() {
1265
- return getEsbuildPlugin(factory);
1266
- },
1267
- get rollup() {
1268
- return getRollupPlugin(factory);
1269
- },
1270
- get vite() {
1271
- return getVitePlugin(factory);
1272
- },
1273
- get rolldown() {
1274
- return getRolldownPlugin(factory);
1275
- },
1276
- get webpack() {
1277
- return getWebpackPlugin(factory);
1278
- },
1279
- get rspack() {
1280
- return getRspackPlugin(factory);
1281
- },
1282
- get farm() {
1283
- return getFarmPlugin(factory);
1284
- },
1285
- get unloader() {
1286
- return getUnloaderPlugin(factory);
1287
- },
1288
- get raw() {
1289
- return factory;
1290
- }
1291
- };
1292
- }
1293
-
1294
- export { createUnplugin as c };