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

Migrate to Bun #87

Merged
merged 2 commits into from
Jan 6, 2025
Merged

Migrate to Bun #87

merged 2 commits into from
Jan 6, 2025

Conversation

Electroid
Copy link
Contributor

@Electroid Electroid commented Jan 4, 2025

Hi there, I noticed you were using Bun, thanks! I tried out your project and made some changes to use Bun in more places, and removed the need to use the run build script.

  • Updated the Dockerfile to use bun install instead of bun install
  • Updated bun run server to run directly with bun, so tsc isn't needed
  • Added fallbacks for using node: e.g. bun run server:node
  • Added bun.lock, which is Bun's new text-lock file (generated from bun install --save-text-lockfile)

Here's a performance comparison if you were curious:

bun install - 1.16 sec
❯ rm -rf node_modules bun.lock pnpm-lock.yaml package-lock.json
❯ time bun install --save-text-lockfile
bun install v1.1.42-canary.44 (aa1b0c9c)

+ @types/bcrypt@5.0.2
+ @types/express-session@1.18.1
+ @types/fluent-ffmpeg@2.1.27
+ @types/multer@1.4.12
+ @types/node@22.10.5
+ typescript@5.7.2
+ @dank074/discord-video-stream@4.1.5
+ @distube/ytdl-core@4.15.8
+ axios@1.7.9
+ bcrypt@5.1.1
+ discord.js-selfbot-v13@3.4.6
+ dotenv@16.4.7
+ express@4.21.2
+ express-session@1.18.1
+ fluent-ffmpeg@2.1.3
+ multer@1.4.5-lts.1
+ p-cancelable@4.0.1
+ play-dl@1.9.7
+ tslib@2.8.1
+ twitch-m3u8@1.1.5

357 packages installed [1140.00ms]

________________________________________________________
Executed in    1.16 secs      fish           external
   usr time  248.62 millis    0.07 millis  248.55 millis
   sys time  232.11 millis    1.59 millis  230.52 millis
npm install - 3.42 sec
❯ rm -rf node_modules bun.lock pnpm-lock.yaml package-lock.json
❯ time npm install
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated npmlog@5.0.1: This package is no longer supported.
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated are-we-there-yet@2.0.0: This package is no longer supported.
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated gauge@3.0.2: This package is no longer supported.

added 387 packages, and audited 388 packages in 3s

67 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

________________________________________________________
Executed in    3.42 secs    fish           external
   usr time    2.50 secs    0.08 millis    2.50 secs
   sys time    1.95 secs    1.82 millis    1.95 secs
pnpm install - 3.11 sec
❯ rm -rf node_modules bun.lock pnpm-lock.yaml package-lock.json
❯ time pnpm install
 WARN  6 deprecated subdependencies found: are-we-there-yet@2.0.0, gauge@3.0.2, glob@7.2.3, inflight@1.0.6, npmlog@5.0.1, rimraf@3.0.2
Packages: +358
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 358, reused 358, downloaded 0, added 358, done

dependencies:
+ @dank074/discord-video-stream 4.1.5
+ @distube/ytdl-core 4.15.8
+ axios 1.7.9
+ bcrypt 5.1.1
+ discord.js-selfbot-v13 3.4.6
+ dotenv 16.4.7
+ express 4.21.2
+ express-session 1.18.1
+ fluent-ffmpeg 2.1.3
+ multer 1.4.5-lts.1
+ p-cancelable 4.0.1
+ play-dl 1.9.7
+ tslib 2.8.1
+ twitch-m3u8 1.1.5

devDependencies:
+ @types/bcrypt 5.0.2
+ @types/express-session 1.18.1
+ @types/fluent-ffmpeg 2.1.27
+ @types/multer 1.4.12
+ @types/node 22.10.5
+ typescript 5.7.2

Done in 3s

________________________________________________________
Executed in    3.11 secs    fish           external
   usr time    1.91 secs    0.10 millis    1.91 secs
   sys time    4.29 secs    1.58 millis    4.29 secs

Thanks and neat project!

* Changes `pnpm install` to `bun install`, adds `bun.lock`
* Changes `bun run server` to run directly, without needing `tsc`
* Keeps fallbacks for using node
@ysdragon
Copy link
Owner

ysdragon commented Jan 4, 2025

Hello @Electroid,

Thank you for your contribution.

I was using Bun until I encountered a compatibility issue. When running the bot using Node.js 22, there are no issues with streaming videos to Discord, and I can see the demuxer logs:

log ```shell Playing (BigBuckBunny)... INFO demux:format Found video stream in input 8e5695d7b96 { INFO demux:format "info": { INFO demux:format "index": 0, INFO demux:format "codec": 27, INFO demux:format "width": 1280, INFO demux:format "height": 720, INFO demux:format "framerate_num": 30, INFO demux:format "framerate_den": 1, INFO demux:format "extradata": { INFO demux:format "sps": [ INFO demux:format { INFO demux:format "type": "Buffer", INFO demux:format "data": [ INFO demux:format 103, INFO demux:format 66, INFO demux:format 192, INFO demux:format 31, INFO demux:format 218, INFO demux:format 1, INFO demux:format 64, INFO demux:format 22, INFO demux:format 236, INFO demux:format 4, INFO demux:format 64, INFO demux:format 0, INFO demux:format 0, INFO demux:format 3, INFO demux:format 0, INFO demux:format 64, INFO demux:format 0, INFO demux:format 0, INFO demux:format 15, INFO demux:format 35, INFO demux:format 198, INFO demux:format 12, INFO demux:format 168 INFO demux:format ] INFO demux:format } INFO demux:format ], INFO demux:format "pps": [ INFO demux:format { INFO demux:format "type": "Buffer", INFO demux:format "data": [ INFO demux:format 104, INFO demux:format 206, INFO demux:format 60, INFO demux:format 128 INFO demux:format ] INFO demux:format } INFO demux:format ] INFO demux:format } INFO demux:format } INFO demux:format } +0ms INFO demux:format Found audio stream in input 8e5695d7b96 { INFO demux:format "info": { INFO demux:format "index": 1, INFO demux:format "codec": 86076, INFO demux:format "sample_rate": 48000 INFO demux:format } INFO demux:format } +2ms Stopped playing INFO demux:frame:common Reached end of stream. Stopping +0ms ```

However, when using Bun, the video does not stream to Discord, and I cannot see the demuxer messages. The only message I see is Started playing video, and nothing else. This issue occurs when using both bun run start and bun run start:node scripts.

Could you suggest what to do in this case? I was really impressed by Bun's performance, so I’d like to resolve this issue if possible.

EDIT: I discovered that this issue occurs because the @dank074/discord-video-stream dependency needs to be linted. I will push your pull request once it's fixed in the mainstream.

@ysdragon ysdragon merged commit 263cfc6 into ysdragon:main Jan 6, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants