Skip to content

Commit ad5c3de

Browse files
feat(scripts): enable hybrid builds using tsup
1 parent 26d3b0d commit ad5c3de

File tree

6 files changed

+1010
-238
lines changed

6 files changed

+1010
-238
lines changed

libs/langchain-scripts/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,54 @@ This package contains the LangChain.js shared scripts for our packages.
77
```bash npm2yarn
88
npm install @langchain/scripts
99
```
10+
11+
## Usage
12+
13+
### Build Script
14+
15+
The build script supports both traditional TypeScript compilation and modern tsup-based builds.
16+
17+
```bash
18+
npx lc_build
19+
```
20+
21+
#### Traditional TypeScript Build
22+
23+
By default, the build script uses TypeScript's compiler (tsc) to build both ESM and CJS versions of your package.
24+
25+
#### tsup-based Build
26+
27+
The build script can also use [tsup](https://github.com/egoist/tsup) (a zero-config TypeScript bundler powered by esbuild) which offers significant performance improvements (10-100x faster builds).
28+
29+
To migrate your package to use tsup:
30+
31+
```bash
32+
npx lc_build --migrate-build
33+
```
34+
35+
This command performs several migration steps:
36+
1. Creates a `tsup.config.ts` file with sensible defaults for LangChain packages
37+
2. Updates TypeScript to the latest version in your package.json
38+
3. Ensures your package.json has a `type-check` script
39+
4. Backs up the tsconfig.cjs.json file (which is no longer needed with tsup)
40+
5. Provides guidance on updating build scripts if needed
41+
42+
After migration, simply run the build script normally:
43+
44+
```bash
45+
npx lc_build
46+
```
47+
48+
The script will automatically detect the presence of a tsup configuration file and use it for building.
49+
50+
### Notebooks Type-Checking
51+
52+
```bash
53+
npx notebook_validate
54+
```
55+
56+
### Serialized Field Extraction
57+
58+
```bash
59+
npx extract_serializable_fields
60+
```

libs/langchain-scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"scripts": {
2323
"build": "yarn clean && yarn turbo:command build:internal --filter=@langchain/scripts",
2424
"build:internal": "tsc --project ./tsconfig.build.json && yarn move:artifacts && yarn build:generated",
25-
"move:artifacts": "rimraf dist && mkdir -p dist && mv dist_build/* dist/",
25+
"move:artifacts": "rimraf dist && mkdir -p dist && cp -r dist_build/* dist/ && mkdir -p dist/build && cp src/build/tsup.config.template.ts dist/build/",
2626
"build:generated": "node bin/build.js --create-entrypoints --pre --tree-shaking",
2727
"build:turbo": "yarn turbo:command build --filter=@langchain/scripts",
2828
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
@@ -52,6 +52,7 @@
5252
"rimraf": "^5.0.1",
5353
"rollup": "^4.5.2",
5454
"ts-morph": "^21.0.1",
55+
"tsup": "^8.4.0",
5556
"typescript": "^5.4.5"
5657
},
5758
"devDependencies": {

0 commit comments

Comments
 (0)