nitro-nightly 4.0.0-20251010-091516-7cafddba → 4.0.0-20251030-091344-d4418b98

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 (195) hide show
  1. package/dist/{_chunks/build2.mjs → _build/build.mjs} +108 -58
  2. package/dist/_build/build2.mjs +556 -0
  3. package/dist/_build/info.mjs +1002 -0
  4. package/dist/_build/prepare.mjs +1511 -0
  5. package/dist/_build/snapshot.mjs +185 -0
  6. package/dist/{_chunks/plugin.mjs → _build/vite.mjs} +295 -296
  7. package/dist/_build/vite2.mjs +149 -0
  8. package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +189 -0
  9. package/dist/_chunks/_deps/@jridgewell/remapping.mjs +137 -0
  10. package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +231 -0
  11. package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +173 -0
  12. package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +170 -0
  13. package/dist/_chunks/_deps/@pi0/vite-plugin-fullstack.mjs +575 -0
  14. package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +89 -0
  15. package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +2376 -0
  16. package/dist/_chunks/{index2.mjs → _deps/@rollup/plugin-inject.mjs} +5 -90
  17. package/dist/_chunks/_deps/@rollup/plugin-json.mjs +37 -0
  18. package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +1386 -0
  19. package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +133 -0
  20. package/dist/_chunks/_deps/@rollup/pluginutils.mjs +346 -0
  21. package/dist/_chunks/_deps/acorn.mjs +6225 -0
  22. package/dist/_chunks/_deps/c12.mjs +510 -0
  23. package/dist/_chunks/_deps/chokidar.mjs +1428 -0
  24. package/dist/_chunks/_deps/citty.mjs +460 -0
  25. package/dist/_chunks/_deps/commondir.mjs +77 -0
  26. package/dist/_chunks/_deps/compatx.mjs +76 -0
  27. package/dist/_chunks/_deps/confbox.mjs +300 -0
  28. package/dist/_chunks/_deps/debug.mjs +885 -0
  29. package/dist/_chunks/_deps/deepmerge.mjs +147 -0
  30. package/dist/_chunks/_deps/depd.mjs +550 -0
  31. package/dist/_chunks/_deps/dot-prop.mjs +282 -0
  32. package/dist/_chunks/_deps/dotenv.mjs +555 -0
  33. package/dist/_chunks/_deps/duplexer.mjs +1 -0
  34. package/dist/_chunks/_deps/ee-first.mjs +104 -0
  35. package/dist/_chunks/_deps/encodeurl.mjs +69 -0
  36. package/dist/_chunks/_deps/escape-html.mjs +87 -0
  37. package/dist/_chunks/_deps/escape-string-regexp.mjs +13 -0
  38. package/dist/_chunks/_deps/estree-walker.mjs +433 -0
  39. package/dist/_chunks/_deps/etag.mjs +147 -0
  40. package/dist/_chunks/_deps/exsolve.mjs +1416 -0
  41. package/dist/_chunks/_deps/fdir.mjs +569 -0
  42. package/dist/_chunks/_deps/fresh.mjs +145 -0
  43. package/dist/_chunks/_deps/function-bind.mjs +106 -0
  44. package/dist/_chunks/{index4.mjs → _deps/giget.mjs} +21 -776
  45. package/dist/_chunks/_deps/gzip-size.mjs +19 -0
  46. package/dist/_chunks/_deps/hasown.mjs +19 -0
  47. package/dist/_chunks/_deps/http-errors.mjs +307 -0
  48. package/dist/_chunks/_deps/httpxy.mjs +580 -0
  49. package/dist/_chunks/_deps/inherits.mjs +57 -0
  50. package/dist/_chunks/_deps/is-core-module.mjs +596 -0
  51. package/dist/_chunks/_deps/is-module.mjs +25 -0
  52. package/dist/_chunks/_deps/is-reference.mjs +31 -0
  53. package/dist/_chunks/_deps/js-tokens.mjs +411 -0
  54. package/dist/_chunks/_deps/klona.mjs +137 -0
  55. package/dist/_chunks/_deps/knitwork.mjs +172 -0
  56. package/dist/_chunks/_deps/local-pkg.mjs +163 -0
  57. package/dist/_chunks/_deps/magic-string.mjs +1296 -0
  58. package/dist/_chunks/_deps/mime-db.mjs +11685 -0
  59. package/dist/_chunks/_deps/mime-types.mjs +287 -0
  60. package/dist/_chunks/_deps/mime.mjs +1172 -0
  61. package/dist/_chunks/_deps/mlly.mjs +2413 -0
  62. package/dist/_chunks/_deps/ms.mjs +172 -0
  63. package/dist/_chunks/_deps/node-fetch-native.mjs +3 -0
  64. package/dist/_chunks/_deps/nypm.mjs +219 -0
  65. package/dist/_chunks/_deps/on-finished.mjs +246 -0
  66. package/dist/_chunks/_deps/parseurl.mjs +168 -0
  67. package/dist/_chunks/_deps/path-parse.mjs +85 -0
  68. package/dist/_chunks/{pathe.M-eThtNZ.mjs → _deps/pathe.mjs} +48 -1
  69. package/dist/_chunks/_deps/perfect-debounce.mjs +88 -0
  70. package/dist/_chunks/_deps/picomatch.mjs +2144 -0
  71. package/dist/_chunks/_deps/pkg-types.mjs +247 -0
  72. package/dist/_chunks/{snapshot.mjs → _deps/pretty-bytes.mjs} +1 -105
  73. package/dist/_chunks/_deps/quansync.mjs +99 -0
  74. package/dist/_chunks/_deps/range-parser.mjs +171 -0
  75. package/dist/_chunks/_deps/rc9.mjs +219 -0
  76. package/dist/_chunks/_deps/readdirp.mjs +245 -0
  77. package/dist/_chunks/_deps/resolve.mjs +1260 -0
  78. package/dist/_chunks/_deps/rou3.mjs +326 -0
  79. package/dist/_chunks/_deps/send.mjs +1022 -0
  80. package/dist/_chunks/_deps/serve-static.mjs +228 -0
  81. package/dist/_chunks/_deps/setprototypeof.mjs +26 -0
  82. package/dist/_chunks/_deps/statuses.mjs +457 -0
  83. package/dist/_chunks/_deps/std-env.mjs +3 -0
  84. package/dist/_chunks/_deps/strip-literal.mjs +67 -0
  85. package/dist/_chunks/_deps/supports-color.mjs +44 -0
  86. package/dist/_chunks/_deps/tinyexec.mjs +552 -0
  87. package/dist/_chunks/_deps/tinyglobby.mjs +293 -0
  88. package/dist/_chunks/_deps/toidentifier.mjs +41 -0
  89. package/dist/_chunks/_deps/ultrahtml.mjs +3 -0
  90. package/dist/_chunks/_deps/unimport.mjs +2267 -0
  91. package/dist/_chunks/_deps/unplugin-utils.mjs +65 -0
  92. package/dist/_chunks/_deps/unplugin.mjs +1294 -0
  93. package/dist/_chunks/_deps/untyped.mjs +375 -0
  94. package/dist/_chunks/{info.mjs → _deps/unwasm.mjs} +8 -4206
  95. package/dist/_chunks/_deps/webpack-virtual-modules.mjs +360 -0
  96. package/dist/_chunks/_presets/_all.mjs +59 -0
  97. package/dist/_chunks/_presets/_nitro.mjs +74 -0
  98. package/dist/_chunks/_presets/_resolve.mjs +64 -0
  99. package/dist/_chunks/_presets/_static.mjs +69 -0
  100. package/dist/_chunks/_presets/_types.mjs +3 -0
  101. package/dist/_chunks/_presets/_utils.mjs +31 -0
  102. package/dist/_chunks/_presets/alwaysdata.mjs +17 -0
  103. package/dist/_chunks/_presets/aws-amplify.mjs +111 -0
  104. package/dist/_chunks/_presets/aws-lambda.mjs +23 -0
  105. package/dist/_chunks/_presets/azure.mjs +162 -0
  106. package/dist/_chunks/_presets/bun.mjs +19 -0
  107. package/dist/_chunks/_presets/cleavr.mjs +15 -0
  108. package/dist/_chunks/_presets/cloudflare.mjs +608 -0
  109. package/dist/_chunks/_presets/deno.mjs +196 -0
  110. package/dist/_chunks/_presets/digitalocean.mjs +14 -0
  111. package/dist/_chunks/_presets/firebase.mjs +47 -0
  112. package/dist/_chunks/_presets/flightcontrol.mjs +14 -0
  113. package/dist/_chunks/_presets/genezio.mjs +13 -0
  114. package/dist/_chunks/_presets/heroku.mjs +14 -0
  115. package/dist/_chunks/_presets/iis.mjs +194 -0
  116. package/dist/_chunks/_presets/index.mjs +62 -0
  117. package/dist/_chunks/_presets/koyeb.mjs +14 -0
  118. package/dist/_chunks/_presets/netlify.mjs +241 -0
  119. package/dist/_chunks/_presets/node.mjs +54 -0
  120. package/dist/_chunks/_presets/platform.mjs +14 -0
  121. package/dist/_chunks/_presets/render.mjs +14 -0
  122. package/dist/_chunks/_presets/standard.mjs +23 -0
  123. package/dist/_chunks/_presets/stormkit.mjs +18 -0
  124. package/dist/_chunks/_presets/vercel.mjs +375 -0
  125. package/dist/_chunks/_presets/winterjs.mjs +22 -0
  126. package/dist/_chunks/_presets/zeabur.mjs +69 -0
  127. package/dist/_chunks/_presets/zerops.mjs +27 -0
  128. package/dist/_chunks/app.mjs +9 -19206
  129. package/dist/_chunks/{index3.mjs → builder.mjs} +560 -970
  130. package/dist/_chunks/server.mjs +6 -4
  131. package/dist/{cli → _cli}/build.mjs +3 -8
  132. package/dist/{cli → _cli}/dev.mjs +38 -12
  133. package/dist/{cli/index2.mjs → _cli/index.mjs} +1 -2
  134. package/dist/{cli → _cli}/list.mjs +3 -4
  135. package/dist/{cli → _cli}/prepare.mjs +3 -4
  136. package/dist/{cli → _cli}/run.mjs +3 -4
  137. package/dist/{index.d.mts → builder.d.mts} +11 -11
  138. package/dist/builder.mjs +117 -0
  139. package/dist/cli/index.mjs +7 -464
  140. package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
  141. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
  142. package/dist/node_modules/@speed-highlight/core/package.json +7 -3
  143. package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
  144. package/dist/node_modules/cookie-es/package.json +37 -0
  145. package/dist/node_modules/hookable/dist/index.mjs +243 -266
  146. package/dist/node_modules/hookable/package.json +29 -26
  147. package/dist/node_modules/rendu/dist/index.mjs +380 -0
  148. package/dist/node_modules/rendu/package.json +47 -0
  149. package/dist/presets/_nitro/runtime/nitro-dev.mjs +4 -7
  150. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +5 -4
  151. package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
  152. package/dist/presets/cloudflare/runtime/_module-handler.mjs +7 -6
  153. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -5
  154. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +7 -10
  155. package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +21 -0
  156. package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
  157. package/dist/presets/node/runtime/node-server.mjs +1 -1
  158. package/dist/runtime/index.d.mts +1 -1
  159. package/dist/runtime/index.mjs +1 -1
  160. package/dist/runtime/internal/app.d.mts +3 -1
  161. package/dist/runtime/internal/app.mjs +90 -64
  162. package/dist/runtime/internal/error/prod.d.mts +3 -2
  163. package/dist/runtime/internal/error/prod.mjs +9 -13
  164. package/dist/runtime/internal/renderer.mjs +4 -4
  165. package/dist/runtime/internal/routes/dev-tasks.d.mts +30 -2
  166. package/dist/runtime/internal/shutdown.d.mts +1 -2
  167. package/dist/runtime/internal/shutdown.mjs +3 -2
  168. package/dist/runtime/internal/task.mjs +1 -2
  169. package/dist/types/index.d.mts +1603 -10
  170. package/dist/vite.d.mts +5 -0
  171. package/dist/vite.mjs +94 -30
  172. package/lib/index.mjs +1 -0
  173. package/lib/indexd.mts +1 -0
  174. package/lib/runtime/meta.mjs +35 -0
  175. package/package.json +40 -41
  176. package/dist/_chunks/build.mjs +0 -84
  177. package/dist/_chunks/build3.mjs +0 -6452
  178. package/dist/_chunks/detect-acorn.mjs +0 -503
  179. package/dist/_chunks/index.mjs +0 -22242
  180. package/dist/_chunks/json5.mjs +0 -68
  181. package/dist/_chunks/jsonc.mjs +0 -51
  182. package/dist/_chunks/toml.mjs +0 -259
  183. package/dist/_chunks/yaml.mjs +0 -86
  184. package/dist/index.mjs +0 -55
  185. package/dist/node_modules/klona/dist/index.mjs +0 -81
  186. package/dist/node_modules/klona/full/index.mjs +0 -53
  187. package/dist/node_modules/klona/package.json +0 -74
  188. package/dist/node_modules/std-env/dist/index.mjs +0 -1
  189. package/dist/node_modules/std-env/package.json +0 -46
  190. package/dist/presets.mjs +0 -2460
  191. package/dist/runtime/internal/debug.d.mts +0 -2
  192. package/dist/runtime/internal/debug.mjs +0 -5
  193. package/lib/runtime-meta.mjs +0 -38
  194. /package/dist/{cli → _cli}/common.mjs +0 -0
  195. /package/lib/{runtime-meta.d.mts → runtime/meta.d.mts} +0 -0
