@nuxt/kit 3.0.0-rc.11 → 3.0.0-rc.13

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 - Nuxt Project
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -3,8 +3,7 @@ import { LoadConfigOptions } from 'c12';
3
3
  import { Import } from 'unimport';
4
4
  import { Configuration, WebpackPluginInstance } from 'webpack';
5
5
  import { UserConfig, Plugin } from 'vite';
6
- import * as unctx from 'unctx';
7
- import { Middleware } from 'h3';
6
+ import * as unctx_index from 'unctx/index';
8
7
  import { NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack';
9
8
  import * as consola from 'consola';
10
9
  import { genSafeVariableName } from 'knitwork';
@@ -100,11 +99,11 @@ declare function extendViteConfig(fn: ((config: UserConfig) => void), options?:
100
99
  /**
101
100
  * Append Webpack plugin to the config.
102
101
  */
103
- declare function addWebpackPlugin(plugin: WebpackPluginInstance, options?: ExtendWebpackConfigOptions): void;
102
+ declare function addWebpackPlugin(plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions): void;
104
103
  /**
105
104
  * Append Vite plugin to the config.
106
105
  */
107
- declare function addVitePlugin(plugin: Plugin, options?: ExtendViteConfigOptions): void;
106
+ declare function addVitePlugin(plugin: Plugin | Plugin[], options?: ExtendViteConfigOptions): void;
108
107
 
109
108
  /**
110
109
  * Check version constraints and return incompatibility issues as an array
@@ -149,7 +148,7 @@ declare type AddComponentOptions = {
149
148
  declare function addComponent(opts: AddComponentOptions): Promise<void>;
150
149
 
151
150
  /** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
152
- declare const nuxtCtx: unctx.UseContext<Nuxt>;
151
+ declare const nuxtCtx: unctx_index.UseContext<Nuxt>;
153
152
  /**
154
153
  * Get access to Nuxt instance.
155
154
  *
@@ -248,18 +247,6 @@ declare function resolveFiles(path: string, pattern: string | string[], opts?: {
248
247
  followSymbolicLinks?: boolean;
249
248
  }): Promise<string[]>;
250
249
 
251
- interface LegacyServerMiddleware {
252
- route?: string;
253
- path?: string;
254
- handle?: Middleware | string;
255
- handler: Middleware | string;
256
- }
257
- /**
258
- * Adds a new server middleware to the end of the server middleware array.
259
- *
260
- * @deprecated Use addServerHandler instead
261
- */
262
- declare function addServerMiddleware(middleware: LegacyServerMiddleware): void;
263
250
  /**
264
251
  * Adds a nitro server handler
265
252
  *
@@ -270,6 +257,14 @@ declare function addServerHandler(handler: NitroEventHandler): void;
270
257
  *
271
258
  */
272
259
  declare function addDevServerHandler(handler: NitroDevEventHandler): void;
260
+ /**
261
+ * Adds a Nitro plugin
262
+ */
263
+ declare function addServerPlugin(plugin: string): void;
264
+ /**
265
+ * Adds routes to be prerendered
266
+ */
267
+ declare function addPrerenderRoutes(routes: string | string[]): void;
273
268
  /**
274
269
  * Access to the Nitro instance
275
270
  *
@@ -295,6 +290,14 @@ declare function addTemplate(_template: NuxtTemplate<any> | string): ResolvedNux
295
290
  * Normalize a nuxt template object
296
291
  */
297
292
  declare function normalizeTemplate(template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
293
+ /**
294
+ * Trigger rebuilding Nuxt templates
295
+ *
296
+ * You can pass a filter within the options to selectively regenerate a subset of templates.
297
+ */
298
+ declare function updateTemplates(options?: {
299
+ filter?: (template: ResolvedNuxtTemplate<any>) => boolean;
300
+ }): Promise<any>;
298
301
 
299
302
  declare const logger: consola.Consola;
300
303
  declare function useLogger(scope?: string): consola.Consola;
@@ -336,4 +339,4 @@ declare const templateUtils: {
336
339
  }) => string;
337
340
  };
338
341
 
339
- export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LegacyServerMiddleware, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, 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, useNitro, useNuxt };
342
+ export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addServerHandler, addServerPlugin, 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, updateTemplates, useLogger, useModuleContainer, useNitro, useNuxt };
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import satisfies from 'semver/functions/satisfies.js';
7
7
  import consola from 'consola';
8
8
  import { pathToFileURL, fileURLToPath } from 'node:url';
9
9
  import { globby } from 'globby';
10
- import { normalizeAliases } from 'pathe/utils';
10
+ import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
11
11
  import { interopDefault } from 'mlly';
12
12
  import jiti from 'jiti';
13
13
  import ignore from 'ignore';
@@ -95,6 +95,9 @@ function normalizeTemplate(template) {
95
95
  }
96
96
  return template;
97
97
  }
98
+ function updateTemplates(options) {
99
+ return useNuxt().hooks.callHook("builder:generateApp", options);
100
+ }
98
101
 
99
102
  async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
100
103
  const issues = [];
@@ -188,30 +191,6 @@ function addLayout(template, name) {
188
191
  });
189
192
  }
190
193
 
191
- function normalizeHandlerMethod(handler) {
192
- const [, method = void 0] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || [];
193
- return {
194
- method,
195
- ...handler
196
- };
197
- }
198
- function addServerMiddleware(middleware) {
199
- useNuxt().options.serverMiddleware.push(middleware);
200
- }
201
- function addServerHandler(handler) {
202
- useNuxt().options.serverHandlers.push(normalizeHandlerMethod(handler));
203
- }
204
- function addDevServerHandler(handler) {
205
- useNuxt().options.devServerHandlers.push(handler);
206
- }
207
- function useNitro() {
208
- const nuxt = useNuxt();
209
- if (!nuxt._nitro) {
210
- throw new Error("Nitro is not initialized yet. You can call `useNitro()` only after `ready` hook.");
211
- }
212
- return nuxt._nitro;
213
- }
214
-
215
194
  const _require = jiti(process.cwd(), { interopDefault: true, esmResolve: true });
