Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bun.sh compatibility & bun CI #1929

Draft
wants to merge 55 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0bddedf
bun compatibility
ThatOneCalculator Sep 23, 2023
e1de6b5
Merge branch 'readme' into bun-sh
ThatOneCalculator Sep 23, 2023
bd24df6
bun compatibility, ci runs
ThatOneCalculator Sep 23, 2023
d3cd1b6
add back comments to webpack config
ThatOneCalculator Sep 23, 2023
c34b0d3
fix detector test
ThatOneCalculator Sep 23, 2023
0be3fcb
Merge branch 'swc' into bun-sh
ThatOneCalculator Sep 23, 2023
eb1431b
Merge branch 'readme' into bun-sh
ThatOneCalculator Sep 23, 2023
7bad8a0
Merge branch 'swc' into bun-sh
ThatOneCalculator Sep 26, 2023
3f72f6e
use pnpm instead of yarn
ThatOneCalculator Sep 26, 2023
cb13549
corepack enable
ThatOneCalculator Sep 26, 2023
d1a3dc4
use pnpm instead of yarn
ThatOneCalculator Sep 26, 2023
f421fa4
corepack enable
ThatOneCalculator Sep 26, 2023
a72bb1f
lockfile
ThatOneCalculator Oct 1, 2023
5860389
fix ci
ThatOneCalculator Oct 1, 2023
c6c3e0a
Merge branch 'master' into bun-sh
ThatOneCalculator Oct 1, 2023
ce04342
Merge branch 'readme' into bun-sh
ThatOneCalculator Oct 2, 2023
cdfd2fb
documentation
ThatOneCalculator Oct 2, 2023
ad892f4
`bun run` in bun test
ThatOneCalculator Oct 2, 2023
c1c553c
fix ci example
ThatOneCalculator Oct 2, 2023
287d51f
bun build for typescript example
ThatOneCalculator Oct 2, 2023
13a7621
seperate bun and bun-node targets
ThatOneCalculator Oct 2, 2023
d4a3dea
Merge branch 'h3poteto:master' into pnpm-clean
ThatOneCalculator Oct 4, 2023
2735505
Merge branch 'master' into pnpm-clean
ThatOneCalculator Oct 7, 2023
a99a0a2
update lockfile
ThatOneCalculator Oct 7, 2023
1f9dae3
Merge branch 'h3poteto:master' into bun-sh
ThatOneCalculator Oct 7, 2023
5f65ba1
fix ci
ThatOneCalculator Oct 7, 2023
ea141c5
fix ci yet again
ThatOneCalculator Oct 7, 2023
b88bcec
Merge branch 'pnpm' into bun-sh
ThatOneCalculator Oct 7, 2023
23d1e28
Merge branch 'bun-sh' of https://github.com/ThatOneCalculator/megalod…
ThatOneCalculator Oct 7, 2023
4c00dd7
webpack -> vite
ThatOneCalculator Oct 7, 2023
04c9439
lockfile
ThatOneCalculator Oct 7, 2023
dc8517a
Merge branch 'pnpm-clean' into bun-sh
ThatOneCalculator Oct 7, 2023
1809286
update lockfile
ThatOneCalculator Oct 7, 2023
f846770
rm unused webpack config
ThatOneCalculator Oct 7, 2023
56c10af
comments in vite config
ThatOneCalculator Oct 7, 2023
0864444
Merge branch 'pnpm-clean' into bun-sh
ThatOneCalculator Oct 7, 2023
1299cac
lockfiles
ThatOneCalculator Oct 7, 2023
84bf97a
add back workspaces for bun
ThatOneCalculator Oct 7, 2023
3f065ca
up pnpm to 8.8.0
ThatOneCalculator Oct 7, 2023
ed370b9
Merge branch 'pnpm-clean' into bun-sh
ThatOneCalculator Oct 7, 2023
2629843
adjust example test for bun
ThatOneCalculator Oct 8, 2023
8e08a00
disable browser bun ci for now
ThatOneCalculator Oct 8, 2023
b17525d
correct import in browser example
ThatOneCalculator Oct 8, 2023
72f84d5
add node polyfills for vite config
ThatOneCalculator Oct 8, 2023
425151f
format
ThatOneCalculator Oct 8, 2023
7afada7
fix for cjs
ThatOneCalculator Oct 8, 2023
d9f1ebf
Merge branch 'pnpm-clean' into bun-sh
ThatOneCalculator Oct 8, 2023
d3282fa
rm stray line
ThatOneCalculator Oct 8, 2023
7a969af
ignore weird import for eslint
ThatOneCalculator Oct 8, 2023
d1652d0
Merge branch 'pnpm-clean' into bun-sh
ThatOneCalculator Oct 8, 2023
f43df7d
proper ignore
ThatOneCalculator Oct 8, 2023
53eab06
Merge branch 'pnpm-clean' into bun-sh
ThatOneCalculator Oct 8, 2023
adf8be1
Proper pipe to fix ci, finally!
ThatOneCalculator Oct 8, 2023
7243999
exclude deps instead of polyfill
ThatOneCalculator Oct 8, 2023
fffbee9
Merge branch 'pnpm-clean' into bun-sh
ThatOneCalculator Oct 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
registry-url: 'https://registry.npmjs.org'
- name: Build
run: |
yarn install
yarn workspace megalodon doc
corepack enable && pnpm install
pnpm --filter megalodon doc
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
cp LICENSE.txt ./megalodon/
- name: Install dependencies
run: |
yarn install
corepack enable && pnpm install
- name: Build
run: |
yarn workspace megalodon run build
pnpm --filter megalodon run build
- name: Publish
run: |
yarn workspace megalodon publish
pnpm --filter megalodon publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ jobs:
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: |
yarn install
corepack enable && pnpm install
- uses: reviewdog/action-setup@v1
- name: megalodon eslint
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
yarn workspace megalodon lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true
pnpm --filter megalodon lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true
- name: example/typescript eslint
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
yarn workspace example lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true
pnpm --filter example lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true
- name: example/browser eslint
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
yarn workspace browser lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true
pnpm --filter browser lint | reviewdog -f=eslint -reporter=github-pr-review -fail-on-error=true
79 changes: 66 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ on:
pull_request:

