Skip to content

Commit ffbb2da

Browse files
stainless-app[bot]RobertCraigie
authored andcommitted
chore(client): drop support for EOL node versions
1 parent caab783 commit ffbb2da

File tree

11 files changed

+30
-137
lines changed

11 files changed

+30
-137
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Node
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: '18'
22+
node-version: '20'
2323

2424
- name: Bootstrap
2525
run: ./scripts/bootstrap
@@ -40,7 +40,7 @@ jobs:
4040
- name: Set up Node
4141
uses: actions/setup-node@v4
4242
with:
43-
node-version: '18'
43+
node-version: '20'
4444

4545
- name: Bootstrap
4646
run: ./scripts/bootstrap
@@ -72,7 +72,7 @@ jobs:
7272
- name: Set up Node
7373
uses: actions/setup-node@v4
7474
with:
75-
node-version: '18'
75+
node-version: '20'
7676

7777
- name: Bootstrap
7878
run: ./scripts/bootstrap

MIGRATION.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ To preview the changes without writing them to disk, run the tool with `--dry`.
1414

1515
The minimum supported runtime and tooling versions are now:
1616

17-
- Node.js 18.x last LTS (Required for builtin fetch support)
18-
- This was previously documented as the minimum supported Node.js version but Node.js 16.x mostly worked at runtime; now it will not.
17+
- Node.js 20 LTS (Most recent non-EOL Node version)
1918
- TypeScript 4.9
2019
- Jest 28
2120

@@ -298,7 +297,7 @@ To resolve these issues, configure your tsconfig.json and install the appropriat
298297
```json
299298
{
300299
"devDependencies": {
301-
"@types/node": ">= 18.18.7"
300+
"@types/node": ">= 20"
302301
}
303302
}
304303
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ TypeScript >= 4.9 is supported.
593593

594594
The following runtimes are supported:
595595

596-
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
596+
- Node.js 20 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
597597
- Deno v1.28.0 or higher.
598598
- Bun 1.0 or later.
599599
- Cloudflare Workers.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
"resolutions": {
5050
"synckit": "0.8.8"
5151
},
52-
"browser": {
53-
"./internal/shims/getBuiltinModule.mjs": "./internal/shims/nullGetBuiltinModule.mjs",
54-
"./internal/shims/getBuiltinModule.js": "./internal/shims/nullGetBuiltinModule.js"
55-
},
5652
"imports": {
5753
"@anthropic-ai/sdk": ".",
5854
"@anthropic-ai/sdk/*": "./src/*"
@@ -75,5 +71,8 @@
7571
"import": "./dist/*.mjs",
7672
"require": "./dist/*.js"
7773
}
74+
},
75+
"engines": {
76+
"node": ">= 20"
7877
}
7978
}

src/internal/shims/crypto.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/internal/shims/file.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/internal/shims/getBuiltinModule.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/internal/shims/nullGetBuiltinModule.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/internal/to-file.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type File, getFile } from './shims/file';
21
import { BlobPart, getName, makeFile, isAsyncIterable } from './uploads';
32
import type { FilePropertyBag } from './builtin-types';
3+
import { checkFileSupport } from './uploads';
44

55
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
66

@@ -85,12 +85,14 @@ export async function toFile(
8585
name?: string | null | undefined,
8686
options?: FilePropertyBag | undefined,
8787
): Promise<File> {
88+
checkFileSupport();
89+
8890
// If it's a promise, resolve it.
8991
value = await value;
9092

9193
// If we've been given a `File` we don't need to do anything
9294
if (isFileLike(value)) {
93-
if (value instanceof getFile()) {
95+
if (value instanceof File) {
9496
return value;
9597
}
9698
return makeFile([await value.arrayBuffer()], value.name);

src/internal/uploads.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { type RequestOptions } from './request-options';
22
import type { FilePropertyBag, Fetch } from './builtin-types';
33
import type { BaseAnthropic } from '../client';
4-
import { type File, getFile } from './shims/file';
54
import { ReadableStreamFrom } from './shims';
65

76
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
@@ -12,6 +11,20 @@ interface BunFile extends Blob {
1211
readonly name?: string | undefined;
1312
}
1413

14+
export const checkFileSupport = () => {
15+
if (typeof File === 'undefined') {
16+
const { process } = globalThis as any;
17+
const isOldNode =
18+
typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
19+
throw new Error(
20+
'`File` is not defined as a global, which is required for file uploads.' +
21+
(isOldNode ?
22+
" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
23+
: ''),
24+
);
25+
}
26+
};
27+
1528
/**
1629
* Typically, this is a native "File" class.
1730
*
@@ -32,7 +45,7 @@ export function makeFile(
3245
fileName: string | undefined,
3346
options?: FilePropertyBag,
3447
): File {
35-
const File = getFile();
48+
checkFileSupport();
3649
return new File(fileBits as any, fileName ?? 'unknown_file', options);
3750
}
3851

@@ -125,8 +138,7 @@ export const createForm = async <T = Record<string, unknown>>(
125138

126139
// We check for Blob not File because Bun.File doesn't inherit from File,
127140
// but they both inherit from Blob and have a `name` property at runtime.
128-
const isNamedBlob = (value: object) =>
129-
value instanceof getFile() || (value instanceof Blob && 'name' in value);
141+
const isNamedBlob = (value: object) => value instanceof Blob && 'name' in value;
130142

131143
const isUploadable = (value: unknown) =>
132144
typeof value === 'object' &&

0 commit comments

Comments
 (0)