3 Commits

Author SHA1 Message Date
b1558bd9fa fix types & add bun adapater (WIP) 2022-07-26 08:32:33 +00:00
f87ab5366e Publish v0.1.0 2022-07-04 10:15:51 +00:00
65841ce965 Publish 0.0.1 2022-07-04 10:02:51 +00:00
11 changed files with 126 additions and 15 deletions

39
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: release
on:
release:
types: [created]
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{ github.event.release.target_commitish }}
- name: Validate and extract release information
id: release
uses: manovotny/github-releases-for-automated-package-publishing-action@v1.0.0
- name: Set node version
uses: actions/setup-node@v3
with:
always-auth: true
node-version: vx.x.x
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: yarn install
- name: Publish tagged version
if: steps.release.outputs.tag != ''
run: yarn publish --new-version ${{ steps.release.outputs.version }} --tag ${{ steps.release.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# This will publish a version of a package.
- name: Publish version
if: steps.release.outputs.tag == ''
run: yarn publish --new-version ${{ steps.release.outputs.version }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

View File

@ -3,7 +3,7 @@
> Handlers.js is a unified and lightweight web application framework for multiple platforms. > Handlers.js is a unified and lightweight web application framework for multiple platforms.
```ts ```ts
import handlerJS from "./"; import handlerJS from "handlers.js";
const App = new handlerJS(); const App = new handlerJS();
@ -15,3 +15,12 @@ App.binding(
App.useMappingAdapter(); App.useMappingAdapter();
App.listen(8080); App.listen(8080);
``` ```
## Installation
```bash
# Use Yarn
yarn add handlers.js
# Use NPM
npm install handlers.js
```

View File

@ -1,8 +1,16 @@
{ {
"name": "handlers.js", "name": "handlers.js",
"description": "Handlers.js is a unified and lightweight web application framework for multiple platforms.", "description": "Handlers.js is a unified and lightweight web application framework for multiple platforms.",
"version": "0.0.1", "version": "0.1.1",
"main": "index.ts", "main": "./dist/index.js",
"webpack": "./dist/index.js",
"browser": "./dist/main.serviceworker.js",
"module": "./dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"LICENSE"
],
"author": "186526 <i@186526.xyz>", "author": "186526 <i@186526.xyz>",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
@ -25,6 +33,7 @@
"@webpack-cli/generators": "^2.5.0", "@webpack-cli/generators": "^2.5.0",
"axios": "^0.27.2", "axios": "^0.27.2",
"bluebird": "^3.7.2", "bluebird": "^3.7.2",
"bun-types": "^0.1.4",
"jest": "^28.1.2", "jest": "^28.1.2",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"ts-jest": "^28.0.5", "ts-jest": "^28.0.5",
@ -36,22 +45,24 @@
}, },
"sideEffects": false, "sideEffects": false,
"scripts": { "scripts": {
"build": "yarn clean && yarn build:node && yarn build:serviceworker && yarn build:cfworker && yarn build:deno && yarn build:txiki", "build": "yarn clean && yarn build:node && yarn build:serviceworker && yarn build:cfworker && yarn build:deno && yarn build:txiki && yarn build:bun",
"build:node": "BUILD_TARGET=node webpack", "build:node": "BUILD_TARGET=node webpack",
"build:serviceworker": "BUILD_TARGET=serviceworker webpack", "build:serviceworker": "BUILD_TARGET=serviceworker webpack",
"build:cfworker": "BUILD_TARGET=cfworker webpack", "build:cfworker": "BUILD_TARGET=cfworker webpack",
"build:deno": "BUILD_TARGET=deno webpack", "build:deno": "BUILD_TARGET=deno webpack",
"build:txiki": "BUILD_TARGET=txiki webpack", "build:txiki": "BUILD_TARGET=txiki webpack",
"build:bun": "BUILD_TARGET=bun webpack",
"watch": "webpack --watch", "watch": "webpack --watch",
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"demo": "env NODE_ENV=development yarn build:node && node ./dist/main.node.js", "demo": "env NODE_ENV=development yarn build:node && node ./dist/main.node.js",
"tsc": "tsc", "tsc": "tsc",
"test:node": "jest ./test/node.test.ts", "test:node": "jest ./test/node.test.ts",
"test:deno": "BUILD_TARGET=deno:test webpack && jest ./test/deno.test.ts", "test:deno": "BUILD_TARGET=deno:test webpack && jest ./test/deno.test.ts",
"coverage": "jest --collectCoverage --" "coverage": "jest --collectCoverage --",
"prepublish": "env NODE_ENV=production yarn build && yarn tsc"
}, },
"engines": { "engines": {
"node": ">=14.0.0" "node": ">=14.0.0"
}, },
"type": "module" "type": "module"
} }

View File

@ -7,6 +7,9 @@ export const platform = (() => {
if (typeof Deno != "undefined") { if (typeof Deno != "undefined") {
return "Deno"; return "Deno";
} }
if (typeof Bun != "undefined") {
return "Bun";
}
if (typeof tjs != "undefined") { if (typeof tjs != "undefined") {
return "txiki.js"; return "txiki.js";
} }
@ -17,7 +20,7 @@ export const platform = (() => {
})(); })();
export const version = (() => { export const version = (() => {
switch (platform) { switch (platform) {
case "Node.js": case "Node.js" || "Bun":
return process.version; return process.version;
case "Deno": case "Deno":
return Deno.version.deno; return Deno.version.deno;

20
src/platform/bun.ts Normal file
View File

@ -0,0 +1,20 @@
import { SWPlatformAdapter } from "./serviceworker";
import { platformAdapater } from "./index";
export class BunPlatformAdapter<T = any, K = any>
extends SWPlatformAdapter<T, K>
implements platformAdapater<T, K>
{
async listen(port: number): Promise<void> {
Bun.serve({
fetch: async (request: Request): Promise<Response> => {
return await this.handleResponse(
await this.handleRequest(request).then((request) =>
this.router.respond(request)
)
);
},
port,
});
}
}

View File

@ -2,7 +2,7 @@ import { platformAdapater } from "./index";
import { request } from "../interface/request"; import { request } from "../interface/request";
import { response } from "../interface/response"; import { response } from "../interface/response";
import { router } from "../router"; import { router } from "../router";
import serveHttp from "./txiki.js/serveHttp"; import serveHttp from "./txiki-js/serveHttp";
export class TxikiPlatformAdapter<T = any, K = any> implements platformAdapater { export class TxikiPlatformAdapter<T = any, K = any> implements platformAdapater {
public router: router<T, K>; public router: router<T, K>;

View File

@ -2,8 +2,15 @@
"compilerOptions": { "compilerOptions": {
"target": "esnext", "target": "esnext",
"module": "esnext", "module": "esnext",
"lib": ["ESNext"], "lib": [
"types": ["@cloudflare/workers-types", "@types/node", "@types/jest"], "ESNext"
],
"types": [
"@cloudflare/workers-types",
"@types/node",
"@types/jest",
"bun-types"
],
"skipLibCheck": true, "skipLibCheck": true,
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "./dist",
@ -23,12 +30,21 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"baseUrl": ".", "baseUrl": ".",
"plugins": [{ "plugins": [
"transform": "@zerollup/ts-transform-paths" {
}], "transform": "@zerollup/ts-transform-paths"
}
],
"declaration": true "declaration": true
}, },
"exclude": ["node_modules"], "exclude": [
"include": ["index.ts", "src/**/*.ts", "demo/**/*.ts", "types/*.d.ts"], "node_modules"
],
"include": [
"index.ts",
"src/**/*.ts",
"demo/**/*.ts",
"types/*.d.ts"
],
// "esm": true // "esm": true
} }

View File

@ -81,12 +81,20 @@ export default () => {
'Promise': 'bluebird' 'Promise': 'bluebird'
}) })
) )
break;
case "bun":
config.mode = "production";
config.target = "node12";
config.output.filename = "main.bun.js";
break;
case "deno:test": case "deno:test":
config.target = "webworker"; config.target = "webworker";
config.output.filename = "test.deno.js"; config.output.filename = "test.deno.js";
config.entry = "./test/test-server.deno.ts"; config.entry = "./test/test-server.deno.ts";
break;
default: default:
config.target = "es6"; config.target = "es6";
break;
} }
return config; return config;

