@dudousxd/nestjs-codegen 0.27.1 → 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 +14 -0
- package/README.md +23 -0
- package/dist/cli/main.cjs +64 -17
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +65 -18
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +163 -11
- 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 +162 -12
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +58 -11
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +59 -12
- package/dist/nest/index.js.map +1 -1
- package/package.json +6 -2
package/dist/cli/main.js
CHANGED
|
@@ -685,12 +685,18 @@ function findTypeInFile(name, file) {
|
|
|
685
685
|
function resolveModuleSpecifier(moduleSpecifier, sourceFile, project) {
|
|
686
686
|
if (moduleSpecifier.startsWith(".")) {
|
|
687
687
|
const dir = dirname(sourceFile.getFilePath());
|
|
688
|
-
const
|
|
689
|
-
|
|
690
|
-
|
|
688
|
+
const ext = /\.(c|m)?(j|t)sx?$/.exec(moduleSpecifier)?.[0];
|
|
689
|
+
const base = ext ? moduleSpecifier.slice(0, -ext.length) : moduleSpecifier;
|
|
690
|
+
const flavour = ext?.startsWith(".c") ? "c" : ext?.startsWith(".m") ? "m" : "";
|
|
691
|
+
const candidates = [
|
|
692
|
+
resolve2(dir, `${base}.${flavour}ts`),
|
|
693
|
+
...flavour === "" ? [resolve2(dir, `${base}.tsx`)] : [],
|
|
691
694
|
resolve2(dir, `${moduleSpecifier}.ts`),
|
|
692
|
-
resolve2(dir, moduleSpecifier, "index.ts")
|
|
695
|
+
resolve2(dir, moduleSpecifier, "index.ts"),
|
|
696
|
+
resolve2(dir, `${base}.d.${flavour}ts`),
|
|
697
|
+
...ext === void 0 ? [resolve2(dir, moduleSpecifier, "index.d.ts")] : []
|
|
693
698
|
];
|
|
699
|
+
return [...new Set(candidates)];
|
|
694
700
|
}
|
|
695
701
|
const ctx = _ctxFor(project);
|
|
696
702
|
const baseUrl = ctx.pathsBase ?? ctx.projectRoot;
|
|
@@ -5641,14 +5647,26 @@ async function computeInputsHash(config, extraInputs = []) {
|
|
|
5641
5647
|
hash.update("\n");
|
|
5642
5648
|
}
|
|
5643
5649
|
for (const file of extra) {
|
|
5644
|
-
const contents = await readFile2(join13(cwd, file), "utf8").catch(() => null);
|
|
5645
5650
|
hash.update(`extra:${file}
|
|
5646
5651
|
`);
|
|
5647
|
-
hash.update(
|
|
5652
|
+
hash.update(await readTrackedInput(join13(cwd, file)));
|
|
5648
5653
|
hash.update("\n");
|
|
5649
5654
|
}
|
|
5650
5655
|
return hash.digest("hex");
|
|
5651
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
|
+
}
|
|
5652
5670
|
async function readManifest(outDir) {
|
|
5653
5671
|
try {
|
|
5654
5672
|
const raw = await readFile2(join13(outDir, MANIFEST_FILE), "utf8");
|
|
@@ -5804,7 +5822,7 @@ async function generate(config, inputRoutes = [], entryPoint = "cli") {
|
|
|
5804
5822
|
|
|
5805
5823
|
// src/watch/watcher.ts
|
|
5806
5824
|
import { readFile as readFile4 } from "fs/promises";
|
|
5807
|
-
import { join as join16 } from "path";
|
|
5825
|
+
import { join as join16, resolve as resolve5 } from "path";
|
|
5808
5826
|
import chokidar from "chokidar";
|
|
5809
5827
|
|
|
5810
5828
|
// src/watch/lock-file.ts
|
|
@@ -5886,11 +5904,36 @@ async function watch(config, onChange, options = {}) {
|
|
|
5886
5904
|
}
|
|
5887
5905
|
return discovery;
|
|
5888
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
|
+
}
|
|
5889
5932
|
async function runInitialPass() {
|
|
5890
5933
|
try {
|
|
5891
5934
|
const initialRoutes = (await getDiscovery()).discover();
|
|
5892
5935
|
lastRoutes = initialRoutes;
|
|
5893
|
-
await
|
|
5936
|
+
await generateAndTrack(initialRoutes);
|
|
5894
5937
|
} catch (err) {
|
|
5895
5938
|
if (err instanceof DriftGuardError) {
|
|
5896
5939
|
console.error(err.message);
|
|
@@ -5900,7 +5943,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5900
5943
|
`[nestjs-codegen] Initial route discovery failed, falling back to pages-only: ${err instanceof Error ? err.message : String(err)}`
|
|
5901
5944
|
);
|
|
5902
5945
|
try {
|
|
5903
|
-
await
|
|
5946
|
+
await generateAndTrack(lastRoutes);
|
|
5904
5947
|
} catch {
|
|
5905
5948
|
}
|
|
5906
5949
|
}
|
|
@@ -5933,7 +5976,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5933
5976
|
pagesDebounceTimer = setTimeout(async () => {
|
|
5934
5977
|
pagesDebounceTimer = void 0;
|
|
5935
5978
|
try {
|
|
5936
|
-
await
|
|
5979
|
+
await generateAndTrack(lastRoutes);
|
|
5937
5980
|
} catch (err) {
|
|
5938
5981
|
console.error(
|
|
5939
5982
|
"[nestjs-codegen] Pages generation failed:",
|
|
@@ -5965,7 +6008,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5965
6008
|
try {
|
|
5966
6009
|
const routes = await (await getDiscovery()).rediscover(changed);
|
|
5967
6010
|
lastRoutes = routes;
|
|
5968
|
-
await
|
|
6011
|
+
await generateAndTrack(routes);
|
|
5969
6012
|
} catch (err) {
|
|
5970
6013
|
console.error(
|
|
5971
6014
|
"[nestjs-codegen] Contracts generation failed:",
|
|
@@ -5986,6 +6029,9 @@ async function watch(config, onChange, options = {}) {
|
|
|
5986
6029
|
formsWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
5987
6030
|
formsWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
5988
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));
|
|
5989
6035
|
return {
|
|
5990
6036
|
close: async () => {
|
|
5991
6037
|
if (pagesDebounceTimer !== void 0) {
|
|
@@ -5999,13 +6045,14 @@ async function watch(config, onChange, options = {}) {
|
|
|
5999
6045
|
await pagesWatcher.close();
|
|
6000
6046
|
await contractsWatcher.close();
|
|
6001
6047
|
await formsWatcher.close();
|
|
6048
|
+
await trackedWatcher.close();
|
|
6002
6049
|
await lock.release();
|
|
6003
6050
|
}
|
|
6004
6051
|
};
|
|
6005
6052
|
}
|
|
6006
6053
|
|
|
6007
6054
|
// src/index.ts
|
|
6008
|
-
var VERSION = "0.
|
|
6055
|
+
var VERSION = "0.28.0";
|
|
6009
6056
|
|
|
6010
6057
|
// src/cli/codegen.ts
|
|
6011
6058
|
async function runCodegen(opts = {}) {
|
|
@@ -6013,9 +6060,9 @@ async function runCodegen(opts = {}) {
|
|
|
6013
6060
|
const config = await loadConfig(cwd);
|
|
6014
6061
|
if (opts.watch) {
|
|
6015
6062
|
const watcher = await watch(config, void 0, { entryPoint: "cli" });
|
|
6016
|
-
await new Promise((
|
|
6063
|
+
await new Promise((resolve6) => {
|
|
6017
6064
|
function onSignal() {
|
|
6018
|
-
watcher.close().then(
|
|
6065
|
+
watcher.close().then(resolve6).catch(resolve6);
|
|
6019
6066
|
}
|
|
6020
6067
|
process.once("SIGINT", onSignal);
|
|
6021
6068
|
process.once("SIGTERM", onSignal);
|
|
@@ -6145,16 +6192,16 @@ async function detectPackageManager(cwd) {
|
|
|
6145
6192
|
}
|
|
6146
6193
|
async function promptFramework() {
|
|
6147
6194
|
if (!process.stdin.isTTY) return "react";
|
|
6148
|
-
return new Promise((
|
|
6195
|
+
return new Promise((resolve6) => {
|
|
6149
6196
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
6150
6197
|
rl.question(
|
|
6151
6198
|
"[nestjs-codegen] Which frontend framework? (react/vue/svelte) [react]: ",
|
|
6152
6199
|
(answer) => {
|
|
6153
6200
|
rl.close();
|
|
6154
6201
|
const trimmed = answer.trim().toLowerCase();
|
|
6155
|
-
if (trimmed === "vue")
|
|
6156
|
-
else if (trimmed === "svelte")
|
|
6157
|
-
else
|
|
6202
|
+
if (trimmed === "vue") resolve6("vue");
|
|
6203
|
+
else if (trimmed === "svelte") resolve6("svelte");
|
|
6204
|
+
else resolve6("react");
|
|
6158
6205
|
}
|
|
6159
6206
|
);
|
|
6160
6207
|
});
|