@kubb/plugin-react-query 5.3.1 → 5.3.3

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { Resolver, Url, addGenerator, ast, createResolver, defineGenerator, definePlugin, setMacros, setResolver, useConfig } from "kubb/kit";
2
+ import { Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
3
3
  import path from "node:path";
4
4
  import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
5
5
  import { File, Function, Type, jsxRenderer } from "kubb/jsx";
@@ -325,12 +325,12 @@ function createGroupConfig(group) {
325
325
  //#endregion
326
326
  //#region kubb-extension.json
327
327
  var compatibility = {
328
- "kubb": ">=5.8.0",
328
+ "kubb": ">=5.8.3",
329
329
  "node": ">=22"
330
330
  };
331
331
  //#endregion
332
332
  //#region package.json
333
- var version = "5.3.1";
333
+ var version = "5.3.3";
334
334
  //#endregion
335
335
  //#region ../../internals/client/src/resolveClient.ts
336
336
  /**
@@ -982,26 +982,28 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
982
982
  //#region src/generators/customHookOptionsFileGenerator.tsx
983
983
  /**
984
984
  * Scaffolds the user-editable `useCustomHookOptions` file when
985
- * `pluginReactQuery({ customOptions: { ... } })` is configured. The file is
985
+ * `pluginReactQuery({ customOptions: { ... }, hooks: true })` is configured. The file is
986
986
  * only created when it does not already exist, so user edits persist across
987
- * regeneration.
987
+ * regeneration, and only when `importPath` resolves inside the plugin's output folder.
988
988
  */
989
989
  const customHookOptionsFileGenerator = defineGenerator({
990
990
  name: "react-query-custom-hook-options-file",
991
991
  renderer: jsxRenderer,
992
992
  operations(nodes, ctx) {
993
993
  const { resolver, root } = ctx;
994
- const { output, customOptions, query, group } = ctx.options;
995
- if (!customOptions) return null;
994
+ const { output, customOptions, query, group, hooks } = ctx.options;
995
+ if (!customOptions || !hooks) return null;
996
996
  const { importPath, name } = customOptions;
997
997
  const hookOptionsName = resolver.hook.optionsName();
998
998
  const customHookOptionsName = resolver.hook.customOptionsName();
999
999
  const reactQueryImportPath = query ? query.importPath : "@tanstack/react-query";
1000
- let hookFilePath;
1000
+ const outputPath = path.resolve(root, output.path);
1001
+ const outputDir = output.mode === "directory" ? outputPath : path.dirname(outputPath);
1002
+ let basePath = outputDir;
1001
1003
  const firstNode = nodes[0];
1002
1004
  if (firstNode) {
1003
1005
  const hookName = resolver.query.name(firstNode);
1004
- hookFilePath = resolver.file({
1006
+ const hookFile = resolver.file({
1005
1007
  name: hookName,
1006
1008
  extname: ".ts",
1007
1009
  tag: firstNode.tags[0] ?? "default",
@@ -1009,18 +1011,20 @@ const customHookOptionsFileGenerator = defineGenerator({
1009
1011
  root,
1010
1012
  output,
1011
1013
  group: group ?? void 0
1012
- }).path;
1013
- } else hookFilePath = path.resolve(root, "index.ts");
1014
+ });
1015
+ basePath = path.dirname(hookFile.path);
1016
+ }
1014
1017
  const ensureExtension = (filePath, extname) => {
1015
1018
  if (path.extname(filePath) === "") return filePath + extname;
1016
1019
  return filePath;
1017
1020
  };
1018
- const basePath = path.dirname(hookFilePath);
1019
1021
  const actualFilePath = ensureExtension(importPath, ".ts");
1020
1022
  const file = {
1021
1023
  baseName: path.basename(actualFilePath),
1022
1024
  path: path.resolve(basePath, actualFilePath)
1023
1025
  };
1026
+ const relativeToOutput = path.relative(outputDir, file.path);
1027
+ if (relativeToOutput === ".." || relativeToOutput.startsWith(`..${path.sep}`) || path.isAbsolute(relativeToOutput)) return null;
1024
1028
  if (fs.existsSync(file.path)) return null;
1025
1029
  return /* @__PURE__ */ jsxs(File, {
1026
1030
  baseName: file.baseName,
@@ -2447,7 +2451,8 @@ const pluginReactQueryName = "plugin-react-query";
2447
2451
  * })
2448
2452
  * ```
2449
2453
  */
2450
- const pluginReactQuery = definePlugin({
2454
+ const pluginReactQuery = defineExtension({
2455
+ kind: "plugin",
2451
2456
  meta: {
2452
2457
  name: pluginReactQueryName,
2453
2458
  version,