nitro-nightly 3.1.0-20251028-090722-437659e4 → 3.1.0-20251028-131831-fe9fd554

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 (157) hide show
  1. package/dist/_build/build.mjs +379 -14
  2. package/dist/_build/{rollup.mjs → build2.mjs} +218 -68
  3. package/dist/_build/info.mjs +963 -7
  4. package/dist/_build/prepare.mjs +1491 -2
  5. package/dist/_build/snapshot.mjs +155 -31
  6. package/dist/_build/vite.mjs +43 -2307
  7. package/dist/_build/vite2.mjs +149 -0
  8. package/dist/{_deps → _chunks/_deps}/c12.mjs +1 -1
  9. package/dist/{_deps → _chunks/_deps}/giget.mjs +1 -1
  10. package/dist/_chunks/_deps/klona.mjs +137 -0
  11. package/dist/{_deps → _chunks/_deps}/knitwork.mjs +1 -1
  12. package/dist/{_deps → _chunks/_deps}/local-pkg.mjs +1 -1
  13. package/dist/{_deps → _chunks/_deps}/mlly.mjs +1 -1
  14. package/dist/{_deps → _chunks/_deps}/nypm.mjs +1 -1
  15. package/dist/{_deps → _chunks/_deps}/pathe.mjs +1 -1
  16. package/dist/{_deps → _chunks/_deps}/pkg-types.mjs +2 -2
  17. package/dist/{_deps → _chunks/_deps}/rou3.mjs +1 -1
  18. package/dist/_chunks/_deps/std-env.mjs +3 -0
  19. package/dist/{_deps → _chunks/_deps}/unimport.mjs +2 -2
  20. package/dist/{_deps → _chunks/_deps}/unplugin-utils.mjs +1 -1
  21. package/dist/{_deps → _chunks/_deps}/untyped.mjs +1 -1
  22. package/dist/{_deps → _chunks/_deps}/unwasm.mjs +2 -2
  23. package/dist/{_presets → _chunks/_presets}/_resolve.mjs +2 -2
  24. package/dist/{_presets → _chunks/_presets}/_utils.mjs +1 -1
  25. package/dist/{_presets → _chunks/_presets}/azure.mjs +1 -1
  26. package/dist/{_presets → _chunks/_presets}/cloudflare.mjs +4 -4
  27. package/dist/{_presets → _chunks/_presets}/deno.mjs +1 -1
  28. package/dist/{_presets → _chunks/_presets}/firebase.mjs +1 -1
  29. package/dist/{_presets → _chunks/_presets}/iis.mjs +1 -1
  30. package/dist/{_presets → _chunks/_presets}/index.mjs +1 -1
  31. package/dist/{_presets → _chunks/_presets}/vercel.mjs +3 -3
  32. package/dist/{_presets → _chunks/_presets}/zeabur.mjs +1 -1
  33. package/dist/_chunks/app.mjs +600 -0
  34. package/dist/_chunks/index.mjs +648 -0
  35. package/dist/_chunks/server.mjs +256 -0
  36. package/dist/_cli/build.mjs +2 -2
  37. package/dist/_cli/dev.mjs +46 -130
  38. package/dist/_cli/index.mjs +1 -1
  39. package/dist/_cli/list.mjs +2 -2
  40. package/dist/_cli/prepare.mjs +2 -2
  41. package/dist/_cli/run.mjs +2 -2
  42. package/dist/cli/index.mjs +1 -1
  43. package/dist/index.mjs +94 -120
  44. package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
  45. package/dist/node_modules/cookie-es/package.json +37 -0
  46. package/dist/node_modules/rendu/dist/index.mjs +380 -0
  47. package/dist/node_modules/rendu/package.json +47 -0
  48. package/dist/runtime/internal/task.mjs +1 -2
  49. package/dist/types/index.d.mts +2 -1
  50. package/dist/vite.mjs +103 -114
  51. package/lib/runtime/meta.mjs +18 -25
  52. package/package.json +9 -10
  53. package/dist/_build/assets.mjs +0 -235
  54. package/dist/_build/config.mjs +0 -124
  55. package/dist/_build/plugins.mjs +0 -1041
  56. package/dist/_build/rolldown.mjs +0 -494
  57. package/dist/_build/types.mjs +0 -268
  58. package/dist/node_modules/klona/dist/index.mjs +0 -81
  59. package/dist/node_modules/klona/full/index.mjs +0 -53
  60. package/dist/node_modules/klona/package.json +0 -74
  61. package/dist/node_modules/std-env/dist/index.mjs +0 -1
  62. package/dist/node_modules/std-env/package.json +0 -46
  63. /package/dist/{_deps → _chunks/_deps}/@jridgewell/gen-mapping.mjs +0 -0
  64. /package/dist/{_deps → _chunks/_deps}/@jridgewell/remapping.mjs +0 -0
  65. /package/dist/{_deps → _chunks/_deps}/@jridgewell/resolve-uri.mjs +0 -0
  66. /package/dist/{_deps → _chunks/_deps}/@jridgewell/sourcemap-codec.mjs +0 -0
  67. /package/dist/{_deps → _chunks/_deps}/@jridgewell/trace-mapping.mjs +0 -0
  68. /package/dist/{_deps → _chunks/_deps}/@pi0/vite-plugin-fullstack.mjs +0 -0
  69. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-alias.mjs +0 -0
  70. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-commonjs.mjs +0 -0
  71. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-inject.mjs +0 -0
  72. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-json.mjs +0 -0
  73. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-node-resolve.mjs +0 -0
  74. /package/dist/{_deps → _chunks/_deps}/@rollup/plugin-replace.mjs +0 -0
  75. /package/dist/{_deps → _chunks/_deps}/@rollup/pluginutils.mjs +0 -0
  76. /package/dist/{_deps → _chunks/_deps}/acorn.mjs +0 -0
  77. /package/dist/{_deps → _chunks/_deps}/chokidar.mjs +0 -0
  78. /package/dist/{_deps → _chunks/_deps}/citty.mjs +0 -0
  79. /package/dist/{_deps → _chunks/_deps}/commondir.mjs +0 -0
  80. /package/dist/{_deps → _chunks/_deps}/compatx.mjs +0 -0
  81. /package/dist/{_deps → _chunks/_deps}/confbox.mjs +0 -0
  82. /package/dist/{_deps → _chunks/_deps}/debug.mjs +0 -0
  83. /package/dist/{_deps → _chunks/_deps}/deepmerge.mjs +0 -0
  84. /package/dist/{_deps → _chunks/_deps}/depd.mjs +0 -0
  85. /package/dist/{_deps → _chunks/_deps}/dot-prop.mjs +0 -0
  86. /package/dist/{_deps → _chunks/_deps}/dotenv.mjs +0 -0
  87. /package/dist/{_deps → _chunks/_deps}/duplexer.mjs +0 -0
  88. /package/dist/{_deps → _chunks/_deps}/ee-first.mjs +0 -0
  89. /package/dist/{_deps → _chunks/_deps}/encodeurl.mjs +0 -0
  90. /package/dist/{_deps → _chunks/_deps}/escape-html.mjs +0 -0
  91. /package/dist/{_deps → _chunks/_deps}/escape-string-regexp.mjs +0 -0
  92. /package/dist/{_deps → _chunks/_deps}/estree-walker.mjs +0 -0
  93. /package/dist/{_deps → _chunks/_deps}/etag.mjs +0 -0
  94. /package/dist/{_deps → _chunks/_deps}/exsolve.mjs +0 -0
  95. /package/dist/{_deps → _chunks/_deps}/fdir.mjs +0 -0
  96. /package/dist/{_deps → _chunks/_deps}/fresh.mjs +0 -0
  97. /package/dist/{_deps → _chunks/_deps}/function-bind.mjs +0 -0
  98. /package/dist/{_deps → _chunks/_deps}/gzip-size.mjs +0 -0
  99. /package/dist/{_deps → _chunks/_deps}/hasown.mjs +0 -0
  100. /package/dist/{_deps → _chunks/_deps}/http-errors.mjs +0 -0
  101. /package/dist/{_deps → _chunks/_deps}/httpxy.mjs +0 -0
  102. /package/dist/{_deps → _chunks/_deps}/inherits.mjs +0 -0
  103. /package/dist/{_deps → _chunks/_deps}/is-core-module.mjs +0 -0
  104. /package/dist/{_deps → _chunks/_deps}/is-module.mjs +0 -0
  105. /package/dist/{_deps → _chunks/_deps}/is-reference.mjs +0 -0
  106. /package/dist/{_deps → _chunks/_deps}/js-tokens.mjs +0 -0
  107. /package/dist/{_deps → _chunks/_deps}/magic-string.mjs +0 -0
  108. /package/dist/{_deps → _chunks/_deps}/mime-db.mjs +0 -0
  109. /package/dist/{_deps → _chunks/_deps}/mime-types.mjs +0 -0
  110. /package/dist/{_deps → _chunks/_deps}/mime.mjs +0 -0
  111. /package/dist/{_deps → _chunks/_deps}/ms.mjs +0 -0
  112. /package/dist/{_deps → _chunks/_deps}/node-fetch-native.mjs +0 -0
  113. /package/dist/{_deps → _chunks/_deps}/on-finished.mjs +0 -0
  114. /package/dist/{_deps → _chunks/_deps}/parseurl.mjs +0 -0
  115. /package/dist/{_deps → _chunks/_deps}/path-parse.mjs +0 -0
  116. /package/dist/{_deps → _chunks/_deps}/perfect-debounce.mjs +0 -0
  117. /package/dist/{_deps → _chunks/_deps}/picomatch.mjs +0 -0
  118. /package/dist/{_deps → _chunks/_deps}/pretty-bytes.mjs +0 -0
  119. /package/dist/{_deps → _chunks/_deps}/quansync.mjs +0 -0
  120. /package/dist/{_deps → _chunks/_deps}/range-parser.mjs +0 -0
  121. /package/dist/{_deps → _chunks/_deps}/rc9.mjs +0 -0
  122. /package/dist/{_deps → _chunks/_deps}/readdirp.mjs +0 -0
  123. /package/dist/{_deps → _chunks/_deps}/resolve.mjs +0 -0
  124. /package/dist/{_deps → _chunks/_deps}/send.mjs +0 -0
  125. /package/dist/{_deps → _chunks/_deps}/serve-static.mjs +0 -0
  126. /package/dist/{_deps → _chunks/_deps}/setprototypeof.mjs +0 -0
  127. /package/dist/{_deps → _chunks/_deps}/statuses.mjs +0 -0
  128. /package/dist/{_deps → _chunks/_deps}/strip-literal.mjs +0 -0
  129. /package/dist/{_deps → _chunks/_deps}/supports-color.mjs +0 -0
  130. /package/dist/{_deps → _chunks/_deps}/tinyexec.mjs +0 -0
  131. /package/dist/{_deps → _chunks/_deps}/tinyglobby.mjs +0 -0
  132. /package/dist/{_deps → _chunks/_deps}/toidentifier.mjs +0 -0
  133. /package/dist/{_deps → _chunks/_deps}/ultrahtml.mjs +0 -0
  134. /package/dist/{_deps → _chunks/_deps}/unplugin.mjs +0 -0
  135. /package/dist/{_deps → _chunks/_deps}/webpack-virtual-modules.mjs +0 -0
  136. /package/dist/{_presets → _chunks/_presets}/_all.mjs +0 -0
  137. /package/dist/{_presets → _chunks/_presets}/_nitro.mjs +0 -0
  138. /package/dist/{_presets → _chunks/_presets}/_static.mjs +0 -0
  139. /package/dist/{_presets → _chunks/_presets}/_types.mjs +0 -0
  140. /package/dist/{_presets → _chunks/_presets}/alwaysdata.mjs +0 -0
  141. /package/dist/{_presets → _chunks/_presets}/aws-amplify.mjs +0 -0
  142. /package/dist/{_presets → _chunks/_presets}/aws-lambda.mjs +0 -0
  143. /package/dist/{_presets → _chunks/_presets}/bun.mjs +0 -0
  144. /package/dist/{_presets → _chunks/_presets}/cleavr.mjs +0 -0
  145. /package/dist/{_presets → _chunks/_presets}/digitalocean.mjs +0 -0
  146. /package/dist/{_presets → _chunks/_presets}/flightcontrol.mjs +0 -0
  147. /package/dist/{_presets → _chunks/_presets}/genezio.mjs +0 -0
  148. /package/dist/{_presets → _chunks/_presets}/heroku.mjs +0 -0
  149. /package/dist/{_presets → _chunks/_presets}/koyeb.mjs +0 -0
  150. /package/dist/{_presets → _chunks/_presets}/netlify.mjs +0 -0
  151. /package/dist/{_presets → _chunks/_presets}/node.mjs +0 -0
  152. /package/dist/{_presets → _chunks/_presets}/platform.mjs +0 -0
  153. /package/dist/{_presets → _chunks/_presets}/render.mjs +0 -0
  154. /package/dist/{_presets → _chunks/_presets}/standard.mjs +0 -0
  155. /package/dist/{_presets → _chunks/_presets}/stormkit.mjs +0 -0
  156. /package/dist/{_presets → _chunks/_presets}/winterjs.mjs +0 -0
  157. /package/dist/{_presets → _chunks/_presets}/zerops.mjs +0 -0
