@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/cli/main.js
CHANGED
|
@@ -5647,14 +5647,26 @@ async function computeInputsHash(config, extraInputs = []) {
|
|
|
5647
5647
|
hash.update("\n");
|
|
5648
5648
|
}
|
|
5649
5649
|
for (const file of extra) {
|
|
5650
|
-
const contents = await readFile2(join13(cwd, file), "utf8").catch(() => null);
|
|
5651
5650
|
hash.update(`extra:${file}
|
|
5652
5651
|
`);
|
|
5653
|
-
hash.update(
|
|
5652
|
+
hash.update(await readTrackedInput(join13(cwd, file)));
|
|
5654
5653
|
hash.update("\n");
|
|
5655
5654
|
}
|
|
5656
5655
|
return hash.digest("hex");
|
|
5657
5656
|
}
|
|
5657
|
+
async function readTrackedInput(path) {
|
|
5658
|
+
try {
|
|
5659
|
+
return await readFile2(path, "utf8");
|
|
5660
|
+
} catch (err) {
|
|
5661
|
+
if (err.code !== "EISDIR") return "\0missing";
|
|
5662
|
+
}
|
|
5663
|
+
try {
|
|
5664
|
+
const entries = await readdir(path);
|
|
5665
|
+
return `\0dir:${entries.sort().join("\n")}`;
|
|
5666
|
+
} catch {
|
|
5667
|
+
return "\0missing";
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5658
5670
|
async function readManifest(outDir) {
|
|
5659
5671
|
try {
|
|
5660
5672
|
const raw = await readFile2(join13(outDir, MANIFEST_FILE), "utf8");
|
|
@@ -5810,7 +5822,7 @@ async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
|
5810
5822
|
|
|
5811
5823
|
// src/watch/watcher.ts
|
|
5812
5824
|
import { readFile as readFile4 } from "fs/promises";
|
|
5813
|
-
import { join as join16 } from "path";
|
|
5825
|
+
import { join as join16, resolve as resolve5 } from "path";
|
|
5814
5826
|
import chokidar from "chokidar";
|
|
5815
5827
|
|
|
5816
5828
|
// src/watch/lock-file.ts
|
|
@@ -5892,11 +5904,36 @@ async function watch(config, onChange, options = {}) {
|
|
|
5892
5904
|
}
|
|
5893
5905
|
return discovery;
|
|
5894
5906
|
}
|
|
5907
|
+
const trackedWatcher = chokidar.watch([], {
|
|
5908
|
+
ignoreInitial: true,
|
|
5909
|
+
persistent: true,
|
|
5910
|
+
awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 20 }
|
|
5911
|
+
});
|
|
5912
|
+
const trackedPaths = /* @__PURE__ */ new Set();
|
|
5913
|
+
async function syncTrackedInputs() {
|
|
5914
|
+
const manifest = await readManifest(config.codegen.outDir);
|
|
5915
|
+
const fresh = [];
|
|
5916
|
+
for (const path of manifest?.extraInputs ?? []) {
|
|
5917
|
+
const abs = resolve5(config.codegen.cwd, path);
|
|
5918
|
+
if (trackedPaths.has(abs)) continue;
|
|
5919
|
+
trackedPaths.add(abs);
|
|
5920
|
+
fresh.push(abs);
|
|
5921
|
+
}
|
|
5922
|
+
if (fresh.length > 0) trackedWatcher.add(fresh);
|
|
5923
|
+
}
|
|
5924
|
+
async function generateAndTrack(routes) {
|
|
5925
|
+
try {
|
|
5926
|
+
await generate(config, routes, entryPoint);
|
|
5927
|
+
} finally {
|
|
5928
|
+
await syncTrackedInputs().catch(() => {
|
|
5929
|
+
});
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5895
5932
|
async function runInitialPass() {
|
|
5896
5933
|
try {
|
|
5897
5934
|
const initialRoutes = (await getDiscovery()).discover();
|
|
5898
5935
|
lastRoutes = initialRoutes;
|
|
5899
|
-
await
|
|
5936
|
+
await generateAndTrack(initialRoutes);
|
|
5900
5937
|
} catch (err) {
|
|
5901
5938
|
if (err instanceof DriftGuardError) {
|
|
5902
5939
|
console.error(err.message);
|
|
@@ -5906,7 +5943,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5906
5943
|
`[nestjs-codegen] Initial route discovery failed, falling back to pages-only: ${err instanceof Error ? err.message : String(err)}`
|
|
5907
5944
|
);
|
|
5908
5945
|
try {
|
|
5909
|
-
await
|
|
5946
|
+
await generateAndTrack(lastRoutes);
|
|
5910
5947
|
} catch {
|
|
5911
5948
|
}
|
|
5912
5949
|
}
|
|
@@ -5939,7 +5976,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5939
5976
|
pagesDebounceTimer = setTimeout(async () => {
|
|
5940
5977
|
pagesDebounceTimer = void 0;
|
|
5941
5978
|
try {
|
|
5942
|
-
await
|
|
5979
|
+
await generateAndTrack(lastRoutes);
|
|
5943
5980
|
} catch (err) {
|
|
5944
5981
|
console.error(
|
|
5945
5982
|
"[nestjs-codegen] Pages generation failed:",
|
|
@@ -5971,7 +6008,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5971
6008
|
try {
|
|
5972
6009
|
const routes = await (await getDiscovery()).rediscover(changed);
|
|
5973
6010
|
lastRoutes = routes;
|
|
5974
|
-
await
|
|
6011
|
+
await generateAndTrack(routes);
|
|
5975
6012
|
} catch (err) {
|
|
5976
6013
|
console.error(
|
|
5977
6014
|
"[nestjs-codegen] Contracts generation failed:",
|
|
@@ -5992,6 +6029,9 @@ async function watch(config, onChange, options = {}) {
|
|
|
5992
6029
|
formsWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
5993
6030
|
formsWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
5994
6031
|
formsWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
6032
|
+
trackedWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
6033
|
+
trackedWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
6034
|
+
trackedWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
5995
6035
|
return {
|
|
5996
6036
|
close: async () => {
|
|
5997
6037
|
if (pagesDebounceTimer !== void 0) {
|
|
@@ -6005,13 +6045,14 @@ async function watch(config, onChange, options = {}) {
|
|
|
6005
6045
|
await pagesWatcher.close();
|
|
6006
6046
|
await contractsWatcher.close();
|
|
6007
6047
|
await formsWatcher.close();
|
|
6048
|
+
await trackedWatcher.close();
|
|
6008
6049
|
await lock.release();
|
|
6009
6050
|
}
|
|
6010
6051
|
};
|
|
6011
6052
|
}
|
|
6012
6053
|
|
|
6013
6054
|
// src/index.ts
|
|
6014
|
-
var VERSION = "0.
|
|
6055
|
+
var VERSION = "0.28.0";
|
|
6015
6056
|
|
|
6016
6057
|
// src/cli/codegen.ts
|
|
6017
6058
|
async function runCodegen(opts = {}) {
|
|
@@ -6019,9 +6060,9 @@ async function runCodegen(opts = {}) {
|
|
|
6019
6060
|
const config = await loadConfig(cwd);
|
|
6020
6061
|
if (opts.watch) {
|
|
6021
6062
|
const watcher = await watch(config, void 0, { entryPoint: "cli" });
|
|
6022
|
-
await new Promise((
|
|
6063
|
+
await new Promise((resolve6) => {
|
|
6023
6064
|
function onSignal() {
|
|
6024
|
-
watcher.close().then(
|
|
6065
|
+
watcher.close().then(resolve6).catch(resolve6);
|
|
6025
6066
|
}
|
|
6026
6067
|
process.once("SIGINT", onSignal);
|
|
6027
6068
|
process.once("SIGTERM", onSignal);
|
|
@@ -6151,16 +6192,16 @@ async function detectPackageManager(cwd) {
|
|
|
6151
6192
|
}
|
|
6152
6193
|
async function promptFramework() {
|
|
6153
6194
|
if (!process.stdin.isTTY) return "react";
|
|
6154
|
-
return new Promise((
|
|
6195
|
+
return new Promise((resolve6) => {
|
|
6155
6196
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
6156
6197
|
rl.question(
|
|
6157
6198
|
"[nestjs-codegen] Which frontend framework? (react/vue/svelte) [react]: ",
|
|
6158
6199
|
(answer) => {
|
|
6159
6200
|
rl.close();
|
|
6160
6201
|
const trimmed = answer.trim().toLowerCase();
|
|
6161
|
-
if (trimmed === "vue")
|
|
6162
|
-
else if (trimmed === "svelte")
|
|
6163
|
-
else
|
|
6202
|
+
if (trimmed === "vue") resolve6("vue");
|
|
6203
|
+
else if (trimmed === "svelte") resolve6("svelte");
|
|
6204
|
+
else resolve6("react");
|
|
6164
6205
|
}
|
|
6165
6206
|
);
|
|
6166
6207
|
});
|