@nuxt/kit 3.0.0-rc.3 → 3.0.0-rc.6

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';
@@ -7,6 +7,7 @@ import * as unctx from 'unctx';
7
7
  import { Middleware } from 'h3';
8
8
  import { NitroEventHandler, NitroDevEventHandler } from 'nitropack';
9
9
  import * as consola from 'consola';
10
+ import { genSafeVariableName } from 'knitwork';
10
11
 
11
12
  declare function useModuleContainer(nuxt?: Nuxt): ModuleContainer;
12
13
 
@@ -52,8 +53,6 @@ interface ExtendConfigOptions {
52
53
  * @default true
53
54
  */
54
55
  build?: boolean;
55
- }
56
- interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
57
56
  /**
58
57
  * Install plugin on server side
59
58
  *
@@ -66,6 +65,8 @@ interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
66
65
  * @default true
67
66
  */
68
67
  client?: boolean;
68
+ }
69
+ interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
69
70
  /**
70
71
  * Install plugin on modern build
71
72
  *
@@ -86,7 +87,7 @@ declare function extendWebpackConfig(fn: ((config: Configuration) => void), opti
86
87
  /**
87
88
  * Extend Vite config
88
89
  */
89
- declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): void;
90
+ declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): () => void;
90
91
  /**
91
92
  * Append Webpack plugin to the config.
92
93
  */
@@ -171,6 +172,8 @@ declare function tryUseNuxt(): Nuxt | null;
171
172
  */
172
173
  declare function isIgnored(pathname: string): boolean;
173
174
 
175
+ declare function addLayout(tmpl: NuxtTemplate, name?: string): void;
176
+
174
177
  declare function extendPages(cb: NuxtHooks['pages:extend']): void;
175
178
 
