@dudousxd/nestjs-codegen 0.14.1 → 0.14.2
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 +6 -0
- package/dist/cli/main.cjs +41 -8
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +41 -8
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +41 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +41 -8
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +41 -8
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +41 -8
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2220,19 +2220,41 @@ function isManifestShape(value) {
|
|
|
2220
2220
|
if (typeof candidate.hash !== "string") return false;
|
|
2221
2221
|
if (candidate.entryPoint !== void 0 && !isEntryPoint(candidate.entryPoint)) return false;
|
|
2222
2222
|
if (candidate.configHash !== void 0 && typeof candidate.configHash !== "string") return false;
|
|
2223
|
+
if (candidate.configKeyHashes !== void 0 && !isStringRecord(candidate.configKeyHashes)) {
|
|
2224
|
+
return false;
|
|
2225
|
+
}
|
|
2223
2226
|
if (!Array.isArray(candidate.files)) return false;
|
|
2224
2227
|
return candidate.files.every((entry) => typeof entry === "string");
|
|
2225
2228
|
}
|
|
2229
|
+
function isStringRecord(value) {
|
|
2230
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
2231
|
+
return Object.values(value).every((entry) => typeof entry === "string");
|
|
2232
|
+
}
|
|
2226
2233
|
function serializeConfig(config) {
|
|
2234
|
+
return serializeConfigValue(config, `unserializable:${config.codegen.outDir}`);
|
|
2235
|
+
}
|
|
2236
|
+
function serializeConfigValue(value, unserializableMarker) {
|
|
2227
2237
|
try {
|
|
2228
|
-
return JSON.stringify(
|
|
2229
|
-
if (typeof
|
|
2230
|
-
return
|
|
2238
|
+
return JSON.stringify(value, (_key, entry) => {
|
|
2239
|
+
if (typeof entry === "function") return `[fn:${entry.name}]`;
|
|
2240
|
+
return entry;
|
|
2231
2241
|
});
|
|
2232
2242
|
} catch {
|
|
2233
|
-
return
|
|
2243
|
+
return unserializableMarker;
|
|
2234
2244
|
}
|
|
2235
2245
|
}
|
|
2246
|
+
function computeConfigKeyHashes(config) {
|
|
2247
|
+
const hashes = {};
|
|
2248
|
+
for (const [key, value] of Object.entries(config)) {
|
|
2249
|
+
if (value === void 0) continue;
|
|
2250
|
+
hashes[key] = (0, import_node_crypto.createHash)("sha256").update(serializeConfigValue(value, `unserializable:${key}`)).digest("hex");
|
|
2251
|
+
}
|
|
2252
|
+
return hashes;
|
|
2253
|
+
}
|
|
2254
|
+
function diffConfigKeyHashes(previous, current) {
|
|
2255
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(current)]);
|
|
2256
|
+
return [...keys].filter((key) => previous[key] !== current[key]).sort();
|
|
2257
|
+
}
|
|
2236
2258
|
async function discoverInputFiles(config) {
|
|
2237
2259
|
const globs = [config.contracts.glob, config.forms.watch];
|
|
2238
2260
|
if (config.pages) globs.push(config.pages.glob);
|
|
@@ -2267,6 +2289,7 @@ async function readManifest(outDir) {
|
|
|
2267
2289
|
hash: parsed.hash,
|
|
2268
2290
|
...parsed.entryPoint ? { entryPoint: parsed.entryPoint } : {},
|
|
2269
2291
|
...parsed.configHash ? { configHash: parsed.configHash } : {},
|
|
2292
|
+
...parsed.configKeyHashes ? { configKeyHashes: parsed.configKeyHashes } : {},
|
|
2270
2293
|
files: parsed.files
|
|
2271
2294
|
};
|
|
2272
2295
|
} catch {
|
|
@@ -2320,8 +2343,9 @@ function debugWarn(message) {
|
|
|
2320
2343
|
}
|
|
2321
2344
|
|
|
2322
2345
|
// src/generate.ts
|
|
2323
|
-
function driftGuardMessage(outDir, previousEntryPoint, currentEntryPoint) {
|
|
2324
|
-
|
|
2346
|
+
function driftGuardMessage(outDir, previousEntryPoint, currentEntryPoint, differingKeys) {
|
|
2347
|
+
const differ = differingKeys.length > 0 ? `their resolved configs differ at: ${differingKeys.map((key) => `\`${key}\``).join(", ")}` : "their resolved configs differ (re-run after this generate records per-key hashes to see which keys)";
|
|
2348
|
+
return `[nestjs-codegen] Config drift detected in "${outDir}": the last generate ran from the "${previousEntryPoint}" entry point, this run is from the "${currentEntryPoint}" entry point, and ${differ}. Both entry points must read the SAME config \u2014 export a shared config object (e.g. codegen.config.ts) and import it from BOTH nestjs-codegen.config.ts (CLI) and NestjsCodegenModule.forRoot() (Nest module), or set \`driftGuard: false\` on either config to opt out of this check.`;
|
|
2325
2349
|
}
|
|
2326
2350
|
async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
2327
2351
|
setCodegenDebug(config.debug);
|
|
@@ -2332,9 +2356,17 @@ async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
|
2332
2356
|
return;
|
|
2333
2357
|
}
|
|
2334
2358
|
const configHash = computeConfigHash(config);
|
|
2359
|
+
const configKeyHashes = computeConfigKeyHashes(config);
|
|
2335
2360
|
if (config.driftGuard && manifest?.entryPoint && manifest.entryPoint !== entryPoint && manifest.configHash && manifest.configHash !== configHash) {
|
|
2336
2361
|
throw new DriftGuardError(
|
|
2337
|
-
driftGuardMessage(
|
|
2362
|
+
driftGuardMessage(
|
|
2363
|
+
config.codegen.outDir,
|
|
2364
|
+
manifest.entryPoint,
|
|
2365
|
+
entryPoint,
|
|
2366
|
+
// A pre-key-hash manifest can't tell us WHICH keys differ — pass none
|
|
2367
|
+
// rather than diffing against {} (which would name every key).
|
|
2368
|
+
manifest.configKeyHashes ? diffConfigKeyHashes(manifest.configKeyHashes, configKeyHashes) : []
|
|
2369
|
+
)
|
|
2338
2370
|
);
|
|
2339
2371
|
}
|
|
2340
2372
|
const extensions = config.extensions ?? [];
|
|
@@ -2404,6 +2436,7 @@ async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
|
2404
2436
|
hash: inputsHash,
|
|
2405
2437
|
entryPoint,
|
|
2406
2438
|
configHash,
|
|
2439
|
+
configKeyHashes,
|
|
2407
2440
|
files: outputFiles
|
|
2408
2441
|
});
|
|
2409
2442
|
}
|
|
@@ -4919,7 +4952,7 @@ function createChainModuleRenderer(opts) {
|
|
|
4919
4952
|
}
|
|
4920
4953
|
|
|
4921
4954
|
// src/index.ts
|
|
4922
|
-
var VERSION = "0.14.
|
|
4955
|
+
var VERSION = "0.14.2";
|
|
4923
4956
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4924
4957
|
0 && (module.exports = {
|
|
4925
4958
|
CodegenError,
|