@nuxt/cli-nightly 3.29.4-20251021-192254-70dcc9b → 3.30.0-20251027-200530-97d8172

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.
@@ -1,5 +1,5 @@
1
1
  import "../logger-Dk0gkCkX.mjs";
2
- import { t as initialize } from "../dev-L7lhoThJ.mjs";
2
+ import { t as initialize } from "../dev-DsH3xiyp.mjs";
3
3
  import "../fs-ewAp6tjM.mjs";
4
4
  import "../kit-xFxVGu6d.mjs";
5
5
  import "../nuxt-Cc9ZTk7m.mjs";
@@ -1,5 +1,5 @@
1
1
  import "./logger-Dk0gkCkX.mjs";
2
- import { t as initialize } from "./dev-L7lhoThJ.mjs";
2
+ import { t as initialize } from "./dev-DsH3xiyp.mjs";
3
3
  import "./fs-ewAp6tjM.mjs";
4
4
  import "./kit-xFxVGu6d.mjs";
5
5
  import "./nuxt-Cc9ZTk7m.mjs";
@@ -1,6 +1,6 @@
1
1
  import { a as legacyRootDirArgs, i as extendsArgs, n as dotEnvArgs, o as logLevelArgs, r as envNameArgs, t as cwdArgs } from "./_shared-C3vB2YLc.mjs";
2
2
  import { t as logger } from "./logger-Dk0gkCkX.mjs";
3
- import { a as parseSocketURL, i as isSocketURL, n as resolveLoadingTemplate, r as renderError, t as initialize } from "./dev-L7lhoThJ.mjs";
3
+ import { a as parseSocketURL, i as isSocketURL, n as resolveLoadingTemplate, r as renderError, t as initialize } from "./dev-DsH3xiyp.mjs";
4
4
  import "./fs-ewAp6tjM.mjs";
5
5
  import { t as loadKit } from "./kit-xFxVGu6d.mjs";
6
6
  import "./nuxt-Cc9ZTk7m.mjs";
@@ -13,12 +13,12 @@ import { listen } from "listhen";
13
13
  import { request } from "node:http";
14
14
  import { isSocketSupported } from "get-port-please";
15
15
  import { resolve } from "pathe";
16
+ import { NodeRequest } from "srvx/node";
16
17
  import { fork } from "node:child_process";
17
18
  import { getArgs, parseArgs } from "listhen/cli";
18
19
  import { satisfies } from "semver";
19
20
  import { Readable } from "node:stream";
20
21
  import { pipeline } from "node:stream/promises";
21
- import { NodeRequest } from "srvx/node";
22
22
  import { Agent } from "undici";
23
23
  import { connect } from "node:net";
24
24
 
@@ -4,7 +4,7 @@ import { a as writeNuxtManifest, i as resolveNuxtManifest, n as loadNuxtManifest
4
4
  import process from "node:process";
5
5
  import { provider } from "std-env";
6
6
  import { pathToFileURL } from "node:url";
7
- import defu from "defu";
7
+ import defu, { defu as defu$1 } from "defu";
8
8
  import { listen } from "listhen";
9
9
  import { Server } from "node:http";
10
10
  import { cleanSocket, getSocketAddress } from "get-port-please";
@@ -12,10 +12,10 @@ import EventEmitter from "node:events";
12
12
  import { existsSync, statSync, watch } from "node:fs";
13
13
  import { mkdir } from "node:fs/promises";
14
14
  import { resolveModulePath } from "exsolve";
15
- import { toNodeListener } from "h3";
15
+ import { joinURL } from "ufo";
16
16
  import { resolve } from "pathe";
17
17
  import { debounce } from "perfect-debounce";
18
- import { joinURL } from "ufo";
18
+ import { toNodeHandler } from "srvx/node";
19
19
  import { Youch } from "youch";
20
20
 
21
21
  //#region ../nuxi/src/dev/socket.ts
@@ -68,6 +68,265 @@ async function createSocketListener(handler, proxyAddress) {
68
68
  };
69
69
  }
70
70
 
