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

refactor(dev): simplify compiler #4410

Merged
merged 17 commits into from
Oct 28, 2022
Merged

refactor(dev): simplify compiler #4410

merged 17 commits into from
Oct 28, 2022

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Oct 24, 2022

Refactored the compiler to be architected around BrowserCompiler, ServerCompiler. Notably, each of these have a compile function that can be called once for the initial build, but can be called again subsequently for rebuilds. This greatly simplifies the mental model for the Remix compiler and cuts down the code in watch. Other changes include:

  • Previously, we used a a ref to the assets manifest promise to coordinate the browser and server builds. The ref was also reused across rebuilds. There were checks in watch and within the serverAssetsManifestPlugin to make sure the ref was set before being accessed. Overall, this approach was error prone and hard to reason about. This has now been replaced with a Golang-style channel so that the browser build can explicitly communicate the assets manifest to the server build.

  • Previously, writing the assets manifest and the server build to the file system needed to be done anywhere in the code where we built the browser and server bundles. This was easy to forget and resulted in duplication. Now, the compile function for the browser and server compilers managed writing the results (including the assets manifest) to the filesystem.

Note that the build and watch APIs for the compiler stayed the same (with the minor exception of renaming onBuildFailure to onCompilerFailure).

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2022

⚠️ No Changeset found

Latest commit: f644f86

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pcattori pcattori marked this pull request as ready for review October 24, 2022 21:00
@pcattori pcattori requested review from mcansh and jacob-ebey October 24, 2022 21:00
@pcattori pcattori marked this pull request as draft October 24, 2022 23:35
@pcattori pcattori force-pushed the pedro/compiler-refactor branch 2 times, most recently from 6e69ead to 9867975 Compare October 25, 2022 20:15
@pcattori pcattori requested a review from mjackson October 26, 2022 17:32
@pcattori pcattori force-pushed the pedro/compiler-refactor branch from 808c104 to 346211f Compare October 26, 2022 17:34
@pcattori pcattori force-pushed the pedro/compiler-refactor branch 5 times, most recently from bf346af to 1a67594 Compare October 27, 2022 01:43
@pcattori pcattori changed the title Compiler refactoring refactor(dev): refactor compiler Oct 27, 2022
@pcattori pcattori changed the title refactor(dev): refactor compiler refactor(dev): simplify compiler Oct 27, 2022
@pcattori pcattori force-pushed the pedro/compiler-refactor branch 2 times, most recently from b91bdde to 225bdea Compare October 27, 2022 16:38
@pcattori pcattori force-pushed the pedro/compiler-refactor branch from 225bdea to f644f86 Compare October 27, 2022 19:34
@pcattori pcattori marked this pull request as ready for review October 27, 2022 19:34
@@ -87,7 +87,7 @@ export async function createAssetsManifest(
);
let route = routesByFile.get(entryPointFile);
invariant(route, `Cannot get route for entry point ${output.entryPoint}`);
let sourceExports = await getRouteModuleExportsCached(config, route.id);
let sourceExports = await getRouteModuleExports(config, route.id);
Copy link
Member

Choose a reason for hiding this comment

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

why aren't we using the cached one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are. I renamed getRouteModuleExportsCached to just getRouteModuleExports since we only ever use the cached version.

@pcattori pcattori merged commit e44bfbf into dev Oct 28, 2022
@pcattori pcattori deleted the pedro/compiler-refactor branch October 28, 2022 20:04
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Oct 28, 2022
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-5020fa4-20221029 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

kentcdodds pushed a commit that referenced this pull request Dec 15, 2022
* refactor(dev): rename getRouteModuleExportsCached to getRouteModuleExports

since caching is perf improvement that is purely an implementation detail.
also remove export for uncached route exports since that is not used
anywhere.

* refactor(dev): simplify build options

using string constant unions instead of enums

* refactor(dev): split up browser and server builds into their own modules

* refactor(dev): factor out logic for finding externals

* refactor(dev): compiler interfaces for browser and server

* refactor(dev): change server assets manifest plugin to accept an assets manifest promise

* refactor(dev): do not compile server incrementally

since it depends on the assets manifest

* refactor(dev): split up build and watch into separate modules

also, split out compile failure logging into its own module

* refactor(dev): implement `build` function based on new remix compiler

* refactor(dev): rename `BuildOptions` to `CompileOptions` and move into `compiler/` directory

* refactor(dev): watch

* refactor(dev): compiler index module

* refactor(dev): camelCase filenames

* refactor(dev): update imports and types for compiler in `commands`

* test(dev): fix type errors

* test(dev): remove outdated, unused test

test was hardcoded to be skipped everytime and referenced the old rollup-based compiler and old gist
app

* refactor(dev): rename `onBuildFailure` to `onCompileFailure`
TrySound added a commit to webstudio-is/webstudio that referenced this pull request Dec 31, 2022
https://github.com/remix-run/remix/releases/tag/remix%401.7.0
https://github.com/remix-run/remix/releases/tag/remix%401.7.4

du -ckd1 node_modules
-795648
+798524

Not much changes though I found since [1.7.5](https://github.com/remix-run/remix/releases/tag/remix%401.7.5) build started to hang when run with turbo or recursive pnpm run.

Looks like in this commit some stream or connection not closed when
build is finished.

remix-run/remix#4410

Let's see if not fixed in newer versions and then file an issue.
TrySound added a commit to webstudio-is/webstudio that referenced this pull request Jan 3, 2023
https://github.com/remix-run/remix/releases/tag/remix%401.7.0
https://github.com/remix-run/remix/releases/tag/remix%401.7.4

du -ckd1 node_modules
-795648
+798524

Not much changes though I found since
[1.7.5](https://github.com/remix-run/remix/releases/tag/remix%401.7.5)
build started to hang when run with turbo or recursive pnpm run.

Looks like in this commit some stream or connection not closed when
build is finished.

remix-run/remix#4410

Let's see if not fixed in newer versions and then file an issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed package:dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants