@nuxt/kit 4.0.0-alpha.1 → 4.0.0-alpha.3
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.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +145 -39
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -372,7 +372,7 @@ declare function useNitro(): Nitro;
|
|
|
372
372
|
/**
|
|
373
373
|
* Add server imports to be auto-imported by Nitro
|
|
374
374
|
*/
|
|
375
|
-
declare function addServerImports(imports: Import[]): void;
|
|
375
|
+
declare function addServerImports(imports: Import | Import[]): void;
|
|
376
376
|
/**
|
|
377
377
|
* Add directories to be scanned for auto-imports by Nitro
|
|
378
378
|
*/
|
|
@@ -406,6 +406,7 @@ declare function addServerTemplate(template: NuxtServerTemplate): NuxtServerTemp
|
|
|
406
406
|
declare function addTypeTemplate<T>(_template: NuxtTypeTemplate<T>, context?: {
|
|
407
407
|
nitro?: boolean;
|
|
408
408
|
nuxt?: boolean;
|
|
409
|
+
node?: boolean;
|
|
409
410
|
}): ResolvedNuxtTemplate<T>;
|
|
410
411
|
/**
|
|
411
412
|
* Normalize a nuxt template object
|
package/dist/index.d.ts
CHANGED
|
@@ -372,7 +372,7 @@ declare function useNitro(): Nitro;
|
|
|
372
372
|
/**
|
|
373
373
|
* Add server imports to be auto-imported by Nitro
|
|
374
374
|
*/
|
|
375
|
-
declare function addServerImports(imports: Import[]): void;
|
|
375
|
+
declare function addServerImports(imports: Import | Import[]): void;
|
|
376
376
|
/**
|
|
377
377
|
* Add directories to be scanned for auto-imports by Nitro
|
|
378
378
|
*/
|
|
@@ -406,6 +406,7 @@ declare function addServerTemplate(template: NuxtServerTemplate): NuxtServerTemp
|
|
|
406
406
|
declare function addTypeTemplate<T>(_template: NuxtTypeTemplate<T>, context?: {
|
|
407
407
|
nitro?: boolean;
|
|
408
408
|
nuxt?: boolean;
|
|
409
|
+
node?: boolean;
|
|
409
410
|
}): ResolvedNuxtTemplate<T>;
|
|
410
411
|
/**
|
|
411
412
|
* Normalize a nuxt template object
|
package/dist/index.mjs
CHANGED
|
@@ -702,7 +702,7 @@ async function loadNuxtSchema(cwd) {
|
|
|
702
702
|
const urls = [url];
|
|
703
703
|
const nuxtPath = resolveModuleURL("nuxt", { try: true, from: url }) ?? resolveModuleURL("nuxt-nightly", { try: true, from: url });
|
|
704
704
|
if (nuxtPath) {
|
|
705
|
-
urls.unshift(
|
|
705
|
+
urls.unshift(nuxtPath);
|
|
706
706
|
}
|
|
707
707
|
const schemaPath = resolveModuleURL("@nuxt/schema", { try: true, from: urls }) ?? "@nuxt/schema";
|
|
708
708
|
return await import(schemaPath).then((r) => r.NuxtConfigSchema);
|
|
@@ -794,10 +794,11 @@ function useNitro() {
|
|
|
794
794
|
}
|
|
795
795
|
function addServerImports(imports) {
|
|
796
796
|
const nuxt = useNuxt();
|
|
797
|
+
const _imports = toArray(imports);
|
|
797
798
|
nuxt.hook("nitro:config", (config) => {
|
|
798
799
|
config.imports ||= {};
|
|
799
800
|
config.imports.imports ||= [];
|
|
800
|
-
config.imports.imports.push(...
|
|
801
|
+
config.imports.imports.push(..._imports);
|
|
801
802
|
});
|
|
802
803
|
}
|
|
803
804
|
function addServerImportsDir(dirs, opts = {}) {
|
|
@@ -1060,6 +1061,11 @@ function addTypeTemplate(_template, context) {
|
|
|
1060
1061
|
references.push({ path: template.dst });
|
|
1061
1062
|
});
|
|
1062
1063
|
}
|
|
1064
|
+
if (context?.node) {
|
|
1065
|
+
nuxt.hook("prepare:types", ({ nodeReferences }) => {
|
|
1066
|
+
nodeReferences.push({ path: template.dst });
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1063
1069
|
if (context?.nitro) {
|
|
1064
1070
|
nuxt.hook("nitro:prepare:types", ({ references }) => {
|
|
1065
1071
|
references.push({ path: template.dst });
|
|
@@ -1100,36 +1106,75 @@ function normalizeTemplate(template, buildDir) {
|
|
|
1100
1106
|
async function updateTemplates(options) {
|
|
1101
1107
|
return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
|
|
1102
1108
|
}
|
|
1109
|
+
function resolveLayerPaths(buildDir, rootDir, srcDir) {
|
|
1110
|
+
const relativeRootDir = relativeWithDot(buildDir, rootDir);
|
|
1111
|
+
return {
|
|
1112
|
+
nuxt: [
|
|
1113
|
+
join(relativeWithDot(buildDir, srcDir), "**/*"),
|
|
1114
|
+
join(relativeRootDir, "modules/*/runtime/**/*"),
|
|
1115
|
+
join(relativeRootDir, "layers/*/modules/*/runtime/**/*")
|
|
1116
|
+
],
|
|
1117
|
+
nitro: [
|
|
1118
|
+
join(relativeRootDir, "modules/*/runtime/server/**/*"),
|
|
1119
|
+
join(relativeRootDir, "layers/*/modules/*/runtime/server/**/*")
|
|
1120
|
+
],
|
|
1121
|
+
node: [
|
|
1122
|
+
join(relativeRootDir, "modules/**/*"),
|
|
1123
|
+
join(relativeRootDir, "nuxt.config.*"),
|
|
1124
|
+
join(relativeRootDir, ".config/nuxt.*"),
|
|
1125
|
+
join(relativeRootDir, "layers/*/nuxt.config.*"),
|
|
1126
|
+
join(relativeRootDir, "layers/*/.config/nuxt.*"),
|
|
1127
|
+
join(relativeRootDir, "layers/*/modules/**/*")
|
|
1128
|
+
]
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1103
1131
|
const EXTENSION_RE = /\b(?:\.d\.[cm]?ts|\.\w+)$/g;
|
|
1104
1132
|
const excludedAlias = [/^@vue\/.*$/, /^#internal\/nuxt/];
|
|
1105
1133
|
async function _generateTypes(nuxt) {
|
|
1106
|
-
const
|
|
1107
|
-
const
|
|
1108
|
-
const
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
if (nuxt.options.srcDir !== nuxt.options.rootDir) {
|
|
1114
|
-
include.add(join(relative(nuxt.options.buildDir, nuxt.options.srcDir), "**/*"));
|
|
1115
|
-
}
|
|
1116
|
-
if (nuxt.options.typescript.includeWorkspace && nuxt.options.workspaceDir !== nuxt.options.rootDir) {
|
|
1134
|
+
const include = /* @__PURE__ */ new Set(["./nuxt.d.ts"]);
|
|
1135
|
+
const nodeInclude = /* @__PURE__ */ new Set(["./nuxt.node.d.ts"]);
|
|
1136
|
+
const legacyInclude = /* @__PURE__ */ new Set(["./nuxt.d.ts"]);
|
|
1137
|
+
const exclude = /* @__PURE__ */ new Set();
|
|
1138
|
+
const nodeExclude = /* @__PURE__ */ new Set();
|
|
1139
|
+
const legacyExclude = /* @__PURE__ */ new Set();
|
|
1140
|
+
if (nuxt.options.typescript.includeWorkspace && nuxt.options.workspaceDir !== nuxt.options.srcDir) {
|
|
1117
1141
|
include.add(join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), "**/*"));
|
|
1142
|
+
legacyInclude.add(join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), "**/*"));
|
|
1118
1143
|
}
|
|
1119
|
-
for (const layer of nuxt.options._layers) {
|
|
1120
|
-
const srcOrCwd = layer.config.srcDir ?? layer.cwd;
|
|
1121
|
-
if (!srcOrCwd.startsWith(rootDirWithSlash) || srcOrCwd.includes("node_modules")) {
|
|
1122
|
-
include.add(join(relative(nuxt.options.buildDir, srcOrCwd), "**/*"));
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
const exclude = /* @__PURE__ */ new Set([
|
|
1126
|
-
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
1127
|
-
relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, "dist")),
|
|
1128
|
-
// nitro generate .data in development when kv storage is used
|
|
1129
|
-
relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, ".data"))
|
|
1130
|
-
]);
|
|
1131
1144
|
for (const dir of nuxt.options.modulesDir) {
|
|
1132
1145
|
exclude.add(relativeWithDot(nuxt.options.buildDir, dir));
|
|
1146
|
+
nodeExclude.add(relativeWithDot(nuxt.options.buildDir, dir));
|
|
1147
|
+
legacyExclude.add(relativeWithDot(nuxt.options.buildDir, dir));
|
|
1148
|
+
}
|
|
1149
|
+
for (const dir of ["dist", ".data"]) {
|
|
1150
|
+
exclude.add(relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, dir)));
|
|
1151
|
+
nodeExclude.add(relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, dir)));
|
|
1152
|
+
legacyExclude.add(relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, dir)));
|
|
1153
|
+
}
|
|
1154
|
+
const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
|
|
1155
|
+
for (const layer of nuxt.options._layers) {
|
|
1156
|
+
const srcOrCwd = withTrailingSlash(layer.config.srcDir ?? layer.cwd);
|
|
1157
|
+
if (!srcOrCwd.startsWith(rootDirWithSlash) || srcOrCwd === rootDirWithSlash || srcOrCwd.includes("node_modules")) {
|
|
1158
|
+
const rootGlob = join(relativeWithDot(nuxt.options.buildDir, layer.cwd), "**/*");
|
|
1159
|
+
const paths = resolveLayerPaths(nuxt.options.buildDir, layer.cwd, layer.config.srcDir);
|
|
1160
|
+
for (const path of paths.nuxt) {
|
|
1161
|
+
include.add(path);
|
|
1162
|
+
legacyInclude.add(path);
|
|
1163
|
+
if (path !== rootGlob) {
|
|
1164
|
+
nodeExclude.add(path);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
for (const path of paths.nitro) {
|
|
1168
|
+
exclude.add(path);
|
|
1169
|
+
nodeExclude.add(path);
|
|
1170
|
+
legacyExclude.add(path);
|
|
1171
|
+
}
|
|
1172
|
+
for (const path of paths.node) {
|
|
1173
|
+
nodeInclude.add(path);
|
|
1174
|
+
legacyInclude.add(path);
|
|
1175
|
+
exclude.add(path);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1133
1178
|
}
|
|
1134
1179
|
const moduleEntryPaths = [];
|
|
1135
1180
|
for (const m of nuxt.options._installedModules) {
|
|
@@ -1141,9 +1186,15 @@ async function _generateTypes(nuxt) {
|
|
|
1141
1186
|
for (const path of modulePaths) {
|
|
1142
1187
|
const relative2 = relativeWithDot(nuxt.options.buildDir, path);
|
|
1143
1188
|
include.add(join(relative2, "runtime"));
|
|
1144
|
-
exclude.add(join(relative2, "runtime/server"));
|
|
1145
1189
|
include.add(join(relative2, "dist/runtime"));
|
|
1190
|
+
legacyInclude.add(join(relative2, "runtime"));
|
|
1191
|
+
legacyInclude.add(join(relative2, "dist/runtime"));
|
|
1192
|
+
nodeExclude.add(join(relative2, "runtime"));
|
|
1193
|
+
nodeExclude.add(join(relative2, "dist/runtime"));
|
|
1194
|
+
exclude.add(join(relative2, "runtime/server"));
|
|
1146
1195
|
exclude.add(join(relative2, "dist/runtime/server"));
|
|
1196
|
+
legacyExclude.add(join(relative2, "runtime/server"));
|
|
1197
|
+
legacyExclude.add(join(relative2, "dist/runtime/server"));
|
|
1147
1198
|
}
|
|
1148
1199
|
const nestedModulesDirs = [];
|
|
1149
1200
|
for (const dir of [...nuxt.options.modulesDir].sort()) {
|
|
@@ -1158,6 +1209,41 @@ async function _generateTypes(nuxt) {
|
|
|
1158
1209
|
}
|
|
1159
1210
|
hasTypescriptVersionWithModulePreserve ??= true;
|
|
1160
1211
|
const useDecorators = Boolean(nuxt.options.experimental?.decorators);
|
|
1212
|
+
const nodeReferences = [];
|
|
1213
|
+
const nodeTsConfig = defu(nuxt.options.typescript?.nodeTsConfig, {
|
|
1214
|
+
compilerOptions: {
|
|
1215
|
+
/* Base options: */
|
|
1216
|
+
esModuleInterop: true,
|
|
1217
|
+
skipLibCheck: true,
|
|
1218
|
+
target: "ESNext",
|
|
1219
|
+
allowJs: true,
|
|
1220
|
+
resolveJsonModule: true,
|
|
1221
|
+
moduleDetection: "force",
|
|
1222
|
+
isolatedModules: true,
|
|
1223
|
+
verbatimModuleSyntax: true,
|
|
1224
|
+
/* Strictness */
|
|
1225
|
+
strict: nuxt.options.typescript?.strict ?? true,
|
|
1226
|
+
noUncheckedIndexedAccess: true,
|
|
1227
|
+
forceConsistentCasingInFileNames: true,
|
|
1228
|
+
noImplicitOverride: true,
|
|
1229
|
+
/* If NOT transpiling with TypeScript: */
|
|
1230
|
+
module: hasTypescriptVersionWithModulePreserve ? "preserve" : "ESNext",
|
|
1231
|
+
noEmit: true,
|
|
1232
|
+
/* remove auto-scanning for types */
|
|
1233
|
+
types: [],
|
|
1234
|
+
/* add paths object for filling-in later */
|
|
1235
|
+
paths: {},
|
|
1236
|
+
/* Possibly consider removing the following in future */
|
|
1237
|
+
moduleResolution: hasTypescriptVersionWithModulePreserve ? void 0 : "Bundler",
|
|
1238
|
+
useDefineForClassFields: true,
|
|
1239
|
+
/* implied by target: es2022+ */
|
|
1240
|
+
noImplicitThis: true,
|
|
1241
|
+
/* enabled with `strict` */
|
|
1242
|
+
allowSyntheticDefaultImports: true
|
|
1243
|
+
},
|
|
1244
|
+
include: [...nodeInclude],
|
|
1245
|
+
exclude: [...nodeExclude]
|
|
1246
|
+
});
|
|
1161
1247
|
const tsConfig = defu(nuxt.options.typescript?.tsConfig, {
|
|
1162
1248
|
compilerOptions: {
|
|
1163
1249
|
/* Base options: */
|
|
@@ -1238,15 +1324,9 @@ async function _generateTypes(nuxt) {
|
|
|
1238
1324
|
if (stats?.isDirectory()) {
|
|
1239
1325
|
tsConfig.compilerOptions.paths[alias] = [relativePath];
|
|
1240
1326
|
tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`];
|
|
1241
|
-
if (!absolutePath.startsWith(rootDirWithSlash)) {
|
|
1242
|
-
tsConfig.include.push(relativePath);
|
|
1243
|
-
}
|
|
1244
1327
|
} else {
|
|
1245
1328
|
const path = stats?.isFile() ? relativePath.replace(EXTENSION_RE, "") : aliases[alias];
|
|
1246
1329
|
tsConfig.compilerOptions.paths[alias] = [path];
|
|
1247
|
-
if (!absolutePath.startsWith(rootDirWithSlash)) {
|
|
1248
|
-
tsConfig.include.push(path);
|
|
1249
|
-
}
|
|
1250
1330
|
}
|
|
1251
1331
|
}
|
|
1252
1332
|
const references = [];
|
|
@@ -1264,7 +1344,7 @@ async function _generateTypes(nuxt) {
|
|
|
1264
1344
|
references.push({ types: id });
|
|
1265
1345
|
}));
|
|
1266
1346
|
const declarations = [];
|
|
1267
|
-
await nuxt.callHook("prepare:types", { references, declarations, tsConfig });
|
|
1347
|
+
await nuxt.callHook("prepare:types", { references, declarations, tsConfig, nodeTsConfig, nodeReferences });
|
|
1268
1348
|
for (const alias in tsConfig.compilerOptions.paths) {
|
|
1269
1349
|
const paths = tsConfig.compilerOptions.paths[alias];
|
|
1270
1350
|
tsConfig.compilerOptions.paths[alias] = await Promise.all(paths.map(async (path) => {
|
|
@@ -1293,18 +1373,44 @@ async function _generateTypes(nuxt) {
|
|
|
1293
1373
|
"export {}",
|
|
1294
1374
|
""
|
|
1295
1375
|
].join("\n");
|
|
1376
|
+
const nodeDeclaration = [
|
|
1377
|
+
...nodeReferences.map((ref) => {
|
|
1378
|
+
if ("path" in ref && isAbsolute(ref.path)) {
|
|
1379
|
+
ref.path = relative(nuxt.options.buildDir, ref.path);
|
|
1380
|
+
}
|
|
1381
|
+
return `/// <reference ${renderAttrs(ref)} />`;
|
|
1382
|
+
}),
|
|
1383
|
+
"",
|
|
1384
|
+
"export {}",
|
|
1385
|
+
""
|
|
1386
|
+
].join("\n");
|
|
1387
|
+
const legacyTsConfig = defu({}, tsConfig, {
|
|
1388
|
+
include: [...legacyInclude],
|
|
1389
|
+
exclude: [...legacyExclude]
|
|
1390
|
+
});
|
|
1296
1391
|
return {
|
|
1297
1392
|
declaration,
|
|
1298
|
-
|
|
1393
|
+
nodeTsConfig,
|
|
1394
|
+
nodeDeclaration,
|
|
1395
|
+
tsConfig,
|
|
1396
|
+
legacyTsConfig
|
|
1299
1397
|
};
|
|
1300
1398
|
}
|
|
1301
1399
|
async function writeTypes(nuxt) {
|
|
1302
|
-
const { tsConfig, declaration } = await _generateTypes(nuxt);
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
|
|
1400
|
+
const { tsConfig, nodeTsConfig, nodeDeclaration, declaration, legacyTsConfig } = await _generateTypes(nuxt);
|
|
1401
|
+
const appTsConfigPath = resolve(nuxt.options.buildDir, "tsconfig.app.json");
|
|
1402
|
+
const legacyTsConfigPath = resolve(nuxt.options.buildDir, "tsconfig.json");
|
|
1403
|
+
const nodeTsConfigPath = resolve(nuxt.options.buildDir, "tsconfig.node.json");
|
|
1306
1404
|
const declarationPath = resolve(nuxt.options.buildDir, "nuxt.d.ts");
|
|
1307
|
-
|
|
1405
|
+
const nodeDeclarationPath = resolve(nuxt.options.buildDir, "nuxt.node.d.ts");
|
|
1406
|
+
await promises.mkdir(nuxt.options.buildDir, { recursive: true });
|
|
1407
|
+
await Promise.all([
|
|
1408
|
+
promises.writeFile(appTsConfigPath, JSON.stringify(tsConfig, null, 2)),
|
|
1409
|
+
promises.writeFile(legacyTsConfigPath, JSON.stringify(legacyTsConfig, null, 2)),
|
|
1410
|
+
promises.writeFile(nodeTsConfigPath, JSON.stringify(nodeTsConfig, null, 2)),
|
|
1411
|
+
promises.writeFile(declarationPath, declaration),
|
|
1412
|
+
promises.writeFile(nodeDeclarationPath, nodeDeclaration)
|
|
1413
|
+
]);
|
|
1308
1414
|
}
|
|
1309
1415
|
function sortTsPaths(paths) {
|
|
1310
1416
|
for (const pathKey in paths) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/kit",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"defu": "^6.1.4",
|
|
29
29
|
"destr": "^2.0.5",
|
|
30
30
|
"errx": "^0.1.0",
|
|
31
|
-
"exsolve": "^1.0.
|
|
31
|
+
"exsolve": "^1.0.7",
|
|
32
32
|
"ignore": "^7.0.5",
|
|
33
33
|
"jiti": "^2.4.2",
|
|
34
34
|
"klona": "^2.0.6",
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"untyped": "^2.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@rspack/core": "1.3.
|
|
49
|
+
"@rspack/core": "1.3.15",
|
|
50
50
|
"@types/semver": "7.7.0",
|
|
51
51
|
"hookable": "5.5.3",
|
|
52
|
-
"nitropack": "2.11.
|
|
52
|
+
"nitropack": "2.11.13",
|
|
53
53
|
"unbuild": "3.5.0",
|
|
54
|
-
"vite": "
|
|
55
|
-
"vitest": "3.2.
|
|
56
|
-
"webpack": "5.99.
|
|
57
|
-
"@nuxt/schema": "4.0.0-alpha.
|
|
54
|
+
"vite": "7.0.0",
|
|
55
|
+
"vitest": "3.2.4",
|
|
56
|
+
"webpack": "5.99.9",
|
|
57
|
+
"@nuxt/schema": "4.0.0-alpha.3"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=18.12.0"
|