@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/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
CodegenError: () => CodegenError,
|
|
34
34
|
ConfigError: () => ConfigError,
|
|
35
|
+
DEFAULT_SANDBOX_KIT_OUTPUT: () => DEFAULT_SANDBOX_KIT_OUTPUT,
|
|
35
36
|
DriftGuardError: () => DriftGuardError,
|
|
36
37
|
VERSION: () => VERSION,
|
|
37
38
|
acquireLock: () => acquireLock,
|
|
@@ -47,6 +48,7 @@ __export(src_exports, {
|
|
|
47
48
|
emitRoutes: () => emitRoutes,
|
|
48
49
|
extractSchemaFromDto: () => extractSchemaFromDto,
|
|
49
50
|
generate: () => generate,
|
|
51
|
+
genuiSandboxKit: () => genuiSandboxKit,
|
|
50
52
|
loadConfig: () => loadConfig,
|
|
51
53
|
renderTsType: () => renderTsType,
|
|
52
54
|
resolveAdapter: () => resolveAdapter,
|
|
@@ -740,12 +742,18 @@ function findTypeInFile(name, file) {
|
|
|
740
742
|
function resolveModuleSpecifier(moduleSpecifier, sourceFile, project) {
|
|
741
743
|
if (moduleSpecifier.startsWith(".")) {
|
|
742
744
|
const dir = (0, import_node_path4.dirname)(sourceFile.getFilePath());
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
745
|
+
const ext = /\.(c|m)?(j|t)sx?$/.exec(moduleSpecifier)?.[0];
|
|
746
|
+
const base = ext ? moduleSpecifier.slice(0, -ext.length) : moduleSpecifier;
|
|
747
|
+
const flavour = ext?.startsWith(".c") ? "c" : ext?.startsWith(".m") ? "m" : "";
|
|
748
|
+
const candidates = [
|
|
749
|
+
(0, import_node_path4.resolve)(dir, `${base}.${flavour}ts`),
|
|
750
|
+
...flavour === "" ? [(0, import_node_path4.resolve)(dir, `${base}.tsx`)] : [],
|
|
746
751
|
(0, import_node_path4.resolve)(dir, `${moduleSpecifier}.ts`),
|
|
747
|
-
(0, import_node_path4.resolve)(dir, moduleSpecifier, "index.ts")
|
|
752
|
+
(0, import_node_path4.resolve)(dir, moduleSpecifier, "index.ts"),
|
|
753
|
+
(0, import_node_path4.resolve)(dir, `${base}.d.${flavour}ts`),
|
|
754
|
+
...ext === void 0 ? [(0, import_node_path4.resolve)(dir, moduleSpecifier, "index.d.ts")] : []
|
|
748
755
|
];
|
|
756
|
+
return [...new Set(candidates)];
|
|
749
757
|
}
|
|
750
758
|
const ctx = _ctxFor(project);
|
|
751
759
|
const baseUrl = ctx.pathsBase ?? ctx.projectRoot;
|
|
@@ -5692,14 +5700,26 @@ async function computeInputsHash(config, extraInputs = []) {
|
|
|
5692
5700
|
hash.update("\n");
|
|
5693
5701
|
}
|
|
5694
5702
|
for (const file of extra) {
|
|
5695
|
-
const contents = await (0, import_promises11.readFile)((0, import_node_path15.join)(cwd, file), "utf8").catch(() => null);
|
|
5696
5703
|
hash.update(`extra:${file}
|
|
5697
5704
|
`);
|
|
5698
|
-
hash.update(
|
|
5705
|
+
hash.update(await readTrackedInput((0, import_node_path15.join)(cwd, file)));
|
|
5699
5706
|
hash.update("\n");
|
|
5700
5707
|
}
|
|
5701
5708
|
return hash.digest("hex");
|
|
5702
5709
|
}
|
|
5710
|
+
async function readTrackedInput(path) {
|
|
5711
|
+
try {
|
|
5712
|
+
return await (0, import_promises11.readFile)(path, "utf8");
|
|
5713
|
+
} catch (err) {
|
|
5714
|
+
if (err.code !== "EISDIR") return "\0missing";
|
|
5715
|
+
}
|
|
5716
|
+
try {
|
|
5717
|
+
const entries = await (0, import_promises11.readdir)(path);
|
|
5718
|
+
return `\0dir:${entries.sort().join("\n")}`;
|
|
5719
|
+
} catch {
|
|
5720
|
+
return "\0missing";
|
|
5721
|
+
}
|
|
5722
|
+
}
|
|
5703
5723
|
async function readManifest(outDir) {
|
|
5704
5724
|
try {
|
|
5705
5725
|
const raw = await (0, import_promises11.readFile)((0, import_node_path15.join)(outDir, MANIFEST_FILE), "utf8");
|
|
@@ -5937,11 +5957,36 @@ async function watch(config, onChange, options = {}) {
|
|
|
5937
5957
|
}
|
|
5938
5958
|
return discovery;
|
|
5939
5959
|
}
|
|
5960
|
+
const trackedWatcher = import_chokidar.default.watch([], {
|
|
5961
|
+
ignoreInitial: true,
|
|
5962
|
+
persistent: true,
|
|
5963
|
+
awaitWriteFinish: { stabilityThreshold: 80, pollInterval: 20 }
|
|
5964
|
+
});
|
|
5965
|
+
const trackedPaths = /* @__PURE__ */ new Set();
|
|
5966
|
+
async function syncTrackedInputs() {
|
|
5967
|
+
const manifest = await readManifest(config.codegen.outDir);
|
|
5968
|
+
const fresh = [];
|
|
5969
|
+
for (const path of manifest?.extraInputs ?? []) {
|
|
5970
|
+
const abs = (0, import_node_path18.resolve)(config.codegen.cwd, path);
|
|
5971
|
+
if (trackedPaths.has(abs)) continue;
|
|
5972
|
+
trackedPaths.add(abs);
|
|
5973
|
+
fresh.push(abs);
|
|
5974
|
+
}
|
|
5975
|
+
if (fresh.length > 0) trackedWatcher.add(fresh);
|
|
5976
|
+
}
|
|
5977
|
+
async function generateAndTrack(routes) {
|
|
5978
|
+
try {
|
|
5979
|
+
await generate(config, routes, entryPoint);
|
|
5980
|
+
} finally {
|
|
5981
|
+
await syncTrackedInputs().catch(() => {
|
|
5982
|
+
});
|
|
5983
|
+
}
|
|
5984
|
+
}
|
|
5940
5985
|
async function runInitialPass() {
|
|
5941
5986
|
try {
|
|
5942
5987
|
const initialRoutes = (await getDiscovery()).discover();
|
|
5943
5988
|
lastRoutes = initialRoutes;
|
|
5944
|
-
await
|
|
5989
|
+
await generateAndTrack(initialRoutes);
|
|
5945
5990
|
} catch (err) {
|
|
5946
5991
|
if (err instanceof DriftGuardError) {
|
|
5947
5992
|
console.error(err.message);
|
|
@@ -5951,7 +5996,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5951
5996
|
`[nestjs-codegen] Initial route discovery failed, falling back to pages-only: ${err instanceof Error ? err.message : String(err)}`
|
|
5952
5997
|
);
|
|
5953
5998
|
try {
|
|
5954
|
-
await
|
|
5999
|
+
await generateAndTrack(lastRoutes);
|
|
5955
6000
|
} catch {
|
|
5956
6001
|
}
|
|
5957
6002
|
}
|
|
@@ -5984,7 +6029,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5984
6029
|
pagesDebounceTimer = setTimeout(async () => {
|
|
5985
6030
|
pagesDebounceTimer = void 0;
|
|
5986
6031
|
try {
|
|
5987
|
-
await
|
|
6032
|
+
await generateAndTrack(lastRoutes);
|
|
5988
6033
|
} catch (err) {
|
|
5989
6034
|
console.error(
|
|
5990
6035
|
"[nestjs-codegen] Pages generation failed:",
|
|
@@ -6016,7 +6061,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
6016
6061
|
try {
|
|
6017
6062
|
const routes = await (await getDiscovery()).rediscover(changed);
|
|
6018
6063
|
lastRoutes = routes;
|
|
6019
|
-
await
|
|
6064
|
+
await generateAndTrack(routes);
|
|
6020
6065
|
} catch (err) {
|
|
6021
6066
|
console.error(
|
|
6022
6067
|
"[nestjs-codegen] Contracts generation failed:",
|
|
@@ -6037,6 +6082,9 @@ async function watch(config, onChange, options = {}) {
|
|
|
6037
6082
|
formsWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
6038
6083
|
formsWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
6039
6084
|
formsWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
6085
|
+
trackedWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
6086
|
+
trackedWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
6087
|
+
trackedWatcher.on("unlink", (p) => scheduleContractsRegenerate(p));
|
|
6040
6088
|
return {
|
|
6041
6089
|
close: async () => {
|
|
6042
6090
|
if (pagesDebounceTimer !== void 0) {
|
|
@@ -6050,6 +6098,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
6050
6098
|
await pagesWatcher.close();
|
|
6051
6099
|
await contractsWatcher.close();
|
|
6052
6100
|
await formsWatcher.close();
|
|
6101
|
+
await trackedWatcher.close();
|
|
6053
6102
|
await lock.release();
|
|
6054
6103
|
}
|
|
6055
6104
|
};
|
|
@@ -6138,12 +6187,114 @@ function createChainModuleRenderer(opts) {
|
|
|
6138
6187
|
};
|
|
6139
6188
|
}
|
|
6140
6189
|
|
|
6190
|
+
// src/extension/genui-sandbox-kit.ts
|
|
6191
|
+
var import_node_fs2 = require("fs");
|
|
6192
|
+
var import_node_path19 = require("path");
|
|
6193
|
+
var import_fast_glob4 = __toESM(require("fast-glob"), 1);
|
|
6194
|
+
var GENUI_KIT_MODULE = "@dudousxd/nestjs-agent-core/genui/kit";
|
|
6195
|
+
var DEFAULT_SANDBOX_KIT_OUTPUT = ".genui/sandbox-kit.json";
|
|
6196
|
+
var DEFAULT_KIT_DIRS = [
|
|
6197
|
+
"inertia/components/ui",
|
|
6198
|
+
"resources/js/components/ui",
|
|
6199
|
+
"src/components/ui",
|
|
6200
|
+
"app/components/ui",
|
|
6201
|
+
"components/ui"
|
|
6202
|
+
];
|
|
6203
|
+
async function loadKitModule(specifier = GENUI_KIT_MODULE) {
|
|
6204
|
+
let mod;
|
|
6205
|
+
try {
|
|
6206
|
+
mod = await import(specifier);
|
|
6207
|
+
} catch (err) {
|
|
6208
|
+
const code = err.code;
|
|
6209
|
+
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
|
|
6210
|
+
throw new CodegenError(
|
|
6211
|
+
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}" \u2014 install @dudousxd/nestjs-agent-core@>=0.52.0, or pass \`generate\` to genuiSandboxKit().`
|
|
6212
|
+
);
|
|
6213
|
+
}
|
|
6214
|
+
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
6215
|
+
throw new CodegenError(
|
|
6216
|
+
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}", which the installed @dudousxd/nestjs-agent-core does not export \u2014 upgrade it to >=0.52.0.`
|
|
6217
|
+
);
|
|
6218
|
+
}
|
|
6219
|
+
throw err;
|
|
6220
|
+
}
|
|
6221
|
+
if (typeof mod.writeSandboxKitDocs !== "function") {
|
|
6222
|
+
throw new CodegenError(
|
|
6223
|
+
`"${GENUI_KIT_MODULE}" has no writeSandboxKitDocs export \u2014 upgrade @dudousxd/nestjs-agent-core to >=0.52.0.`
|
|
6224
|
+
);
|
|
6225
|
+
}
|
|
6226
|
+
return mod;
|
|
6227
|
+
}
|
|
6228
|
+
function globBase(glob) {
|
|
6229
|
+
const base = [];
|
|
6230
|
+
for (const part of glob.replace(/\\/g, "/").split("/")) {
|
|
6231
|
+
if (/[*?{[]/.test(part)) break;
|
|
6232
|
+
base.push(part);
|
|
6233
|
+
}
|
|
6234
|
+
return base.join("/");
|
|
6235
|
+
}
|
|
6236
|
+
function resolveKitFilesLocally(root, options) {
|
|
6237
|
+
if (options.entry !== void 0) {
|
|
6238
|
+
const entry = (0, import_node_path19.isAbsolute)(options.entry) ? options.entry : (0, import_node_path19.resolve)(root, options.entry);
|
|
6239
|
+
return { entry, files: [entry], dirs: [(0, import_node_path19.dirname)(entry)] };
|
|
6240
|
+
}
|
|
6241
|
+
const include = options.include ?? DEFAULT_KIT_DIRS.filter((dir) => (0, import_node_fs2.existsSync)((0, import_node_path19.resolve)(root, dir))).map(
|
|
6242
|
+
(dir) => `${dir}/*.{tsx,jsx,ts,js}`
|
|
6243
|
+
)[0];
|
|
6244
|
+
if (include === void 0) return null;
|
|
6245
|
+
const globs = typeof include === "string" ? [include] : [...include];
|
|
6246
|
+
const files = import_fast_glob4.default.sync(globs, { cwd: root, absolute: true, onlyFiles: true }).sort();
|
|
6247
|
+
return { files, dirs: [...new Set(globs.map((glob) => (0, import_node_path19.resolve)(root, globBase(glob))))] };
|
|
6248
|
+
}
|
|
6249
|
+
function genuiSandboxKit(options = {}) {
|
|
6250
|
+
const output = options.output ?? DEFAULT_SANDBOX_KIT_OUTPUT;
|
|
6251
|
+
const source = {
|
|
6252
|
+
...options.entry !== void 0 ? { entry: options.entry } : {},
|
|
6253
|
+
...options.include !== void 0 ? { include: options.include } : {}
|
|
6254
|
+
};
|
|
6255
|
+
const extension = {
|
|
6256
|
+
name: "genui-sandbox-kit",
|
|
6257
|
+
// Not read by the host: serialized into the config hash, so changing an option
|
|
6258
|
+
// invalidates skip-when-unchanged.
|
|
6259
|
+
options: { ...source, css: options.css, tsconfig: options.tsconfig, output },
|
|
6260
|
+
async emitFiles(ctx) {
|
|
6261
|
+
const root = ctx.cwd;
|
|
6262
|
+
let generate2 = options.generate;
|
|
6263
|
+
let resolveFiles = resolveKitFilesLocally;
|
|
6264
|
+
if (!generate2) {
|
|
6265
|
+
const mod = await loadKitModule(options.kitModule);
|
|
6266
|
+
generate2 = mod.writeSandboxKitDocs;
|
|
6267
|
+
if (typeof mod.resolveSandboxKitFiles === "function") {
|
|
6268
|
+
resolveFiles = mod.resolveSandboxKitFiles;
|
|
6269
|
+
}
|
|
6270
|
+
}
|
|
6271
|
+
const kit = resolveFiles(root, source);
|
|
6272
|
+
if (kit) ctx.trackInput(...kit.files, ...kit.dirs);
|
|
6273
|
+
if (options.css !== void 0) {
|
|
6274
|
+
const css = typeof options.css === "string" ? [options.css] : [...options.css];
|
|
6275
|
+
ctx.trackInput(...import_fast_glob4.default.sync(css, { cwd: root, absolute: true, onlyFiles: true }));
|
|
6276
|
+
}
|
|
6277
|
+
ctx.trackInput((0, import_node_path19.isAbsolute)(output) ? output : (0, import_node_path19.resolve)(root, output));
|
|
6278
|
+
await generate2({
|
|
6279
|
+
root,
|
|
6280
|
+
output,
|
|
6281
|
+
...source,
|
|
6282
|
+
...options.css !== void 0 ? { css: options.css } : {},
|
|
6283
|
+
...options.tsconfig !== void 0 ? { tsconfig: options.tsconfig } : {}
|
|
6284
|
+
});
|
|
6285
|
+
return [];
|
|
6286
|
+
}
|
|
6287
|
+
};
|
|
6288
|
+
return extension;
|
|
6289
|
+
}
|
|
6290
|
+
|
|
6141
6291
|
// src/index.ts
|
|
6142
|
-
var VERSION = "0.
|
|
6292
|
+
var VERSION = "0.28.0";
|
|
6143
6293
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6144
6294
|
0 && (module.exports = {
|
|
6145
6295
|
CodegenError,
|
|
6146
6296
|
ConfigError,
|
|
6297
|
+
DEFAULT_SANDBOX_KIT_OUTPUT,
|
|
6147
6298
|
DriftGuardError,
|
|
6148
6299
|
VERSION,
|
|
6149
6300
|
acquireLock,
|
|
@@ -6159,6 +6310,7 @@ var VERSION = "0.27.1";
|
|
|
6159
6310
|
emitRoutes,
|
|
6160
6311
|
extractSchemaFromDto,
|
|
6161
6312
|
generate,
|
|
6313
|
+
genuiSandboxKit,
|
|
6162
6314
|
loadConfig,
|
|
6163
6315
|
renderTsType,
|
|
6164
6316
|
resolveAdapter,
|