-
Notifications
You must be signed in to change notification settings - Fork 5
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
chore: use preconstruct to manage monorepo #37
Conversation
Since the base package isn't built or published, there's no distinction between dependencies and devDependencies. We can just put everything under `dependencies`.
These deps belong in the individual packages rather than the base `package.json`. If we have conflicting versions in the future, we can use the `resolutions` field to fix that.
"overrides": [ | ||
{ | ||
"files": "*.js", | ||
// rule overrides for js config files (next.config.js, etc.) | ||
"rules": { | ||
"@typescript-eslint/no-var-requires": "off" | ||
} | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows us to use require
statements in .js
files, which I imagine will mostly be configuration files for this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have some developer documentation as based on just looking at the diff I wasn't confident on how to actually have the same setup I had before (running Next.js' dev server and have the components auto build). After reading #37 (comment), I guessed just doing cd nextjs
and yarn run dev
but this didn't work (after modifying PackageUpload.tsx
, the change was not reflected).
- [`preconstruct`](https://preconstruct.tools/) tool takes a lot of the pain | ||
out of managing a monorepo | ||
- code behaves the same in dev as it will in production |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit 3rd person/an extract from the docs instead of more of a guide/explanation of how the tool works with/is used in the repo
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this need to be part of nextjs
?
- [`preconstruct`](https://preconstruct.tools/) tool takes a lot of the pain | ||
out of managing a monorepo | ||
- code behaves the same in dev as it will in production | ||
- packages linked locally via `preconstruct dev` (runs automatically in | ||
`postinstall` hook) without needing to manually build anything | ||
- `nextjs` workspace uses `@preconstruct/next` plugin to integrate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could include some documentation on exactly how to setup the project from after git clone
which includes how to start the Next.js dev server and having the components automatically compiled (this might change with #28 or at least how important knowing how to start Next.js is but having the commands for the typical running dev environments would help, e.g. components and storybook, components and Next.js, just Next.js (if that's even useful)).
- packages linked locally via `preconstruct dev` (runs automatically in | ||
`postinstall` hook) without needing to manually build anything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runs automatically in
postinstall
hook
From preconstruct's docs:
If you're in a monorepo, you should also run
yarn preconstruct dev
and add it to a postinstall script("postinstall": "preconstruct dev"
) that runs preconstruct dev so that you can import your code without having to rebuild your project every time in changes.
Where is this actually setup?
Basically the changes done here are the results of following this tutorial: https://monorepo.guide/getting-started . Additionally some changes are from an earlier pr (#37), which was also about setting up Preconstruct. * Add Preconstruct as dependency * Setup Babel and ESLint * Rename workspaces to use the structure used in the tutorial. I don't know if this is some convention oslt, but it seems like a nice, clear structure for the repo * Add a script for using Preconstruct, and a postinstall hook to run it automatically while devving (see root package.json) * Move all devDependencies to dependencies on root package.json. This was recommended by Preconstruct, but I can't quite recall why
Basically the changes done here are the results of following this tutorial: https://monorepo.guide/getting-started . Additionally some changes are from an earlier pr (#37), which was also about setting up Preconstruct. * Add Preconstruct as dependency * Setup Babel and ESLint * Rename workspaces to use the structure used in the tutorial. I don't know if this is some convention oslt, but it seems like a nice, clear structure for the repo * Add a script for using Preconstruct, and a postinstall hook to run it automatically while devving (see root package.json) * Move all devDependencies to dependencies on root package.json. This was recommended by Preconstruct, but I can't quite recall why
Basically the changes done here are the results of following this tutorial: https://monorepo.guide/getting-started . Additionally some changes are from an earlier pr (#37), which was also about setting up Preconstruct. * Add Preconstruct as dependency * Setup Babel and ESLint * Rename workspaces to use the structure used in the tutorial. I don't know if this is some convention oslt, but it seems like a nice, clear structure for the repo * Add a script for using Preconstruct, and a postinstall hook to run it automatically while devving (see root package.json) * Move all devDependencies to dependencies on root package.json. This was recommended by Preconstruct, but I can't quite recall why
Basically the changes done here are the results of following this tutorial: https://monorepo.guide/getting-started . Additionally some changes are from an earlier pr (#37), which was also about setting up Preconstruct. * Add Preconstruct as dependency * Setup Babel and ESLint * Rename workspaces to use the structure used in the tutorial. I don't know if this is some convention oslt, but it seems like a nice, clear structure for the repo * Add a script for using Preconstruct, and a postinstall hook to run it automatically while devving (see root package.json) * Move all devDependencies to dependencies on root package.json. This was recommended by Preconstruct, but I can't quite recall why
Basically the changes done here are the results of following this tutorial: https://monorepo.guide/getting-started . Additionally some changes are from an earlier pr (#37), which was also about setting up Preconstruct. * Add Preconstruct as dependency * Setup Babel and ESLint * Rename workspaces to use the structure used in the tutorial. I don't know if this is some convention oslt, but it seems like a nice, clear structure for the repo * Add a script for using Preconstruct, and a postinstall hook to run it automatically while devving (see root package.json) * Move all devDependencies to dependencies on root package.json. This was recommended by Preconstruct, but I can't quite recall why
Basically the changes done here are the results of following this tutorial: https://monorepo.guide/getting-started . Additionally some changes are from an earlier pr (#37), which was also about setting up Preconstruct. * Add Preconstruct as dependency * Setup Babel and ESLint * Rename workspaces to use the structure used in the tutorial. I don't know if this is some convention oslt, but it seems like a nice, clear structure for the repo * Add a script for using Preconstruct, and a postinstall hook to run it automatically while devving (see root package.json) * Move all devDependencies to dependencies on root package.json. This was recommended by Preconstruct, but I can't quite recall why
This PR makes a few changes to the project in order to use
preconstruct
for managing the monorepo.preconstruct
simplifies a few things that are typically painful in a monorepo, and I wish we were using this for Chakra, so I thought I'd propose it early here.Changes
react
/react-dom
should exist in individual packages and not the basepackage.json
package.json
is just a umbrella for the other packages and has no distinction between deps/devDeps, so we can just install all base packages as regular depspreconstruct
yarn install
thunderstore-components
atmpreconstruct.packages
inpackage.json
, and runningpreconstruct init
@preconstruct/next
plugin innext.config.js
so nextbuild
/dev
commands work the same regardless of whether we're using local dev link or prod buildWhat
preconstruct
handlesLocal package links
Normally with a monorepo, you link packages for local dev, but the consumed package needs to be rebuilt anytime it changes in order for those changes to make it to consuming packages (like
nextjs
for example). This is a real hassle and requires usingwatch
, which can be annoying if you have more than one consumed package you're working on at once.preconstruct dev
analyzes the project to link packages in the right way, and also generates a shimdist
for each package it's responsible for that just points to the source folder, so there's no need to build the package for local dev work.Build process
preconstruct build
handles the build process for all packages we make it responsible for, using a sanerollup
config andbabel
. This takes a significant amount of effort out of the build configuration process, as we can simply install thebabel
plugins/presets/transforms we want to use and allowpreconstruct
to handle the rest. Adding new buildable packages requires no additional effort.