View File

@ -1565,6 +1565,11 @@ builtins@^1.0.3:
resolved "https://registry.yarnpkg.com/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88" resolved "https://registry.yarnpkg.com/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88"
integrity sha512-uYBjakWipfaO/bXI7E8rq6kpwHRZK5cNYrUv2OzZSI/FvmdMyXJ2tG9dKcjEC5YHmHpUAwsargWIZNWdxb/bnQ== integrity sha512-uYBjakWipfaO/bXI7E8rq6kpwHRZK5cNYrUv2OzZSI/FvmdMyXJ2tG9dKcjEC5YHmHpUAwsargWIZNWdxb/bnQ==
bun-types@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/bun-types/-/bun-types-0.1.4.tgz#b4ab4ae10828bea0eacf1f221b197b37abd88cda"
integrity sha512-8nyx22INhlPT+R/1MebbAK7TX48aLQdrLTEmce3oTlne5GunoxMEtCiHOku90XKeHbxxbMkkPI2TX1m0pvlLaw==
cacache@^15.0.3, cacache@^15.0.5, cacache@^15.2.0: cacache@^15.0.3, cacache@^15.0.5, cacache@^15.2.0:
version "15.3.0" version "15.3.0"
resolved "https://registry.yarnpkg.com/cacache/-/cacache-15.3.0.tgz#dc85380fb2f556fe3dda4c719bfa0ec875a7f1eb" resolved "https://registry.yarnpkg.com/cacache/-/cacache-15.3.0.tgz#dc85380fb2f556fe3dda4c719bfa0ec875a7f1eb"