Skip to content

Commit b628def

Browse files
authored
Dont use require() for imports in TS files (#1665)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Replace `require()` with `import` for `ThrowIfVersionMismatch` in TypeScript files and update comments for upgrade guidance. > > - **Imports**: > - Replace `require()` with `import` for `ThrowIfVersionMismatch` in `index.ts.j2`, `react/baml_client/index.ts`, and `typescript/baml_client/index.ts`. > - **Error Handling**: > - Remove error handling for `require()` failures, as `import` will handle this. > - **Comments**: > - Add comments in all files to guide users on upgrading `@boundaryml/baml` if import fails. > > <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 295be65. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent f503cdc commit b628def

3 files changed

Lines changed: 54 additions & 87 deletions

File tree

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

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
1-
export const version = "{{ version }}";
2-
1+
/**
2+
* If this import fails, you may need to upgrade @boundaryml/baml.
3+
*
4+
* Please upgrade @boundaryml/baml to {{version}}.
5+
*
6+
* $ npm install @boundaryml/baml@{{version}}
7+
* $ yarn add @boundaryml/baml@{{version}}
8+
* $ pnpm add @boundaryml/baml@{{version}}
9+
*
10+
* If nothing else works, please ask for help:
11+
*
12+
* https://github.com/boundaryml/baml/issues
13+
* https://boundaryml.com/discord
14+
*
15+
**/
16+
import { ThrowIfVersionMismatch } from "@boundaryml/baml";
317

4-
let ThrowIfVersionMismatch: (version: string) => void;
5-
try {
6-
ThrowIfVersionMismatch = require("@boundaryml/baml").ThrowIfVersionMismatch;
7-
} catch (error) {
8-
9-
}
18+
export const version = "{{ version }}";
1019

11-
if (ThrowIfVersionMismatch) {
12-
ThrowIfVersionMismatch(version);
13-
} else {
14-
// You're probably using a different version of baml.
15-
// Please upgrade to the version used by generators.baml.
16-
const errorMessage = `Update to @boundaryml/baml required.
17-
Version of index.ts.j2 (see generators.baml): ${version}
18-
19-
Please upgrade @boundaryml/baml to ${version}.
20-
21-
$ npm install @boundaryml/baml@${version}
22-
$ yarn add @boundaryml/baml@${version}
23-
$ pnpm add @boundaryml/baml@${version}
24-
25-
If nothing else works, please ask for help:
26-
27-
https://github.com/boundaryml/baml/issues
28-
https://boundaryml.com/discord`;
29-
30-
throw new Error(errorMessage.trim());
31-
}
20+
ThrowIfVersionMismatch(version);
3221

3322

3423
{% if default_client_mode == GeneratorDefaultClientMode::Async %}

integ-tests/react/baml_client/index.ts

Lines changed: 18 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integ-tests/typescript/baml_client/index.ts

Lines changed: 18 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)