Skip to content

Commit 74b3dbf

Browse files
authored
fix: react codegen (#1490)
There was an issue where we were failing to generate on the second save. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fixes BAML client generation issue by ensuring only BAML-generated files are removed and critical directories are preserved. > > - **Behavior**: > - Fixes issue with failing to generate on the second save by ensuring only BAML-generated files are removed. > - Updates `checkDirectorySafety` function in `baml_project_manager.ts` to include critical directories that should not be removed. > - Modifies logic to check if files are generated by BAML before removal. > - **Imports**: > - Removes unused imports like `access`, `exec`, `debounce`, and `semver` from `baml_project_manager.ts`. > - **Misc**: > - Updates version in `01-quick-start.mdx` and `generator.mdx` from `0.75.0` to `0.76.2`. > - Changes `catch (error: any)` to `catch (error)` in multiple files for better error handling. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for ff639ab. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 4e6368c commit 74b3dbf

File tree

13 files changed

+573
-489
lines changed

13 files changed

+573
-489
lines changed

engine/language_client_codegen/src/typescript/templates/async_client.ts.j2

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image, ClientRegistry, toBamlError, Audio } from "@boundaryml/baml"
2-
import { Checked, Check, RecursivePartialNull as MovedRecursivePartialNull } from "./types"
1+
import type { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image, ClientRegistry, toBamlError, Audio } from "@boundaryml/baml"
2+
import { toBamlError } from "@boundaryml/baml"
3+
import type { Checked, Check, RecursivePartialNull as MovedRecursivePartialNull } from "./types"
34
import type { partial_types } from "./partial_types"
4-
import {
5+
import type * as types from "./types"
6+
import type {
57
{%- for t in types %}{{ t }}{% if !loop.last %}, {% endif %}{% endfor -%}
68
} from "./types"
7-
import * as types from "./types"
89
import type TypeBuilder from "./type_builder"
910
import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME } from "./globals"
1011

@@ -48,7 +49,7 @@ export class BamlAsyncClient {
4849
__baml_options__?.clientRegistry,
4950
)
5051
return raw.parsed(false) as {{fn.return_type}}
51-
} catch (error: any) {
52+
} catch (error) {
5253
throw toBamlError(error);
5354
}
5455
}

engine/language_client_codegen/src/typescript/templates/react/hooks.tsx.j2

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function useBamlAction<FunctionName extends FunctionNames>(
290290
throw error_
291291
}
292292
},
293-
[action, props.stream, onFinalData, onError],
293+
[action, onFinalData, onError, props],
294294
)
295295

296296
const status = useMemo<HookStatus<{ stream: typeof props.stream }>>(() => {
@@ -301,7 +301,10 @@ function useBamlAction<FunctionName extends FunctionNames>(
301301
return 'idle'
302302
}, [isLoading, state.error, state.isSuccess, state.isStreaming])
303303

304-
let data = state.finalData
304+
let data:
305+
| FinalDataType<FunctionName>
306+
| StreamDataType<FunctionName>
307+
| undefined = state.finalData;
305308
if (state.isStreaming) data = state.streamData
306309

307310
const result = {

engine/language_client_codegen/src/typescript/templates/sync_client.ts.j2

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { BamlRuntime, FunctionResult, BamlCtxManager, Image, Audio, ClientRegistry, toBamlError } from "@boundaryml/baml"
2-
import { Checked, Check, RecursivePartialNull as MovedRecursivePartialNull } from "./types"
3-
import * as types from "./types"
4-
import {
1+
import type { BamlRuntime, FunctionResult, BamlCtxManager, Image, Audio, ClientRegistry } from "@boundaryml/baml"
2+
import { toBamlError } from "@boundaryml/baml"
3+
import type { Checked, Check, RecursivePartialNull as MovedRecursivePartialNull } from "./types"
4+
import type * as types from "./types"
5+
import type {
56
{%- for t in types %}{{ t }}{% if !loop.last %}, {% endif %}{% endfor -%}
67
} from "./types"
78
import type TypeBuilder from "./type_builder"

engine/language_client_ruby/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
baml (0.75.0)
4+
baml (0.76.2)
55

66
GEM
77
remote: https://rubygems.org/

fern/01-guide/08-frameworks/01-react-nextjs/01-quick-start.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ generator typescript {
185185
- output_type "typescript"
186186
+ output_type "typescript/react"
187187
output_dir "../"
188-
version "0.75.0"
188+
version "0.76.2"
189189
}
190190
```
191191

fern/03-reference/generator.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ generator target {
2323
default_client_mode "sync"
2424
2525
// Version of runtime to generate code for (should match installed baml-py version)
26-
version "0.75.0"
26+
version "0.76.2"
2727
}
2828
```
2929

@@ -40,7 +40,7 @@ generator target {
4040
default_client_mode "async"
4141
4242
// Version of runtime to generate code for (should match the package @boundaryml/baml version)
43-
version "0.75.0"
43+
version "0.76.2"
4444
}
4545
```
4646

@@ -57,7 +57,7 @@ generator target {
5757
default_client_mode "async"
5858

5959
// Version of runtime to generate code for (should match the package @boundaryml/baml version)
60-
version "0.75.0"
60+
version "0.76.2"
6161
}
6262
```
6363

@@ -69,7 +69,7 @@ generator target {
6969
output_dir "../"
7070
7171
// Version of runtime to generate code for (should match installed `baml` package version)
72-
version "0.75.0"
72+
version "0.76.2"
7373
}
7474
```
7575

@@ -81,7 +81,7 @@ generator target {
8181
output_dir "../"
8282
8383
// Version of runtime to generate code for (should match installed `baml` package version)
84-
version "0.54.0"
84+
version "0.76.2"
8585
8686
// 'baml-cli generate' will run this after generating openapi.yaml, to generate your OpenAPI client
8787
// This command will be run from within $output_dir

0 commit comments

Comments
 (0)