Просмотр исходного кода

chore(js-sdk): Compatible with nodenext (#1667)

zWing 6 месяцев назад
Родитель
Сommit
2f4291672b

+ 4 - 1
packages/sdk/js/script/generate.ts

@@ -12,7 +12,10 @@ await $`bun dev generate > ${dir}/openapi.json`.cwd(path.resolve(dir, "../../ope
 
 await createClient({
   input: "./openapi.json",
-  output: "./src/gen",
+  output: {
+    path: "./src/gen",
+    tsConfigPath: path.join(dir, 'tsconfig.json')
+  },
   plugins: [
     {
       name: "@hey-api/typescript",

+ 2 - 2
packages/sdk/js/src/gen/client.gen.ts

@@ -1,7 +1,7 @@
 // This file is auto-generated by @hey-api/openapi-ts
 
-import type { ClientOptions } from "./types.gen"
-import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from "./client"
+import type { ClientOptions } from "./types.gen.js"
+import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from "./client/index.js"
 
 /**
  * The `createClientConfig()` function will be called on client initialization

+ 2 - 2
packages/sdk/js/src/gen/client/client.ts

@@ -1,4 +1,4 @@
-import type { Client, Config, RequestOptions } from "./types"
+import type { Client, Config, RequestOptions } from "./types.js"
 import {
   buildUrl,
   createConfig,
@@ -7,7 +7,7 @@ import {
   mergeConfigs,
   mergeHeaders,
   setAuthParams,
-} from "./utils"
+} from "./utils.js"
 
 type ReqInit = Omit<RequestInit, "body" | "headers"> & {
   body?: any

+ 7 - 7
packages/sdk/js/src/gen/client/index.ts

@@ -1,8 +1,8 @@
-export type { Auth } from "../core/auth"
-export type { QuerySerializerOptions } from "../core/bodySerializer"
-export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer } from "../core/bodySerializer"
-export { buildClientParams } from "../core/params"
-export { createClient } from "./client"
+export type { Auth } from "../core/auth.js"
+export type { QuerySerializerOptions } from "../core/bodySerializer.js"
+export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer } from "../core/bodySerializer.js"
+export { buildClientParams } from "../core/params.js"
+export { createClient } from "./client.js"
 export type {
   Client,
   ClientOptions,
@@ -14,5 +14,5 @@ export type {
   RequestResult,
   ResponseStyle,
   TDataShape,
-} from "./types"
-export { createConfig, mergeHeaders } from "./utils"
+} from "./types.js"
+export { createConfig, mergeHeaders } from "./utils.js"

+ 3 - 3
packages/sdk/js/src/gen/client/types.ts

@@ -1,6 +1,6 @@
-import type { Auth } from "../core/auth"
-import type { Client as CoreClient, Config as CoreConfig } from "../core/types"
-import type { Middleware } from "./utils"
+import type { Auth } from "../core/auth.js"
+import type { Client as CoreClient, Config as CoreConfig } from "../core/types.js"
+import type { Middleware } from "./utils.js"
 
 export type ResponseStyle = "data" | "fields"
 

+ 5 - 5
packages/sdk/js/src/gen/client/utils.ts

@@ -1,8 +1,8 @@
-import { getAuthToken } from "../core/auth"
-import type { QuerySerializer, QuerySerializerOptions } from "../core/bodySerializer"
-import { jsonBodySerializer } from "../core/bodySerializer"
-import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer"
-import type { Client, ClientOptions, Config, RequestOptions } from "./types"
+import { getAuthToken } from "../core/auth.js"
+import type { QuerySerializer, QuerySerializerOptions } from "../core/bodySerializer.js"
+import { jsonBodySerializer } from "../core/bodySerializer.js"
+import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.js"
+import type { Client, ClientOptions, Config, RequestOptions } from "./types.js"
 
 interface PathSerializer {
   path: Record<string, unknown>

+ 1 - 1
packages/sdk/js/src/gen/core/bodySerializer.ts

@@ -1,4 +1,4 @@
-import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer"
+import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.js"
 
 export type QuerySerializer = (query: Record<string, unknown>) => string
 

+ 2 - 2
packages/sdk/js/src/gen/core/types.ts

@@ -1,5 +1,5 @@
-import type { Auth, AuthToken } from "./auth"
-import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from "./bodySerializer"
+import type { Auth, AuthToken } from "./auth.js"
+import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from "./bodySerializer.js"
 
 export interface Client<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never> {
   /**

+ 3 - 3
packages/sdk/js/src/gen/sdk.gen.ts

@@ -1,6 +1,6 @@
 // This file is auto-generated by @hey-api/openapi-ts
 
-import type { Options as ClientOptions, TDataShape, Client } from "./client"
+import type { Options as ClientOptions, TDataShape, Client } from "./client/index.js"
 import type {
   EventSubscribeData,
   EventSubscribeResponses,
@@ -73,8 +73,8 @@ import type {
   TuiClearPromptResponses,
   TuiExecuteCommandData,
   TuiExecuteCommandResponses,
-} from "./types.gen"
-import { client as _heyApiClient } from "./client.gen"
+} from "./types.gen.js"
+import { client as _heyApiClient } from "./client.gen.js"
 
 export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<
   TData,

+ 4 - 4
packages/sdk/js/src/index.ts

@@ -1,7 +1,7 @@
-import { createClient } from "./gen/client/client"
-import { type Config } from "./gen/client/types"
-import { OpencodeClient } from "./gen/sdk.gen"
-export * from "./gen/types.gen"
+import { createClient } from "./gen/client/client.js"
+import { type Config } from "./gen/client/types.js"
+import { OpencodeClient } from "./gen/sdk.gen.js"
+export * from "./gen/types.gen.js"
 
 export function createOpencodeClient(config?: Config) {
   const client = createClient(config)

+ 2 - 2
packages/sdk/js/tsconfig.json

@@ -3,9 +3,9 @@
   "extends": "@tsconfig/node22/tsconfig.json",
   "compilerOptions": {
     "outDir": "dist",
-    "module": "preserve",
+    "module": "nodenext",
     "declaration": true,
-    "moduleResolution": "bundler",
+    "moduleResolution": "nodenext",
     "lib": [
       "es2022",
       "dom",