@nuxt/kit 3.0.0-rc.4 → 3.0.0-rc.5

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Nuxt, ModuleContainer, ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, NuxtOptions, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtHooks, NuxtPlugin, NuxtPluginTemplate, NuxtTemplate } from '@nuxt/schema';
1
+ import { Nuxt, ModuleContainer, ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, NuxtOptions, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtTemplate, NuxtHooks, NuxtPlugin, NuxtPluginTemplate } from '@nuxt/schema';
2
2
  import { LoadConfigOptions } from 'c12';
3
3
  import { Import } from 'unimport';
4
4
  import { Configuration, WebpackPluginInstance } from 'webpack';
@@ -53,8 +53,6 @@ interface ExtendConfigOptions {
53
53
  * @default true
54
54
  */
55
55
  build?: boolean;
56
- }
57
- interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
58
56
  /**
59
57
  * Install plugin on server side
60
58
  *
@@ -67,6 +65,8 @@ interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
67
65
  * @default true
68
66
  */
69
67
  client?: boolean;
68
+ }
69
+ interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
70
70
  /**
71
71
  * Install plugin on modern build
72
72
  *
@@ -172,6 +172,8 @@ declare function tryUseNuxt(): Nuxt | null;
172
172
  */
173
173
  declare function isIgnored(pathname: string): boolean;
174
174
 
175
+ declare function addLayout(tmpl: NuxtTemplate, name?: string): void;
176
+
175
177
  declare function extendPages(cb: NuxtHooks['pages:extend']): void;
176
178
 
177
179
  /**
@@ -306,4 +308,4 @@ declare const templateUtils: {
306
308
  }) => string;
307
309
  };
308
310
 
309
- export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LegacyServerMiddleware, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addPlugin, addPluginTemplate, addServerHandler, addServerMiddleware, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, clearRequireCache, compileTemplate, createResolver, defineNuxtModule, extendPages, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, getRequireCacheItem, hasNuxtCompatibility, importModule, installModule, isIgnored, isNodeModules, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, useLogger, useModuleContainer, useNuxt };
311
+ export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LegacyServerMiddleware, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addLayout, addPlugin, addPluginTemplate, addServerHandler, addServerMiddleware, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, clearRequireCache, compileTemplate, createResolver, defineNuxtModule, extendPages, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, getRequireCacheItem, hasNuxtCompatibility, importModule, installModule, isIgnored, isNodeModules, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, useLogger, useModuleContainer, useNuxt };
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
- import { parse, basename, resolve, normalize, join, relative, isAbsolute, dirname } from 'pathe';
2
- import consola from 'consola';
1
+ import { parse, basename, resolve, relative, join, normalize, isAbsolute, dirname } from 'pathe';
3
2
  import { existsSync, readFileSync, promises } from 'node:fs';
4
3
  import hash from 'hash-sum';
5
4
  import { getContext } from 'unctx';
5
+ import { kebabCase, pascalCase } from 'scule';
6
6
  import satisfies from 'semver/functions/satisfies.js';
7
+ import consola from 'consola';
7
8
  import { pathToFileURL, fileURLToPath } from 'node:url';
8
9
  import { interopDefault } from 'mlly';
9
10
  import jiti from 'jiti';
@@ -16,12 +17,6 @@ import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
16
17
  import { loadConfig } from 'c12';
17
18
  import { NuxtConfigSchema } from '@nuxt/schema';
18
19
  import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
19
- import { kebabCase, pascalCase } from 'scule';
20
-
21
- const logger = consola;
22
- function useLogger(scope) {
23
- return scope ? logger.withScope(scope) : logger;
24
- }
25
20
 
26
21
  function chainFn(base, fn) {
27
22
  if (typeof fn !== "function") {
@@ -96,16 +91,6 @@ function normalizeTemplate(template) {
96
91
  return template;
97
92
  }
98
93
 
99
- function addServerMiddleware(middleware) {
100
- useNuxt().options.serverMiddleware.push(middleware);
101
- }
102
- function addServerHandler(handler) {
103
- useNuxt().options.serverHandlers.push(handler);
104
- }
105
- function addDevServerHandler(handler) {
106
- useNuxt().options.devServerHandlers.push(handler);
107
- }
108
-
109
94
  async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
110
95
  const issues = [];
111
96
  if (constraints.nuxt) {
@@ -162,6 +147,55 @@ function getNuxtVersion(nuxt = useNuxt()) {
162
147
  return version;
163
148
  }
164
149
 
150
+ const logger = consola;
151
+ function useLogger(scope) {
152
+ return scope ? logger.withScope(scope) : logger;
153
+ }
154
+
155
+ function addLayout(tmpl, name) {
156
+ const nuxt = useNuxt();
157
+ const { filename, src } = addTemplate(tmpl);
158
+ const layoutName = kebabCase(name || parse(tmpl.filename).name).replace(/["']/g, "");
159
+ if (isNuxt2(nuxt)) {
160
+ const layout = nuxt.options.layouts[layoutName];
161
+ if (layout) {
162
+ return logger.warn(`Not overriding \`${layoutName}\` (provided by \`${layout}\`) with \`${src || filename}\`.`);
163
+ }
164
+ nuxt.options.layouts[layoutName] = `./${filename}`;
165
+ if (name === "error") {
166
+ this.addErrorLayout(filename);
167
+ }
168
+ return;
169
+ }
170
+ nuxt.hook("app:templates", (app) => {
171
+ if (layoutName in app.layouts) {
172
+ const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName].file);
173
+ return logger.warn(`Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.`);
174
+ }
175
+ app.layouts[layoutName] = {
176
+ file: join("#build", filename),
177
+ name: layoutName
178
+ };
179
+ });
180
+ }
181
+
182
+ function normalizeHandlerMethod(handler) {
183
+ const [, method = void 0] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || [];
184
+ return {
185
+ method,
186
+ ...handler
187
+ };
188
+ }
189
+ function addServerMiddleware(middleware) {
190
+ useNuxt().options.serverMiddleware.push(middleware);
191
+ }
192
+ function addServerHandler(handler) {
193
+ useNuxt().options.serverHandlers.push(normalizeHandlerMethod(handler));
194
+ }
195
+ function addDevServerHandler(handler) {
196
+ useNuxt().options.devServerHandlers.push(handler);
197
+ }
198
+
165
199
  function normalizePlugin(plugin) {
166
200
  if (typeof plugin === "string") {
167
201
  plugin = { src: plugin };
@@ -466,16 +500,7 @@ function useModuleContainer(nuxt = useNuxt()) {
466
500
  return addPluginTemplate(pluginTemplate);
467
501
  },
468
502
  addLayout(tmpl, name) {
469
- const { filename, src } = addTemplate(tmpl);
470
- const layoutName = name || parse(src).name;
471
- const layout = nuxt.options.layouts[layoutName];
472
- if (layout) {
473
- logger.warn(`Duplicate layout registration, "${layoutName}" has been registered as "${layout}"`);
474
- }
475
- nuxt.options.layouts[layoutName] = `./${filename}`;
476
- if (name === "error") {
477
- this.addErrorLayout(filename);
478
- }
503
+ return addLayout(tmpl, name);
479
504
  },
480
505
  addErrorLayout(dst) {
481
506
  const relativeBuildDir = relative(nuxt.options.rootDir, nuxt.options.buildDir);
@@ -734,7 +759,14 @@ function extendViteConfig(fn, options = {}) {
734
759
  if (options.build === false && nuxt.options.build) {
735
760
  return;
736
761
  }
737
- nuxt.hook("vite:extend", ({ config }) => fn(config));
762
+ nuxt.hook("vite:extendConfig", (config, { isClient, isServer }) => {
763
+ if (options.server !== false && isServer) {
764
+ return fn(config);
765
+ }
766
+ if (options.client !== false && isClient) {
767
+ return fn(config);
768
+ }
769
+ });
738
770
  }
739
771
  function addWebpackPlugin(plugin, options) {
740
772
  extendWebpackConfig((config) => {
@@ -778,7 +810,7 @@ async function addComponent(opts) {
778
810
  ...opts
779
811
  };
780
812
  nuxt.hook("components:extend", (components) => {
781
- const existingComponent = components.find((c) => c.pascalName === component.pascalName || c.kebabName === component.kebabName);
813
+ const existingComponent = components.find((c) => (c.pascalName === component.pascalName || c.kebabName === component.kebabName) && c.mode === component.mode);
782
814
  if (existingComponent) {
783
815
  const name = existingComponent.pascalName || existingComponent.kebabName;
784
816
  console.warn(`Overriding ${name} component.`);
@@ -798,4 +830,4 @@ function extendPages(cb) {
798
830
  }
799
831
  }
800
832
 
801
- export { addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addPlugin, addPluginTemplate, addServerHandler, addServerMiddleware, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, clearRequireCache, compileTemplate, createResolver, defineNuxtModule, extendPages, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, getRequireCacheItem, hasNuxtCompatibility, importModule, installModule, isIgnored, isNodeModules, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, useLogger, useModuleContainer, useNuxt };
833
+ export { addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addLayout, addPlugin, addPluginTemplate, addServerHandler, addServerMiddleware, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, clearRequireCache, compileTemplate, createResolver, defineNuxtModule, extendPages, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, getRequireCacheItem, hasNuxtCompatibility, importModule, installModule, isIgnored, isNodeModules, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, useLogger, useModuleContainer, useNuxt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.0.0-rc.4",
3
+ "version": "3.0.0-rc.5",
4
4
  "repository": "nuxt/framework",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,23 +13,23 @@
13
13
  "prepack": "unbuild"
14
14
  },
15
15
  "dependencies": {
16
- "@nuxt/schema": "^3.0.0-rc.4",
17
- "c12": "^0.2.7",
16
+ "@nuxt/schema": "^3.0.0-rc.5",
17
+ "c12": "^0.2.8",
18
18
  "consola": "^2.15.3",
19
19
  "defu": "^6.0.0",
20
20
  "globby": "^13.1.2",
21
21
  "hash-sum": "^2.0.0",
22
22
  "ignore": "^5.2.0",
23
- "jiti": "^1.13.0",
23
+ "jiti": "^1.14.0",
24
24
  "knitwork": "^0.1.2",
25
25
  "lodash.template": "^4.5.0",
26
- "mlly": "^0.5.2",
27
- "pathe": "^0.3.0",
28
- "pkg-types": "^0.3.2",
26
+ "mlly": "^0.5.4",
27
+ "pathe": "^0.3.2",
28
+ "pkg-types": "^0.3.3",
29
29
  "scule": "^0.2.1",
30
30
  "semver": "^7.3.7",
31
31
  "unctx": "^1.1.4",
32
- "unimport": "^0.2.7",
32
+ "unimport": "^0.4.4",
33
33
  "untyped": "^0.4.4"
34
34
  },
35
35
  "devDependencies": {