@nuxt/kit 3.0.0-rc.0 → 3.0.0-rc.10
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 +50 -18
- package/dist/index.mjs +184 -96
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { Nuxt, ModuleContainer, ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, NuxtOptions, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtHooks, NuxtPlugin, NuxtPluginTemplate,
|
|
1
|
+
import { Nuxt, ModuleContainer, ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, NuxtOptions, ImportPresetWithDeprecation, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtTemplate, NuxtHooks, NuxtPlugin, NuxtPluginTemplate, ResolvedNuxtTemplate } from '@nuxt/schema';
|
|
2
2
|
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
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
|
|
|
@@ -35,8 +37,17 @@ interface LoadNuxtOptions extends LoadNuxtConfigOptions {
|
|
|
35
37
|
declare function loadNuxt(opts: LoadNuxtOptions): Promise<Nuxt>;
|
|
36
38
|
declare function buildNuxt(nuxt: Nuxt): Promise<any>;
|
|
37
39
|
|
|
38
|
-
declare function
|
|
39
|
-
|
|
40
|
+
declare function addImports(imports: Import | Import[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Please use `addImports` instead with nuxt>=3.0.0-rc.9
|
|
43
|
+
*/
|
|
44
|
+
declare const addAutoImport: typeof addImports;
|
|
45
|
+
declare function addImportsDir(dirs: string | string[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Please use `addImportsDir` instead with nuxt>=3.0.0-rc.9
|
|
48
|
+
*/
|
|
49
|
+
declare const addAutoImportDir: typeof addImportsDir;
|
|
50
|
+
declare function addImportsSources(presets: ImportPresetWithDeprecation | ImportPresetWithDeprecation[]): void;
|
|
40
51
|
|
|
41
52
|
interface ExtendConfigOptions {
|
|
42
53
|
/**
|
|
@@ -51,8 +62,6 @@ interface ExtendConfigOptions {
|
|
|
51
62
|
* @default true
|
|
52
63
|
*/
|
|
53
64
|
build?: boolean;
|
|
54
|
-
}
|
|
55
|
-
interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
|
|
56
65
|
/**
|
|
57
66
|
* Install plugin on server side
|
|
58
67
|
*
|
|
@@ -65,6 +74,8 @@ interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
|
|
|
65
74
|
* @default true
|
|
66
75
|
*/
|
|
67
76
|
client?: boolean;
|
|
77
|
+
}
|
|
78
|
+
interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
|
|
68
79
|
/**
|
|
69
80
|
* Install plugin on modern build
|
|
70
81
|
*
|
|
@@ -85,7 +96,7 @@ declare function extendWebpackConfig(fn: ((config: Configuration) => void), opti
|
|
|
85
96
|
/**
|
|
86
97
|
* Extend Vite config
|
|
87
98
|
*/
|
|
88
|
-
declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): void;
|
|
99
|
+
declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): (() => void) | undefined;
|
|
89
100
|
/**
|
|
90
101
|
* Append Webpack plugin to the config.
|
|
91
102
|
*/
|
|
@@ -170,6 +181,8 @@ declare function tryUseNuxt(): Nuxt | null;
|
|
|
170
181
|
*/
|
|
171
182
|
declare function isIgnored(pathname: string): boolean;
|
|
172
183
|
|
|
184
|
+
declare function addLayout(this: any, template: NuxtTemplate, name?: string): void;
|
|
185
|
+
|
|
173
186
|
declare function extendPages(cb: NuxtHooks['pages:extend']): void;
|
|
174
187
|
|
|
175
188
|
/**
|
|
@@ -224,30 +237,48 @@ declare function findPath(paths: string | string[], opts?: ResolvePathOptions, p
|
|
|
224
237
|
*/
|
|
225
238
|
declare function resolveAlias(path: string, alias?: Record<string, string>): string;
|
|
226
239
|
interface Resolver {
|
|
227
|
-
resolve(...path:
|
|
240
|
+
resolve(...path: string[]): string;
|
|
228
241
|
resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
|
|
229
242
|
}
|
|
230
243
|
/**
|
|
231
244
|
* Create a relative resolver
|
|
232
245
|
*/
|
|
233
246
|
declare function createResolver(base: string | URL): Resolver;
|
|
234
|
-
declare function resolveFiles(path: string, pattern: string | string[]
|
|
247
|
+
declare function resolveFiles(path: string, pattern: string | string[], opts?: {
|
|
248
|
+
followSymbolicLinks?: boolean;
|
|
249
|
+
}): Promise<string[]>;
|
|
235
250
|
|
|
236
|
-
interface
|
|
251
|
+
interface LegacyServerMiddleware {
|
|
237
252
|
route?: string;
|
|
253
|
+
path?: string;
|
|
254
|
+
handle?: Middleware | string;
|
|
238
255
|
handler: Middleware | string;
|
|
239
256
|
}
|
|
240
|
-
/**
|
|
241
|
-
|
|
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
|
+
/**
|
|
264
|
+
* Adds a nitro server handler
|
|
265
|
+
*
|
|
266
|
+
*/
|
|
267
|
+
declare function addServerHandler(handler: NitroEventHandler): void;
|
|
268
|
+
/**
|
|
269
|
+
* Adds a nitro server handler for development-only
|
|
270
|
+
*
|
|
271
|
+
*/
|
|
272
|
+
declare function addDevServerHandler(handler: NitroDevEventHandler): void;
|
|
242
273
|
|
|
243
274
|
/**
|
|
244
275
|
* Renders given template using lodash template during build into the project buildDir
|
|
245
276
|
*/
|
|
246
|
-
declare function addTemplate(_template: NuxtTemplate | string):
|
|
277
|
+
declare function addTemplate(_template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
|
|
247
278
|
/**
|
|
248
279
|
* Normalize a nuxt template object
|
|
249
280
|
*/
|
|
250
|
-
declare function normalizeTemplate(template: NuxtTemplate | string):
|
|
281
|
+
declare function normalizeTemplate(template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
|
|
251
282
|
|
|
252
283
|
declare const logger: consola.Consola;
|
|
253
284
|
declare function useLogger(scope?: string): consola.Consola;
|
|
@@ -265,7 +296,7 @@ declare function isNodeModules(id: string): boolean;
|
|
|
265
296
|
declare function clearRequireCache(id: string): void;
|
|
266
297
|
declare function scanRequireTree(id: string, files?: Set<string>): Set<string>;
|
|
267
298
|
/** Access the require cache by module id. */
|
|
268
|
-
declare function getRequireCacheItem(id: string): NodeModule;
|
|
299
|
+
declare function getRequireCacheItem(id: string): NodeModule | undefined;
|
|
269
300
|
/** Resolve the `package.json` file for a given module. */
|
|
270
301
|
declare function requireModulePkg(id: string, opts?: RequireModuleOptions): any;
|
|
271
302
|
/** Resolve the path of a module. */
|
|
@@ -275,17 +306,18 @@ declare function tryResolveModule(path: string, opts?: ResolveModuleOptions): st
|
|
|
275
306
|
/** Require a module and return it. */
|
|
276
307
|
declare function requireModule(id: string, opts?: RequireModuleOptions): any;
|
|
277
308
|
declare function importModule(id: string, opts?: RequireModuleOptions): Promise<any>;
|
|
278
|
-
declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any
|
|
309
|
+
declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any> | undefined;
|
|
279
310
|
/** Try to require a module, but don't emit an error if the module can't be required. */
|
|
280
311
|
declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
|
|
281
312
|
|
|
282
313
|
declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
|
|
314
|
+
/** @deprecated */
|
|
283
315
|
declare const templateUtils: {
|
|
284
316
|
serialize: (data: any) => string;
|
|
285
|
-
importName:
|
|
317
|
+
importName: typeof genSafeVariableName;
|
|
286
318
|
importSources: (sources: string | string[], { lazy }?: {
|
|
287
|
-
lazy?: boolean;
|
|
319
|
+
lazy?: boolean | undefined;
|
|
288
320
|
}) => string;
|
|
289
321
|
};
|
|
290
322
|
|
|
291
|
-
export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver,
|
|
323
|
+
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, useNuxt };
|
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
import { parse, basename, resolve,
|
|
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';
|
|
9
|
+
import { globby } from 'globby';
|
|
10
|
+
import { normalizeAliases } from 'pathe/utils';
|
|
8
11
|
import { interopDefault } from 'mlly';
|
|
9
12
|
import jiti from 'jiti';
|
|
10
|
-
import { globby } from 'globby';
|
|
11
13
|
import ignore from 'ignore';
|
|
12
14
|
import defu from 'defu';
|
|
13
15
|
import { applyDefaults } from 'untyped';
|
|
14
16
|
import lodashTemplate from 'lodash.template';
|
|
15
|
-
import {
|
|
16
|
-
import { genDynamicImport, genImport } from 'knitwork';
|
|
17
|
+
import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
|
|
17
18
|
import { loadConfig } from 'c12';
|
|
18
19
|
import { NuxtConfigSchema } from '@nuxt/schema';
|
|
19
20
|
import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
|
|
20
21
|
|
|
21
|
-
const logger = consola;
|
|
22
|
-
function useLogger(scope) {
|
|
23
|
-
return scope ? logger.withScope(scope) : logger;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
22
|
function chainFn(base, fn) {
|
|
27
23
|
if (typeof fn !== "function") {
|
|
28
24
|
return base;
|
|
@@ -35,7 +31,11 @@ function chainFn(base, fn) {
|
|
|
35
31
|
if (baseResult === void 0) {
|
|
36
32
|
[baseResult] = args;
|
|
37
33
|
}
|
|
38
|
-
const fnResult = fn.call(
|
|
34
|
+
const fnResult = fn.call(
|
|
35
|
+
this,
|
|
36
|
+
baseResult,
|
|
37
|
+
...Array.prototype.slice.call(args, 1)
|
|
38
|
+
);
|
|
39
39
|
if (fnResult === void 0) {
|
|
40
40
|
return baseResult;
|
|
41
41
|
}
|
|
@@ -45,14 +45,14 @@ function chainFn(base, fn) {
|
|
|
45
45
|
|
|
46
46
|
const nuxtCtx = getContext("nuxt");
|
|
47
47
|
function useNuxt() {
|
|
48
|
-
const instance = nuxtCtx.
|
|
48
|
+
const instance = nuxtCtx.tryUse();
|
|
49
49
|
if (!instance) {
|
|
50
50
|
throw new Error("Nuxt instance is unavailable!");
|
|
51
51
|
}
|
|
52
52
|
return instance;
|
|
53
53
|
}
|
|
54
54
|
function tryUseNuxt() {
|
|
55
|
-
return nuxtCtx.
|
|
55
|
+
return nuxtCtx.tryUse();
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function addTemplate(_template) {
|
|
@@ -96,16 +96,12 @@ function normalizeTemplate(template) {
|
|
|
96
96
|
return template;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
function addServerMiddleware(middleware) {
|
|
100
|
-
useNuxt().options.serverMiddleware.push(middleware);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
99
|
async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
104
100
|
const issues = [];
|
|
105
101
|
if (constraints.nuxt) {
|
|
106
102
|
const nuxtVersion = getNuxtVersion(nuxt);
|
|
107
|
-
const nuxtSemanticVersion = nuxtVersion.
|
|
108
|
-
if (!satisfies(nuxtSemanticVersion, constraints.nuxt)) {
|
|
103
|
+
const nuxtSemanticVersion = nuxtVersion.replace(/-[0-9]+\.[0-9a-f]{7,8}/, "");
|
|
104
|
+
if (!satisfies(nuxtSemanticVersion, constraints.nuxt, { includePrerelease: true })) {
|
|
109
105
|
issues.push({
|
|
110
106
|
name: "nuxt",
|
|
111
107
|
message: `Nuxt version \`${constraints.nuxt}\` is required but currently using \`${nuxtVersion}\``
|
|
@@ -113,7 +109,7 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
111
|
if (isNuxt2(nuxt)) {
|
|
116
|
-
const bridgeRequirement = constraints
|
|
112
|
+
const bridgeRequirement = constraints.bridge;
|
|
117
113
|
const hasBridge = !!nuxt.options.bridge;
|
|
118
114
|
if (bridgeRequirement === true && !hasBridge) {
|
|
119
115
|
issues.push({
|
|
@@ -151,43 +147,65 @@ function isNuxt3(nuxt = useNuxt()) {
|
|
|
151
147
|
function getNuxtVersion(nuxt = useNuxt()) {
|
|
152
148
|
const version = (nuxt?._version || nuxt?.version || nuxt?.constructor?.version || "").replace(/^v/g, "");
|
|
153
149
|
if (!version) {
|
|
154
|
-
throw new Error("Cannot determine nuxt version! Is
|
|
150
|
+
throw new Error("Cannot determine nuxt version! Is current instance passed?");
|
|
155
151
|
}
|
|
156
152
|
return version;
|
|
157
153
|
}
|
|
158
154
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
} else {
|
|
163
|
-
plugin = { ...plugin };
|
|
164
|
-
}
|
|
165
|
-
if (!plugin.src) {
|
|
166
|
-
throw new Error("Invalid plugin. src option is required: " + JSON.stringify(plugin));
|
|
167
|
-
}
|
|
168
|
-
plugin.src = normalize(plugin.src);
|
|
169
|
-
if (plugin.ssr) {
|
|
170
|
-
plugin.mode = "server";
|
|
171
|
-
}
|
|
172
|
-
if (!plugin.mode) {
|
|
173
|
-
const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
|
|
174
|
-
plugin.mode = mode;
|
|
175
|
-
}
|
|
176
|
-
return plugin;
|
|
155
|
+
const logger = consola;
|
|
156
|
+
function useLogger(scope) {
|
|
157
|
+
return scope ? logger.withScope(scope) : logger;
|
|
177
158
|
}
|
|
178
|
-
|
|
159
|
+
|
|
160
|
+
function addLayout(template, name) {
|
|
179
161
|
const nuxt = useNuxt();
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
162
|
+
const { filename, src } = addTemplate(template);
|
|
163
|
+
const layoutName = kebabCase(name || parse(filename).name).replace(/["']/g, "");
|
|
164
|
+
if (isNuxt2(nuxt)) {
|
|
165
|
+
const layout = nuxt.options.layouts[layoutName];
|
|
166
|
+
if (layout) {
|
|
167
|
+
return logger.warn(
|
|
168
|
+
`Not overriding \`${layoutName}\` (provided by \`${layout}\`) with \`${src || filename}\`.`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
nuxt.options.layouts[layoutName] = `./${filename}`;
|
|
172
|
+
if (name === "error") {
|
|
173
|
+
this.addErrorLayout(filename);
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
nuxt.hook("app:templates", (app) => {
|
|
178
|
+
if (layoutName in app.layouts) {
|
|
179
|
+
const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName].file);
|
|
180
|
+
return logger.warn(
|
|
181
|
+
`Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
app.layouts[layoutName] = {
|
|
185
|
+
file: join("#build", filename),
|
|
186
|
+
name: layoutName
|
|
187
|
+
};
|
|
188
|
+
});
|
|
184
189
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
|
|
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);
|
|
188
206
|
}
|
|
189
207
|
|
|
190
|
-
const _require = jiti(process.cwd(), { interopDefault: true });
|
|
208
|
+
const _require = jiti(process.cwd(), { interopDefault: true, esmResolve: true });
|
|
191
209
|
function isNodeModules(id) {
|
|
192
210
|
return /[/\\]node_modules[/\\]/.test(id);
|
|
193
211
|
}
|
|
@@ -234,14 +252,19 @@ function requireModulePkg(id, opts = {}) {
|
|
|
234
252
|
}
|
|
235
253
|
function resolveModule(id, opts = {}) {
|
|
236
254
|
return normalize(_require.resolve(id, {
|
|
237
|
-
paths: [].concat(
|
|
255
|
+
paths: [].concat(
|
|
256
|
+
global.__NUXT_PREPATHS__,
|
|
257
|
+
opts.paths || [],
|
|
258
|
+
process.cwd(),
|
|
259
|
+
global.__NUXT_PATHS__
|
|
260
|
+
).filter(Boolean)
|
|
238
261
|
}));
|
|
239
262
|
}
|
|
240
263
|
function tryResolveModule(path, opts = {}) {
|
|
241
264
|
try {
|
|
242
265
|
return resolveModule(path, opts);
|
|
243
266
|
} catch (error) {
|
|
244
|
-
if (error
|
|
267
|
+
if (error?.code !== "MODULE_NOT_FOUND") {
|
|
245
268
|
throw error;
|
|
246
269
|
}
|
|
247
270
|
}
|
|
@@ -278,7 +301,7 @@ function tryRequireModule(id, opts = {}) {
|
|
|
278
301
|
function isIgnored(pathname) {
|
|
279
302
|
const nuxt = tryUseNuxt();
|
|
280
303
|
if (!nuxt) {
|
|
281
|
-
return
|
|
304
|
+
return false;
|
|
282
305
|
}
|
|
283
306
|
if (!nuxt._ignore) {
|
|
284
307
|
nuxt._ignore = ignore(nuxt.options.ignoreOptions);
|
|
@@ -292,13 +315,13 @@ function isIgnored(pathname) {
|
|
|
292
315
|
if (relativePath.startsWith("..")) {
|
|
293
316
|
return false;
|
|
294
317
|
}
|
|
295
|
-
return relativePath && nuxt._ignore.ignores(relativePath);
|
|
318
|
+
return !!(relativePath && nuxt._ignore.ignores(relativePath));
|
|
296
319
|
}
|
|
297
320
|
|
|
298
321
|
async function resolvePath(path, opts = {}) {
|
|
299
322
|
const _path = path;
|
|
300
323
|
path = normalize(path);
|
|
301
|
-
if (isAbsolute(path) && existsSync(path)) {
|
|
324
|
+
if (isAbsolute(path) && existsSync(path) && !await isDirectory(path)) {
|
|
302
325
|
return path;
|
|
303
326
|
}
|
|
304
327
|
const nuxt = useNuxt();
|
|
@@ -309,10 +332,10 @@ async function resolvePath(path, opts = {}) {
|
|
|
309
332
|
if (!isAbsolute(path)) {
|
|
310
333
|
path = resolve(cwd, path);
|
|
311
334
|
}
|
|
312
|
-
let
|
|
335
|
+
let _isDir = false;
|
|
313
336
|
if (existsSync(path)) {
|
|
314
|
-
|
|
315
|
-
if (!
|
|
337
|
+
_isDir = await isDirectory(path);
|
|
338
|
+
if (!_isDir) {
|
|
316
339
|
return path;
|
|
317
340
|
}
|
|
318
341
|
}
|
|
@@ -322,7 +345,7 @@ async function resolvePath(path, opts = {}) {
|
|
|
322
345
|
return pathWithExt;
|
|
323
346
|
}
|
|
324
347
|
const pathWithIndex = join(path, "index" + ext);
|
|
325
|
-
if (
|
|
348
|
+
if (_isDir && existsSync(pathWithIndex)) {
|
|
326
349
|
return pathWithIndex;
|
|
327
350
|
}
|
|
328
351
|
}
|
|
@@ -339,8 +362,8 @@ async function findPath(paths, opts, pathType = "file") {
|
|
|
339
362
|
for (const path of paths) {
|
|
340
363
|
const rPath = await resolvePath(path, opts);
|
|
341
364
|
if (await existsSensitive(rPath)) {
|
|
342
|
-
const
|
|
343
|
-
if (!pathType || pathType === "file" && !
|
|
365
|
+
const _isDir = await isDirectory(rPath);
|
|
366
|
+
if (!pathType || pathType === "file" && !_isDir || pathType === "dir" && _isDir) {
|
|
344
367
|
return rPath;
|
|
345
368
|
}
|
|
346
369
|
}
|
|
@@ -351,7 +374,7 @@ function resolveAlias(path, alias) {
|
|
|
351
374
|
if (!alias) {
|
|
352
375
|
alias = tryUseNuxt()?.options.alias || {};
|
|
353
376
|
}
|
|
354
|
-
for (const key in alias) {
|
|
377
|
+
for (const key in normalizeAliases(alias)) {
|
|
355
378
|
if (key === "@" && !path.startsWith("@/")) {
|
|
356
379
|
continue;
|
|
357
380
|
}
|
|
@@ -381,15 +404,53 @@ async function existsSensitive(path) {
|
|
|
381
404
|
const dirFiles = await promises.readdir(dirname(path));
|
|
382
405
|
return dirFiles.includes(basename(path));
|
|
383
406
|
}
|
|
384
|
-
async function
|
|
385
|
-
|
|
386
|
-
|
|
407
|
+
async function isDirectory(path) {
|
|
408
|
+
return (await promises.lstat(path)).isDirectory();
|
|
409
|
+
}
|
|
410
|
+
async function resolveFiles(path, pattern, opts = {}) {
|
|
411
|
+
const files = await globby(pattern, { cwd: path, followSymbolicLinks: opts.followSymbolicLinks ?? true });
|
|
412
|
+
return files.map((p) => resolve(path, p)).filter((p) => !isIgnored(p)).sort();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function normalizePlugin(plugin) {
|
|
416
|
+
if (typeof plugin === "string") {
|
|
417
|
+
plugin = { src: plugin };
|
|
418
|
+
} else {
|
|
419
|
+
plugin = { ...plugin };
|
|
420
|
+
}
|
|
421
|
+
if (!plugin.src) {
|
|
422
|
+
throw new Error("Invalid plugin. src option is required: " + JSON.stringify(plugin));
|
|
423
|
+
}
|
|
424
|
+
plugin.src = normalize(resolveAlias(plugin.src));
|
|
425
|
+
if (plugin.ssr) {
|
|
426
|
+
plugin.mode = "server";
|
|
427
|
+
}
|
|
428
|
+
if (!plugin.mode) {
|
|
429
|
+
const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
|
|
430
|
+
plugin.mode = mode;
|
|
431
|
+
}
|
|
432
|
+
return plugin;
|
|
433
|
+
}
|
|
434
|
+
function addPlugin(_plugin, opts = {}) {
|
|
435
|
+
const nuxt = useNuxt();
|
|
436
|
+
const plugin = normalizePlugin(_plugin);
|
|
437
|
+
nuxt.options.plugins = nuxt.options.plugins.filter((p) => normalizePlugin(p).src !== plugin.src);
|
|
438
|
+
nuxt.options.plugins[opts.append ? "push" : "unshift"](plugin);
|
|
439
|
+
return plugin;
|
|
440
|
+
}
|
|
441
|
+
function addPluginTemplate(plugin, opts = {}) {
|
|
442
|
+
const normalizedPlugin = typeof plugin === "string" ? { src: plugin } : { ...plugin, src: addTemplate(plugin).dst };
|
|
443
|
+
return addPlugin(normalizedPlugin, opts);
|
|
387
444
|
}
|
|
388
445
|
|
|
389
446
|
async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
|
|
390
447
|
const nuxt = useNuxt();
|
|
391
448
|
const { nuxtModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions);
|
|
392
|
-
await nuxtModule.call(
|
|
449
|
+
await nuxtModule.call(
|
|
450
|
+
useModuleContainer(),
|
|
451
|
+
inlineOptions,
|
|
452
|
+
nuxt
|
|
453
|
+
);
|
|
393
454
|
nuxt.options._installedModules = nuxt.options._installedModules || [];
|
|
394
455
|
nuxt.options._installedModules.push({
|
|
395
456
|
meta: await nuxtModule.getMeta?.(),
|
|
@@ -436,7 +497,7 @@ function useModuleContainer(nuxt = useNuxt()) {
|
|
|
436
497
|
}
|
|
437
498
|
await installModule(src, inlineOptions);
|
|
438
499
|
}
|
|
439
|
-
|
|
500
|
+
const container = {
|
|
440
501
|
nuxt,
|
|
441
502
|
options: nuxt.options,
|
|
442
503
|
ready() {
|
|
@@ -460,16 +521,7 @@ function useModuleContainer(nuxt = useNuxt()) {
|
|
|
460
521
|
return addPluginTemplate(pluginTemplate);
|
|
461
522
|
},
|
|
462
523
|
addLayout(tmpl, name) {
|
|
463
|
-
|
|
464
|
-
const layoutName = name || parse(src).name;
|
|
465
|
-
const layout = nuxt.options.layouts[layoutName];
|
|
466
|
-
if (layout) {
|
|
467
|
-
logger.warn(`Duplicate layout registration, "${layoutName}" has been registered as "${layout}"`);
|
|
468
|
-
}
|
|
469
|
-
nuxt.options.layouts[layoutName] = `./${filename}`;
|
|
470
|
-
if (name === "error") {
|
|
471
|
-
this.addErrorLayout(filename);
|
|
472
|
-
}
|
|
524
|
+
return addLayout(tmpl, name);
|
|
473
525
|
},
|
|
474
526
|
addErrorLayout(dst) {
|
|
475
527
|
const relativeBuildDir = relative(nuxt.options.rootDir, nuxt.options.buildDir);
|
|
@@ -494,6 +546,7 @@ function useModuleContainer(nuxt = useNuxt()) {
|
|
|
494
546
|
}
|
|
495
547
|
}
|
|
496
548
|
};
|
|
549
|
+
nuxt[MODULE_CONTAINER_KEY] = container;
|
|
497
550
|
return nuxt[MODULE_CONTAINER_KEY];
|
|
498
551
|
}
|
|
499
552
|
|
|
@@ -514,18 +567,18 @@ async function compileTemplate(template, ctx) {
|
|
|
514
567
|
throw new Error("Invalid template: " + JSON.stringify(template));
|
|
515
568
|
}
|
|
516
569
|
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
570
|
const importSources = (sources, { lazy = false } = {}) => {
|
|
519
571
|
if (!Array.isArray(sources)) {
|
|
520
572
|
sources = [sources];
|
|
521
573
|
}
|
|
522
574
|
return sources.map((src) => {
|
|
523
575
|
if (lazy) {
|
|
524
|
-
return `const ${
|
|
576
|
+
return `const ${genSafeVariableName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
|
|
525
577
|
}
|
|
526
|
-
return genImport(src,
|
|
578
|
+
return genImport(src, genSafeVariableName(src));
|
|
527
579
|
}).join("\n");
|
|
528
580
|
};
|
|
581
|
+
const importName = genSafeVariableName;
|
|
529
582
|
const templateUtils = { serialize, importName, importSources };
|
|
530
583
|
|
|
531
584
|
function defineNuxtModule(definition) {
|
|
@@ -538,14 +591,14 @@ function defineNuxtModule(definition) {
|
|
|
538
591
|
}
|
|
539
592
|
if (!definition.meta.configKey) {
|
|
540
593
|
definition.meta.name = definition.meta.name || definition.name;
|
|
541
|
-
definition.meta.configKey = definition.
|
|
594
|
+
definition.meta.configKey = definition.configKey || definition.meta.name;
|
|
542
595
|
}
|
|
543
|
-
function getOptions(inlineOptions, nuxt = useNuxt()) {
|
|
596
|
+
async function getOptions(inlineOptions, nuxt = useNuxt()) {
|
|
544
597
|
const configKey = definition.meta.configKey || definition.meta.name;
|
|
545
598
|
const _defaults = definition.defaults instanceof Function ? definition.defaults(nuxt) : definition.defaults;
|
|
546
599
|
let _options = defu(inlineOptions, nuxt.options[configKey], _defaults);
|
|
547
600
|
if (definition.schema) {
|
|
548
|
-
_options = applyDefaults(definition.schema, _options);
|
|
601
|
+
_options = await applyDefaults(definition.schema, _options);
|
|
549
602
|
}
|
|
550
603
|
return Promise.resolve(_options);
|
|
551
604
|
}
|
|
@@ -587,7 +640,7 @@ function nuxt2Shims(nuxt) {
|
|
|
587
640
|
}
|
|
588
641
|
nuxt[NUXT2_SHIMS_KEY] = true;
|
|
589
642
|
nuxt.hooks = nuxt;
|
|
590
|
-
if (!nuxtCtx.
|
|
643
|
+
if (!nuxtCtx.tryUse()) {
|
|
591
644
|
nuxtCtx.set(nuxt);
|
|
592
645
|
nuxt.hook("close", () => nuxtCtx.unset());
|
|
593
646
|
}
|
|
@@ -622,23 +675,38 @@ function nuxt2Shims(nuxt) {
|
|
|
622
675
|
}
|
|
623
676
|
|
|
624
677
|
async function loadNuxtConfig(opts) {
|
|
625
|
-
|
|
678
|
+
globalThis.defineNuxtConfig = (c) => c;
|
|
679
|
+
const result = await loadConfig({
|
|
626
680
|
name: "nuxt",
|
|
627
681
|
configFile: "nuxt.config",
|
|
628
682
|
rcFile: ".nuxtrc",
|
|
683
|
+
extend: { extendKey: ["theme", "extends"] },
|
|
629
684
|
dotenv: true,
|
|
630
685
|
globalRc: true,
|
|
631
686
|
...opts
|
|
632
687
|
});
|
|
688
|
+
delete globalThis.defineNuxtConfig;
|
|
689
|
+
const { configFile, layers = [], cwd } = result;
|
|
690
|
+
const nuxtConfig = result.config;
|
|
633
691
|
nuxtConfig.rootDir = nuxtConfig.rootDir || cwd;
|
|
634
692
|
nuxtConfig._nuxtConfigFile = configFile;
|
|
635
693
|
nuxtConfig._nuxtConfigFiles = [configFile];
|
|
636
694
|
for (const layer of layers) {
|
|
695
|
+
layer.config = layer.config || {};
|
|
637
696
|
layer.config.rootDir = layer.config.rootDir ?? layer.cwd;
|
|
638
697
|
layer.config.srcDir = resolve(layer.config.rootDir, layer.config.srcDir);
|
|
639
698
|
}
|
|
640
699
|
nuxtConfig._layers = layers.filter((layer) => layer.configFile && !layer.configFile.endsWith(".nuxtrc"));
|
|
641
|
-
|
|
700
|
+
if (!nuxtConfig._layers.length) {
|
|
701
|
+
nuxtConfig._layers.push({
|
|
702
|
+
cwd,
|
|
703
|
+
config: {
|
|
704
|
+
rootDir: cwd,
|
|
705
|
+
srcDir: cwd
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
return await applyDefaults(NuxtConfigSchema, nuxtConfig);
|
|
642
710
|
}
|
|
643
711
|
|
|
644
712
|
async function loadNuxt(opts) {
|
|
@@ -677,19 +745,29 @@ async function buildNuxt(nuxt) {
|
|
|
677
745
|
return build(nuxt);
|
|
678
746
|
}
|
|
679
747
|
|
|
680
|
-
function
|
|
748
|
+
function addImports(imports) {
|
|
681
749
|
assertNuxtCompatibility({ bridge: true });
|
|
682
|
-
useNuxt().hook("autoImports:extend", (
|
|
683
|
-
|
|
684
|
-
});
|
|
750
|
+
useNuxt().hook("autoImports:extend", (_imports) => {
|
|
751
|
+
_imports.push(...Array.isArray(imports) ? imports : [imports]);
|
|
752
|
+
}, { allowDeprecated: true });
|
|
685
753
|
}
|
|
686
|
-
|
|
754
|
+
const addAutoImport = addImports;
|
|
755
|
+
function addImportsDir(dirs) {
|
|
687
756
|
assertNuxtCompatibility({ bridge: true });
|
|
688
|
-
useNuxt().hook("autoImports:dirs", (
|
|
689
|
-
for (const dir of Array.isArray(
|
|
690
|
-
|
|
757
|
+
useNuxt().hook("autoImports:dirs", (_dirs) => {
|
|
758
|
+
for (const dir of Array.isArray(dirs) ? dirs : [dirs]) {
|
|
759
|
+
_dirs.push(dir);
|
|
691
760
|
}
|
|
692
|
-
});
|
|
761
|
+
}, { allowDeprecated: true });
|
|
762
|
+
}
|
|
763
|
+
const addAutoImportDir = addImportsDir;
|
|
764
|
+
function addImportsSources(presets) {
|
|
765
|
+
assertNuxtCompatibility({ bridge: true });
|
|
766
|
+
useNuxt().hook("autoImports:sources", (_presets) => {
|
|
767
|
+
for (const preset of Array.isArray(presets) ? presets : [presets]) {
|
|
768
|
+
_presets.push(preset);
|
|
769
|
+
}
|
|
770
|
+
}, { allowDeprecated: true });
|
|
693
771
|
}
|
|
694
772
|
|
|
695
773
|
function extendWebpackConfig(fn, options = {}) {
|
|
@@ -729,7 +807,17 @@ function extendViteConfig(fn, options = {}) {
|
|
|
729
807
|
if (options.build === false && nuxt.options.build) {
|
|
730
808
|
return;
|
|
731
809
|
}
|
|
732
|
-
|
|
810
|
+
if (options.server !== false && options.client !== false) {
|
|
811
|
+
return nuxt.hook("vite:extend", ({ config }) => fn(config));
|
|
812
|
+
}
|
|
813
|
+
nuxt.hook("vite:extendConfig", (config, { isClient, isServer }) => {
|
|
814
|
+
if (options.server !== false && isServer) {
|
|
815
|
+
return fn(config);
|
|
816
|
+
}
|
|
817
|
+
if (options.client !== false && isClient) {
|
|
818
|
+
return fn(config);
|
|
819
|
+
}
|
|
820
|
+
});
|
|
733
821
|
}
|
|
734
822
|
function addWebpackPlugin(plugin, options) {
|
|
735
823
|
extendWebpackConfig((config) => {
|
|
@@ -773,7 +861,7 @@ async function addComponent(opts) {
|
|
|
773
861
|
...opts
|
|
774
862
|
};
|
|
775
863
|
nuxt.hook("components:extend", (components) => {
|
|
776
|
-
const existingComponent = components.find((c) => c.pascalName === component.pascalName || c.kebabName === component.kebabName);
|
|
864
|
+
const existingComponent = components.find((c) => (c.pascalName === component.pascalName || c.kebabName === component.kebabName) && c.mode === component.mode);
|
|
777
865
|
if (existingComponent) {
|
|
778
866
|
const name = existingComponent.pascalName || existingComponent.kebabName;
|
|
779
867
|
console.warn(`Overriding ${name} component.`);
|
|
@@ -793,4 +881,4 @@ function extendPages(cb) {
|
|
|
793
881
|
}
|
|
794
882
|
}
|
|
795
883
|
|
|
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 };
|
|
884
|
+
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, useNuxt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/kit",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.10",
|
|
4
4
|
"repository": "nuxt/framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,24 +13,24 @@
|
|
|
13
13
|
"prepack": "unbuild"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@nuxt/schema": "3.0.0-rc.
|
|
17
|
-
"c12": "^0.2.
|
|
16
|
+
"@nuxt/schema": "3.0.0-rc.10",
|
|
17
|
+
"c12": "^0.2.12",
|
|
18
18
|
"consola": "^2.15.3",
|
|
19
|
-
"defu": "^6.
|
|
20
|
-
"globby": "^13.1.
|
|
19
|
+
"defu": "^6.1.0",
|
|
20
|
+
"globby": "^13.1.2",
|
|
21
21
|
"hash-sum": "^2.0.0",
|
|
22
22
|
"ignore": "^5.2.0",
|
|
23
|
-
"jiti": "^1.
|
|
24
|
-
"knitwork": "^0.1.
|
|
23
|
+
"jiti": "^1.15.0",
|
|
24
|
+
"knitwork": "^0.1.2",
|
|
25
25
|
"lodash.template": "^4.5.0",
|
|
26
|
-
"mlly": "^0.5.
|
|
27
|
-
"pathe": "^0.
|
|
28
|
-
"pkg-types": "^0.3.
|
|
29
|
-
"scule": "^0.2
|
|
26
|
+
"mlly": "^0.5.14",
|
|
27
|
+
"pathe": "^0.3.7",
|
|
28
|
+
"pkg-types": "^0.3.5",
|
|
29
|
+
"scule": "^0.3.2",
|
|
30
30
|
"semver": "^7.3.7",
|
|
31
|
-
"unctx": "^
|
|
32
|
-
"unimport": "^0.
|
|
33
|
-
"untyped": "^0.
|
|
31
|
+
"unctx": "^2.0.2",
|
|
32
|
+
"unimport": "^0.6.7",
|
|
33
|
+
"untyped": "^0.5.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/lodash.template": "^4",
|