New:Socket for Asana Is Now Available.Learn more
Get Started

@7nohe/openapi-react-query-codegen

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@7nohe/openapi-react-query-codegen - npm Package Compare versions

Comparing version
3.0.0-beta.5
to
3.0.0
+1
-0
dist/generate.d.mts
import type { LimitedUserConfig } from "./cli.mjs";
export declare function findNearestTsConfigPath(startDir: string): string | undefined;
export declare function generate(options: LimitedUserConfig, version: string): Promise<void>;

@@ -1,2 +0,3 @@

import { writeFile } from "node:fs/promises";
import { readdirSync } from "node:fs";
import { readFile, writeFile } from "node:fs/promises";
import path from "node:path";

@@ -8,2 +9,21 @@ import { createClient } from "@hey-api/openapi-ts";

import { print } from "./print.mjs";
// openapi-ts's own tsconfig auto-detection walks up from its *install*
// location, which in this monorepo reaches this repo's own root tsconfig
// (NodeNext) instead of the caller's project config. Anchoring the search
// at cwd instead finds the tsconfig that actually applies to the generated
// output, matching the resolution the caller's own `tsc` will use.
export function findNearestTsConfigPath(startDir) {
let dir = startDir;
while (true) {
const candidates = readdirSync(dir).filter((file) => file.startsWith("tsconfig") && file.endsWith(".json"));
if (candidates.length > 0) {
candidates.sort((a) => (a === "tsconfig.json" ? -1 : 1));
return path.join(dir, candidates[0]);
}
const parent = path.dirname(dir);
if (parent === dir)
return undefined;
dir = parent;
}
}
export async function generate(options, version) {

@@ -59,3 +79,6 @@ const openApiOutputPath = buildRequestsOutputPath(options.output);

input: formattedOptions.input,
output: openApiOutputPath,
output: {
path: openApiOutputPath,
tsConfigPath: findNearestTsConfigPath(process.cwd()) ?? null,
},
plugins,

@@ -65,4 +88,8 @@ };

// Generate backward-compatible services.gen.ts shim
// client.gen.ts has the `client` instance; sdk.gen.ts has SDK functions
const shimContent = `// This file is auto-generated for backward compatibility\nexport * from './client.gen.js';\nexport * from './sdk.gen.js';\n`;
// client.gen.ts has the `client` instance; sdk.gen.ts has SDK functions.
// Mirror whatever extension convention openapi-ts used for its own
// cross-file imports (e.g. `.js` for NodeNext, none for bundler resolution).
const sdkGenContent = await readFile(path.join(openApiOutputPath, "sdk.gen.ts"), "utf-8");
const importExtension = sdkGenContent.match(/from ['"]\.\/client\.gen(\.\S*)?['"]/)?.[1] ?? "";
const shimContent = `// This file is auto-generated for backward compatibility\nexport * from './client.gen${importExtension}';\nexport * from './sdk.gen${importExtension}';\n`;
await writeFile(path.join(openApiOutputPath, "services.gen.ts"), shimContent);

@@ -69,0 +96,0 @@ const source = await createSource({

+1
-1
{
"name": "@7nohe/openapi-react-query-codegen",
"version": "3.0.0-beta.5",
"version": "3.0.0",
"description": "OpenAPI React Query Codegen",

@@ -5,0 +5,0 @@ "bin": {