@nuxt/kit 4.0.0-alpha.2 → 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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +142 -37
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -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
|
@@ -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
|
@@ -1061,6 +1061,11 @@ function addTypeTemplate(_template, context) {
|
|
|
1061
1061
|
references.push({ path: template.dst });
|
|
1062
1062
|
});
|
|
1063
1063
|
}
|
|
1064
|
+
if (context?.node) {
|
|
1065
|
+
nuxt.hook("prepare:types", ({ nodeReferences }) => {
|
|
1066
|
+
nodeReferences.push({ path: template.dst });
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1064
1069
|
if (context?.nitro) {
|
|
1065
1070
|
nuxt.hook("nitro:prepare:types", ({ references }) => {
|
|
1066
1071
|
references.push({ path: template.dst });
|
|
@@ -1101,36 +1106,75 @@ function normalizeTemplate(template, buildDir) {
|
|
|
1101
1106
|
async function updateTemplates(options) {
|
|
1102
1107
|
return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
|
|
1103
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
|
+
}
|
|
1104
1131
|
const EXTENSION_RE = /\b(?:\.d\.[cm]?ts|\.\w+)$/g;
|
|
1105
1132
|
const excludedAlias = [/^@vue\/.*$/, /^#internal\/nuxt/];
|
|
1106
1133
|
async function _generateTypes(nuxt) {
|
|
1107
|
-
const
|
|
1108
|
-
const
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
if (nuxt.options.srcDir !== nuxt.options.rootDir) {
|
|
1115
|
-
include.add(join(relative(nuxt.options.buildDir, nuxt.options.srcDir), "**/*"));
|
|
1116
|
-
}
|
|
1117
|
-
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) {
|
|
1118
1141
|
include.add(join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), "**/*"));
|
|
1142
|
+
legacyInclude.add(join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), "**/*"));
|
|
1119
1143
|
}
|
|
1120
|
-
for (const layer of nuxt.options._layers) {
|
|
1121
|
-
const srcOrCwd = layer.config.srcDir ?? layer.cwd;
|
|
1122
|
-
if (!srcOrCwd.startsWith(rootDirWithSlash) || srcOrCwd.includes("node_modules")) {
|
|
1123
|
-
include.add(join(relative(nuxt.options.buildDir, srcOrCwd), "**/*"));
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
const exclude = /* @__PURE__ */ new Set([
|
|
1127
|
-
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
1128
|
-
relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, "dist")),
|
|
1129
|
-
// nitro generate .data in development when kv storage is used
|
|
1130
|
-
relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, ".data"))
|
|
1131
|
-
]);
|
|
1132
1144
|
for (const dir of nuxt.options.modulesDir) {
|
|
1133
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
|
+
}
|
|
1134
1178
|
}
|
|
1135
1179
|
const moduleEntryPaths = [];
|
|
1136
1180
|
for (const m of nuxt.options._installedModules) {
|
|
@@ -1142,9 +1186,15 @@ async function _generateTypes(nuxt) {
|
|
|
1142
1186
|
for (const path of modulePaths) {
|
|
1143
1187
|
const relative2 = relativeWithDot(nuxt.options.buildDir, path);
|
|
1144
1188
|
include.add(join(relative2, "runtime"));
|
|
1145
|
-
exclude.add(join(relative2, "runtime/server"));
|
|
1146
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"));
|
|
1147
1195
|
exclude.add(join(relative2, "dist/runtime/server"));
|
|
1196
|
+
legacyExclude.add(join(relative2, "runtime/server"));
|
|
1197
|
+
legacyExclude.add(join(relative2, "dist/runtime/server"));
|
|
1148
1198
|
}
|
|
1149
1199
|
const nestedModulesDirs = [];
|
|
1150
1200
|
for (const dir of [...nuxt.options.modulesDir].sort()) {
|
|
@@ -1159,6 +1209,41 @@ async function _generateTypes(nuxt) {
|
|
|
1159
1209
|
}
|
|
1160
1210
|
hasTypescriptVersionWithModulePreserve ??= true;
|
|
1161
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
|
+
});
|
|
1162
1247
|
const tsConfig = defu(nuxt.options.typescript?.tsConfig, {
|
|
1163
1248
|
compilerOptions: {
|
|
1164
1249
|
/* Base options: */
|
|
@@ -1239,15 +1324,9 @@ async function _generateTypes(nuxt) {
|
|
|
1239
1324
|
if (stats?.isDirectory()) {
|
|
1240
1325
|
tsConfig.compilerOptions.paths[alias] = [relativePath];
|
|
1241
1326
|
tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`];
|
|
1242
|
-
if (!absolutePath.startsWith(rootDirWithSlash)) {
|
|
1243
|
-
tsConfig.include.push(relativePath);
|
|
1244
|
-
}
|
|
1245
1327
|
} else {
|
|
1246
1328
|
const path = stats?.isFile() ? relativePath.replace(EXTENSION_RE, "") : aliases[alias];
|
|
1247
1329
|
tsConfig.compilerOptions.paths[alias] = [path];
|
|
1248
|
-
if (!absolutePath.startsWith(rootDirWithSlash)) {
|
|
1249
|
-
tsConfig.include.push(path);
|
|
1250
|
-
}
|
|
1251
1330
|
}
|
|
1252
1331
|
}
|
|
1253
1332
|
const references = [];
|
|
@@ -1265,7 +1344,7 @@ async function _generateTypes(nuxt) {
|
|
|
1265
1344
|
references.push({ types: id });
|
|
1266
1345
|
}));
|
|
1267
1346
|
const declarations = [];
|
|
1268
|
-
await nuxt.callHook("prepare:types", { references, declarations, tsConfig });
|
|
1347
|
+
await nuxt.callHook("prepare:types", { references, declarations, tsConfig, nodeTsConfig, nodeReferences });
|
|
1269
1348
|
for (const alias in tsConfig.compilerOptions.paths) {
|
|
1270
1349
|
const paths = tsConfig.compilerOptions.paths[alias];
|
|
1271
1350
|
tsConfig.compilerOptions.paths[alias] = await Promise.all(paths.map(async (path) => {
|
|
@@ -1294,18 +1373,44 @@ async function _generateTypes(nuxt) {
|
|
|
1294
1373
|
"export {}",
|
|
1295
1374
|
""
|
|
1296
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
|
+
});
|
|
1297
1391
|
return {
|
|
1298
1392
|
declaration,
|
|
1299
|
-
|
|
1393
|
+
nodeTsConfig,
|
|
1394
|
+
nodeDeclaration,
|
|
1395
|
+
tsConfig,
|
|
1396
|
+
legacyTsConfig
|
|
1300
1397
|
};
|
|
1301
1398
|
}
|
|
1302
1399
|
async function writeTypes(nuxt) {
|
|
1303
|
-
const { tsConfig, declaration } = await _generateTypes(nuxt);
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
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");
|
|
1307
1404
|
const declarationPath = resolve(nuxt.options.buildDir, "nuxt.d.ts");
|
|
1308
|
-
|
|
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
|
+
]);
|
|
1309
1414
|
}
|
|
1310
1415
|
function sortTsPaths(paths) {
|
|
1311
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",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
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.
|
|
54
|
+
"vite": "7.0.0",
|
|
55
|
+
"vitest": "3.2.4",
|
|
56
56
|
"webpack": "5.99.9",
|
|
57
|
-
"@nuxt/schema": "4.0.0-alpha.
|
|
57
|
+
"@nuxt/schema": "4.0.0-alpha.3"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=18.12.0"
|