@@ -0,0 +1,575 @@
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { M as MagicString } from '../magic-string.mjs';
6
+ import 'srvx/node';
7
+ import { s as stripLiteral } from '../strip-literal.mjs';
8
+ import { normalizePath, isCSSRequest } from 'vite';
9
+ import 'node:assert';
10
+ import { createHash } from 'node:crypto';
11
+
12
+ //#region src/plugins/shared.ts
13
+ function parseIdQuery(id) {
14
+ if (!id.includes("?")) return {
15
+ filename: id,
16
+ query: {}
17
+ };
18
+ const [filename, rawQuery] = id.split(`?`, 2);
19
+ const query = Object.fromEntries(new URLSearchParams(rawQuery));
20
+ return {
21
+ filename,
22
+ query
23
+ };
24
+ }
25
+ function toAssetsVirtual(options) {
26
+ return `virtual:fullstack/assets?${new URLSearchParams(options)}&lang.js`;
27
+ }
28
+ function parseAssetsVirtual(id) {
29
+ if (id.startsWith("\0virtual:fullstack/assets?")) return parseIdQuery(id).query;
30
+ }
31
+
32
+ //#endregion
33
+ //#region src/plugins/utils.ts
34
+ function createVirtualPlugin(name, load) {
35
+ name = "virtual:" + name;
36
+ return {
37
+ name: `rsc:virtual-${name}`,
38
+ resolveId: { handler(source, _importer, _options) {
39
+ return source === name ? "\0" + name : void 0;
40
+ } },
41
+ load: { handler(id, options) {
42
+ if (id === "\0" + name) return load.apply(this, [id, options]);
43
+ } }
44
+ };
45
+ }
46
+ function normalizeRelativePath(s) {
47
+ s = normalizePath(s);
48
+ return s[0] === "." ? s : "./" + s;
49
+ }
50
+ function hashString(v) {
51
+ return createHash("sha256").update(v).digest().toString("hex").slice(0, 12);
52
+ }
53
+
54
+ //#endregion
55
+ //#region src/plugins/vite-utils.ts
56
+ const VALID_ID_PREFIX = `/@id/`;
57
+ const NULL_BYTE_PLACEHOLDER = `__x00__`;
58
+ const FS_PREFIX = `/@fs/`;
59
+ function wrapId(id) {
60
+ return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
61
+ }
62
+ function withTrailingSlash(path$1) {
63
+ if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
64
+ return path$1;
65
+ }
66
+ const postfixRE = /[?#].*$/;
67
+ function cleanUrl(url) {
68
+ return url.replace(postfixRE, "");
69
+ }
70
+ function splitFileAndPostfix(path$1) {
71
+ const file = cleanUrl(path$1);
72
+ return {
73
+ file,
74
+ postfix: path$1.slice(file.length)
75
+ };
76
+ }
77
+ const windowsSlashRE = /\\/g;
78
+ function slash(p) {
79
+ return p.replace(windowsSlashRE, "/");
80
+ }
81
+ const isWindows = typeof process !== "undefined" && process.platform === "win32";
82
+ function injectQuery(url, queryToInject) {
83
+ const { file, postfix } = splitFileAndPostfix(url);
84
+ const normalizedFile = isWindows ? slash(file) : file;
85
+ return `${normalizedFile}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : postfix}`;
86
+ }
87
+ function normalizeResolvedIdToUrl(environment, url, resolved) {
88
+ const root = environment.config.root;
89
+ const depsOptimizer = environment.depsOptimizer;
90
+ if (resolved.id.startsWith(withTrailingSlash(root))) url = resolved.id.slice(root.length);
91
+ else if (depsOptimizer?.isOptimizedDepFile(resolved.id) || resolved.id !== "/@react-refresh" && path.isAbsolute(resolved.id) && fs.existsSync(cleanUrl(resolved.id))) url = path.posix.join(FS_PREFIX, resolved.id);
92
+ else url = resolved.id;
93
+ if (url[0] !== "." && url[0] !== "/") url = wrapId(resolved.id);
94
+ return url;
95
+ }
96
+ function normalizeViteImportAnalysisUrl(environment, id) {
97
+ let url = normalizeResolvedIdToUrl(environment, id, { id });
98
+ if (environment.config.consumer === "client") {
99
+ const mod = environment.moduleGraph.getModuleById(id);
100
+ if (mod && mod.lastHMRTimestamp > 0) url = injectQuery(url, `t=${mod.lastHMRTimestamp}`);
101
+ }
102
+ return url;
103
+ }
104
+ function evalValue(rawValue) {
105
+ const fn = new Function(`
106
+ var console, exports, global, module, process, require
107
+ return (\n${rawValue}\n)
108
+ `);
109
+ return fn();
110
+ }
111
+ const directRequestRE = /(\?|&)direct=?(?:&|$)/;
112
+ function assetsPlugin(pluginOpts) {
113
+ let server;
114
+ let resolvedConfig;
115
+ const importAssetsMetaMap = {};
116
+ const bundleMap = {};
117
+ async function processAssetsImport(ctx, id, options) {
118
+ if (ctx.environment.mode === "dev") {
119
+ const result = {
120
+ entry: void 0,
121
+ js: [],
122
+ css: []
123
+ };
124
+ const environment = server.environments[options.environment];
125
+ assert(environment, `Unknown environment: ${options.environment}`);
126
+ if (options.environment === "client") result.entry = normalizeViteImportAnalysisUrl(environment, id);
127
+ if (environment.name !== "client") {
128
+ const collected = await collectCss(environment, id, { eager: pluginOpts?.experimental?.devEagerTransform ?? true });
129
+ result.css = collected.hrefs.map((href, i) => ({
130
+ href,
131
+ "data-vite-dev-id": collected.ids[i]
132
+ }));
133
+ }
134
+ return JSON.stringify(result);
135
+ } else {
136
+ const map = importAssetsMetaMap[options.environment] ??= {};
137
+ const meta = {
138
+ id,
139
+ key: path.relative(resolvedConfig.root, id),
140
+ importerEnvironment: ctx.environment.name,
141
+ isEntry: !!(map[id]?.isEntry || options.isEntry)
142
+ };
143
+ map[id] = meta;
144
+ return `__assets_manifest[${JSON.stringify(options.environment)}][${JSON.stringify(meta.key)}]`;
145
+ }
146
+ }
147
+ let writeAssetsManifestCalled = false;
148
+ async function writeAssetsManifest(builder) {
149
+ if (writeAssetsManifestCalled) return;
150
+ writeAssetsManifestCalled = true;
151
+ const manifest = {};
152
+ for (const [environmentName, metas] of Object.entries(importAssetsMetaMap)) {
153
+ const bundle = bundleMap[environmentName];
154
+ const assetDepsMap = collectAssetDeps(bundle);
155
+ for (const [id, meta] of Object.entries(metas)) {
156
+ const found = assetDepsMap[id];
157
+ if (!found) {
158
+ builder.config.logger.error(`[vite-plugin-fullstack] failed to find built chunk for ${meta.id} imported by ${meta.importerEnvironment} environment`);
159
+ return;
160
+ }
161
+ const result = {
162
+ js: [],
163
+ css: []
164
+ };
165
+ const { chunk, deps } = found;
166
+ if (environmentName === "client") {
167
+ result.entry = `/${chunk.fileName}`;
168
+ result.js = deps.js.map((fileName) => ({ href: `/${fileName}` }));
169
+ }
170
+ result.css = deps.css.map((fileName) => ({ href: `/${fileName}` }));
171
+ if (!builder.environments[environmentName].config.build.cssCodeSplit) {
172
+ const singleCss = Object.values(bundle).find((v) => v.type === "asset" && v.originalFileNames.includes("style.css"));
173
+ if (singleCss) result.css.push({ href: `/${singleCss.fileName}` });
174
+ }
175
+ (manifest[environmentName] ??= {})[meta.key] = result;
176
+ }
177
+ }
178
+ const importerEnvironments = new Set(Object.values(importAssetsMetaMap).flatMap((metas) => Object.values(metas)).flatMap((meta) => meta.importerEnvironment));
179
+ for (const environmentName of importerEnvironments) {
180
+ const outDir = builder.environments[environmentName].config.build.outDir;
181
+ fs.writeFileSync(path.join(outDir, BUILD_ASSETS_MANIFEST_NAME), `export default ${JSON.stringify(manifest, null, 2)};`);
182
+ const clientOutDir = builder.environments["client"].config.build.outDir;
183
+ for (const asset of Object.values(bundleMap[environmentName])) if (asset.type === "asset") {
184
+ const srcFile = path.join(outDir, asset.fileName);
185
+ const destFile = path.join(clientOutDir, asset.fileName);
186
+ fs.mkdirSync(path.dirname(destFile), { recursive: true });
187
+ fs.copyFileSync(srcFile, destFile);
188
+ }
189
+ }
190
+ }
191
+ return [
192
+ {
193
+ name: "fullstack:assets",
194
+ sharedDuringBuild: true,
195
+ configureServer(server_) {
196
+ server = server_;
197
+ },
198
+ configResolved(config) {
199
+ resolvedConfig = config;
200
+ },
201
+ configEnvironment(name) {
202
+ const serverEnvironments = pluginOpts?.serverEnvironments ?? ["ssr"];
203
+ if (serverEnvironments.includes(name)) return { build: { emitAssets: true } };
204
+ },
205
+ transform: { async handler(code, id, _options) {
206
+ if (!code.includes("import.meta.vite.assets")) return;
207
+ const output = new MagicString(code);
208
+ const strippedCode = stripLiteral(code);
209
+ const newImports = /* @__PURE__ */ new Set();
210
+ for (const match of code.matchAll(/import\.meta\.vite\.assets\(([\s\S]*?)\)/dg)) {
211
+ const [start, end] = match.indices[0];
212
+ if (!strippedCode.slice(start, end).includes("import.meta.vite.assets")) continue;
213
+ if (this.environment.name === "client") {
214
+ const replacement$1 = `(${JSON.stringify(EMPTY_ASSETS)})`;
215
+ output.update(start, end, replacement$1);
216
+ continue;
217
+ }
218
+ const argCode = match[1].trim();
219
+ const options = {
220
+ import: id,
221
+ environment: void 0,
222
+ asEntry: false
223
+ };
224
+ if (argCode) {
225
+ const argValue = evalValue(argCode);
226
+ Object.assign(options, argValue);
227
+ }
228
+ const environments = options.environment ? [options.environment] : ["client", this.environment.name];
229
+ const importedNames = [];
230
+ for (const environment of environments) {
231
+ const importSource = toAssetsVirtual({
232
+ import: options.import,
233
+ importer: id,
234
+ environment,
235
+ entry: options.asEntry ? "1" : ""
236
+ });
237
+ const hash = hashString(importSource);
238
+ const importedName = `__assets_${hash}`;
239
+ newImports.add(`;import ${importedName} from ${JSON.stringify(importSource)};\n`);
240
+ importedNames.push(importedName);
241
+ }
242
+ let replacement = importedNames[0];
243
+ if (importedNames.length > 1) {
244
+ newImports.add(`;import * as __assets_runtime from "virtual:fullstack/runtime";\n`);
245
+ replacement = `__assets_runtime.mergeAssets(${importedNames.join(", ")})`;
246
+ }
247
+ output.update(start, end, `(${replacement})`);
248
+ }
249
+ if (output.hasChanged()) {
250
+ for (const newImport of newImports) output.append(newImport);
251
+ return {
252
+ code: output.toString(),
253
+ map: output.generateMap({ hires: "boundary" })
254
+ };
255
+ }
256
+ } },
257
+ resolveId: { handler(source) {
258
+ if (source.startsWith("virtual:fullstack/assets?")) return "\0" + source;
259
+ if (source === "virtual:fullstack/assets-manifest") {
260
+ assert.notEqual(this.environment.name, "client");
261
+ assert.equal(this.environment.mode, "build");
262
+ return {
263
+ id: source,
264
+ external: true
265
+ };
266
+ }
267
+ if (source === "virtual:fullstack/runtime") return { id: source };
268
+ } },
269
+ load: { async handler(id) {
270
+ if (id === "virtual:fullstack/runtime") return runtimeUtils();
271
+ const parsed = parseAssetsVirtual(id);
272
+ if (!parsed) return;
273
+ assert.notEqual(this.environment.name, "client");
274
+ const resolved = await this.resolve(parsed.import, parsed.importer);
275
+ assert(resolved, `Failed to resolve: ${parsed.import}`);
276
+ const s = new MagicString("");
277
+ const code = await processAssetsImport(this, resolved.id, {
278
+ environment: parsed.environment,
279
+ isEntry: !!parsed.entry
280
+ });
281
+ s.append(`export default ${code};\n`);
282
+ if (this.environment.mode === "build") s.prepend(`import __assets_manifest from "virtual:fullstack/assets-manifest";\n`);
283
+ return s.toString();
284
+ } },
285
+ renderChunk(code, chunk) {
286
+ if (code.includes("virtual:fullstack/assets-manifest")) {
287
+ const replacement = normalizeRelativePath(path.relative(path.join(chunk.fileName, ".."), BUILD_ASSETS_MANIFEST_NAME));
288
+ code = code.replaceAll("virtual:fullstack/assets-manifest", () => replacement);
289
+ return { code };
290
+ }
291
+ return;
292
+ },
293
+ writeBundle(_options, bundle) {
294
+ bundleMap[this.environment.name] = bundle;
295
+ },
296
+ buildStart() {
297
+ if (this.environment.mode == "build" && this.environment.name === "client") {
298
+ const metas = importAssetsMetaMap["client"];
299
+ if (metas) {
300
+ for (const meta of Object.values(importAssetsMetaMap["client"])) if (meta.isEntry) this.emitFile({
301
+ type: "chunk",
302
+ id: meta.id,
303
+ preserveSignature: "exports-only"
304
+ });
305
+ }
306
+ }
307
+ },
308
+ buildApp: {
309
+ order: "pre",
310
+ async handler(builder) {
311
+ builder.writeAssetsManifest = async () => {
312
+ await writeAssetsManifest(builder);
313
+ };
314
+ }
315
+ }
316
+ },
317
+ {
318
+ name: "fullstack:write-assets-manifest-post",
319
+ buildApp: {
320
+ order: "post",
321
+ async handler(builder) {
322
+ await builder.writeAssetsManifest();
323
+ }
324
+ }
325
+ },
326
+ {
327
+ name: "fullstack:assets-query",
328
+ sharedDuringBuild: true,
329
+ resolveId: {
330
+ order: "pre",
331
+ handler(source) {
332
+ const { query } = parseIdQuery(source);
333
+ const value = query["assets"];
334
+ if (typeof value !== "undefined") {
335
+ if (this.environment.name === "client") return `\0virtual:fullstack/empty-assets`;
336
+ }
337
+ if (source === "virtual:fullstack/runtime") return source;
338
+ }
339
+ },
340
+ load: { async handler(id) {
341
+ if (id === "\0virtual:fullstack/empty-assets") return `export default ${JSON.stringify(EMPTY_ASSETS)}`;
342
+ if (id === "virtual:fullstack/runtime") return runtimeUtils();
343
+ const { filename, query } = parseIdQuery(id);
344
+ const value = query["assets"];
345
+ if (typeof value !== "undefined") {
346
+ const s = new MagicString("");
347
+ const codes = [];
348
+ if (value) {
349
+ const code = await processAssetsImport(this, filename, {
350
+ environment: value,
351
+ isEntry: value === "client"
352
+ });
353
+ codes.push(code);
354
+ } else {
355
+ const code1 = await processAssetsImport(this, filename, {
356
+ environment: "client",
357
+ isEntry: false
358
+ });
359
+ const code2 = await processAssetsImport(this, filename, {
360
+ environment: this.environment.name,
361
+ isEntry: false
362
+ });
363
+ codes.push(code1, code2);
364
+ }
365
+ s.append(`
366
+ import * as __assets_runtime from "virtual:fullstack/runtime";\n
367
+ export default __assets_runtime.mergeAssets(${codes.join(", ")});
368
+ `);
369
+ if (this.environment.mode === "build") s.prepend(`import __assets_manifest from "virtual:fullstack/assets-manifest";\n`);
370
+ return {
371
+ code: s.toString(),
372
+ moduleSideEffects: false
373
+ };
374
+ }
375
+ } },
376
+ hotUpdate(ctx) {
377
+ if (this.environment.name === "rsc") {
378
+ const mods = collectModuleDependents(ctx.modules);
379
+ for (const mod of mods) if (mod.id) {
380
+ const ids = [
381
+ `${mod.id}?assets`,
382
+ `${mod.id}?assets=client`,
383
+ `${mod.id}?assets=${this.environment.name}`
384
+ ];
385
+ for (const id of ids) invalidteModuleById(this.environment, id);
386
+ }
387
+ }
388
+ }
389
+ },
390
+ {
391
+ ...createVirtualPlugin("fullstack/client-fallback", () => "export {}"),
392
+ configEnvironment: {
393
+ order: "post",
394
+ handler(name, config, _env) {
395
+ if (name === "client") {
396
+ const clientBuildFallback = pluginOpts?.experimental?.clientBuildFallback ?? true;
397
+ if (clientBuildFallback && !config.build?.rollupOptions?.input) return { build: { rollupOptions: { input: { __fallback: "virtual:fullstack/client-fallback" } } } };
398
+ }
399
+ }
400
+ },
401
+ generateBundle(_optoins, bundle) {
402
+ if (this.environment.name !== "client") return;
403
+ for (const [k, v] of Object.entries(bundle)) if (v.type === "chunk" && v.name === "__fallback") delete bundle[k];
404
+ }
405
+ },
406
+ patchViteClientPlugin(),
407
+ patchVueScopeCssHmr(),
408
+ patchCssLinkSelfAccept()
409
+ ];
410
+ }
411
+ const EMPTY_ASSETS = {
412
+ js: [],
413
+ css: []
414
+ };
415
+ const BUILD_ASSETS_MANIFEST_NAME = "__fullstack_assets_manifest.js";
416
+ async function collectCss(environment, entryId, options) {
417
+ const visited = /* @__PURE__ */ new Set();
418
+ const cssIds = /* @__PURE__ */ new Set();
419
+ async function recurse(id) {
420
+ if (visited.has(id) || parseAssetsVirtual(id) || "assets" in parseIdQuery(id).query) return;
421
+ visited.add(id);
422
+ const mod = environment.moduleGraph.getModuleById(id);
423
+ if (!mod) return;
424
+ if (options.eager && !mod?.transformResult) try {
425
+ await environment.transformRequest(id);
426
+ } catch (e) {
427
+ console.error(`[collectCss] Failed to transform '${id}'`, e);
428
+ }
429
+ for (const next of mod?.importedModules ?? []) if (next.id) if (isCSSRequest(next.id)) {
430
+ if (hasSpecialCssQuery(next.id)) continue;
431
+ cssIds.add(next.id);
432
+ } else await recurse(next.id);
433
+ }
434
+ await recurse(entryId);
435
+ const hrefs = [...cssIds].map((id) => normalizeViteImportAnalysisUrl(environment, id));
436
+ return {
437
+ ids: [...cssIds],
438
+ hrefs
439
+ };
440
+ }
441
+ function invalidteModuleById(environment, id) {
442
+ const mod = environment.moduleGraph.getModuleById(id);
443
+ if (mod) environment.moduleGraph.invalidateModule(mod);
444
+ return mod;
445
+ }
446
+ function collectModuleDependents(mods) {
447
+ const visited = /* @__PURE__ */ new Set();
448
+ function recurse(mod) {
449
+ if (visited.has(mod)) return;
450
+ visited.add(mod);
451
+ for (const importer of mod.importers) recurse(importer);
452
+ }
453
+ for (const mod of mods) recurse(mod);
454
+ return [...visited];
455
+ }
456
+ function hasSpecialCssQuery(id) {
457
+ return /[?&](url|inline|raw)(\b|=|&|$)/.test(id);
458
+ }
459
+ function collectAssetDeps(bundle) {
460
+ const chunkToDeps = /* @__PURE__ */ new Map();
461
+ for (const chunk of Object.values(bundle)) if (chunk.type === "chunk") chunkToDeps.set(chunk, collectAssetDepsInner(chunk.fileName, bundle));
462
+ const idToDeps = {};
463
+ for (const [chunk, deps] of chunkToDeps.entries()) for (const id of chunk.moduleIds) idToDeps[id] = {
464
+ chunk,
465
+ deps
466
+ };
467
+ return idToDeps;
468
+ }
469
+ function collectAssetDepsInner(fileName, bundle) {
470
+ const visited = /* @__PURE__ */ new Set();
471
+ const css = [];
472
+ function recurse(k) {
473
+ if (visited.has(k)) return;
474
+ visited.add(k);
475
+ const v = bundle[k];
476
+ assert(v, `Not found '${k}' in the bundle`);
477
+ if (v.type === "chunk") {
478
+ css.push(...v.viteMetadata?.importedCss ?? []);
479
+ for (const k2 of v.imports) if (k2 in bundle) recurse(k2);
480
+ }
481
+ }
482
+ recurse(fileName);
483
+ return {
484
+ js: [...visited],
485
+ css: [...new Set(css)]
486
+ };
487
+ }
488
+ function patchViteClientPlugin() {
489
+ const viteClientPath = normalizePath(fileURLToPath(import.meta.resolve("vite/dist/client/client.mjs")));
490
+ function endIndexOf(code, searchValue) {
491
+ const i = code.lastIndexOf(searchValue);
492
+ return i === -1 ? i : i + searchValue.length;
493
+ }
494
+ return {
495
+ name: "fullstack:patch-vite-client",
496
+ transform: { handler(code, id) {
497
+ if (id === viteClientPath) {
498
+ if (code.includes("linkSheetsMap")) return;
499
+ const s = new MagicString(code);
500
+ s.prependLeft(code.indexOf("const sheetsMap"), `\
501
+ const linkSheetsMap = new Map();
502
+ document
503
+ .querySelectorAll('link[rel="stylesheet"][data-vite-dev-id]')
504
+ .forEach((el) => {
505
+ linkSheetsMap.set(el.getAttribute('data-vite-dev-id'), el)
506
+ });
507
+ `);
508
+ s.appendLeft(endIndexOf(code, `function updateStyle(id, content) {`), `if (linkSheetsMap.has(id)) { return }`);
509
+ s.appendLeft(endIndexOf(code, `function removeStyle(id) {`), `
510
+ const link = linkSheetsMap.get(id);
511
+ if (link) {
512
+ document
513
+ .querySelectorAll(
514
+ 'link[rel="stylesheet"][data-vite-dev-id]',
515
+ )
516
+ .forEach((el) => {
517
+ if (el.getAttribute('data-vite-dev-id') === id) {
518
+ el.remove()
519
+ }
520
+ })
521
+ linkSheetsMap.delete(id)
522
+ }
523
+ `);
524
+ return s.toString();
525
+ }
526
+ } }
527
+ };
528
+ }
529
+ function patchVueScopeCssHmr() {
530
+ return {
531
+ name: "fullstack:patch-vue-scoped-css-hmr",
532
+ configureServer(server) {
533
+ server.middlewares.use((req, _res, next) => {
534
+ if (req.headers.accept?.includes("text/css") && req.url?.includes("&lang.css=")) req.url = req.url.replace("&lang.css=", "?lang.css");
535
+ next();
536
+ });
537
+ }
538
+ };
539
+ }
540
+ function patchCssLinkSelfAccept() {
541
+ return {
542
+ name: "fullstack:patch-css-link-self-accept",
543
+ apply: "serve",
544
+ transform: {
545
+ order: "post",
546
+ handler(_code, id, _options) {
547
+ if (this.environment.name === "client" && this.environment.mode === "dev" && isCSSRequest(id) && directRequestRE.test(id)) {
548
+ const mod = this.environment.moduleGraph.getModuleById(id);
549
+ if (mod && !mod.isSelfAccepting) mod.isSelfAccepting = true;
550
+ }
551
+ }
552
+ }
553
+ };
554
+ }
555
+ function runtimeUtils() {
556
+ return `
557
+ export function mergeAssets(...args) {
558
+ const js = uniqBy(args.flatMap((h) => h.js), (a) => a.href);
559
+ const css = uniqBy(args.flatMap((h) => h.css), (a) => a.href);
560
+ const entry = args.filter((arg) => arg.entry)?.[0]?.entry;
561
+ const raw = { entry, js, css };
562
+ return { ...raw, merge: (...args$1) => mergeAssets(raw, ...args$1) };
563
+ }
564
+ function uniqBy(array, key) {
565
+ const seen = new Set();
566
+ return array.filter((item) => {
567
+ const k = key(item);
568
+ if (seen.has(k)) return false;
569
+ seen.add(k);
570
+ return true;
571
+ });
572
+ }`;
573
+ }
574
+
575
+ export { assetsPlugin as a };
@@ -0,0 +1,89 @@
1
+ import path from 'node:path';
2
+
3
+ function matches(pattern, importee) {
4
+ if (pattern instanceof RegExp) {
5
+ return pattern.test(importee);
6
+ }
7
+ if (importee.length < pattern.length) {
8
+ return false;
9
+ }
10
+ if (importee === pattern) {
11
+ return true;
12
+ }
13
+ // eslint-disable-next-line prefer-template
14
+ return importee.startsWith(pattern + '/');
15
+ }
16
+ function getEntries({ entries, customResolver }) {
17
+ if (!entries) {
18
+ return [];
19
+ }
20
+ const resolverFunctionFromOptions = resolveCustomResolver(customResolver);
21
+ if (Array.isArray(entries)) {
22
+ return entries.map((entry) => {
23
+ return {
24
+ find: entry.find,
25
+ replacement: entry.replacement,
26
+ resolverFunction: resolveCustomResolver(entry.customResolver) || resolverFunctionFromOptions
27
+ };
28
+ });
29
+ }
30
+ return Object.entries(entries).map(([key, value]) => {
31
+ return { find: key, replacement: value, resolverFunction: resolverFunctionFromOptions };
32
+ });
33
+ }
34
+ function getHookFunction(hook) {
35
+ if (typeof hook === 'function') {
36
+ return hook;
37
+ }
38
+ if (hook && 'handler' in hook && typeof hook.handler === 'function') {
39
+ return hook.handler;
40
+ }
41
+ return null;
42
+ }
43
+ function resolveCustomResolver(customResolver) {
44
+ if (typeof customResolver === 'function') {
45
+ return customResolver;
46
+ }
47
+ if (customResolver) {
48
+ return getHookFunction(customResolver.resolveId);
49
+ }
50
+ return null;
51
+ }
52
+ function alias(options = {}) {
53
+ const entries = getEntries(options);
54
+ if (entries.length === 0) {
55
+ return {
56
+ name: 'alias',
57
+ resolveId: () => null
58
+ };
59
+ }
60
+ return {
61
+ name: 'alias',
62
+ async buildStart(inputOptions) {
63
+ await Promise.all([...(Array.isArray(options.entries) ? options.entries : []), options].map(({ customResolver }) => customResolver && getHookFunction(customResolver.buildStart)?.call(this, inputOptions)));
64
+ },
65
+ resolveId(importee, importer, resolveOptions) {
66
+ // First match is supposed to be the correct one
67
+ const matchedEntry = entries.find((entry) => matches(entry.find, importee));
68
+ if (!matchedEntry) {
69
+ return null;
70
+ }
71
+ const updatedId = importee.replace(matchedEntry.find, matchedEntry.replacement);
72
+ if (matchedEntry.resolverFunction) {
73
+ return matchedEntry.resolverFunction.call(this, updatedId, importer, resolveOptions);
74
+ }
75
+ return this.resolve(updatedId, importer, Object.assign({ skipSelf: true }, resolveOptions)).then((resolved) => {
76
+ if (resolved)
77
+ return resolved;
78
+ if (!path.isAbsolute(updatedId)) {
79
+ this.warn(`rewrote ${importee} to ${updatedId} but was not an absolute path and was not handled by other plugins. ` +
80
+ `This will lead to duplicated modules for the same path. ` +
81
+ `To avoid duplicating modules, you should resolve to an absolute path.`);
82
+ }
83
+ return { id: updatedId };
84
+ });
85
+ }
86
+ };
87
+ }
88
+
89
+ export { alias as a };