@nuxt/vite-builder-nightly 4.6.0-29843345.e2eb0b5e → 4.6.0-29843569.8cf90bcd

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 (2) hide show
  1. package/dist/index.mjs +66 -11
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -24,6 +24,7 @@ import { randomUUID } from "node:crypto";
24
24
  import { win32 } from "node:path";
25
25
  import { ViteNodeServer } from "vite-node/server";
26
26
  import { normalizeViteManifest, precomputeDependencies } from "vue-bundle-renderer";
27
+ import { tracingChannel } from "node:diagnostics_channel";
27
28
  import { colorize, stripAnsi } from "consola/utils";
28
29
  import { hasTTY, isCI } from "std-env";
29
30
  import { link } from "clickable-path";
@@ -301,6 +302,24 @@ function collectDevCss(nuxt, moduleGraph) {
301
302
  return [...urls];
302
303
  }
303
304
  //#endregion
305
+ //#region src/utils/tracing.ts
306
+ const channels = {};
307
+ function isBundlerTracingEnabled(nuxt) {
308
+ const options = nuxt.options.tracingChannel;
309
+ return !!(options && typeof options === "object" && options.nuxt);
310
+ }
311
+ /**
312
+ * Publishes `nuxt.bundler.module` (`{ url, environment }`) and `nuxt.bundler.plugin`
313
+ * (`{ plugin, hook, id?, environment? }`) spans.
314
+ *
315
+ * @experimental Channel names and payload shapes may change.
316
+ */
317
+ function traceAsync(name, context, fn) {
318
+ const channel = channels[name] ??= tracingChannel(name);
319
+ if (channel.hasSubscribers === false) return fn();
320
+ return channel.tracePromise(() => Promise.resolve(fn()), context);
321
+ }
322
+ //#endregion
304
323
  //#region src/plugins/vite-node.ts
305
324
  /**
306
325
  * Serialise a Vite transform failure for transport over the vite-node socket, keeping the
@@ -590,7 +609,12 @@ function createViteNodeSocketServer(nuxt, ssrServer, clientServer, invalidates,
590
609
  status: 400,
591
610
  message: "Invalid moduleId"
592
611
  };
593
- const response = await (nuxt.options.experimental.viteEnvironmentApi ? ssrServer.environments.ssr : getNode(ssrServer)).fetchModule(request.payload.moduleId).catch(async (err) => {
612
+ const moduleId = request.payload.moduleId;
613
+ const fetchModule = nuxt.options.experimental.viteEnvironmentApi ? () => ssrServer.environments.ssr.fetchModule(moduleId) : isBundlerTracingEnabled(nuxt) ? () => traceAsync("nuxt.bundler.module", {
614
+ url: moduleId,
615
+ environment: "ssr"
616
+ }, () => getNode(ssrServer).fetchModule(moduleId)) : () => getNode(ssrServer).fetchModule(moduleId);
617
+ const response = await Promise.resolve(fetchModule()).catch(async (err) => {
594
618
  const file = ssrServer.environments.ssr.moduleGraph.getModuleById(request.payload.moduleId)?.file ?? void 0;
595
619
  const errorData = serializeViteNodeError(err, request.payload.moduleId, file);
596
620
  if (!errorData.frame && err.code === "PARSE_ERROR") try {
@@ -3213,37 +3237,68 @@ const HOOKS_TO_TRACK = [
3213
3237
  "load"
3214
3238
  ];
3215
3239
  function PerfPlugin(nuxt) {
3240
+ const tracing = isBundlerTracingEnabled(nuxt);
3241
+ const wrapped = /* @__PURE__ */ new WeakSet();
3242
+ const wrapPlugins = (plugins) => {
3243
+ for (const plugin of plugins) {
3244
+ if (plugin.name === "nuxt:perf" || wrapped.has(plugin)) continue;
3245
+ wrapped.add(plugin);
3246
+ for (const hookName of HOOKS_TO_TRACK) wrapPluginHook(plugin, plugin.name, hookName, nuxt, tracing);
3247
+ }
3248
+ };
3216
3249
  return {
3217
3250
  name: "nuxt:perf",
3218
3251
  enforce: "pre",
3219
- apply: () => !!nuxt?._perf,
3252
+ apply: () => !!nuxt?._perf || tracing,
3220
3253
  configResolved(config) {
3221
- for (const plugin of config.plugins) {
3222
- if (plugin.name === "nuxt:perf") continue;
3223
- const pluginName = plugin.name;
3224
- for (const hookName of HOOKS_TO_TRACK) wrapPluginHook(plugin, pluginName, hookName, nuxt);
3254
+ wrapPlugins(config.plugins);
3255
+ },
3256
+ configureServer(server) {
3257
+ for (const name in server.environments) {
3258
+ const environment = server.environments[name];
3259
+ wrapPlugins(environment.plugins);
3260
+ if (tracing && name !== "client") traceFetchModule(environment);
3225
3261
  }
3262
+ },
3263
+ buildStart() {
3264
+ wrapPlugins(this.environment.plugins);
3226
3265
  }
3227
3266
  };
3228
3267
  }
