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

Rewrite built-in modules to use CommonJS over ESM #3814

Merged
merged 19 commits into from
Aug 2, 2023
Merged

Conversation

paperdave
Copy link
Member

@paperdave paperdave commented Jul 26, 2023

Closes #3773
Closes #3863
Closes
Fixes immediate segfault of #3746 but astro isnt working fully yet

  • This changes all node:* and bun:* modules to use CommonJS modules. Since the bundler does not emit CommonJS code, this is done with a custom pre/postprocessor step.
    • require is intercepted at build time and inlined to $requireId(...) where a static number is inlined.
    • Introduce InternalModuleRegistry in C++. This is an internal fields object of about 50.
  • All builtin modules now actually use builtins syntax. Meaning we can access private globals like $isArray and so on.
  • make builtins & make esm are now one build process: make js. It is also faster.
  • Removes some hacks we had
    • Symbol.for("CommonJS")
    • $lazy("primordials")
    • in the future we can remove globalThis[Symbol.for("Bun.lazy")] and make $lazy real, or take a diff approach to this.
  • Changes how native c++ modules are formatted to be a bit easier for us to add more if we want.
  • Removes bun:events_native. it is now $lazy('events'), we should fully remove this later.
  • Moves bun:jsc into a native module
  • process.binding('constants') into native code, add ProcessBindingConstants and $processBindingConstants
  • a few specific strings to process.binding() will throw issues with github issue links.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2023

@paperdave 4 files with test failures on linux-x64:

  • test/bundler/bundler_browser.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/third_party/prisma/prisma.test.ts
  • test/js/web/fetch/fetch.test.ts

View test output

#c79b96d021ad8ea844ec3c5b04cc81ebaf2a2bb7

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2023

@paperdave 3 files with test failures on linux-x64-baseline:

  • test/bundler/bundler_browser.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/web/fetch/fetch.test.ts

View test output

#c79b96d021ad8ea844ec3c5b04cc81ebaf2a2bb7

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2023

@paperdave 2 files with test failures on bun-darwin-aarch64:

  • test/bundler/bundler_browser.test.ts
  • test/js/bun/test/test-test.test.ts

View test output

#c79b96d021ad8ea844ec3c5b04cc81ebaf2a2bb7

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2023

@paperdave 7 files with test failures on bun-darwin-x64-baseline:

  • test/bundler/bundler_browser.test.ts
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts
  • test/js/bun/spawn/spawn.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/node/child_process/child_process-node.test.js
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setTimeout.test.js

View test output

#c79b96d021ad8ea844ec3c5b04cc81ebaf2a2bb7

@paperdave paperdave force-pushed the dave/commonjs branch 2 times, most recently from 230f5bb to 0ed39c7 Compare July 30, 2023 23:18
@paperdave paperdave marked this pull request as draft July 30, 2023 23:19
@paperdave paperdave marked this pull request as ready for review August 2, 2023 01:11

DEFINE_VISIT_CHILDREN_WITH_MODIFIER(template<unsigned passedNumberOfInternalFields>, JSInternalFieldObjectImpl<passedNumberOfInternalFields>);

} // namespace JSC
Copy link
Member Author

Choose a reason for hiding this comment

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

explanation: added JSInternalFieldObjectImplInlines.h which fixes needing this copypaste

sadffdsa

stuff

finish commonjs stuff

asdf

not done but work

not done but work

not done yet but this is how far i am

remove files

lol

update built files

uncomment everything in events lol

export default

stuff
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2023

zig fmt errors have been resolved. Thank you.

#c79b96d021ad8ea844ec3c5b04cc81ebaf2a2bb7
zig v0.11.0-dev.4006+bf827d0b5

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2023

prettier errors have been resolved. Thank you.

#c79b96d021ad8ea844ec3c5b04cc81ebaf2a2bb7

@Jarred-Sumner Jarred-Sumner merged commit c2a77cf into main Aug 2, 2023
15 of 18 checks passed
@Jarred-Sumner Jarred-Sumner deleted the dave/commonjs branch August 2, 2023 23:27
@kanashimia kanashimia mentioned this pull request Aug 3, 2023
trnxdev pushed a commit to trnxdev/bun that referenced this pull request Aug 9, 2023
* stfdsafsd

sadffdsa

stuff

finish commonjs stuff

asdf

not done but work

not done but work

not done yet but this is how far i am

remove files

lol

update built files

uncomment everything in events lol

export default

stuff

* afdsafsd

* its not perfect but almost done

* okay

* cool

* remove temp file

* finish rebase

* revert settings.json

* a

* ch-ch-ch-ch-changes

* okay

* remove this check in release for now

* sxdcfghnjm,

* lkjhgf

* fmt

* filename can be null

* Update NodeModuleModule.h

* weee

* fmt

---------

Co-authored-by: Jarred Sumner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants