@nuxt/kit 3.0.0-rc.8 → 3.0.0
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 +21 -0
- package/dist/index.d.ts +64 -45
- package/dist/index.mjs +333 -390
- package/package.json +18 -20
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
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleOptions, ModuleDefinition, NuxtModule, Nuxt, 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
|
-
import * as
|
|
7
|
-
import {
|
|
8
|
-
import { NitroEventHandler, NitroDevEventHandler } from 'nitropack';
|
|
6
|
+
import * as unctx_index from 'unctx/index';
|
|
7
|
+
import { NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack';
|
|
9
8
|
import * as consola from 'consola';
|
|
10
9
|
import { genSafeVariableName } from 'knitwork';
|
|
11
10
|
|
|
12
|
-
declare function useModuleContainer(nuxt?: Nuxt): ModuleContainer;
|
|
13
|
-
|
|
14
11
|
/**
|
|
15
12
|
* Define a Nuxt module, automatically merging defaults with user provided options, installing
|
|
16
13
|
* any hooks that are provided, and calling an optional setup function for full control.
|
|
@@ -37,8 +34,9 @@ interface LoadNuxtOptions extends LoadNuxtConfigOptions {
|
|
|
37
34
|
declare function loadNuxt(opts: LoadNuxtOptions): Promise<Nuxt>;
|
|
38
35
|
declare function buildNuxt(nuxt: Nuxt): Promise<any>;
|
|
39
36
|
|
|
40
|
-
declare function
|
|
41
|
-
declare function
|
|
37
|
+
declare function addImports(imports: Import | Import[]): void;
|
|
38
|
+
declare function addImportsDir(dirs: string | string[]): void;
|
|
39
|
+
declare function addImportsSources(presets: ImportPresetWithDeprecation | ImportPresetWithDeprecation[]): void;
|
|
42
40
|
|
|
43
41
|
interface ExtendConfigOptions {
|
|
44
42
|
/**
|
|
@@ -67,13 +65,6 @@ interface ExtendConfigOptions {
|
|
|
67
65
|
client?: boolean;
|
|
68
66
|
}
|
|
69
67
|
interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
|
|
70
|
-
/**
|
|
71
|
-
* Install plugin on modern build
|
|
72
|
-
*
|
|
73
|
-
* @default true
|
|
74
|
-
* @deprecated Nuxt 2 only
|
|
75
|
-
*/
|
|
76
|
-
modern?: boolean;
|
|
77
68
|
}
|
|
78
69
|
interface ExtendViteConfigOptions extends ExtendConfigOptions {
|
|
79
70
|
}
|
|
@@ -87,15 +78,15 @@ declare function extendWebpackConfig(fn: ((config: Configuration) => void), opti
|
|
|
87
78
|
/**
|
|
88
79
|
* Extend Vite config
|
|
89
80
|
*/
|
|
90
|
-
declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): () => void;
|
|
81
|
+
declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): (() => void) | undefined;
|
|
91
82
|
/**
|
|
92
83
|
* Append Webpack plugin to the config.
|
|
93
84
|
*/
|
|
94
|
-
declare function addWebpackPlugin(plugin: WebpackPluginInstance, options?: ExtendWebpackConfigOptions): void;
|
|
85
|
+
declare function addWebpackPlugin(plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions): void;
|
|
95
86
|
/**
|
|
96
87
|
* Append Vite plugin to the config.
|
|
97
88
|
*/
|
|
98
|
-
declare function addVitePlugin(plugin: Plugin, options?: ExtendViteConfigOptions): void;
|
|
89
|
+
declare function addVitePlugin(plugin: Plugin | Plugin[], options?: ExtendViteConfigOptions): void;
|
|
99
90
|
|
|
100
91
|
/**
|
|
101
92
|
* Check version constraints and return incompatibility issues as an array
|
|
@@ -128,7 +119,7 @@ declare function getNuxtVersion(nuxt?: Nuxt | any): any;
|
|
|
128
119
|
* Requires Nuxt 2.13+
|
|
129
120
|
*/
|
|
130
121
|
declare function addComponentsDir(dir: ComponentsDir): Promise<void>;
|
|
131
|
-
|
|
122
|
+
type AddComponentOptions = {
|
|
132
123
|
name: string;
|
|
133
124
|
filePath: string;
|
|
134
125
|
} & Partial<Exclude<Component, 'shortPath' | 'async' | 'level' | 'import' | 'asyncImport'>>;
|
|
@@ -140,7 +131,7 @@ declare type AddComponentOptions = {
|
|
|
140
131
|
declare function addComponent(opts: AddComponentOptions): Promise<void>;
|
|
141
132
|
|
|
142
133
|
/** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
|
|
143
|
-
declare const nuxtCtx:
|
|
134
|
+
declare const nuxtCtx: unctx_index.UseContext<Nuxt>;
|
|
144
135
|
/**
|
|
145
136
|
* Get access to Nuxt instance.
|
|
146
137
|
*
|
|
@@ -172,7 +163,7 @@ declare function tryUseNuxt(): Nuxt | null;
|
|
|
172
163
|
*/
|
|
173
164
|
declare function isIgnored(pathname: string): boolean;
|
|
174
165
|
|
|
175
|
-
declare function addLayout(
|
|
166
|
+
declare function addLayout(this: any, template: NuxtTemplate, name?: string): void;
|
|
176
167
|
|
|
177
168
|
declare function extendPages(cb: NuxtHooks['pages:extend']): void;
|
|
178
169
|
|
|
@@ -228,7 +219,7 @@ declare function findPath(paths: string | string[], opts?: ResolvePathOptions, p
|
|
|
228
219
|
*/
|
|
229
220
|
declare function resolveAlias(path: string, alias?: Record<string, string>): string;
|
|
230
221
|
interface Resolver {
|
|
231
|
-
resolve(...path:
|
|
222
|
+
resolve(...path: string[]): string;
|
|
232
223
|
resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
|
|
233
224
|
}
|
|
234
225
|
/**
|
|
@@ -239,18 +230,6 @@ declare function resolveFiles(path: string, pattern: string | string[], opts?: {
|
|
|
239
230
|
followSymbolicLinks?: boolean;
|
|
240
231
|
}): Promise<string[]>;
|
|
241
232
|
|
|
242
|
-
interface LegacyServerMiddleware {
|
|
243
|
-
route?: string;
|
|
244
|
-
path?: string;
|
|
245
|
-
handle?: Middleware | string;
|
|
246
|
-
handler: Middleware | string;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Adds a new server middleware to the end of the server middleware array.
|
|
250
|
-
*
|
|
251
|
-
* @deprecated Use addServerHandler instead
|
|
252
|
-
*/
|
|
253
|
-
declare function addServerMiddleware(middleware: LegacyServerMiddleware): void;
|
|
254
233
|
/**
|
|
255
234
|
* Adds a nitro server handler
|
|
256
235
|
*
|
|
@@ -261,54 +240,94 @@ declare function addServerHandler(handler: NitroEventHandler): void;
|
|
|
261
240
|
*
|
|
262
241
|
*/
|
|
263
242
|
declare function addDevServerHandler(handler: NitroDevEventHandler): void;
|
|
243
|
+
/**
|
|
244
|
+
* Adds a Nitro plugin
|
|
245
|
+
*/
|
|
246
|
+
declare function addServerPlugin(plugin: string): void;
|
|
247
|
+
/**
|
|
248
|
+
* Adds routes to be prerendered
|
|
249
|
+
*/
|
|
250
|
+
declare function addPrerenderRoutes(routes: string | string[]): void;
|
|
251
|
+
/**
|
|
252
|
+
* Access to the Nitro instance
|
|
253
|
+
*
|
|
254
|
+
* **Note:** You can call `useNitro()` only after `ready` hook.
|
|
255
|
+
*
|
|
256
|
+
* **Note:** Changes to the Nitro instance configuration are not applied.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
*
|
|
260
|
+
* ```ts
|
|
261
|
+
* nuxt.hook('ready', () => {
|
|
262
|
+
* console.log(useNitro())
|
|
263
|
+
* })
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
declare function useNitro(): Nitro;
|
|
264
267
|
|
|
265
268
|
/**
|
|
266
269
|
* Renders given template using lodash template during build into the project buildDir
|
|
267
270
|
*/
|
|
268
|
-
declare function addTemplate(_template: NuxtTemplate | string):
|
|
271
|
+
declare function addTemplate(_template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
|
|
269
272
|
/**
|
|
270
273
|
* Normalize a nuxt template object
|
|
271
274
|
*/
|
|
272
|
-
declare function normalizeTemplate(template: NuxtTemplate | string):
|
|
275
|
+
declare function normalizeTemplate(template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
|
|
276
|
+
/**
|
|
277
|
+
* Trigger rebuilding Nuxt templates
|
|
278
|
+
*
|
|
279
|
+
* You can pass a filter within the options to selectively regenerate a subset of templates.
|
|
280
|
+
*/
|
|
281
|
+
declare function updateTemplates(options?: {
|
|
282
|
+
filter?: (template: ResolvedNuxtTemplate<any>) => boolean;
|
|
283
|
+
}): Promise<any>;
|
|
273
284
|
|
|
274
285
|
declare const logger: consola.Consola;
|
|
275
286
|
declare function useLogger(scope?: string): consola.Consola;
|
|
276
287
|
|
|
288
|
+
/** @deprecated Do not use CJS utils */
|
|
277
289
|
interface ResolveModuleOptions {
|
|
278
290
|
paths?: string | string[];
|
|
279
291
|
}
|
|
292
|
+
/** @deprecated Do not use CJS utils */
|
|
280
293
|
interface RequireModuleOptions extends ResolveModuleOptions {
|
|
281
294
|
/** Clear the require cache (force fresh require) but only if not within `node_modules` */
|
|
282
295
|
clearCache?: boolean;
|
|
283
296
|
/** Automatically de-default the result of requiring the module. */
|
|
284
297
|
interopDefault?: boolean;
|
|
285
298
|
}
|
|
299
|
+
/** @deprecated Do not use CJS utils */
|
|
286
300
|
declare function isNodeModules(id: string): boolean;
|
|
301
|
+
/** @deprecated Do not use CJS utils */
|
|
287
302
|
declare function clearRequireCache(id: string): void;
|
|
303
|
+
/** @deprecated Do not use CJS utils */
|
|
288
304
|
declare function scanRequireTree(id: string, files?: Set<string>): Set<string>;
|
|
289
|
-
/**
|
|
290
|
-
declare function getRequireCacheItem(id: string): NodeModule;
|
|
305
|
+
/** @deprecated Do not use CJS utils */
|
|
306
|
+
declare function getRequireCacheItem(id: string): NodeModule | undefined;
|
|
291
307
|
/** Resolve the `package.json` file for a given module. */
|
|
292
308
|
declare function requireModulePkg(id: string, opts?: RequireModuleOptions): any;
|
|
293
|
-
/**
|
|
309
|
+
/** @deprecated Do not use CJS utils */
|
|
294
310
|
declare function resolveModule(id: string, opts?: ResolveModuleOptions): string;
|
|
295
|
-
/**
|
|
311
|
+
/** @deprecated Do not use CJS utils */
|
|
296
312
|
declare function tryResolveModule(path: string, opts?: ResolveModuleOptions): string | null;
|
|
297
|
-
/**
|
|
313
|
+
/** @deprecated Do not use CJS utils */
|
|
298
314
|
declare function requireModule(id: string, opts?: RequireModuleOptions): any;
|
|
315
|
+
/** @deprecated Do not use CJS utils */
|
|
299
316
|
declare function importModule(id: string, opts?: RequireModuleOptions): Promise<any>;
|
|
300
|
-
|
|
301
|
-
|
|
317
|
+
/** @deprecated Do not use CJS utils */
|
|
318
|
+
declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any> | undefined;
|
|
319
|
+
/** @deprecated Do not use CJS utils */
|
|
302
320
|
declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
|
|
303
321
|
|
|
322
|
+
/** @deprecated */
|
|
304
323
|
declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
|
|
305
324
|
/** @deprecated */
|
|
306
325
|
declare const templateUtils: {
|
|
307
326
|
serialize: (data: any) => string;
|
|
308
327
|
importName: typeof genSafeVariableName;
|
|
309
328
|
importSources: (sources: string | string[], { lazy }?: {
|
|
310
|
-
lazy?: boolean;
|
|
329
|
+
lazy?: boolean | undefined;
|
|
311
330
|
}) => string;
|
|
312
331
|
};
|
|
313
332
|
|
|
314
|
-
export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions,
|
|
333
|
+
export { AddComponentOptions, AddPluginOptions, ExtendConfigOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, 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, useNitro, useNuxt };
|
package/dist/index.mjs
CHANGED
|
@@ -1,45 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { promises, existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import defu from 'defu';
|
|
3
|
+
import { applyDefaults } from 'untyped';
|
|
4
|
+
import { dirname, join, normalize, relative, isAbsolute, resolve, basename, parse } from 'pathe';
|
|
5
|
+
import consola from 'consola';
|
|
4
6
|
import { getContext } from 'unctx';
|
|
5
|
-
import { kebabCase, pascalCase } from 'scule';
|
|
6
7
|
import satisfies from 'semver/functions/satisfies.js';
|
|
7
|
-
import
|
|
8
|
+
import lodashTemplate from 'lodash.template';
|
|
9
|
+
import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
|
|
8
10
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
9
|
-
import { globby } from 'globby';
|
|
10
11
|
import { interopDefault } from 'mlly';
|
|
11
12
|
import jiti from 'jiti';
|
|
13
|
+
import { globby } from 'globby';
|
|
14
|
+
import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
|
|
12
15
|
import ignore from 'ignore';
|
|
13
|
-
import defu from 'defu';
|
|
14
|
-
import { applyDefaults } from 'untyped';
|
|
15
|
-
import lodashTemplate from 'lodash.template';
|
|
16
|
-
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
|
+
import hash from 'hash-sum';
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
return function(...args) {
|
|
26
|
-
if (typeof base !== "function") {
|
|
27
|
-
return fn.apply(this, args);
|
|
28
|
-
}
|
|
29
|
-
let baseResult = base.apply(this, args);
|
|
30
|
-
if (baseResult === void 0) {
|
|
31
|
-
[baseResult] = args;
|
|
32
|
-
}
|
|
33
|
-
const fnResult = fn.call(
|
|
34
|
-
this,
|
|
35
|
-
baseResult,
|
|
36
|
-
...Array.prototype.slice.call(args, 1)
|
|
37
|
-
);
|
|
38
|
-
if (fnResult === void 0) {
|
|
39
|
-
return baseResult;
|
|
40
|
-
}
|
|
41
|
-
return fnResult;
|
|
42
|
-
};
|
|
22
|
+
const logger = consola;
|
|
23
|
+
function useLogger(scope) {
|
|
24
|
+
return scope ? logger.withScope(scope) : logger;
|
|
43
25
|
}
|
|
44
26
|
|
|
45
27
|
const nuxtCtx = getContext("nuxt");
|
|
@@ -54,53 +36,12 @@ function tryUseNuxt() {
|
|
|
54
36
|
return nuxtCtx.tryUse();
|
|
55
37
|
}
|
|
56
38
|
|
|
57
|
-
function addTemplate(_template) {
|
|
58
|
-
const nuxt = useNuxt();
|
|
59
|
-
const template = normalizeTemplate(_template);
|
|
60
|
-
nuxt.options.build.templates = nuxt.options.build.templates.filter((p) => normalizeTemplate(p).filename !== template.filename);
|
|
61
|
-
nuxt.options.build.templates.push(template);
|
|
62
|
-
return template;
|
|
63
|
-
}
|
|
64
|
-
function normalizeTemplate(template) {
|
|
65
|
-
if (!template) {
|
|
66
|
-
throw new Error("Invalid template: " + JSON.stringify(template));
|
|
67
|
-
}
|
|
68
|
-
if (typeof template === "string") {
|
|
69
|
-
template = { src: template };
|
|
70
|
-
} else {
|
|
71
|
-
template = { ...template };
|
|
72
|
-
}
|
|
73
|
-
if (template.src) {
|
|
74
|
-
if (!existsSync(template.src)) {
|
|
75
|
-
throw new Error("Template not found: " + template.src);
|
|
76
|
-
}
|
|
77
|
-
if (!template.filename) {
|
|
78
|
-
const srcPath = parse(template.src);
|
|
79
|
-
template.filename = template.fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hash(template.src)}${srcPath.ext}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (!template.src && !template.getContents) {
|
|
83
|
-
throw new Error("Invalid template. Either getContents or src options should be provided: " + JSON.stringify(template));
|
|
84
|
-
}
|
|
85
|
-
if (!template.filename) {
|
|
86
|
-
throw new Error("Invalid template. Either filename should be provided: " + JSON.stringify(template));
|
|
87
|
-
}
|
|
88
|
-
if (template.filename.endsWith(".d.ts")) {
|
|
89
|
-
template.write = true;
|
|
90
|
-
}
|
|
91
|
-
if (!template.dst) {
|
|
92
|
-
const nuxt = useNuxt();
|
|
93
|
-
template.dst = resolve(nuxt.options.buildDir, template.filename);
|
|
94
|
-
}
|
|
95
|
-
return template;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
39
|
async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
99
40
|
const issues = [];
|
|
100
41
|
if (constraints.nuxt) {
|
|
101
42
|
const nuxtVersion = getNuxtVersion(nuxt);
|
|
102
|
-
const nuxtSemanticVersion = nuxtVersion.
|
|
103
|
-
if (!satisfies(nuxtSemanticVersion, constraints.nuxt)) {
|
|
43
|
+
const nuxtSemanticVersion = nuxtVersion.replace(/-[0-9]+\.[0-9a-f]{7,8}/, "");
|
|
44
|
+
if (!satisfies(nuxtSemanticVersion, constraints.nuxt, { includePrerelease: true })) {
|
|
104
45
|
issues.push({
|
|
105
46
|
name: "nuxt",
|
|
106
47
|
message: `Nuxt version \`${constraints.nuxt}\` is required but currently using \`${nuxtVersion}\``
|
|
@@ -151,59 +92,125 @@ function getNuxtVersion(nuxt = useNuxt()) {
|
|
|
151
92
|
return version;
|
|
152
93
|
}
|
|
153
94
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
95
|
+
async function compileTemplate(template, ctx) {
|
|
96
|
+
const data = { ...ctx, options: template.options };
|
|
97
|
+
if (template.src) {
|
|
98
|
+
try {
|
|
99
|
+
const srcContents = await promises.readFile(template.src, "utf-8");
|
|
100
|
+
return lodashTemplate(srcContents, {})(data);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error("Error compiling template: ", template);
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (template.getContents) {
|
|
107
|
+
return template.getContents(data);
|
|
108
|
+
}
|
|
109
|
+
throw new Error("Invalid template: " + JSON.stringify(template));
|
|
157
110
|
}
|
|
111
|
+
const serialize = (data) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, (r) => JSON.parse(r).replace(/^{(.*)}$/, "$1"));
|
|
112
|
+
const importSources = (sources, { lazy = false } = {}) => {
|
|
113
|
+
if (!Array.isArray(sources)) {
|
|
114
|
+
sources = [sources];
|
|
115
|
+
}
|
|
116
|
+
return sources.map((src) => {
|
|
117
|
+
if (lazy) {
|
|
118
|
+
return `const ${genSafeVariableName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
|
|
119
|
+
}
|
|
120
|
+
return genImport(src, genSafeVariableName(src));
|
|
121
|
+
}).join("\n");
|
|
122
|
+
};
|
|
123
|
+
const importName = genSafeVariableName;
|
|
124
|
+
const templateUtils = { serialize, importName, importSources };
|
|
158
125
|
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
126
|
+
function defineNuxtModule(definition) {
|
|
127
|
+
if (!definition.meta) {
|
|
128
|
+
definition.meta = {};
|
|
129
|
+
}
|
|
130
|
+
if (definition.meta.configKey === void 0) {
|
|
131
|
+
definition.meta.configKey = definition.meta.name;
|
|
132
|
+
}
|
|
133
|
+
async function getOptions(inlineOptions, nuxt = useNuxt()) {
|
|
134
|
+
const configKey = definition.meta.configKey || definition.meta.name;
|
|
135
|
+
const _defaults = definition.defaults instanceof Function ? definition.defaults(nuxt) : definition.defaults;
|
|
136
|
+
let _options = defu(inlineOptions, nuxt.options[configKey], _defaults);
|
|
137
|
+
if (definition.schema) {
|
|
138
|
+
_options = await applyDefaults(definition.schema, _options);
|
|
169
139
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
140
|
+
return Promise.resolve(_options);
|
|
141
|
+
}
|
|
142
|
+
async function normalizedModule(inlineOptions, nuxt) {
|
|
143
|
+
if (!nuxt) {
|
|
144
|
+
nuxt = tryUseNuxt() || this.nuxt;
|
|
145
|
+
}
|
|
146
|
+
const uniqueKey = definition.meta.name || definition.meta.configKey;
|
|
147
|
+
if (uniqueKey) {
|
|
148
|
+
nuxt.options._requiredModules = nuxt.options._requiredModules || {};
|
|
149
|
+
if (nuxt.options._requiredModules[uniqueKey]) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
nuxt.options._requiredModules[uniqueKey] = true;
|
|
173
153
|
}
|
|
154
|
+
if (definition.meta.compatibility) {
|
|
155
|
+
const issues = await checkNuxtCompatibility(definition.meta.compatibility, nuxt);
|
|
156
|
+
if (issues.length) {
|
|
157
|
+
logger.warn(`Module \`${definition.meta.name}\` is disabled due to incompatibility issues:
|
|
158
|
+
${issues.toString()}`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
nuxt2Shims(nuxt);
|
|
163
|
+
const _options = await getOptions(inlineOptions, nuxt);
|
|
164
|
+
if (definition.hooks) {
|
|
165
|
+
nuxt.hooks.addHooks(definition.hooks);
|
|
166
|
+
}
|
|
167
|
+
await definition.setup?.call(null, _options, nuxt);
|
|
168
|
+
}
|
|
169
|
+
normalizedModule.getMeta = () => Promise.resolve(definition.meta);
|
|
170
|
+
normalizedModule.getOptions = getOptions;
|
|
171
|
+
return normalizedModule;
|
|
172
|
+
}
|
|
173
|
+
const NUXT2_SHIMS_KEY = "__nuxt2_shims_key__";
|
|
174
|
+
function nuxt2Shims(nuxt) {
|
|
175
|
+
if (!isNuxt2(nuxt) || nuxt[NUXT2_SHIMS_KEY]) {
|
|
174
176
|
return;
|
|
175
177
|
}
|
|
176
|
-
nuxt
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
nuxt[NUXT2_SHIMS_KEY] = true;
|
|
179
|
+
nuxt.hooks = nuxt;
|
|
180
|
+
if (!nuxtCtx.tryUse()) {
|
|
181
|
+
nuxtCtx.set(nuxt);
|
|
182
|
+
nuxt.hook("close", () => nuxtCtx.unset());
|
|
183
|
+
}
|
|
184
|
+
let virtualTemplates;
|
|
185
|
+
nuxt.hook("builder:prepared", (_builder, buildOptions) => {
|
|
186
|
+
virtualTemplates = buildOptions.templates.filter((t) => t.getContents);
|
|
187
|
+
for (const template of virtualTemplates) {
|
|
188
|
+
buildOptions.templates.splice(buildOptions.templates.indexOf(template), 1);
|
|
182
189
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
190
|
+
});
|
|
191
|
+
nuxt.hook("build:templates", async (templates) => {
|
|
192
|
+
const context = {
|
|
193
|
+
nuxt,
|
|
194
|
+
utils: templateUtils,
|
|
195
|
+
app: {
|
|
196
|
+
dir: nuxt.options.srcDir,
|
|
197
|
+
extensions: nuxt.options.extensions,
|
|
198
|
+
plugins: nuxt.options.plugins,
|
|
199
|
+
templates: [
|
|
200
|
+
...templates.templatesFiles,
|
|
201
|
+
...virtualTemplates
|
|
202
|
+
],
|
|
203
|
+
templateVars: templates.templateVars
|
|
204
|
+
}
|
|
186
205
|
};
|
|
206
|
+
for await (const template of virtualTemplates) {
|
|
207
|
+
const contents = await compileTemplate({ ...template, src: "" }, context);
|
|
208
|
+
await promises.mkdir(dirname(template.dst), { recursive: true });
|
|
209
|
+
await promises.writeFile(template.dst, contents);
|
|
210
|
+
}
|
|
187
211
|
});
|
|
188
212
|
}
|
|
189
213
|
|
|
190
|
-
function normalizeHandlerMethod(handler) {
|
|
191
|
-
const [, method = void 0] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || [];
|
|
192
|
-
return {
|
|
193
|
-
method,
|
|
194
|
-
...handler
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
function addServerMiddleware(middleware) {
|
|
198
|
-
useNuxt().options.serverMiddleware.push(middleware);
|
|
199
|
-
}
|
|
200
|
-
function addServerHandler(handler) {
|
|
201
|
-
useNuxt().options.serverHandlers.push(normalizeHandlerMethod(handler));
|
|
202
|
-
}
|
|
203
|
-
function addDevServerHandler(handler) {
|
|
204
|
-
useNuxt().options.devServerHandlers.push(handler);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
214
|
const _require = jiti(process.cwd(), { interopDefault: true, esmResolve: true });
|
|
208
215
|
function isNodeModules(id) {
|
|
209
216
|
return /[/\\]node_modules[/\\]/.test(id);
|
|
@@ -253,7 +260,7 @@ function resolveModule(id, opts = {}) {
|
|
|
253
260
|
return normalize(_require.resolve(id, {
|
|
254
261
|
paths: [].concat(
|
|
255
262
|
global.__NUXT_PREPATHS__,
|
|
256
|
-
opts.paths,
|
|
263
|
+
opts.paths || [],
|
|
257
264
|
process.cwd(),
|
|
258
265
|
global.__NUXT_PATHS__
|
|
259
266
|
).filter(Boolean)
|
|
@@ -263,7 +270,7 @@ function tryResolveModule(path, opts = {}) {
|
|
|
263
270
|
try {
|
|
264
271
|
return resolveModule(path, opts);
|
|
265
272
|
} catch (error) {
|
|
266
|
-
if (error
|
|
273
|
+
if (error?.code !== "MODULE_NOT_FOUND") {
|
|
267
274
|
throw error;
|
|
268
275
|
}
|
|
269
276
|
}
|
|
@@ -300,7 +307,7 @@ function tryRequireModule(id, opts = {}) {
|
|
|
300
307
|
function isIgnored(pathname) {
|
|
301
308
|
const nuxt = tryUseNuxt();
|
|
302
309
|
if (!nuxt) {
|
|
303
|
-
return
|
|
310
|
+
return false;
|
|
304
311
|
}
|
|
305
312
|
if (!nuxt._ignore) {
|
|
306
313
|
nuxt._ignore = ignore(nuxt.options.ignoreOptions);
|
|
@@ -314,7 +321,7 @@ function isIgnored(pathname) {
|
|
|
314
321
|
if (relativePath.startsWith("..")) {
|
|
315
322
|
return false;
|
|
316
323
|
}
|
|
317
|
-
return relativePath && nuxt._ignore.ignores(relativePath);
|
|
324
|
+
return !!(relativePath && nuxt._ignore.ignores(relativePath));
|
|
318
325
|
}
|
|
319
326
|
|
|
320
327
|
async function resolvePath(path, opts = {}) {
|
|
@@ -323,7 +330,7 @@ async function resolvePath(path, opts = {}) {
|
|
|
323
330
|
if (isAbsolute(path) && existsSync(path) && !await isDirectory(path)) {
|
|
324
331
|
return path;
|
|
325
332
|
}
|
|
326
|
-
const nuxt =
|
|
333
|
+
const nuxt = tryUseNuxt();
|
|
327
334
|
const cwd = opts.cwd || (nuxt ? nuxt.options.rootDir : process.cwd());
|
|
328
335
|
const extensions = opts.extensions || (nuxt ? nuxt.options.extensions : [".ts", ".mjs", ".cjs", ".json"]);
|
|
329
336
|
const modulesDir = nuxt ? nuxt.options.modulesDir : [];
|
|
@@ -373,15 +380,7 @@ function resolveAlias(path, alias) {
|
|
|
373
380
|
if (!alias) {
|
|
374
381
|
alias = tryUseNuxt()?.options.alias || {};
|
|
375
382
|
}
|
|
376
|
-
|
|
377
|
-
if (key === "@" && !path.startsWith("@/")) {
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
if (path.startsWith(key)) {
|
|
381
|
-
path = alias[key] + path.slice(key.length);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return path;
|
|
383
|
+
return resolveAlias$1(path, alias);
|
|
385
384
|
}
|
|
386
385
|
function createResolver(base) {
|
|
387
386
|
if (!base) {
|
|
@@ -411,41 +410,13 @@ async function resolveFiles(path, pattern, opts = {}) {
|
|
|
411
410
|
return files.map((p) => resolve(path, p)).filter((p) => !isIgnored(p)).sort();
|
|
412
411
|
}
|
|
413
412
|
|
|
414
|
-
function normalizePlugin(plugin) {
|
|
415
|
-
if (typeof plugin === "string") {
|
|
416
|
-
plugin = { src: plugin };
|
|
417
|
-
} else {
|
|
418
|
-
plugin = { ...plugin };
|
|
419
|
-
}
|
|
420
|
-
if (!plugin.src) {
|
|
421
|
-
throw new Error("Invalid plugin. src option is required: " + JSON.stringify(plugin));
|
|
422
|
-
}
|
|
423
|
-
plugin.src = normalize(resolveAlias(plugin.src));
|
|
424
|
-
if (plugin.ssr) {
|
|
425
|
-
plugin.mode = "server";
|
|
426
|
-
}
|
|
427
|
-
if (!plugin.mode) {
|
|
428
|
-
const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
|
|
429
|
-
plugin.mode = mode;
|
|
430
|
-
}
|
|
431
|
-
return plugin;
|
|
432
|
-
}
|
|
433
|
-
function addPlugin(_plugin, opts = {}) {
|
|
434
|
-
const nuxt = useNuxt();
|
|
435
|
-
const plugin = normalizePlugin(_plugin);
|
|
436
|
-
nuxt.options.plugins = nuxt.options.plugins.filter((p) => normalizePlugin(p).src !== plugin.src);
|
|
437
|
-
nuxt.options.plugins[opts.append ? "push" : "unshift"](plugin);
|
|
438
|
-
return plugin;
|
|
439
|
-
}
|
|
440
|
-
function addPluginTemplate(plugin, opts = {}) {
|
|
441
|
-
const normalizedPlugin = typeof plugin === "string" ? { src: plugin } : { ...plugin, src: addTemplate(plugin).dst };
|
|
442
|
-
return addPlugin(normalizedPlugin, opts);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
413
|
async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
|
|
446
414
|
const nuxt = useNuxt();
|
|
447
415
|
const { nuxtModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions);
|
|
448
|
-
await nuxtModule
|
|
416
|
+
await nuxtModule(inlineOptions, nuxt);
|
|
417
|
+
if (typeof moduleToInstall === "string") {
|
|
418
|
+
nuxt.options.build.transpile.push(moduleToInstall);
|
|
419
|
+
}
|
|
449
420
|
nuxt.options._installedModules = nuxt.options._installedModules || [];
|
|
450
421
|
nuxt.options._installedModules.push({
|
|
451
422
|
meta: await nuxtModule.getMeta?.(),
|
|
@@ -454,14 +425,15 @@ async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
|
|
|
454
425
|
}
|
|
455
426
|
async function normalizeModule(nuxtModule, inlineOptions) {
|
|
456
427
|
const nuxt = useNuxt();
|
|
457
|
-
if (nuxtModule?._version || nuxtModule?.version || nuxtModule?.constructor?.version || "") {
|
|
458
|
-
[nuxtModule, inlineOptions] = [inlineOptions, {}];
|
|
459
|
-
console.warn(new Error("`installModule` is being called with old signature!"));
|
|
460
|
-
}
|
|
461
428
|
if (typeof nuxtModule === "string") {
|
|
462
429
|
const _src = resolveModule(resolveAlias(nuxtModule), { paths: nuxt.options.modulesDir });
|
|
463
430
|
const isESM = _src.endsWith(".mjs");
|
|
464
|
-
|
|
431
|
+
try {
|
|
432
|
+
nuxtModule = isESM ? await importModule(_src) : requireModule(_src);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
console.error(`Error while requiring module \`${nuxtModule}\`: ${error}`);
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
465
437
|
}
|
|
466
438
|
if (typeof nuxtModule !== "function") {
|
|
467
439
|
throw new TypeError("Nuxt module should be a function: " + nuxtModule);
|
|
@@ -469,223 +441,40 @@ async function normalizeModule(nuxtModule, inlineOptions) {
|
|
|
469
441
|
return { nuxtModule, inlineOptions };
|
|
470
442
|
}
|
|
471
443
|
|
|
472
|
-
const MODULE_CONTAINER_KEY = "__module_container__";
|
|
473
|
-
function useModuleContainer(nuxt = useNuxt()) {
|
|
474
|
-
if (nuxt[MODULE_CONTAINER_KEY]) {
|
|
475
|
-
return nuxt[MODULE_CONTAINER_KEY];
|
|
476
|
-
}
|
|
477
|
-
async function requireModule(moduleOpts) {
|
|
478
|
-
let src, inlineOptions;
|
|
479
|
-
if (typeof moduleOpts === "string") {
|
|
480
|
-
src = moduleOpts;
|
|
481
|
-
} else if (Array.isArray(moduleOpts)) {
|
|
482
|
-
[src, inlineOptions] = moduleOpts;
|
|
483
|
-
} else if (typeof moduleOpts === "object") {
|
|
484
|
-
if (moduleOpts.src || moduleOpts.handler) {
|
|
485
|
-
src = moduleOpts.src || moduleOpts.handler;
|
|
486
|
-
inlineOptions = moduleOpts.options;
|
|
487
|
-
} else {
|
|
488
|
-
src = moduleOpts;
|
|
489
|
-
}
|
|
490
|
-
} else {
|
|
491
|
-
src = moduleOpts;
|
|
492
|
-
}
|
|
493
|
-
await installModule(src, inlineOptions);
|
|
494
|
-
}
|
|
495
|
-
nuxt[MODULE_CONTAINER_KEY] = {
|
|
496
|
-
nuxt,
|
|
497
|
-
options: nuxt.options,
|
|
498
|
-
ready() {
|
|
499
|
-
return Promise.resolve();
|
|
500
|
-
},
|
|
501
|
-
addVendor() {
|
|
502
|
-
},
|
|
503
|
-
requireModule,
|
|
504
|
-
addModule: requireModule,
|
|
505
|
-
addServerMiddleware,
|
|
506
|
-
addTemplate(template) {
|
|
507
|
-
if (typeof template === "string") {
|
|
508
|
-
template = { src: template };
|
|
509
|
-
}
|
|
510
|
-
if (template.write === void 0) {
|
|
511
|
-
template.write = true;
|
|
512
|
-
}
|
|
513
|
-
return addTemplate(template);
|
|
514
|
-
},
|
|
515
|
-
addPlugin(pluginTemplate) {
|
|
516
|
-
return addPluginTemplate(pluginTemplate);
|
|
517
|
-
},
|
|
518
|
-
addLayout(tmpl, name) {
|
|
519
|
-
return addLayout(tmpl, name);
|
|
520
|
-
},
|
|
521
|
-
addErrorLayout(dst) {
|
|
522
|
-
const relativeBuildDir = relative(nuxt.options.rootDir, nuxt.options.buildDir);
|
|
523
|
-
nuxt.options.ErrorPage = `~/${relativeBuildDir}/${dst}`;
|
|
524
|
-
},
|
|
525
|
-
extendBuild(fn) {
|
|
526
|
-
nuxt.options.build.extend = chainFn(nuxt.options.build.extend, fn);
|
|
527
|
-
if (!isNuxt2(nuxt)) {
|
|
528
|
-
console.warn("[kit] [compat] Using `extendBuild` in Nuxt 3 has no effect. Instead call extendWebpackConfig and extendViteConfig.");
|
|
529
|
-
}
|
|
530
|
-
},
|
|
531
|
-
extendRoutes(fn) {
|
|
532
|
-
if (isNuxt2(nuxt)) {
|
|
533
|
-
nuxt.options.router.extendRoutes = chainFn(nuxt.options.router.extendRoutes, fn);
|
|
534
|
-
} else {
|
|
535
|
-
nuxt.hook("pages:extend", async (pages, ...args) => {
|
|
536
|
-
const maybeRoutes = await fn(pages, ...args);
|
|
537
|
-
if (maybeRoutes) {
|
|
538
|
-
console.warn("[kit] [compat] Using `extendRoutes` in Nuxt 3 needs to directly modify first argument instead of returning updated routes. Skipping extended routes.");
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
return nuxt[MODULE_CONTAINER_KEY];
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
async function compileTemplate(template, ctx) {
|
|
548
|
-
const data = { ...ctx, options: template.options };
|
|
549
|
-
if (template.src) {
|
|
550
|
-
try {
|
|
551
|
-
const srcContents = await promises.readFile(template.src, "utf-8");
|
|
552
|
-
return lodashTemplate(srcContents, {})(data);
|
|
553
|
-
} catch (err) {
|
|
554
|
-
console.error("Error compiling template: ", template);
|
|
555
|
-
throw err;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (template.getContents) {
|
|
559
|
-
return template.getContents(data);
|
|
560
|
-
}
|
|
561
|
-
throw new Error("Invalid template: " + JSON.stringify(template));
|
|
562
|
-
}
|
|
563
|
-
const serialize = (data) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, (r) => JSON.parse(r).replace(/^{(.*)}$/, "$1"));
|
|
564
|
-
const importSources = (sources, { lazy = false } = {}) => {
|
|
565
|
-
if (!Array.isArray(sources)) {
|
|
566
|
-
sources = [sources];
|
|
567
|
-
}
|
|
568
|
-
return sources.map((src) => {
|
|
569
|
-
if (lazy) {
|
|
570
|
-
return `const ${genSafeVariableName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
|
|
571
|
-
}
|
|
572
|
-
return genImport(src, genSafeVariableName(src));
|
|
573
|
-
}).join("\n");
|
|
574
|
-
};
|
|
575
|
-
const importName = genSafeVariableName;
|
|
576
|
-
const templateUtils = { serialize, importName, importSources };
|
|
577
|
-
|
|
578
|
-
function defineNuxtModule(definition) {
|
|
579
|
-
if (typeof definition === "function") {
|
|
580
|
-
definition = definition(useNuxt());
|
|
581
|
-
logger.warn("Module definition as function is deprecated and will be removed in the future versions", definition);
|
|
582
|
-
}
|
|
583
|
-
if (!definition.meta) {
|
|
584
|
-
definition.meta = {};
|
|
585
|
-
}
|
|
586
|
-
if (!definition.meta.configKey) {
|
|
587
|
-
definition.meta.name = definition.meta.name || definition.name;
|
|
588
|
-
definition.meta.configKey = definition.configKey || definition.meta.name;
|
|
589
|
-
}
|
|
590
|
-
function getOptions(inlineOptions, nuxt = useNuxt()) {
|
|
591
|
-
const configKey = definition.meta.configKey || definition.meta.name;
|
|
592
|
-
const _defaults = definition.defaults instanceof Function ? definition.defaults(nuxt) : definition.defaults;
|
|
593
|
-
let _options = defu(inlineOptions, nuxt.options[configKey], _defaults);
|
|
594
|
-
if (definition.schema) {
|
|
595
|
-
_options = applyDefaults(definition.schema, _options);
|
|
596
|
-
}
|
|
597
|
-
return Promise.resolve(_options);
|
|
598
|
-
}
|
|
599
|
-
async function normalizedModule(inlineOptions, nuxt) {
|
|
600
|
-
if (!nuxt) {
|
|
601
|
-
nuxt = tryUseNuxt() || this.nuxt;
|
|
602
|
-
}
|
|
603
|
-
const uniqueKey = definition.meta.name || definition.meta.configKey;
|
|
604
|
-
if (uniqueKey) {
|
|
605
|
-
nuxt.options._requiredModules = nuxt.options._requiredModules || {};
|
|
606
|
-
if (nuxt.options._requiredModules[uniqueKey]) {
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
609
|
-
nuxt.options._requiredModules[uniqueKey] = true;
|
|
610
|
-
}
|
|
611
|
-
if (definition.meta.compatibility) {
|
|
612
|
-
const issues = await checkNuxtCompatibility(definition.meta.compatibility, nuxt);
|
|
613
|
-
if (issues.length) {
|
|
614
|
-
logger.warn(`Module \`${definition.meta.name}\` is disabled due to incompatibility issues:
|
|
615
|
-
${issues.toString()}`);
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
nuxt2Shims(nuxt);
|
|
620
|
-
const _options = await getOptions(inlineOptions, nuxt);
|
|
621
|
-
if (definition.hooks) {
|
|
622
|
-
nuxt.hooks.addHooks(definition.hooks);
|
|
623
|
-
}
|
|
624
|
-
await definition.setup?.call(null, _options, nuxt);
|
|
625
|
-
}
|
|
626
|
-
normalizedModule.getMeta = () => Promise.resolve(definition.meta);
|
|
627
|
-
normalizedModule.getOptions = getOptions;
|
|
628
|
-
return normalizedModule;
|
|
629
|
-
}
|
|
630
|
-
const NUXT2_SHIMS_KEY = "__nuxt2_shims_key__";
|
|
631
|
-
function nuxt2Shims(nuxt) {
|
|
632
|
-
if (!isNuxt2(nuxt) || nuxt[NUXT2_SHIMS_KEY]) {
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
nuxt[NUXT2_SHIMS_KEY] = true;
|
|
636
|
-
nuxt.hooks = nuxt;
|
|
637
|
-
if (!nuxtCtx.tryUse()) {
|
|
638
|
-
nuxtCtx.set(nuxt);
|
|
639
|
-
nuxt.hook("close", () => nuxtCtx.unset());
|
|
640
|
-
}
|
|
641
|
-
let virtualTemplates;
|
|
642
|
-
nuxt.hook("builder:prepared", (_builder, buildOptions) => {
|
|
643
|
-
virtualTemplates = buildOptions.templates.filter((t) => t.getContents);
|
|
644
|
-
for (const template of virtualTemplates) {
|
|
645
|
-
buildOptions.templates.splice(buildOptions.templates.indexOf(template), 1);
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
nuxt.hook("build:templates", async (templates) => {
|
|
649
|
-
const context = {
|
|
650
|
-
nuxt,
|
|
651
|
-
utils: templateUtils,
|
|
652
|
-
app: {
|
|
653
|
-
dir: nuxt.options.srcDir,
|
|
654
|
-
extensions: nuxt.options.extensions,
|
|
655
|
-
plugins: nuxt.options.plugins,
|
|
656
|
-
templates: [
|
|
657
|
-
...templates.templatesFiles,
|
|
658
|
-
...virtualTemplates
|
|
659
|
-
],
|
|
660
|
-
templateVars: templates.templateVars
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
for await (const template of virtualTemplates) {
|
|
664
|
-
const contents = await compileTemplate({ ...template, src: "" }, context);
|
|
665
|
-
await promises.mkdir(dirname(template.dst), { recursive: true });
|
|
666
|
-
await promises.writeFile(template.dst, contents);
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
|
|
671
444
|
async function loadNuxtConfig(opts) {
|
|
672
|
-
|
|
445
|
+
globalThis.defineNuxtConfig = (c) => c;
|
|
446
|
+
const result = await loadConfig({
|
|
673
447
|
name: "nuxt",
|
|
674
448
|
configFile: "nuxt.config",
|
|
675
449
|
rcFile: ".nuxtrc",
|
|
450
|
+
extend: { extendKey: ["theme", "extends"] },
|
|
676
451
|
dotenv: true,
|
|
677
452
|
globalRc: true,
|
|
678
453
|
...opts
|
|
679
454
|
});
|
|
455
|
+
delete globalThis.defineNuxtConfig;
|
|
456
|
+
const { configFile, layers = [], cwd } = result;
|
|
457
|
+
const nuxtConfig = result.config;
|
|
680
458
|
nuxtConfig.rootDir = nuxtConfig.rootDir || cwd;
|
|
681
459
|
nuxtConfig._nuxtConfigFile = configFile;
|
|
682
460
|
nuxtConfig._nuxtConfigFiles = [configFile];
|
|
683
461
|
for (const layer of layers) {
|
|
462
|
+
layer.config = layer.config || {};
|
|
684
463
|
layer.config.rootDir = layer.config.rootDir ?? layer.cwd;
|
|
685
464
|
layer.config.srcDir = resolve(layer.config.rootDir, layer.config.srcDir);
|
|
686
465
|
}
|
|
687
|
-
|
|
688
|
-
|
|
466
|
+
const _layers = layers.filter((layer) => layer.configFile && !layer.configFile.endsWith(".nuxtrc"));
|
|
467
|
+
nuxtConfig._layers = _layers;
|
|
468
|
+
if (!_layers.length) {
|
|
469
|
+
_layers.push({
|
|
470
|
+
cwd,
|
|
471
|
+
config: {
|
|
472
|
+
rootDir: cwd,
|
|
473
|
+
srcDir: cwd
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return await applyDefaults(NuxtConfigSchema, nuxtConfig);
|
|
689
478
|
}
|
|
690
479
|
|
|
691
480
|
async function loadNuxt(opts) {
|
|
@@ -724,17 +513,25 @@ async function buildNuxt(nuxt) {
|
|
|
724
513
|
return build(nuxt);
|
|
725
514
|
}
|
|
726
515
|
|
|
727
|
-
function
|
|
516
|
+
function addImports(imports) {
|
|
517
|
+
assertNuxtCompatibility({ bridge: true });
|
|
518
|
+
useNuxt().hook("imports:extend", (_imports) => {
|
|
519
|
+
_imports.push(...Array.isArray(imports) ? imports : [imports]);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function addImportsDir(dirs) {
|
|
728
523
|
assertNuxtCompatibility({ bridge: true });
|
|
729
|
-
useNuxt().hook("
|
|
730
|
-
|
|
524
|
+
useNuxt().hook("imports:dirs", (_dirs) => {
|
|
525
|
+
for (const dir of Array.isArray(dirs) ? dirs : [dirs]) {
|
|
526
|
+
_dirs.push(dir);
|
|
527
|
+
}
|
|
731
528
|
});
|
|
732
529
|
}
|
|
733
|
-
function
|
|
530
|
+
function addImportsSources(presets) {
|
|
734
531
|
assertNuxtCompatibility({ bridge: true });
|
|
735
|
-
useNuxt().hook("
|
|
736
|
-
for (const
|
|
737
|
-
|
|
532
|
+
useNuxt().hook("imports:sources", (_presets) => {
|
|
533
|
+
for (const preset of Array.isArray(presets) ? presets : [presets]) {
|
|
534
|
+
_presets.push(preset);
|
|
738
535
|
}
|
|
739
536
|
});
|
|
740
537
|
}
|
|
@@ -760,12 +557,6 @@ function extendWebpackConfig(fn, options = {}) {
|
|
|
760
557
|
fn(config);
|
|
761
558
|
}
|
|
762
559
|
}
|
|
763
|
-
if (options.modern !== false) {
|
|
764
|
-
const config = configs.find((i) => i.name === "modern");
|
|
765
|
-
if (config) {
|
|
766
|
-
fn(config);
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
560
|
});
|
|
770
561
|
}
|
|
771
562
|
function extendViteConfig(fn, options = {}) {
|
|
@@ -791,13 +582,21 @@ function extendViteConfig(fn, options = {}) {
|
|
|
791
582
|
function addWebpackPlugin(plugin, options) {
|
|
792
583
|
extendWebpackConfig((config) => {
|
|
793
584
|
config.plugins = config.plugins || [];
|
|
794
|
-
|
|
585
|
+
if (Array.isArray(plugin)) {
|
|
586
|
+
config.plugins.push(...plugin);
|
|
587
|
+
} else {
|
|
588
|
+
config.plugins.push(plugin);
|
|
589
|
+
}
|
|
795
590
|
}, options);
|
|
796
591
|
}
|
|
797
592
|
function addVitePlugin(plugin, options) {
|
|
798
593
|
extendViteConfig((config) => {
|
|
799
594
|
config.plugins = config.plugins || [];
|
|
800
|
-
|
|
595
|
+
if (Array.isArray(plugin)) {
|
|
596
|
+
config.plugins.push(...plugin);
|
|
597
|
+
} else {
|
|
598
|
+
config.plugins.push(plugin);
|
|
599
|
+
}
|
|
801
600
|
}, options);
|
|
802
601
|
}
|
|
803
602
|
|
|
@@ -823,10 +622,6 @@ async function addComponent(opts) {
|
|
|
823
622
|
preload: false,
|
|
824
623
|
mode: "all",
|
|
825
624
|
shortPath: opts.filePath,
|
|
826
|
-
async: false,
|
|
827
|
-
level: 0,
|
|
828
|
-
asyncImport: `${genDynamicImport(opts.filePath)}.then(r => r['${opts.export || "default"}'])`,
|
|
829
|
-
import: `require(${JSON.stringify(opts.filePath)})['${opts.export || "default"}']`,
|
|
830
625
|
...opts
|
|
831
626
|
};
|
|
832
627
|
nuxt.hook("components:extend", (components) => {
|
|
@@ -841,6 +636,81 @@ async function addComponent(opts) {
|
|
|
841
636
|
});
|
|
842
637
|
}
|
|
843
638
|
|
|
639
|
+
function addTemplate(_template) {
|
|
640
|
+
const nuxt = useNuxt();
|
|
641
|
+
const template = normalizeTemplate(_template);
|
|
642
|
+
nuxt.options.build.templates = nuxt.options.build.templates.filter((p) => normalizeTemplate(p).filename !== template.filename);
|
|
643
|
+
nuxt.options.build.templates.push(template);
|
|
644
|
+
return template;
|
|
645
|
+
}
|
|
646
|
+
function normalizeTemplate(template) {
|
|
647
|
+
if (!template) {
|
|
648
|
+
throw new Error("Invalid template: " + JSON.stringify(template));
|
|
649
|
+
}
|
|
650
|
+
if (typeof template === "string") {
|
|
651
|
+
template = { src: template };
|
|
652
|
+
} else {
|
|
653
|
+
template = { ...template };
|
|
654
|
+
}
|
|
655
|
+
if (template.src) {
|
|
656
|
+
if (!existsSync(template.src)) {
|
|
657
|
+
throw new Error("Template not found: " + template.src);
|
|
658
|
+
}
|
|
659
|
+
if (!template.filename) {
|
|
660
|
+
const srcPath = parse(template.src);
|
|
661
|
+
template.filename = template.fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hash(template.src)}${srcPath.ext}`;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (!template.src && !template.getContents) {
|
|
665
|
+
throw new Error("Invalid template. Either getContents or src options should be provided: " + JSON.stringify(template));
|
|
666
|
+
}
|
|
667
|
+
if (!template.filename) {
|
|
668
|
+
throw new Error("Invalid template. Either filename should be provided: " + JSON.stringify(template));
|
|
669
|
+
}
|
|
670
|
+
if (template.filename.endsWith(".d.ts")) {
|
|
671
|
+
template.write = true;
|
|
672
|
+
}
|
|
673
|
+
if (!template.dst) {
|
|
674
|
+
const nuxt = useNuxt();
|
|
675
|
+
template.dst = resolve(nuxt.options.buildDir, template.filename);
|
|
676
|
+
}
|
|
677
|
+
return template;
|
|
678
|
+
}
|
|
679
|
+
function updateTemplates(options) {
|
|
680
|
+
return useNuxt().hooks.callHook("builder:generateApp", options);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function addLayout(template, name) {
|
|
684
|
+
const nuxt = useNuxt();
|
|
685
|
+
const { filename, src } = addTemplate(template);
|
|
686
|
+
const layoutName = kebabCase(name || parse(filename).name).replace(/["']/g, "");
|
|
687
|
+
if (isNuxt2(nuxt)) {
|
|
688
|
+
const layout = nuxt.options.layouts[layoutName];
|
|
689
|
+
if (layout) {
|
|
690
|
+
return logger.warn(
|
|
691
|
+
`Not overriding \`${layoutName}\` (provided by \`${layout}\`) with \`${src || filename}\`.`
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
nuxt.options.layouts[layoutName] = `./${filename}`;
|
|
695
|
+
if (name === "error") {
|
|
696
|
+
this.addErrorLayout(filename);
|
|
697
|
+
}
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
nuxt.hook("app:templates", (app) => {
|
|
701
|
+
if (layoutName in app.layouts) {
|
|
702
|
+
const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName].file);
|
|
703
|
+
return logger.warn(
|
|
704
|
+
`Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.`
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
app.layouts[layoutName] = {
|
|
708
|
+
file: join("#build", filename),
|
|
709
|
+
name: layoutName
|
|
710
|
+
};
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
|
|
844
714
|
function extendPages(cb) {
|
|
845
715
|
const nuxt = useNuxt();
|
|
846
716
|
if (isNuxt2(nuxt)) {
|
|
@@ -850,4 +720,77 @@ function extendPages(cb) {
|
|
|
850
720
|
}
|
|
851
721
|
}
|
|
852
722
|
|
|
853
|
-
|
|
723
|
+
function normalizePlugin(plugin) {
|
|
724
|
+
if (typeof plugin === "string") {
|
|
725
|
+
plugin = { src: plugin };
|
|
726
|
+
} else {
|
|
727
|
+
plugin = { ...plugin };
|
|
728
|
+
}
|
|
729
|
+
if (!plugin.src) {
|
|
730
|
+
throw new Error("Invalid plugin. src option is required: " + JSON.stringify(plugin));
|
|
731
|
+
}
|
|
732
|
+
plugin.src = normalize(resolveAlias(plugin.src));
|
|
733
|
+
if (plugin.ssr) {
|
|
734
|
+
plugin.mode = "server";
|
|
735
|
+
}
|
|
736
|
+
if (!plugin.mode) {
|
|
737
|
+
const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
|
|
738
|
+
plugin.mode = mode;
|
|
739
|
+
}
|
|
740
|
+
return plugin;
|
|
741
|
+
}
|
|
742
|
+
function addPlugin(_plugin, opts = {}) {
|
|
743
|
+
const nuxt = useNuxt();
|
|
744
|
+
const plugin = normalizePlugin(_plugin);
|
|
745
|
+
nuxt.options.plugins = nuxt.options.plugins.filter((p) => normalizePlugin(p).src !== plugin.src);
|
|
746
|
+
nuxt.options.plugins[opts.append ? "push" : "unshift"](plugin);
|
|
747
|
+
return plugin;
|
|
748
|
+
}
|
|
749
|
+
function addPluginTemplate(plugin, opts = {}) {
|
|
750
|
+
const normalizedPlugin = typeof plugin === "string" ? { src: plugin } : { ...plugin, src: addTemplate(plugin).dst };
|
|
751
|
+
return addPlugin(normalizedPlugin, opts);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function normalizeHandlerMethod(handler) {
|
|
755
|
+
const [, method = void 0] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || [];
|
|
756
|
+
return {
|
|
757
|
+
method,
|
|
758
|
+
...handler,
|
|
759
|
+
handler: normalize(handler.handler)
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
function addServerHandler(handler) {
|
|
763
|
+
useNuxt().options.serverHandlers.push(normalizeHandlerMethod(handler));
|
|
764
|
+
}
|
|
765
|
+
function addDevServerHandler(handler) {
|
|
766
|
+
useNuxt().options.devServerHandlers.push(handler);
|
|
767
|
+
}
|
|
768
|
+
function addServerPlugin(plugin) {
|
|
769
|
+
const nuxt = useNuxt();
|
|
770
|
+
nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || [];
|
|
771
|
+
nuxt.options.nitro.plugins.push(normalize(plugin));
|
|
772
|
+
}
|
|
773
|
+
function addPrerenderRoutes(routes) {
|
|
774
|
+
const nuxt = useNuxt();
|
|
775
|
+
if (!Array.isArray(routes)) {
|
|
776
|
+
routes = [routes];
|
|
777
|
+
}
|
|
778
|
+
routes = routes.filter(Boolean);
|
|
779
|
+
if (!routes.length) {
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
nuxt.hook("prerender:routes", (ctx) => {
|
|
783
|
+
for (const route of routes) {
|
|
784
|
+
ctx.routes.add(route);
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
function useNitro() {
|
|
789
|
+
const nuxt = useNuxt();
|
|
790
|
+
if (!nuxt._nitro) {
|
|
791
|
+
throw new Error("Nitro is not initialized yet. You can call `useNitro()` only after `ready` hook.");
|
|
792
|
+
}
|
|
793
|
+
return nuxt._nitro;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export { 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, useNitro, useNuxt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/kit",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"repository": "nuxt/framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,28 +9,25 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"prepack": "unbuild"
|
|
14
|
-
},
|
|
15
12
|
"dependencies": {
|
|
16
|
-
"@nuxt/schema": "3.0.0
|
|
17
|
-
"c12": "^0.
|
|
13
|
+
"@nuxt/schema": "3.0.0",
|
|
14
|
+
"c12": "^1.0.1",
|
|
18
15
|
"consola": "^2.15.3",
|
|
19
|
-
"defu": "^6.
|
|
16
|
+
"defu": "^6.1.1",
|
|
20
17
|
"globby": "^13.1.2",
|
|
21
18
|
"hash-sum": "^2.0.0",
|
|
22
19
|
"ignore": "^5.2.0",
|
|
23
|
-
"jiti": "^1.
|
|
24
|
-
"knitwork": "^0.
|
|
20
|
+
"jiti": "^1.16.0",
|
|
21
|
+
"knitwork": "^1.0.0",
|
|
25
22
|
"lodash.template": "^4.5.0",
|
|
26
|
-
"mlly": "^0.
|
|
27
|
-
"pathe": "^0.
|
|
28
|
-
"pkg-types": "^0.
|
|
29
|
-
"scule": "^0.
|
|
30
|
-
"semver": "^7.3.
|
|
31
|
-
"unctx": "^2.0
|
|
32
|
-
"unimport": "^0.
|
|
33
|
-
"untyped": "^0.
|
|
23
|
+
"mlly": "^1.0.0",
|
|
24
|
+
"pathe": "^1.0.0",
|
|
25
|
+
"pkg-types": "^1.0.1",
|
|
26
|
+
"scule": "^1.0.0",
|
|
27
|
+
"semver": "^7.3.8",
|
|
28
|
+
"unctx": "^2.1.0",
|
|
29
|
+
"unimport": "^1.0.1",
|
|
30
|
+
"untyped": "^1.0.0"
|
|
34
31
|
},
|
|
35
32
|
"devDependencies": {
|
|
36
33
|
"@types/lodash.template": "^4",
|
|
@@ -38,6 +35,7 @@
|
|
|
38
35
|
"unbuild": "latest"
|
|
39
36
|
},
|
|
40
37
|
"engines": {
|
|
41
|
-
"node": "^14.16.0 || ^16.
|
|
42
|
-
}
|
|
43
|
-
}
|
|
38
|
+
"node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {}
|
|
41
|
+
}
|