Skip to content

Commit 0d7b066

Browse files
authored
Support cloudflare worker
1 parent f81921a commit 0d7b066

18 files changed

+4042
-0
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.eslintrc.cjs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const { defineConfig } = require('eslint-define-config')
2+
3+
module.exports = defineConfig({
4+
root: true,
5+
extends: [
6+
'eslint:recommended',
7+
'plugin:node/recommended',
8+
'plugin:@typescript-eslint/recommended',
9+
'prettier',
10+
],
11+
parser: '@typescript-eslint/parser',
12+
parserOptions: {
13+
sourceType: 'module',
14+
ecmaVersion: 2021,
15+
},
16+
plugins: ['@typescript-eslint', 'import'],
17+
globals: {
18+
fetch: false,
19+
Response: false,
20+
Request: false,
21+
addEventListener: false,
22+
},
23+
rules: {
24+
quotes: ['error', 'single'],
25+
semi: ['error', 'never'],
26+
'no-debugger': ['error'],
27+
'no-empty': ['warn', { allowEmptyCatch: true }],
28+
'no-process-exit': 'off',
29+
'no-useless-escape': 'off',
30+
'prefer-const': [
31+
'warn',
32+
{
33+
destructuring: 'all',
34+
},
35+
],
36+
'@typescript-eslint/ban-types': [
37+
'error',
38+
{
39+
types: {
40+
Function: false,
41+
},
42+
},
43+
],
44+
'sort-imports': 0,
45+
'import/order': [2, { alphabetize: { order: 'asc' } }],
46+
47+
'node/no-missing-import': 'off',
48+
'node/no-missing-require': 'off',
49+
'node/no-deprecated-api': 'off',
50+
'node/no-unpublished-import': 'off',
51+
'node/no-unpublished-require': 'off',
52+
'node/no-unsupported-features/es-syntax': 'off',
53+
54+
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
55+
'@typescript-eslint/no-empty-interface': 'off',
56+
'@typescript-eslint/no-inferrable-types': 'off',
57+
'@typescript-eslint/no-var-requires': 'off',
58+
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
59+
},
60+
})

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: ['metrue']

.github/workflows/ci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: ci
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: ['*']
7+
8+
jobs:
9+
ci:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [18.x, 20.x]
15+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- run: yarn install --frozen-lockfile
24+
- run: yarn run lint
25+
- name: 'Test'
26+
run: npx vitest --coverage.enabled true --run
27+
- name: 'Report Coverage'
28+
if: always()
29+
uses: davelosert/vitest-coverage-report-action@v2

