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

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
@@ -5,7 +5,9 @@ import { Configuration, WebpackPluginInstance } from 'webpack';
5
5
  import { UserConfig, Plugin } from 'vite';
6
6
  import * as unctx from 'unctx';
7
7
  import { Middleware } from 'h3';
8
+ import { NitroEventHandler, NitroDevEventHandler } from 'nitropack';
8
9
  import * as consola from 'consola';
10
+ import { genSafeVariableName } from 'knitwork';
9
11
 
10
12
  declare function useModuleContainer(nuxt?: Nuxt): ModuleContainer;
11
13
 
@@ -233,12 +235,28 @@ interface Resolver {
233
235
  declare function createResolver(base: string | URL): Resolver;
234
236
  declare function resolveFiles(path: string, pattern: string | string[]): Promise<string[]>;
235
237
 
236
- interface ServerMiddleware {
238
+ interface LegacyServerMiddleware {
237
239
  route?: string;
240
+ path?: string;
241
+ handle?: Middleware | string;
238
242
  handler: Middleware | string;
239
243
  }
240
- /** Adds a new server middleware to the end of the server middleware array. */
241
- declare function addServerMiddleware(middleware: ServerMiddleware): void;
244
+ /**
245
+ * Adds a new server middleware to the end of the server middleware array.
246
+ *
247
+ * @deprecated Use addServerHandler instead
248
+ */
249
+ declare function addServerMiddleware(middleware: LegacyServerMiddleware): void;
250
+ /**
251
+ * Adds a nitro server handler
252
+ *
253
+ */
254
+ declare function addServerHandler(handler: NitroEventHandler): void;
255
+ /**
256
+ * Adds a nitro server handler for development-only
257
+ *
258
+ */
259
+ declare function addDevServerHandler(handler: NitroDevEventHandler): void;
242
260
 
243
261
  /**
244
262
  * Renders given template using lodash template during build into the project buildDir
@@ -282,10 +300,10 @@ declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
282
300
  declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
283
301
  declare const templateUtils: {
284
302
  serialize: (data: any) => string;
285
- importName: (src: string) => string;
303
+ importName: typeof genSafeVariableName;
286
304
  importSources: (sources: string | string[], { lazy }?: {
287
305
  lazy?: boolean;
288
306
  }) => string;
289
307
  };
290
308
 
291
- export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, ServerMiddleware, addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addPlugin, addPluginTemplate, 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 };
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 };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { parse, basename, resolve, normalize, join, relative, isAbsolute, dirname, extname } from 'pathe';
1
+ import { parse, basename, resolve, normalize, join, relative, isAbsolute, dirname } from 'pathe';
2
2
  import consola from 'consola';
3
3
  import { existsSync, readFileSync, promises } from 'node:fs';
4
4
  import hash from 'hash-sum';
@@ -12,11 +12,11 @@ import ignore from 'ignore';
12
12
  import defu from 'defu';
13
13
  import { applyDefaults } from 'untyped';
14
14
  import lodashTemplate from 'lodash.template';
15
- import { camelCase, kebabCase, pascalCase } from 'scule';
16
- import { genDynamicImport, genImport } from 'knitwork';
15
+ import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
17
16
  import { loadConfig } from 'c12';
18
17
  import { NuxtConfigSchema } from '@nuxt/schema';
19
18
  import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
19
+ import { kebabCase, pascalCase } from 'scule';
20
20
 
21
21
  const logger = consola;
22
22
  function useLogger(scope) {
@@ -99,6 +99,12 @@ function normalizeTemplate(template) {
99
99
  function addServerMiddleware(middleware) {
100
100
  useNuxt().options.serverMiddleware.push(middleware);
101
101
  }
102
+ function addServerHandler(handler) {
103
+ useNuxt().options.serverHandlers.push(handler);
104
+ }
105
+ function addDevServerHandler(handler) {
106
+ useNuxt().options.devServerHandlers.push(handler);
107
+ }
102
108
 
103
109
  async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
104
110
  const issues = [];
@@ -113,7 +119,7 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
113
119
  }
114
120
  }
115
121
  if (isNuxt2(nuxt)) {
116
- const bridgeRequirement = constraints?.bridge;
122
+ const bridgeRequirement = constraints.bridge;
117
123
  const hasBridge = !!nuxt.options.bridge;
118
124
  if (bridgeRequirement === true && !hasBridge) {
119
125
  issues.push({
@@ -151,7 +157,7 @@ function isNuxt3(nuxt = useNuxt()) {
151
157
  function getNuxtVersion(nuxt = useNuxt()) {
152
158
  const version = (nuxt?._version || nuxt?.version || nuxt?.constructor?.version || "").replace(/^v/g, "");
153
159
  if (!version) {
154
- throw new Error("Cannot determine nuxt version! Is currect instance passed?");
160
+ throw new Error("Cannot determine nuxt version! Is current instance passed?");
155
161
  }
156
162
  return version;
157
163
  }
@@ -383,7 +389,7 @@ async function existsSensitive(path) {
383
389
  }
384
390
  async function resolveFiles(path, pattern) {
385
391
  const files = await globby(pattern, { cwd: path, followSymbolicLinks: true });
386
- return files.filter((p) => !isIgnored(p)).map((p) => resolve(path, p));
392
+ return files.map((p) => resolve(path, p)).filter((p) => !isIgnored(p));
387
393
  }
388
394
 
389
395
  async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
@@ -514,19 +520,18 @@ async function compileTemplate(template, ctx) {
514
520
  throw new Error("Invalid template: " + JSON.stringify(template));
515
521
  }
516
522
  const serialize = (data) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, (r) => JSON.parse(r).replace(/^{(.*)}$/, "$1"));
517
- const importName = (src) => `${camelCase(basename(src, extname(src))).replace(/[^a-zA-Z?\d\s:]/g, "")}_${hash(src)}`;
518
523
  const importSources = (sources, { lazy = false } = {}) => {
519
524
  if (!Array.isArray(sources)) {
520
525
  sources = [sources];
521
526
  }
522
527
  return sources.map((src) => {
523
528
  if (lazy) {
524
- return `const ${importName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
529
+ return `const ${genSafeVariableName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
525
530
  }
526
- return genImport(src, importName(src));
531
+ return genImport(src, genSafeVariableName(src));
527
532
  }).join("\n");
528
533
  };
529
- const templateUtils = { serialize, importName, importSources };
534
+ const templateUtils = { serialize, importName: genSafeVariableName, importSources };
530
535
 
531
536
  function defineNuxtModule(definition) {
532
537
  if (typeof definition === "function") {
@@ -538,7 +543,7 @@ function defineNuxtModule(definition) {
538
543
  }
539
544
  if (!definition.meta.configKey) {
540
545
  definition.meta.name = definition.meta.name || definition.name;
541
- definition.meta.configKey = definition.meta.configKey || definition.configKey || definition.meta.name;
546
+ definition.meta.configKey = definition.configKey || definition.meta.name;
542
547
  }
543
548
  function getOptions(inlineOptions, nuxt = useNuxt()) {
544
549
  const configKey = definition.meta.configKey || definition.meta.name;
@@ -793,4 +798,4 @@ function extendPages(cb) {
793
798
  }
794
799
  }
795
800
 
796
- export { addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addPlugin, addPluginTemplate, 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 };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.4",
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.1",
16
+ "@nuxt/schema": "^3.0.0-rc.4",
17
17
  "c12": "^0.2.7",
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
23
  "jiti": "^1.13.0",
24
- "knitwork": "^0.1.1",
24
+ "knitwork": "^0.1.2",
25
25
  "lodash.template": "^4.5.0",
26
26
  "mlly": "^0.5.2",
27
- "pathe": "^0.2.0",
27
+ "pathe": "^0.3.0",
28
28
  "pkg-types": "^0.3.2",
29
29
  "scule": "^0.2.1",
30
30
  "semver": "^7.3.7",
31
31
  "unctx": "^1.1.4",
32
- "unimport": "^0.1.6",
32
+ "unimport": "^0.2.7",
33
33
  "untyped": "^0.4.4"
34
34
  },
35
35
  "devDependencies": {