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

framework api: init / work in progress #13215

Merged
merged 73 commits into from
Sep 12, 2024
Merged

framework api: init / work in progress #13215

merged 73 commits into from
Sep 12, 2024

Conversation

paperclover
Copy link
Member

@paperclover paperclover commented Aug 10, 2024

This is initial work for the "Framework API", internally code named "Kit". This name is not final and just something to give me a fresh namespace for new code.

This configures Kit to be compiled as a part of canary to reduce bit-rot. I will periodically submit follow-up PRs expanding the feature set.

There are many changes in the JS parser and Bundler to

  • BundleThread has been generalized to take a type of the completion struct (and moved to bundle_v2.BundleThread(T)). This allows Kit to re-use a lot of Bun.build's asynchronous and queued bundling features. The completion struct has two methods, configureBundler and completeOnBundleThread, which is all the needed abstraction to re-use that code.
  • JSPromise gets an unwrap function to read a nice union(enum)
  • Introduce an easier way to deal with JSC locks
  • JS Parser changes
    • IIFE kind of works, not enough to pass tests and is still disabled
    • Implement react fast refresh, available as --react-fast-refresh. I exposed this flag so I can manually test it myself, in isolation from the hot module transforms.
    • Removed legacy HMR transform
    • Removed legacy CommonJS transform
    • Removed unused runtime.js functions
    • Removed options.OutputFormat in favor of options.Format
    • Removed other unused legacy code. There is more to be deleted but not now (likely a small chore pr, some of it i am keeping for reference)

Copy link
Contributor

github-actions bot commented Aug 10, 2024

clang-tidy nits are fixed! Thank you.

src/kit/kit.zig Outdated Show resolved Hide resolved
try pool.start(
this,
thread_pool,
);

return generator;
// sanity checks for kit
if (this.bundler.options.output_format == .internal_kit_dev) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be wrapped in if (isDebug)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can, but i don't want the bundler to ever continue if these options are misconfigured. these checks are not expensive.

src/js_printer.zig Outdated Show resolved Hide resolved
const import_record_index = p.addImportRecordByRange(.stmt, logger.Range.None, "react-refresh/runtime");

const Item = if (hot_module_reloading) B.Object.Property else js_ast.ClauseItem;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const num_items = 1 + @intFromBool(p.react_refresh.register_used) + @intFromBool(p.react_refresh.signature_used); and use it for items.initCapacity and declared_symbols.ensureTotalCapacity?

none: void,
bun_dev: Expr,
bun_js: void,
const WrapMode = union(enum) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this just be an enum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea this can now be an enum since bun_dev was deleted

src/js_parser.zig Outdated Show resolved Hide resolved
},
if (have_custom_hooks) {
// () => [useCustom1, useCustom2]
args[3] = p.newExpr(E.Arrow{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is out of bounds if !have_force_arg and have_custom_hooks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not possible because have_force_arg is defined in terms of have_custom_hooks

const have_custom_hooks = ctx.user_hooks.count() > 0;
const have_force_arg = have_custom_hooks or p.react_refresh.force_reset;

// the file. That is also why tree-shaking is disabled.
if (p.options.features.hot_module_reloading) {
bun.assert(!p.options.tree_shaking);
bun.assert(p.options.features.hot_module_reloading);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's harmless but this assert isn't necessary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@paperclover paperclover marked this pull request as ready for review September 12, 2024 21:30
@paperclover paperclover merged commit c2c2048 into main Sep 12, 2024
45 of 46 checks passed
@paperclover paperclover deleted the dave/kit branch September 12, 2024 23:44
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.

4 participants