nitro-nightly 3.1.0-20251028-004953-57503e42 → 3.1.0-20251028-110430-e607b753
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.
- package/dist/_build/assets.mjs +235 -0
- package/dist/_build/build.mjs +21 -0
- package/dist/_build/config.mjs +124 -0
- package/dist/_build/info.mjs +39 -0
- package/dist/_build/plugins.mjs +1041 -0
- package/dist/_build/prepare.mjs +17 -0
- package/dist/{_chunks/build2.mjs → _build/rolldown.mjs} +238 -64
- package/dist/_build/rollup.mjs +404 -0
- package/dist/_build/snapshot.mjs +61 -0
- package/dist/_build/types.mjs +268 -0
- package/dist/_build/vite.mjs +3266 -0
- package/dist/{cli → _cli}/build.mjs +2 -3
- package/dist/_cli/dev.mjs +205 -0
- package/dist/{cli/index2.mjs → _cli/index.mjs} +1 -2
- package/dist/{cli → _cli}/list.mjs +2 -3
- package/dist/{cli → _cli}/prepare.mjs +2 -3
- package/dist/{cli → _cli}/run.mjs +2 -3
- package/dist/_deps/@jridgewell/gen-mapping.mjs +189 -0
- package/dist/_deps/@jridgewell/remapping.mjs +137 -0
- package/dist/_deps/@jridgewell/resolve-uri.mjs +231 -0
- package/dist/_deps/@jridgewell/sourcemap-codec.mjs +173 -0
- package/dist/_deps/@jridgewell/trace-mapping.mjs +170 -0
- package/dist/_deps/@pi0/vite-plugin-fullstack.mjs +575 -0
- package/dist/_deps/@rollup/plugin-alias.mjs +89 -0
- package/dist/_deps/@rollup/plugin-commonjs.mjs +2376 -0
- package/dist/{_chunks/index2.mjs → _deps/@rollup/plugin-inject.mjs} +5 -90
- package/dist/_deps/@rollup/plugin-json.mjs +37 -0
- package/dist/_deps/@rollup/plugin-node-resolve.mjs +1386 -0
- package/dist/_deps/@rollup/plugin-replace.mjs +133 -0
- package/dist/_deps/@rollup/pluginutils.mjs +346 -0
- package/dist/_deps/acorn.mjs +6225 -0
- package/dist/_deps/c12.mjs +510 -0
- package/dist/_deps/chokidar.mjs +1428 -0
- package/dist/_deps/citty.mjs +460 -0
- package/dist/_deps/commondir.mjs +77 -0
- package/dist/_deps/compatx.mjs +76 -0
- package/dist/_deps/confbox.mjs +300 -0
- package/dist/_deps/debug.mjs +885 -0
- package/dist/_deps/deepmerge.mjs +147 -0
- package/dist/_deps/depd.mjs +550 -0
- package/dist/_deps/dot-prop.mjs +282 -0
- package/dist/_deps/dotenv.mjs +555 -0
- package/dist/_deps/duplexer.mjs +1 -0
- package/dist/_deps/ee-first.mjs +104 -0
- package/dist/_deps/encodeurl.mjs +69 -0
- package/dist/_deps/escape-html.mjs +87 -0
- package/dist/_deps/escape-string-regexp.mjs +13 -0
- package/dist/_deps/estree-walker.mjs +433 -0
- package/dist/_deps/etag.mjs +147 -0
- package/dist/_deps/exsolve.mjs +1416 -0
- package/dist/_deps/fdir.mjs +569 -0
- package/dist/_deps/fresh.mjs +145 -0
- package/dist/_deps/function-bind.mjs +106 -0
- package/dist/{_chunks/index4.mjs → _deps/giget.mjs} +21 -776
- package/dist/_deps/gzip-size.mjs +19 -0
- package/dist/_deps/hasown.mjs +19 -0
- package/dist/_deps/http-errors.mjs +307 -0
- package/dist/_deps/httpxy.mjs +580 -0
- package/dist/_deps/inherits.mjs +57 -0
- package/dist/_deps/is-core-module.mjs +596 -0
- package/dist/_deps/is-module.mjs +25 -0
- package/dist/_deps/is-reference.mjs +31 -0
- package/dist/_deps/js-tokens.mjs +411 -0
- package/dist/_deps/knitwork.mjs +172 -0
- package/dist/_deps/local-pkg.mjs +163 -0
- package/dist/_deps/magic-string.mjs +1296 -0
- package/dist/_deps/mime-db.mjs +11685 -0
- package/dist/_deps/mime-types.mjs +287 -0
- package/dist/_deps/mime.mjs +1172 -0
- package/dist/_deps/mlly.mjs +2413 -0
- package/dist/_deps/ms.mjs +172 -0
- package/dist/_deps/node-fetch-native.mjs +3 -0
- package/dist/_deps/nypm.mjs +219 -0
- package/dist/_deps/on-finished.mjs +246 -0
- package/dist/_deps/parseurl.mjs +168 -0
- package/dist/_deps/path-parse.mjs +85 -0
- package/dist/{_chunks/pathe.M-eThtNZ.mjs → _deps/pathe.mjs} +48 -1
- package/dist/_deps/perfect-debounce.mjs +88 -0
- package/dist/_deps/picomatch.mjs +2144 -0
- package/dist/_deps/pkg-types.mjs +247 -0
- package/dist/_deps/pretty-bytes.mjs +180 -0
- package/dist/_deps/quansync.mjs +99 -0
- package/dist/_deps/range-parser.mjs +171 -0
- package/dist/_deps/rc9.mjs +219 -0
- package/dist/_deps/readdirp.mjs +245 -0
- package/dist/_deps/resolve.mjs +1260 -0
- package/dist/_deps/rou3.mjs +326 -0
- package/dist/_deps/send.mjs +1022 -0
- package/dist/_deps/serve-static.mjs +228 -0
- package/dist/_deps/setprototypeof.mjs +26 -0
- package/dist/_deps/statuses.mjs +457 -0
- package/dist/_deps/strip-literal.mjs +67 -0
- package/dist/_deps/supports-color.mjs +44 -0
- package/dist/_deps/tinyexec.mjs +552 -0
- package/dist/_deps/tinyglobby.mjs +293 -0
- package/dist/_deps/toidentifier.mjs +41 -0
- package/dist/_deps/ultrahtml.mjs +3 -0
- package/dist/_deps/unimport.mjs +2267 -0
- package/dist/_deps/unplugin-utils.mjs +65 -0
- package/dist/_deps/unplugin.mjs +1294 -0
- package/dist/_deps/untyped.mjs +375 -0
- package/dist/{_chunks/info.mjs → _deps/unwasm.mjs} +8 -4122
- package/dist/_deps/webpack-virtual-modules.mjs +360 -0
- package/dist/_presets/_all.mjs +59 -0
- package/dist/_presets/_nitro.mjs +74 -0
- package/dist/_presets/_resolve.mjs +64 -0
- package/dist/_presets/_static.mjs +69 -0
- package/dist/_presets/_types.mjs +3 -0
- package/dist/_presets/_utils.mjs +31 -0
- package/dist/_presets/alwaysdata.mjs +17 -0
- package/dist/_presets/aws-amplify.mjs +111 -0
- package/dist/_presets/aws-lambda.mjs +23 -0
- package/dist/_presets/azure.mjs +162 -0
- package/dist/_presets/bun.mjs +19 -0
- package/dist/_presets/cleavr.mjs +15 -0
- package/dist/_presets/cloudflare.mjs +608 -0
- package/dist/_presets/deno.mjs +196 -0
- package/dist/_presets/digitalocean.mjs +14 -0
- package/dist/_presets/firebase.mjs +47 -0
- package/dist/_presets/flightcontrol.mjs +14 -0
- package/dist/_presets/genezio.mjs +13 -0
- package/dist/_presets/heroku.mjs +14 -0
- package/dist/_presets/iis.mjs +194 -0
- package/dist/_presets/index.mjs +62 -0
- package/dist/_presets/koyeb.mjs +14 -0
- package/dist/_presets/netlify.mjs +241 -0
- package/dist/_presets/node.mjs +54 -0
- package/dist/_presets/platform.mjs +14 -0
- package/dist/_presets/render.mjs +14 -0
- package/dist/_presets/standard.mjs +23 -0
- package/dist/_presets/stormkit.mjs +18 -0
- package/dist/_presets/vercel.mjs +365 -0
- package/dist/_presets/winterjs.mjs +22 -0
- package/dist/_presets/zeabur.mjs +69 -0
- package/dist/_presets/zerops.mjs +27 -0
- package/dist/cli/index.mjs +7 -464
- package/dist/index.mjs +122 -34
- package/dist/vite.mjs +118 -44
- package/package.json +1 -1
- package/dist/_chunks/app.mjs +0 -19797
- package/dist/_chunks/build.mjs +0 -86
- package/dist/_chunks/build3.mjs +0 -6538
- package/dist/_chunks/detect-acorn.mjs +0 -503
- package/dist/_chunks/index.mjs +0 -22256
- package/dist/_chunks/index3.mjs +0 -1062
- package/dist/_chunks/json5.mjs +0 -68
- package/dist/_chunks/jsonc.mjs +0 -51
- package/dist/_chunks/plugin.mjs +0 -1560
- package/dist/_chunks/server.mjs +0 -254
- package/dist/_chunks/snapshot.mjs +0 -376
- package/dist/_chunks/toml.mjs +0 -259
- package/dist/_chunks/yaml.mjs +0 -86
- package/dist/cli/dev.mjs +0 -95
- package/dist/presets.mjs +0 -2494
- /package/dist/{cli → _cli}/common.mjs +0 -0
package/dist/_chunks/server.mjs
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { N as NitroDevApp, d as debounce, w as watch, a as NodeDevWorker } from './app.mjs';
|
|
2
|
-
import { HTTPError } from 'h3';
|
|
3
|
-
import { version } from 'nitro/meta';
|
|
4
|
-
import consola from 'consola';
|
|
5
|
-
import { writeFile } from 'node:fs/promises';
|
|
6
|
-
import { serve } from 'srvx/node';
|
|
7
|
-
import { isTest, isCI } from 'std-env';
|
|
8
|
-
import { r as resolve } from './pathe.M-eThtNZ.mjs';
|
|
9
|
-
|
|
10
|
-
function createDevServer(nitro) {
|
|
11
|
-
return new NitroDevServer(nitro);
|
|
12
|
-
}
|
|
13
|
-
class NitroDevServer extends NitroDevApp {
|
|
14
|
-
#entry;
|
|
15
|
-
#workerData = {};
|
|
16
|
-
#listeners = [];
|
|
17
|
-
#watcher;
|
|
18
|
-
#workers = [];
|
|
19
|
-
#workerIdCtr = 0;
|
|
20
|
-
#workerError;
|
|
21
|
-
#building = true;
|
|
22
|
-
// Assume initial build will start soon
|
|
23
|
-
#buildError;
|
|
24
|
-
#messageListeners = /* @__PURE__ */ new Set();
|
|
25
|
-
constructor(nitro) {
|
|
26
|
-
super(nitro, async (event) => {
|
|
27
|
-
const worker = await this.#getWorker();
|
|
28
|
-
if (!worker) {
|
|
29
|
-
return this.#generateError();
|
|
30
|
-
}
|
|
31
|
-
return worker.fetch(event.req);
|
|
32
|
-
});
|
|
33
|
-
for (const key of Object.getOwnPropertyNames(NitroDevServer.prototype)) {
|
|
34
|
-
const value = this[key];
|
|
35
|
-
if (typeof value === "function" && key !== "constructor") {
|
|
36
|
-
this[key] = value.bind(this);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
this.#entry = resolve(
|
|
40
|
-
nitro.options.output.dir,
|
|
41
|
-
nitro.options.output.serverDir,
|
|
42
|
-
"index.mjs"
|
|
43
|
-
);
|
|
44
|
-
nitro.hooks.hook("close", () => this.close());
|
|
45
|
-
nitro.hooks.hook("dev:start", () => {
|
|
46
|
-
this.#building = true;
|
|
47
|
-
this.#buildError = void 0;
|
|
48
|
-
});
|
|
49
|
-
nitro.hooks.hook("dev:reload", (payload) => {
|
|
50
|
-
this.#buildError = void 0;
|
|
51
|
-
this.#building = false;
|
|
52
|
-
if (payload?.entry) {
|
|
53
|
-
this.#entry = payload.entry;
|
|
54
|
-
}
|
|
55
|
-
if (payload?.workerData) {
|
|
56
|
-
this.#workerData = payload.workerData;
|
|
57
|
-
}
|
|
58
|
-
this.reload();
|
|
59
|
-
});
|
|
60
|
-
nitro.hooks.hook("dev:error", (cause) => {
|
|
61
|
-
this.#buildError = cause;
|
|
62
|
-
this.#building = false;
|
|
63
|
-
for (const worker of this.#workers) {
|
|
64
|
-
worker.close();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
if (nitro.options.devServer.watch.length > 0) {
|
|
68
|
-
const debouncedReload = debounce(() => this.reload());
|
|
69
|
-
this.#watcher = watch(
|
|
70
|
-
nitro.options.devServer.watch,
|
|
71
|
-
nitro.options.watchOptions
|
|
72
|
-
);
|
|
73
|
-
this.#watcher.on("add", debouncedReload).on("change", debouncedReload);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// #region Public Methods
|
|
77
|
-
async upgrade(req, socket, head) {
|
|
78
|
-
const worker = await this.#getWorker();
|
|
79
|
-
if (!worker) {
|
|
80
|
-
throw new HTTPError({
|
|
81
|
-
status: 503,
|
|
82
|
-
statusText: "No worker available."
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return worker.upgrade(req, socket, head);
|
|
86
|
-
}
|
|
87
|
-
listen(opts) {
|
|
88
|
-
const server = serve({
|
|
89
|
-
...opts,
|
|
90
|
-
fetch: this.fetch
|
|
91
|
-
});
|
|
92
|
-
this.#listeners.push(server);
|
|
93
|
-
if (server.node?.server) {
|
|
94
|
-
server.node.server.on(
|
|
95
|
-
"upgrade",
|
|
96
|
-
(req, sock, head) => this.upgrade(req, sock, head)
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
return server;
|
|
100
|
-
}
|
|
101
|
-
async close() {
|
|
102
|
-
await Promise.all(
|
|
103
|
-
[
|
|
104
|
-
Promise.all(this.#listeners.map((l) => l.close())).then(() => {
|
|
105
|
-
this.#listeners = [];
|
|
106
|
-
}),
|
|
107
|
-
Promise.all(this.#workers.map((w) => w.close())).then(() => {
|
|
108
|
-
this.#workers = [];
|
|
109
|
-
}),
|
|
110
|
-
Promise.resolve(this.#watcher?.close()).then(() => {
|
|
111
|
-
this.#watcher = void 0;
|
|
112
|
-
})
|
|
113
|
-
].map(
|
|
114
|
-
(p) => p.catch((error) => {
|
|
115
|
-
consola.error(error);
|
|
116
|
-
})
|
|
117
|
-
)
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
reload() {
|
|
121
|
-
for (const worker2 of this.#workers) {
|
|
122
|
-
worker2.close();
|
|
123
|
-
}
|
|
124
|
-
const worker = new NodeDevWorker({
|
|
125
|
-
name: `Nitro_${this.#workerIdCtr++}`,
|
|
126
|
-
entry: this.#entry,
|
|
127
|
-
data: {
|
|
128
|
-
...this.#workerData,
|
|
129
|
-
globals: {
|
|
130
|
-
__NITRO_RUNTIME_CONFIG__: this.nitro.options.runtimeConfig,
|
|
131
|
-
...this.#workerData.globals
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
hooks: {
|
|
135
|
-
onClose: (worker2, cause) => {
|
|
136
|
-
this.#workerError = cause;
|
|
137
|
-
const index = this.#workers.indexOf(worker2);
|
|
138
|
-
if (index !== -1) {
|
|
139
|
-
this.#workers.splice(index, 1);
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
onReady: (worker2, addr) => {
|
|
143
|
-
this.#writeBuildInfo(worker2, addr);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
if (!worker.closed) {
|
|
148
|
-
for (const listener of this.#messageListeners) {
|
|
149
|
-
worker.onMessage(listener);
|
|
150
|
-
}
|
|
151
|
-
this.#workers.unshift(worker);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
sendMessage(message) {
|
|
155
|
-
for (const worker of this.#workers) {
|
|
156
|
-
if (!worker.closed) {
|
|
157
|
-
worker.sendMessage(message);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
onMessage(listener) {
|
|
162
|
-
this.#messageListeners.add(listener);
|
|
163
|
-
for (const worker of this.#workers) {
|
|
164
|
-
worker.onMessage(listener);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
offMessage(listener) {
|
|
168
|
-
this.#messageListeners.delete(listener);
|
|
169
|
-
for (const worker of this.#workers) {
|
|
170
|
-
worker.offMessage(listener);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// #endregion
|
|
174
|
-
// #region Private Methods
|
|
175
|
-
#writeBuildInfo(_worker, addr) {
|
|
176
|
-
const buildInfoPath = resolve(this.nitro.options.buildDir, "nitro.json");
|
|
177
|
-
const buildInfo = {
|
|
178
|
-
date: (/* @__PURE__ */ new Date()).toJSON(),
|
|
179
|
-
preset: this.nitro.options.preset,
|
|
180
|
-
framework: this.nitro.options.framework,
|
|
181
|
-
versions: {
|
|
182
|
-
nitro: version
|
|
183
|
-
},
|
|
184
|
-
dev: {
|
|
185
|
-
pid: process.pid,
|
|
186
|
-
workerAddress: addr
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
writeFile(buildInfoPath, JSON.stringify(buildInfo, null, 2)).catch(
|
|
190
|
-
(error) => {
|
|
191
|
-
consola.error(error);
|
|
192
|
-
}
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
async #getWorker() {
|
|
196
|
-
let retry = 0;
|
|
197
|
-
const maxRetries = isTest || isCI ? 100 : 10;
|
|
198
|
-
while (this.#building || ++retry < maxRetries) {
|
|
199
|
-
if ((this.#workers.length === 0 || this.#buildError) && !this.#building) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const activeWorker = this.#workers.find((w) => w.ready);
|
|
203
|
-
if (activeWorker) {
|
|
204
|
-
return activeWorker;
|
|
205
|
-
}
|
|
206
|
-
await new Promise((resolve2) => setTimeout(resolve2, 600));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
#generateError() {
|
|
210
|
-
const error = this.#buildError || this.#workerError;
|
|
211
|
-
if (error) {
|
|
212
|
-
try {
|
|
213
|
-
error.unhandled = false;
|
|
214
|
-
let id = error.id || error.path;
|
|
215
|
-
if (id) {
|
|
216
|
-
const cause = error.errors?.[0];
|
|
217
|
-
const loc = error.location || error.loc || cause?.location || cause?.loc;
|
|
218
|
-
if (loc) {
|
|
219
|
-
id += `:${loc.line}:${loc.column}`;
|
|
220
|
-
}
|
|
221
|
-
error.stack = (error.stack || "").replace(
|
|
222
|
-
/(^\s*at\s+.+)/m,
|
|
223
|
-
` at ${id}
|
|
224
|
-
$1`
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
} catch {
|
|
228
|
-
}
|
|
229
|
-
return new HTTPError(error);
|
|
230
|
-
}
|
|
231
|
-
return new Response(
|
|
232
|
-
JSON.stringify(
|
|
233
|
-
{
|
|
234
|
-
error: "Dev server is unavailable.",
|
|
235
|
-
hint: "Please reload the page and check the console for errors if the issue persists."
|
|
236
|
-
},
|
|
237
|
-
null,
|
|
238
|
-
2
|
|
239
|
-
),
|
|
240
|
-
{
|
|
241
|
-
status: 503,
|
|
242
|
-
statusText: "Dev server is unavailable",
|
|
243
|
-
headers: {
|
|
244
|
-
"Content-Type": "application/json",
|
|
245
|
-
"Cache-Control": "no-store",
|
|
246
|
-
Refresh: "3"
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
// #endregion
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export { NitroDevServer as N, createDevServer as c };
|
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { promises } from 'node:fs';
|
|
2
|
-
import { m as mime, b as glob, c as snapshotStorage } from './index.mjs';
|
|
3
|
-
import { e as extname, r as resolve, d as dirname, a as relative, j as join } from './pathe.M-eThtNZ.mjs';
|
|
4
|
-
import { upperFirst } from 'scule';
|
|
5
|
-
import { colors } from 'consola/utils';
|
|
6
|
-
import 'node:stream';
|
|
7
|
-
import zlib from 'node:zlib';
|
|
8
|
-
import { promisify } from 'node:util';
|
|
9
|
-
import 'stream';
|
|
10
|
-
import { isTest } from 'std-env';
|
|
11
|
-
import { r as runParallel } from './index3.mjs';
|
|
12
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
13
|
-
|
|
14
|
-
const HELPER_ID = "\0raw-helpers";
|
|
15
|
-
function raw(opts = {}) {
|
|
16
|
-
const extensions = /* @__PURE__ */ new Set([
|
|
17
|
-
".md",
|
|
18
|
-
".mdx",
|
|
19
|
-
".txt",
|
|
20
|
-
".css",
|
|
21
|
-
".htm",
|
|
22
|
-
".html",
|
|
23
|
-
".sql",
|
|
24
|
-
...opts.extensions || []
|
|
25
|
-
]);
|
|
26
|
-
return {
|
|
27
|
-
name: "raw",
|
|
28
|
-
async resolveId(id, importer, resolveOpts) {
|
|
29
|
-
if (id === HELPER_ID) {
|
|
30
|
-
return id;
|
|
31
|
-
}
|
|
32
|
-
if (id[0] === "\0") {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const withRawSpecifier = id.startsWith("raw:");
|
|
36
|
-
if (withRawSpecifier) {
|
|
37
|
-
id = id.slice(4);
|
|
38
|
-
}
|
|
39
|
-
if (!withRawSpecifier && !extensions.has(extname(id))) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const resolvedId = (await this.resolve(id, importer, resolveOpts))?.id;
|
|
43
|
-
if (!resolvedId || resolvedId.startsWith("\0")) {
|
|
44
|
-
return resolvedId;
|
|
45
|
-
}
|
|
46
|
-
if (!withRawSpecifier && !extensions.has(extname(resolvedId))) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
return { id: "\0raw:" + resolvedId };
|
|
50
|
-
},
|
|
51
|
-
load(id) {
|
|
52
|
-
if (id === HELPER_ID) {
|
|
53
|
-
return getHelpers();
|
|
54
|
-
}
|
|
55
|
-
if (id.startsWith("\0raw:")) {
|
|
56
|
-
return promises.readFile(id.slice(5), isBinary(id) ? "binary" : "utf8");
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
transform(code, id) {
|
|
60
|
-
if (!id.startsWith("\0raw:")) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (isBinary(id)) {
|
|
64
|
-
const serialized = Buffer.from(code, "binary").toString("base64");
|
|
65
|
-
return {
|
|
66
|
-
code: `// ROLLUP_NO_REPLACE
|
|
67
|
-
import {base64ToUint8Array } from "${HELPER_ID}"
|
|
68
|
-
export default base64ToUint8Array("${serialized}")`,
|
|
69
|
-
map: null
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
code: `// ROLLUP_NO_REPLACE
|
|
74
|
-
export default ${JSON.stringify(code)}`,
|
|
75
|
-
map: null,
|
|
76
|
-
moduleType: "js"
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function isBinary(id) {
|
|
82
|
-
const idMime = mime.getType(id) || "";
|
|
83
|
-
if (idMime.startsWith("text/")) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
if (/application\/(json|sql|xml|yaml)/.test(idMime)) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
function getHelpers() {
|
|
92
|
-
const js = String.raw;
|
|
93
|
-
return js`
|
|
94
|
-
export function base64ToUint8Array(str) {
|
|
95
|
-
const data = atob(str);
|
|
96
|
-
const size = data.length;
|
|
97
|
-
const bytes = new Uint8Array(size);
|
|
98
|
-
for (let i = 0; i < size; i++) {
|
|
99
|
-
bytes[i] = data.charCodeAt(i);
|
|
100
|
-
}
|
|
101
|
-
return bytes;
|
|
102
|
-
}
|
|
103
|
-
`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function nitroServerName(nitro) {
|
|
107
|
-
return nitro.options.framework.name === "nitro" ? "Nitro Server" : `${upperFirst(nitro.options.framework.name)} Nitro server`;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const getOptions = options => ({level: 9, ...options});
|
|
111
|
-
const gzip = promisify(zlib.gzip);
|
|
112
|
-
|
|
113
|
-
async function gzipSize(input, options) {
|
|
114
|
-
if (!input) {
|
|
115
|
-
return 0;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const data = await gzip(input, getOptions(options));
|
|
119
|
-
return data.length;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const BYTE_UNITS = [
|
|
123
|
-
'B',
|
|
124
|
-
'kB',
|
|
125
|
-
'MB',
|
|
126
|
-
'GB',
|
|
127
|
-
'TB',
|
|
128
|
-
'PB',
|
|
129
|
-
'EB',
|
|
130
|
-
'ZB',
|
|
131
|
-
'YB',
|
|
132
|
-
];
|
|
133
|
-
|
|
134
|
-
const BIBYTE_UNITS = [
|
|
135
|
-
'B',
|
|
136
|
-
'KiB',
|
|
137
|
-
'MiB',
|
|
138
|
-
'GiB',
|
|
139
|
-
'TiB',
|
|
140
|
-
'PiB',
|
|
141
|
-
'EiB',
|
|
142
|
-
'ZiB',
|
|
143
|
-
'YiB',
|
|
144
|
-
];
|
|
145
|
-
|
|
146
|
-
const BIT_UNITS = [
|
|
147
|
-
'b',
|
|
148
|
-
'kbit',
|
|
149
|
-
'Mbit',
|
|
150
|
-
'Gbit',
|
|
151
|
-
'Tbit',
|
|
152
|
-
'Pbit',
|
|
153
|
-
'Ebit',
|
|
154
|
-
'Zbit',
|
|
155
|
-
'Ybit',
|
|
156
|
-
];
|
|
157
|
-
|
|
158
|
-
const BIBIT_UNITS = [
|
|
159
|
-
'b',
|
|
160
|
-
'kibit',
|
|
161
|
-
'Mibit',
|
|
162
|
-
'Gibit',
|
|
163
|
-
'Tibit',
|
|
164
|
-
'Pibit',
|
|
165
|
-
'Eibit',
|
|
166
|
-
'Zibit',
|
|
167
|
-
'Yibit',
|
|
168
|
-
];
|
|
169
|
-
|
|
170
|
-
/*
|
|
171
|
-
Formats the given number using `Number#toLocaleString`.
|
|
172
|
-
- If locale is a string, the value is expected to be a locale-key (for example: `de`).
|
|
173
|
-
- If locale is true, the system default locale is used for translation.
|
|
174
|
-
- If no value for locale is specified, the number is returned unmodified.
|
|
175
|
-
*/
|
|
176
|
-
const toLocaleString = (number, locale, options) => {
|
|
177
|
-
let result = number;
|
|
178
|
-
if (typeof locale === 'string' || Array.isArray(locale)) {
|
|
179
|
-
result = number.toLocaleString(locale, options);
|
|
180
|
-
} else if (locale === true || options !== undefined) {
|
|
181
|
-
result = number.toLocaleString(undefined, options);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return result;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const log10 = numberOrBigInt => {
|
|
188
|
-
if (typeof numberOrBigInt === 'number') {
|
|
189
|
-
return Math.log10(numberOrBigInt);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const string = numberOrBigInt.toString(10);
|
|
193
|
-
|
|
194
|
-
return string.length + Math.log10(`0.${string.slice(0, 15)}`);
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const log = numberOrBigInt => {
|
|
198
|
-
if (typeof numberOrBigInt === 'number') {
|
|
199
|
-
return Math.log(numberOrBigInt);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return log10(numberOrBigInt) * Math.log(10);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const divide = (numberOrBigInt, divisor) => {
|
|
206
|
-
if (typeof numberOrBigInt === 'number') {
|
|
207
|
-
return numberOrBigInt / divisor;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const integerPart = numberOrBigInt / BigInt(divisor);
|
|
211
|
-
const remainder = numberOrBigInt % BigInt(divisor);
|
|
212
|
-
return Number(integerPart) + (Number(remainder) / divisor);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const applyFixedWidth = (result, fixedWidth) => {
|
|
216
|
-
if (fixedWidth === undefined) {
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (typeof fixedWidth !== 'number' || !Number.isSafeInteger(fixedWidth) || fixedWidth < 0) {
|
|
221
|
-
throw new TypeError(`Expected fixedWidth to be a non-negative integer, got ${typeof fixedWidth}: ${fixedWidth}`);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (fixedWidth === 0) {
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return result.length < fixedWidth ? result.padStart(fixedWidth, ' ') : result;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const buildLocaleOptions = options => {
|
|
232
|
-
const {minimumFractionDigits, maximumFractionDigits} = options;
|
|
233
|
-
|
|
234
|
-
if (minimumFractionDigits === undefined && maximumFractionDigits === undefined) {
|
|
235
|
-
return undefined;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return {
|
|
239
|
-
...(minimumFractionDigits !== undefined && {minimumFractionDigits}),
|
|
240
|
-
...(maximumFractionDigits !== undefined && {maximumFractionDigits}),
|
|
241
|
-
roundingMode: 'trunc',
|
|
242
|
-
};
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
function prettyBytes(number, options) {
|
|
246
|
-
if (typeof number !== 'bigint' && !Number.isFinite(number)) {
|
|
247
|
-
throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
options = {
|
|
251
|
-
bits: false,
|
|
252
|
-
binary: false,
|
|
253
|
-
space: true,
|
|
254
|
-
nonBreakingSpace: false,
|
|
255
|
-
...options,
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
const UNITS = options.bits
|
|
259
|
-
? (options.binary ? BIBIT_UNITS : BIT_UNITS)
|
|
260
|
-
: (options.binary ? BIBYTE_UNITS : BYTE_UNITS);
|
|
261
|
-
|
|
262
|
-
const separator = options.space ? (options.nonBreakingSpace ? '\u00A0' : ' ') : '';
|
|
263
|
-
|
|
264
|
-
// Handle signed zero case
|
|
265
|
-
const isZero = typeof number === 'number' ? number === 0 : number === 0n;
|
|
266
|
-
if (options.signed && isZero) {
|
|
267
|
-
const result = ` 0${separator}${UNITS[0]}`;
|
|
268
|
-
return applyFixedWidth(result, options.fixedWidth);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const isNegative = number < 0;
|
|
272
|
-
const prefix = isNegative ? '-' : (options.signed ? '+' : '');
|
|
273
|
-
|
|
274
|
-
if (isNegative) {
|
|
275
|
-
number = -number;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const localeOptions = buildLocaleOptions(options);
|
|
279
|
-
let result;
|
|
280
|
-
|
|
281
|
-
if (number < 1) {
|
|
282
|
-
const numberString = toLocaleString(number, options.locale, localeOptions);
|
|
283
|
-
result = prefix + numberString + separator + UNITS[0];
|
|
284
|
-
} else {
|
|
285
|
-
const exponent = Math.min(Math.floor(options.binary ? log(number) / Math.log(1024) : log10(number) / 3), UNITS.length - 1);
|
|
286
|
-
number = divide(number, (options.binary ? 1024 : 1000) ** exponent);
|
|
287
|
-
|
|
288
|
-
if (!localeOptions) {
|
|
289
|
-
const minPrecision = Math.max(3, Math.floor(number).toString().length);
|
|
290
|
-
number = number.toPrecision(minPrecision);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const numberString = toLocaleString(Number(number), options.locale, localeOptions);
|
|
294
|
-
const unit = UNITS[exponent];
|
|
295
|
-
result = prefix + numberString + separator + unit;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return applyFixedWidth(result, options.fixedWidth);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
async function generateFSTree(dir, options = {}) {
|
|
302
|
-
if (isTest) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const files = await glob("**/*.*", { cwd: dir, ignore: ["*.map"] });
|
|
306
|
-
const items = [];
|
|
307
|
-
await runParallel(
|
|
308
|
-
new Set(files),
|
|
309
|
-
async (file) => {
|
|
310
|
-
const path = resolve(dir, file);
|
|
311
|
-
const src = await promises.readFile(path);
|
|
312
|
-
const size = src.byteLength;
|
|
313
|
-
const gzip = options.compressedSizes ? await gzipSize(src) : 0;
|
|
314
|
-
items.push({ file, path, size, gzip });
|
|
315
|
-
},
|
|
316
|
-
{ concurrency: 10 }
|
|
317
|
-
);
|
|
318
|
-
items.sort((a, b) => a.path.localeCompare(b.path));
|
|
319
|
-
let totalSize = 0;
|
|
320
|
-
let totalGzip = 0;
|
|
321
|
-
let totalNodeModulesSize = 0;
|
|
322
|
-
let totalNodeModulesGzip = 0;
|
|
323
|
-
let treeText = "";
|
|
324
|
-
for (const [index, item] of items.entries()) {
|
|
325
|
-
dirname(item.file);
|
|
326
|
-
const rpath = relative(process.cwd(), item.path);
|
|
327
|
-
const treeChar = index === items.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
328
|
-
const isNodeModules = item.file.includes("node_modules");
|
|
329
|
-
if (isNodeModules) {
|
|
330
|
-
totalNodeModulesSize += item.size;
|
|
331
|
-
totalNodeModulesGzip += item.gzip;
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
treeText += colors.gray(
|
|
335
|
-
` ${treeChar} ${rpath} (${prettyBytes(item.size)})`
|
|
336
|
-
);
|
|
337
|
-
if (options.compressedSizes) {
|
|
338
|
-
treeText += colors.gray(` (${prettyBytes(item.gzip)} gzip)`);
|
|
339
|
-
}
|
|
340
|
-
treeText += "\n";
|
|
341
|
-
totalSize += item.size;
|
|
342
|
-
totalGzip += item.gzip;
|
|
343
|
-
}
|
|
344
|
-
treeText += `${colors.cyan("\u03A3 Total size:")} ${prettyBytes(
|
|
345
|
-
totalSize + totalNodeModulesSize
|
|
346
|
-
)}`;
|
|
347
|
-
if (options.compressedSizes) {
|
|
348
|
-
treeText += ` (${prettyBytes(totalGzip + totalNodeModulesGzip)} gzip)`;
|
|
349
|
-
}
|
|
350
|
-
treeText += "\n";
|
|
351
|
-
return treeText;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
async function snapshot(nitro) {
|
|
355
|
-
if (nitro.options.bundledStorage.length === 0 || nitro.options.preset === "nitro-prerender") {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
const storageDir = resolve(nitro.options.buildDir, "snapshot");
|
|
359
|
-
nitro.options.serverAssets.push({
|
|
360
|
-
baseName: "nitro:bundled",
|
|
361
|
-
dir: storageDir
|
|
362
|
-
});
|
|
363
|
-
const data = await snapshotStorage(nitro);
|
|
364
|
-
await Promise.all(
|
|
365
|
-
Object.entries(data).map(async ([path, contents]) => {
|
|
366
|
-
if (typeof contents !== "string") {
|
|
367
|
-
contents = JSON.stringify(contents);
|
|
368
|
-
}
|
|
369
|
-
const fsPath = join(storageDir, path.replace(/:/g, "/"));
|
|
370
|
-
await mkdir(dirname(fsPath), { recursive: true });
|
|
371
|
-
await writeFile(fsPath, contents, "utf8");
|
|
372
|
-
})
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
export { generateFSTree as g, nitroServerName as n, raw as r, snapshot as s };
|