@dudousxd/nestjs-codegen 0.28.0 → 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/dist/index.cjs CHANGED
@@ -6200,6 +6200,12 @@ var DEFAULT_KIT_DIRS = [
6200
6200
  "app/components/ui",
6201
6201
  "components/ui"
6202
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";
6203
6209
  async function loadKitModule(specifier = GENUI_KIT_MODULE) {
6204
6210
  let mod;
6205
6211
  try {
@@ -6208,19 +6214,24 @@ async function loadKitModule(specifier = GENUI_KIT_MODULE) {
6208
6214
  const code = err.code;
6209
6215
  if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
6210
6216
  throw new CodegenError(
6211
- `genuiSandboxKit() needs "${GENUI_KIT_MODULE}" \u2014 install @dudousxd/nestjs-agent-core@>=0.52.0, or pass \`generate\` to genuiSandboxKit().`
6217
+ `genuiSandboxKit() needs "${GENUI_KIT_MODULE}" \u2014 install @dudousxd/nestjs-agent-core@>=${MIN_CORE}, or pass \`generate\` to genuiSandboxKit().`
6212
6218
  );
6213
6219
  }
6214
6220
  if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
6215
6221
  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.`
6222
+ `genuiSandboxKit() needs "${GENUI_KIT_MODULE}", which the installed @dudousxd/nestjs-agent-core does not export \u2014 upgrade it to >=${MIN_CORE}.`
6217
6223
  );
6218
6224
  }
6219
6225
  throw err;
6220
6226
  }
6221
6227
  if (typeof mod.writeSandboxKitDocs !== "function") {
6222
6228
  throw new CodegenError(
6223
- `"${GENUI_KIT_MODULE}" has no writeSandboxKitDocs export \u2014 upgrade @dudousxd/nestjs-agent-core to >=0.52.0.`
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}.`
6224
6235
  );
6225
6236
  }
6226
6237
  return mod;
@@ -6234,52 +6245,92 @@ function globBase(glob) {
6234
6245
  return base.join("/");
6235
6246
  }
6236
6247
  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
+ 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] };
6248
6272
  }
6249
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
+ }
6250
6282
  const output = options.output ?? DEFAULT_SANDBOX_KIT_OUTPUT;
6251
6283
  const source = {
6252
- ...options.entry !== void 0 ? { entry: options.entry } : {},
6253
- ...options.include !== void 0 ? { include: options.include } : {}
6284
+ ...options.components !== void 0 ? { components: options.components } : {},
6285
+ ...options.wrapper !== void 0 ? { wrapper: options.wrapper } : {}
6254
6286
  };
6255
6287
  const extension = {
6256
6288
  name: "genui-sandbox-kit",
6257
6289
  // Not read by the host: serialized into the config hash, so changing an option
6258
6290
  // invalidates skip-when-unchanged.
6259
- options: { ...source, css: options.css, tsconfig: options.tsconfig, output },
6291
+ options: {
6292
+ ...source,
6293
+ styles: options.styles,
6294
+ stylesDocs: options.stylesDocs,
6295
+ tsconfig: options.tsconfig,
6296
+ output
6297
+ },
6260
6298
  async emitFiles(ctx) {
6261
6299
  const root = ctx.cwd;
6262
6300
  let generate2 = options.generate;
6263
- let resolveFiles = resolveKitFilesLocally;
6301
+ let mod;
6264
6302
  if (!generate2) {
6265
- const mod = await loadKitModule(options.kitModule);
6303
+ mod = await loadKitModule(options.kitModule);
6266
6304
  generate2 = mod.writeSandboxKitDocs;
6267
- if (typeof mod.resolveSandboxKitFiles === "function") {
6268
- resolveFiles = mod.resolveSandboxKitFiles;
6269
- }
6270
6305
  }
6271
- const kit = resolveFiles(root, source);
6306
+ const resolveFiles = mod?.resolveSandboxKitFiles ?? resolveKitFilesLocally;
6307
+ let kit = null;
6308
+ try {
6309
+ kit = resolveFiles(root, source);
6310
+ } catch {
6311
+ kit = null;
6312
+ }
6272
6313
  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 }));
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);
6276
6326
  }
6277
6327
  ctx.trackInput((0, import_node_path19.isAbsolute)(output) ? output : (0, import_node_path19.resolve)(root, output));
6278
6328
  await generate2({
6279
6329
  root,
6280
6330
  output,
6281
6331
  ...source,
6282
- ...options.css !== void 0 ? { css: options.css } : {},
6332
+ ...options.styles !== void 0 ? { styles: options.styles } : {},
6333
+ ...options.stylesDocs !== void 0 ? { stylesDocs: options.stylesDocs } : {},
6283
6334
  ...options.tsconfig !== void 0 ? { tsconfig: options.tsconfig } : {}
6284
6335
  });
6285
6336
  return [];
@@ -6289,7 +6340,7 @@ function genuiSandboxKit(options = {}) {
6289
6340
  }
6290
6341
 
6291
6342
  // src/index.ts
6292
- var VERSION = "0.28.0";
6343
+ var VERSION = "0.29.0";
6293
6344
  // Annotate the CommonJS export names for ESM import in node:
6294
6345
  0 && (module.exports = {
6295
6346
  CodegenError,