@nuxt/nitro-server-nightly 4.4.0-29551604.0a8a57da → 4.4.0-29552640.096fa1dc

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 +95 -20
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { performance } from "node:perf_hooks";
1
2
  import { fileURLToPath, pathToFileURL } from "node:url";
2
3
  import { existsSync, promises, readFileSync } from "node:fs";
3
4
  import { cpus } from "node:os";
@@ -21,7 +22,7 @@ import { ImpoundPlugin } from "impound";
21
22
  import { resolveModulePath } from "exsolve";
22
23
  import { runtimeDependencies } from "nitropack/runtime/meta";
23
24
  //#region package.json
24
- var version = "4.4.0-29551604.0a8a57da";
25
+ var version = "4.4.0-29552640.096fa1dc";
25
26
  //#endregion
26
27
  //#region src/utils.ts
27
28
  function toArray(value) {
@@ -40,20 +41,53 @@ const template = () => {
40
41
  function createImportProtectionPatterns(nuxt, options) {
41
42
  const patterns = [];
42
43
  const context = contextFlags[options.context];
43
- patterns.push([/^(nuxt|nuxt3|nuxt-nightly)$/, `\`nuxt\`, or \`nuxt-nightly\` cannot be imported directly in ${context}.` + (options.context === "nuxt-app" ? " Instead, import runtime Nuxt composables from `#app` or `#imports`." : "")]);
44
- patterns.push([/^((~|~~|@|@@)?\/)?nuxt\.config(\.|$)/, "Importing directly from a `nuxt.config` file is not allowed. Instead, use runtime config or a module."]);
44
+ patterns.push([
45
+ /^(nuxt|nuxt3|nuxt-nightly)$/,
46
+ `\`nuxt\` or \`nuxt-nightly\` cannot be imported directly in ${context}.`,
47
+ options.context === "nuxt-app" ? ["Import runtime Nuxt composables from `#app` or `#imports` instead."] : ["Use `#app` or `#imports` for runtime composables in your Vue app code."]
48
+ ]);
49
+ patterns.push([
50
+ /^((~|~~|@|@@)?\/)?nuxt\.config(\.|$)/,
51
+ "Importing directly from a `nuxt.config` file is not allowed.",
52
+ [
53
+ "Use `useRuntimeConfig()` to access runtime config in your app.",
54
+ "Use `useAppConfig()` to access config that doesn't need to be changed at runtime.",
55
+ "Use a Nuxt module to access build-time configuration."
56
+ ]
57
+ ]);
45
58
  patterns.push([/(^|node_modules\/)@vue\/composition-api/]);
46
- for (const mod of nuxt.options._installedModules) if (mod.entryPath) patterns.push([new RegExp(`^${escapeRE(mod.entryPath)}$`), "Importing directly from module entry-points is not allowed."]);
59
+ for (const mod of nuxt.options._installedModules) if (mod.entryPath) patterns.push([
60
+ new RegExp(`^${escapeRE(mod.entryPath)}$`),
61
+ "Importing directly from module entry-points is not allowed.",
62
+ ["Import from the module's runtime directory instead (e.g. `my-module/runtime/...`)."]
63
+ ]);
47
64
  for (const i of [
48
65
  /(^|node_modules\/)@nuxt\/(cli|kit|test-utils)/,
49
66
  /(^|node_modules\/)nuxi/,
50
67
  /(^|node_modules\/)nitro(?:pack)?(?:-nightly)?(?:$|\/)(?!(?:dist\/)?(?:node_modules|presets|runtime|types))/,
51
68
  /(^|node_modules\/)nuxt\/(config|kit|schema)/
52
- ]) patterns.push([i, `This module cannot be imported in ${context}.`]);
53
- if (options.context === "nitro-app" || options.context === "shared") for (const i of ["#app", /^#build(\/|$)/]) patterns.push([i, `Vue app aliases are not allowed in ${context}.`]);
69
+ ]) patterns.push([
70
+ i,
71
+ `This module cannot be imported in ${context}.`,
72
+ ["These are build-time only packages and cannot be used at runtime."]
73
+ ]);
74
+ if (options.context === "nitro-app" || options.context === "shared") for (const i of ["#app", /^#build(\/|$)/]) patterns.push([
75
+ i,
76
+ `Vue app aliases are not allowed in ${context}.`,
77
+ ["Move this code to your Vue app directory or use a shared utility."]
78
+ ]);
54
79
  if (options.context === "nuxt-app" || options.context === "shared") {
55
- patterns.push([new RegExp(escapeRE(relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, nuxt.options.serverDir || "server"))) + "\\/(api|routes|middleware|plugins)\\/"), `Importing from server is not allowed in ${context}.`]);
56
- patterns.push([/^#server(\/|$)/, `Server aliases are not allowed in ${context}.`]);
80
+ const serverRelative = escapeRE(relative(nuxt.options.rootDir, resolve(nuxt.options.srcDir, nuxt.options.serverDir || "server")));
81
+ patterns.push([
82
+ new RegExp("^" + serverRelative + "\\/(api|routes|middleware|plugins)\\/"),
83
+ `Importing from server is not allowed in ${context}.`,
84
+ ["Use `$fetch()` or `useFetch()` to fetch data from server routes.", "Move shared logic to the `shared/` directory."]
85
+ ]);
86
+ patterns.push([
87
+ /^#server(\/|$)/,
88
+ `Server aliases are not allowed in ${context}.`,
89
+ ["Use `$fetch()` or `useFetch()` to call server endpoints.", "Move shared logic to the `shared/` directory."]
90
+ ]);
57
91
  }
58
92
  return patterns;
59
93
  }
@@ -585,10 +619,12 @@ async function bundle(nuxt) {
585
619
  ];
586
620
  nitroConfig.rollupConfig.plugins.push(ImpoundPlugin.rollup({
587
621
  cwd: nuxt.options.rootDir,
622
+ trace: true,
588
623
  include: sharedPatterns,
589
624
  patterns: createImportProtectionPatterns(nuxt, { context: "shared" })
590
625
  }), ImpoundPlugin.rollup({
591
626
  cwd: nuxt.options.rootDir,
627
+ trace: true,
592
628
  patterns: createImportProtectionPatterns(nuxt, { context: "nitro-app" }),
593
629
  exclude: [/node_modules[\\/]nitro(?:pack)?(?:-nightly)?[\\/]|(packages|@nuxt)[\\/]nitro-server(?:-nightly)?[\\/](src|dist)[\\/]runtime[\\/]/, ...sharedPatterns]
594
630
  }));
@@ -639,10 +675,12 @@ async function bundle(nuxt) {
639
675
  tsConfig.compilerOptions.paths[alias] = [absolutePath];
640
676
  if (isDirectory) tsConfig.compilerOptions.paths[`${alias}/*`] = [`${absolutePath}/*`];
641
677
  }
678
+ nuxt._perf?.startPhase("nitro:createNitro");
642
679
  const nitro = await createNitro(nitroConfig, {
643
680
  compatibilityDate: nuxt.options.compatibilityDate,
644
681
  dotenv: nuxt.options._loadOptions?.dotenv
645
682
  });
683
+ nuxt._perf?.endPhase("nitro:createNitro");
646
684
  if (nuxt.options.experimental.serverAppConfig === false && nitro.options.imports) {
647
685
  nitro.options.imports.presets ||= [];
648
686
  nitro.options.imports.presets = nitro.options.imports.presets.map((preset) => typeof preset === "string" || !("imports" in preset) ? preset : {
@@ -667,6 +705,34 @@ async function bundle(nuxt) {
667
705
  } });
668
706
  nuxt._nitro = nitro;
669
707
  await nuxt.callHook("nitro:init", nitro);
708
+ if (nuxt._perf) nitro.hooks.hook("rollup:before", (_nitro, rollupConfig) => {
709
+ const plugins = rollupConfig.plugins || [];
710
+ for (const plugin of plugins) {
711
+ if (!plugin || !plugin.name) continue;
712
+ const pluginName = `nitro:${plugin.name}`;
713
+ for (const hookName of [
714
+ "transform",
715
+ "resolveId",
716
+ "load"
717
+ ]) {
718
+ const original = plugin[hookName];
719
+ if (typeof original !== "function") continue;
720
+ plugin[hookName] = function(...args) {
721
+ const start = performance.now();
722
+ const record = () => nuxt._perf?.recordBundlerPluginHook(pluginName, hookName, performance.now() - start, start);
723
+ try {
724
+ const result = original.apply(this, args);
725
+ if (result && typeof result === "object" && "then" in result) return result.finally(record);
726
+ record();
727
+ return result;
728
+ } catch (err) {
729
+ record();
730
+ throw err;
731
+ }
732
+ };
733
+ }
734
+ }
735
+ });
670
736
  nuxt["~runtimeDependencies"] ||= [];
671
737
  nuxt["~runtimeDependencies"].push(...runtimeDependencies, "unhead", "@unhead/vue", "@nuxt/devalue", "unstorage", ...nitro.options.inlineDynamicImports ? ["vue", "@vue/server-renderer"] : []);
672
738
  addVitePlugin({
@@ -778,16 +844,7 @@ async function bundle(nuxt) {
778
844
  if (!existsSync(distDir)) await promises.symlink(nitro.options.output.publicDir, distDir, "junction").catch(() => {});
779
845
  }
780
846
  }
781
- nuxt.hook("build:done", async () => {
782
- await nuxt.callHook("nitro:build:before", nitro);
783
- await prepare(nitro);
784
- if (nuxt.options.dev) return build(nitro);
785
- await prerender(nitro);
786
- logger.restoreAll();
787
- await build(nitro);
788
- logger.wrapAll();
789
- await symlinkDist();
790
- });
847
+ let waitUntilCompile;
791
848
  if (nuxt.options.dev) {
792
849
  for (const builder of ["webpack", "rspack"]) {
793
850
  nuxt.hook(`${builder}:compile`, ({ name, compiler }) => {
@@ -813,9 +870,27 @@ async function bundle(nuxt) {
813
870
  }));
814
871
  });
815
872
  nuxt.server = createDevServer(nitro);
816
- const waitUntilCompile = new Promise((resolve) => nitro.hooks.hook("compiled", () => resolve()));
817
- nuxt.hook("build:done", () => waitUntilCompile);
873
+ waitUntilCompile = new Promise((resolve) => nitro.hooks.hook("compiled", () => resolve()));
818
874
  }
875
+ nuxt.hook("build:done", async () => {
876
+ nuxt._perf?.startPhase("nitro:build");
877
+ try {
878
+ await nuxt.callHook("nitro:build:before", nitro);
879
+ await prepare(nitro);
880
+ if (nuxt.options.dev) {
881
+ await build(nitro);
882
+ await waitUntilCompile;
883
+ return;
884
+ }
885
+ await prerender(nitro);
886
+ logger.restoreAll();
887
+ await build(nitro);
888
+ logger.wrapAll();
889
+ await symlinkDist();
890
+ } finally {
891
+ nuxt._perf?.endPhase("nitro:build");
892
+ }
893
+ });
819
894
  }
820
895
  const RELATIVE_RE = /^([^.])/;
821
896
  function relativeWithDot(from, to) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/nitro-server-nightly",
3
- "version": "4.4.0-29551604.0a8a57da",
3
+ "version": "4.4.0-29552640.096fa1dc",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@babel/plugin-syntax-typescript": "^7.28.6",
30
30
  "@nuxt/devalue": "^2.0.2",
31
- "@nuxt/kit": "npm:@nuxt/kit-nightly@4.4.0-29551604.0a8a57da",
31
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.4.0-29552640.096fa1dc",
32
32
  "@unhead/vue": "^2.1.10",
33
33
  "@vue/shared": "^3.5.29",
34
34
  "consola": "^3.4.2",
@@ -39,7 +39,7 @@
39
39
  "escape-string-regexp": "^5.0.0",
40
40
  "exsolve": "^1.0.8",
41
41
  "h3": "^1.15.5",
42
- "impound": "^1.0.0",
42
+ "impound": "^1.1.5",
43
43
  "klona": "^2.0.6",
44
44
  "mocked-exports": "^0.1.1",
45
45
  "nitropack": "^2.13.1",
@@ -59,7 +59,7 @@
59
59
  "peerDependencies": {
60
60
  "@babel/plugin-proposal-decorators": "^7.25.0",
61
61
  "@rollup/plugin-babel": "^6.0.0 || ^7.0.0",
62
- "nuxt": "npm:nuxt-nightly@4.4.0-29551604.0a8a57da"
62
+ "nuxt": "npm:nuxt-nightly@4.4.0-29552640.096fa1dc"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "@babel/plugin-proposal-decorators": {
@@ -71,9 +71,9 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@babel/plugin-proposal-decorators": "7.29.0",
74
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.4.0-29551604.0a8a57da",
74
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.4.0-29552640.096fa1dc",
75
75
  "@rollup/plugin-babel": "7.0.0",
76
- "nuxt": "npm:nuxt-nightly@4.4.0-29551604.0a8a57da",
76
+ "nuxt": "npm:nuxt-nightly@4.4.0-29552640.096fa1dc",
77
77
  "obuild": "0.4.31",
78
78
  "vitest": "4.0.18"
79
79
  },