@@ -1,1041 +0,0 @@
1
- import { r as replace$1 } from '../_deps/@rollup/plugin-replace.mjs';
2
- import { pathToFileURL } from 'node:url';
3
- import { builtinModules } from 'node:module';
4
- import { hash } from 'ohash';
5
- import { defu } from 'defu';
6
- import { r as resolveModulePath } from '../_deps/exsolve.mjs';
7
- import { runtimeDir, runtimeDependencies } from 'nitro/runtime/meta';
8
- import { u as unplugin } from '../_deps/unimport.mjs';
9
- import { r as rollup } from '../_deps/unwasm.mjs';
10
- import { connectors } from 'db0';
11
- import { camelCase } from 'scule';
12
- import { a as resolve, d as dirname, e as extname, r as relative, j as join, i as isAbsolute } from '../_deps/pathe.mjs';
13
- import { readFile } from 'node:fs/promises';
14
- import { transform } from 'esbuild';
15
- import { promises } from 'node:fs';
16
- import { c as createEtag } from '../_deps/etag.mjs';
17
- import { g as glob } from '../_deps/tinyglobby.mjs';
18
- import { m as mime } from '../_deps/mime.mjs';
19
- import { withTrailingSlash } from 'ufo';
20
- import { normalizeKey, builtinDrivers } from 'unstorage';
21
- import { g as genImport, a as genSafeVariableName } from '../_deps/knitwork.mjs';
22
- import { rollupNodeFileTrace } from 'nf3';
23
- import { hasTemplateSyntax, compileTemplateToString, RENDER_CONTEXT_KEYS } from 'rendu';
24
- import { c as createFilter } from '../_deps/unplugin-utils.mjs';
25
-
26
- const NO_REPLACE_RE = /ROLLUP_NO_REPLACE|\\0raw:/;
27
- function replace(options) {
28
- const _plugin = replace$1(options);
29
- return {
30
- ..._plugin,
31
- // https://github.com/rollup/plugins/blob/master/packages/replace/src/index.js#L94
32
- renderChunk(code, chunk, options2) {
33
- if (!NO_REPLACE_RE.test(code)) {
34
- return _plugin.renderChunk.call(this, code, chunk, options2);
35
- }
36
- }
37
- };
38
- }
39
-
40
- const PREFIX = "\0virtual:";
41
- function virtual(modules, cache = {}) {
42
- const _modules = /* @__PURE__ */ new Map();
43
- for (const [id, mod] of Object.entries(modules)) {
44
- cache[id] = mod;
45
- _modules.set(id, mod);
46
- _modules.set(resolve(id), mod);
47
- }
48
- return {
49
- name: "virtual",
50
- resolveId(id, importer) {
51
- if (id in modules) {
52
- return PREFIX + id;
53
- }
54
- if (importer) {
55
- const importerNoPrefix = importer.startsWith(PREFIX) ? importer.slice(PREFIX.length) : importer;
56
- const resolved = resolve(dirname(importerNoPrefix), id);
57
- if (_modules.has(resolved)) {
58
- return PREFIX + resolved;
59
- }
60
- }
61
- return null;
62
- },
63
- async load(id) {
64
- if (!id.startsWith(PREFIX)) {
65
- return null;
66
- }
67
- const idNoPrefix = id.slice(PREFIX.length);
68
- if (!_modules.has(idNoPrefix)) {
69
- return null;
70
- }
71
- let m = _modules.get(idNoPrefix);
72
- if (typeof m === "function") {
73
- m = await m();
74
- }
75
- if (!m) {
76
- return null;
77
- }
78
- cache[id.replace(PREFIX, "")] = m;
79
- return {
80
- code: m,
81
- map: null
82
- };
83
- }
84
- };
85
- }
86
-
87
- function database(nitro) {
88
- if (!nitro.options.experimental.database) {
89
- return virtual(
90
- {
91
- "#nitro-internal-virtual/database": () => {
92
- return (
93
- /* js */
94
- `export const connectionConfigs = {};`
95
- );
96
- }
97
- },
98
- nitro.vfs
99
- );
100
- }
101
- const dbConfigs = nitro.options.dev && nitro.options.devDatabase || nitro.options.database;
102
- const connectorsNames = [
103
- ...new Set(
104
- Object.values(dbConfigs || {}).map((config) => config?.connector)
105
- )
106
- ].filter(Boolean);
107
- for (const name of connectorsNames) {
108
- if (!connectors[name]) {
109
- throw new Error(`Database connector "${name}" is invalid.`);
110
- }
111
- }
112
- return virtual(
113
- {
114
- "#nitro-internal-virtual/database": () => {
115
- return `
116
- ${connectorsNames.map(
117
- (name) => `import ${camelCase(name)}Connector from "${connectors[name]}";`
118
- ).join("\n")}
119
-
120
- export const connectionConfigs = {
121
- ${Object.entries(dbConfigs || {}).map(
122
- ([name, { connector, options }]) => `${name}: {
123
- connector: ${camelCase(connector)}Connector,
124
- options: ${JSON.stringify(options)}
125
- }`
126
- ).join(",\n")}
127
- };
128
- `;
129
- }
130
- },
131
- nitro.vfs
132
- );
133
- }
134
-
135
- const RuntimeRouteRules = [
136
- "headers",
137
- "redirect",
138
- "proxy",
139
- "cache"
140
- ];
141
- function routing(nitro) {
142
- return virtual(
143
- {
144
- // --- routing (routes, routeRules and middleware) ---
145
- "#nitro-internal-virtual/routing": () => {
146
- const allHandlers = uniqueBy(
147
- [
148
- ...Object.values(nitro.routing.routes.routes).map((h) => h.data),
149
- ...Object.values(nitro.routing.routedMiddleware.routes).map(
150
- (h) => h.data
151
- ),
152
- ...nitro.routing.globalMiddleware
153
- ],
154
- "_importHash"
155
- );
156
- const h3Imports = [
157
- allHandlers.some((h) => !h.lazy) && "toEventHandler",
158
- nitro.options.serverEntry && "toMiddleware",
159
- allHandlers.some((h) => h.lazy) && "defineLazyEventHandler"
160
- ].filter(Boolean);
161
- return (
162
- /* js */
163
- `
164
- import * as __routeRules__ from "nitro/runtime/internal/route-rules";
165
- ${nitro.options.serverEntry ? `import __serverEntry__ from ${JSON.stringify(nitro.options.serverEntry)};` : ""}
166
- import {${h3Imports.join(", ")}} from "nitro/deps/h3";
167
-
168
- export const hasRouteRules = ${nitro.routing.routeRules.hasRoutes() ? "true" : "false"};
169
- export const findRouteRules = ${nitro.routing.routeRules.compileToString({ serialize: serializeRouteRule, matchAll: true })}
170
-
171
- ${allHandlers.filter((h) => !h.lazy).map((h) => (
172
- /* js */
173
- `import ${h._importHash} from "${h.handler}";`
174
- )).join("\n")}
175
-
176
- ${allHandlers.filter((h) => h.lazy).map(
177
- (h) => (
178
- /* js */
179
- `const ${h._importHash} = defineLazyEventHandler(() => import("${h.handler}"));`
180
- )
181
- ).join("\n")}
182
-
183
- export const hasRoutes = ${nitro.routing.routes.hasRoutes() ? "true" : "false"};
184
- export const findRoute = ${nitro.routing.routes.compileToString({ serialize: serializeHandler })}
185
-
186
- export const hasRoutedMiddleware = ${nitro.routing.routedMiddleware.hasRoutes() ? "true" : "false"};
187
- export const findRoutedMiddleware = ${nitro.routing.routedMiddleware.compileToString({ serialize: serializeHandler, matchAll: true })};
188
-
189
- export const hasGlobalMiddleware = ${nitro.routing.globalMiddleware.length > 0 || nitro.options.serverEntry ? "true" : "false"};
190
- export const globalMiddleware = [
191
- ${nitro.routing.globalMiddleware.map((h) => h.lazy ? h._importHash : `toEventHandler(${h._importHash})`).join(",")}
192
- ${nitro.options.serverEntry ? `,toMiddleware(__serverEntry__)` : ""}
193
- ].filter(Boolean);
194
- `
195
- );
196
- },
197
- // --- routing-meta ---
198
- "#nitro-internal-virtual/routing-meta": () => {
199
- const routeHandlers = uniqueBy(
200
- Object.values(nitro.routing.routes.routes).map((h) => h.data),
201
- "_importHash"
202
- );
203
- return (
204
- /* js */
205
- `
206
- ${routeHandlers.map(
207
- (h) => (
208
- /* js */
209
- `import ${h._importHash}Meta from "${h.handler}?meta";`
210
- )
211
- ).join("\n")}
212
- export const handlersMeta = [
213
- ${routeHandlers.map(
214
- (h) => (
215
- /* js */
216
- `{ route: ${JSON.stringify(h.route)}, method: ${JSON.stringify(
217
- h.method?.toLowerCase()
218
- )}, meta: ${h._importHash}Meta }`
219
- )
220
- ).join(",\n")}
221
- ];
222
- `.trim()
223
- );
224
- }
225
- },
226
- nitro.vfs
227
- );
228
- }
229
- function uniqueBy(arr, key) {
230
- return [...new Map(arr.map((item) => [item[key], item])).values()];
231
- }
232
- function serializeHandler(h) {
233
- return `{${[
234
- `route:${JSON.stringify(h.route)}`,
235
- h.method && `method:${JSON.stringify(h.method)}`,
236
- h.meta && `meta:${JSON.stringify(h.meta)}`,
237
- `handler:${h.lazy ? h._importHash : `toEventHandler(${h._importHash})`}`
238
- ].filter(Boolean).join(",")}}`;
239
- }
240
- function serializeRouteRule(h) {
241
- return `[${Object.entries(h).filter(([name, options]) => options !== void 0 && name[0] !== "_").map(([name, options]) => {
242
- return `{${[
243
- `name:${JSON.stringify(name)}`,
244
- `route:${JSON.stringify(h._route)}`,
245
- h._method && `method:${JSON.stringify(h._method)}`,
246
- RuntimeRouteRules.includes(name) && `handler:__routeRules__.${name}`,
247
- `options:${JSON.stringify(options)}`
248
- ].filter(Boolean).join(",")}}`;
249
- }).join(",")}]`;
250
- }
251
-
252
- const virtualPrefix = "\0nitro-handler-meta:";
253
- const esbuildLoaders = {
254
- ".ts": "ts",
255
- ".js": "js",
256
- ".tsx": "tsx",
257
- ".jsx": "jsx"
258
- };
259
- function routeMeta(nitro) {
260
- return {
261
- name: "nitro:route-meta",
262
- async resolveId(id, importer, resolveOpts) {
263
- if (id.startsWith("\0")) {
264
- return;
265
- }
266
- if (id.endsWith(`?meta`)) {
267
- const resolved = await this.resolve(
268
- id.replace(`?meta`, ``),
269
- importer,
270
- resolveOpts
271
- );
272
- if (!resolved) {
273
- return;
274
- }
275
- return virtualPrefix + resolved.id;
276
- }
277
- },
278
- load(id) {
279
- if (id.startsWith(virtualPrefix)) {
280
- const fullPath = id.slice(virtualPrefix.length);
281
- return readFile(fullPath, { encoding: "utf8" });
282
- }
283
- },
284
- async transform(code, id) {
285
- if (!id.startsWith(virtualPrefix)) {
286
- return;
287
- }
288
- let meta = null;
289
- try {
290
- const ext = extname(id);
291
- const jsCode = await transform(code, {
292
- loader: esbuildLoaders[ext]
293
- }).then((r) => r.code);
294
- const ast = this.parse(jsCode);
295
- for (const node of ast.body) {
296
- if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" && node.expression.callee.name === "defineRouteMeta" && node.expression.arguments.length === 1) {
297
- meta = astToObject(node.expression.arguments[0]);
298
- break;
299
- }
300
- }
301
- } catch (error) {
302
- nitro.logger.warn(
303
- `[handlers-meta] Cannot extra route meta for: ${id}: ${error}`
304
- );
305
- }
306
- return {
307
- code: `export default ${JSON.stringify(meta)};`,
308
- map: null
309
- };
310
- }
311
- };
312
- }
313
- function astToObject(node) {
314
- switch (node.type) {
315
- case "ObjectExpression": {
316
- const obj = {};
317
- for (const prop of node.properties) {
318
- if (prop.type === "Property") {
319
- const key = prop.key.name ?? prop.key.value;
320
- obj[key] = astToObject(prop.value);
321
- }
322
- }
323
- return obj;
324
- }
325
- case "ArrayExpression": {
326
- return node.elements.map((el) => astToObject(el)).filter(Boolean);
327
- }
328
- case "Literal": {
329
- return node.value;
330
- }
331
- }
332
- }
333
-
334
- function serverMain(nitro) {
335
- return {
336
- name: "nitro:server-main",
337
- renderChunk(code, chunk) {
338
- if (chunk.isEntry) {
339
- return {
340
- code: `globalThis.__nitro_main__ = import.meta.url; ${code}`,
341
- map: null
342
- };
343
- }
344
- }
345
- };
346
- }
347
-
348
- const readAssetHandler = {
349
- true: "node",
350
- node: "node",
351
- false: "null",
352
- deno: "deno",
353
- inline: "inline"
354
- };
355
- function publicAssets(nitro) {
356
- return virtual(
357
- {
358
- // #nitro-internal-virtual/public-assets-data
359
- "#nitro-internal-virtual/public-assets-data": async () => {
360
- const assets = {};
361
- const files = await glob("**", {
362
- cwd: nitro.options.output.publicDir,
363
- absolute: false,
364
- dot: true
365
- });
366
- for (const id of files) {
367
- let mimeType = mime.getType(id.replace(/\.(gz|br)$/, "")) || "text/plain";
368
- if (mimeType.startsWith("text")) {
369
- mimeType += "; charset=utf-8";
370
- }
371
- const fullPath = resolve(nitro.options.output.publicDir, id);
372
- const assetData = await promises.readFile(fullPath);
373
- const etag = createEtag(assetData);
374
- const stat = await promises.stat(fullPath);
375
- const assetId = "/" + decodeURIComponent(id);
376
- let encoding;
377
- if (id.endsWith(".gz")) {
378
- encoding = "gzip";
379
- } else if (id.endsWith(".br")) {
380
- encoding = "br";
381
- }
382
- assets[assetId] = {
383
- type: nitro._prerenderMeta?.[assetId]?.contentType || mimeType,
384
- encoding,
385
- etag,
386
- mtime: stat.mtime.toJSON(),
387
- size: stat.size,
388
- path: relative(nitro.options.output.serverDir, fullPath),
389
- data: nitro.options.serveStatic === "inline" ? assetData.toString("base64") : void 0
390
- };
391
- }
392
- return `export default ${JSON.stringify(assets, null, 2)};`;
393
- },
394
- // #nitro-internal-virtual/public-assets-node
395
- "#nitro-internal-virtual/public-assets-node": () => {
396
- return `
397
- import { promises as fsp } from 'node:fs'
398
- import { fileURLToPath } from 'node:url'
399
- import { resolve, dirname } from 'node:path'
400
- import assets from '#nitro-internal-virtual/public-assets-data'
401
- export function readAsset (id) {
402
- const serverDir = dirname(fileURLToPath(globalThis.__nitro_main__))
403
- return fsp.readFile(resolve(serverDir, assets[id].path))
404
- }`;
405
- },
406
- // #nitro-internal-virtual/public-assets-deno
407
- "#nitro-internal-virtual/public-assets-deno": () => {
408
- return `
409
- import assets from '#nitro-internal-virtual/public-assets-data'
410
- export function readAsset (id) {
411
- // https://deno.com/deploy/docs/serve-static-assets
412
- const path = '.' + decodeURIComponent(new URL(\`../public\${id}\`, 'file://').pathname)
413
- return Deno.readFile(path);
414
- }`;
415
- },
416
- // #nitro-internal-virtual/public-assets-null
417
- "#nitro-internal-virtual/public-assets-null": () => {
418
- return `
419
- export function readAsset (id) {
420
- return Promise.resolve(null);
421
- }`;
422
- },
423
- // #nitro-internal-virtual/public-assets-inline
424
- "#nitro-internal-virtual/public-assets-inline": () => {
425
- return `
426
- import assets from '#nitro-internal-virtual/public-assets-data'
427
- export function readAsset (id) {
428
- if (!assets[id]) { return undefined }
429
- if (assets[id]._data) { return assets[id]._data }
430
- if (!assets[id].data) { return assets[id].data }
431
- assets[id]._data = Uint8Array.from(atob(assets[id].data), (c) => c.charCodeAt(0))
432
- return assets[id]._data
433
- }`;
434
- },
435
- // #nitro-internal-virtual/public-assets
436
- "#nitro-internal-virtual/public-assets": () => {
437
- const publicAssetBases = Object.fromEntries(
438
- nitro.options.publicAssets.filter((dir) => !dir.fallthrough && dir.baseURL !== "/").map((dir) => [
439
- withTrailingSlash(dir.baseURL),
440
- { maxAge: dir.maxAge }
441
- ])
442
- );
443
- const handlerName = readAssetHandler[nitro.options.serveStatic] || "null";
444
- const readAssetImport = `#nitro-internal-virtual/public-assets-${handlerName}`;
445
- return `
446
- import assets from '#nitro-internal-virtual/public-assets-data'
447
- export { readAsset } from "${readAssetImport}"
448
- export const publicAssetBases = ${JSON.stringify(publicAssetBases)}
449
-
450
- export function isPublicAssetURL(id = '') {
451
- if (assets[id]) {
452
- return true
453
- }
454
- for (const base in publicAssetBases) {
455
- if (id.startsWith(base)) { return true }
456
- }
457
- return false
458
- }
459
-
460
- export function getPublicAssetMeta(id = '') {
461
- for (const base in publicAssetBases) {
462
- if (id.startsWith(base)) { return publicAssetBases[base] }
463
- }
464
- return {}
465
- }
466
-
467
- export function getAsset (id) {
468
- return assets[id]
469
- }
470
- `;
471
- }
472
- },
473
- nitro.vfs
474
- );
475
- }
476
-
477
- function serverAssets(nitro) {
478
- if (nitro.options.dev || nitro.options.preset === "nitro-prerender") {
479
- return virtual(
480
- { "#nitro-internal-virtual/server-assets": getAssetsDev(nitro) },
481
- nitro.vfs
482
- );
483
- }
484
- return virtual(
485
- {
486
- "#nitro-internal-virtual/server-assets": async () => {
487
- const assets = {};
488
- for (const asset of nitro.options.serverAssets) {
489
- const files = await glob(asset.pattern || "**/*", {
490
- cwd: asset.dir,
491
- absolute: false,
492
- ignore: asset.ignore
493
- });
494
- for (const _id of files) {
495
- const fsPath = resolve(asset.dir, _id);
496
- const id = asset.baseName + "/" + _id;
497
- assets[id] = { fsPath, meta: {} };
498
- let type = mime.getType(id) || "text/plain";
499
- if (type.startsWith("text")) {
500
- type += "; charset=utf-8";
501
- }
502
- const etag = createEtag(await promises.readFile(fsPath));
503
- const mtime = await promises.stat(fsPath).then((s) => s.mtime.toJSON());
504
- assets[id].meta = { type, etag, mtime };
505
- }
506
- }
507
- return getAssetProd(assets);
508
- }
509
- },
510
- nitro.vfs
511
- );
512
- }
513
- function getAssetsDev(nitro) {
514
- return `
515
- import { createStorage } from 'unstorage'
516
- import fsDriver from 'unstorage/drivers/fs'
517
-
518
- const serverAssets = ${JSON.stringify(nitro.options.serverAssets)}
519
-
520
- export const assets = createStorage()
521
-
522
- for (const asset of serverAssets) {
523
- assets.mount(asset.baseName, fsDriver({ base: asset.dir, ignore: (asset?.ignore || []) }))
524
- }`;
525
- }
526
- function getAssetProd(assets) {
527
- return `
528
- const _assets = {
529
- ${Object.entries(assets).map(
530
- ([id, asset]) => ` [${JSON.stringify(
531
- normalizeKey(id)
532
- )}]: {
533
- import: () => import(${JSON.stringify(
534
- "raw:" + asset.fsPath
535
- )}).then(r => r.default || r),
536
- meta: ${JSON.stringify(
537
- asset.meta
538
- )}
539
- }`
540
- ).join(",\n")}
541
- }
542
-
543
- const normalizeKey = ${normalizeKey.toString()}
544
-
545
- export const assets = {
546
- getKeys() {
547
- return Promise.resolve(Object.keys(_assets))
548
- },
549
- hasItem (id) {
550
- id = normalizeKey(id)
551
- return Promise.resolve(id in _assets)
552
- },
553
- getItem (id) {
554
- id = normalizeKey(id)
555
- return Promise.resolve(_assets[id] ? _assets[id].import() : null)
556
- },
557
- getMeta (id) {
558
- id = normalizeKey(id)
559
- return Promise.resolve(_assets[id] ? _assets[id].meta : {})
560
- }
561
- }
562
- `;
563
- }
564
-
565
- function storage(nitro) {
566
- const mounts = [];
567
- const isDevOrPrerender = nitro.options.dev || nitro.options.preset === "nitro-prerender";
568
- const storageMounts = isDevOrPrerender ? { ...nitro.options.storage, ...nitro.options.devStorage } : nitro.options.storage;
569
- for (const path in storageMounts) {
570
- const mount = storageMounts[path];
571
- mounts.push({
572
- path,
573
- driver: builtinDrivers[mount.driver] || mount.driver,
574
- opts: mount
575
- });
576
- }
577
- const driverImports = [...new Set(mounts.map((m) => m.driver))];
578
- const bundledStorageCode = `
579
- import { prefixStorage } from 'unstorage'
580
- import overlay from 'unstorage/drivers/overlay'
581
- import memory from 'unstorage/drivers/memory'
582
-
583
- const bundledStorage = ${JSON.stringify(nitro.options.bundledStorage)}
584
- for (const base of bundledStorage) {
585
- storage.mount(base, overlay({
586
- layers: [
587
- memory(),
588
- // TODO
589
- // prefixStorage(storage, base),
590
- prefixStorage(storage, 'assets:nitro:bundled:' + base)
591
- ]
592
- }))
593
- }`;
594
- return virtual(
595
- {
596
- "#nitro-internal-virtual/storage": (
597
- /* js */
598
- `
599
- import { createStorage } from 'unstorage'
600
- import { assets } from '#nitro-internal-virtual/server-assets'
601
-
602
- ${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
603
-
604
- export function initStorage() {
605
- const storage = createStorage({})
606
- storage.mount('/assets', assets)
607
- ${mounts.map(
608
- (m) => `storage.mount('${m.path}', ${genSafeVariableName(
609
- m.driver
610
- )}(${JSON.stringify(m.opts)}))`
611
- ).join("\n")}
612
-
613
- ${!isDevOrPrerender && nitro.options.bundledStorage.length > 0 ? bundledStorageCode : ""}
614
- return storage
615
- }
616
- `
617
- )
618
- },
619
- nitro.vfs
620
- );
621
- }
622
-
623
- function errorHandler(nitro) {
624
- return virtual(
625
- {
626
- "#nitro-internal-virtual/error-handler": () => {
627
- const errorHandlers = Array.isArray(nitro.options.errorHandler) ? nitro.options.errorHandler : [nitro.options.errorHandler];
628
- const builtinHandler = join(
629
- runtimeDir,
630
- `internal/error/${nitro.options.dev ? "dev" : "prod"}`
631
- );
632
- return (
633
- /* js */
634
- `
635
- ${errorHandlers.map((h, i) => `import errorHandler$${i} from "${h}";`).join("\n")}
636
-
637
- const errorHandlers = [${errorHandlers.map((_, i) => `errorHandler$${i}`).join(", ")}];
638
-
639
- import { defaultHandler } from "${builtinHandler}";
640
-
641
- export default async function(error, event) {
642
- for (const handler of errorHandlers) {
643
- try {
644
- const response = await handler(error, event, { defaultHandler });
645
- if (response) {
646
- return response;
647
- }
648
- } catch(error) {
649
- // Handler itself thrown, log and continue
650
- console.error(error);
651
- }
652
- }
653
- // H3 will handle fallback
654
- }
655
- `
656
- );
657
- }
658
- },
659
- nitro.vfs
660
- );
661
- }
662
-
663
- function rendererTemplate(nitro) {
664
- return virtual(
665
- {
666
- "#nitro-internal-virtual/renderer-template": async () => {
667
- if (typeof nitro.options.renderer?.template !== "string") {
668
- return `export const rendererTemplate = () => '<!-- renderer.template is not set -->'; export const rendererTemplateFile = undefined;`;
669
- }
670
- if (nitro.options.dev) {
671
- return `import { readFile } from 'node:fs/promises';export const rendererTemplate = () => readFile(${JSON.stringify(nitro.options.renderer?.template)}, "utf8"); export const rendererTemplateFile = ${JSON.stringify(
672
- nitro.options.renderer?.template
673
- )};`;
674
- } else {
675
- const html = await readFile(nitro.options.renderer?.template, "utf8");
676
- if (hasTemplateSyntax(html)) {
677
- const template = compileTemplateToString(html, {
678
- contextKeys: [...RENDER_CONTEXT_KEYS]
679
- });
680
- return (
681
- /* js */
682
- `
683
- import { renderToResponse } from 'rendu'
684
- const template = ${template};
685
- export const rendererTemplate = (request) => renderToResponse(template, { request })
686
- `
687
- );
688
- } else {
689
- return (
690
- /* js */
691
- `
692
- import { HTTPResponse } from "nitro/deps/h3";
693
- export const rendererTemplate = () => new HTTPResponse(${JSON.stringify(html)}, { headers: { "content-type": "text/html; charset=utf-8" } });
694
- `
695
- );
696
- }
697
- }
698
- }
699
- },
700
- nitro.vfs
701
- );
702
- }
703
-
704
- function baseBuildPlugins(nitro, base) {
705
- const plugins = [];
706
- if (nitro.options.imports) {
707
- plugins.push(unplugin.rollup(nitro.options.imports));
708
- }
709
- if (nitro.options.experimental.wasm) {
710
- plugins.push(rollup(nitro.options.wasm || {}));
711
- }
712
- plugins.push(serverMain());
713
- const nitroPlugins = [...new Set(nitro.options.plugins)];
714
- plugins.push(
715
- virtual(
716
- {
717
- "#nitro-internal-virtual/plugins": (
718
- /* js */
719
- `
720
- ${nitroPlugins.map(
721
- (plugin) => `import _${hash(plugin).replace(/-/g, "")} from '${plugin}';`
722
- ).join("\n")}
723
-
724
- export const plugins = [
725
- ${nitroPlugins.map((plugin) => `_${hash(plugin).replace(/-/g, "")}`).join(",\n")}
726
- ]
727
- `
728
- )
729
- },
730
- nitro.vfs
731
- )
732
- );
733
- plugins.push(serverAssets(nitro));
734
- plugins.push(publicAssets(nitro));
735
- plugins.push(storage(nitro));
736
- plugins.push(database(nitro));
737
- plugins.push(routing(nitro));
738
- if (nitro.options.experimental.openAPI) {
739
- plugins.push(routeMeta(nitro));
740
- }
741
- plugins.push(errorHandler(nitro));
742
- plugins.push(
743
- virtual(
744
- {
745
- "#nitro-internal-pollyfills": base.env.polyfill.map((p) => (
746
- /* js */
747
- `import '${p}';`
748
- )).join("\n") || /* js */
749
- `/* No polyfills */`
750
- },
751
- nitro.vfs
752
- )
753
- );
754
- plugins.push(virtual(nitro.options.virtual, nitro.vfs));
755
- if (nitro.options.renderer?.template) {
756
- plugins.push(rendererTemplate(nitro));
757
- }
758
- if (nitro.options.noExternals) {
759
- plugins.push({
760
- name: "no-externals",
761
- async resolveId(id, importer, resolveOpts) {
762
- if (resolveOpts.custom?.skipNoExternals) {
763
- return;
764
- }
765
- id = base.aliases[id] || id;
766
- if (base.env.external.includes(id) || nitro.options.node && (id.startsWith("node:") || builtinModules.includes(id))) {
767
- return { id, external: true };
768
- }
769
- const resolved = await this.resolve(id, importer, resolveOpts);
770
- if (!resolved) {
771
- const _resolved = resolveModulePath(id, {
772
- try: true,
773
- from: importer && isAbsolute(importer) ? [pathToFileURL(importer), ...nitro.options.nodeModulesDirs] : nitro.options.nodeModulesDirs,
774
- suffixes: ["", "/index"],
775
- extensions: [".mjs", ".cjs", ".js", ".mts", ".cts", ".ts", ".json"],
776
- conditions: [
777
- "default",
778
- nitro.options.dev ? "development" : "production",
779
- "node",
780
- "import",
781
- "require"
782
- ]
783
- });
784
- if (_resolved) {
785
- return { id: _resolved, external: false };
786
- }
787
- }
788
- if (!resolved || resolved.external && !id.endsWith(".wasm")) {
789
- throw new Error(
790
- `Cannot resolve ${JSON.stringify(id)} from ${JSON.stringify(
791
- importer
792
- )} and externals are not allowed!`
793
- );
794
- }
795
- }
796
- });
797
- } else if (!nitro.options.dev) {
798
- plugins.push(
799
- rollupNodeFileTrace(
800
- defu(nitro.options.externals, {
801
- outDir: nitro.options.output.serverDir,
802
- moduleDirectories: nitro.options.nodeModulesDirs,
803
- external: [
804
- ...nitro.options.dev ? [nitro.options.buildDir] : [],
805
- ...nitro.options.nodeModulesDirs
806
- ],
807
- inline: [
808
- "#",
809
- "~",
810
- "@/",
811
- "~~",
812
- "@@/",
813
- "virtual:",
814
- "nitro/runtime",
815
- "nitro/runtime",
816
- dirname(nitro.options.entry),
817
- ...nitro.options.experimental.wasm ? [(id) => id?.endsWith(".wasm")] : [],
818
- runtimeDir,
819
- nitro.options.srcDir,
820
- ...nitro.options.handlers.map((m) => m.handler).filter((i) => typeof i === "string"),
821
- ...nitro.options.dev || nitro.options.preset === "nitro-prerender" || nitro.options.experimental.bundleRuntimeDependencies === false ? [] : runtimeDependencies
822
- ],
823
- traceOptions: {
824
- base: "/",
825
- processCwd: nitro.options.rootDir,
826
- exportsOnly: true
827
- },
828
- traceAlias: {
829
- "h3-nightly": "h3",
830
- ...nitro.options.externals?.traceAlias
831
- },
832
- exportConditions: nitro.options.exportConditions,
833
- writePackageJson: true
834
- })
835
- )
836
- );
837
- }
838
- return plugins;
839
- }
840
-
841
- const defaultLoaders = {
842
- ".ts": "ts",
843
- ".js": "js",
844
- ".tsx": "tsx",
845
- ".jsx": "jsx"
846
- };
847
- function esbuild(options) {
848
- const {
849
- include,
850
- exclude,
851
- sourceMap,
852
- loaders: loadersConfig,
853
- minify,
854
- ...transformOptions
855
- } = options;
856
- const loaders = { ...defaultLoaders };
857
- if (loadersConfig) {
858
- for (const key of Object.keys(loadersConfig)) {
859
- const value = loadersConfig[key];
860
- if (typeof value === "string") {
861
- loaders[key] = value;
862
- } else if (value === false) {
863
- delete loaders[key];
864
- }
865
- }
866
- }
867
- const extensions = Object.keys(loaders);
868
- const INCLUDE_REGEXP = new RegExp(
869
- `\\.(${extensions.map((ext) => ext.slice(1)).join("|")})$`
870
- );
871
- const EXCLUDE_REGEXP = /node_modules/;
872
- const filter = createFilter(
873
- include || INCLUDE_REGEXP,
874
- exclude || EXCLUDE_REGEXP
875
- );
876
- return {
877
- name: "esbuild",
878
- async transform(code, id) {
879
- if (!filter(id)) {
880
- return null;
881
- }
882
- const ext = extname(id);
883
- const loader = loaders[ext];
884
- if (!loader) {
885
- return null;
886
- }
887
- const result = await transform(code, {
888
- sourcemap: sourceMap === "hidden" ? "external" : sourceMap,
889
- ...transformOptions,
890
- loader,
891
- sourcefile: id
892
- });
893
- printWarnings(id, result, this);
894
- return result.code && {
895
- code: result.code,
896
- map: result.map || null
897
- };
898
- },
899
- async renderChunk(code) {
900
- if (minify) {
901
- const result = await transform(code, {
902
- loader: "js",
903
- minify: true,
904
- target: transformOptions.target
905
- });
906
- if (result.code) {
907
- return {
908
- code: result.code,
909
- map: result.map || null
910
- };
911
- }
912
- }
913
- return null;
914
- }
915
- };
916
- }
917
- function printWarnings(id, result, plugin) {
918
- if (result.warnings) {
919
- for (const warning of result.warnings) {
920
- let message = "[esbuild]";
921
- if (warning.location) {
922
- message += ` (${relative(process.cwd(), id)}:${warning.location.line}:${warning.location.column})`;
923
- }
924
- message += ` ${warning.text}`;
925
- plugin.warn(message);
926
- }
927
- }
928
- }
929
-
930
- function sourcemapMininify() {
931
- return {
932
- name: "nitro:sourcemap-minify",
933
- generateBundle(_options, bundle) {
934
- for (const [key, asset] of Object.entries(bundle)) {
935
- if (!key.endsWith(".map") || !("source" in asset) || typeof asset.source !== "string") {
936
- continue;
937
- }
938
- const sourcemap = JSON.parse(asset.source);
939
- if (!(sourcemap.sources || []).some((s) => s.includes("node_modules"))) {
940
- continue;
941
- }
942
- sourcemap.mappings = "";
943
- asset.source = JSON.stringify(sourcemap);
944
- }
945
- }
946
- };
947
- }
948
-
949
- const HELPER_ID = "\0raw-helpers";
950
- function raw(opts = {}) {
951
- const extensions = /* @__PURE__ */ new Set([
952
- ".md",
953
- ".mdx",
954
- ".txt",
955
- ".css",
956
- ".htm",
957
- ".html",
958
- ".sql",
959
- ...opts.extensions || []
960
- ]);
961
- return {
962
- name: "raw",
963
- async resolveId(id, importer, resolveOpts) {
964
- if (id === HELPER_ID) {
965
- return id;
966
- }
967
- if (id[0] === "\0") {
968
- return;
969
- }
970
- const withRawSpecifier = id.startsWith("raw:");
971
- if (withRawSpecifier) {
972
- id = id.slice(4);
973
- }
974
- if (!withRawSpecifier && !extensions.has(extname(id))) {
975
- return;
976
- }
977
- const resolvedId = (await this.resolve(id, importer, resolveOpts))?.id;
978
- if (!resolvedId || resolvedId.startsWith("\0")) {
979
- return resolvedId;
980
- }
981
- if (!withRawSpecifier && !extensions.has(extname(resolvedId))) {
982
- return;
983
- }
984
- return { id: "\0raw:" + resolvedId };
985
- },
986
- load(id) {
987
- if (id === HELPER_ID) {
988
- return getHelpers();
989
- }
990
- if (id.startsWith("\0raw:")) {
991
- return promises.readFile(id.slice(5), isBinary(id) ? "binary" : "utf8");
992
- }
993
- },
994
- transform(code, id) {
995
- if (!id.startsWith("\0raw:")) {
996
- return;
997
- }
998
- if (isBinary(id)) {
999
- const serialized = Buffer.from(code, "binary").toString("base64");
1000
- return {
1001
- code: `// ROLLUP_NO_REPLACE
1002
- import {base64ToUint8Array } from "${HELPER_ID}"
1003
- export default base64ToUint8Array("${serialized}")`,
1004
- map: null
1005
- };
1006
- }
1007
- return {
1008
- code: `// ROLLUP_NO_REPLACE
1009
- export default ${JSON.stringify(code)}`,
1010
- map: null,
1011
- moduleType: "js"
1012
- };
1013
- }
1014
- };
1015
- }
1016
- function isBinary(id) {
1017
- const idMime = mime.getType(id) || "";
1018
- if (idMime.startsWith("text/")) {
1019
- return false;
1020
- }
1021
- if (/application\/(json|sql|xml|yaml)/.test(idMime)) {
1022
- return false;
1023
- }
1024
- return true;
1025
- }
1026
- function getHelpers() {
1027
- const js = String.raw;
1028
- return js`
1029
- export function base64ToUint8Array(str) {
1030
- const data = atob(str);
1031
- const size = data.length;
1032
- const bytes = new Uint8Array(size);
1033
- for (let i = 0; i < size; i++) {
1034
- bytes[i] = data.charCodeAt(i);
1035
- }
1036
- return bytes;
1037
- }
1038
- `;
1039
- }
1040
-
1041
- export { raw as a, baseBuildPlugins as b, esbuild as e, replace as r, sourcemapMininify as s };