@nuxt/kit 4.3.0 → 4.3.1
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/README.md +1 -1
- package/dist/THIRD-PARTY-LICENSES.md +1129 -0
- package/dist/_chunks/libs/@oxc-project/types.d.mts +1300 -0
- package/dist/_chunks/libs/@rolldown/pluginutils.d.mts +63 -0
- package/dist/_chunks/libs/@rollup/plugin-commonjs.d.mts +1345 -0
- package/dist/_chunks/libs/@vercel/nft.d.mts +114 -0
- package/dist/_chunks/libs/chokidar.d.mts +34 -0
- package/dist/_chunks/libs/compatx.d.mts +47 -0
- package/dist/_chunks/libs/crossws.d.mts +7 -0
- package/dist/_chunks/libs/db0.d.mts +8 -0
- package/dist/_chunks/libs/esbuild.d.mts +137 -0
- package/dist/_chunks/libs/httpxy.d.mts +79 -0
- package/dist/_chunks/libs/ioredis.d.mts +6 -0
- package/dist/_chunks/libs/listhen.d.mts +7 -0
- package/dist/_chunks/libs/magic-string.d.mts +220 -0
- package/dist/_chunks/libs/nitro.d.mts +9879 -0
- package/dist/_chunks/libs/nitropack.d.mts +3343 -0
- package/dist/index.d.mts +19 -10
- package/dist/index.mjs +49 -369
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -26,62 +26,27 @@ import { kebabCase, pascalCase, snakeCase } from "scule";
|
|
|
26
26
|
import { klona } from "klona";
|
|
27
27
|
import { hash } from "ohash";
|
|
28
28
|
import { isAbsolute as isAbsolute$1 } from "node:path";
|
|
29
|
-
|
|
30
|
-
//#region src/logger.ts
|
|
31
29
|
const logger = consola;
|
|
32
30
|
function useLogger(tag, options = {}) {
|
|
33
31
|
return tag ? logger.create(options).withTag(tag) : logger;
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/context.ts
|
|
38
|
-
/**
|
|
39
|
-
* Direct access to the Nuxt global context - see https://github.com/unjs/unctx.
|
|
40
|
-
* @deprecated Use `getNuxtCtx` instead
|
|
41
|
-
*/
|
|
42
33
|
const nuxtCtx = getContext("nuxt");
|
|
43
|
-
/** async local storage for the name of the current nuxt instance */
|
|
44
34
|
const asyncNuxtStorage = createContext({
|
|
45
35
|
asyncContext: true,
|
|
46
36
|
AsyncLocalStorage
|
|
47
37
|
});
|
|
48
|
-
/** Direct access to the Nuxt context with asyncLocalStorage - see https://github.com/unjs/unctx. */
|
|
49
38
|
const getNuxtCtx = () => asyncNuxtStorage.tryUse();
|
|
50
|
-
/**
|
|
51
|
-
* Get access to Nuxt instance.
|
|
52
|
-
*
|
|
53
|
-
* Throws an error if Nuxt instance is unavailable.
|
|
54
|
-
* @example
|
|
55
|
-
* ```js
|
|
56
|
-
* const nuxt = useNuxt()
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
39
|
function useNuxt() {
|
|
60
40
|
const instance = asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
|
|
61
41
|
if (!instance) throw new Error("Nuxt instance is unavailable!");
|
|
62
42
|
return instance;
|
|
63
43
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Get access to Nuxt instance.
|
|
66
|
-
*
|
|
67
|
-
* Returns null if Nuxt instance is unavailable.
|
|
68
|
-
* @example
|
|
69
|
-
* ```js
|
|
70
|
-
* const nuxt = tryUseNuxt()
|
|
71
|
-
* if (nuxt) {
|
|
72
|
-
* // Do something
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
44
|
function tryUseNuxt() {
|
|
77
45
|
return asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
|
|
78
46
|
}
|
|
79
47
|
function runWithNuxtContext(nuxt, fn) {
|
|
80
48
|
return asyncNuxtStorage.call(nuxt, fn);
|
|
81
49
|
}
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/compatibility.ts
|
|
85
50
|
const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
|
|
86
51
|
function normalizeSemanticVersion(version) {
|
|
87
52
|
return version.replace(SEMANTIC_VERSION_RE, "");
|
|
@@ -94,9 +59,6 @@ const builderMap = {
|
|
|
94
59
|
function checkNuxtVersion(version, nuxt = useNuxt()) {
|
|
95
60
|
return satisfies(normalizeSemanticVersion(getNuxtVersion(nuxt)), version, { includePrerelease: true });
|
|
96
61
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Check version constraints and return incompatibility issues as an array
|
|
99
|
-
*/
|
|
100
62
|
async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
101
63
|
const issues = [];
|
|
102
64
|
if (constraints.nuxt) {
|
|
@@ -134,54 +96,33 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
|
134
96
|
issues.toString = () => issues.map((issue) => ` - [${issue.name}] ${issue.message}`).join("\n");
|
|
135
97
|
return issues;
|
|
136
98
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Check version constraints and throw a detailed error if has any, otherwise returns true
|
|
139
|
-
*/
|
|
140
99
|
async function assertNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
141
100
|
const issues = await checkNuxtCompatibility(constraints, nuxt);
|
|
142
101
|
if (issues.length) throw new Error("Nuxt compatibility issues found:\n" + issues.toString());
|
|
143
102
|
return true;
|
|
144
103
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Check version constraints and return true if passed, otherwise returns false
|
|
147
|
-
*/
|
|
148
104
|
async function hasNuxtCompatibility(constraints, nuxt = useNuxt()) {
|
|
149
105
|
return !(await checkNuxtCompatibility(constraints, nuxt)).length;
|
|
150
106
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Check if current Nuxt instance is of specified major version
|
|
153
|
-
*/
|
|
154
107
|
function isNuxtMajorVersion(majorVersion, nuxt = useNuxt()) {
|
|
155
108
|
const version = getNuxtVersion(nuxt);
|
|
156
109
|
return version[0] === majorVersion.toString() && version[1] === ".";
|
|
157
110
|
}
|
|
158
|
-
/**
|
|
159
|
-
* @deprecated Use `isNuxtMajorVersion(2, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version.
|
|
160
|
-
*/
|
|
161
111
|
function isNuxt2(nuxt = useNuxt()) {
|
|
162
112
|
return isNuxtMajorVersion(2, nuxt);
|
|
163
113
|
}
|
|
164
|
-
/**
|
|
165
|
-
* @deprecated Use `isNuxtMajorVersion(3, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version.
|
|
166
|
-
*/
|
|
167
114
|
function isNuxt3(nuxt = useNuxt()) {
|
|
168
115
|
return isNuxtMajorVersion(3, nuxt);
|
|
169
116
|
}
|
|
170
117
|
const NUXT_VERSION_RE = /^v/g;
|
|
171
|
-
/**
|
|
172
|
-
* Get nuxt version
|
|
173
|
-
*/
|
|
174
118
|
function getNuxtVersion(nuxt = useNuxt()) {
|
|
175
119
|
const rawVersion = nuxt?._version || nuxt?.version || nuxt?.constructor?.version;
|
|
176
120
|
if (typeof rawVersion !== "string") throw new TypeError("Cannot determine nuxt version! Is current instance passed?");
|
|
177
121
|
return rawVersion.replace(NUXT_VERSION_RE, "");
|
|
178
122
|
}
|
|
179
|
-
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/module/define.ts
|
|
182
123
|
function defineNuxtModule(definition) {
|
|
183
124
|
if (definition) return _defineNuxtModule(definition);
|
|
184
|
-
return { with: (definition
|
|
125
|
+
return { with: (definition) => _defineNuxtModule(definition) };
|
|
185
126
|
}
|
|
186
127
|
function _defineNuxtModule(definition) {
|
|
187
128
|
if (typeof definition === "function") return _defineNuxtModule({ setup: definition });
|
|
@@ -236,9 +177,6 @@ function _defineNuxtModule(definition) {
|
|
|
236
177
|
normalizedModule.onUpgrade = module.onUpgrade;
|
|
237
178
|
return normalizedModule;
|
|
238
179
|
}
|
|
239
|
-
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/internal/trace.ts
|
|
242
180
|
const distURL = import.meta.url.replace(/\/dist\/.*$/, "/");
|
|
243
181
|
function getUserCaller() {
|
|
244
182
|
if (!import.meta.dev) return null;
|
|
@@ -257,21 +195,7 @@ function warn(warning) {
|
|
|
257
195
|
warnings.add(warning);
|
|
258
196
|
}
|
|
259
197
|
}
|
|
260
|
-
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/layers.ts
|
|
263
198
|
const layerMap = /* @__PURE__ */ new WeakMap();
|
|
264
|
-
/**
|
|
265
|
-
* Get the resolved directory paths for all layers in a Nuxt application.
|
|
266
|
-
*
|
|
267
|
-
* Returns an array of LayerDirectories objects, ordered by layer priority:
|
|
268
|
-
* - The first layer is the user/project layer (highest priority)
|
|
269
|
-
* - Earlier layers override later layers in the array
|
|
270
|
-
* - Base layers appear last in the array (lowest priority)
|
|
271
|
-
*
|
|
272
|
-
* @param nuxt - The Nuxt instance to get layers from. Defaults to the current Nuxt context.
|
|
273
|
-
* @returns Array of LayerDirectories objects, ordered by priority (user layer first)
|
|
274
|
-
*/
|
|
275
199
|
function getLayerDirectories(nuxt = useNuxt()) {
|
|
276
200
|
return nuxt.options._layers.map((layer) => {
|
|
277
201
|
if (layerMap.has(layer)) return layerMap.get(layer);
|
|
@@ -297,15 +221,9 @@ function getLayerDirectories(nuxt = useNuxt()) {
|
|
|
297
221
|
function withTrailingSlash$2(dir) {
|
|
298
222
|
return dir.replace(/[^/]$/, "$&/");
|
|
299
223
|
}
|
|
300
|
-
|
|
301
|
-
//#endregion
|
|
302
|
-
//#region src/ignore.ts
|
|
303
224
|
function createIsIgnored(nuxt = tryUseNuxt()) {
|
|
304
225
|
return (pathname, stats) => isIgnored(pathname, stats, nuxt);
|
|
305
226
|
}
|
|
306
|
-
/**
|
|
307
|
-
* Return a filter function to filter an array of paths
|
|
308
|
-
*/
|
|
309
227
|
function isIgnored(pathname, _stats, nuxt = tryUseNuxt()) {
|
|
310
228
|
if (!nuxt) return false;
|
|
311
229
|
if (!nuxt._ignore) {
|
|
@@ -333,53 +251,27 @@ function resolveIgnorePatterns(relativePath) {
|
|
|
333
251
|
});
|
|
334
252
|
return ignorePatterns;
|
|
335
253
|
}
|
|
336
|
-
/**
|
|
337
|
-
* This function turns string containing groups '**\/*.{spec,test}.{js,ts}' into an array of strings.
|
|
338
|
-
* For example will '**\/*.{spec,test}.{js,ts}' be resolved to:
|
|
339
|
-
* ['**\/*.spec.js', '**\/*.spec.ts', '**\/*.test.js', '**\/*.test.ts']
|
|
340
|
-
* @param group string containing the group syntax
|
|
341
|
-
* @returns {string[]} array of strings without the group syntax
|
|
342
|
-
*/
|
|
343
254
|
function resolveGroupSyntax(group) {
|
|
344
255
|
let groups = [group];
|
|
345
|
-
while (groups.some((group
|
|
346
|
-
const [head, ...tail] = group
|
|
256
|
+
while (groups.some((group) => group.includes("{"))) groups = groups.flatMap((group) => {
|
|
257
|
+
const [head, ...tail] = group.split("{");
|
|
347
258
|
if (tail.length) {
|
|
348
259
|
const [body = "", ...rest] = tail.join("{").split("}");
|
|
349
260
|
return body.split(",").map((part) => `${head}${part}${rest.join("")}`);
|
|
350
261
|
}
|
|
351
|
-
return group
|
|
262
|
+
return group;
|
|
352
263
|
});
|
|
353
264
|
return groups;
|
|
354
265
|
}
|
|
355
|
-
|
|
356
|
-
//#endregion
|
|
357
|
-
//#region src/utils.ts
|
|
358
|
-
/** @since 3.9.0 */
|
|
359
266
|
function toArray(value) {
|
|
360
267
|
return Array.isArray(value) ? value : [value];
|
|
361
268
|
}
|
|
362
|
-
/**
|
|
363
|
-
* Filter out items from an array in place. This function mutates the array.
|
|
364
|
-
* `predicate` get through the array from the end to the start for performance.
|
|
365
|
-
*
|
|
366
|
-
* This function should be faster than `Array.prototype.filter` on large arrays.
|
|
367
|
-
*/
|
|
368
269
|
function filterInPlace(array, predicate) {
|
|
369
270
|
for (let i = array.length; i--;) if (!predicate(array[i], i, array)) array.splice(i, 1);
|
|
370
271
|
return array;
|
|
371
272
|
}
|
|
372
273
|
const MODE_RE = /\.(server|client)(\.\w+)*$/;
|
|
373
274
|
const distDirURL = new URL(".", import.meta.url);
|
|
374
|
-
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region src/resolve.ts
|
|
377
|
-
/**
|
|
378
|
-
* Resolve the full path to a file or a directory (based on the provided type), respecting Nuxt alias and extensions options.
|
|
379
|
-
*
|
|
380
|
-
* If a path cannot be resolved, normalized input will be returned unless the `fallbackToOriginal` option is set to `true`,
|
|
381
|
-
* in which case the original input path will be returned.
|
|
382
|
-
*/
|
|
383
275
|
async function resolvePath(path, opts = {}) {
|
|
384
276
|
const { type = "file" } = opts;
|
|
385
277
|
const res = await _resolvePathGranularly(path, {
|
|
@@ -389,9 +281,6 @@ async function resolvePath(path, opts = {}) {
|
|
|
389
281
|
if (res.type === type) return res.path;
|
|
390
282
|
return opts.fallbackToOriginal ? path : res.path;
|
|
391
283
|
}
|
|
392
|
-
/**
|
|
393
|
-
* Try to resolve first existing file in paths
|
|
394
|
-
*/
|
|
395
284
|
async function findPath(paths, opts, pathType = "file") {
|
|
396
285
|
for (const path of toArray(paths)) {
|
|
397
286
|
const res = await _resolvePathGranularly(path, {
|
|
@@ -403,16 +292,10 @@ async function findPath(paths, opts, pathType = "file") {
|
|
|
403
292
|
}
|
|
404
293
|
return null;
|
|
405
294
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Resolve path aliases respecting Nuxt alias options
|
|
408
|
-
*/
|
|
409
295
|
function resolveAlias(path, alias) {
|
|
410
296
|
alias ||= tryUseNuxt()?.options.alias || {};
|
|
411
297
|
return resolveAlias$1(path, alias);
|
|
412
298
|
}
|
|
413
|
-
/**
|
|
414
|
-
* Create a relative resolver
|
|
415
|
-
*/
|
|
416
299
|
function createResolver(base) {
|
|
417
300
|
if (!base) throw new Error("`base` argument is missing for createResolver(base)!");
|
|
418
301
|
base = base.toString();
|
|
@@ -470,8 +353,8 @@ async function _resolvePathGranularly(path, opts = { type: "file" }) {
|
|
|
470
353
|
const _path = path;
|
|
471
354
|
path = normalize(path);
|
|
472
355
|
if (isAbsolute(path)) {
|
|
473
|
-
const res
|
|
474
|
-
if (res
|
|
356
|
+
const res = await _resolvePathType(path, opts);
|
|
357
|
+
if (res && res.type === opts.type) return res;
|
|
475
358
|
}
|
|
476
359
|
const nuxt = tryUseNuxt();
|
|
477
360
|
const cwd = opts.cwd || (nuxt ? nuxt.options.rootDir : process.cwd());
|
|
@@ -515,15 +398,6 @@ function existsInVFS(path, nuxt = tryUseNuxt()) {
|
|
|
515
398
|
if (path in nuxt.vfs) return true;
|
|
516
399
|
return (nuxt.apps.default?.templates ?? nuxt.options.build.templates).some((template) => template.dst === path);
|
|
517
400
|
}
|
|
518
|
-
/**
|
|
519
|
-
* Resolve absolute file paths in the provided directory with respect to `.nuxtignore` and return them sorted.
|
|
520
|
-
* @param path path to the directory to resolve files in
|
|
521
|
-
* @param pattern glob pattern or an array of glob patterns to match files
|
|
522
|
-
* @param opts options for globbing
|
|
523
|
-
* @param opts.followSymbolicLinks whether to follow symbolic links, default is `true`
|
|
524
|
-
* @param opts.ignore additional glob patterns to ignore
|
|
525
|
-
* @returns sorted array of absolute file paths
|
|
526
|
-
*/
|
|
527
401
|
async function resolveFiles(path, pattern, opts = {}) {
|
|
528
402
|
const files = [];
|
|
529
403
|
for (const p of await glob(pattern, {
|
|
@@ -534,9 +408,6 @@ async function resolveFiles(path, pattern, opts = {}) {
|
|
|
534
408
|
})) if (!isIgnored(p)) files.push(p);
|
|
535
409
|
return files.sort();
|
|
536
410
|
}
|
|
537
|
-
|
|
538
|
-
//#endregion
|
|
539
|
-
//#region src/internal/esm.ts
|
|
540
411
|
function directoryToURL(dir) {
|
|
541
412
|
return pathToFileURL(dir + "/");
|
|
542
413
|
}
|
|
@@ -568,26 +439,17 @@ function tryImportModule(id, opts) {
|
|
|
568
439
|
return importModule(id, opts).catch(() => void 0);
|
|
569
440
|
} catch {}
|
|
570
441
|
}
|
|
571
|
-
/**
|
|
572
|
-
* @deprecated Please use `importModule` instead.
|
|
573
|
-
*/
|
|
574
442
|
function requireModule(id, opts) {
|
|
575
443
|
const caller = getUserCaller();
|
|
576
444
|
warn(`[@nuxt/kit] \`requireModule\` is deprecated${caller ? ` (used at \`${resolveAlias(caller.source)}:${caller.line}:${caller.column}\`)` : ""}. Please use \`importModule\` instead.`);
|
|
577
445
|
const resolvedPath = resolveModule(id, opts);
|
|
578
446
|
return createJiti(import.meta.url, { interopDefault: opts?.interopDefault !== false })(pathToFileURL(resolvedPath).href);
|
|
579
447
|
}
|
|
580
|
-
/**
|
|
581
|
-
* @deprecated Please use `tryImportModule` instead.
|
|
582
|
-
*/
|
|
583
448
|
function tryRequireModule(id, opts) {
|
|
584
449
|
try {
|
|
585
450
|
return requireModule(id, opts);
|
|
586
451
|
} catch {}
|
|
587
452
|
}
|
|
588
|
-
|
|
589
|
-
//#endregion
|
|
590
|
-
//#region src/module/install.ts
|
|
591
453
|
const NODE_MODULES_RE = /[/\\]node_modules[/\\]/;
|
|
592
454
|
const ignoredConfigKeys = new Set([
|
|
593
455
|
"components",
|
|
@@ -596,10 +458,6 @@ const ignoredConfigKeys = new Set([
|
|
|
596
458
|
"devtools",
|
|
597
459
|
"telemetry"
|
|
598
460
|
]);
|
|
599
|
-
/**
|
|
600
|
-
* Installs a set of modules on a Nuxt instance.
|
|
601
|
-
* @internal
|
|
602
|
-
*/
|
|
603
461
|
async function installModules(modulesToInstall, resolvedModulePaths, nuxt = useNuxt()) {
|
|
604
462
|
const localLayerModuleDirs = [];
|
|
605
463
|
for (const l of nuxt.options._layers) {
|
|
@@ -608,7 +466,16 @@ async function installModules(modulesToInstall, resolvedModulePaths, nuxt = useN
|
|
|
608
466
|
}
|
|
609
467
|
nuxt._moduleOptionsFunctions ||= /* @__PURE__ */ new Map();
|
|
610
468
|
const resolvedModules = [];
|
|
611
|
-
const
|
|
469
|
+
const modulesByMetaName = /* @__PURE__ */ new Map();
|
|
470
|
+
const inlineConfigKeys = new Set(await Promise.all([...modulesToInstall].map(async ([mod]) => {
|
|
471
|
+
if (typeof mod === "string") return;
|
|
472
|
+
const meta = await Promise.resolve(mod.getMeta?.());
|
|
473
|
+
if (meta?.name) modulesByMetaName.set(meta.name, mod);
|
|
474
|
+
if (meta?.configKey) {
|
|
475
|
+
if (meta.configKey !== meta.name) modulesByMetaName.set(meta.configKey, mod);
|
|
476
|
+
return meta.configKey;
|
|
477
|
+
}
|
|
478
|
+
})));
|
|
612
479
|
let error;
|
|
613
480
|
const dependencyMap = /* @__PURE__ */ new Map();
|
|
614
481
|
for (const [key, options] of modulesToInstall) {
|
|
@@ -619,7 +486,7 @@ async function installModules(modulesToInstall, resolvedModulePaths, nuxt = useN
|
|
|
619
486
|
const dependencyMeta = await res.nuxtModule.getModuleDependencies?.(nuxt) || {};
|
|
620
487
|
for (const [name, value] of Object.entries(dependencyMeta)) {
|
|
621
488
|
if (!value.overrides && !value.defaults && !value.version && value.optional) continue;
|
|
622
|
-
const resolvedModule = resolveModuleWithOptions(name, nuxt);
|
|
489
|
+
const resolvedModule = modulesByMetaName.has(name) ? resolveModuleWithOptions(modulesByMetaName.get(name), nuxt) : resolveModuleWithOptions(name, nuxt);
|
|
623
490
|
const moduleToAttribute = typeof key === "string" ? `\`${key}\`` : "a module in `nuxt.options`";
|
|
624
491
|
if (!resolvedModule?.module) {
|
|
625
492
|
const message = `Could not resolve \`${name}\` (specified as a dependency of ${moduleToAttribute}).`;
|
|
@@ -628,7 +495,7 @@ async function installModules(modulesToInstall, resolvedModulePaths, nuxt = useN
|
|
|
628
495
|
}
|
|
629
496
|
if (value.version) {
|
|
630
497
|
const pkg = await readPackageJSON(name, { from: [res.resolvedModulePath, ...nuxt.options.modulesDir].filter(Boolean) }).catch(() => null);
|
|
631
|
-
if (pkg?.version && !semver.satisfies(pkg.version, value.version)) {
|
|
498
|
+
if (pkg?.version && !semver.satisfies(pkg.version, value.version, { includePrerelease: true })) {
|
|
632
499
|
const message = `Module \`${name}\` version (\`${pkg.version}\`) does not satisfy \`${value.version}\` (requested by ${moduleToAttribute}).`;
|
|
633
500
|
error = new TypeError(message);
|
|
634
501
|
}
|
|
@@ -689,10 +556,6 @@ async function installModules(modulesToInstall, resolvedModulePaths, nuxt = useN
|
|
|
689
556
|
}
|
|
690
557
|
delete nuxt._moduleOptionsFunctions;
|
|
691
558
|
}
|
|
692
|
-
/**
|
|
693
|
-
* Installs a module on a Nuxt instance.
|
|
694
|
-
* @deprecated Use module dependencies.
|
|
695
|
-
*/
|
|
696
559
|
async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
|
|
697
560
|
const { nuxtModule, buildTimeModuleMeta, resolvedModulePath } = await loadNuxtModuleInstance(moduleToInstall, nuxt);
|
|
698
561
|
const localLayerModuleDirs = [];
|
|
@@ -867,36 +730,19 @@ async function callModule(nuxt, nuxtModule, moduleOptions = {}, options) {
|
|
|
867
730
|
entryPath
|
|
868
731
|
});
|
|
869
732
|
}
|
|
870
|
-
|
|
871
|
-
//#endregion
|
|
872
|
-
//#region src/module/compatibility.ts
|
|
873
733
|
function resolveNuxtModuleEntryName(m) {
|
|
874
734
|
if (typeof m === "object" && !Array.isArray(m)) return m.name;
|
|
875
735
|
if (Array.isArray(m)) return resolveNuxtModuleEntryName(m[0]);
|
|
876
736
|
return m || false;
|
|
877
737
|
}
|
|
878
|
-
/**
|
|
879
|
-
* Check if a Nuxt module is installed by name.
|
|
880
|
-
*
|
|
881
|
-
* This will check both the installed modules and the modules to be installed. Note
|
|
882
|
-
* that it cannot detect if a module is _going to be_ installed programmatically by another module.
|
|
883
|
-
*/
|
|
884
738
|
function hasNuxtModule(moduleName, nuxt = useNuxt()) {
|
|
885
739
|
return nuxt.options._installedModules.some(({ meta }) => meta.name === moduleName) || nuxt.options.modules.some((m) => moduleName === resolveNuxtModuleEntryName(m));
|
|
886
740
|
}
|
|
887
|
-
/**
|
|
888
|
-
* Checks if a Nuxt module is compatible with a given semver version.
|
|
889
|
-
*/
|
|
890
741
|
async function hasNuxtModuleCompatibility(module, semverVersion, nuxt = useNuxt()) {
|
|
891
742
|
const version = await getNuxtModuleVersion(module, nuxt);
|
|
892
743
|
if (!version) return false;
|
|
893
744
|
return satisfies(normalizeSemanticVersion(version), semverVersion, { includePrerelease: true });
|
|
894
745
|
}
|
|
895
|
-
/**
|
|
896
|
-
* Get the version of a Nuxt module.
|
|
897
|
-
*
|
|
898
|
-
* Scans installed modules for the version, if it's not found it will attempt to load the module instance and get the version from there.
|
|
899
|
-
*/
|
|
900
746
|
async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
|
|
901
747
|
const moduleMeta = (typeof module === "string" ? { name: module } : await module.getMeta?.()) || {};
|
|
902
748
|
if (moduleMeta.version) return moduleMeta.version;
|
|
@@ -908,9 +754,6 @@ async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
|
|
|
908
754
|
}
|
|
909
755
|
return false;
|
|
910
756
|
}
|
|
911
|
-
|
|
912
|
-
//#endregion
|
|
913
|
-
//#region src/loader/config.ts
|
|
914
757
|
const merger = createDefu((obj, key, value) => {
|
|
915
758
|
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
916
759
|
obj[key] = obj[key].concat(value);
|
|
@@ -1022,47 +865,35 @@ async function withDefineNuxtConfig(fn) {
|
|
|
1022
865
|
if (!globalSelf[key].count) delete globalSelf[key];
|
|
1023
866
|
}
|
|
1024
867
|
}
|
|
1025
|
-
|
|
1026
|
-
//#endregion
|
|
1027
|
-
//#region src/loader/schema.ts
|
|
1028
868
|
function extendNuxtSchema(def) {
|
|
1029
869
|
useNuxt().hook("schema:extend", (schemas) => {
|
|
1030
870
|
schemas.push(typeof def === "function" ? def() : def);
|
|
1031
871
|
});
|
|
1032
872
|
}
|
|
1033
|
-
|
|
1034
|
-
//#endregion
|
|
1035
|
-
//#region src/loader/nuxt.ts
|
|
1036
873
|
async function loadNuxt(opts) {
|
|
1037
874
|
opts.cwd = resolve(opts.cwd || opts.rootDir || ".");
|
|
1038
875
|
opts.overrides ||= opts.config || {};
|
|
1039
876
|
opts.overrides.dev = !!opts.dev;
|
|
1040
|
-
const resolvedPath = ["nuxt-nightly", "nuxt"].reduce((resolvedPath
|
|
877
|
+
const resolvedPath = ["nuxt-nightly", "nuxt"].reduce((resolvedPath, pkg) => {
|
|
1041
878
|
const path = resolveModulePath(pkg, {
|
|
1042
879
|
try: true,
|
|
1043
880
|
from: [directoryToURL(opts.cwd)]
|
|
1044
881
|
});
|
|
1045
|
-
return path && path.length > resolvedPath
|
|
882
|
+
return path && path.length > resolvedPath.length ? path : resolvedPath;
|
|
1046
883
|
}, "");
|
|
1047
884
|
if (!resolvedPath) throw new Error(`Cannot find any nuxt version from ${opts.cwd}`);
|
|
1048
|
-
const { loadNuxt
|
|
1049
|
-
return await loadNuxt
|
|
885
|
+
const { loadNuxt } = await import(pathToFileURL(resolvedPath).href).then((r) => interopDefault(r));
|
|
886
|
+
return await loadNuxt(opts);
|
|
1050
887
|
}
|
|
1051
888
|
async function buildNuxt(nuxt) {
|
|
1052
889
|
const rootURL = directoryToURL(nuxt.options.rootDir);
|
|
1053
890
|
const { build } = await tryImportModule("nuxt-nightly", { url: rootURL }) || await importModule("nuxt", { url: rootURL });
|
|
1054
891
|
return runWithNuxtContext(nuxt, () => build(nuxt));
|
|
1055
892
|
}
|
|
1056
|
-
|
|
1057
|
-
//#endregion
|
|
1058
|
-
//#region src/head.ts
|
|
1059
893
|
function setGlobalHead(head) {
|
|
1060
894
|
const nuxt = useNuxt();
|
|
1061
895
|
nuxt.options.app.head = defu(head, nuxt.options.app.head);
|
|
1062
896
|
}
|
|
1063
|
-
|
|
1064
|
-
//#endregion
|
|
1065
|
-
//#region src/imports.ts
|
|
1066
897
|
function addImports(imports) {
|
|
1067
898
|
useNuxt().hook("imports:extend", (_imports) => {
|
|
1068
899
|
_imports.push(...toArray(imports));
|
|
@@ -1078,14 +909,7 @@ function addImportsSources(presets) {
|
|
|
1078
909
|
for (const preset of toArray(presets)) _presets.push(preset);
|
|
1079
910
|
});
|
|
1080
911
|
}
|
|
1081
|
-
|
|
1082
|
-
//#endregion
|
|
1083
|
-
//#region src/nitro.ts
|
|
1084
912
|
const HANDLER_METHOD_RE = /\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/;
|
|
1085
|
-
/**
|
|
1086
|
-
* normalize handler object
|
|
1087
|
-
*
|
|
1088
|
-
*/
|
|
1089
913
|
function normalizeHandlerMethod(handler) {
|
|
1090
914
|
const [, method = void 0] = handler.handler.match(HANDLER_METHOD_RE) || [];
|
|
1091
915
|
return {
|
|
@@ -1094,31 +918,17 @@ function normalizeHandlerMethod(handler) {
|
|
|
1094
918
|
handler: normalize(handler.handler)
|
|
1095
919
|
};
|
|
1096
920
|
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Adds a nitro server handler
|
|
1099
|
-
*
|
|
1100
|
-
*/
|
|
1101
921
|
function addServerHandler(handler) {
|
|
1102
922
|
useNuxt().options.serverHandlers.push(normalizeHandlerMethod(handler));
|
|
1103
923
|
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Adds a nitro server handler for development-only
|
|
1106
|
-
*
|
|
1107
|
-
*/
|
|
1108
924
|
function addDevServerHandler(handler) {
|
|
1109
925
|
useNuxt().options.devServerHandlers.push(handler);
|
|
1110
926
|
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Adds a Nitro plugin
|
|
1113
|
-
*/
|
|
1114
927
|
function addServerPlugin(plugin) {
|
|
1115
928
|
const nuxt = useNuxt();
|
|
1116
929
|
nuxt.options.nitro.plugins ||= [];
|
|
1117
930
|
nuxt.options.nitro.plugins.push(normalize(plugin));
|
|
1118
931
|
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Adds routes to be prerendered
|
|
1121
|
-
*/
|
|
1122
932
|
function addPrerenderRoutes(routes) {
|
|
1123
933
|
const nuxt = useNuxt();
|
|
1124
934
|
routes = toArray(routes).filter(Boolean);
|
|
@@ -1127,28 +937,11 @@ function addPrerenderRoutes(routes) {
|
|
|
1127
937
|
for (const route of routes) ctx.routes.add(route);
|
|
1128
938
|
});
|
|
1129
939
|
}
|
|
1130
|
-
/**
|
|
1131
|
-
* Access to the Nitro instance
|
|
1132
|
-
*
|
|
1133
|
-
* **Note:** You can call `useNitro()` only after `ready` hook.
|
|
1134
|
-
*
|
|
1135
|
-
* **Note:** Changes to the Nitro instance configuration are not applied.
|
|
1136
|
-
* @example
|
|
1137
|
-
*
|
|
1138
|
-
* ```ts
|
|
1139
|
-
* nuxt.hook('ready', () => {
|
|
1140
|
-
* console.log(useNitro())
|
|
1141
|
-
* })
|
|
1142
|
-
* ```
|
|
1143
|
-
*/
|
|
1144
940
|
function useNitro() {
|
|
1145
941
|
const nuxt = useNuxt();
|
|
1146
942
|
if (!nuxt._nitro) throw new Error("Nitro is not initialized yet. You can call `useNitro()` only after `ready` hook.");
|
|
1147
943
|
return nuxt._nitro;
|
|
1148
944
|
}
|
|
1149
|
-
/**
|
|
1150
|
-
* Add server imports to be auto-imported by Nitro
|
|
1151
|
-
*/
|
|
1152
945
|
function addServerImports(imports) {
|
|
1153
946
|
const nuxt = useNuxt();
|
|
1154
947
|
const _imports = toArray(imports);
|
|
@@ -1158,9 +951,6 @@ function addServerImports(imports) {
|
|
|
1158
951
|
config.imports.imports.push(..._imports);
|
|
1159
952
|
});
|
|
1160
953
|
}
|
|
1161
|
-
/**
|
|
1162
|
-
* Add directories to be scanned for auto-imports by Nitro
|
|
1163
|
-
*/
|
|
1164
954
|
function addServerImportsDir(dirs, opts = {}) {
|
|
1165
955
|
const nuxt = useNuxt();
|
|
1166
956
|
const _dirs = toArray(dirs);
|
|
@@ -1170,24 +960,12 @@ function addServerImportsDir(dirs, opts = {}) {
|
|
|
1170
960
|
config.imports.dirs[opts.prepend ? "unshift" : "push"](..._dirs);
|
|
1171
961
|
});
|
|
1172
962
|
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Add directories to be scanned by Nitro. It will check for subdirectories,
|
|
1175
|
-
* which will be registered just like the `~/server` folder is.
|
|
1176
|
-
*/
|
|
1177
963
|
function addServerScanDir(dirs, opts = {}) {
|
|
1178
964
|
useNuxt().hook("nitro:config", (config) => {
|
|
1179
965
|
config.scanDirs ||= [];
|
|
1180
966
|
for (const dir of toArray(dirs)) config.scanDirs[opts.prepend ? "unshift" : "push"](dir);
|
|
1181
967
|
});
|
|
1182
968
|
}
|
|
1183
|
-
|
|
1184
|
-
//#endregion
|
|
1185
|
-
//#region src/runtime-config.ts
|
|
1186
|
-
/**
|
|
1187
|
-
* Access 'resolved' Nuxt runtime configuration, with values updated from environment.
|
|
1188
|
-
*
|
|
1189
|
-
* This mirrors the runtime behavior of Nitro.
|
|
1190
|
-
*/
|
|
1191
969
|
function useRuntimeConfig() {
|
|
1192
970
|
const nuxt = useNuxt();
|
|
1193
971
|
return applyEnv(klona(nuxt.options.nitro.runtimeConfig), {
|
|
@@ -1196,9 +974,6 @@ function useRuntimeConfig() {
|
|
|
1196
974
|
envExpansion: nuxt.options.nitro.experimental?.envExpansion ?? !!process.env.NITRO_ENV_EXPANSION
|
|
1197
975
|
});
|
|
1198
976
|
}
|
|
1199
|
-
/**
|
|
1200
|
-
* Update Nuxt runtime configuration.
|
|
1201
|
-
*/
|
|
1202
977
|
function updateRuntimeConfig(runtimeConfig) {
|
|
1203
978
|
const nuxt = useNuxt();
|
|
1204
979
|
Object.assign(nuxt.options.nitro.runtimeConfig, defu(runtimeConfig, nuxt.options.nitro.runtimeConfig));
|
|
@@ -1236,9 +1011,6 @@ function _expandFromEnv(value, env = process.env) {
|
|
|
1236
1011
|
return env[key] || match;
|
|
1237
1012
|
});
|
|
1238
1013
|
}
|
|
1239
|
-
|
|
1240
|
-
//#endregion
|
|
1241
|
-
//#region src/build.ts
|
|
1242
1014
|
const extendWebpackCompatibleConfig = (builder) => (fn, options = {}) => {
|
|
1243
1015
|
const nuxt = useNuxt();
|
|
1244
1016
|
if (options.dev === false && nuxt.options.dev) return;
|
|
@@ -1254,23 +1026,8 @@ const extendWebpackCompatibleConfig = (builder) => (fn, options = {}) => {
|
|
|
1254
1026
|
}
|
|
1255
1027
|
});
|
|
1256
1028
|
};
|
|
1257
|
-
/**
|
|
1258
|
-
* Extend webpack config
|
|
1259
|
-
*
|
|
1260
|
-
* The fallback function might be called multiple times
|
|
1261
|
-
* when applying to both client and server builds.
|
|
1262
|
-
*/
|
|
1263
1029
|
const extendWebpackConfig = extendWebpackCompatibleConfig("webpack");
|
|
1264
|
-
/**
|
|
1265
|
-
* Extend rspack config
|
|
1266
|
-
*
|
|
1267
|
-
* The fallback function might be called multiple times
|
|
1268
|
-
* when applying to both client and server builds.
|
|
1269
|
-
*/
|
|
1270
1030
|
const extendRspackConfig = extendWebpackCompatibleConfig("rspack");
|
|
1271
|
-
/**
|
|
1272
|
-
* Extend Vite config
|
|
1273
|
-
*/
|
|
1274
1031
|
function extendViteConfig(fn, options = {}) {
|
|
1275
1032
|
const nuxt = useNuxt();
|
|
1276
1033
|
if (options.dev === false && nuxt.options.dev) return;
|
|
@@ -1281,9 +1038,6 @@ function extendViteConfig(fn, options = {}) {
|
|
|
1281
1038
|
}
|
|
1282
1039
|
return nuxt.hook("vite:extend", ({ config }) => fn(config));
|
|
1283
1040
|
}
|
|
1284
|
-
/**
|
|
1285
|
-
* Append webpack plugin to the config.
|
|
1286
|
-
*/
|
|
1287
1041
|
function addWebpackPlugin(pluginOrGetter, options) {
|
|
1288
1042
|
extendWebpackConfig(async (config) => {
|
|
1289
1043
|
const method = options?.prepend ? "unshift" : "push";
|
|
@@ -1292,9 +1046,6 @@ function addWebpackPlugin(pluginOrGetter, options) {
|
|
|
1292
1046
|
config.plugins[method](...toArray(plugin));
|
|
1293
1047
|
}, options);
|
|
1294
1048
|
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Append rspack plugin to the config.
|
|
1297
|
-
*/
|
|
1298
1049
|
function addRspackPlugin(pluginOrGetter, options) {
|
|
1299
1050
|
extendRspackConfig(async (config) => {
|
|
1300
1051
|
const method = options?.prepend ? "unshift" : "push";
|
|
@@ -1303,9 +1054,6 @@ function addRspackPlugin(pluginOrGetter, options) {
|
|
|
1303
1054
|
config.plugins[method](...toArray(plugin));
|
|
1304
1055
|
}, options);
|
|
1305
1056
|
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Append Vite plugin to the config.
|
|
1308
|
-
*/
|
|
1309
1057
|
function addVitePlugin(pluginOrGetter, options = {}) {
|
|
1310
1058
|
const nuxt = useNuxt();
|
|
1311
1059
|
if (options.dev === false && nuxt.options.dev) return;
|
|
@@ -1346,12 +1094,6 @@ function addBuildPlugin(pluginFactory, options) {
|
|
|
1346
1094
|
if (pluginFactory.webpack) addWebpackPlugin(pluginFactory.webpack, options);
|
|
1347
1095
|
if (pluginFactory.rspack) addRspackPlugin(pluginFactory.rspack, options);
|
|
1348
1096
|
}
|
|
1349
|
-
|
|
1350
|
-
//#endregion
|
|
1351
|
-
//#region src/components.ts
|
|
1352
|
-
/**
|
|
1353
|
-
* Register a directory to be scanned for components and imported only when used.
|
|
1354
|
-
*/
|
|
1355
1097
|
function addComponentsDir(dir, opts = {}) {
|
|
1356
1098
|
const nuxt = useNuxt();
|
|
1357
1099
|
nuxt.options.components ||= [];
|
|
@@ -1360,9 +1102,6 @@ function addComponentsDir(dir, opts = {}) {
|
|
|
1360
1102
|
dirs[opts.prepend ? "unshift" : "push"](dir);
|
|
1361
1103
|
});
|
|
1362
1104
|
}
|
|
1363
|
-
/**
|
|
1364
|
-
* This utility takes a file path or npm package that is scanned for named exports, which are get added automatically
|
|
1365
|
-
*/
|
|
1366
1105
|
function addComponentExports(opts) {
|
|
1367
1106
|
const nuxt = useNuxt();
|
|
1368
1107
|
const components = [];
|
|
@@ -1377,9 +1116,6 @@ function addComponentExports(opts) {
|
|
|
1377
1116
|
});
|
|
1378
1117
|
addComponents(components);
|
|
1379
1118
|
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Register a component by its name and filePath.
|
|
1382
|
-
*/
|
|
1383
1119
|
function addComponent(opts) {
|
|
1384
1120
|
addComponents([normalizeComponent(opts)]);
|
|
1385
1121
|
}
|
|
@@ -1423,12 +1159,6 @@ function normalizeComponent(opts) {
|
|
|
1423
1159
|
...opts
|
|
1424
1160
|
};
|
|
1425
1161
|
}
|
|
1426
|
-
|
|
1427
|
-
//#endregion
|
|
1428
|
-
//#region src/template.ts
|
|
1429
|
-
/**
|
|
1430
|
-
* Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
|
|
1431
|
-
*/
|
|
1432
1162
|
function addTemplate(_template) {
|
|
1433
1163
|
const nuxt = useNuxt();
|
|
1434
1164
|
const template = normalizeTemplate(_template);
|
|
@@ -1444,23 +1174,12 @@ function addTemplate(_template) {
|
|
|
1444
1174
|
nuxt.options.build.templates.push(template);
|
|
1445
1175
|
return template;
|
|
1446
1176
|
}
|
|
1447
|
-
/**
|
|
1448
|
-
* Adds a virtual file that can be used within the Nuxt Nitro server build.
|
|
1449
|
-
*/
|
|
1450
1177
|
function addServerTemplate(template) {
|
|
1451
1178
|
const nuxt = useNuxt();
|
|
1452
1179
|
nuxt.options.nitro.virtual ||= {};
|
|
1453
1180
|
nuxt.options.nitro.virtual[template.filename] = template.getContents;
|
|
1454
1181
|
return template;
|
|
1455
1182
|
}
|
|
1456
|
-
/**
|
|
1457
|
-
* Renders given types during build to disk in the project `buildDir`
|
|
1458
|
-
* and register them as types.
|
|
1459
|
-
*
|
|
1460
|
-
* You can pass a second context object to specify in which context the type should be added.
|
|
1461
|
-
*
|
|
1462
|
-
* If no context object is passed, then it will only be added to the nuxt context.
|
|
1463
|
-
*/
|
|
1464
1183
|
function addTypeTemplate(_template, context) {
|
|
1465
1184
|
const nuxt = useNuxt();
|
|
1466
1185
|
const template = addTemplate(_template);
|
|
@@ -1484,9 +1203,6 @@ function addTypeTemplate(_template, context) {
|
|
|
1484
1203
|
});
|
|
1485
1204
|
return template;
|
|
1486
1205
|
}
|
|
1487
|
-
/**
|
|
1488
|
-
* Normalize a nuxt template object
|
|
1489
|
-
*/
|
|
1490
1206
|
function normalizeTemplate(template, buildDir) {
|
|
1491
1207
|
if (!template) throw new Error("Invalid template: " + JSON.stringify(template));
|
|
1492
1208
|
if (typeof template === "string") template = { src: template };
|
|
@@ -1504,11 +1220,6 @@ function normalizeTemplate(template, buildDir) {
|
|
|
1504
1220
|
template.dst ||= resolve(buildDir ?? useNuxt().options.buildDir, template.filename);
|
|
1505
1221
|
return template;
|
|
1506
1222
|
}
|
|
1507
|
-
/**
|
|
1508
|
-
* Trigger rebuilding Nuxt templates
|
|
1509
|
-
*
|
|
1510
|
-
* You can pass a filter within the options to selectively regenerate a subset of templates.
|
|
1511
|
-
*/
|
|
1512
1223
|
async function updateTemplates(options) {
|
|
1513
1224
|
return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
|
|
1514
1225
|
}
|
|
@@ -1616,22 +1327,22 @@ async function _generateTypes(nuxt) {
|
|
|
1616
1327
|
}
|
|
1617
1328
|
const modulePaths = await resolveNuxtModule(rootDirWithSlash, moduleEntryPaths);
|
|
1618
1329
|
for (const path of modulePaths) {
|
|
1619
|
-
const relative
|
|
1330
|
+
const relative = relativeWithDot(nuxt.options.buildDir, path);
|
|
1620
1331
|
if (!path.includes("node_modules") && path.startsWith(rootDirWithSlash)) {
|
|
1621
|
-
include.add(join(relative
|
|
1622
|
-
include.add(join(relative
|
|
1623
|
-
nodeInclude.add(join(relative
|
|
1332
|
+
include.add(join(relative, "runtime"));
|
|
1333
|
+
include.add(join(relative, "dist/runtime"));
|
|
1334
|
+
nodeInclude.add(join(relative, "*.*"));
|
|
1624
1335
|
}
|
|
1625
|
-
legacyInclude.add(join(relative
|
|
1626
|
-
legacyInclude.add(join(relative
|
|
1627
|
-
nodeExclude.add(join(relative
|
|
1628
|
-
nodeExclude.add(join(relative
|
|
1629
|
-
exclude.add(join(relative
|
|
1630
|
-
exclude.add(join(relative
|
|
1631
|
-
exclude.add(join(relative
|
|
1632
|
-
exclude.add(join(relative
|
|
1633
|
-
legacyExclude.add(join(relative
|
|
1634
|
-
legacyExclude.add(join(relative
|
|
1336
|
+
legacyInclude.add(join(relative, "runtime"));
|
|
1337
|
+
legacyInclude.add(join(relative, "dist/runtime"));
|
|
1338
|
+
nodeExclude.add(join(relative, "runtime"));
|
|
1339
|
+
nodeExclude.add(join(relative, "dist/runtime"));
|
|
1340
|
+
exclude.add(join(relative, "runtime/server"));
|
|
1341
|
+
exclude.add(join(relative, "dist/runtime/server"));
|
|
1342
|
+
exclude.add(join(relative, "*.*"));
|
|
1343
|
+
exclude.add(join(relative, "dist/*.*"));
|
|
1344
|
+
legacyExclude.add(join(relative, "runtime/server"));
|
|
1345
|
+
legacyExclude.add(join(relative, "dist/runtime/server"));
|
|
1635
1346
|
}
|
|
1636
1347
|
const nestedModulesDirs = [];
|
|
1637
1348
|
for (const dir of [...nuxt.options.modulesDir].sort()) {
|
|
@@ -1799,18 +1510,18 @@ async function _generateTypes(nuxt) {
|
|
|
1799
1510
|
include: [...tsConfig.include, ...legacyInclude],
|
|
1800
1511
|
exclude: [...legacyExclude]
|
|
1801
1512
|
});
|
|
1802
|
-
async function resolveConfig(tsConfig
|
|
1803
|
-
for (const alias in tsConfig
|
|
1804
|
-
const paths = tsConfig
|
|
1805
|
-
tsConfig
|
|
1513
|
+
async function resolveConfig(tsConfig) {
|
|
1514
|
+
for (const alias in tsConfig.compilerOptions.paths) {
|
|
1515
|
+
const paths = tsConfig.compilerOptions.paths[alias];
|
|
1516
|
+
tsConfig.compilerOptions.paths[alias] = [...new Set(await Promise.all(paths.map(async (path) => {
|
|
1806
1517
|
if (!isAbsolute(path)) return path;
|
|
1807
1518
|
const stats = await promises.stat(path).catch(() => null);
|
|
1808
1519
|
return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(EXTENSION_RE, "") : path);
|
|
1809
1520
|
})))];
|
|
1810
1521
|
}
|
|
1811
|
-
sortTsPaths(tsConfig
|
|
1812
|
-
tsConfig
|
|
1813
|
-
tsConfig
|
|
1522
|
+
sortTsPaths(tsConfig.compilerOptions.paths);
|
|
1523
|
+
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))];
|
|
1524
|
+
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))];
|
|
1814
1525
|
}
|
|
1815
1526
|
await Promise.all([
|
|
1816
1527
|
resolveConfig(tsConfig),
|
|
@@ -1819,20 +1530,14 @@ async function _generateTypes(nuxt) {
|
|
|
1819
1530
|
resolveConfig(legacyTsConfig)
|
|
1820
1531
|
]);
|
|
1821
1532
|
const declaration = [
|
|
1822
|
-
...references.map((ref) =>
|
|
1823
|
-
if ("path" in ref && isAbsolute(ref.path)) ref.path = relative(nuxt.options.buildDir, ref.path);
|
|
1824
|
-
return `/// <reference ${renderAttrs(ref)} />`;
|
|
1825
|
-
}),
|
|
1533
|
+
...references.map((ref) => renderReference(ref, nuxt.options.buildDir)),
|
|
1826
1534
|
...declarations,
|
|
1827
1535
|
"",
|
|
1828
1536
|
"export {}",
|
|
1829
1537
|
""
|
|
1830
1538
|
].join("\n");
|
|
1831
1539
|
const nodeDeclaration = [
|
|
1832
|
-
...nodeReferences.map((ref) =>
|
|
1833
|
-
if ("path" in ref && isAbsolute(ref.path)) ref.path = relative(nuxt.options.buildDir, ref.path);
|
|
1834
|
-
return `/// <reference ${renderAttrs(ref)} />`;
|
|
1835
|
-
}),
|
|
1540
|
+
...nodeReferences.map((ref) => renderReference(ref, nuxt.options.buildDir)),
|
|
1836
1541
|
"",
|
|
1837
1542
|
"export {}",
|
|
1838
1543
|
""
|
|
@@ -1841,10 +1546,7 @@ async function _generateTypes(nuxt) {
|
|
|
1841
1546
|
declaration,
|
|
1842
1547
|
sharedTsConfig,
|
|
1843
1548
|
sharedDeclaration: [
|
|
1844
|
-
...sharedReferences.map((ref) =>
|
|
1845
|
-
if ("path" in ref && isAbsolute(ref.path)) ref.path = relative(nuxt.options.buildDir, ref.path);
|
|
1846
|
-
return `/// <reference ${renderAttrs(ref)} />`;
|
|
1847
|
-
}),
|
|
1549
|
+
...sharedReferences.map((ref) => renderReference(ref, nuxt.options.buildDir)),
|
|
1848
1550
|
"",
|
|
1849
1551
|
"export {}",
|
|
1850
1552
|
""
|
|
@@ -1882,13 +1584,8 @@ function sortTsPaths(paths) {
|
|
|
1882
1584
|
paths[pathKey] = pathValue;
|
|
1883
1585
|
}
|
|
1884
1586
|
}
|
|
1885
|
-
function
|
|
1886
|
-
|
|
1887
|
-
for (const key in obj) attrs.push(renderAttr(key, obj[key]));
|
|
1888
|
-
return attrs.join(" ");
|
|
1889
|
-
}
|
|
1890
|
-
function renderAttr(key, value) {
|
|
1891
|
-
return value ? `${key}="${value}"` : "";
|
|
1587
|
+
function renderReference(ref, baseDir) {
|
|
1588
|
+
return `/// <reference ${"path" in ref ? `path="${isAbsolute(ref.path) ? relative(baseDir, ref.path) : ref.path}"` : `types="${ref.types}"`} />`;
|
|
1892
1589
|
}
|
|
1893
1590
|
const RELATIVE_WITH_DOT_RE = /^([^.])/;
|
|
1894
1591
|
function relativeWithDot(from, to) {
|
|
@@ -1897,9 +1594,6 @@ function relativeWithDot(from, to) {
|
|
|
1897
1594
|
function withTrailingSlash$1(dir) {
|
|
1898
1595
|
return dir.replace(/[^/]$/, "$&/");
|
|
1899
1596
|
}
|
|
1900
|
-
|
|
1901
|
-
//#endregion
|
|
1902
|
-
//#region src/layout.ts
|
|
1903
1597
|
const LAYOUT_RE = /["']/g;
|
|
1904
1598
|
function addLayout(template, name) {
|
|
1905
1599
|
const nuxt = useNuxt();
|
|
@@ -1923,9 +1617,6 @@ const strippedAtAliases = {
|
|
|
1923
1617
|
"@": "",
|
|
1924
1618
|
"@@": ""
|
|
1925
1619
|
};
|
|
1926
|
-
|
|
1927
|
-
//#endregion
|
|
1928
|
-
//#region src/pages.ts
|
|
1929
1620
|
function extendPages(cb) {
|
|
1930
1621
|
useNuxt().hook("pages:extend", cb);
|
|
1931
1622
|
}
|
|
@@ -1952,12 +1643,6 @@ function addRouteMiddleware(input, options = {}) {
|
|
|
1952
1643
|
}
|
|
1953
1644
|
});
|
|
1954
1645
|
}
|
|
1955
|
-
|
|
1956
|
-
//#endregion
|
|
1957
|
-
//#region src/plugin.ts
|
|
1958
|
-
/**
|
|
1959
|
-
* Normalize a nuxt plugin object
|
|
1960
|
-
*/
|
|
1961
1646
|
const pluginSymbol = Symbol.for("nuxt plugin");
|
|
1962
1647
|
function normalizePlugin(plugin) {
|
|
1963
1648
|
if (typeof plugin === "string") plugin = { src: plugin };
|
|
@@ -1991,15 +1676,10 @@ function addPlugin(_plugin, opts = {}) {
|
|
|
1991
1676
|
nuxt.options.plugins[opts.append ? "push" : "unshift"](plugin);
|
|
1992
1677
|
return plugin;
|
|
1993
1678
|
}
|
|
1994
|
-
/**
|
|
1995
|
-
* Adds a template and registers as a nuxt plugin.
|
|
1996
|
-
*/
|
|
1997
1679
|
function addPluginTemplate(plugin, opts = {}) {
|
|
1998
1680
|
return addPlugin(typeof plugin === "string" ? { src: plugin } : {
|
|
1999
1681
|
...plugin,
|
|
2000
1682
|
src: addTemplate(plugin).dst
|
|
2001
1683
|
}, opts);
|
|
2002
1684
|
}
|
|
2003
|
-
|
|
2004
|
-
//#endregion
|
|
2005
|
-
export { addBuildPlugin, addComponent, addComponentExports, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, createIsIgnored, createResolver, defineNuxtModule, directoryToURL, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getLayerDirectories, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, installModules, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveModuleWithOptions, resolveNuxtModule, resolvePath, runWithNuxtContext, setGlobalHead, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
|
|
1685
|
+
export { addBuildPlugin, addComponent, addComponentExports, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, createIsIgnored, createResolver, defineNuxtModule, directoryToURL, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getLayerDirectories, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, installModules, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveModuleWithOptions, resolveNuxtModule, resolvePath, runWithNuxtContext, setGlobalHead, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
|