@dudousxd/nestjs-codegen 0.27.2 → 0.28.0
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 +8 -0
- package/README.md +23 -0
- package/dist/cli/main.cjs +54 -13
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +55 -14
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +153 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -3
- package/dist/index.d.ts +56 -3
- package/dist/index.js +152 -8
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +48 -7
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +49 -8
- package/dist/nest/index.js.map +1 -1
- package/package.json +6 -2
package/dist/nest/index.js
CHANGED
|
@@ -5590,7 +5590,7 @@ async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
|
5590
5590
|
|
|
5591
5591
|
// src/watch/watcher.ts
|
|
5592
5592
|
import { readFile as readFile3 } from "fs/promises";
|
|
5593
|
-
import { join as join15 } from "path";
|
|
5593
|
+
import { join as join15, resolve as resolve5 } from "path";
|
|
5594
5594
|
import chokidar from "chokidar";
|
|
5595
5595
|
|
|
5596
5596
|
// src/watch/lock-file.ts
|
|
@@ -5672,11 +5672,36 @@ async function watch(config, onChange, options = {}) {
|
|
|
5672
5672
|
}
|
|
5673
5673
|
return discovery;
|
|
5674
5674
|
}
|
|
5675
|
+
const trackedWatcher = chokidar.watch([], {
|
|
5676
|
+
ignoreInitial: true,
|
|
5677
|
+
persistent: true,
|
|
5678
|
+
awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 20 }
|
|
5679
|
+
});
|
|
5680
|
+
const trackedPaths = /* @__PURE__ */ new Set();
|
|
5681
|
+
async function syncTrackedInputs() {
|
|
5682
|
+
const manifest = await readManifest(config.codegen.outDir);
|
|
5683
|
+
const fresh = [];
|
|
5684
|
+
for (const path of manifest?.extraInputs ?? []) {
|
|
5685
|
+
const abs = resolve5(config.codegen.cwd, path);
|
|
5686
|
+
if (trackedPaths.has(abs)) continue;
|
|
5687
|
+
trackedPaths.add(abs);
|
|
5688
|
+
fresh.push(abs);
|
|
5689
|
+
}
|
|
5690
|
+
if (fresh.length > 0) trackedWatcher.add(fresh);
|
|
5691
|
+
}
|
|
5692
|
+
async function generateAndTrack(routes) {
|
|
5693
|
+
try {
|
|
5694
|
+
await generate(config, routes, entryPoint);
|
|
5695
|
+
} finally {
|
|
5696
|
+
await syncTrackedInputs().catch(() => {
|
|
5697
|
+
});
|
|
5698
|
+
}
|
|
5699
|
+
}
|
|
5675
5700
|
async function runInitialPass() {
|
|
5676
5701
|
try {
|
|
5677
5702
|
const initialRoutes = (await getDiscovery()).discover();
|
|
5678
5703
|
lastRoutes = initialRoutes;
|
|
5679
|
-
await
|
|
5704
|
+
await generateAndTrack(initialRoutes);
|
|
5680
5705
|
} catch (err) {
|
|
5681
5706
|
if (err instanceof DriftGuardError) {
|
|
5682
5707
|
console.error(err.message);
|
|
@@ -5686,7 +5711,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5686
5711
|
`[nestjs-codegen] Initial route discovery failed, falling back to pages-only: ${err instanceof Error ? err.message : String(err)}`
|
|
5687
5712
|
);
|
|
5688
5713
|
try {
|
|
5689
|
-
await
|
|
5714
|
+
await generateAndTrack(lastRoutes);
|
|
5690
5715
|
} catch {
|
|
5691
5716
|
}
|
|
5692
5717
|
}
|
|
@@ -5719,7 +5744,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5719
5744
|
pagesDebounceTimer = setTimeout(async () => {
|
|
5720
5745
|
pagesDebounceTimer = void 0;
|
|
5721
5746
|
try {
|
|
5722
|
-
await
|
|
5747
|
+
await generateAndTrack(lastRoutes);
|
|
5723
5748
|
} catch (err) {
|
|
5724
5749
|
console.error(
|
|
5725
5750
|
"[nestjs-codegen] Pages generation failed:",
|
|
@@ -5751,7 +5776,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5751
5776
|
try {
|
|
5752
5777
|
const routes = await (await getDiscovery()).rediscover(changed);
|
|
5753
5778
|
lastRoutes = routes;
|
|
5754
|
-
await
|
|
5779
|
+
await generateAndTrack(routes);
|
|
5755
5780
|
} catch (err) {
|
|
5756
5781
|
console.error(
|
|
5757
5782
|
"[nestjs-codegen] Contracts generation failed:",
|
|
@@ -5772,6 +5797,9 @@ async function watch(config, onChange, options = {}) {
|
|
|
5772
5797
|
formsWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
5773
5798
|
formsWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
5774
5799
|
formsWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
5800
|
+
trackedWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
5801
|
+
trackedWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
5802
|
+
trackedWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
5775
5803
|
return {
|
|
5776
5804
|
close: async () => {
|
|
5777
5805
|
if (pagesDebounceTimer !== void 0) {
|
|
@@ -5785,13 +5813,14 @@ async function watch(config, onChange, options = {}) {
|
|
|
5785
5813
|
await pagesWatcher.close();
|
|
5786
5814
|
await contractsWatcher.close();
|
|
5787
5815
|
await formsWatcher.close();
|
|
5816
|
+
await trackedWatcher.close();
|
|
5788
5817
|
await lock.release();
|
|
5789
5818
|
}
|
|
5790
5819
|
};
|
|
5791
5820
|
}
|
|
5792
5821
|
|
|
5793
5822
|
// src/index.ts
|
|
5794
|
-
var VERSION = "0.
|
|
5823
|
+
var VERSION = "0.28.0";
|
|
5795
5824
|
|
|
5796
5825
|
// src/generate-manifest.ts
|
|
5797
5826
|
var MANIFEST_FILE = ".codegen-manifest.json";
|
|
@@ -5883,14 +5912,26 @@ async function computeInputsHash(config, extraInputs = []) {
|
|
|
5883
5912
|
hash.update("\n");
|
|
5884
5913
|
}
|
|
5885
5914
|
for (const file of extra) {
|
|
5886
|
-
const contents = await readFile4(join16(cwd, file), "utf8").catch(() => null);
|
|
5887
5915
|
hash.update(`extra:${file}
|
|
5888
5916
|
`);
|
|
5889
|
-
hash.update(
|
|
5917
|
+
hash.update(await readTrackedInput(join16(cwd, file)));
|
|
5890
5918
|
hash.update("\n");
|
|
5891
5919
|
}
|
|
5892
5920
|
return hash.digest("hex");
|
|
5893
5921
|
}
|
|
5922
|
+
async function readTrackedInput(path) {
|
|
5923
|
+
try {
|
|
5924
|
+
return await readFile4(path, "utf8");
|
|
5925
|
+
} catch (err) {
|
|
5926
|
+
if (err.code !== "EISDIR") return "\0missing";
|
|
5927
|
+
}
|
|
5928
|
+
try {
|
|
5929
|
+
const entries = await readdir(path);
|
|
5930
|
+
return `\0dir:${entries.sort().join("\n")}`;
|
|
5931
|
+
} catch {
|
|
5932
|
+
return "\0missing";
|
|
5933
|
+
}
|
|
5934
|
+
}
|
|
5894
5935
|
async function readManifest(outDir) {
|
|
5895
5936
|
try {
|
|
5896
5937
|
const raw = await readFile4(join16(outDir, MANIFEST_FILE), "utf8");
|