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

Compile to CJS and ESM #1564

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

NullVoxPopuli
Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli commented Jul 31, 2023

very wip

at the time of pushing, I've run in to:

 ERROR  run failed: Invalid package dependency graph: cyclic dependency detected:
	@embroider/macros,@embroider/core
Turbo error: Invalid package dependency graph: cyclic dependency detected:
	@embroider/macros,@embroider/core

which may require untangling the package cycle

Why turbo?

When moving from a one-build-across-the-whole-repo to a build per package, we need to build packages in the "correct order", for example, @embroider/core needs to be built before @embroider/addon-dev. Turbo is really good at this.

We only need turbo for script order orchestration, and we don't really care about anything else.

Why build-per-package

the way we've used tsc, transpiles each file co-located to the original source location. tsc does not provide a way to build to multiple targets at once -- additionally, tsc does not provide a way to change the file extension depending on target -- rollup is really good at this.

the way people have used tsc for multi-target projects outside of embroider is to have a tsc build per project, where they can specify a separate output directory (dist/cjs and dist/esm, for example) -- but this breaks the ability to typecheck the whole repo at once.

Build types can happen with tsc still with some "clever CLI args". I want to keep the ts setup mostly the same in this PR, and we can iterate on doing other things with tsc later, but this would allow us to keep monorepo-wide type-checking (pnpm tsc --watch --noEmit, for example)

Why test packages?

when determinining the package graph, we must ignore cycles. Because devDependencies are no different from dependencies when it comes to "what must be built in what order", we have to untangle the graph. Extracting a test package for relevant packages is one way to untangling cycles in the graph.

What do we lose with this approach?

simplicity
the single tsc strategy is very simple, and easy to maintain -- with one build per project we have a lot more files / configs to maintain.

  • package.json#exports
  • rollup.config.mjs's -- though most of this is extracted to @embroider/build (a new private/internal package)

What we keep

the ability to code anywhere, and see errors everywhere

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.

1 participant