jobs:
test:
test-node:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 19.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -25,20 +25,45 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
yarn install
corepack enable && pnpm install
- name: Build
run: |
yarn workspace megalodon run build
pnpm --filter megalodon run build
- name: Testing
run: |
yarn workspace megalodon run test
pnpm --filter megalodon run test

test-bun:
runs-on: ubuntu-latest

strategy:
matrix:
bun-version: ['latest']

steps:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ matrix.bun-version }}
- name: Install dependencies
run: |
bun install
- name: Build (Bun)
run: cd megalodon && bun run build:bun
- name: Testing (Bun)
run: cd megalodon && bun run test
# - name: Browser example (Bun)
# run: cd example/browser && bun run build
- name: Typescript example (Bun)
run: |
cd megalodon && bun run test

example:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 19.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -48,22 +73,50 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
yarn install
- name: Build
corepack enable && pnpm install
- name: Build library
run: |
yarn workspace megalodon run build
- name: Browser example
pnpm --filter megalodon run build
- name: Build examples
run: |
yarn workspace browser run build
pnpm --filter !megalodon run build
- name: Typescript example
env:
MASTODON_URL: https://fedibird.com
PLEROMA_URL: https://pleroma.io
FIREFISH_URL: https://cybre.club
FIREFISH_URL: https://fedi.software
FRIENDICA_URL: https://squeet.me
run: |
yarn workspace example run build
pnpm --filter example run build
node example/typescript/dist/mastodon/instance.js
node example/typescript/dist/pleroma/instance.js
node example/typescript/dist/firefish/instance.js
node example/typescript/dist/friendica/instance.js


example-bun:
runs-on: ubuntu-latest

strategy:
matrix:
bun-version: ['latest']

