@nuxt/kit 3.0.0-rc.6 → 3.0.0-rc.9
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 +24 -13
- package/dist/index.mjs +102 -73
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Nuxt, ModuleContainer, ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, NuxtOptions, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtTemplate, NuxtHooks, NuxtPlugin, NuxtPluginTemplate } from '@nuxt/schema';
|
|
1
|
+
import { Nuxt, ModuleContainer, ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, NuxtOptions, 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';
|
|
@@ -37,8 +37,16 @@ interface LoadNuxtOptions extends LoadNuxtConfigOptions {
|
|
|
37
37
|
declare function loadNuxt(opts: LoadNuxtOptions): Promise<Nuxt>;
|
|
38
38
|
declare function buildNuxt(nuxt: Nuxt): Promise<any>;
|
|
39
39
|
|
|
40
|
-
declare function
|
|
41
|
-
|
|
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;
|
|
42
50
|
|
|
43
51
|
interface ExtendConfigOptions {
|
|
44
52
|
/**
|
|
@@ -87,7 +95,7 @@ declare function extendWebpackConfig(fn: ((config: Configuration) => void), opti
|
|
|
87
95
|
/**
|
|
88
96
|
* Extend Vite config
|
|
89
97
|
*/
|
|
90
|
-
declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): () => void;
|
|
98
|
+
declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): (() => void) | undefined;
|
|
91
99
|
/**
|
|
92
100
|
* Append Webpack plugin to the config.
|
|
93
101
|
*/
|
|
@@ -172,7 +180,7 @@ declare function tryUseNuxt(): Nuxt | null;
|
|
|
172
180
|
*/
|
|
173
181
|
declare function isIgnored(pathname: string): boolean;
|
|
174
182
|
|
|
175
|
-
declare function addLayout(
|
|
183
|
+
declare function addLayout(this: any, template: NuxtTemplate, name?: string): void;
|
|
176
184
|
|
|
177
185
|
declare function extendPages(cb: NuxtHooks['pages:extend']): void;
|
|
178
186
|
|
|
@@ -228,14 +236,16 @@ declare function findPath(paths: string | string[], opts?: ResolvePathOptions, p
|
|
|
228
236
|
*/
|
|
229
237
|
declare function resolveAlias(path: string, alias?: Record<string, string>): string;
|
|
230
238
|
interface Resolver {
|
|
231
|
-
resolve(...path:
|
|
239
|
+
resolve(...path: string[]): string;
|
|
232
240
|
resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
|
|
233
241
|
}
|
|
234
242
|
/**
|
|
235
243
|
* Create a relative resolver
|
|
236
244
|
*/
|
|
237
245
|
declare function createResolver(base: string | URL): Resolver;
|
|
238
|
-
declare function resolveFiles(path: string, pattern: string | string[]
|
|
246
|
+
declare function resolveFiles(path: string, pattern: string | string[], opts?: {
|
|
247
|
+
followSymbolicLinks?: boolean;
|
|
248
|
+
}): Promise<string[]>;
|
|
239
249
|
|
|
240
250
|
interface LegacyServerMiddleware {
|
|
241
251
|
route?: string;
|
|
@@ -263,11 +273,11 @@ declare function addDevServerHandler(handler: NitroDevEventHandler): void;
|
|
|
263
273
|
/**
|
|
264
274
|
* Renders given template using lodash template during build into the project buildDir
|
|
265
275
|
*/
|
|
266
|
-
declare function addTemplate(_template: NuxtTemplate | string):
|
|
276
|
+
declare function addTemplate(_template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
|
|
267
277
|
/**
|
|
268
278
|
* Normalize a nuxt template object
|
|
269
279
|
*/
|
|
270
|
-
declare function normalizeTemplate(template: NuxtTemplate | string):
|
|
280
|
+
declare function normalizeTemplate(template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
|
|
271
281
|
|
|
272
282
|
declare const logger: consola.Consola;
|
|
273
283
|
declare function useLogger(scope?: string): consola.Consola;
|
|
@@ -285,7 +295,7 @@ declare function isNodeModules(id: string): boolean;
|
|
|
285
295
|
declare function clearRequireCache(id: string): void;
|
|
286
296
|
declare function scanRequireTree(id: string, files?: Set<string>): Set<string>;
|
|
287
297
|
/** Access the require cache by module id. */
|
|
288
|
-
declare function getRequireCacheItem(id: string): NodeModule;
|
|
298
|
+
declare function getRequireCacheItem(id: string): NodeModule | undefined;
|
|
289
299
|
/** Resolve the `package.json` file for a given module. */
|
|
290
300
|
declare function requireModulePkg(id: string, opts?: RequireModuleOptions): any;
|
|
291
301
|
/** Resolve the path of a module. */
|
|
@@ -295,17 +305,18 @@ declare function tryResolveModule(path: string, opts?: ResolveModuleOptions): st
|
|
|
295
305
|
/** Require a module and return it. */
|
|
296
306
|
declare function requireModule(id: string, opts?: RequireModuleOptions): any;
|
|
297
307
|
declare function importModule(id: string, opts?: RequireModuleOptions): Promise<any>;
|
|
298
|
-
declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any
|
|
308
|
+
declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any> | undefined;
|
|
299
309
|
/** Try to require a module, but don't emit an error if the module can't be required. */
|
|
300
310
|
declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
|
|
301
311
|
|
|
302
312
|
declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
|
|
313
|
+
/** @deprecated */
|
|
303
314
|
declare const templateUtils: {
|
|
304
315
|
serialize: (data: any) => string;
|
|
305
316
|
importName: typeof genSafeVariableName;
|
|
306
317
|
importSources: (sources: string | string[], { lazy }?: {
|
|
307
|
-
lazy?: boolean;
|
|
318
|
+
lazy?: boolean | undefined;
|
|
308
319
|
}) => string;
|
|
309
320
|
};
|
|
310
321
|
|
|
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 };
|
|
322
|
+
export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LegacyServerMiddleware, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, 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
|
@@ -6,9 +6,10 @@ import { kebabCase, pascalCase } from 'scule';
|
|
|
6
6
|
import satisfies from 'semver/functions/satisfies.js';
|
|
7
7
|
import consola from 'consola';
|
|
8
8
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
9
|
+
import { globby } from 'globby';
|
|
10
|
+
import { normalizeAliases } from 'pathe/utils';
|
|
9
11
|
import { interopDefault } from 'mlly';
|
|
10
12
|
import jiti from 'jiti';
|
|
11
|
-
import { globby } from 'globby';
|
|
12
13
|
import ignore from 'ignore';
|
|
13
14
|
import defu from 'defu';
|
|
14
15
|
import { applyDefaults } from 'untyped';
|
|
@@ -30,7 +31,11 @@ function chainFn(base, fn) {
|
|
|
30
31
|
if (baseResult === void 0) {
|
|
31
32
|
[baseResult] = args;
|
|
32
33
|
}
|
|
33
|
-
const fnResult = fn.call(
|
|
34
|
+
const fnResult = fn.call(
|
|
35
|
+
this,
|
|
36
|
+
baseResult,
|
|
37
|
+
...Array.prototype.slice.call(args, 1)
|
|
38
|
+
);
|
|
34
39
|
if (fnResult === void 0) {
|
|
35
40
|
return baseResult;
|
|
36
41
|
}
|
|
@@ -40,14 +45,14 @@ function chainFn(base, fn) {
|
|
|
40
45
|
|
|
41
46
|
const nuxtCtx = getContext("nuxt");
|
|
42
47
|
function useNuxt() {
|
|
43
|
-
const instance = nuxtCtx.
|
|
48
|
+
const instance = nuxtCtx.tryUse();
|
|
44
49
|
if (!instance) {
|
|
45
50
|
throw new Error("Nuxt instance is unavailable!");
|
|
46
51
|
}
|
|
47
52
|
return instance;
|
|
48
53
|
}
|
|
49
54
|
function tryUseNuxt() {
|
|
50
|
-
return nuxtCtx.
|
|
55
|
+
return nuxtCtx.tryUse();
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
function addTemplate(_template) {
|
|
@@ -95,8 +100,8 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
|
95
100
|
const issues = [];
|
|
96
101
|
if (constraints.nuxt) {
|
|
97
102
|
const nuxtVersion = getNuxtVersion(nuxt);
|
|
98
|
-
const nuxtSemanticVersion = nuxtVersion.
|
|
99
|
-
if (!satisfies(nuxtSemanticVersion, constraints.nuxt)) {
|
|
103
|
+
const nuxtSemanticVersion = nuxtVersion.replace(/-[0-9]+\.[0-9a-f]{7}/, "");
|
|
104
|
+
if (!satisfies(nuxtSemanticVersion, constraints.nuxt, { includePrerelease: true })) {
|
|
100
105
|
issues.push({
|
|
101
106
|
name: "nuxt",
|
|
102
107
|
message: `Nuxt version \`${constraints.nuxt}\` is required but currently using \`${nuxtVersion}\``
|
|
@@ -152,14 +157,16 @@ function useLogger(scope) {
|
|
|
152
157
|
return scope ? logger.withScope(scope) : logger;
|
|
153
158
|
}
|
|
154
159
|
|
|
155
|
-
function addLayout(
|
|
160
|
+
function addLayout(template, name) {
|
|
156
161
|
const nuxt = useNuxt();
|
|
157
|
-
const { filename, src } = addTemplate(
|
|
158
|
-
const layoutName = kebabCase(name || parse(
|
|
162
|
+
const { filename, src } = addTemplate(template);
|
|
163
|
+
const layoutName = kebabCase(name || parse(filename).name).replace(/["']/g, "");
|
|
159
164
|
if (isNuxt2(nuxt)) {
|
|
160
165
|
const layout = nuxt.options.layouts[layoutName];
|
|
161
166
|
if (layout) {
|
|
162
|
-
return logger.warn(
|
|
167
|
+
return logger.warn(
|
|
168
|
+
`Not overriding \`${layoutName}\` (provided by \`${layout}\`) with \`${src || filename}\`.`
|
|
169
|
+
);
|
|
163
170
|
}
|
|
164
171
|
nuxt.options.layouts[layoutName] = `./${filename}`;
|
|
165
172
|
if (name === "error") {
|
|
@@ -170,7 +177,9 @@ function addLayout(tmpl, name) {
|
|
|
170
177
|
nuxt.hook("app:templates", (app) => {
|
|
171
178
|
if (layoutName in app.layouts) {
|
|
172
179
|
const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName].file);
|
|
173
|
-
return logger.warn(
|
|
180
|
+
return logger.warn(
|
|
181
|
+
`Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.`
|
|
182
|
+
);
|
|
174
183
|
}
|
|
175
184
|
app.layouts[layoutName] = {
|
|
176
185
|
file: join("#build", filename),
|
|
@@ -196,38 +205,7 @@ function addDevServerHandler(handler) {
|
|
|
196
205
|
useNuxt().options.devServerHandlers.push(handler);
|
|
197
206
|
}
|
|
198
207
|
|
|
199
|
-
|
|
200
|
-
if (typeof plugin === "string") {
|
|
201
|
-
plugin = { src: plugin };
|
|
202
|
-
} else {
|
|
203
|
-
plugin = { ...plugin };
|
|
204
|
-
}
|
|
205
|
-
if (!plugin.src) {
|
|
206
|
-
throw new Error("Invalid plugin. src option is required: " + JSON.stringify(plugin));
|
|
207
|
-
}
|
|
208
|
-
plugin.src = normalize(plugin.src);
|
|
209
|
-
if (plugin.ssr) {
|
|
210
|
-
plugin.mode = "server";
|
|
211
|
-
}
|
|
212
|
-
if (!plugin.mode) {
|
|
213
|
-
const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
|
|
214
|
-
plugin.mode = mode;
|
|
215
|
-
}
|
|
216
|
-
return plugin;
|
|
217
|
-
}
|
|
218
|
-
function addPlugin(_plugin, opts = {}) {
|
|
219
|
-
const nuxt = useNuxt();
|
|
220
|
-
const plugin = normalizePlugin(_plugin);
|
|
221
|
-
nuxt.options.plugins = nuxt.options.plugins.filter((p) => normalizePlugin(p).src !== plugin.src);
|
|
222
|
-
nuxt.options.plugins[opts.append ? "push" : "unshift"](plugin);
|
|
223
|
-
return plugin;
|
|
224
|
-
}
|
|
225
|
-
function addPluginTemplate(plugin, opts = {}) {
|
|
226
|
-
const normalizedPlugin = typeof plugin === "string" ? { src: plugin } : { ...plugin, src: addTemplate(plugin).dst };
|
|
227
|
-
return addPlugin(normalizedPlugin, opts);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const _require = jiti(process.cwd(), { interopDefault: true });
|
|
208
|
+
const _require = jiti(process.cwd(), { interopDefault: true, esmResolve: true });
|
|
231
209
|
function isNodeModules(id) {
|
|
232
210
|
return /[/\\]node_modules[/\\]/.test(id);
|
|
233
211
|
}
|
|
@@ -274,14 +252,19 @@ function requireModulePkg(id, opts = {}) {
|
|
|
274
252
|
}
|
|
275
253
|
function resolveModule(id, opts = {}) {
|
|
276
254
|
return normalize(_require.resolve(id, {
|
|
277
|
-
paths: [].concat(
|
|
255
|
+
paths: [].concat(
|
|
256
|
+
global.__NUXT_PREPATHS__,
|
|
257
|
+
opts.paths || [],
|
|
258
|
+
process.cwd(),
|
|
259
|
+
global.__NUXT_PATHS__
|
|
260
|
+
).filter(Boolean)
|
|
278
261
|
}));
|
|
279
262
|
}
|
|
280
263
|
function tryResolveModule(path, opts = {}) {
|
|
281
264
|
try {
|
|
282
265
|
return resolveModule(path, opts);
|
|
283
266
|
} catch (error) {
|
|
284
|
-
if (error
|
|
267
|
+
if (error?.code !== "MODULE_NOT_FOUND") {
|
|
285
268
|
throw error;
|
|
286
269
|
}
|
|
287
270
|
}
|
|
@@ -318,7 +301,7 @@ function tryRequireModule(id, opts = {}) {
|
|
|
318
301
|
function isIgnored(pathname) {
|
|
319
302
|
const nuxt = tryUseNuxt();
|
|
320
303
|
if (!nuxt) {
|
|
321
|
-
return
|
|
304
|
+
return false;
|
|
322
305
|
}
|
|
323
306
|
if (!nuxt._ignore) {
|
|
324
307
|
nuxt._ignore = ignore(nuxt.options.ignoreOptions);
|
|
@@ -332,13 +315,13 @@ function isIgnored(pathname) {
|
|
|
332
315
|
if (relativePath.startsWith("..")) {
|
|
333
316
|
return false;
|
|
334
317
|
}
|
|
335
|
-
return relativePath && nuxt._ignore.ignores(relativePath);
|
|
318
|
+
return !!(relativePath && nuxt._ignore.ignores(relativePath));
|
|
336
319
|
}
|
|
337
320
|
|
|
338
321
|
async function resolvePath(path, opts = {}) {
|
|
339
322
|
const _path = path;
|
|
340
323
|
path = normalize(path);
|
|
341
|
-
if (isAbsolute(path) && existsSync(path)) {
|
|
324
|
+
if (isAbsolute(path) && existsSync(path) && !await isDirectory(path)) {
|
|
342
325
|
return path;
|
|
343
326
|
}
|
|
344
327
|
const nuxt = useNuxt();
|
|
@@ -349,10 +332,10 @@ async function resolvePath(path, opts = {}) {
|
|
|
349
332
|
if (!isAbsolute(path)) {
|
|
350
333
|
path = resolve(cwd, path);
|
|
351
334
|
}
|
|
352
|
-
let
|
|
335
|
+
let _isDir = false;
|
|
353
336
|
if (existsSync(path)) {
|
|
354
|
-
|
|
355
|
-
if (!
|
|
337
|
+
_isDir = await isDirectory(path);
|
|
338
|
+
if (!_isDir) {
|
|
356
339
|
return path;
|
|
357
340
|
}
|
|
358
341
|
}
|
|
@@ -362,7 +345,7 @@ async function resolvePath(path, opts = {}) {
|
|
|
362
345
|
return pathWithExt;
|
|
363
346
|
}
|
|
364
347
|
const pathWithIndex = join(path, "index" + ext);
|
|
365
|
-
if (
|
|
348
|
+
if (_isDir && existsSync(pathWithIndex)) {
|
|
366
349
|
return pathWithIndex;
|
|
367
350
|
}
|
|
368
351
|
}
|
|
@@ -379,8 +362,8 @@ async function findPath(paths, opts, pathType = "file") {
|
|
|
379
362
|
for (const path of paths) {
|
|
380
363
|
const rPath = await resolvePath(path, opts);
|
|
381
364
|
if (await existsSensitive(rPath)) {
|
|
382
|
-
const
|
|
383
|
-
if (!pathType || pathType === "file" && !
|
|
365
|
+
const _isDir = await isDirectory(rPath);
|
|
366
|
+
if (!pathType || pathType === "file" && !_isDir || pathType === "dir" && _isDir) {
|
|
384
367
|
return rPath;
|
|
385
368
|
}
|
|
386
369
|
}
|
|
@@ -391,7 +374,7 @@ function resolveAlias(path, alias) {
|
|
|
391
374
|
if (!alias) {
|
|
392
375
|
alias = tryUseNuxt()?.options.alias || {};
|
|
393
376
|
}
|
|
394
|
-
for (const key in alias) {
|
|
377
|
+
for (const key in normalizeAliases(alias)) {
|
|
395
378
|
if (key === "@" && !path.startsWith("@/")) {
|
|
396
379
|
continue;
|
|
397
380
|
}
|
|
@@ -421,15 +404,53 @@ async function existsSensitive(path) {
|
|
|
421
404
|
const dirFiles = await promises.readdir(dirname(path));
|
|
422
405
|
return dirFiles.includes(basename(path));
|
|
423
406
|
}
|
|
424
|
-
async function
|
|
425
|
-
|
|
426
|
-
|
|
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);
|
|
427
444
|
}
|
|
428
445
|
|
|
429
446
|
async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
|
|
430
447
|
const nuxt = useNuxt();
|
|
431
448
|
const { nuxtModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions);
|
|
432
|
-
await nuxtModule.call(
|
|
449
|
+
await nuxtModule.call(
|
|
450
|
+
useModuleContainer(),
|
|
451
|
+
inlineOptions,
|
|
452
|
+
nuxt
|
|
453
|
+
);
|
|
433
454
|
nuxt.options._installedModules = nuxt.options._installedModules || [];
|
|
434
455
|
nuxt.options._installedModules.push({
|
|
435
456
|
meta: await nuxtModule.getMeta?.(),
|
|
@@ -476,7 +497,7 @@ function useModuleContainer(nuxt = useNuxt()) {
|
|
|
476
497
|
}
|
|
477
498
|
await installModule(src, inlineOptions);
|
|
478
499
|
}
|
|
479
|
-
|
|
500
|
+
const container = {
|
|
480
501
|
nuxt,
|
|
481
502
|
options: nuxt.options,
|
|
482
503
|
ready() {
|
|
@@ -525,6 +546,7 @@ function useModuleContainer(nuxt = useNuxt()) {
|
|
|
525
546
|
}
|
|
526
547
|
}
|
|
527
548
|
};
|
|
549
|
+
nuxt[MODULE_CONTAINER_KEY] = container;
|
|
528
550
|
return nuxt[MODULE_CONTAINER_KEY];
|
|
529
551
|
}
|
|
530
552
|
|
|
@@ -556,7 +578,8 @@ const importSources = (sources, { lazy = false } = {}) => {
|
|
|
556
578
|
return genImport(src, genSafeVariableName(src));
|
|
557
579
|
}).join("\n");
|
|
558
580
|
};
|
|
559
|
-
const
|
|
581
|
+
const importName = genSafeVariableName;
|
|
582
|
+
const templateUtils = { serialize, importName, importSources };
|
|
560
583
|
|
|
561
584
|
function defineNuxtModule(definition) {
|
|
562
585
|
if (typeof definition === "function") {
|
|
@@ -617,7 +640,7 @@ function nuxt2Shims(nuxt) {
|
|
|
617
640
|
}
|
|
618
641
|
nuxt[NUXT2_SHIMS_KEY] = true;
|
|
619
642
|
nuxt.hooks = nuxt;
|
|
620
|
-
if (!nuxtCtx.
|
|
643
|
+
if (!nuxtCtx.tryUse()) {
|
|
621
644
|
nuxtCtx.set(nuxt);
|
|
622
645
|
nuxt.hook("close", () => nuxtCtx.unset());
|
|
623
646
|
}
|
|
@@ -652,18 +675,22 @@ function nuxt2Shims(nuxt) {
|
|
|
652
675
|
}
|
|
653
676
|
|
|
654
677
|
async function loadNuxtConfig(opts) {
|
|
655
|
-
const
|
|
678
|
+
const result = await loadConfig({
|
|
656
679
|
name: "nuxt",
|
|
657
680
|
configFile: "nuxt.config",
|
|
658
681
|
rcFile: ".nuxtrc",
|
|
682
|
+
extend: { extendKey: ["theme", "extends"] },
|
|
659
683
|
dotenv: true,
|
|
660
684
|
globalRc: true,
|
|
661
685
|
...opts
|
|
662
686
|
});
|
|
687
|
+
const { configFile, layers = [], cwd } = result;
|
|
688
|
+
const nuxtConfig = result.config;
|
|
663
689
|
nuxtConfig.rootDir = nuxtConfig.rootDir || cwd;
|
|
664
690
|
nuxtConfig._nuxtConfigFile = configFile;
|
|
665
691
|
nuxtConfig._nuxtConfigFiles = [configFile];
|
|
666
692
|
for (const layer of layers) {
|
|
693
|
+
layer.config = layer.config || {};
|
|
667
694
|
layer.config.rootDir = layer.config.rootDir ?? layer.cwd;
|
|
668
695
|
layer.config.srcDir = resolve(layer.config.rootDir, layer.config.srcDir);
|
|
669
696
|
}
|
|
@@ -707,20 +734,22 @@ async function buildNuxt(nuxt) {
|
|
|
707
734
|
return build(nuxt);
|
|
708
735
|
}
|
|
709
736
|
|
|
710
|
-
function
|
|
737
|
+
function addImports(imports) {
|
|
711
738
|
assertNuxtCompatibility({ bridge: true });
|
|
712
|
-
useNuxt().hook("autoImports:extend", (
|
|
713
|
-
|
|
714
|
-
});
|
|
739
|
+
useNuxt().hook("autoImports:extend", (_imports) => {
|
|
740
|
+
_imports.push(...Array.isArray(imports) ? imports : [imports]);
|
|
741
|
+
}, { allowDeprecated: true });
|
|
715
742
|
}
|
|
716
|
-
|
|
743
|
+
const addAutoImport = addImports;
|
|
744
|
+
function addImportsDir(dirs) {
|
|
717
745
|
assertNuxtCompatibility({ bridge: true });
|
|
718
|
-
useNuxt().hook("autoImports:dirs", (
|
|
719
|
-
for (const dir of Array.isArray(
|
|
720
|
-
|
|
746
|
+
useNuxt().hook("autoImports:dirs", (_dirs) => {
|
|
747
|
+
for (const dir of Array.isArray(dirs) ? dirs : [dirs]) {
|
|
748
|
+
_dirs.push(dir);
|
|
721
749
|
}
|
|
722
|
-
});
|
|
750
|
+
}, { allowDeprecated: true });
|
|
723
751
|
}
|
|
752
|
+
const addAutoImportDir = addImportsDir;
|
|
724
753
|
|
|
725
754
|
function extendWebpackConfig(fn, options = {}) {
|
|
726
755
|
const nuxt = useNuxt();
|
|
@@ -833,4 +862,4 @@ function extendPages(cb) {
|
|
|
833
862
|
}
|
|
834
863
|
}
|
|
835
864
|
|
|
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 };
|
|
865
|
+
export { addAutoImport, addAutoImportDir, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, 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.9",
|
|
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": "
|
|
17
|
-
"c12": "^0.2.
|
|
16
|
+
"@nuxt/schema": "3.0.0-rc.9",
|
|
17
|
+
"c12": "^0.2.10",
|
|
18
18
|
"consola": "^2.15.3",
|
|
19
|
-
"defu": "^6.
|
|
19
|
+
"defu": "^6.1.0",
|
|
20
20
|
"globby": "^13.1.2",
|
|
21
21
|
"hash-sum": "^2.0.0",
|
|
22
22
|
"ignore": "^5.2.0",
|
|
23
23
|
"jiti": "^1.14.0",
|
|
24
24
|
"knitwork": "^0.1.2",
|
|
25
25
|
"lodash.template": "^4.5.0",
|
|
26
|
-
"mlly": "^0.5.
|
|
27
|
-
"pathe": "^0.3.
|
|
28
|
-
"pkg-types": "^0.3.
|
|
29
|
-
"scule": "^0.2
|
|
26
|
+
"mlly": "^0.5.14",
|
|
27
|
+
"pathe": "^0.3.5",
|
|
28
|
+
"pkg-types": "^0.3.4",
|
|
29
|
+
"scule": "^0.3.2",
|
|
30
30
|
"semver": "^7.3.7",
|
|
31
|
-
"unctx": "^
|
|
32
|
-
"unimport": "^0.
|
|
33
|
-
"untyped": "^0.4.
|
|
31
|
+
"unctx": "^2.0.2",
|
|
32
|
+
"unimport": "^0.6.7",
|
|
33
|
+
"untyped": "^0.4.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/lodash.template": "^4",
|