@kubb/plugin-react-query 5.3.2 → 5.3.4

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
@@ -357,7 +357,7 @@ var compatibility = {
357
357
  };
358
358
  //#endregion
359
359
  //#region package.json
360
- var version = "5.3.2";
360
+ var version = "5.3.4";
361
361
  //#endregion
362
362
  //#region ../../internals/client/src/resolveClient.ts
363
363
  /**
@@ -1009,26 +1009,28 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
1009
1009
  //#region src/generators/customHookOptionsFileGenerator.tsx
1010
1010
  /**
1011
1011
  * Scaffolds the user-editable `useCustomHookOptions` file when
1012
- * `pluginReactQuery({ customOptions: { ... } })` is configured. The file is
1012
+ * `pluginReactQuery({ customOptions: { ... }, hooks: true })` is configured. The file is
1013
1013
  * only created when it does not already exist, so user edits persist across
1014
- * regeneration.
1014
+ * regeneration, and only when `importPath` resolves inside the plugin's output folder.
1015
1015
  */
1016
1016
  const customHookOptionsFileGenerator = (0, kubb_kit.defineGenerator)({
1017
1017
  name: "react-query-custom-hook-options-file",
1018
1018
  renderer: kubb_jsx.jsxRenderer,
1019
1019
  operations(nodes, ctx) {
1020
1020
  const { resolver, root } = ctx;
1021
- const { output, customOptions, query, group } = ctx.options;
1022
- if (!customOptions) return null;
1021
+ const { output, customOptions, query, group, hooks } = ctx.options;
1022
+ if (!customOptions || !hooks) return null;
1023
1023
  const { importPath, name } = customOptions;
1024
1024
  const hookOptionsName = resolver.hook.optionsName();
1025
1025
  const customHookOptionsName = resolver.hook.customOptionsName();
1026
1026
  const reactQueryImportPath = query ? query.importPath : "@tanstack/react-query";
1027
- let hookFilePath;
1027
+ const outputPath = node_path.default.resolve(root, output.path);
1028
+ const outputDir = output.mode === "directory" ? outputPath : node_path.default.dirname(outputPath);
1029
+ let basePath = outputDir;
1028
1030
  const firstNode = nodes[0];
1029
1031
  if (firstNode) {
1030
1032
  const hookName = resolver.query.name(firstNode);
1031
- hookFilePath = resolver.file({
1033
+ const hookFile = resolver.file({
1032
1034
  name: hookName,
1033
1035
  extname: ".ts",
1034
1036
  tag: firstNode.tags[0] ?? "default",
@@ -1036,18 +1038,20 @@ const customHookOptionsFileGenerator = (0, kubb_kit.defineGenerator)({
1036
1038
  root,
1037
1039
  output,
1038
1040
  group: group ?? void 0
1039
- }).path;
1040
- } else hookFilePath = node_path.default.resolve(root, "index.ts");
1041
+ });
1042
+ basePath = node_path.default.dirname(hookFile.path);
1043
+ }
1041
1044
  const ensureExtension = (filePath, extname) => {
1042
1045
  if (node_path.default.extname(filePath) === "") return filePath + extname;
1043
1046
  return filePath;
1044
1047
  };
1045
- const basePath = node_path.default.dirname(hookFilePath);
1046
1048
  const actualFilePath = ensureExtension(importPath, ".ts");
1047
1049
  const file = {
1048
1050
  baseName: node_path.default.basename(actualFilePath),
1049
1051
  path: node_path.default.resolve(basePath, actualFilePath)
1050
1052
  };
1053
+ const relativeToOutput = node_path.default.relative(outputDir, file.path);
1054
+ if (relativeToOutput === ".." || relativeToOutput.startsWith(`..${node_path.default.sep}`) || node_path.default.isAbsolute(relativeToOutput)) return null;
1051
1055
  if (node_fs.default.existsSync(file.path)) return null;
1052
1056
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1053
1057
  baseName: file.baseName,