@dudousxd/nestjs-codegen 0.16.0 → 0.17.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/CHANGELOG.md +37 -0
- package/dist/cli/main.cjs +142 -97
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +83 -38
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.cjs.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/{index-LQNP7Ms3.d.cts → index-DCF9QSPY.d.cts} +24 -0
- package/dist/{index-LQNP7Ms3.d.ts → index-DCF9QSPY.d.ts} +24 -0
- package/dist/index.cjs +105 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +77 -32
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +105 -60
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +77 -32
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/main.cjs
CHANGED
|
@@ -219,7 +219,7 @@ Run \`nestjs-codegen init\` to create a starter config.`
|
|
|
219
219
|
|
|
220
220
|
// src/generate.ts
|
|
221
221
|
var import_promises12 = require("fs/promises");
|
|
222
|
-
var
|
|
222
|
+
var import_node_path14 = require("path");
|
|
223
223
|
|
|
224
224
|
// src/discovery/pages.ts
|
|
225
225
|
var import_promises2 = require("fs/promises");
|
|
@@ -548,9 +548,10 @@ function inferExpressionType(node) {
|
|
|
548
548
|
|
|
549
549
|
// src/emit/emit-api.ts
|
|
550
550
|
var import_promises3 = require("fs/promises");
|
|
551
|
-
var
|
|
551
|
+
var import_node_path5 = require("path");
|
|
552
552
|
|
|
553
553
|
// src/extension/registry.ts
|
|
554
|
+
var import_node_path4 = require("path");
|
|
554
555
|
var import_ts_morph2 = require("ts-morph");
|
|
555
556
|
function resolveApiSlots(extensions) {
|
|
556
557
|
let layer;
|
|
@@ -583,7 +584,7 @@ function mergeExclusive(target, incoming, {
|
|
|
583
584
|
target.set(key, { value, owner });
|
|
584
585
|
}
|
|
585
586
|
}
|
|
586
|
-
function createExtensionContext(config, getRoutes) {
|
|
587
|
+
function createExtensionContext(config, getRoutes, trackedInputs) {
|
|
587
588
|
let project;
|
|
588
589
|
return {
|
|
589
590
|
cwd: config.codegen.cwd,
|
|
@@ -592,6 +593,13 @@ function createExtensionContext(config, getRoutes) {
|
|
|
592
593
|
get routes() {
|
|
593
594
|
return getRoutes();
|
|
594
595
|
},
|
|
596
|
+
trackInput(...paths) {
|
|
597
|
+
if (!trackedInputs) return;
|
|
598
|
+
for (const path of paths) {
|
|
599
|
+
if (!path) continue;
|
|
600
|
+
trackedInputs.add((0, import_node_path4.relative)(config.codegen.cwd, (0, import_node_path4.resolve)(config.codegen.cwd, path)));
|
|
601
|
+
}
|
|
602
|
+
},
|
|
595
603
|
project() {
|
|
596
604
|
if (!project) {
|
|
597
605
|
project = new import_ts_morph2.Project({
|
|
@@ -651,7 +659,7 @@ function requestShape(route) {
|
|
|
651
659
|
async function emitApi(routes, outDir, opts = {}) {
|
|
652
660
|
await (0, import_promises3.mkdir)(outDir, { recursive: true });
|
|
653
661
|
const content = buildApiFile(routes, outDir, opts);
|
|
654
|
-
await (0, import_promises3.writeFile)((0,
|
|
662
|
+
await (0, import_promises3.writeFile)((0, import_node_path5.join)(outDir, "api.ts"), content, "utf8");
|
|
655
663
|
}
|
|
656
664
|
function splitName(name) {
|
|
657
665
|
return name.split(".");
|
|
@@ -759,7 +767,7 @@ function rawResponseType(c, outDir) {
|
|
|
759
767
|
return c.contractSource.response;
|
|
760
768
|
}
|
|
761
769
|
if (c.controllerRef) {
|
|
762
|
-
let relPath = (0,
|
|
770
|
+
let relPath = (0, import_node_path5.relative)(outDir, c.controllerRef.filePath).replace(/\.ts$/, "");
|
|
763
771
|
if (!relPath.startsWith(".")) relPath = `./${relPath}`;
|
|
764
772
|
return `Awaited<ReturnType<import('${relPath}').${c.controllerRef.className}['${c.controllerRef.methodName}']>>`;
|
|
765
773
|
}
|
|
@@ -1085,6 +1093,11 @@ function buildApiFile(routes, outDir, opts = {}) {
|
|
|
1085
1093
|
config: {},
|
|
1086
1094
|
project: () => {
|
|
1087
1095
|
throw new Error("ExtensionContext.project() is unavailable in standalone emitApi.");
|
|
1096
|
+
},
|
|
1097
|
+
// No manifest is written on the standalone path, so there is nothing for
|
|
1098
|
+
// tracked dependencies to be recorded into — accept and discard them
|
|
1099
|
+
// rather than making every caller supply a sink.
|
|
1100
|
+
trackInput: () => {
|
|
1088
1101
|
}
|
|
1089
1102
|
};
|
|
1090
1103
|
const importsByFile = /* @__PURE__ */ new Map();
|
|
@@ -1140,8 +1153,8 @@ function buildApiFile(routes, outDir, opts = {}) {
|
|
|
1140
1153
|
const emittedNames = /* @__PURE__ */ new Set();
|
|
1141
1154
|
for (const [filePath, names] of importsByFile) {
|
|
1142
1155
|
let relPath;
|
|
1143
|
-
if ((0,
|
|
1144
|
-
relPath = (0,
|
|
1156
|
+
if ((0, import_node_path5.isAbsolute)(filePath)) {
|
|
1157
|
+
relPath = (0, import_node_path5.relative)(outDir, filePath).replace(/\.ts$/, "");
|
|
1145
1158
|
if (!relPath.startsWith(".")) relPath = `./${relPath}`;
|
|
1146
1159
|
} else {
|
|
1147
1160
|
relPath = filePath;
|
|
@@ -1235,7 +1248,7 @@ function buildApiFile(routes, outDir, opts = {}) {
|
|
|
1235
1248
|
|
|
1236
1249
|
// src/emit/emit-cache.ts
|
|
1237
1250
|
var import_promises4 = require("fs/promises");
|
|
1238
|
-
var
|
|
1251
|
+
var import_node_path6 = require("path");
|
|
1239
1252
|
async function emitCache(pages, outDir) {
|
|
1240
1253
|
await (0, import_promises4.mkdir)(outDir, { recursive: true });
|
|
1241
1254
|
const entries = await Promise.all(
|
|
@@ -1249,19 +1262,19 @@ async function emitCache(pages, outDir) {
|
|
|
1249
1262
|
})
|
|
1250
1263
|
);
|
|
1251
1264
|
const cache = { pages: entries };
|
|
1252
|
-
await (0, import_promises4.writeFile)((0,
|
|
1265
|
+
await (0, import_promises4.writeFile)((0, import_node_path6.join)(outDir, "components.json"), `${JSON.stringify(cache, null, 2)}
|
|
1253
1266
|
`, "utf8");
|
|
1254
1267
|
}
|
|
1255
1268
|
|
|
1256
1269
|
// src/emit/emit-forms.ts
|
|
1257
1270
|
var import_promises5 = require("fs/promises");
|
|
1258
|
-
var
|
|
1271
|
+
var import_node_path7 = require("path");
|
|
1259
1272
|
async function emitForms(routes, outDir, config, adapter) {
|
|
1260
1273
|
if (config && config.enabled === false) return false;
|
|
1261
1274
|
const content = buildFormsFileWithAdapter(routes, outDir, adapter, config);
|
|
1262
1275
|
if (content === null) return false;
|
|
1263
1276
|
await (0, import_promises5.mkdir)(outDir, { recursive: true });
|
|
1264
|
-
await (0, import_promises5.writeFile)((0,
|
|
1277
|
+
await (0, import_promises5.writeFile)((0, import_node_path7.join)(outDir, "forms.ts"), content, "utf8");
|
|
1265
1278
|
return true;
|
|
1266
1279
|
}
|
|
1267
1280
|
function pascal(segment) {
|
|
@@ -1274,7 +1287,7 @@ function deriveBaseName(routeName) {
|
|
|
1274
1287
|
return { method, full };
|
|
1275
1288
|
}
|
|
1276
1289
|
function relImport(outDir, filePath) {
|
|
1277
|
-
let relPath = (0,
|
|
1290
|
+
let relPath = (0, import_node_path7.relative)(outDir, filePath).replace(/\.ts$/, "");
|
|
1278
1291
|
if (!relPath.startsWith(".")) relPath = `./${relPath}`;
|
|
1279
1292
|
return relPath;
|
|
1280
1293
|
}
|
|
@@ -1548,7 +1561,7 @@ function buildFormsFileWithAdapter(routes, outDir, adapter, config) {
|
|
|
1548
1561
|
|
|
1549
1562
|
// src/emit/emit-index.ts
|
|
1550
1563
|
var import_promises6 = require("fs/promises");
|
|
1551
|
-
var
|
|
1564
|
+
var import_node_path8 = require("path");
|
|
1552
1565
|
async function emitIndex(outDir, hasContracts = false, hasForms = false) {
|
|
1553
1566
|
await (0, import_promises6.mkdir)(outDir, { recursive: true });
|
|
1554
1567
|
const exports2 = ["export * from './pages.js';", "export * from './routes.js';"];
|
|
@@ -1561,12 +1574,12 @@ async function emitIndex(outDir, hasContracts = false, hasForms = false) {
|
|
|
1561
1574
|
const content = ["// Generated by @dudousxd/nestjs-codegen. Do not edit.", ...exports2, ""].join(
|
|
1562
1575
|
"\n"
|
|
1563
1576
|
);
|
|
1564
|
-
await (0, import_promises6.writeFile)((0,
|
|
1577
|
+
await (0, import_promises6.writeFile)((0, import_node_path8.join)(outDir, "index.d.ts"), content, "utf8");
|
|
1565
1578
|
}
|
|
1566
1579
|
|
|
1567
1580
|
// src/emit/emit-mocks.ts
|
|
1568
1581
|
var import_promises7 = require("fs/promises");
|
|
1569
|
-
var
|
|
1582
|
+
var import_node_path9 = require("path");
|
|
1570
1583
|
|
|
1571
1584
|
// src/ir/schema-node-to-json-schema.ts
|
|
1572
1585
|
var DEFAULT_CTX = { refPrefix: "#/components/schemas/" };
|
|
@@ -1890,12 +1903,12 @@ async function emitMocks(routes, outDir, opts = {}) {
|
|
|
1890
1903
|
await (0, import_promises7.mkdir)(outDir, { recursive: true });
|
|
1891
1904
|
const content = buildMocksFile(routes, opts);
|
|
1892
1905
|
const fileName = opts.fileName ?? "mocks.ts";
|
|
1893
|
-
await (0, import_promises7.writeFile)((0,
|
|
1906
|
+
await (0, import_promises7.writeFile)((0, import_node_path9.join)(outDir, fileName), content, "utf8");
|
|
1894
1907
|
}
|
|
1895
1908
|
|
|
1896
1909
|
// src/emit/emit-openapi.ts
|
|
1897
1910
|
var import_promises8 = require("fs/promises");
|
|
1898
|
-
var
|
|
1911
|
+
var import_node_path10 = require("path");
|
|
1899
1912
|
var REF_PREFIX2 = "#/components/schemas/";
|
|
1900
1913
|
function toOpenApiPath(path) {
|
|
1901
1914
|
return path.replace(/:([^/]+)/g, "{$1}");
|
|
@@ -2016,13 +2029,13 @@ async function emitOpenApi(routes, outDir, opts = {}) {
|
|
|
2016
2029
|
await (0, import_promises8.mkdir)(outDir, { recursive: true });
|
|
2017
2030
|
const doc = buildOpenApiSpec(routes, opts);
|
|
2018
2031
|
const fileName = opts.fileName ?? "openapi.json";
|
|
2019
|
-
await (0, import_promises8.writeFile)((0,
|
|
2032
|
+
await (0, import_promises8.writeFile)((0, import_node_path10.join)(outDir, fileName), `${JSON.stringify(doc, null, 2)}
|
|
2020
2033
|
`, "utf8");
|
|
2021
2034
|
}
|
|
2022
2035
|
|
|
2023
2036
|
// src/emit/emit-pages.ts
|
|
2024
2037
|
var import_promises9 = require("fs/promises");
|
|
2025
|
-
var
|
|
2038
|
+
var import_node_path11 = require("path");
|
|
2026
2039
|
async function emitPages(pages, outDir, _options = {}) {
|
|
2027
2040
|
await (0, import_promises9.mkdir)(outDir, { recursive: true });
|
|
2028
2041
|
const pageNameUnion = pages.length > 0 ? pages.map((p) => JSON.stringify(p.name)).join(" | ") : "never";
|
|
@@ -2043,7 +2056,7 @@ ${augBody}
|
|
|
2043
2056
|
}
|
|
2044
2057
|
${sharedPropsBlock}}
|
|
2045
2058
|
`;
|
|
2046
|
-
await (0, import_promises9.writeFile)((0,
|
|
2059
|
+
await (0, import_promises9.writeFile)((0, import_node_path11.join)(outDir, "pages.d.ts"), content, "utf8");
|
|
2047
2060
|
}
|
|
2048
2061
|
function buildSharedPropsBlock(sharedProps) {
|
|
2049
2062
|
if (!sharedProps) return "";
|
|
@@ -2062,7 +2075,7 @@ ${propsBody}
|
|
|
2062
2075
|
`;
|
|
2063
2076
|
}
|
|
2064
2077
|
function buildAugmentationType(page, outDir) {
|
|
2065
|
-
let importPath = (0,
|
|
2078
|
+
let importPath = (0, import_node_path11.relative)(outDir, page.absolutePath).replace(/\.(tsx?|vue|svelte)$/, "");
|
|
2066
2079
|
if (!importPath.startsWith(".")) {
|
|
2067
2080
|
importPath = `./${importPath}`;
|
|
2068
2081
|
}
|
|
@@ -2074,11 +2087,11 @@ function needsQuotes(name) {
|
|
|
2074
2087
|
|
|
2075
2088
|
// src/emit/emit-routes.ts
|
|
2076
2089
|
var import_promises10 = require("fs/promises");
|
|
2077
|
-
var
|
|
2090
|
+
var import_node_path12 = require("path");
|
|
2078
2091
|
async function emitRoutes(routes, outDir) {
|
|
2079
2092
|
await (0, import_promises10.mkdir)(outDir, { recursive: true });
|
|
2080
2093
|
const content = buildRoutesFile(routes);
|
|
2081
|
-
await (0, import_promises10.writeFile)((0,
|
|
2094
|
+
await (0, import_promises10.writeFile)((0, import_node_path12.join)(outDir, "routes.ts"), content, "utf8");
|
|
2082
2095
|
}
|
|
2083
2096
|
function buildRoutesFile(routes) {
|
|
2084
2097
|
if (routes.length === 0) {
|
|
@@ -2193,7 +2206,7 @@ function buildEmpty() {
|
|
|
2193
2206
|
// src/generate-manifest.ts
|
|
2194
2207
|
var import_node_crypto = require("crypto");
|
|
2195
2208
|
var import_promises11 = require("fs/promises");
|
|
2196
|
-
var
|
|
2209
|
+
var import_node_path13 = require("path");
|
|
2197
2210
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
2198
2211
|
var MANIFEST_FILE = ".codegen-manifest.json";
|
|
2199
2212
|
var LOCK_FILE = ".watcher.lock";
|
|
@@ -2216,6 +2229,9 @@ function isManifestShape(value) {
|
|
|
2216
2229
|
if (candidate.configKeyHashes !== void 0 && !isStringRecord(candidate.configKeyHashes)) {
|
|
2217
2230
|
return false;
|
|
2218
2231
|
}
|
|
2232
|
+
if (candidate.extraInputs !== void 0 && (!Array.isArray(candidate.extraInputs) || !candidate.extraInputs.every((entry) => typeof entry === "string"))) {
|
|
2233
|
+
return false;
|
|
2234
|
+
}
|
|
2219
2235
|
if (!Array.isArray(candidate.files)) return false;
|
|
2220
2236
|
return candidate.files.every((entry) => typeof entry === "string");
|
|
2221
2237
|
}
|
|
@@ -2255,26 +2271,35 @@ async function discoverInputFiles(config) {
|
|
|
2255
2271
|
const matched = await (0, import_fast_glob2.default)(globs, { cwd, absolute: true, onlyFiles: true });
|
|
2256
2272
|
return [...new Set(matched)].sort();
|
|
2257
2273
|
}
|
|
2258
|
-
async function computeInputsHash(config) {
|
|
2274
|
+
async function computeInputsHash(config, extraInputs = []) {
|
|
2259
2275
|
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
2260
2276
|
hash.update(`version:${VERSION}
|
|
2261
2277
|
`);
|
|
2262
2278
|
hash.update(`config:${serializeConfig(config)}
|
|
2263
2279
|
`);
|
|
2264
|
-
const inputFiles = await discoverInputFiles(config);
|
|
2265
2280
|
const cwd = config.codegen.cwd;
|
|
2266
|
-
|
|
2281
|
+
const globbed = await discoverInputFiles(config);
|
|
2282
|
+
const globbedRelative = new Set(globbed.map((file) => (0, import_node_path13.relative)(cwd, file)));
|
|
2283
|
+
const extra = [...new Set(extraInputs)].filter((file) => !globbedRelative.has(file)).sort();
|
|
2284
|
+
for (const file of globbed) {
|
|
2267
2285
|
const contents = await (0, import_promises11.readFile)(file, "utf8");
|
|
2268
|
-
hash.update(`file:${(0,
|
|
2286
|
+
hash.update(`file:${(0, import_node_path13.relative)(cwd, file)}
|
|
2269
2287
|
`);
|
|
2270
2288
|
hash.update(contents);
|
|
2271
2289
|
hash.update("\n");
|
|
2272
2290
|
}
|
|
2291
|
+
for (const file of extra) {
|
|
2292
|
+
const contents = await (0, import_promises11.readFile)((0, import_node_path13.join)(cwd, file), "utf8").catch(() => null);
|
|
2293
|
+
hash.update(`extra:${file}
|
|
2294
|
+
`);
|
|
2295
|
+
hash.update(contents ?? "\0missing");
|
|
2296
|
+
hash.update("\n");
|
|
2297
|
+
}
|
|
2273
2298
|
return hash.digest("hex");
|
|
2274
2299
|
}
|
|
2275
2300
|
async function readManifest(outDir) {
|
|
2276
2301
|
try {
|
|
2277
|
-
const raw = await (0, import_promises11.readFile)((0,
|
|
2302
|
+
const raw = await (0, import_promises11.readFile)((0, import_node_path13.join)(outDir, MANIFEST_FILE), "utf8");
|
|
2278
2303
|
const parsed = JSON.parse(raw);
|
|
2279
2304
|
if (!isManifestShape(parsed)) return null;
|
|
2280
2305
|
return {
|
|
@@ -2283,6 +2308,7 @@ async function readManifest(outDir) {
|
|
|
2283
2308
|
...parsed.entryPoint ? { entryPoint: parsed.entryPoint } : {},
|
|
2284
2309
|
...parsed.configHash ? { configHash: parsed.configHash } : {},
|
|
2285
2310
|
...parsed.configKeyHashes ? { configKeyHashes: parsed.configKeyHashes } : {},
|
|
2311
|
+
...parsed.extraInputs ? { extraInputs: parsed.extraInputs } : {},
|
|
2286
2312
|
files: parsed.files
|
|
2287
2313
|
};
|
|
2288
2314
|
} catch {
|
|
@@ -2293,7 +2319,7 @@ function computeConfigHash(config) {
|
|
|
2293
2319
|
return (0, import_node_crypto.createHash)("sha256").update(serializeConfig(config)).digest("hex");
|
|
2294
2320
|
}
|
|
2295
2321
|
async function writeManifest(outDir, manifest) {
|
|
2296
|
-
await (0, import_promises11.writeFile)((0,
|
|
2322
|
+
await (0, import_promises11.writeFile)((0, import_node_path13.join)(outDir, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
|
|
2297
2323
|
`, "utf8");
|
|
2298
2324
|
}
|
|
2299
2325
|
async function listOutputFiles(outDir) {
|
|
@@ -2301,11 +2327,11 @@ async function listOutputFiles(outDir) {
|
|
|
2301
2327
|
async function walk(dir) {
|
|
2302
2328
|
const entries = await (0, import_promises11.readdir)(dir, { withFileTypes: true }).catch(() => []);
|
|
2303
2329
|
for (const entry of entries) {
|
|
2304
|
-
const abs = (0,
|
|
2330
|
+
const abs = (0, import_node_path13.join)(dir, entry.name);
|
|
2305
2331
|
if (entry.isDirectory()) {
|
|
2306
2332
|
await walk(abs);
|
|
2307
2333
|
} else if (entry.isFile()) {
|
|
2308
|
-
const rel = (0,
|
|
2334
|
+
const rel = (0, import_node_path13.relative)(outDir, abs);
|
|
2309
2335
|
if (rel === MANIFEST_FILE || rel === LOCK_FILE) continue;
|
|
2310
2336
|
found.push(rel);
|
|
2311
2337
|
}
|
|
@@ -2342,8 +2368,8 @@ function driftGuardMessage(outDir, previousEntryPoint, currentEntryPoint, differ
|
|
|
2342
2368
|
}
|
|
2343
2369
|
async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
2344
2370
|
setCodegenDebug(config.debug);
|
|
2345
|
-
const inputsHash = await computeInputsHash(config);
|
|
2346
2371
|
const manifest = await readManifest(config.codegen.outDir);
|
|
2372
|
+
const inputsHash = await computeInputsHash(config, manifest?.extraInputs ?? []);
|
|
2347
2373
|
if (await isManifestFresh(config.codegen.outDir, manifest, inputsHash)) {
|
|
2348
2374
|
console.log(`[nestjs-codegen] ${config.codegen.outDir} up to date, skipped`);
|
|
2349
2375
|
return;
|
|
@@ -2364,7 +2390,8 @@ async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
|
2364
2390
|
}
|
|
2365
2391
|
const extensions = config.extensions ?? [];
|
|
2366
2392
|
let routes = inputRoutes;
|
|
2367
|
-
const
|
|
2393
|
+
const trackedInputs = /* @__PURE__ */ new Set();
|
|
2394
|
+
const ctx = createExtensionContext(config, () => routes, trackedInputs);
|
|
2368
2395
|
if (extensions.length > 0) {
|
|
2369
2396
|
routes = await applyTransformRoutes(routes, extensions, ctx);
|
|
2370
2397
|
}
|
|
@@ -2418,29 +2445,32 @@ async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
|
2418
2445
|
if (extensions.length > 0) {
|
|
2419
2446
|
const extraFiles = await collectEmittedFiles(extensions, ctx);
|
|
2420
2447
|
for (const file of extraFiles) {
|
|
2421
|
-
const dest = (0,
|
|
2422
|
-
await (0, import_promises12.mkdir)((0,
|
|
2448
|
+
const dest = (0, import_node_path14.join)(config.codegen.outDir, file.path);
|
|
2449
|
+
await (0, import_promises12.mkdir)((0, import_node_path14.dirname)(dest), { recursive: true });
|
|
2423
2450
|
await (0, import_promises12.writeFile)(dest, file.contents, "utf8");
|
|
2424
2451
|
}
|
|
2425
2452
|
}
|
|
2426
2453
|
const outputFiles = await listOutputFiles(config.codegen.outDir);
|
|
2454
|
+
const extraInputs = [...trackedInputs].sort();
|
|
2455
|
+
const recordedHash = extraInputs.length > 0 ? await computeInputsHash(config, extraInputs) : inputsHash;
|
|
2427
2456
|
await writeManifest(config.codegen.outDir, {
|
|
2428
2457
|
version: VERSION,
|
|
2429
|
-
hash:
|
|
2458
|
+
hash: recordedHash,
|
|
2430
2459
|
entryPoint,
|
|
2431
2460
|
configHash,
|
|
2432
2461
|
configKeyHashes,
|
|
2433
|
-
files: outputFiles
|
|
2462
|
+
files: outputFiles,
|
|
2463
|
+
...extraInputs.length > 0 ? { extraInputs } : {}
|
|
2434
2464
|
});
|
|
2435
2465
|
}
|
|
2436
2466
|
|
|
2437
2467
|
// src/watch/watcher.ts
|
|
2438
2468
|
var import_promises15 = require("fs/promises");
|
|
2439
|
-
var
|
|
2469
|
+
var import_node_path18 = require("path");
|
|
2440
2470
|
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
2441
2471
|
|
|
2442
2472
|
// src/discovery/contracts-fast.ts
|
|
2443
|
-
var
|
|
2473
|
+
var import_node_path16 = require("path");
|
|
2444
2474
|
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
2445
2475
|
var import_ts_morph10 = require("ts-morph");
|
|
2446
2476
|
|
|
@@ -2452,7 +2482,7 @@ var import_ts_morph4 = require("ts-morph");
|
|
|
2452
2482
|
|
|
2453
2483
|
// src/discovery/type-ref-resolution.ts
|
|
2454
2484
|
var import_node_fs = require("fs");
|
|
2455
|
-
var
|
|
2485
|
+
var import_node_path15 = require("path");
|
|
2456
2486
|
var import_ts_morph3 = require("ts-morph");
|
|
2457
2487
|
var _EMPTY_CTX = { projectRoot: "", tsconfigPaths: null };
|
|
2458
2488
|
var _ctxByProject = /* @__PURE__ */ new WeakMap();
|
|
@@ -2504,12 +2534,12 @@ function findTypeInFile(name, file) {
|
|
|
2504
2534
|
}
|
|
2505
2535
|
function resolveModuleSpecifier(moduleSpecifier, sourceFile, project) {
|
|
2506
2536
|
if (moduleSpecifier.startsWith(".")) {
|
|
2507
|
-
const dir = (0,
|
|
2537
|
+
const dir = (0, import_node_path15.dirname)(sourceFile.getFilePath());
|
|
2508
2538
|
const noExt = moduleSpecifier.replace(/\.(js|ts)$/, "");
|
|
2509
2539
|
return [
|
|
2510
|
-
(0,
|
|
2511
|
-
(0,
|
|
2512
|
-
(0,
|
|
2540
|
+
(0, import_node_path15.resolve)(dir, `${noExt}.ts`),
|
|
2541
|
+
(0, import_node_path15.resolve)(dir, `${moduleSpecifier}.ts`),
|
|
2542
|
+
(0, import_node_path15.resolve)(dir, moduleSpecifier, "index.ts")
|
|
2513
2543
|
];
|
|
2514
2544
|
}
|
|
2515
2545
|
const ctx = _ctxFor(project);
|
|
@@ -2530,8 +2560,8 @@ function resolveModuleSpecifier(moduleSpecifier, sourceFile, project) {
|
|
|
2530
2560
|
const rest = moduleSpecifier.slice(prefix.length);
|
|
2531
2561
|
const candidates = [];
|
|
2532
2562
|
for (const mapping of mappings) {
|
|
2533
|
-
const resolved = (0,
|
|
2534
|
-
candidates.push(`${resolved}.ts`, (0,
|
|
2563
|
+
const resolved = (0, import_node_path15.resolve)(baseUrl, mapping.replace("*", rest));
|
|
2564
|
+
candidates.push(`${resolved}.ts`, (0, import_node_path15.resolve)(resolved, "index.ts"));
|
|
2535
2565
|
}
|
|
2536
2566
|
dbg(" resolved candidates:", candidates);
|
|
2537
2567
|
return candidates;
|
|
@@ -4173,6 +4203,19 @@ function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
|
4173
4203
|
|
|
4174
4204
|
// src/discovery/heritage.ts
|
|
4175
4205
|
var import_ts_morph8 = require("ts-morph");
|
|
4206
|
+
function resolveHeritageCall(node) {
|
|
4207
|
+
if (!node) return void 0;
|
|
4208
|
+
const expr = unwrapExpression(node);
|
|
4209
|
+
if (import_ts_morph8.Node.isCallExpression(expr)) return expr;
|
|
4210
|
+
if (!import_ts_morph8.Node.isIdentifier(expr)) return void 0;
|
|
4211
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find(
|
|
4212
|
+
(n) => n !== void 0 && import_ts_morph8.Node.isVariableDeclaration(n)
|
|
4213
|
+
);
|
|
4214
|
+
const init = decl?.getInitializer();
|
|
4215
|
+
if (!init) return void 0;
|
|
4216
|
+
const unwrapped = unwrapExpression(init);
|
|
4217
|
+
return import_ts_morph8.Node.isCallExpression(unwrapped) ? unwrapped : void 0;
|
|
4218
|
+
}
|
|
4176
4219
|
function unwrapExpression(node) {
|
|
4177
4220
|
let current = node;
|
|
4178
4221
|
while (import_ts_morph8.Node.isAsExpression(current) || import_ts_morph8.Node.isSatisfiesExpression(current) || import_ts_morph8.Node.isParenthesizedExpression(current) || import_ts_morph8.Node.isTypeAssertion(current)) {
|
|
@@ -4200,8 +4243,8 @@ function resolveReturnedClass(factoryDecl) {
|
|
|
4200
4243
|
return void 0;
|
|
4201
4244
|
}
|
|
4202
4245
|
function resolveInheritedMethods(cls) {
|
|
4203
|
-
const expr = cls.getExtends()?.getExpression();
|
|
4204
|
-
if (!expr
|
|
4246
|
+
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
4247
|
+
if (!expr) return void 0;
|
|
4205
4248
|
const callee = expr.getExpression();
|
|
4206
4249
|
if (!import_ts_morph8.Node.isIdentifier(callee)) return void 0;
|
|
4207
4250
|
const factoryDecl = callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => import_ts_morph8.Node.isFunctionDeclaration(n));
|
|
@@ -4390,7 +4433,7 @@ async function discoverContractsFast(opts) {
|
|
|
4390
4433
|
return extractAllRoutes(project);
|
|
4391
4434
|
}
|
|
4392
4435
|
function resolveTsconfigPath(cwd, tsconfig) {
|
|
4393
|
-
return tsconfig ? (0,
|
|
4436
|
+
return tsconfig ? (0, import_node_path16.resolve)(tsconfig) : (0, import_node_path16.join)(cwd, "tsconfig.json");
|
|
4394
4437
|
}
|
|
4395
4438
|
function createDiscoveryProject(tsconfigPath) {
|
|
4396
4439
|
try {
|
|
@@ -4476,7 +4519,7 @@ var PersistentDiscovery = class _PersistentDiscovery {
|
|
|
4476
4519
|
async rediscover(changedPaths) {
|
|
4477
4520
|
if (changedPaths) {
|
|
4478
4521
|
for (const p of changedPaths) {
|
|
4479
|
-
const abs = (0,
|
|
4522
|
+
const abs = (0, import_node_path16.resolve)(p);
|
|
4480
4523
|
const sf = this.project.getSourceFile(abs);
|
|
4481
4524
|
if (sf) {
|
|
4482
4525
|
await sf.refreshFromFileSystem();
|
|
@@ -4756,9 +4799,11 @@ function extractFromSourceFile(sourceFile, project) {
|
|
|
4756
4799
|
factoryFilePath: inherited.factoryFilePath,
|
|
4757
4800
|
classArgs: inherited.classArgs
|
|
4758
4801
|
} : void 0;
|
|
4802
|
+
const ownMethods = cls.getMethods();
|
|
4803
|
+
const ownNames = new Set(ownMethods.map((m) => m.getName()));
|
|
4759
4804
|
const methods = [
|
|
4760
|
-
...
|
|
4761
|
-
...(inherited?.methods ?? []).map((method) => ({ method, mixin: mixinBinding }))
|
|
4805
|
+
...ownMethods.map((method) => ({ method, mixin: mixinBinding })),
|
|
4806
|
+
...(inherited?.methods ?? []).filter((method) => !ownNames.has(method.getName())).map((method) => ({ method, mixin: mixinBinding }))
|
|
4762
4807
|
];
|
|
4763
4808
|
for (const { method, mixin } of methods) {
|
|
4764
4809
|
const verb = resolveVerb(method);
|
|
@@ -4794,7 +4839,7 @@ function extractFromSourceFile(sourceFile, project) {
|
|
|
4794
4839
|
// src/watch/lock-file.ts
|
|
4795
4840
|
var import_promises13 = require("fs/promises");
|
|
4796
4841
|
var import_promises14 = require("fs/promises");
|
|
4797
|
-
var
|
|
4842
|
+
var import_node_path17 = require("path");
|
|
4798
4843
|
var LOCK_FILE2 = ".watcher.lock";
|
|
4799
4844
|
function isProcessAlive(pid) {
|
|
4800
4845
|
try {
|
|
@@ -4806,7 +4851,7 @@ function isProcessAlive(pid) {
|
|
|
4806
4851
|
}
|
|
4807
4852
|
async function acquireLock(outDir) {
|
|
4808
4853
|
await (0, import_promises14.mkdir)(outDir, { recursive: true });
|
|
4809
|
-
const lockPath = (0,
|
|
4854
|
+
const lockPath = (0, import_node_path17.join)(outDir, LOCK_FILE2);
|
|
4810
4855
|
const lockData = { pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4811
4856
|
try {
|
|
4812
4857
|
const fd = await (0, import_promises13.open)(lockPath, "wx");
|
|
@@ -4847,7 +4892,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4847
4892
|
if (lock === null) {
|
|
4848
4893
|
let holderPid = "unknown";
|
|
4849
4894
|
try {
|
|
4850
|
-
const raw = await (0, import_promises15.readFile)((0,
|
|
4895
|
+
const raw = await (0, import_promises15.readFile)((0, import_node_path18.join)(config.codegen.outDir, ".watcher.lock"), "utf8");
|
|
4851
4896
|
const data = JSON.parse(raw);
|
|
4852
4897
|
if (data.pid !== void 0) holderPid = String(data.pid);
|
|
4853
4898
|
} catch {
|
|
@@ -4900,7 +4945,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4900
4945
|
}
|
|
4901
4946
|
let pagesDebounceTimer;
|
|
4902
4947
|
const pagesGlob = config.pages?.glob ?? ".nestjs-codegen-no-pages";
|
|
4903
|
-
const pagesWatcher = import_chokidar.default.watch((0,
|
|
4948
|
+
const pagesWatcher = import_chokidar.default.watch((0, import_node_path18.join)(config.codegen.cwd, pagesGlob), {
|
|
4904
4949
|
ignoreInitial: true,
|
|
4905
4950
|
persistent: true,
|
|
4906
4951
|
awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 20 }
|
|
@@ -4927,7 +4972,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4927
4972
|
pagesWatcher.on("unlink", schedulePagesRegenerate);
|
|
4928
4973
|
let contractsDebounceTimer;
|
|
4929
4974
|
const pendingChangedPaths = /* @__PURE__ */ new Set();
|
|
4930
|
-
const contractsWatcher = import_chokidar.default.watch((0,
|
|
4975
|
+
const contractsWatcher = import_chokidar.default.watch((0, import_node_path18.join)(config.codegen.cwd, config.contracts.glob), {
|
|
4931
4976
|
ignoreInitial: true,
|
|
4932
4977
|
persistent: true,
|
|
4933
4978
|
awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 20 }
|
|
@@ -4957,7 +5002,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4957
5002
|
contractsWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
4958
5003
|
contractsWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
4959
5004
|
contractsWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
4960
|
-
const formsWatcher = import_chokidar.default.watch((0,
|
|
5005
|
+
const formsWatcher = import_chokidar.default.watch((0, import_node_path18.join)(config.codegen.cwd, config.forms.watch), {
|
|
4961
5006
|
ignoreInitial: true,
|
|
4962
5007
|
persistent: true,
|
|
4963
5008
|
awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 20 }
|
|
@@ -4984,7 +5029,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4984
5029
|
}
|
|
4985
5030
|
|
|
4986
5031
|
// src/index.ts
|
|
4987
|
-
var VERSION = "0.
|
|
5032
|
+
var VERSION = "0.17.1";
|
|
4988
5033
|
|
|
4989
5034
|
// src/cli/codegen.ts
|
|
4990
5035
|
async function runCodegen(opts = {}) {
|
|
@@ -4992,9 +5037,9 @@ async function runCodegen(opts = {}) {
|
|
|
4992
5037
|
const config = await loadConfig(cwd);
|
|
4993
5038
|
if (opts.watch) {
|
|
4994
5039
|
const watcher = await watch(config, void 0, { entryPoint: "cli" });
|
|
4995
|
-
await new Promise((
|
|
5040
|
+
await new Promise((resolve5) => {
|
|
4996
5041
|
function onSignal() {
|
|
4997
|
-
watcher.close().then(
|
|
5042
|
+
watcher.close().then(resolve5).catch(resolve5);
|
|
4998
5043
|
}
|
|
4999
5044
|
process.once("SIGINT", onSignal);
|
|
5000
5045
|
process.once("SIGTERM", onSignal);
|
|
@@ -5013,13 +5058,13 @@ async function runCodegen(opts = {}) {
|
|
|
5013
5058
|
// src/cli/doctor.ts
|
|
5014
5059
|
var import_node_child_process2 = require("child_process");
|
|
5015
5060
|
var import_node_fs4 = require("fs");
|
|
5016
|
-
var
|
|
5061
|
+
var import_node_path20 = require("path");
|
|
5017
5062
|
|
|
5018
5063
|
// src/cli/init.ts
|
|
5019
5064
|
var import_node_child_process = require("child_process");
|
|
5020
5065
|
var import_node_fs3 = require("fs");
|
|
5021
5066
|
var import_promises16 = require("fs/promises");
|
|
5022
|
-
var
|
|
5067
|
+
var import_node_path19 = require("path");
|
|
5023
5068
|
var import_node_readline = require("readline");
|
|
5024
5069
|
|
|
5025
5070
|
// src/cli/patch-utils.ts
|
|
@@ -5081,7 +5126,7 @@ ${bold(title)}`);
|
|
|
5081
5126
|
}
|
|
5082
5127
|
async function readPackageJson(cwd) {
|
|
5083
5128
|
try {
|
|
5084
|
-
const raw = await (0, import_promises16.readFile)((0,
|
|
5129
|
+
const raw = await (0, import_promises16.readFile)((0, import_node_path19.join)(cwd, "package.json"), "utf8");
|
|
5085
5130
|
return JSON.parse(raw);
|
|
5086
5131
|
} catch {
|
|
5087
5132
|
return {};
|
|
@@ -5112,7 +5157,7 @@ async function detectTemplateEngine(cwd) {
|
|
|
5112
5157
|
async function detectPackageManager(cwd) {
|
|
5113
5158
|
async function exists(file) {
|
|
5114
5159
|
try {
|
|
5115
|
-
await (0, import_promises16.access)((0,
|
|
5160
|
+
await (0, import_promises16.access)((0, import_node_path19.join)(cwd, file));
|
|
5116
5161
|
return true;
|
|
5117
5162
|
} catch {
|
|
5118
5163
|
return false;
|
|
@@ -5124,16 +5169,16 @@ async function detectPackageManager(cwd) {
|
|
|
5124
5169
|
}
|
|
5125
5170
|
async function promptFramework() {
|
|
5126
5171
|
if (!process.stdin.isTTY) return "react";
|
|
5127
|
-
return new Promise((
|
|
5172
|
+
return new Promise((resolve5) => {
|
|
5128
5173
|
const rl = (0, import_node_readline.createInterface)({ input: process.stdin, output: process.stdout });
|
|
5129
5174
|
rl.question(
|
|
5130
5175
|
"[nestjs-codegen] Which frontend framework? (react/vue/svelte) [react]: ",
|
|
5131
5176
|
(answer) => {
|
|
5132
5177
|
rl.close();
|
|
5133
5178
|
const trimmed = answer.trim().toLowerCase();
|
|
5134
|
-
if (trimmed === "vue")
|
|
5135
|
-
else if (trimmed === "svelte")
|
|
5136
|
-
else
|
|
5179
|
+
if (trimmed === "vue") resolve5("vue");
|
|
5180
|
+
else if (trimmed === "svelte") resolve5("svelte");
|
|
5181
|
+
else resolve5("react");
|
|
5137
5182
|
}
|
|
5138
5183
|
);
|
|
5139
5184
|
});
|
|
@@ -5159,7 +5204,7 @@ async function writeIfNotExists(filePath, content, label) {
|
|
|
5159
5204
|
logCreated(label);
|
|
5160
5205
|
}
|
|
5161
5206
|
async function handleViteConfig(cwd, framework) {
|
|
5162
|
-
const filePath = (0,
|
|
5207
|
+
const filePath = (0, import_node_path19.join)(cwd, "vite.config.ts");
|
|
5163
5208
|
if (await fileExists2(filePath)) {
|
|
5164
5209
|
const existing = await (0, import_promises16.readFile)(filePath, "utf8");
|
|
5165
5210
|
const hasPlugin = existing.includes("nestInertia") || existing.includes("nestjs-inertia-vite/plugin");
|
|
@@ -5217,7 +5262,7 @@ function installDeps(pkgManager, deps, dev) {
|
|
|
5217
5262
|
}
|
|
5218
5263
|
}
|
|
5219
5264
|
async function patchPackageJsonScripts(cwd, scripts) {
|
|
5220
|
-
const pkgPath = (0,
|
|
5265
|
+
const pkgPath = (0, import_node_path19.join)(cwd, "package.json");
|
|
5221
5266
|
let pkg = {};
|
|
5222
5267
|
try {
|
|
5223
5268
|
pkg = JSON.parse(await (0, import_promises16.readFile)(pkgPath, "utf8"));
|
|
@@ -5534,7 +5579,7 @@ export class HomeController {
|
|
|
5534
5579
|
}
|
|
5535
5580
|
`;
|
|
5536
5581
|
function patchTsconfigExclude(cwd, dir, filename = "tsconfig.json") {
|
|
5537
|
-
const filePath = (0,
|
|
5582
|
+
const filePath = (0, import_node_path19.join)(cwd, filename);
|
|
5538
5583
|
return patchJsonFile(
|
|
5539
5584
|
filePath,
|
|
5540
5585
|
(json) => {
|
|
@@ -5549,7 +5594,7 @@ function patchTsconfigExclude(cwd, dir, filename = "tsconfig.json") {
|
|
|
5549
5594
|
);
|
|
5550
5595
|
}
|
|
5551
5596
|
function patchNestCliJson(cwd, shellDir) {
|
|
5552
|
-
const filePath = (0,
|
|
5597
|
+
const filePath = (0, import_node_path19.join)(cwd, "nest-cli.json");
|
|
5553
5598
|
return patchJsonFile(filePath, (json) => {
|
|
5554
5599
|
const compiler = json.compilerOptions ?? {};
|
|
5555
5600
|
const assets = compiler.assets ?? [];
|
|
@@ -5572,46 +5617,46 @@ async function scaffoldFiles(ctx) {
|
|
|
5572
5617
|
const { cwd, framework, engine, shellFileName, entryExt, pageExt } = ctx;
|
|
5573
5618
|
logSection("Scaffold files");
|
|
5574
5619
|
await writeIfNotExists(
|
|
5575
|
-
(0,
|
|
5620
|
+
(0, import_node_path19.join)(cwd, "nestjs-inertia.config.ts"),
|
|
5576
5621
|
configTemplate(framework),
|
|
5577
5622
|
"nestjs-inertia.config.ts"
|
|
5578
5623
|
);
|
|
5579
|
-
await writeIfNotExists((0,
|
|
5624
|
+
await writeIfNotExists((0, import_node_path19.join)(cwd, "nestjs-inertia.d.ts"), DTS_TEMPLATE, "nestjs-inertia.d.ts");
|
|
5580
5625
|
await writeIfNotExists(
|
|
5581
|
-
(0,
|
|
5626
|
+
(0, import_node_path19.join)(cwd, "tsconfig.inertia.json"),
|
|
5582
5627
|
TSCONFIG_INERTIA_TEMPLATE,
|
|
5583
5628
|
"tsconfig.inertia.json"
|
|
5584
5629
|
);
|
|
5585
5630
|
await writeIfNotExists(
|
|
5586
|
-
(0,
|
|
5631
|
+
(0, import_node_path19.join)(cwd, "inertia", "tsconfig.json"),
|
|
5587
5632
|
INERTIA_TSCONFIG_TEMPLATE,
|
|
5588
5633
|
"inertia/tsconfig.json"
|
|
5589
5634
|
);
|
|
5590
5635
|
await writeIfNotExists(
|
|
5591
|
-
(0,
|
|
5636
|
+
(0, import_node_path19.join)(cwd, "inertia", shellFileName),
|
|
5592
5637
|
htmlShellTemplate(framework, engine),
|
|
5593
5638
|
`inertia/${shellFileName}`
|
|
5594
5639
|
);
|
|
5595
5640
|
await handleViteConfig(cwd, framework);
|
|
5596
5641
|
await writeIfNotExists(
|
|
5597
|
-
(0,
|
|
5642
|
+
(0, import_node_path19.join)(cwd, "inertia", "app", `client.${entryExt}`),
|
|
5598
5643
|
entryPointTemplate(framework),
|
|
5599
5644
|
`inertia/app/client.${entryExt}`
|
|
5600
5645
|
);
|
|
5601
5646
|
await writeIfNotExists(
|
|
5602
|
-
(0,
|
|
5647
|
+
(0, import_node_path19.join)(cwd, "inertia", "pages", `Home.${pageExt}`),
|
|
5603
5648
|
samplePageTemplate(framework),
|
|
5604
5649
|
`inertia/pages/Home.${pageExt}`
|
|
5605
5650
|
);
|
|
5606
5651
|
await writeIfNotExists(
|
|
5607
|
-
(0,
|
|
5652
|
+
(0, import_node_path19.join)(cwd, "src", "home.controller.ts"),
|
|
5608
5653
|
SAMPLE_CONTROLLER,
|
|
5609
5654
|
"src/home.controller.ts"
|
|
5610
5655
|
);
|
|
5611
5656
|
}
|
|
5612
5657
|
function patchServerAppModule(ctx) {
|
|
5613
5658
|
const { cwd, rootView } = ctx;
|
|
5614
|
-
const appModulePath = (0,
|
|
5659
|
+
const appModulePath = (0, import_node_path19.join)(cwd, "src", "app.module.ts");
|
|
5615
5660
|
const appModuleResult = patchAppModule(appModulePath, rootView);
|
|
5616
5661
|
if (appModuleResult === "patched") {
|
|
5617
5662
|
logPatched("src/app.module.ts", "added InertiaModule.forRoot");
|
|
@@ -5625,7 +5670,7 @@ function patchServerAppModule(ctx) {
|
|
|
5625
5670
|
}
|
|
5626
5671
|
}
|
|
5627
5672
|
function patchServerMainTs(ctx) {
|
|
5628
|
-
const mainTsPath = (0,
|
|
5673
|
+
const mainTsPath = (0, import_node_path19.join)(ctx.cwd, "src", "main.ts");
|
|
5629
5674
|
const mainTsResult = patchMainTs(mainTsPath);
|
|
5630
5675
|
if (mainTsResult === "patched") {
|
|
5631
5676
|
logPatched("src/main.ts", "added setupInertiaVite after NestFactory.create");
|
|
@@ -5660,7 +5705,7 @@ function patchBuildConfigs(ctx) {
|
|
|
5660
5705
|
}
|
|
5661
5706
|
async function patchGitignoreAndDist(ctx) {
|
|
5662
5707
|
const { cwd } = ctx;
|
|
5663
|
-
await patchGitignore((0,
|
|
5708
|
+
await patchGitignore((0, import_node_path19.join)(cwd, ".gitignore"));
|
|
5664
5709
|
const tsconfigDistResult = patchTsconfigExclude(cwd, "dist", "tsconfig.json");
|
|
5665
5710
|
if (tsconfigDistResult === "patched") {
|
|
5666
5711
|
logPatched("tsconfig.json", "excluded dist/ from server compilation");
|
|
@@ -5766,7 +5811,7 @@ ${green("\u2713")} Setup complete! Run: ${bold("nest start --watch")}
|
|
|
5766
5811
|
|
|
5767
5812
|
// src/cli/doctor.ts
|
|
5768
5813
|
function checkFileExists(cwd, file) {
|
|
5769
|
-
return (0, import_node_fs4.existsSync)((0,
|
|
5814
|
+
return (0, import_node_fs4.existsSync)((0, import_node_path20.join)(cwd, file));
|
|
5770
5815
|
}
|
|
5771
5816
|
function readJson(path) {
|
|
5772
5817
|
try {
|
|
@@ -5802,15 +5847,15 @@ function writeJsonField(filePath, dotPath, value) {
|
|
|
5802
5847
|
}
|
|
5803
5848
|
function getPackageVersion(cwd, pkg) {
|
|
5804
5849
|
try {
|
|
5805
|
-
const pkgJson = readJson((0,
|
|
5850
|
+
const pkgJson = readJson((0, import_node_path20.join)(cwd, "node_modules", pkg, "package.json"));
|
|
5806
5851
|
return pkgJson?.version ?? null;
|
|
5807
5852
|
} catch {
|
|
5808
5853
|
return null;
|
|
5809
5854
|
}
|
|
5810
5855
|
}
|
|
5811
5856
|
function detectPkgManager(cwd) {
|
|
5812
|
-
if ((0, import_node_fs4.existsSync)((0,
|
|
5813
|
-
if ((0, import_node_fs4.existsSync)((0,
|
|
5857
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path20.join)(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
5858
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path20.join)(cwd, "yarn.lock"))) return "yarn";
|
|
5814
5859
|
return "npm";
|
|
5815
5860
|
}
|
|
5816
5861
|
async function runDoctor(opts) {
|
|
@@ -5848,7 +5893,7 @@ async function runDoctor(opts) {
|
|
|
5848
5893
|
autoFix: () => runInit({ cwd })
|
|
5849
5894
|
});
|
|
5850
5895
|
if (foundShellDir) {
|
|
5851
|
-
const nestCliPath = (0,
|
|
5896
|
+
const nestCliPath = (0, import_node_path20.join)(cwd, "nest-cli.json");
|
|
5852
5897
|
const nestCli = readJson(nestCliPath);
|
|
5853
5898
|
const compiler = nestCli?.compilerOptions ?? {};
|
|
5854
5899
|
const assets = compiler.assets ?? [];
|
|
@@ -5887,7 +5932,7 @@ async function runDoctor(opts) {
|
|
|
5887
5932
|
fix: "Run: nestjs-codegen codegen",
|
|
5888
5933
|
autoFix: () => runCodegen({ cwd })
|
|
5889
5934
|
});
|
|
5890
|
-
const tsconfigPath = (0,
|
|
5935
|
+
const tsconfigPath = (0, import_node_path20.join)(cwd, "tsconfig.json");
|
|
5891
5936
|
const tsconfig = readJson(tsconfigPath);
|
|
5892
5937
|
const paths = tsconfig?.compilerOptions?.paths;
|
|
5893
5938
|
checks.push({
|
|
@@ -5898,7 +5943,7 @@ async function runDoctor(opts) {
|
|
|
5898
5943
|
});
|
|
5899
5944
|
const inertiaDir = foundShellDir ?? "inertia";
|
|
5900
5945
|
for (const tsconfigFile of ["tsconfig.json", "tsconfig.build.json"]) {
|
|
5901
|
-
const tsc = readJson((0,
|
|
5946
|
+
const tsc = readJson((0, import_node_path20.join)(cwd, tsconfigFile));
|
|
5902
5947
|
if (!tsc) continue;
|
|
5903
5948
|
const excl = tsc.exclude ?? [];
|
|
5904
5949
|
const excludesIt = excl.includes(inertiaDir);
|
|
@@ -5924,7 +5969,7 @@ async function runDoctor(opts) {
|
|
|
5924
5969
|
}
|
|
5925
5970
|
});
|
|
5926
5971
|
}
|
|
5927
|
-
const inertiaTsconfigPath = (0,
|
|
5972
|
+
const inertiaTsconfigPath = (0, import_node_path20.join)(cwd, "tsconfig.inertia.json");
|
|
5928
5973
|
const inertiaTsconfig = readJson(inertiaTsconfigPath);
|
|
5929
5974
|
checks.push({
|
|
5930
5975
|
name: "tsconfig.inertia.json exists",
|
|
@@ -5976,7 +6021,7 @@ async function runDoctor(opts) {
|
|
|
5976
6021
|
fix: 'Add "nestjs-inertia.d.ts" to include array (resolves InertiaRegistry augmentation)'
|
|
5977
6022
|
});
|
|
5978
6023
|
}
|
|
5979
|
-
const innerTsconfigPath = (0,
|
|
6024
|
+
const innerTsconfigPath = (0, import_node_path20.join)(cwd, "inertia", "tsconfig.json");
|
|
5980
6025
|
checks.push({
|
|
5981
6026
|
name: "inertia/tsconfig.json exists (VSCode picks up ~codegen alias)",
|
|
5982
6027
|
pass: (0, import_node_fs4.existsSync)(innerTsconfigPath),
|
|
@@ -5986,7 +6031,7 @@ async function runDoctor(opts) {
|
|
|
5986
6031
|
}
|
|
5987
6032
|
});
|
|
5988
6033
|
if (checkFileExists(cwd, "vite.config.ts")) {
|
|
5989
|
-
const viteContent = (0, import_node_fs4.readFileSync)((0,
|
|
6034
|
+
const viteContent = (0, import_node_fs4.readFileSync)((0, import_node_path20.join)(cwd, "vite.config.ts"), "utf8");
|
|
5990
6035
|
checks.push({
|
|
5991
6036
|
name: "vite.config.ts has resolve.alias",
|
|
5992
6037
|
pass: viteContent.includes("resolve") && viteContent.includes("alias"),
|
|
@@ -6051,7 +6096,7 @@ async function runDoctor(opts) {
|
|
|
6051
6096
|
});
|
|
6052
6097
|
}
|
|
6053
6098
|
if (checkFileExists(cwd, ".gitignore")) {
|
|
6054
|
-
const gitignorePath = (0,
|
|
6099
|
+
const gitignorePath = (0, import_node_path20.join)(cwd, ".gitignore");
|
|
6055
6100
|
const gitignore = (0, import_node_fs4.readFileSync)(gitignorePath, "utf8");
|
|
6056
6101
|
checks.push({
|
|
6057
6102
|
name: ".gitignore includes .nestjs-inertia/",
|
|
@@ -6060,7 +6105,7 @@ async function runDoctor(opts) {
|
|
|
6060
6105
|
autoFix: () => (0, import_node_fs4.appendFileSync)(gitignorePath, "\n.nestjs-inertia/\n")
|
|
6061
6106
|
});
|
|
6062
6107
|
}
|
|
6063
|
-
const pkgJsonPath = (0,
|
|
6108
|
+
const pkgJsonPath = (0, import_node_path20.join)(cwd, "package.json");
|
|
6064
6109
|
const pkgJson = readJson(pkgJsonPath);
|
|
6065
6110
|
const scripts = pkgJson?.scripts ?? {};
|
|
6066
6111
|
checks.push({
|