diff --git a/README.md b/README.md index 60d9ccd..db8fb99 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ For each **source** (a named API, e.g. `atlas`), under `//gener | `functions/**/*.ts` | Typed callers (`getWidgets`, …) | | `routes.ts` | `Routes` string map + `RouteTargets` enum (name configurable) | | `runtime.ts` | Re-exports `HTTPFetch`, `httpFetch` (if singleton), routes | -| `base.ts` | `BaseResponse` when the spec uses a response envelope | +| `base.ts` | `BaseResponse` when the spec uses a response envelope (or `base.d.ts` for split declaration output) | Optional: @@ -65,7 +65,7 @@ Prefer the `package.json` script above. To invoke the binary directly: | `init` | Scaffold `http.ts`, `source.ts`, `known-types.ts` | | `generate` | Write generated files | | `check` | Same as `generate --check` — exit 1 if output would change | -| `accept-base` | Update `generated/base.ts` and patch `models.ts` `BaseResponse` | +| `accept-base` | Update generated `base.ts` (`base.d.ts` for split declaration output) and patch `models.ts` `BaseResponse` | `--check` and `--accept-base` cannot be combined. See [docs/cli.md](docs/cli.md) for the full command reference. @@ -138,7 +138,7 @@ Re-exported types from the package root: | --- | --- | | `spec` | Project-relative spec path (used when no `--spec` / env override) | | `functionsDir` | Project-relative function output directory (defaults to the source's `generated/functions`) | -| `typesDir` | Project-relative type output directory (defaults to the source's `generated/types`; a generated `base.ts` is placed beside this directory when customized) | +| `typesDir` | Project-relative type output directory (defaults to the source's `generated/types`; a generated `base.d.ts` is placed beside this directory when customized) | | `pathPrefix` | Only generate operations under this prefix (e.g. `/api/acme/v3`) | | `ignorePaths` | Extra paths to skip | | `stripApiPrefix` | Strip a leading `/api` segment from route enum member names | @@ -178,7 +178,8 @@ Adapters implement `HTTPFetch` from `@openmirai/openapi-codegen/http` (or the ax ### 6. Path-alias aware imports Generated function files import types and `runtime`, and generated response -types import `base.ts`, using: +types import the generated base declaration (`base.ts` in monolith output, or +`base.d.ts` for split declaration output), using: 1. `importBase` in `source.ts`, if set 2. Else `compilerOptions.paths` from the nearest ancestor `tsconfig.json` with path aliases, starting at the corresponding `functionsDir` or `typesDir` diff --git a/src/emitters/types/index.ts b/src/emitters/types/index.ts index 862ae64..a047250 100644 --- a/src/emitters/types/index.ts +++ b/src/emitters/types/index.ts @@ -327,7 +327,9 @@ export function emitTypeFiles( const typeFile = `${options.typesDir}/${pathItem.cleanPath}/${operation.method.toUpperCase()}.d.ts`; const baseImportPath = resolveAliasAwareImport({ fromAbsolutePath: typeFile, - toAbsolutePath: options.baseFile.replace(/\.ts$/, ""), + toAbsolutePath: options.baseFile + .replace(/\.d\.ts$/, "") + .replace(/\.ts$/, ""), ...(options.tsconfigPaths === undefined ? {} : { tsconfigPaths: options.tsconfigPaths }), diff --git a/src/generate/index.ts b/src/generate/index.ts index 182afe8..5e3fd30 100644 --- a/src/generate/index.ts +++ b/src/generate/index.ts @@ -86,7 +86,7 @@ export function buildGenerateContext( baseFile: sourceConfig.typesDir === undefined ? join(generatedDir, "base.ts") - : join(dirname(typesDir), "base.ts"), + : join(dirname(typesDir), "base.d.ts"), cwd, functionsDir, generatedDir, diff --git a/test/integration/generate.test.ts b/test/integration/generate.test.ts index 0a9cc4c..fb722a1 100644 --- a/test/integration/generate.test.ts +++ b/test/integration/generate.test.ts @@ -118,7 +118,8 @@ describe("integration: monolith generate", () => { await generateForSource({ cwd: root, sourceKey: "core" }); - expect(existsSync(join(typesDir, "../base.ts"))).toBe(true); + expect(existsSync(join(typesDir, "../base.d.ts"))).toBe(true); + expect(existsSync(join(typesDir, "../base.ts"))).toBe(false); expect(existsSync(join(typesDir, "api/acme/v3/widgets/GET.d.ts"))).toBe( true );