216
195
  function isNodeModules(id) {
217
196
  return /[/\\]node_modules[/\\]/.test(id);
@@ -331,7 +310,7 @@ async function resolvePath(path, opts = {}) {
331
310
  if (isAbsolute(path) && existsSync(path) && !await isDirectory(path)) {
332
311
  return path;
333
312
  }
334
- const nuxt = useNuxt();
313
+ const nuxt = tryUseNuxt();
335
314
  const cwd = opts.cwd || (nuxt ? nuxt.options.rootDir : process.cwd());
336
315
  const extensions = opts.extensions || (nuxt ? nuxt.options.extensions : [".ts", ".mjs", ".cjs", ".json"]);
337
316
  const modulesDir = nuxt ? nuxt.options.modulesDir : [];
@@ -381,15 +360,7 @@ function resolveAlias(path, alias) {
381
360
  if (!alias) {
382
361
  alias = tryUseNuxt()?.options.alias || {};
383
362
  }
384
- for (const key in normalizeAliases(alias)) {
385
- if (key === "@" && !path.startsWith("@/")) {
386
- continue;
387
- }
388
- if (path.startsWith(key)) {
389
- path = alias[key] + path.slice(key.length);
390
- }
391
- }
392
- return path;
363
+ return resolveAlias$1(path, alias);
393
364
  }
394
365
  function createResolver(base) {
395
366
  if (!base) {
@@ -473,7 +444,12 @@ async function normalizeModule(nuxtModule, inlineOptions) {
473
444
  if (typeof nuxtModule === "string") {
474
445
  const _src = resolveModule(resolveAlias(nuxtModule), { paths: nuxt.options.modulesDir });
475
446
  const isESM = _src.endsWith(".mjs");
476
- nuxtModule = isESM ? await importModule(_src) : requireModule(_src);
447
+ try {
448
+ nuxtModule = isESM ? await importModule(_src) : requireModule(_src);
449
+ } catch (error) {
450
+ console.error(`Error while requiring module \`${nuxtModule}\`: ${error}`);
451
+ throw error;
452
+ }
477
453
  }
478
454
  if (typeof nuxtModule !== "function") {
479
455
  throw new TypeError("Nuxt module should be a function: " + nuxtModule);
@@ -514,7 +490,8 @@ function useModuleContainer(nuxt = useNuxt()) {
514
490
  },
515
491
  requireModule,
516
492
  addModule: requireModule,
517
- addServerMiddleware,
493
+ addServerMiddleware: () => {
494
+ },
518
495
  addTemplate(template) {
519
496
  if (typeof template === "string") {
520
497
  template = { src: template };
@@ -703,9 +680,10 @@ async function loadNuxtConfig(opts) {
703
680
  layer.config.rootDir = layer.config.rootDir ?? layer.cwd;
704
681
  layer.config.srcDir = resolve(layer.config.rootDir, layer.config.srcDir);
705
682
  }
706
- nuxtConfig._layers = layers.filter((layer) => layer.configFile && !layer.configFile.endsWith(".nuxtrc"));
707
- if (!nuxtConfig._layers.length) {
708
- nuxtConfig._layers.push({
683
+ const _layers = layers.filter((layer) => layer.configFile && !layer.configFile.endsWith(".nuxtrc"));
684
+ nuxtConfig._layers = _layers;
685
+ if (!_layers.length) {
686
+ _layers.push({
709
687
  cwd,
710
688
  config: {
711
689
  rootDir: cwd,
@@ -829,13 +807,21 @@ function extendViteConfig(fn, options = {}) {
829
807
  function addWebpackPlugin(plugin, options) {
830
808
  extendWebpackConfig((config) => {
831
809
  config.plugins = config.plugins || [];
832
- config.plugins.push(plugin);
810
+ if (Array.isArray(plugin)) {
811
+ config.plugins.push(...plugin);
812
+ } else {
813
+ config.plugins.push(plugin);
814
+ }
833
815
  }, options);
834
816
  }
835
817
  function addVitePlugin(plugin, options) {
836
818
  extendViteConfig((config) => {
837
819
  config.plugins = config.plugins || [];
838
- config.plugins.push(plugin);
820
+ if (Array.isArray(plugin)) {
821
+ config.plugins.push(...plugin);
822
+ } else {
823
+ config.plugins.push(plugin);
824
+ }
839
825
  }, options);
840
826
  }
841
827
 
@@ -888,4 +874,46 @@ function extendPages(cb) {
888
874
  }
889
875
  }
890
876
 
891
- export { addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, 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, useNitro, useNuxt };
877
+ function normalizeHandlerMethod(handler) {
878
+ const [, method = void 0] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || [];
879
+ return {
880
+ method,
881
+ ...handler,
882
+ handler: normalize(handler.handler)
883
+ };
884
+ }
885
+ function addServerHandler(handler) {
886
+ useNuxt().options.serverHandlers.push(normalizeHandlerMethod(handler));
887
+ }
888
+ function addDevServerHandler(handler) {
889
+ useNuxt().options.devServerHandlers.push(handler);
890
+ }
891
+ function addServerPlugin(plugin) {
892
+ const nuxt = useNuxt();
893
+ nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || [];
894
+ nuxt.options.nitro.plugins.push(normalize(plugin));
895
+ }
896
+ function addPrerenderRoutes(routes) {
897
+ const nuxt = useNuxt();
898
+ if (!Array.isArray(routes)) {
899
+ routes = [routes];
900
+ }
901
+ routes = routes.filter(Boolean);
902
+ if (!routes.length) {
903
+ return;
904
+ }
905
+ nuxt.hook("prerender:routes", (ctx) => {
906
+ for (const route of routes) {
907
+ ctx.routes.add(route);
908
+ }
909
+ });
910
+ }
911
+ function useNitro() {
912
+ const nuxt = useNuxt();
913
+ if (!nuxt._nitro) {
914
+ throw new Error("Nitro is not initialized yet. You can call `useNitro()` only after `ready` hook.");
915
+ }
916
+ return nuxt._nitro;
917
+ }
918
+
919
+ export { addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addServerHandler, addServerPlugin, 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, updateTemplates, useLogger, useModuleContainer, useNitro, useNuxt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.0.0-rc.11",
3
+ "version": "3.0.0-rc.13",
4
4
  "repository": "nuxt/framework",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,11 +9,8 @@
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
- "scripts": {
13
- "prepack": "unbuild"
14
- },
15
12
  "dependencies": {
16
- "@nuxt/schema": "3.0.0-rc.11",
13
+ "@nuxt/schema": "3.0.0-rc.13",
17
14
  "c12": "^0.2.13",
18
15
  "consola": "^2.15.3",
19
16
  "defu": "^6.1.0",
@@ -24,12 +21,12 @@
24
21
  "knitwork": "^0.1.2",
25
22
  "lodash.template": "^4.5.0",
26
23
  "mlly": "^0.5.16",
27
- "pathe": "^0.3.8",
28
- "pkg-types": "^0.3.5",
24
+ "pathe": "^0.3.9",
25
+ "pkg-types": "^0.3.6",
29
26
  "scule": "^0.3.2",
30
- "semver": "^7.3.7",
27
+ "semver": "^7.3.8",
31
28
  "unctx": "^2.0.2",
32
- "unimport": "^0.6.7",
29
+ "unimport": "^0.7.0",
33
30
  "untyped": "^0.5.0"
34
31
  },
35
32
  "devDependencies": {
@@ -38,6 +35,7 @@
38
35
  "unbuild": "latest"
39
36
  },
40
37
  "engines": {
41
- "node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0"
42
- }
43
- }
38
+ "node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
39
+ },
40
+ "scripts": {}
41
+ }