@dudousxd/nestjs-codegen 0.27.2 → 0.29.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 +16 -0
- package/README.md +25 -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 +204 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -3
- package/dist/index.d.ts +69 -3
- package/dist/index.js +203 -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 -1
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,
|
|
@@ -5698,14 +5700,26 @@ async function computeInputsHash(config, extraInputs = []) {
|
|
|
5698
5700
|
hash.update("\n");
|
|
5699
5701
|
}
|
|
5700
5702
|
for (const file of extra) {
|
|
5701
|
-
const contents = await (0, import_promises11.readFile)((0, import_node_path15.join)(cwd, file), "utf8").catch(() => null);
|
|
5702
5703
|
hash.update(`extra:${file}
|
|
5703
5704
|
`);
|
|
5704
|
-
hash.update(
|
|
5705
|
+
hash.update(await readTrackedInput((0, import_node_path15.join)(cwd, file)));
|
|
5705
5706
|
hash.update("\n");
|
|
5706
5707
|
}
|
|
5707
5708
|
return hash.digest("hex");
|
|
5708
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
|
+
}
|
|
5709
5723
|
async function readManifest(outDir) {
|
|
5710
5724
|
try {
|
|
5711
5725
|
const raw = await (0, import_promises11.readFile)((0, import_node_path15.join)(outDir, MANIFEST_FILE), "utf8");
|
|
@@ -5943,11 +5957,36 @@ async function watch(config, onChange, options = {}) {
|
|
|
5943
5957
|
}
|
|
5944
5958
|
return discovery;
|
|
5945
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
|
+
}
|
|
5946
5985
|
async function runInitialPass() {
|
|
5947
5986
|
try {
|
|
5948
5987
|
const initialRoutes = (await getDiscovery()).discover();
|
|
5949
5988
|
lastRoutes = initialRoutes;
|
|
5950
|
-
await
|
|
5989
|
+
await generateAndTrack(initialRoutes);
|
|
5951
5990
|
} catch (err) {
|
|
5952
5991
|
if (err instanceof DriftGuardError) {
|
|
5953
5992
|
console.error(err.message);
|
|
@@ -5957,7 +5996,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5957
5996
|
`[nestjs-codegen] Initial route discovery failed, falling back to pages-only: ${err instanceof Error ? err.message : String(err)}`
|
|
5958
5997
|
);
|
|
5959
5998
|
try {
|
|
5960
|
-
await
|
|
5999
|
+
await generateAndTrack(lastRoutes);
|
|
5961
6000
|
} catch {
|
|
5962
6001
|
}
|
|
5963
6002
|
}
|
|
@@ -5990,7 +6029,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
5990
6029
|
pagesDebounceTimer = setTimeout(async () => {
|
|
5991
6030
|
pagesDebounceTimer = void 0;
|
|
5992
6031
|
try {
|
|
5993
|
-
await
|
|
6032
|
+
await generateAndTrack(lastRoutes);
|
|
5994
6033
|
} catch (err) {
|
|
5995
6034
|
console.error(
|
|
5996
6035
|
"[nestjs-codegen] Pages generation failed:",
|
|
@@ -6022,7 +6061,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
6022
6061
|
try {
|
|
6023
6062
|
const routes = await (await getDiscovery()).rediscover(changed);
|
|
6024
6063
|
lastRoutes = routes;
|
|
6025
|
-
await
|
|
6064
|
+
await generateAndTrack(routes);
|
|
6026
6065
|
} catch (err) {
|
|
6027
6066
|
console.error(
|
|
6028
6067
|
"[nestjs-codegen] Contracts generation failed:",
|
|
@@ -6043,6 +6082,9 @@ async function watch(config, onChange, options = {}) {
|
|
|
6043
6082
|
formsWatcher.on("add", (p) => scheduleContractsRegenerate(p));
|
|
6044
6083
|
formsWatcher.on("change", (p) => scheduleContractsRegenerate(p));
|
|
6045
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));
|
|
6046
6088
|
return {
|
|
6047
6089
|
close: async () => {
|
|
6048
6090
|
if (pagesDebounceTimer !== void 0) {
|
|
@@ -6056,6 +6098,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
6056
6098
|
await pagesWatcher.close();
|
|
6057
6099
|
await contractsWatcher.close();
|
|
6058
6100
|
await formsWatcher.close();
|
|
6101
|
+
await trackedWatcher.close();
|
|
6059
6102
|
await lock.release();
|
|
6060
6103
|
}
|
|
6061
6104
|
};
|
|
@@ -6144,12 +6187,165 @@ function createChainModuleRenderer(opts) {
|
|
|
6144
6187
|
};
|
|
6145
6188
|
}
|
|
6146
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
|
+
var LEGACY_OPTIONS = {
|
|
6204
|
+
entry: "`entry: X` is now `components: X`",
|
|
6205
|
+
include: "`include: G` is now `components: G` (globs, files, directories or packages)",
|
|
6206
|
+
css: "`css: G` is now `styles: G` (the app's style entry files)"
|
|
6207
|
+
};
|
|
6208
|
+
var MIN_CORE = "0.53.0";
|
|
6209
|
+
async function loadKitModule(specifier = GENUI_KIT_MODULE) {
|
|
6210
|
+
let mod;
|
|
6211
|
+
try {
|
|
6212
|
+
mod = await import(specifier);
|
|
6213
|
+
} catch (err) {
|
|
6214
|
+
const code = err.code;
|
|
6215
|
+
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
|
|
6216
|
+
throw new CodegenError(
|
|
6217
|
+
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}" \u2014 install @dudousxd/nestjs-agent-core@>=${MIN_CORE}, or pass \`generate\` to genuiSandboxKit().`
|
|
6218
|
+
);
|
|
6219
|
+
}
|
|
6220
|
+
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
6221
|
+
throw new CodegenError(
|
|
6222
|
+
`genuiSandboxKit() needs "${GENUI_KIT_MODULE}", which the installed @dudousxd/nestjs-agent-core does not export \u2014 upgrade it to >=${MIN_CORE}.`
|
|
6223
|
+
);
|
|
6224
|
+
}
|
|
6225
|
+
throw err;
|
|
6226
|
+
}
|
|
6227
|
+
if (typeof mod.writeSandboxKitDocs !== "function") {
|
|
6228
|
+
throw new CodegenError(
|
|
6229
|
+
`"${GENUI_KIT_MODULE}" has no writeSandboxKitDocs export \u2014 upgrade @dudousxd/nestjs-agent-core to >=${MIN_CORE}.`
|
|
6230
|
+
);
|
|
6231
|
+
}
|
|
6232
|
+
if (typeof mod.resolveStyleEntries !== "function") {
|
|
6233
|
+
throw new CodegenError(
|
|
6234
|
+
`The installed @dudousxd/nestjs-agent-core predates genuiSandboxKit({ components, styles, wrapper }) \u2014 upgrade it to >=${MIN_CORE}.`
|
|
6235
|
+
);
|
|
6236
|
+
}
|
|
6237
|
+
return mod;
|
|
6238
|
+
}
|
|
6239
|
+
function globBase(glob) {
|
|
6240
|
+
const base = [];
|
|
6241
|
+
for (const part of glob.replace(/\\/g, "/").split("/")) {
|
|
6242
|
+
if (/[*?{[]/.test(part)) break;
|
|
6243
|
+
base.push(part);
|
|
6244
|
+
}
|
|
6245
|
+
return base.join("/");
|
|
6246
|
+
}
|
|
6247
|
+
function resolveKitFilesLocally(root, options) {
|
|
6248
|
+
const specs = options.components === void 0 ? DEFAULT_KIT_DIRS.filter((dir) => (0, import_node_fs2.existsSync)((0, import_node_path19.resolve)(root, dir))).slice(0, 1) : typeof options.components === "string" ? [options.components] : [...options.components];
|
|
6249
|
+
const files = [];
|
|
6250
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
6251
|
+
for (const spec of specs) {
|
|
6252
|
+
if (/[*?{]/.test(spec)) {
|
|
6253
|
+
files.push(...import_fast_glob4.default.sync(spec, { cwd: root, absolute: true, onlyFiles: true }));
|
|
6254
|
+
dirs.add((0, import_node_path19.resolve)(root, globBase(spec)));
|
|
6255
|
+
continue;
|
|
6256
|
+
}
|
|
6257
|
+
const path = (0, import_node_path19.isAbsolute)(spec) ? spec : (0, import_node_path19.resolve)(root, spec);
|
|
6258
|
+
if ((0, import_node_fs2.existsSync)(path) && (0, import_node_fs2.statSync)(path).isDirectory()) {
|
|
6259
|
+
files.push(...import_fast_glob4.default.sync("*.{tsx,jsx,ts,js}", { cwd: path, absolute: true, onlyFiles: true }));
|
|
6260
|
+
dirs.add(path);
|
|
6261
|
+
} else if ((0, import_node_fs2.existsSync)(path)) {
|
|
6262
|
+
files.push(path);
|
|
6263
|
+
dirs.add((0, import_node_path19.dirname)(path));
|
|
6264
|
+
}
|
|
6265
|
+
}
|
|
6266
|
+
if (options.wrapper !== void 0) {
|
|
6267
|
+
const wrapper = (0, import_node_path19.isAbsolute)(options.wrapper) ? options.wrapper : (0, import_node_path19.resolve)(root, options.wrapper);
|
|
6268
|
+
if ((0, import_node_fs2.existsSync)(wrapper)) files.push(wrapper);
|
|
6269
|
+
}
|
|
6270
|
+
if (files.length === 0 && dirs.size === 0) return null;
|
|
6271
|
+
return { files: [...new Set(files)].sort(), dirs: [...dirs] };
|
|
6272
|
+
}
|
|
6273
|
+
function genuiSandboxKit(options = {}) {
|
|
6274
|
+
const legacy = Object.keys(LEGACY_OPTIONS).filter(
|
|
6275
|
+
(key) => options[key] !== void 0
|
|
6276
|
+
);
|
|
6277
|
+
if (legacy.length > 0) {
|
|
6278
|
+
throw new CodegenError(
|
|
6279
|
+
`genuiSandboxKit(): ${legacy.map((key) => `\`${key}\``).join(", ")} ${legacy.length > 1 ? "were" : "was"} removed \u2014 ${legacy.map((key) => LEGACY_OPTIONS[key]).join("; ")}. The options are now the agent's Vite plugin's: components, styles, wrapper, stylesDocs.`
|
|
6280
|
+
);
|
|
6281
|
+
}
|
|
6282
|
+
const output = options.output ?? DEFAULT_SANDBOX_KIT_OUTPUT;
|
|
6283
|
+
const source = {
|
|
6284
|
+
...options.components !== void 0 ? { components: options.components } : {},
|
|
6285
|
+
...options.wrapper !== void 0 ? { wrapper: options.wrapper } : {}
|
|
6286
|
+
};
|
|
6287
|
+
const extension = {
|
|
6288
|
+
name: "genui-sandbox-kit",
|
|
6289
|
+
// Not read by the host: serialized into the config hash, so changing an option
|
|
6290
|
+
// invalidates skip-when-unchanged.
|
|
6291
|
+
options: {
|
|
6292
|
+
...source,
|
|
6293
|
+
styles: options.styles,
|
|
6294
|
+
stylesDocs: options.stylesDocs,
|
|
6295
|
+
tsconfig: options.tsconfig,
|
|
6296
|
+
output
|
|
6297
|
+
},
|
|
6298
|
+
async emitFiles(ctx) {
|
|
6299
|
+
const root = ctx.cwd;
|
|
6300
|
+
let generate2 = options.generate;
|
|
6301
|
+
let mod;
|
|
6302
|
+
if (!generate2) {
|
|
6303
|
+
mod = await loadKitModule(options.kitModule);
|
|
6304
|
+
generate2 = mod.writeSandboxKitDocs;
|
|
6305
|
+
}
|
|
6306
|
+
const resolveFiles = mod?.resolveSandboxKitFiles ?? resolveKitFilesLocally;
|
|
6307
|
+
let kit = null;
|
|
6308
|
+
try {
|
|
6309
|
+
kit = resolveFiles(root, source);
|
|
6310
|
+
} catch {
|
|
6311
|
+
kit = null;
|
|
6312
|
+
}
|
|
6313
|
+
if (kit) ctx.trackInput(...kit.files, ...kit.dirs);
|
|
6314
|
+
if (options.styles !== void 0) {
|
|
6315
|
+
const entries = mod?.resolveStyleEntries ? mod.resolveStyleEntries(root, options.styles).files : import_fast_glob4.default.sync(typeof options.styles === "string" ? [options.styles] : [...options.styles], {
|
|
6316
|
+
cwd: root,
|
|
6317
|
+
absolute: true,
|
|
6318
|
+
onlyFiles: true
|
|
6319
|
+
});
|
|
6320
|
+
const files = mod?.collectStyleSources ? mod.collectStyleSources(entries).map((source2) => source2.file) : entries;
|
|
6321
|
+
ctx.trackInput(.../* @__PURE__ */ new Set([...entries, ...files]));
|
|
6322
|
+
}
|
|
6323
|
+
if (options.stylesDocs !== void 0 && !options.stylesDocs.includes("\n")) {
|
|
6324
|
+
const guide = (0, import_node_path19.isAbsolute)(options.stylesDocs) ? options.stylesDocs : (0, import_node_path19.resolve)(root, options.stylesDocs);
|
|
6325
|
+
if ((0, import_node_fs2.existsSync)(guide)) ctx.trackInput(guide);
|
|
6326
|
+
}
|
|
6327
|
+
ctx.trackInput((0, import_node_path19.isAbsolute)(output) ? output : (0, import_node_path19.resolve)(root, output));
|
|
6328
|
+
await generate2({
|
|
6329
|
+
root,
|
|
6330
|
+
output,
|
|
6331
|
+
...source,
|
|
6332
|
+
...options.styles !== void 0 ? { styles: options.styles } : {},
|
|
6333
|
+
...options.stylesDocs !== void 0 ? { stylesDocs: options.stylesDocs } : {},
|
|
6334
|
+
...options.tsconfig !== void 0 ? { tsconfig: options.tsconfig } : {}
|
|
6335
|
+
});
|
|
6336
|
+
return [];
|
|
6337
|
+
}
|
|
6338
|
+
};
|
|
6339
|
+
return extension;
|
|
6340
|
+
}
|
|
6341
|
+
|
|
6147
6342
|
// src/index.ts
|
|
6148
|
-
var VERSION = "0.
|
|
6343
|
+
var VERSION = "0.29.0";
|
|
6149
6344
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6150
6345
|
0 && (module.exports = {
|
|
6151
6346
|
CodegenError,
|
|
6152
6347
|
ConfigError,
|
|
6348
|
+
DEFAULT_SANDBOX_KIT_OUTPUT,
|
|
6153
6349
|
DriftGuardError,
|
|
6154
6350
|
VERSION,
|
|
6155
6351
|
acquireLock,
|
|
@@ -6165,6 +6361,7 @@ var VERSION = "0.27.2";
|
|
|
6165
6361
|
emitRoutes,
|
|
6166
6362
|
extractSchemaFromDto,
|
|
6167
6363
|
generate,
|
|
6364
|
+
genuiSandboxKit,
|
|
6168
6365
|
loadConfig,
|
|
6169
6366
|
renderTsType,
|
|
6170
6367
|
resolveAdapter,
|