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

proper builds + use pnpm workspaces #396

Merged
merged 39 commits into from
Feb 1, 2023
Merged

proper builds + use pnpm workspaces #396

merged 39 commits into from
Feb 1, 2023

Conversation

felixroos
Copy link
Collaborator

@felixroos felixroos commented Jan 30, 2023

this PR adds proper builds to each package. So far, the source files were packaged as is (ES Modules / ESM), resulting in problems for CommonJS (CJS) based bundlers, see #381

With this PR, each package has a build task, which builds each index.mjs as dist/index.mjs (ESM) + dist/index.js (CJS).

In the process, I refactored the monorepo from npm workspaces to pnpm workspaces. This change was necessary to ensure a smooth package resolution.

I'll try to explain: To tell a bundler which file is the entry file, the package.json has the fields main (CJS) and module (ESM), see explanation, also this stackoverflow.

The problem: The main field is also used by the dev server to resolve packages, see bare module import.

Because of that, using the unbuilt index.mjs as main allows the dev server to instantly (hot) reload on change (it already does that), without the need to rebuild the whole package. Also, the tests can run without needing to build in advance.

If the main would contain the built CJS version, each package would need an additional watch task that checks for file changes and reruns the build. This is potentially possible with workspace watching, but slows down development + further complicates the setup. Also, the build needs to run before testing to make sure the main files are there (adding builds to git is not a nice option).

The rescue comes with pnpm and its ability to overwrite main and module on publish, using the publishConfig field, see pnpm docs. Although npm also supports publishConfig, it does not support setting main / module, see npm docs. pnpm has additional features that simplify working with monorepos. For example, I was able to find some wrong dependencies, which npm did not tell me about + pnpm is much faster. The only downside is that pnpm requires an additional install via npm i pnpm -g + using npm won't work.

I have already tested the publishing, releasing 0.6.x versions: https://www.npmjs.com/search?q=%40strudel.cycles
Finally, using the strudel packages should be possible in all common scenarios, e.g. using codesandbox.

Also, I've started to update the core examples, the rest will follow.

@felixroos felixroos marked this pull request as ready for review February 1, 2023 19:47
@felixroos felixroos merged commit 9ec3fee into main Feb 1, 2023
@felixroos felixroos deleted the pnpm branch February 1, 2023 21:17
@m-onz
Copy link

m-onz commented Feb 8, 2023

Nice 1.

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.

2 participants