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: Remove the primer-app workspace, flatten to one project. #547

Merged
merged 3 commits into from
Oct 10, 2022

Conversation

dhess
Copy link
Member

@dhess dhess commented Oct 10, 2022

This takes #546 one step farther and removes workspaces altogether.

dhess added 2 commits October 10, 2022 02:43
We do this for the following reasons:

* We want to get rid of the `primer-types` package, which duplicates
types exported from the Primer API. However, in the process of doing
this, we ran into some long-standing upstream issues (described in
#545) which seem to be
related to using React Hooks defined in one package but used in
another.

* I originally chose this particular project organization so that we
could decouple Storybook.js from the frontend application, because I
was worried that, if they were integrated into the same package,
issues with Storybook and new versions of React would hold up
development of the frontend. However, we've already successfully made
the transition from React v17 to v18, and Storybook.js was ready
before we were, so this hasn't been an issue in practice.

* Interactive development would be simpler, and possibly faster, if we
unified the packages.

The refactoring here could probably be improved, but this was the
simplest first step I could come up with. The next most obvious step
is to remove the `primer-app` workspace and move to just a flat
package.

Note that I have *not* actually removed the `primer-types` types in
this commit: I've only moved them into a single `Types.ts` file.
@dhess dhess changed the title dhess/flatten refactor: Remove the primer-app workspace, flatten to one project. Oct 10, 2022
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 10, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: bb37048
Status: ✅  Deploy successful!
Preview URL: https://fe86334b.primer-app.pages.dev
Branch Preview URL: https://dhess-flatten.primer-app.pages.dev

View logs

@dhess
Copy link
Member Author

dhess commented Oct 10, 2022

Note that this PR has one very bad side effect: if you have a .direnv directory at top-level (because you're using direnv to automatically enter the Nix shell in your editor, shell, etc.), then vite becomes very very slow. It is obviously poking around in .direnv for some reason, even though it has not been told to look for any source files there. I'm looking into how to tell it to completely ignore that directory, but if this is not possible, we'll have to move the Node project to a subdirectory of the repo, assuming we want to merge this PR and commit to a single project in the first place.

edit: Fixed in bb37048.

This fixes the issue described here:

#547 (comment)

It does so by configuring `direnv` to write its cache for this project
in `~/.cache/direnv/layouts`. This is a bit intrusive, but without
this workaround, `vite` commands search the local `.direnv` cache for
dependencies, and it adds about 10 seconds or more to every `vite`
command. Note that the fix comes from here:

https://github.com/direnv/direnv/wiki/Customizing-cache-location

Before falling back to this workaround, I also tried the following
Vite configuration tricks, but none of them worked:

https://vitejs.dev/config/server-options.html#server-watch
https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-exclude

There are multiple (somewhat) related issues currently filed on Vite
which suggest that convincing Vite not to look everywhere in the
project root directory is a known issue:

https://github.com/vitejs/vite/pull/8778/files
vitejs/vite#7363
vitejs/vite#8341
@dhess
Copy link
Member Author

dhess commented Oct 10, 2022

I'm going to merge this even with the known local Storybook development issue. I will file an issue and come back to it when I have time. Please let me know if this is a priority for your particular development process.

edit: Tracked in #548

@dhess dhess added the Ready to merge Ready to merge label Oct 10, 2022
@dhess dhess merged commit bb37048 into main Oct 10, 2022
@dhess dhess deleted the dhess/flatten branch October 10, 2022 11:24
@dhess dhess temporarily deployed to Production October 10, 2022 11:24 Inactive
@github-actions github-actions bot temporarily deployed to Production October 10, 2022 11:25 Inactive
dhess added a commit that referenced this pull request Oct 18, 2022
What we initially thought was a Storybook issue (see
#548) turns out to be
some sort of Vite HMR problem with the way we were exporting our
component classes. See
#546 (comment)
for details of how the issue manifested in Storybook, and
#548 (comment)
for details of how one could trigger it from `pnpm watch` on the
application itself.

Somehow this issue only manifested once we merged our components into
a single project alongside the application code in
#547, possibly because
we're now importing the components directly from the filesystem,
rather than via an intra-workspace package dependency.

It's not precisely clear what is happening here, nor why the changes
in this commit fix it, but given the constant parade of module- and
import-related issues endemic to the JavaScript ecosystem, frankly I'm
not sure we really care to dive in and figure it out.

Suffice to say that, in addition to fixing the issue at hand, this
commit also simplifies the definition of our components by removing a
boilerplate-y `index.tsx` file that simply re-exports the definitions
defined in the "home" `.tsx` file.

Closes #548
@dhess dhess mentioned this pull request Oct 18, 2022
dhess added a commit that referenced this pull request Oct 18, 2022
What we initially thought was a Storybook issue (see
#548) turns out to be
some sort of Vite HMR problem with the way we were exporting our
component classes. See
#546 (comment)
for details of how the issue manifested in Storybook, and
#548 (comment)
for details of how one could trigger it from `pnpm watch` on the
application itself.

Somehow this issue only manifested once we merged our components into
a single project alongside the application code in
#547, possibly because
we're now importing the components directly from the filesystem,
rather than via an intra-workspace package dependency.

It's not precisely clear what is happening here, nor why the changes
in this commit fix it, but given the constant parade of module- and
import-related issues endemic to the JavaScript ecosystem, frankly I'm
not sure we really care to dive in and figure it out.

Suffice to say that, in addition to fixing the issue at hand, this
commit also simplifies the definition of our components by removing a
boilerplate-y `index.tsx` file that simply re-exports the definitions
defined in the "home" `.tsx` file.

Closes #548
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready to merge Ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants