Skip to content

Commit ad5d8a2

Browse files
authored
Merge pull request #64 from 2fd/fix/add-support-for-cloudflare
fix: add support for cloudflare worker
2 parents d72d7f2 + 273a3d2 commit ad5d8a2

14 files changed

+2695
-25
lines changed

.github/workflows/pull_request.yml

+31-2
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ jobs:
117117

118118
strategy:
119119
matrix:
120-
version: ["v1.x"]
120+
version: ["1.x"]
121121

122122
steps:
123123
- uses: actions/checkout@v4
124124

125125
- name: Run denoland/setup-deno@v1 (${{ matrix.version }})
126126
uses: denoland/setup-deno@v1
127127
with:
128-
deno-version: ${{ matrix.version }}
128+
deno-version: "v${{ matrix.version }}"
129129

130130
- uses: actions/download-artifact@v4
131131
with:
@@ -135,3 +135,32 @@ jobs:
135135
- run: deno run --allow-read=lib/rregex.wasm lib/esm.mjs
136136

137137
- run: deno test --allow-read=lib/rregex.wasm test/deno.test.mjs
138+
139+
test_cf:
140+
runs-on: ubuntu-20.04
141+
142+
needs: build
143+
144+
strategy:
145+
matrix:
146+
version: ["3.x"]
147+
148+
steps:
149+
- uses: actions/checkout@v4
150+
151+
- name: Run actions/setup-node@v4
152+
uses: actions/setup-node@v4
153+
with:
154+
node-version: "20"
155+
registry-url: https://registry.npmjs.org/
156+
157+
- uses: actions/download-artifact@v4
158+
with:
159+
name: lib
160+
path: lib
161+
162+
- run: npm ci
163+
working-directory: ./test/cf
164+
165+
- run: npm test
166+
working-directory: ./test/cf

.github/workflows/release.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ jobs:
117117

118118
strategy:
119119
matrix:
120-
version: ["v1.x"]
120+
version: ["1.x"]
121121

122122
steps:
123123
- uses: actions/checkout@v4
124124

125125
- name: Run denoland/setup-deno@v1 (${{ matrix.version }})
126126
uses: denoland/setup-deno@v1
127127
with:
128-
deno-version: ${{ matrix.version }}
128+
deno-version: "v${{ matrix.version }}"
129129

130130
- uses: actions/download-artifact@v4
131131
with:
@@ -136,6 +136,35 @@ jobs:
136136

137137
- run: deno test --allow-read=lib/rregex.wasm test/deno.test.mjs
138138

139+
test_cf:
140+
runs-on: ubuntu-20.04
141+
142+
needs: build
143+
144+
strategy:
145+
matrix:
146+
version: ["3.x"]
147+
148+
steps:
149+
- uses: actions/checkout@v4
150+
151+
- name: Run actions/setup-node@v4
152+
uses: actions/setup-node@v4
153+
with:
154+
node-version: "20"
155+
registry-url: https://registry.npmjs.org/
156+
157+
- uses: actions/download-artifact@v4
158+
with:
159+
name: lib
160+
path: lib
161+
162+
- run: npm ci
163+
working-directory: ./test/cf
164+
165+
- run: npm test
166+
working-directory: ./test/cf
167+
139168
publish:
140169
runs-on: ubuntu-20.04
141170

@@ -149,6 +178,7 @@ jobs:
149178
- test_node
150179
- test_bun
151180
- test_deno
181+
- test_cf
152182

153183
steps:
154184
- uses: actions/checkout@v4

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ Rust has a powerful Regex library with a lot of features that don't exists en th
4747

4848
This package includes builds for multiple runtimes
4949

50-
| Runtime | Import |
51-
| ------------------ | ---------------------------------------------------- |
52-
| Node.js (esm) | `import { RRegex, RRegexSet } from 'rregex'` |
53-
| Node.js (commonjs) | `const { RRegex, RRegexSet } = require('rregex')` |
54-
| Deno | `import { RRegex, RRegexSet } from '@rregex/rregex'` |
55-
| Bun | `import { RRegex, RRegexSet } from '@rregex/rregex'` |
56-
| Cloudflare Workers | TODO |
57-
| Browser | TODO |
58-
| Standalone | TODO |
50+
| Runtime | Import | version |
51+
| ------------------ | ------------------------------------------------------- | ---------- |
52+
| Node.js (esm) | `import { RRegex, RRegexSet } from 'rregex'` | `*` |
53+
| Node.js (commonjs) | `const { RRegex, RRegexSet } = require('rregex')` | `*` |
54+
| Deno | `import { RRegex, RRegexSet } from '@rregex/rregex'` | `>=1.10.8` |
55+
| Bun | `import { RRegex, RRegexSet } from '@rregex/rregex'` | `>=1.10.8` |
56+
| Cloudflare Workers | `import { RRegex, RRegexSet } from 'rregex/lib/cf.mjs'` | `>=1.10.8` |
57+
| Browser | TODO | |
58+
| Standalone | TODO | |
5959