71
+ //#endregion
72
+ //#region ../../node_modules/.pnpm/h3@1.15.4/node_modules/h3/dist/index.mjs
73
+ function hasProp(obj, prop) {
74
+ try {
75
+ return prop in obj;
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
80
+ var H3Error = class extends Error {
81
+ static __h3_error__ = true;
82
+ statusCode = 500;
83
+ fatal = false;
84
+ unhandled = false;
85
+ statusMessage;
86
+ data;
87
+ cause;
88
+ constructor(message, opts = {}) {
89
+ super(message, opts);
90
+ if (opts.cause && !this.cause) this.cause = opts.cause;
91
+ }
92
+ toJSON() {
93
+ const obj = {
94
+ message: this.message,
95
+ statusCode: sanitizeStatusCode(this.statusCode, 500)
96
+ };
97
+ if (this.statusMessage) obj.statusMessage = sanitizeStatusMessage(this.statusMessage);
98
+ if (this.data !== void 0) obj.data = this.data;
99
+ return obj;
100
+ }
101
+ };
102
+ function createError(input) {
103
+ if (typeof input === "string") return new H3Error(input);
104
+ if (isError(input)) return input;
105
+ const err = new H3Error(input.message ?? input.statusMessage ?? "", { cause: input.cause || input });
106
+ if (hasProp(input, "stack")) try {
107
+ Object.defineProperty(err, "stack", { get() {
108
+ return input.stack;
109
+ } });
110
+ } catch {
111
+ try {
112
+ err.stack = input.stack;
113
+ } catch {}
114
+ }
115
+ if (input.data) err.data = input.data;
116
+ if (input.statusCode) err.statusCode = sanitizeStatusCode(input.statusCode, err.statusCode);
117
+ else if (input.status) err.statusCode = sanitizeStatusCode(input.status, err.statusCode);
118
+ if (input.statusMessage) err.statusMessage = input.statusMessage;
119
+ else if (input.statusText) err.statusMessage = input.statusText;
120
+ if (err.statusMessage) {
121
+ const originalMessage = err.statusMessage;
122
+ if (sanitizeStatusMessage(err.statusMessage) !== originalMessage) console.warn("[h3] Please prefer using `message` for longer error messages instead of `statusMessage`. In the future, `statusMessage` will be sanitized by default.");
123
+ }
124
+ if (input.fatal !== void 0) err.fatal = input.fatal;
125
+ if (input.unhandled !== void 0) err.unhandled = input.unhandled;
126
+ return err;
127
+ }
128
+ function sendError(event, error, debug) {
129
+ if (event.handled) return;
130
+ const h3Error = isError(error) ? error : createError(error);
131
+ const responseBody = {
132
+ statusCode: h3Error.statusCode,
133
+ statusMessage: h3Error.statusMessage,
134
+ stack: [],
135
+ data: h3Error.data
136
+ };
137
+ if (debug) responseBody.stack = (h3Error.stack || "").split("\n").map((l) => l.trim());
138
+ if (event.handled) return;
139
+ setResponseStatus(event, Number.parseInt(h3Error.statusCode), h3Error.statusMessage);
140
+ event.node.res.setHeader("content-type", MIMES.json);
141
+ event.node.res.end(JSON.stringify(responseBody, void 0, 2));
142
+ }
143
+ function isError(input) {
144
+ return input?.constructor?.__h3_error__ === true;
145
+ }
146
+ const RawBodySymbol = Symbol.for("h3RawBody");
147
+ const ParsedBodySymbol = Symbol.for("h3ParsedBody");
148
+ const MIMES = {
149
+ html: "text/html",
150
+ json: "application/json"
151
+ };
152
+ const DISALLOWED_STATUS_CHARS = /[^\u0009\u0020-\u007E]/g;
153
+ function sanitizeStatusMessage(statusMessage = "") {
154
+ return statusMessage.replace(DISALLOWED_STATUS_CHARS, "");
155
+ }
156
+ function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
157
+ if (!statusCode) return defaultStatusCode;
158
+ if (typeof statusCode === "string") statusCode = Number.parseInt(statusCode, 10);
159
+ if (statusCode < 100 || statusCode > 999) return defaultStatusCode;
160
+ return statusCode;
161
+ }
162
+ function splitCookiesString(cookiesString) {
163
+ if (Array.isArray(cookiesString)) return cookiesString.flatMap((c) => splitCookiesString(c));
164
+ if (typeof cookiesString !== "string") return [];
165
+ const cookiesStrings = [];
166
+ let pos = 0;
167
+ let start$1;
168
+ let ch;
169
+ let lastComma;
170
+ let nextStart;
171
+ let cookiesSeparatorFound;
172
+ const skipWhitespace = () => {
173
+ while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) pos += 1;
174
+ return pos < cookiesString.length;
175
+ };
176
+ const notSpecialChar = () => {
177
+ ch = cookiesString.charAt(pos);
178
+ return ch !== "=" && ch !== ";" && ch !== ",";
179
+ };
180
+ while (pos < cookiesString.length) {
181
+ start$1 = pos;
182
+ cookiesSeparatorFound = false;
183
+ while (skipWhitespace()) {
184
+ ch = cookiesString.charAt(pos);
185
+ if (ch === ",") {
186
+ lastComma = pos;
187
+ pos += 1;
188
+ skipWhitespace();
189
+ nextStart = pos;
190
+ while (pos < cookiesString.length && notSpecialChar()) pos += 1;
191
+ if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
192
+ cookiesSeparatorFound = true;
193
+ pos = nextStart;
194
+ cookiesStrings.push(cookiesString.slice(start$1, lastComma));
195
+ start$1 = pos;
196
+ } else pos = lastComma + 1;
197
+ } else pos += 1;
198
+ }
199
+ if (!cookiesSeparatorFound || pos >= cookiesString.length) cookiesStrings.push(cookiesString.slice(start$1));
200
+ }
201
+ return cookiesStrings;
202
+ }
203
+ function setResponseStatus(event, code, text) {
204
+ if (code) event.node.res.statusCode = sanitizeStatusCode(code, event.node.res.statusCode);
205
+ if (text) event.node.res.statusMessage = sanitizeStatusMessage(text);
206
+ }
207
+ function sendStream(event, stream) {
208
+ if (!stream || typeof stream !== "object") throw new Error("[h3] Invalid stream provided.");
209
+ event.node.res._data = stream;
210
+ if (!event.node.res.socket) {
211
+ event._handled = true;
212
+ return Promise.resolve();
213
+ }
214
+ if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") return stream.pipeTo(new WritableStream({ write(chunk) {
215
+ event.node.res.write(chunk);
216
+ } })).then(() => {
217
+ event.node.res.end();
218
+ });
219
+ if (hasProp(stream, "pipe") && typeof stream.pipe === "function") return new Promise((resolve$1, reject) => {
220
+ stream.pipe(event.node.res);
221
+ if (stream.on) {
222
+ stream.on("end", () => {
223
+ event.node.res.end();
224
+ resolve$1();
225
+ });
226
+ stream.on("error", (error) => {
227
+ reject(error);
228
+ });
229
+ }
230
+ event.node.res.on("close", () => {
231
+ if (stream.abort) stream.abort();
232
+ });
233
+ });
234
+ throw new Error("[h3] Invalid or incompatible stream provided.");
235
+ }
236
+ function sendWebResponse(event, response) {
237
+ for (const [key, value] of response.headers) if (key === "set-cookie") event.node.res.appendHeader(key, splitCookiesString(value));
238
+ else event.node.res.setHeader(key, value);
239
+ if (response.status) event.node.res.statusCode = sanitizeStatusCode(response.status, event.node.res.statusCode);
240
+ if (response.statusText) event.node.res.statusMessage = sanitizeStatusMessage(response.statusText);
241
+ if (response.redirected) event.node.res.setHeader("location", response.url);
242
+ if (!response.body) {
243
+ event.node.res.end();
244
+ return;
245
+ }
246
+ return sendStream(event, response.body);
247
+ }
248
+ const getSessionPromise = Symbol("getSession");
249
+ var H3Event = class {
250
+ "__is_event__" = true;
251
+ node;
252
+ web;
253
+ context = {};
254
+ _method;
255
+ _path;
256
+ _headers;
257
+ _requestBody;
258
+ _handled = false;
259
+ _onBeforeResponseCalled;
260
+ _onAfterResponseCalled;
261
+ constructor(req, res) {
262
+ this.node = {
263
+ req,
264
+ res
265
+ };
266
+ }
267
+ get method() {
268
+ if (!this._method) this._method = (this.node.req.method || "GET").toUpperCase();
269
+ return this._method;
270
+ }
271
+ get path() {
272
+ return this._path || this.node.req.url || "/";
273
+ }
274
+ get headers() {
275
+ if (!this._headers) this._headers = _normalizeNodeHeaders(this.node.req.headers);
276
+ return this._headers;
277
+ }
278
+ get handled() {
279
+ return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
280
+ }
281
+ respondWith(response) {
282
+ return Promise.resolve(response).then((_response) => sendWebResponse(this, _response));
283
+ }
284
+ toString() {
285
+ return `[${this.method}] ${this.path}`;
286
+ }
287
+ toJSON() {
288
+ return this.toString();
289
+ }
290
+ /** @deprecated Please use `event.node.req` instead. */
291
+ get req() {
292
+ return this.node.req;
293
+ }
294
+ /** @deprecated Please use `event.node.res` instead. */
295
+ get res() {
296
+ return this.node.res;
297
+ }
298
+ };
299
+ function createEvent(req, res) {
300
+ return new H3Event(req, res);
301
+ }
302
+ function _normalizeNodeHeaders(nodeHeaders) {
303
+ const headers = new Headers();
304
+ for (const [name, value] of Object.entries(nodeHeaders)) if (Array.isArray(value)) for (const item of value) headers.append(name, item);
305
+ else if (value) headers.set(name, value);
306
+ return headers;
307
+ }
308
+ const H3Headers = globalThis.Headers;
309
+ const H3Response = globalThis.Response;
310
+ function toNodeListener(app) {
311
+ const toNodeHandle = async function(req, res) {
312
+ const event = createEvent(req, res);
313
+ try {
314
+ await app.handler(event);
315
+ } catch (_error) {
316
+ const error = createError(_error);
317
+ if (!isError(_error)) error.unhandled = true;
318
+ setResponseStatus(event, error.statusCode, error.statusMessage);
319
+ if (app.options.onError) await app.options.onError(error, event);
320
+ if (event.handled) return;
321
+ if (error.unhandled || error.fatal) console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
322
+ if (app.options.onBeforeResponse && !event._onBeforeResponseCalled) await app.options.onBeforeResponse(event, { body: error });
323
+ await sendError(event, error, !!app.options.debug);
324
+ if (app.options.onAfterResponse && !event._onAfterResponseCalled) await app.options.onAfterResponse(event, { body: error });
325
+ }
326
+ };
327
+ return toNodeHandle;
328
+ }
329
+
71
330
  //#endregion
