aspida / aspida

TypeScript friendly HTTP client wrapper for the browser and node.js.

Home Page:https://github.com/aspida/aspida

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[@aspida/fetch]`aspida`コマンドが正常に動作しない

ueda-kio opened this issue · comments

Description

@aspida/fetchにおいてaspidaコマンドが正常に動作しません。
以下codesandboxにて再現を確認できます。
https://codesandbox.io/p/sandbox/yi-chang-aspida-build-test-ldfpvm

aspidaコマンドを走らせると$api.tsファイルが以下のように崩れた状態で生成されます。

import type { AspidaClient } from 'aspida'
import type { Methods as Methods0 } from './user/_uid'

const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
  const prefix = (baseURL === undefined ? 'http://localhost:3000/api/' : baseURL).replace(/\/$/, '')
  const PATH0 = '/user'


  return {
    user: {
      _uid: (val1: number | string) => {
        const prefix1 = `${PATH0}/${val1}`

        return {
            get: (option?: { config?: T | undefined } | undefined) =>
            fetch(prefix, prefix1,  GET, option).send(),
          $ get: (option?: { config?: T | undefined } | undefined) =>
            fetch(prefix, prefix1,  GET, option).send().then(r => r.body),
          $path: () => `${prefix}${prefix1}`
        }
      }
    }
  }
}

export type ApiInstance = ReturnType<typeof api>
export default api

Environment

  • Package version:
    • "@aspida/fetch": "^1.12.0",
    • "aspida": "^1.12.0",
    • "typescript": "5.0.4"
  • OS:
    • Linux
    • Windows
    • macOS
  • Node.js version:
    • node: v18.16.0
  • npm version:
    • pnpm: v8.4.0

Additional context

ほとんど同じ環境である以下codesandboxでは正常に動作することを確認できています。
https://codesandbox.io/p/sandbox/zheng-chang-aspida-build-test-l6gqt6

生成されたコード
import type { AspidaClient } from 'aspida'
import type { Methods as Methods0 } from './user/_uid'

const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
  const prefix = (baseURL === undefined ? 'http://localhost:3000/api/' : baseURL).replace(/\/$/, '')
  const PATH0 = '/user'
  const GET = 'GET'
  const PUT = 'PUT'

  return {
    user: {
      _uid: (val1: number | string) => {
        const prefix1 = `${PATH0}/${val1}`

        return {
          get: (option?: { config?: T | undefined } | undefined) =>
            fetch<Methods0['get']['resBody']>(prefix, prefix1, GET, option).json(),
          $get: (option?: { config?: T | undefined } | undefined) =>
            fetch<Methods0['get']['resBody']>(prefix, prefix1, GET, option).json().then(r => r.body),
          put: (option: { body: Methods0['put']['reqBody'], config?: T | undefined }) =>
            fetch<Methods0['put']['resBody']>(prefix, prefix1, PUT, option).json(),
          $put: (option: { body: Methods0['put']['reqBody'], config?: T | undefined }) =>
            fetch<Methods0['put']['resBody']>(prefix, prefix1, PUT, option).json().then(r => r.body),
          $path: () => `${prefix}${prefix1}`
        }
      }
    }
  }
}

export type ApiInstance = ReturnType<typeof api>
export default api

キャッシュ?を参照しているようにも見えますが、如何せんaspidaを触ってみたのが初めてなので具体の原因までは追えていません。ご確認よろしくお願いいたします。

ほぼ同様のコードが自動生成されます.
macOSです.

  • Package version:
    • @aspida/axios: ^1.12.0
    • axios: ^1.4.0
    • typescript: 5.1.6
  • Node.js version:
    • node: v20.2.0
    • npm: 9.6.6
commented

タブ文字を使うと発生する重大なバグでした
報告ありがとうございます
v1.13.0で修正しました