@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/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,114 @@ 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
|
+
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
|
+
|
|
6147
6291
|
// src/index.ts
|
|
6148
|
-
var VERSION = "0.
|
|
6292
|
+
var VERSION = "0.28.0";
|
|
6149
6293
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6150
6294
|
0 && (module.exports = {
|
|
6151
6295
|
CodegenError,
|
|
6152
6296
|
ConfigError,
|
|
6297
|
+
DEFAULT_SANDBOX_KIT_OUTPUT,
|
|
6153
6298
|
DriftGuardError,
|
|
6154
6299
|
VERSION,
|
|
6155
6300
|
acquireLock,
|
|
@@ -6165,6 +6310,7 @@ var VERSION = "0.27.2";
|
|
|
6165
6310
|
emitRoutes,
|
|
6166
6311
|
extractSchemaFromDto,
|
|
6167
6312
|
generate,
|
|
6313
|
+
genuiSandboxKit,
|
|
6168
6314
|
loadConfig,
|
|
6169
6315
|
renderTsType,
|
|
6170
6316
|
resolveAdapter,
|