@kubb/core 5.0.0-beta.96 → 5.0.0-beta.97

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
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_usingCtx = require("./usingCtx-eyNeehd2.cjs");
2
+ const require_usingCtx = require("./usingCtx-BLzqdXPG.cjs");
3
3
  let node_async_hooks = require("node:async_hooks");
4
4
  let node_util = require("node:util");
5
5
  let node_crypto = require("node:crypto");
@@ -191,7 +191,7 @@ function memoize(store, factory) {
191
191
  }
192
192
  //#endregion
193
193
  //#region package.json
194
- var version = "5.0.0-beta.96";
194
+ var version = "5.0.0-beta.97";
195
195
  //#endregion
196
196
  //#region src/constants.ts
197
197
  /**
@@ -269,6 +269,11 @@ const diagnosticCode = {
269
269
  */
270
270
  pathTraversal: "KUBB_PATH_TRAVERSAL",
271
271
  /**
272
+ * `output.clean` is enabled but `output.path` resolves to the project root or a parent of it,
273
+ * so cleaning would delete kubb.config and every source file.
274
+ */
275
+ cleanRoot: "KUBB_CLEAN_ROOT",
276
+ /**
272
277
  * A plugin's options are invalid, for example `output.mode: 'file'` paired with a `group` option.
273
278
  */
274
279
  invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS",
@@ -416,6 +421,11 @@ const diagnosticCatalog = {
416
421
  cause: "A resolved output path escaped the output directory, which can stem from a path traversal in the spec or a misconfigured `group.name`.",
417
422
  fix: "Keep generated paths within the output directory. Review the `group.name` function and the names coming from the spec."
418
423
  },
424
+ [diagnosticCode.cleanRoot]: {
425
+ title: "Clean targets the project root",
426
+ cause: "`output.clean` is enabled and `output.path` resolves to the project root or a parent of it, so cleaning would delete `kubb.config` and every source file.",
427
+ fix: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code, or disable `output.clean`."
428
+ },
419
429
  [diagnosticCode.invalidPluginOptions]: {
420
430
  title: "Invalid plugin options",
421
431
  cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
@@ -2094,7 +2104,17 @@ var Kubb = class {
2094
2104
  const config = this.config;
2095
2105
  const driver = new KubbDriver(config, { hooks: this.hooks });
2096
2106
  this.hooks.setMaxListeners(Math.max(10, config.plugins.length * 4));
2097
- if (config.output.clean) await config.storage.clear((0, node_path.resolve)(config.root, config.output.path));
2107
+ if (config.output.clean) {
2108
+ const cleanPath = (0, node_path.resolve)(config.root, config.output.path);
2109
+ if (require_usingCtx.isPathInside(config.root, cleanPath)) throw new Diagnostics.Error({
2110
+ code: Diagnostics.code.cleanRoot,
2111
+ severity: "error",
2112
+ message: `output.clean cannot delete "${cleanPath}" because it is the project root or a parent of it.`,
2113
+ help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
2114
+ location: { kind: "config" }
2115
+ });
2116
+ await config.storage.clear(cleanPath);
2117
+ }
2098
2118
  await driver.setup();
2099
2119
  this.#driver = driver;
2100
2120
  this.#storage = config.storage;