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's Roadmap #159

Open
54 of 137 tasks
Jarred-Sumner opened this issue May 6, 2022 · 33 comments
Open
54 of 137 tasks

Bun's Roadmap #159

Jarred-Sumner opened this issue May 6, 2022 · 33 comments
Labels
tracking An umbrella issue for tracking big features

Comments

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented May 6, 2022

This tracks the current near-term plans for Bun.

Edge bundling

With bundle-time functions, static analysis goes dynamic. Objects returned by functions executed at bundle-time are injected into the AST. This makes dead-code elimination work a lot better.

I expect this to spawn a new generation of bundle-time JavaScript frameworks.

But first, a lot more needs to be built.

Main blockers

JavaScript minifier

  • Minify JavaScript identifier names
  • Compress JavaScript syntax (this is partially implemented)
  • Constant folding
  • Dead code elimination (this is partially implemented)
  • Read "sideEffects" from package.json

Web Bundler (production-focused, instead of development-focused)):

  • Tree-shaking
  • Source maps
    • Source maps for JavaScript (exists today without bundling)
    • Source maps for CSS
    • Input source maps
  • Code splitting (esm)
  • Link-time optimizations
    • const TypeScript enum support
    • cross-module inlining for bundle-time known objects
  • Optional concurrency. In the CI-scenario, it needs to work great in parallel and in the edge runtime scenario, it needs to work great potentially running single-threaded.
  • Multiple output formats
    • IIFE (immediately invoked function expressions)
    • CommonJS
    • ES Modules
  • Continue supporting Hot Module Reloading after these changes

CSS parser:

  • CSS Minifier
  • CSS Lexer
  • CSS Parser/AST
  • CSS Auto-prefixer
  • Bun.Transpiler support for CSS
  • Support for parsing css inside of JavaScript
    • <style jsx> support

Once complete, the next step is integration with the HTTP server and other Bun APIs

Efficient bundling format

Cache builds into a binary archive format with metadata designed for fast random access, splice(), and sendfile() support. Outside of the edge runtime, these will work as a single-file JavaScript executable internally holding many files.

Instances of Bun will need to know what bundle(s) they're serving. From there, instead of going through a filesystem, we can serve static requests directly from the bundle and dynamic requests will bundle on-demand, potentially importing code from statically-bundled code.

  • Bundle API (not finalized yet)

    • Bundle.prototype.resolve(path): string API
    • Bundle.prototype.build(entryPoint, context): Response API
    • Bundle.prototype.generate(entryPoints, options): Promise<Bundle> API
  • JSNode AST API

    • Receive context/env data from the HTTP server and/or Bundle
    • Support generated functions
    • Support generated classes
    • Support generated objects
    • Support injecting imports

Server-side rendering

  • Support Next.js (partial support right now)
  • Support Remix (partial support right now)
  • Support SvelteKit
  • Support Nuxt.js
  • Support Vite
  • Experiment with React-specific optimizations
    • Stringify static React elements into raw HTML at bundle-time, handling encoding and escaping correctly
  • Support a fast path for generating ETags
  • Integrate with Bundle, JSNode, and other Bun APIs

Runtime

  • Foreign function interface (FFI) to support loading native code
  • Module loader hooks to enable .vue, .svelte, .scss imports and more.
    • Implement esbuild's onLoad API in bun.js
    • Implement esbuild's onResolve API in bun.js
    • Support when building for bun.js
    • Support when building for web
    • A way to configure which hooks to load before bun starts, likely in bunfig.toml
    • onLoad plugins from native libraries
    • onResolve plugins from native libraries
  • Fastest SQLite client available in JavaScript
  • Fastest PostgreSQL client available in JavaScript
    • Explore a socket-based implementation
    • Explore a libpq-based implementation
  • Fastest MySQL client available in JavaScript
    • Explore a socket-based implementation
    • Explore a libmysqlclient-based implementation
  • TCP sockets API with TLS 1.3, likely based on uSockets
  • DNS resolution API, probably using c-ares
  • Support https: and http: imports. This includes a disk cache possibly integrated into the bundling format.
  • Support data: imports
  • Support blob: imports & URLs (URL.createObjectURL, URL.revokeObjectURL)
  • Reliably unload JavaScript VMs without memory leaks and without restarting bun's process
  • Rewrite the JavaScript event loop implementation to be more efficient

Edge Runtime

Slimmer, linux-only build of bun.js:

  • Only loads prebundled code
  • Design for starting as fast as possible
    • No tsconfig.json parsing
    • No package.json parsing
    • No bunfig.toml parsing
    • No node_module resolver
    • Use binary bundling format
    • Potentially disable NAPI and FFI
  • Spawn a new JSGlobalObject per HTTP request and suspend it after response is sent/fully queued
  • No bun install
  • No other subcommands

Usability & Developer Experience

  • High-quality examples for getting started with bun. Right now, the examples are poor quality.
  • bun REPL with transpiler-enabled support for async/await, typescript and ES Modules (those are not supported by eval usually)
  • Public docs
  • Public landing page
  • Public github repo
  • bun subcommand for running npm packages or URLs that may not already be installed. Like npx
  • GitHub Actions for bun
  • @types/bun npm package

Ecosystem

  • Run Next.js apps in production with bun.js
  • Run Remix apps in production with bun.js
  • Run SvelteKit apps in production with bun.js
  • Use Prisma, Apollo, etc with bun.js
  • more frameworks
  • Investigate running Vite inside bun.js
  • Support running Bun from StackBlitz

Web Compatibility

note: after a little testing, performance of safari's web streams implementation is similar to deno and much faster than node 18. I expect the final result to be faster than deno because bun's TextEncoder/TextDecoder & Blob implementation seems generally faster than safari's

Security

  • Verify TLS certificates in fetch. Right now, it doesn't.
  • Investigate supporting Content Security Policy (CSP) in bun.js
    • This would mean limiting which domains are accessible to the runtime based on the script execution context and how/where code is loaded into the runtime.
    • If we decide to support this, we likely can use WebKit's implementation for most of it.

Windows support

  • The HTTP client needs a Windows implementation for the syscalls
  • Bun needs test coverage for Windows filepath handling
  • All of bun's dependencies need to compile on Windows
  • Building JavaScriptCore needs to work on Windows and the JIT tiers need to work. I don't know what the current status of this is. WebKit's bug tracker suggests it may not have JITs enabled which will likely need some patches to fix it.

Node.js Compatibility

  • Node-API support
  • child_process support
  • non-blocking "fs"
  • "net" module
  • "crypto" polyfill should use hardware-accelerated crypto for better performance
  • Finish "buffer" implementation
  • require implementation that natively supports ESM (rather than via transpiler). This would involve subclassing AbstractModuleRecord in JSC. This would better support lazy-loading CommonJS modules.

Reliability

  • Better fetch implementation:
    • HTTP Keep-Alive
    • TLS 1.3 0-RTT
    • HTTP Pipelining
    • Cookie Jar
    • HTTP/3 (QUIC)
  • Run Web Platform tests
  • Run Test262
  • Support ActiveDOMObject from WebKit so that all native objects can be suspended & terminated

Misc

@RnbWd
Copy link

RnbWd commented Jul 7, 2022

this seems like a lot of work... wow

@space7panda
Copy link

Can't wait for full npm-like config support. We are using our own npm registry, and the current build time is 40-60 minutes. If it will be at least 10 minutes this will be a game-changer!

@officialrajdeepsingh
Copy link

I am waiting for the stable version of the bun. What change bun in the javascript world.

@tipiirai
Copy link

Also waiting for the stable version. So exciting! I bet it's going to take a lot of time though. The scope of this project is much larger than what Node attempts to solve.

@matepaiva
Copy link

can someone confirm that right now I can't use the package mysql2? It throws me an error because it depends on TLS package and on NET package, and I think they were not implemented yet in Bun, but I am not sure.

@Kapsonfire-DE
Copy link
Contributor

still missing websocket server support

@GCSBOSS
Copy link

GCSBOSS commented Jul 12, 2022

Can a tinitiny docker image be placed somewhere in there? 👀

@MystPi
Copy link

MystPi commented Jul 14, 2022

Can't wait for Windows support... I'll be anxiously awaiting it until it's out. 😅

@jastraberg
Copy link

still missing websocket server support

Dito

@sodeprecated
Copy link

Are you planning to support http2?

@moderation
Copy link

Are you planning to support http2?

HTTP/3 is on #159 so I would say HTTP/2 will likely be added before that

@sodeprecated
Copy link

Are you planning to support http2?

HTTP/3 is on #159 so I would say HTTP/2 will likely be added before that