72
331
  //#region ../nuxi/src/dev/error.ts
73
332
  async function renderError(req, res, error) {
@@ -257,7 +516,8 @@ var NuxtDevServer = class extends EventEmitter {
257
516
  if (!this._fileChangeTracker.shouldEmitChange(resolve(distDir, file || ""))) return;
258
517
  this.loadDebounced(true, ".nuxt/dist directory has been removed");
259
518
  });
260
- this._handler = toNodeListener(this._currentNuxt.server.app);
519
+ if ("fetch" in this._currentNuxt.server) this._handler = toNodeHandler(this._currentNuxt.server.fetch);
520
+ else this._handler = toNodeListener(this._currentNuxt.server.app);
261
521
  this.emit("ready", "socketPath" in addr ? formatSocketURL(addr.socketPath, !!this.listener.https) : `http://127.0.0.1:${addr.port}`);
262
522
  }
263
523
  _watchConfig() {
@@ -25,7 +25,7 @@ var dev_child_default = defineCommand({
25
25
  async run(ctx) {
26
26
  if (!process.send && !isTest) console.warn("`nuxi _dev` is an internal command and should not be used directly. Please use `nuxi dev` instead.");
27
27
  const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
28
- const { initialize } = await import("./dev-CnQwDUaD.mjs");
28
+ const { initialize } = await import("./dev-Bv3ZMKhd.mjs");
29
29
  await initialize({
30
30
  cwd,
31
31
  args: ctx.args
package/dist/index.mjs CHANGED
@@ -11,19 +11,19 @@ import { fileURLToPath } from "node:url";
11
11
  const _rDefault = (r) => r.default || r;
12
12
  const commands = {
13
13
  add: () => import("./add-BGMHIn5L.mjs").then(_rDefault),
14
- analyze: () => import("./analyze-CUKAi_IN.mjs").then(_rDefault),
14
+ analyze: () => import("./analyze-BA0BTFOc.mjs").then(_rDefault),
15
15
  build: () => import("./build-BebJ09xA.mjs").then(_rDefault),
16
16
  cleanup: () => import("./cleanup-8GRakeLu.mjs").then(_rDefault),
17
- _dev: () => import("./dev-child-CSiX6Uyv.mjs").then(_rDefault),
18
- dev: () => import("./dev-BfX9NUUq.mjs").then(_rDefault),
17
+ _dev: () => import("./dev-child-CJxOnht6.mjs").then(_rDefault),
18
+ dev: () => import("./dev-DG7T8nNT.mjs").then(_rDefault),
19
19
  devtools: () => import("./devtools-BLGzUSNU.mjs").then(_rDefault),
20
20
  generate: () => import("./generate-B328yidV.mjs").then(_rDefault),
21
- info: () => import("./info-CrSXb5ro.mjs").then(_rDefault),
22
- init: () => import("./init-_n9DXzzY.mjs").then(_rDefault),
23
- module: () => import("./module-CqBrGD-s.mjs").then(_rDefault),
21
+ info: () => import("./info-VcLxzwux.mjs").then(_rDefault),
22
+ init: () => import("./init-CvLYtdn1.mjs").then(_rDefault),
23
+ module: () => import("./module-BUBa48Be.mjs").then(_rDefault),
24
24
  prepare: () => import("./prepare-B0KOhO-L.mjs").then(_rDefault),
25
- preview: () => import("./preview-C5fNqrC6.mjs").then(_rDefault),
26
- start: () => import("./preview-C5fNqrC6.mjs").then(_rDefault),
25
+ preview: () => import("./preview-BEqrL1ey.mjs").then(_rDefault),
26
+ start: () => import("./preview-BEqrL1ey.mjs").then(_rDefault),
27
27
  test: () => import("./test-CBt1emEB.mjs").then(_rDefault),
28
28
  typecheck: () => import("./typecheck-DCWe7Iej.mjs").then(_rDefault),
29
29
  upgrade: () => import("./upgrade-BMSFcUWJ.mjs").then(_rDefault)
@@ -63,7 +63,7 @@ async function checkEngines() {
63
63
  //#endregion
64
64
  //#region package.json
65
65
  var name = "@nuxt/cli-nightly";
66
- var version = "3.29.4-20251021-192254-70dcc9b";
66
+ var version = "3.30.0-20251027-200530-97d8172";
67
67
  var description = "Nuxt CLI";
68
68
 
69
69
  //#endregion
@@ -13,7 +13,7 @@ import { detectPackageManager } from "nypm";
13
13
  import { readPackageJSON } from "pkg-types";
14
14
 
15
15
  //#region ../nuxi/package.json
16
- var version = "3.29.4-20251021-192246-70dcc9b";
16
+ var version = "3.30.0-20251027-200522-97d8172";
17
17
 
18
18
  //#endregion
19
19
  //#region ../nuxi/src/commands/info.ts
@@ -2,7 +2,7 @@ import { o as logLevelArgs, t as cwdArgs } from "./_shared-C3vB2YLc.mjs";
2
2
  import { t as logger } from "./logger-Dk0gkCkX.mjs";
3
3
  import "./fs-ewAp6tjM.mjs";
4
4
  import "./kit-xFxVGu6d.mjs";
5
- import { n as runCommand$1, t as add_default } from "./add-CRBwIlDF.mjs";
5
+ import { n as runCommand$1, t as add_default } from "./add-CHYEpn7Y.mjs";
6
6
  import "./versions-CSy_3o_-.mjs";
7
7
  import "./prepare-xI978yFg.mjs";
8
8
  import "./_utils-DTrPahho.mjs";
@@ -8,7 +8,7 @@ var module_default = defineCommand({
8
8
  },
9
9
  args: {},
10
10
  subCommands: {
11
- add: () => import("./add-hFFIzkcy.mjs").then((r) => r.default || r),
11
+ add: () => import("./add-qJhPcmZB.mjs").then((r) => r.default || r),
12
12
  search: () => import("./search-DCyXfxzn.mjs").then((r) => r.default || r)
13
13
  }
14
14
  });
@@ -7,7 +7,6 @@ import { defineCommand } from "citty";
7
7
  import { existsSync, promises } from "node:fs";
8
8
  import { resolve as resolve$1 } from "pathe";
9
9
  import { box, colors } from "consola/utils";
10
- import { getArgs } from "listhen/cli";
11
10
  import { x } from "tinyexec";
12
11
  import { setupDotenv } from "c12";
13
12
 
@@ -24,7 +23,8 @@ const command = defineCommand({
24
23
  ...extendsArgs,
25
24
  ...legacyRootDirArgs,
26
25
  port: {
27
- ...getArgs().port,
26
+ type: "string",
27
+ description: "Port to listen on",
28
28
  alias: ["p"]
29
29
  },
30
30
  ...dotEnvArgs
@@ -82,7 +82,7 @@ const command = defineCommand({
82
82
  fileName: envFileName
83
83
  });
84
84
  } else if (ctx.args.dotenv) logger.error(`Cannot find \`${envFileName}\`.`);
85
- const { port } = _resolveListenOptions(ctx.args);
85
+ const port = ctx.args.port ?? process.env.NUXT_PORT ?? process.env.NITRO_PORT ?? process.env.PORT;
86
86
  logger.info(`Starting preview command: \`${nitroJSON.commands.preview}\``);
87
87
  const [command$1, ...commandArgs] = nitroJSON.commands.preview.split(" ");
88
88
  logger.log("");
@@ -101,9 +101,6 @@ const command = defineCommand({
101
101
  }
102
102
  });
103
103
  var preview_default = command;
104
- function _resolveListenOptions(args) {
105
- return { port: args.port ?? process.env.NUXT_PORT ?? process.env.NITRO_PORT ?? process.env.PORT };
106
- }
107
104
 
108
105
  //#endregion
109
106
  export { preview_default as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxt/cli-nightly",
3
3
  "type": "module",
4
- "version": "3.29.4-20251021-192254-70dcc9b",
4
+ "version": "3.30.0-20251027-200530-97d8172",
5
5
  "description": "Nuxt CLI",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -43,7 +43,6 @@
43
43
  "fuse.js": "^7.1.0",
44
44
  "get-port-please": "^3.2.0",
45
45
  "giget": "^2.0.0",
46
- "h3": "^1.15.4",
47
46
  "jiti": "^2.6.1",
48
47
  "listhen": "^1.9.0",
49
48
  "nypm": "^0.6.2",
@@ -65,6 +64,10 @@
65
64
  "@nuxt/kit": "^4.1.3",
66
65
  "@nuxt/schema": "^4.1.3",
67
66
  "@types/node": "^22.18.12",
67
+ "h3": "^1.15.4",
68
+ "h3-next": "npm:h3@^2.0.1-rc.4",
69
+ "nitro": "^3.0.1-alpha.0",
70
+ "nitropack": "^2.12.7",
68
71
  "rollup": "^4.52.5",
69
72
  "rollup-plugin-visualizer": "^6.0.5",
70
73
  "tsdown": "^0.15.9",
@@ -1,115 +0,0 @@
1
- import { a as legacyRootDirArgs, i as extendsArgs, n as dotEnvArgs, o as logLevelArgs, t as cwdArgs } from "./_shared-C3vB2YLc.mjs";
2
- import { t as logger } from "./logger-Dk0gkCkX.mjs";
3
- import { n as clearDir } from "./fs-ewAp6tjM.mjs";
4
- import { t as loadKit } from "./kit-xFxVGu6d.mjs";
5
- import { t as overrideEnv } from "./env-Dz4K_NkM.mjs";
6
- import process from "node:process";
7
- import { defineCommand } from "citty";
8
- import { defu as defu$1 } from "defu";
9
- import { listen } from "listhen";
10
- import { promises } from "node:fs";
11
- import { createApp, eventHandler, lazyEventHandler, toNodeListener } from "h3";
12
- import { join, resolve } from "pathe";
13
-
14
- //#region ../nuxi/src/commands/analyze.ts
15
- var analyze_default = defineCommand({
16
- meta: {
17
- name: "analyze",
18
- description: "Build nuxt and analyze production bundle (experimental)"
19
- },
20
- args: {
21
- ...cwdArgs,
22
- ...logLevelArgs,
23
- ...legacyRootDirArgs,
24
- ...dotEnvArgs,
25
- ...extendsArgs,
26
- name: {
27
- type: "string",
28
- description: "Name of the analysis",
29
- default: "default",
30
- valueHint: "name"
31
- },
32
- serve: {
33
- type: "boolean",
34
- description: "Serve the analysis results",
35
- negativeDescription: "Skip serving the analysis results",
36
- default: true
37
- }
38
- },
39
- async run(ctx) {
40
- overrideEnv("production");
41
- const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
42
- const name = ctx.args.name || "default";
43
- const slug = name.trim().replace(/[^\w-]/g, "_");
44
- const startTime = Date.now();
45
- const { loadNuxt, buildNuxt } = await loadKit(cwd);
46
- const nuxt = await loadNuxt({
47
- cwd,
48
- dotenv: {
49
- cwd,
50
- fileName: ctx.args.dotenv
51
- },
52
- overrides: defu$1(ctx.data?.overrides, {
53
- ...ctx.args.extends && { extends: ctx.args.extends },
54
- build: { analyze: { enabled: true } },
55
- vite: { build: { rollupOptions: { output: {
56
- chunkFileNames: "_nuxt/[name].js",
57
- entryFileNames: "_nuxt/[name].js"
58
- } } } },
59
- logLevel: ctx.args.logLevel
60
- })
61
- });
62
- const analyzeDir = nuxt.options.analyzeDir;
63
- const buildDir = nuxt.options.buildDir;
64
- const outDir = nuxt.options.nitro.output?.dir || join(nuxt.options.rootDir, ".output");
65
- nuxt.options.build.analyze = defu$1(nuxt.options.build.analyze, { filename: join(analyzeDir, "client.html") });
66
- await clearDir(analyzeDir);
67
- await buildNuxt(nuxt);
68
- const meta = {
69
- name,
70
- slug,
71
- startTime,
72
- endTime: Date.now(),
73
- analyzeDir,
74
- buildDir,
75
- outDir
76
- };
77
- await nuxt.callHook("build:analyze:done", meta);
78
- await promises.writeFile(join(analyzeDir, "meta.json"), JSON.stringify(meta, null, 2), "utf-8");
79
- logger.info(`Analyze results are available at: \`${analyzeDir}\``);
80
- logger.warn("Do not deploy analyze results! Use `nuxi build` before deploying.");
81
- if (ctx.args.serve !== false && !process.env.CI) {
82
- const app = createApp();
83
- const serveFile = (filePath) => lazyEventHandler(async () => {
84
- const contents = await promises.readFile(filePath, "utf-8");
85
- return eventHandler((event) => {
86
- event.node.res.end(contents);
87
- });
88
- });
89
- logger.info("Starting stats server...");
90
- app.use("/client", serveFile(join(analyzeDir, "client.html")));
91
- app.use("/nitro", serveFile(join(analyzeDir, "nitro.html")));
92
- app.use(eventHandler(() => `<!DOCTYPE html>
93
- <html lang="en">
94
- <head>
95
- <meta charset="utf-8">
96
- <title>Nuxt Bundle Stats (experimental)</title>
97
- </head>
98
- <h1>Nuxt Bundle Stats (experimental)</h1>
99
- <ul>
100
- <li>
101
- <a href="/nitro">Nitro server bundle stats</a>
102
- </li>
103
- <li>
104
- <a href="/client">Client bundle stats</a>
105
- </li>
106
- </ul>
107
- </html>
108
- `));
109
- await listen(toNodeListener(app));
110
- }
111
- }
112
- });
113
-
114
- //#endregion
115
- export { analyze_default as default };