Skip to content

Commit

Permalink
add get-connect-fn resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 committed Mar 4, 2024
1 parent fabe289 commit a338548
Show file tree
Hide file tree
Showing 11 changed files with 731 additions and 451 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
32 changes: 5 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Connect to your Redis server using `cloudflare:sockets`.

This package is designed to work with Cloudflare Workers, but it can also be used in node.js thanks to the implementation of [`cloudflare:sockets` for node.js](https://github.com/Ethan-Arrowood/socket).

For next.js users, please see the [Next.js](#nextjs) section for extra configuration.
For next.js users, please see the [Node.js, Next.js local development](#nodejs-nextjs-local-development) section.

## Installation

Expand Down Expand Up @@ -50,34 +50,12 @@ const value = await redis.raw("GET", "foo");
console.log(value); // <Buffer 62 61 72>
```

### Node.js
### Node.js, Next.js local development

We import the node.js polyfill for `cloudflare:sockets` to make it work in node.js.
Please install the node.js polyfill for `cloudflare:sockets` to use this package in node.js.

```ts
import { createRedis } from "redis-on-workers";
import { connect } from "@arrowood.dev/socket";

const redis = createRedis({
url: "redis://<username>:<password>@<host>:<port>",
connectFn: connect,
});
```

### Next.js

We import the node.js polyfill for `cloudflare:sockets` only in development mode.

```ts
import { createRedis } from "redis-on-workers";

const redis = createRedis({
url: "redis://<username>:<password>@<host>:<port>",
connectFn:
process.env.NODE_ENV === "development"
? import("@arrowood.dev/socket").then((m) => m.connect)
: undefined,
});
```sh
npm install @arrowood.dev/socket
```

#### Extra webpack configuration for Next.js
Expand Down
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "redis-on-workers",
"version": "0.1.2",
"version": "0.2.0",
"description": "Connect to your Redis server using cloudflare:sockets",
"scripts": {
"build": "tsup",
"build": "swc src -d dist/esm --strip-leading-paths && swc src -d dist/cjs -C module.type=commonjs --strip-leading-paths && tsc --declaration --emitDeclarationOnly --declarationDir dist/types",
"test": "vitest"
},
"main": "dist/index.mjs",
Expand All @@ -13,11 +13,17 @@
"README.md",
"LICENSE"
],
"typings": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./": {
"types": "./dist/types/",
"import": "./dist/esm/",
"require": "./dist/cjs/"
},
"./package.json": "./package.json"
},
Expand All @@ -33,20 +39,24 @@
"name": "Kane",
"email": "[email protected]"
},
"type": "module",
"license": "MIT",
"devDependencies": {
"@arrowood.dev/socket": "^0.2.0",
"@cloudflare/workers-types": "^4.20240222.0",
"@swc/cli": "^0.3.10",
"@swc/core": "^1.4.2",
"@types/node": "^20.11.24",
"@types/redis-errors": "^1.2.3",
"@types/redis-parser": "^3.0.3",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"redis-errors": "^1.2.0",
"tsup": "^8.0.2",
"typescript": "^5.3.3",
"vitest": "^1.3.1"
},
"optionalDependencies": {
"@arrowood.dev/socket": "^0.2.0"
},
"dependencies": {
"@redis/client": "^1.5.14",
"redis-parser": "^3.0.0"
Expand Down
Loading

0 comments on commit a338548

Please sign in to comment.