I would say that http3 on roadmap is more about quic protocol and there is no straight inheritance between http3 and http2, so maybe support of http2 needs to be marked explicitly.

@frodoe7
Copy link

frodoe7 commented Jul 19, 2022

Motivated to see a stable version ASAP

@LaurelineP
Copy link

Promising !
Any roadmap on a progressive translation ?

@Parvat-R
Copy link

When is the support for windows coming? Cant wait for it.

@jacoscaz
Copy link

I would say that http3 on roadmap is more about quic protocol and there is no straight inheritance between http3 and http2, so maybe support of http2 needs to be marked explicitly.

Another vote for HTTP/2 as it's a prerequisite to gRPC support.

@DetachHead DetachHead mentioned this issue Aug 1, 2022
@dyaskur
Copy link

dyaskur commented Aug 4, 2022

Any plans to create a desktop app like electron?

@xHyroM
Copy link
Collaborator

xHyroM commented Aug 4, 2022

When is the support for windows coming? Cant wait for it.

#43 you can use WSL for now

@xHyroM
Copy link
Collaborator

xHyroM commented Aug 4, 2022

When is the support for windows coming? Cant wait for it.

#43 you can use WSL for now

I don't use WSL. Node.js and Deno support Windows natively; why can't Bun?

Check #43

@devongovett
Copy link

On the topic of CSS parsing, transpilation, minification, etc., what's your stance on dependencies? Do you want to reimplement everything yourself, or would you consider using an embeddable library? If so, I'd love to collaborate with you on embedding Parcel CSS in Bun. It's implemented in Rust, but if we added a C API, I think Bun could call into it pretty easily. It may also work via Bun's napi support, but that would probably be slower. It's about 4x faster than esbuild on benchmarks, minifying over 2 million lines of code per second on a single thread. You can find more info in the announcement blog post from February, though it's gotten even faster since then. Would be cool to work together, and I'm happy to help support how I can.

@aphix
Copy link

aphix commented Aug 10, 2022

One thought re: minification, please include a way to exclude class/parameter (on both function and constructor args, and incl. subkeys)/function names from minification as it makes certain dependency injection patterns impossible.

Traditionally, many of the existing DI libraries would use Function.toString() and then use some regex to pull out the fn name & args, but given the reason that is needed and how hacky it is, this may be an opportunity for bun to create a better solution ahead of time, for example by exposing the pre-minified function/class names + argument names programmatically such that they are available at runtime. Note that they much be able to be retrieved before the function is called or class is instantiated.

@piosystems
Copy link

How about full support for NestJS? Looking forward to it.

@sayjeyhi
Copy link

[ ] read resolutions from package.json

@DippsoN
Copy link

DippsoN commented Dec 18, 2022

Bun should move toward full support for nestjs.

@kuator
Copy link

kuator commented Jan 14, 2023

Are there any plans for bun language server? Deno provides one: https://deno.land/manual@v1.29.1/advanced/language_server/overview, so I thought bun might do as well

@gabriiels

This comment was marked as off-topic.

@vanor89

This comment was marked as off-topic.

@wxs77577
Copy link

As a Electron or Tauri alternative.
Maybe should consider to build single-file executable files. .exe or .msi for windows and .dmg for macos.

@Alberto-Safra
Copy link

Would love to eventually see support for Qwik. Down the line would be willing to help with the effort too.

@gabriiels
Copy link

Would love to eventually see support for Qwik. Down the line would be willing to help with the effort too.

Yes!!!!!!!!!!!!!!!!! Qwik + Bun === GOAT

@Willdune
Copy link

Willdune commented May 12, 2023

Some cool dependency injection would be nice, such as https://www.npmjs.com/package/node-dependency-injection without decorators and making possible configuring yml files for each enviroment, for example. Keep that absolute good work! Love it <3

@innocenzi
Copy link

Would a linter/formatter be considered in the future? An alternative to eslint that'd use Bun's parser, would be faster and would have a better plugin/config format?

@wsz7777
Copy link

wsz7777 commented Jun 3, 2023

when can have a tool with bundle analyzer?It's like webpack-bundle-analyzer。
https://github.com/webpack-contrib/webpack-bundle-analyzer

of course , Providing 'stats.json' files is also possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracking An umbrella issue for tracking big features
Projects
None yet
Development

No branches or pull requests