.gitignore

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Logs
2+
3+
logs
4+
_.log
5+
npm-debug.log_
6+
yarn-debug.log*
7+
yarn-error.log*
8+
lerna-debug.log*
9+
.pnpm-debug.log*
10+
11+
# Diagnostic reports (https://nodejs.org/api/report.html)
12+
13+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
14+
15+
# Runtime data
16+
17+
pids
18+
_.pid
19+
_.seed
20+
\*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
24+
lib-cov
25+
26+
# Coverage directory used by tools like istanbul
27+
28+
coverage
29+
\*.lcov
30+
31+
# nyc test coverage
32+
33+
.nyc_output
34+
35+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
36+
37+
.grunt
38+
39+
# Bower dependency directory (https://bower.io/)
40+
41+
bower_components
42+
43+
# node-waf configuration
44+
45+
.lock-wscript
46+
47+
# Compiled binary addons (https://nodejs.org/api/addons.html)
48+
49+
build/Release
50+
51+
# Dependency directories
52+
53+
node_modules/
54+
jspm_packages/
55+
56+
# Snowpack dependency directory (https://snowpack.dev/)
57+
58+
web_modules/
59+
60+
# TypeScript cache
61+
62+
\*.tsbuildinfo
63+
64+
# Optional npm cache directory
65+
66+
.npm
67+
68+
# Optional eslint cache
69+
70+
.eslintcache
71+
72+
# Optional stylelint cache
73+
74+
.stylelintcache
75+
76+
# Microbundle cache
77+
78+
.rpt2_cache/
79+
.rts2_cache_cjs/
80+
.rts2_cache_es/
81+
.rts2_cache_umd/
82+
83+
# Optional REPL history
84+
85+
.node_repl_history
86+
87+
# Output of 'npm pack'
88+
89+
\*.tgz
90+
91+
# Yarn Integrity file
92+
93+
.yarn-integrity
94+
95+
# dotenv environment variable files
96+
97+
.env
98+
.env.development.local
99+
.env.test.local
100+
.env.production.local
101+
.env.local
102+
103+
# parcel-bundler cache (https://parceljs.org/)
104+
105+
.cache
106+
.parcel-cache
107+
108+
# Next.js build output
109+
110+
.next
111+
out
112+
113+
# Nuxt.js build / generate output
114+
115+
.nuxt
116+
dist
117+
118+
# Gatsby files
119+
120+
.cache/
121+
122+
# Comment in the public line in if your project uses Gatsby and not Next.js
123+
124+
# https://nextjs.org/blog/next-9-1#public-directory-support
125+
126+
# public
127+
128+
# vuepress build output
129+
130+
.vuepress/dist
131+
132+
# vuepress v2.x temp and cache directory
133+
134+
.temp
135+
.cache
136+
137+
# Docusaurus cache and generated files
138+
139+
.docusaurus
140+
141+
# Serverless directories
142+
143+
.serverless/
144+
145+
# FuseBox cache
146+
147+
.fusebox/
148+
149+
# DynamoDB Local files
150+
151+
.dynamodb/
152+
153+
# TernJS port file
154+
155+
.tern-port
156+
157+
# Stores VSCode versions used for testing VSCode extensions
158+
159+
.vscode-test
160+
161+
# yarn v2
162+
163+
.yarn/cache
164+
.yarn/unplugged
165+
.yarn/build-state.yml
166+
.yarn/install-state.gz
167+
.pnp.\*
168+
169+
# wrangler project
170+
171+
.dev.vars
172+
.wrangler/

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"printWidth": 100,
3+
"trailingComma": "es5",
4+
"tabWidth": 2,
5+
"semi": false,
6+
"singleQuote": true,
7+
"jsxSingleQuote": true,
8+
"endOfLine": "lf"
9+
}

package.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "yo",
3+
"version": "0.0.0",
4+
"devDependencies": {
5+
"@cloudflare/workers-types": "^4.20240117.0",
6+
"@types/crypto-js": "^4.1.1",
7+
"@types/glob": "^8.0.0",
8+
"@types/jest": "^29.0.2",
9+
"@types/node": "^17.0.29",
10+
"@typescript-eslint/eslint-plugin": "^5.21.0",
11+
"@typescript-eslint/parser": "^5.21.0",
12+
"@vitest/coverage-v8": "^1.2.2",
13+
"eslint-config-prettier": "^8.5.0",
14+
"eslint-define-config": "^1.4.0",
15+
"eslint-import-resolver-typescript": "^2.7.1",
16+
"eslint-plugin-eslint-comments": "^3.2.0",
17+
"eslint-plugin-flowtype": "^8.0.3",
18+
"eslint-plugin-import": "^2.26.0",
19+
"eslint-plugin-node": "^11.1.0",
20+
"typescript": "^5.3.3",
21+
"vite": "^5.0.12",
22+
"vitest": "^1.2.2",
23+
"wrangler": "3.25.0"
24+
},
25+
"private": true,
26+
"scripts": {
27+
"start": "http_proxy='' https_proxy='' wrangler dev",
28+
"deploy": "http_proxy='' https_proxy='' wrangler deploy",
29+
"test:watch": "vitest",
30+
"test": " vitest --run",
31+
"lint": "eslint --ext js,ts src .eslintrc.cjs",
32+
"lint:fix": "eslint --ext js,ts src .eslintrc.cjs --fix"
33+
},
34+
"dependencies": {
35+
"@pothos/core": "^3.41.0",
36+
"eslint": "^8.56.0",
37+
"graphql": "^16.8.1",
38+
"prettier": "^3.2.4"
39+
},
40+
"engines": {
41+
"node": ">=18.0.0"
42+
}
43+
}

src/core/context.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { Context } from './context'
3+
4+
describe('context', () => {
5+
it('should be defined', () => {
6+
const ctx = new Context(
7+
new Request('http://localhost'),
8+
{ Bindings: {}, Variables: {} },
9+
{ waitUntil: () => {}, passThroughOnException: () => {} }
10+
)
11+
expect(ctx).not.toBe(null)
12+
})
13+
})

0 commit comments

Comments
 (0)