6060
## Known Issues
6161

bin/build.sh

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
echo " 🚀 Building..."
44
concurrently \
5-
-c "cyan,blue,green,yellow,red" \
6-
-n "std,web,cjs,esm,mod" \
5+
-c "cyan,blue,green,yellow" \
6+
-n "std,web,cjs,esm" \
77
"wasm-pack build -d lib_no_modules --release --target no-modules" \
88
"wasm-pack build -d lib_web --release --target web" \
99
"wasm-pack build -d lib_nodejs --release --target nodejs" \
10-
"wasm-pack build -d lib_bundler --release --target bundler" \
1110
"wasm-pack build -d lib_deno --release --target deno"
1211

1312
function replace() {
@@ -34,26 +33,37 @@ for t in lib_*/*.d.ts; do
3433
replace 's/matches(text: string): any\[\];/matches(text: string): number[];/g' $t
3534
done
3635

36+
echo " 📦 Bundling Cloudflare bundle..."
37+
mkdir -p lib_cf
38+
39+
echo '' > lib_cf/cf.mjs
40+
echo 'import wasm from "./rregex.wasm";' >> lib_cf/cf.mjs
41+
echo 'import { initSync } from "./web.js";' >> lib_cf/cf.mjs
42+
echo 'export * from "./web.js";' >> lib_cf/cf.mjs
43+
echo '' >> lib_cf/cf.mjs
44+
echo 'initSync(wasm);' >> lib_cf/cf.mjs
45+
echo '' >> lib_cf/cf.mjs
46+
3747
echo " 📝 Adding metadata..."
3848
node bin/medatata.mjs
3949

4050
echo " 🔨 Creating lib..."
4151
mkdir -p lib
4252
cp lib_web/rregex.js lib/web.js
53+
cp lib_web/rregex.d.ts lib/web.d.ts
54+
cp lib_web/rregex.d.ts lib/cf.d.ts
4355
cp lib_web/rregex.d.ts lib/types.d.ts
4456
cp lib_web/rregex_bg.wasm lib/rregex.wasm
4557
cp lib_web/rregex_bg.wasm.d.ts lib/rregex.wasm.d.ts
4658

59+
cp lib_cf/cf.mjs lib/cf.mjs
60+
4761
cp lib_nodejs/rregex.js lib/commonjs.cjs
4862
cp lib_nodejs/rregex.d.ts lib/commonjs.d.ts
4963

5064
cp lib_no_modules/rregex.js lib/standalone.js
5165
cp lib_no_modules/rregex.d.ts lib/standalone.d.ts
5266

53-
cp lib_bundler/rregex.js lib/bundler.mjs
54-
cp lib_bundler/rregex_bg.js lib/bundler_bg.mjs
55-
cp lib_bundler/rregex.d.ts lib/bundler.d.ts
56-
5767
cp lib_deno/rregex.d.ts lib/esm.d.ts
5868
echo -e "import { readFile } from \"node:fs/promises\";\n$(cat lib_deno/rregex.js)" > lib/esm.mjs
5969

@@ -66,17 +76,14 @@ replace 's/__wbindgen_placeholder__/wbg/g' lib/commonjs.cjs
6676
replace 's/\\\.js\$/standalone\\.js$/g' lib/standalone.js
6777
replace 's/_bg\.wasm/rregex.wasm/g' lib/standalone.js
6878

69-
replace 's/rregex_bg\.wasm/rregex.wasm/g' lib/bundler.mjs
70-
replace 's/rregex_bg\.js/bundler_bg.mjs/g' lib/bundler.mjs
71-
7279
replace 's/rregex_bg\.wasm/rregex.wasm/g' lib/esm.mjs
7380
replace 's/__wbindgen_placeholder__/wbg/g' lib/esm.mjs
7481
replace 's/Deno\.readFile/readFile/g' lib/esm.mjs
7582

7683
echo " 🧹 Removing build files..."
7784
rm -rf lib_web
7885
rm -rf lib_nodejs
79-
rm -rf lib_bundler
86+
rm -rf lib_cf
8087
rm -rf lib_deno
8188
rm -rf lib_no_modules
8289
if [[ "$OSTYPE" == "darwin"* ]]; then

bin/medatata.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ function append(path, data) {
2525
append(`./lib_web/rregex.d.ts`, `export const metadata: ${metadata}`)
2626
append(`./lib_web/rregex.js`, `export const metadata = ${metadata}`)
2727
append(`./lib_deno/rregex.js`, `export const metadata = ${metadata}`)
28-
append(`./lib_bundler/rregex.js`, `export const metadata = ${metadata}`)
28+
append(`./lib_cf/cf.mjs`, `export const metadata = ${metadata}`)
2929
append(`./lib_nodejs/commonjs.cjs`, `module.exports.metadata = ${metadata}`)

test/cf/.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = tab
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.yml]
12+
indent_style = space

0 commit comments

Comments
 (0)