steps:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ matrix.bun-version }}
- name: Install dependencies
run: |
bun install
- name: Build (Bun)
run: cd megalodon && bun run build:bun
- name: Testing (Bun)
run: cd megalodon && bun run test
- name: Typescript example (Bun)
run: |
cd example/typescript && bun run build:bun
(env URL=https://fedibird.com bun run dist/detector.js | grep -q 'mastodon' && exit 0 || exit 1)
(env URL=https://pleroma.io bun run dist/detector.js | grep -q 'pleroma' && exit 0 || exit 1)
(env URL=https://fedi.software bun run dist/detector.js | grep -q 'firefish' && exit 0 || exit 1)
(env URL=https://squeet.me bun run dist/detector.js | grep -q 'friendica' && exit 0 || exit 1)
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![npm](https://img.shields.io/npm/dm/megalodon)](https://www.npmjs.com/package/megalodon)
[![NPM](https://img.shields.io/npm/l/megalodon)](/LICENSE.txt)

Megalodon is a Fediverse API client library for [NodeJS](https://nodejs.org) and browsers.
Megalodon is a Fediverse API client library for [NodeJS](https://nodejs.org), [Bun](https://bun.sh), and browsers.
This library allows for interfacing with [Mastodon](https://joinmastodon.org), [Pleroma](https://pleroma.social), [Friendica](https://friendi.ca), and [Firefish](https://joinfirefish.org) servers all with the same interface, providing REST API and streaming methods.

The Rust version is [megalodon-rs](https://github.com/h3poteto/megalodon-rs).
Expand All @@ -26,7 +26,7 @@ The Rust version is [megalodon-rs](https://github.com/h3poteto/megalodon-rs).
- [x] WebSocket for streaming
- [x] Promisified methods
- [x] Proxy support
- [x] NodeJS and browser support
- [x] NodeJS, Bun, and browser support
- [x] Written in TypeScript

## Install
Expand All @@ -38,6 +38,9 @@ npm install -S megalodon
# pnpm
pnpm add megalodon

# bun
bun add megalodon

# yarn
yarn add megalodon
```
Expand Down
Binary file added bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion example/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Megalodon</title>
<script src="./dist/main.js"></script>
<script type="module" src="./src/index.ts"></script>
</head>
<body>
</body>
Expand Down
14 changes: 9 additions & 5 deletions example/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
"version": "4.0.0",
"private": true,
"scripts": {
"build": "webpack",
"build": "vite build",
"start": "http-server -p 8000 -s index.html",
"lint": "eslint --ext .js,.ts src"
"lint": "eslint --ext .js,.ts src",
"serve": "vite",
"preview": "vite preview"
},
"author": "Akira Fukushima <[email protected]> (https://github.com/h3poteto)",
"license": "MIT",
"dependencies": {
"megalodon": "*"
},
"devDependencies": {
"@originjs/vite-plugin-commonjs": "^1.0.1",
"assert": "^2.1.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
Expand All @@ -27,7 +30,8 @@
"ts-loader": "^9.4.4",
"typescript": "5.2.2",
"url": "^0.11.3",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
"vite": "^2.7.2",
"vite-plugin-env-compatible": "^1.1.1",
"vite-plugin-html": "3.2.0"
}
}
}
4 changes: 3 additions & 1 deletion example/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import generator, { Entity } from 'megalodon'
import { Entity } from 'megalodon'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const generator = require('megalodon').default

const BASE_URL: string = process.env.MASTODON_URL!
const ACCESS_TOKEN: string = process.env.MASTODON_ACCESS_TOKEN!
Expand Down
38 changes: 38 additions & 0 deletions example/browser/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { defineConfig } from 'vite'
import path from 'path'
import envCompatible from 'vite-plugin-env-compatible'
import { createHtmlPlugin } from 'vite-plugin-html'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'

// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: [
{
find: /^~/,
replacement: ''
},
{
find: '@',
replacement: path.resolve(__dirname, 'src')
}
],
extensions: ['.mjs', '.js', '.ts']
},
plugins: [
viteCommonjs(),
envCompatible(),
createHtmlPlugin({
inject: {
data: {
title: 'browser'
}
}
})
],
optimizeDeps: {
// https-proxy-agent and socks-proxy-agent is node library, so can't compile for browser.
exclude: ['https-proxy-agent', 'socks-proxy-agent']
},
build: {}
})
58 changes: 0 additions & 58 deletions example/browser/webpack.config.js

This file was deleted.

1 change: 1 addition & 0 deletions example/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"build": "tsc -p ./",
"build:bun": "bun build ./src/detector.ts --outdir=dist --minify --target=bun",
"lint": "eslint --ext .js,.ts src"
},
"author": "h3poteto",
Expand Down
8 changes: 7 additions & 1 deletion megalodon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"main": "./lib/src/index.js",
"typings": "./lib/src/index.d.ts",
"scripts": {
"build:bun-node": "bun build ./src --outdir=lib --minify --target=node",
"build:bun": "bun build ./src --outdir=lib --minify --target=bun",
"build": "tsc -p ./",
"lint": "eslint --ext .js,.ts src",
"doc": "typedoc --out ../docs ./src",
Expand Down Expand Up @@ -76,6 +78,7 @@
"@types/uuid": "^9.0.4",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"bun-types": "^1.0.3",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
Expand All @@ -85,5 +88,8 @@
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"typedoc": "^0.25.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"packageManager": "[email protected]",
"workspaces": [
"megalodon",
"example/typescript",
Expand Down
Loading
Loading