@kubb/plugin-fetch 5.5.0 → 5.5.2

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,11 +1,10 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { Resolver, Url, ast, createResolver, defineGenerator, definePlugin, macroSimplifyUnion } from "kubb/kit";
2
+ import { Diagnostics, Resolver, Url, ast, createResolver, defineGenerator, definePlugin, macroSimplifyUnion } from "kubb/kit";
3
3
  import path from "node:path";
4
4
  import { createFunctionParameter, createFunctionParameters, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
5
5
  import { File, Function, jsxRenderer } from "kubb/jsx";
6
6
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
7
7
  import { pluginZodName } from "@kubb/plugin-zod";
8
- import { readFileSync } from "node:fs";
9
8
  import { fileURLToPath } from "node:url";
10
9
  //#region ../../internals/shared/src/params.ts
11
10
  /**
@@ -1224,6 +1223,14 @@ function createSdkGenerator() {
1224
1223
  const { config, resolver, root } = ctx;
1225
1224
  const { output, group, validator, returnType, throwOnErrorDefault, sdk } = ctx.options;
1226
1225
  if (!sdk) return null;
1226
+ if (sdk.mode === "tag" && output.mode === "file") throw new Diagnostics.Error({
1227
+ code: Diagnostics.code.invalidPluginOptions,
1228
+ severity: "error",
1229
+ message: `Plugin "${ctx.plugin.name}" resolves \`output.mode\` to 'file' but also configures \`sdk.mode: 'tag'\`.`,
1230
+ help: "A single-file output has nothing to split tag classes into. Set `sdk.mode: 'flat'` to emit one class into that file, or give `output.path` an extensionless directory name (or set `output.mode: 'directory'` explicitly) so each tag gets its own file.",
1231
+ location: { kind: "config" },
1232
+ plugin: ctx.plugin.name
1233
+ });
1227
1234
  const types = resolveOperationTypes(ctx.driver);
1228
1235
  if (!types) {
1229
1236
  ctx.warn(MISSING_OPERATION_TYPES_WARNING);
@@ -1395,27 +1402,6 @@ const resolverClient = createResolver({
1395
1402
  }
1396
1403
  });
1397
1404
  //#endregion
1398
- //#region ../../internals/client/src/runtimeTemplate.ts
1399
- /** Apply the active TypeScript parser's import extension to a copied client runtime. */
1400
- function runtimeTemplate(path, config) {
1401
- const parser = config.parsers.find((item) => item.extNames?.includes(".ts"));
1402
- const probe = ast.factory.createFile({
1403
- baseName: "probe.ts",
1404
- path: "probe.ts",
1405
- imports: [ast.factory.createImport({
1406
- name: ["KubbRuntimeImport"],
1407
- path: "/probeDependency.ts",
1408
- root: "/"
1409
- })],
1410
- sources: [ast.factory.createSource({
1411
- name: "probe",
1412
- nodes: [ast.factory.createText("KubbRuntimeImport")]
1413
- })]
1414
- });
1415
- const extension = parser?.parse(probe).match(/from ['"]\.\/probeDependency(\.[^'"]+)?['"]/)?.[1] ?? "";
1416
- return readFileSync(path, "utf8").replace(/(from ['"]\.\/(?:serializers|standardSchema))(?:\.ts|\.js)?(['"])/g, `$1${extension}$2`);
1417
- }
1418
- //#endregion
1419
1405
  //#region src/generators/clientGenerator.tsx
1420
1406
  /**
1421
1407
  * Built-in operation generator for `@kubb/plugin-fetch`. Emits one async function per OpenAPI
@@ -1504,7 +1490,7 @@ const pluginFetch = definePlugin((options) => {
1504
1490
  ctx.injectFile({
1505
1491
  baseName: "client.ts",
1506
1492
  path: path.resolve(root, ".kubb/client.ts"),
1507
- banner: runtimeTemplate(fetchClientTemplatePath, ctx.config),
1493
+ copy: fetchClientTemplatePath,
1508
1494
  footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : void 0
1509
1495
  });
1510
1496
  ctx.injectFile({