@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/nest/index.cjs
CHANGED
|
@@ -279,12 +279,18 @@ function findTypeInFile(name, file) {
|
|
|
279
279
|
function resolveModuleSpecifier(moduleSpecifier, sourceFile, project) {
|
|
280
280
|
if (moduleSpecifier.startsWith(".")) {
|
|
281
281
|
const dir = (0, import_node_path2.dirname)(sourceFile.getFilePath());
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
282
|
+
const ext = /\.(c|m)?(j|t)sx?$/.exec(moduleSpecifier)?.[0];
|
|
283
|
+
const base = ext ? moduleSpecifier.slice(0, -ext.length) : moduleSpecifier;
|
|
284
|
+
const flavour = ext?.startsWith(".c") ? "c" : ext?.startsWith(".m") ? "m" : "";
|
|
285
|
+
const candidates = [
|
|
286
|
+
(0, import_node_path2.resolve)(dir, `${base}.${flavour}ts`),
|
|
287
|
+
...flavour === "" ? [(0, import_node_path2.resolve)(dir, `${base}.tsx`)] : [],
|
|
285
288
|
(0, import_node_path2.resolve)(dir, `${moduleSpecifier}.ts`),
|
|
286
|
-
(0, import_node_path2.resolve)(dir, moduleSpecifier, "index.ts")
|
|
289
|
+
(0, import_node_path2.resolve)(dir, moduleSpecifier, "index.ts"),
|
|
290
|
+
(0, import_node_path2.resolve)(dir, `${base}.d.${flavour}ts`),
|
|
291
|
+
...ext === void 0 ? [(0, import_node_path2.resolve)(dir, moduleSpecifier, "index.d.ts")] : []
|
|
287
292
|
];
|
|
293
|
+
return [...new Set(candidates)];
|
|
288
294
|
}
|
|
289
295
|
const ctx = _ctxFor(project);
|
|
290
296
|
const baseUrl = ctx.pathsBase ?? ctx.projectRoot;
|
|
@@ -5687,11 +5693,36 @@ async function watch(config, onChange, options = {}) {
|
|
|
5687
5693
|
}
|
|
5688
5694
|
return discovery;
|
|
5689
5695
|
}
|
|
5696
|
+
const trackedWatcher = import_chokidar.default.watch([], {
|
|
5697
|
+
ignoreInitial: true,
|
|
5698
|
+
persistent: true,
|
|
5699
|
+
awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 20 }
|
|
5700
|
+
});
|
|
5701
|
+
const trackedPaths = /* @__PURE__ */ new Set();
|
|
5702
|
+
async function syncTrackedInputs() {
|
|
5703
|
+
const manifest = await readManifest(config.codegen.outDir);
|
|
5704
|
+
const fresh = [];
|
|
5705
|
+
for (const path of manifest?.extraInputs ?? []) {
|
|
5706
|
+
const abs = (0, import_node_path17.resolve)(config.codegen.cwd, path);
|
|
5707
|
+
if (trackedPaths.has(abs)) continue;
|
|
5708
|
+
trackedPaths.add(abs);
|
|
5709
|
+
fresh.push(abs);
|
|
5710
|
+
}
|
|
5711
|
+
if (fresh.length > 0) trackedWatcher.add(fresh);
|
|
5712
|
+
}
|
|
5713
|
+
async function generateAndTrack(routes) {
|
|
5714
|
+
try {
|
|
5715
|
+
await generate(config, routes, entryPoint);
|
|
5716
|
+
} finally {
|
|
5717
|
+
await syncTrackedInputs().catch(() => {
|
|
5718
|
+
});
|
|
5719
|
+
}
|
|
5720
|
+
}
|
|
5690
5721
|
async function runInitialPass() {
|
|
5691
5722
|
try {
|
|
5692
5723
|
const initialRoutes = (await getDiscovery()).discover();
|
|
5693
5724
|
lastRoutes = initialRoutes;
|
|
5694
|
-
await
|
|
5725
|
+
await generateAndTrack(initialRoutes);
|
|
5695
5726
|
} catch (err) {
|
|
5696
5727
|
if (err instanceof DriftGuardError) {
|
|
5697
5728
|
console.error(err.message);
|
|
@@ -5701,7 +5732,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5701
5732
|
`[nestjs-codegen] Initial route discovery failed, falling back to pages-only: ${err instanceof Error ? err.message : String(err)}`
|
|
5702
5733
|
);
|
|
5703
5734
|
try {
|
|
5704
|
-
await
|
|
5735
|
+
await generateAndTrack(lastRoutes);
|
|
5705
5736
|
} catch {
|
|
5706
5737
|
}
|
|
5707
5738
|
}
|
|
@@ -5734,7 +5765,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5734
5765
|
pagesDebounceTimer = setTimeout(async () => {
|
|
5735
5766
|
pagesDebounceTimer = void 0;
|
|
5736
5767
|
try {
|
|
5737
|
-
await
|
|
5768
|
+
await generateAndTrack(lastRoutes);
|
|
5738
5769
|
} catch (err) {
|
|
5739
5770
|
console.error(
|
|
5740
5771
|
"[nestjs-codegen] Pages generation failed:",
|
|
@@ -5766,7 +5797,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5766
5797
|
try {
|
|
5767
5798
|
const routes = await (await getDiscovery()).rediscover(changed);
|
|
5768
5799
|
lastRoutes = routes;
|
|
5769
|
-
await
|
|
5800
|
+
await generateAndTrack(routes);
|
|
5770
5801
|
} catch (err) {
|
|
5771
5802
|
console.error(
|
|
5772
5803
|
"[nestjs-codegen] Contracts generation failed:",
|
|
@@ -5787,6 +5818,9 @@ async function watch(config, onChange, options = {}) {
|
|
|
5787
5818
|
formsWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
5788
5819
|
formsWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
5789
5820
|
formsWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
5821
|
+
trackedWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
5822
|
+
trackedWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
5823
|
+
trackedWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
5790
5824
|
return {
|
|
5791
5825
|
close: async () => {
|
|
5792
5826
|
if (pagesDebounceTimer !== void 0) {
|
|
@@ -5800,13 +5834,14 @@ async function watch(config, onChange, options = {}) {
|
|
|
5800
5834
|
await pagesWatcher.close();
|
|
5801
5835
|
await contractsWatcher.close();
|
|
5802
5836
|
await formsWatcher.close();
|
|
5837
|
+
await trackedWatcher.close();
|
|
5803
5838
|
await lock.release();
|
|
5804
5839
|
}
|
|
5805
5840
|
};
|
|
5806
5841
|
}
|
|
5807
5842
|
|
|
5808
5843
|
// src/index.ts
|
|
5809
|
-
var VERSION = "0.
|
|
5844
|
+
var VERSION = "0.28.0";
|
|
5810
5845
|
|
|
5811
5846
|
// src/generate-manifest.ts
|
|
5812
5847
|
var MANIFEST_FILE = ".codegen-manifest.json";
|
|
@@ -5898,14 +5933,26 @@ async function computeInputsHash(config, extraInputs = []) {
|
|
|
5898
5933
|
hash.update("\n");
|
|
5899
5934
|
}
|
|
5900
5935
|
for (const file of extra) {
|
|
5901
|
-
const contents = await (0, import_promises15.readFile)((0, import_node_path18.join)(cwd, file), "utf8").catch(() => null);
|
|
5902
5936
|
hash.update(`extra:${file}
|
|
5903
5937
|
`);
|
|
5904
|
-
hash.update(
|
|
5938
|
+
hash.update(await readTrackedInput((0, import_node_path18.join)(cwd, file)));
|
|
5905
5939
|
hash.update("\n");
|
|
5906
5940
|
}
|
|
5907
5941
|
return hash.digest("hex");
|
|
5908
5942
|
}
|
|
5943
|
+
async function readTrackedInput(path) {
|
|
5944
|
+
try {
|
|
5945
|
+
return await (0, import_promises15.readFile)(path, "utf8");
|
|
5946
|
+
} catch (err) {
|
|
5947
|
+
if (err.code !== "EISDIR") return "\0missing";
|
|
5948
|
+
}
|
|
5949
|
+
try {
|
|
5950
|
+
const entries = await (0, import_promises15.readdir)(path);
|
|
5951
|
+
return `\0dir:${entries.sort().join("\n")}`;
|
|
5952
|
+
} catch {
|
|
5953
|
+
return "\0missing";
|
|
5954
|
+
}
|
|
5955
|
+
}
|
|
5909
5956
|
async function readManifest(outDir) {
|
|
5910
5957
|
try {
|
|
5911
5958
|
const raw = await (0, import_promises15.readFile)((0, import_node_path18.join)(outDir, MANIFEST_FILE), "utf8");
|