Skip to content

Commit

Permalink
Add support for Cloudflare Workers and Bun (#3)
Browse files Browse the repository at this point in the history
* Implement experimental support for Cloudflare Workers

* Implement experimental support for Bun

* Add sample app for Bun

* Add sample app for Cloudflare Workers

* Remove proxy from common client options

* Improve debug logging

* Update README.md

* Bump version

* npm audit fix

* Temporary disable tests on ubuntu-latest and macOS-latest for Bun
  • Loading branch information
adams85 authored Nov 21, 2024
1 parent 9e67406 commit c6ff3d5
Show file tree
Hide file tree
Showing 105 changed files with 2,077 additions and 11,225 deletions.
109 changes: 77 additions & 32 deletions .github/workflows/js-sdk-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,6 @@ jobs:
- name: Run check
run: npm run check:ts-compat

test-node:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x, 22.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
exclude:
- node-version: 14.x
os: macOS-latest
name: Node.js ${{ matrix.node-version }} (${{ matrix.os }}) test
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies & build
run: npm install

- name: Test
run: npm run test:node

test-browser-chrome:
runs-on: ubuntu-latest
strategy:
Expand All @@ -62,7 +39,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Setup chrome
uses: browser-actions/setup-chrome@latest
Expand All @@ -86,7 +63,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Setup chrome
uses: browser-actions/setup-chrome@latest
Expand All @@ -110,7 +87,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Setup firefox
uses: browser-actions/setup-firefox@latest
Expand All @@ -123,6 +100,30 @@ jobs:
- name: Test
run: npm run test:browser:firefox

test-bun:
runs-on: ${{ matrix.os }}
strategy:
matrix:
bun-version: ["1.1.0", "1.1.34"]
# Bun fails to run tests on ubuntu-latest and macOS-latest.
# It may not be possible at all for now: https://github.com/oven-sh/bun/issues/10001
# Bun version "latest" (1.1.36) seems to have a regression,
# so we use 1.1.34 until it fixed.
os: [windows-latest]
name: Bun ${{ matrix.bun-version }} (${{ matrix.os }}) test
steps:
- uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ matrix.bun-version }}

- name: Install dependencies & build
run: npm install

- name: Test
run: npm run test:bun

test-chromium-extension-chrome:
runs-on: ubuntu-latest
strategy:
Expand All @@ -134,7 +135,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Setup chrome
uses: browser-actions/setup-chrome@latest
Expand All @@ -158,7 +159,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Setup chrome
uses: browser-actions/setup-chrome@latest
Expand All @@ -171,6 +172,25 @@ jobs:
- name: Test
run: CHROMIUM_BIN=$(which chrome) npm run test:chromium-extension:chromium

test-cloudflare-worker:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
name: Cloudflare Worker (${{ matrix.os }}) test
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 18

- name: Install dependencies & build
run: npm install

- name: Test
run: npm run test:cloudflare-worker

test-deno:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -196,13 +216,38 @@ jobs:
- name: Test
run: npm run test:deno

test-node:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x, 22.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
exclude:
- node-version: 14.x
os: macOS-latest
name: Node.js ${{ matrix.node-version }} (${{ matrix.os }}) test
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies & build
run: npm install

- name: Test
run: npm run test:node

coverage:
needs: [
check-ts-compat,
test-node,
test-browser-chrome, test-browser-chromium, test-browser-firefox,
test-bun,
test-chromium-extension-chrome, test-chromium-extension-chromium,
test-deno
test-cloudflare-worker,
test-deno,
test-node
]
runs-on: ubuntu-latest
steps:
Expand All @@ -211,7 +256,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Install dependencies & build
run: npm install
Expand Down Expand Up @@ -240,7 +285,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ lib/
dist/
.idea/
.parcel-cache/
bun.lockb
deno.lock
deno.import-map.json
deno.import-map.json
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ lib/**/*.map
test/
tsconfig*.json
types/
webpack.*.config.js
webpack.*.config.js
workerd.config.capnp
58 changes: 39 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,45 @@
"/base/": "${workspaceRoot}/"
}
},
{
// This configuration needs the `oven.bun-vscode` extension to be installed.
"type": "bun",
"name": "Run tests (Bun)",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtime": "bun",
"runtimeArgs": ["--tsconfig-override ./tsconfig.mocha.bun.json"],
"program": "./node_modules/mocha/bin/mocha.js",
"args": [
"test/bun/index.ts",
"--fgrep",
"",
"--color",
"--exit",
"--timeout",
"30000"
],
"noDebug": false,
},
{
"type": "node",
"name": "Run tests (Deno)",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--inspect",
"-A",
"test/deno/index.ts",
"--fgrep",
"",
"--timeout",
"30000"
],
"attachSimplePort": 9229,
"outputCapture": "std"
},
{
"type": "node",
"request": "launch",
Expand Down Expand Up @@ -62,25 +101,6 @@
"skipFiles": [
"<node_internals>/**/*.js"
]
},
{
"type": "node",
"name": "Run tests (Deno)",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--inspect-brk",
"-A",
"test/deno/index.ts",
"--fgrep",
"",
"--timeout",
"30000"
],
"attachSimplePort": 9229,
"outputCapture": "std"
}
]
}
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@

ConfigCat SDK for JavaScript provides easy integration for your application to [ConfigCat](https://configcat.com).

This repository hosts the next generation of the ConfigCat SDK for JavaScript platforms. It ships in the form of a single, unified NPM package for
different JS platforms, as opposed to the one package per platform model used before.

The new SDK combines and, thus, supersedes these packages:
* [configcat-common](https://www.npmjs.com/package/configcat-common)
* [configcat-js](https://www.npmjs.com/package/configcat-js)
* [configcat-js-ssr](https://www.npmjs.com/package/configcat-js-ssr)
* [configcat-js-chromium-extension](https://www.npmjs.com/package/configcat-js-chromium-extension)
* [configcat-node](https://www.npmjs.com/package/configcat-node)

The new SDK maintains backward compatibility, so it can be used as a drop-in replacement for the packages listed above. In most cases you just need to
replace the old package with the new and adjust the import specifiers (as shown [here](#1-install-and-import-package)).

> [!CAUTION]
> Please note that the SDK is still under development and is currently in beta phase. Use it at your own risk.
## Getting Started

### 1. Install and import package:
Expand All @@ -25,7 +41,7 @@ npm i @configcat/sdk

Then import it into your application:

* Frontend applications running in the browser:
* Frontend applications and Web Workers running in the browser:
```js
import * as configcat from "@configcat/sdk/browser";
```
Expand All @@ -35,13 +51,23 @@ Then import it into your application:
import * as configcat from "@configcat/sdk/node";
```

* Bun backend applications:
```js
import * as configcat from "@configcat/sdk/bun";
```

* Deno backend applications:
```js
import * as configcat from "npm:@configcat/sdk/deno";
```

(To make this work, you may need to enable the [unstable-byonm](https://docs.deno.com/runtime/manual/tools/unstable_flags/#--unstable-byonm) feature or adjust your [import map](https://docs.deno.com/runtime/manual/basics/import_maps/).)

* Cloudflare Workers:
```js
import * as configcat from "@configcat/sdk/cloudflare-worker";
```

* Extensions for Chromium-based browsers (Chrome, Edge, etc.):
```js
import * as configcat from "@configcat/sdk/chromium-extension";
Expand All @@ -53,7 +79,7 @@ Then import it into your application:

Import the package directly from a CDN server into your application:

* Frontend applications running in the browser:
* Frontend applications and Web Workers running in the browser:

```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@configcat/sdk@latest/dist/configcat.browser.umd.min.js"></script>
Expand All @@ -74,7 +100,7 @@ Import the package directly from a CDN server into your application:
```

### 2. Go to the <a href="https://app.configcat.com/sdkkey" target="_blank">ConfigCat Dashboard</a> to get your *SDK Key*:
![SDK-KEY](https://raw.githubusercontent.com/ConfigCat/js-sdk/master/media/readme02-3.png "SDK-KEY")
![SDK-KEY](https://raw.githubusercontent.com/configcat/js-unified-sdk/master/media/readme02-3.png "SDK-KEY")

### 3. Create a *ConfigCat* client instance:
```js
Expand Down Expand Up @@ -131,7 +157,7 @@ if (value) {
## Sample/Demo apps
- [Plain HTML + JS](https://github.com/configcat/js-unified-sdk/tree/master/samples/html)
- [Plain HTML + JS using ECMAScript module system](https://github.com/configcat/js-unified-sdk/tree/master/samples/html-esm)
- [Plain HTML + bundled TS running the SDK in a Web Worker](https://github.com/configcat/js-unified-sdk/tree/master/samples/web-worker)
- [Plain HTML + TS running the SDK in a Web Worker](https://github.com/configcat/js-unified-sdk/tree/master/samples/web-worker)
- [Sample Angular web application](https://github.com/configcat/js-unified-sdk/tree/master/samples/angular-sample)
- [Sample React web application](https://github.com/configcat/js-unified-sdk/tree/master/samples/react-sample)
- [Sample React Native application](https://github.com/configcat/js-unified-sdk/tree/master/samples/react-native-sample)
Expand All @@ -142,7 +168,9 @@ if (value) {
- [Sample Node.js console application using TypeScript and ECMAScript module system](https://github.com/configcat/js-unified-sdk/tree/master/samples/ts-node-console-esm)
- [Sample Node.js application using Express and Docker](https://github.com/configcat/js-unified-sdk/tree/master/samples/node-expresswithdocker)
- [Sample Node.js application on how to get real time updates on feature flag changes](https://github.com/configcat/js-unified-sdk/tree/master/samples/node-realtimeupdate)
- [Sample Bun console application](https://github.com/configcat/js-unified-sdk/tree/master/samples/bun-console)
- [Sample Deno console application](https://github.com/configcat/js-unified-sdk/tree/master/samples/deno-console)
- [Sample Cloudflare Worker](https://github.com/configcat/js-unified-sdk/tree/master/samples/cloudflare-worker)
- [Sample Chrome extension](https://github.com/configcat/js-unified-sdk/tree/master/samples/chrome-extension)

## Polling Modes
Expand Down Expand Up @@ -193,13 +221,17 @@ The SDK is [tested](https://github.com/configcat/js-unified-sdk/blob/master/.git
- Chrome (stable, latest, beta)
- Chromium (64.0.3282.0, 72.0.3626.0, 80.0.3987.0)
- Firefox (latest, latest-beta, 84.0)
- @configcat/sdk/chromium-extension:
- Chrome (stable, latest, beta)
- Chromium (72.0.3626.0, 80.0.3987.0)
- @configcat/sdk/bun:
- Bun (v1.1.0, v1.1.34) on Windows
- @configcat/sdk/deno:
- Deno (v1.31, v1.46, latest stable) on Windows / Ubuntu / macOS
- @configcat/sdk/node:
- Node.js (v14.x, v16.x, v18.x, v20.x, v22.x) on Windows / Ubuntu / macOS
- @configcat/sdk/cloudflare-worker:
- Workerd (2023-02-28)
- @configcat/sdk/chromium-extension:
- Chrome (stable, latest, beta)
- Chromium (72.0.3626.0, 80.0.3987.0)

The SDK should be compatible with TypeScript v4.0.2 or newer. Earlier versions may work but those are not tested, thus, not supported officially.

Expand Down
Binary file added media/readme02-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c6ff3d5

Please sign in to comment.