3229
- function wrapPluginHook(plugin, pluginName, hookName, nuxt) {
3268
+ function traceFetchModule(environment) {
3269
+ const fetchModule = environment.fetchModule;
3270
+ environment.fetchModule = function(id, ...rest) {
3271
+ return traceAsync("nuxt.bundler.module", {
3272
+ url: id,
3273
+ environment: environment.name
3274
+ }, () => fetchModule.call(this, id, ...rest));
3275
+ };
3276
+ }
3277
+ function wrapPluginHook(plugin, pluginName, hookName, nuxt, tracing) {
3230
3278
  const original = plugin[hookName];
3231
3279
  if (!original) return;
3232
3280
  if (typeof original === "function") plugin[hookName] = function(...args) {
3233
- return timedCall(original, this, args, pluginName, hookName, nuxt);
3281
+ return timedCall(original, this, args, pluginName, hookName, nuxt, tracing);
3234
3282
  };
3235
3283
  else if (typeof original === "object" && "handler" in original) {
3236
3284
  const originalHandler = original.handler;
3237
3285
  original.handler = function(...args) {
3238
- return timedCall(originalHandler, this, args, pluginName, hookName, nuxt);
3286
+ return timedCall(originalHandler, this, args, pluginName, hookName, nuxt, tracing);
3239
3287
  };
3240
3288
  }
3241
3289
  }
3242
- function timedCall(fn, ctx, args, pluginName, hookName, nuxt) {
3290
+ function timedCall(fn, ctx, args, pluginName, hookName, nuxt, tracing) {
3291
+ const call = tracing ? () => traceAsync("nuxt.bundler.plugin", {
3292
+ plugin: pluginName,
3293
+ hook: hookName,
3294
+ id: hookName === "transform" ? args[1] : args[0],
3295
+ environment: ctx?.environment?.name
3296
+ }, () => fn.apply(ctx, args)) : () => fn.apply(ctx, args);
3297
+ if (!nuxt._perf) return call();
3243
3298
  const start = performance.now();
3244
3299
  const record = () => nuxt._perf?.recordBundlerPluginHook(pluginName, hookName, performance.now() - start, start);
3245
3300
  try {
3246
- const result = fn.apply(ctx, args);
3301
+ const result = call();
3247
3302
  if (result && typeof result === "object" && "then" in result) return result.finally(record);
3248
3303
  record();
3249
3304
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/vite-builder-nightly",
3
- "version": "4.6.0-29843345.e2eb0b5e",
3
+ "version": "4.6.0-29843569.8cf90bcd",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -25,7 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@nuxt/kit": "npm:@nuxt/kit-nightly@4.6.0-29843345.e2eb0b5e",
28
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.6.0-29843569.8cf90bcd",
29
29
  "@vitejs/plugin-vue": "^6.0.9",
30
30
  "@vitejs/plugin-vue-jsx": "^5.1.6",
31
31
  "autoprefixer": "^10.6.1",
@@ -40,7 +40,7 @@
40
40
  "js-tokens": "^10.0.0",
41
41
  "knitwork": "^1.3.0",
42
42
  "mocked-exports": "^0.1.1",
43
- "my-bad": "^0.2.7",
43
+ "my-bad": "^0.2.9",
44
44
  "pathe": "^2.0.3",
45
45
  "pkg-types": "^2.3.3",
46
46
  "postcss": "^8.5.28",
@@ -57,12 +57,12 @@
57
57
  "devDependencies": {
58
58
  "@babel/plugin-proposal-decorators": "8.0.2",
59
59
  "@babel/plugin-syntax-jsx": "8.0.1",
60
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.6.0-29843345.e2eb0b5e",
60
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.6.0-29843569.8cf90bcd",
61
61
  "h3": "1.15.11",
62
62
  "h3-next": "npm:h3@2.0.1-rc.26",
63
63
  "nitropack": "2.13.4",
64
64
  "rolldown": "~1.2.11",
65
- "rollup": "4.63.4",
65
+ "rollup": "4.63.5",
66
66
  "rollup-plugin-visualizer": "7.1.1",
67
67
  "tsdown": "0.23.0",
68
68
  "vue": "^3.5.43"
@@ -70,7 +70,7 @@
70
70
  "peerDependencies": {
71
71
  "@babel/plugin-proposal-decorators": "^7.25.0 || ^8.0.0",
72
72
  "@babel/plugin-syntax-jsx": "^7.25.0 || ^8.0.0",
73
- "nuxt": "npm:nuxt-nightly@4.6.0-29843345.e2eb0b5e",
73
+ "nuxt": "npm:nuxt-nightly@4.6.0-29843569.8cf90bcd",
74
74
  "rolldown": "^1.0.0",
75
75
  "rollup-plugin-visualizer": "^6.0.0 || ^7.0.1",
76
76
  "vue": "^3.3.4"