176
179
  /**
@@ -299,10 +302,10 @@ declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
299
302
  declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
300
303
  declare const templateUtils: {
301
304
  serialize: (data: any) => string;
302
- importName: (src: string) => string;
305
+ importName: typeof genSafeVariableName;
303
306
  importSources: (sources: string | string[], { lazy }?: {
304
307
  lazy?: boolean;
305
308
  }) => string;
306
309
  };
307
310
 
308
- 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, extname } 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';
@@ -12,17 +13,11 @@ import ignore from 'ignore';
12
13
  import defu from 'defu';
13
14
  import { applyDefaults } from 'untyped';
14
15
  import lodashTemplate from 'lodash.template';
15
- import { camelCase, kebabCase, pascalCase } from 'scule';
16
- import { genDynamicImport, genImport } from 'knitwork';
16
+ import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
17
17
  import { loadConfig } from 'c12';
18
18
  import { NuxtConfigSchema } from '@nuxt/schema';
19
19
  import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
20
20
 
21
- const logger = consola;
22
- function useLogger(scope) {
23
- return scope ? logger.withScope(scope) : logger;
24
- }
25
-
26
21
  function chainFn(base, fn) {
27
22
  if (typeof fn !== "function") {
28
23
  return base;
@@ -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) {
@@ -119,7 +104,7 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
119
104
  }
120
105
  }
121
106
  if (isNuxt2(nuxt)) {
122
- const bridgeRequirement = constraints?.bridge;
107
+ const bridgeRequirement = constraints.bridge;
123
108
  const hasBridge = !!nuxt.options.bridge;
124
109
  if (bridgeRequirement === true && !hasBridge) {
125
110
  issues.push({
@@ -157,11 +142,60 @@ function isNuxt3(nuxt = useNuxt()) {
157
142
  function getNuxtVersion(nuxt = useNuxt()) {
158
143
  const version = (nuxt?._version || nuxt?.version || nuxt?.constructor?.version || "").replace(/^v/g, "");
159
144
  if (!version) {
160
- throw new Error("Cannot determine nuxt version! Is currect instance passed?");
145
+ throw new Error("Cannot determine nuxt version! Is current instance passed?");
161
146
  }
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 };
@@ -389,7 +423,7 @@ async function existsSensitive(path) {
389
423
  }
390
424
  async function resolveFiles(path, pattern) {
391
425
  const files = await globby(pattern, { cwd: path, followSymbolicLinks: true });
392
- return files.filter((p) => !isIgnored(p)).map((p) => resolve(path, p));
426
+ return files.map((p) => resolve(path, p)).filter((p) => !isIgnored(p));
393
427
  }
394
428
 
395
429
  async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
@@ -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);
@@ -520,19 +545,18 @@ async function compileTemplate(template, ctx) {
520
545
  throw new Error("Invalid template: " + JSON.stringify(template));
521
546
  }
522
547
  const serialize = (data) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, (r) => JSON.parse(r).replace(/^{(.*)}$/, "$1"));
523
- const importName = (src) => `${camelCase(basename(src, extname(src))).replace(/[^a-zA-Z?\d\s:]/g, "")}_${hash(src)}`;
524
548
  const importSources = (sources, { lazy = false } = {}) => {
525
549
  if (!Array.isArray(sources)) {
526
550
  sources = [sources];
527
551
  }
528
552
  return sources.map((src) => {
529
553
  if (lazy) {
530
- return `const ${importName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
554
+ return `const ${genSafeVariableName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
531
555
  }
532
- return genImport(src, importName(src));
556
+ return genImport(src, genSafeVariableName(src));
533
557
  }).join("\n");
534
558
  };
535
- const templateUtils = { serialize, importName, importSources };
559
+ const templateUtils = { serialize, importName: genSafeVariableName, importSources };
536
560
 
537
561
  function defineNuxtModule(definition) {
538
562
  if (typeof definition === "function") {
@@ -544,7 +568,7 @@ function defineNuxtModule(definition) {
544
568
  }
545
569
  if (!definition.meta.configKey) {
546
570
  definition.meta.name = definition.meta.name || definition.name;
547
- definition.meta.configKey = definition.meta.configKey || definition.configKey || definition.meta.name;
571
+ definition.meta.configKey = definition.configKey || definition.meta.name;
548
572
  }
549
573
  function getOptions(inlineOptions, nuxt = useNuxt()) {
550
574
  const configKey = definition.meta.configKey || definition.meta.name;
@@ -735,7 +759,17 @@ function extendViteConfig(fn, options = {}) {
735
759
  if (options.build === false && nuxt.options.build) {
736
760
  return;
737
761
  }
738
- nuxt.hook("vite:extend", ({ config }) => fn(config));
762
+ if (options.server !== false && options.client !== false) {
763
+ return nuxt.hook("vite:extend", ({ config }) => fn(config));
764
+ }
765
+ nuxt.hook("vite:extendConfig", (config, { isClient, isServer }) => {
766
+ if (options.server !== false && isServer) {
767
+ return fn(config);
768
+ }
769
+ if (options.client !== false && isClient) {
770
+ return fn(config);
771
+ }
772
+ });
739
773
  }
740
774
  function addWebpackPlugin(plugin, options) {
741
775
  extendWebpackConfig((config) => {
@@ -779,7 +813,7 @@ async function addComponent(opts) {
779
813
  ...opts
780
814
  };
781
815
  nuxt.hook("components:extend", (components) => {
782
- const existingComponent = components.find((c) => c.pascalName === component.pascalName || c.kebabName === component.kebabName);
816
+ const existingComponent = components.find((c) => (c.pascalName === component.pascalName || c.kebabName === component.kebabName) && c.mode === component.mode);
783
817
  if (existingComponent) {
784
818
  const name = existingComponent.pascalName || existingComponent.kebabName;
785
819
  console.warn(`Overriding ${name} component.`);
@@ -799,4 +833,4 @@ function extendPages(cb) {
799
833
  }
800
834
  }
801
835
 
802
- 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 };
836
+ 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.3",
3
+ "version": "3.0.0-rc.6",
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.3",
17
- "c12": "^0.2.7",
16
+ "@nuxt/schema": "^3.0.0-rc.6",
17
+ "c12": "^0.2.8",
18
18
  "consola": "^2.15.3",
19
19
  "defu": "^6.0.0",
20
- "globby": "^13.1.1",
20
+ "globby": "^13.1.2",
21
21
  "hash-sum": "^2.0.0",
22
22
  "ignore": "^5.2.0",
23
- "jiti": "^1.13.0",
24
- "knitwork": "^0.1.1",
23
+ "jiti": "^1.14.0",
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.1.9",
32
+ "unimport": "^0.4.5",
33
33
  "untyped": "^0.4.4"
34
34
  },
35
35
  "devDependencies": {