@nuxt/kit 3.0.0-rc.6 → 3.0.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +68 -51
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -235,7 +235,9 @@ interface Resolver {
|
|
|
235
235
|
* Create a relative resolver
|
|
236
236
|
*/
|
|
237
237
|
declare function createResolver(base: string | URL): Resolver;
|
|
238
|
-
declare function resolveFiles(path: string, pattern: string | string[]
|
|
238
|
+
declare function resolveFiles(path: string, pattern: string | string[], opts?: {
|
|
239
|
+
followSymbolicLinks?: boolean;
|
|
240
|
+
}): Promise<string[]>;
|
|
239
241
|
|
|
240
242
|
interface LegacyServerMiddleware {
|
|
241
243
|
route?: string;
|
|
@@ -300,6 +302,7 @@ declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promi
|
|
|
300
302
|
declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
|
|
301
303
|
|
|
302
304
|
declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
|
|
305
|
+
/** @deprecated */
|
|
303
306
|
declare const templateUtils: {
|
|
304
307
|
serialize: (data: any) => string;
|
|
305
308
|
importName: typeof genSafeVariableName;
|
package/dist/index.mjs
CHANGED
|
@@ -6,9 +6,9 @@ import { kebabCase, pascalCase } from 'scule';
|
|
|
6
6
|
import satisfies from 'semver/functions/satisfies.js';
|
|
7
7
|
import consola from 'consola';
|
|
8
8
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
9
|
+
import { globby } from 'globby';
|
|
9
10
|
import { interopDefault } from 'mlly';
|
|
10
11
|
import jiti from 'jiti';
|
|
11
|
-
import { globby } from 'globby';
|
|
12
12
|
import ignore from 'ignore';
|
|
13
13
|
import defu from 'defu';
|
|
14
14
|
import { applyDefaults } from 'untyped';
|
|
@@ -30,7 +30,11 @@ function chainFn(base, fn) {
|
|
|
30
30
|
if (baseResult === void 0) {
|
|
31
31
|
[baseResult] = args;
|
|
32
32
|
}
|
|
33
|
-
const fnResult = fn.call(
|
|
33
|
+
const fnResult = fn.call(
|
|
34
|
+
this,
|
|
35
|
+
baseResult,
|
|
36
|
+
...Array.prototype.slice.call(args, 1)
|
|
37
|
+
);
|
|
34
38
|
if (fnResult === void 0) {
|
|
35
39
|
return baseResult;
|
|
36
40
|
}
|
|
@@ -40,14 +44,14 @@ function chainFn(base, fn) {
|
|
|
40
44
|
|
|
41
45
|
const nuxtCtx = getContext("nuxt");
|
|
42
46
|
function useNuxt() {
|
|
43
|
-
const instance = nuxtCtx.
|
|
47
|
+
const instance = nuxtCtx.tryUse();
|
|
44
48
|
if (!instance) {
|
|
45
49
|
throw new Error("Nuxt instance is unavailable!");
|
|
46
50
|
}
|
|
47
51
|
return instance;
|
|
48
52
|
}
|
|
49
53
|
function tryUseNuxt() {
|
|
50
|
-
return nuxtCtx.
|
|
54
|
+
return nuxtCtx.tryUse();
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
function addTemplate(_template) {
|
|
@@ -159,7 +163,9 @@ function addLayout(tmpl, name) {
|
|
|
159
163
|
if (isNuxt2(nuxt)) {
|
|
160
164
|
const layout = nuxt.options.layouts[layoutName];
|
|
161
165
|
if (layout) {
|
|
162
|
-
return logger.warn(
|
|
166
|
+
return logger.warn(
|
|
167
|
+
`Not overriding \`${layoutName}\` (provided by \`${layout}\`) with \`${src || filename}\`.`
|
|
168
|
+
);
|
|
163
169
|
}
|
|
164
170
|
nuxt.options.layouts[layoutName] = `./${filename}`;
|
|
165
171
|
if (name === "error") {
|
|
@@ -170,7 +176,9 @@ function addLayout(tmpl, name) {
|
|
|
170
176
|
nuxt.hook("app:templates", (app) => {
|
|
171
177
|
if (layoutName in app.layouts) {
|
|
172
178
|
const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName].file);
|
|
173
|
-
return logger.warn(
|
|
179
|
+
return logger.warn(
|
|
180
|
+
`Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.`
|
|
181
|
+
);
|
|
174
182
|
}
|
|
175
183
|
app.layouts[layoutName] = {
|
|
176
184
|
file: join("#build", filename),
|
|
@@ -196,38 +204,7 @@ function addDevServerHandler(handler) {
|
|
|
196
204
|
useNuxt().options.devServerHandlers.push(handler);
|
|
197
205
|
}
|
|
198
206
|
|
|
199
|
-
|
|
200
|
-
if (typeof plugin === "string") {
|
|
201
|
-
plugin = { src: plugin };
|
|
202
|
-
} else {
|
|
203
|
-
plugin = { ...plugin };
|
|
204
|
-
}
|
|
205
|
-
if (!plugin.src) {
|
|
206
|
-
throw new Error("Invalid plugin. src option is required: " + JSON.stringify(plugin));
|
|
207
|
-
}
|
|
208
|
-
plugin.src = normalize(plugin.src);
|
|
209
|
-
if (plugin.ssr) {
|
|
210
|
-
plugin.mode = "server";
|
|
211
|
-
}
|
|
212
|
-
if (!plugin.mode) {
|
|
213
|
-
const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
|
|
214
|
-
plugin.mode = mode;
|
|
215
|
-
}
|
|
216
|
-
return plugin;
|
|
217
|
-
}
|
|
218
|
-
function addPlugin(_plugin, opts = {}) {
|
|
219
|
-
const nuxt = useNuxt();
|
|
220
|
-
const plugin = normalizePlugin(_plugin);
|
|
221
|
-
nuxt.options.plugins = nuxt.options.plugins.filter((p) => normalizePlugin(p).src !== plugin.src);
|
|
222
|
-
nuxt.options.plugins[opts.append ? "push" : "unshift"](plugin);
|
|
223
|
-
return plugin;
|
|
224
|
-
}
|
|
225
|
-
function addPluginTemplate(plugin, opts = {}) {
|
|
226
|
-
const normalizedPlugin = typeof plugin === "string" ? { src: plugin } : { ...plugin, src: addTemplate(plugin).dst };
|
|
227
|
-
return addPlugin(normalizedPlugin, opts);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const _require = jiti(process.cwd(), { interopDefault: true });
|
|
207
|
+
const _require = jiti(process.cwd(), { interopDefault: true, esmResolve: true });
|
|
231
208
|
function isNodeModules(id) {
|
|
232
209
|
return /[/\\]node_modules[/\\]/.test(id);
|
|
233
210
|
}
|
|
@@ -274,7 +251,12 @@ function requireModulePkg(id, opts = {}) {
|
|
|
274
251
|
}
|
|
275
252
|
function resolveModule(id, opts = {}) {
|
|
276
253
|
return normalize(_require.resolve(id, {
|
|
277
|
-
paths: [].concat(
|
|
254
|
+
paths: [].concat(
|
|
255
|
+
global.__NUXT_PREPATHS__,
|
|
256
|
+
opts.paths,
|
|
257
|
+
process.cwd(),
|
|
258
|
+
global.__NUXT_PATHS__
|
|
259
|
+
).filter(Boolean)
|
|
278
260
|
}));
|
|
279
261
|
}
|
|
280
262
|
function tryResolveModule(path, opts = {}) {
|
|
@@ -338,7 +320,7 @@ function isIgnored(pathname) {
|
|
|
338
320
|
async function resolvePath(path, opts = {}) {
|
|
339
321
|
const _path = path;
|
|
340
322
|
path = normalize(path);
|
|
341
|
-
if (isAbsolute(path) && existsSync(path)) {
|
|
323
|
+
if (isAbsolute(path) && existsSync(path) && !await isDirectory(path)) {
|
|
342
324
|
return path;
|
|
343
325
|
}
|
|
344
326
|
const nuxt = useNuxt();
|
|
@@ -349,10 +331,10 @@ async function resolvePath(path, opts = {}) {
|
|
|
349
331
|
if (!isAbsolute(path)) {
|
|
350
332
|
path = resolve(cwd, path);
|
|
351
333
|
}
|
|
352
|
-
let
|
|
334
|
+
let _isDir = false;
|
|
353
335
|
if (existsSync(path)) {
|
|
354
|
-
|
|
355
|
-
if (!
|
|
336
|
+
_isDir = await isDirectory(path);
|
|
337
|
+
if (!_isDir) {
|
|
356
338
|
return path;
|
|
357
339
|
}
|
|
358
340
|
}
|
|
@@ -362,7 +344,7 @@ async function resolvePath(path, opts = {}) {
|
|
|
362
344
|
return pathWithExt;
|
|
363
345
|
}
|
|
364
346
|
const pathWithIndex = join(path, "index" + ext);
|
|
365
|
-
if (
|
|
347
|
+
if (_isDir && existsSync(pathWithIndex)) {
|
|
366
348
|
return pathWithIndex;
|
|
367
349
|
}
|
|
368
350
|
}
|
|
@@ -379,8 +361,8 @@ async function findPath(paths, opts, pathType = "file") {
|
|
|
379
361
|
for (const path of paths) {
|
|
380
362
|
const rPath = await resolvePath(path, opts);
|
|
381
363
|
if (await existsSensitive(rPath)) {
|
|
382
|
-
const
|
|
383
|
-
if (!pathType || pathType === "file" && !
|
|
364
|
+
const _isDir = await isDirectory(rPath);
|
|
365
|
+
if (!pathType || pathType === "file" && !_isDir || pathType === "dir" && _isDir) {
|
|
384
366
|
return rPath;
|
|
385
367
|
}
|
|
386
368
|
}
|
|
@@ -421,9 +403,43 @@ async function existsSensitive(path) {
|
|
|
421
403
|
const dirFiles = await promises.readdir(dirname(path));
|
|
422
404
|
return dirFiles.includes(basename(path));
|
|
423
405
|
}
|
|
424
|
-
async function
|
|
425
|
-
|
|
426
|
-
|
|
406
|
+
async function isDirectory(path) {
|
|
407
|
+
return (await promises.lstat(path)).isDirectory();
|
|
408
|
+
}
|
|
409
|
+
async function resolveFiles(path, pattern, opts = {}) {
|
|
410
|
+
const files = await globby(pattern, { cwd: path, followSymbolicLinks: opts.followSymbolicLinks ?? true });
|
|
411
|
+
return files.map((p) => resolve(path, p)).filter((p) => !isIgnored(p)).sort();
|
|
412
|
+
}
|
|
413
|
+
|
|
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);
|
|
427
443
|
}
|
|
428
444
|
|
|
429
445
|
async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
|
|
@@ -556,7 +572,8 @@ const importSources = (sources, { lazy = false } = {}) => {
|
|
|
556
572
|
return genImport(src, genSafeVariableName(src));
|
|
557
573
|
}).join("\n");
|
|
558
574
|
};
|
|
559
|
-
const
|
|
575
|
+
const importName = genSafeVariableName;
|
|
576
|
+
const templateUtils = { serialize, importName, importSources };
|
|
560
577
|
|
|
561
578
|
function defineNuxtModule(definition) {
|
|
562
579
|
if (typeof definition === "function") {
|
|
@@ -617,7 +634,7 @@ function nuxt2Shims(nuxt) {
|
|
|
617
634
|
}
|
|
618
635
|
nuxt[NUXT2_SHIMS_KEY] = true;
|
|
619
636
|
nuxt.hooks = nuxt;
|
|
620
|
-
if (!nuxtCtx.
|
|
637
|
+
if (!nuxtCtx.tryUse()) {
|
|
621
638
|
nuxtCtx.set(nuxt);
|
|
622
639
|
nuxt.hook("close", () => nuxtCtx.unset());
|
|
623
640
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/kit",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.7",
|
|
4
4
|
"repository": "nuxt/framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"prepack": "unbuild"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@nuxt/schema": "
|
|
17
|
-
"c12": "^0.2.
|
|
16
|
+
"@nuxt/schema": "3.0.0-rc.7",
|
|
17
|
+
"c12": "^0.2.9",
|
|
18
18
|
"consola": "^2.15.3",
|
|
19
19
|
"defu": "^6.0.0",
|
|
20
20
|
"globby": "^13.1.2",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"jiti": "^1.14.0",
|
|
24
24
|
"knitwork": "^0.1.2",
|
|
25
25
|
"lodash.template": "^4.5.0",
|
|
26
|
-
"mlly": "^0.5.
|
|
27
|
-
"pathe": "^0.3.
|
|
26
|
+
"mlly": "^0.5.10",
|
|
27
|
+
"pathe": "^0.3.4",
|
|
28
28
|
"pkg-types": "^0.3.3",
|
|
29
|
-
"scule": "^0.2
|
|
29
|
+
"scule": "^0.3.2",
|
|
30
30
|
"semver": "^7.3.7",
|
|
31
|
-
"unctx": "^
|
|
32
|
-
"unimport": "^0.
|
|
33
|
-
"untyped": "^0.4.
|
|
31
|
+
"unctx": "^2.0.1",
|
|
32
|
+
"unimport": "^0.6.7",
|
|
33
|
+
"untyped": "^0.4.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/lodash.template": "^4",
|