-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add root-level package.json and set up workspaces. #37
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
As vercel only permits serverless functions on the backend (https://vercel.com/templates/other/fastify-serverless-function), I don't build the backend project locally, but instead deploy to a dev instance of vercel using the I have checked that the backend still function the same as before and I am happy for this change to merge as long as the front-end deployment is fixed :) |
I think we ran into this. https://stackoverflow.com/questions/70117752/unable-to-deploy-a-next-js-monorepo-using-workspaces-to-vercel. I'll try it with yarn and request review again when it's done. |
@cdcyang @rickycheah this change is ready for review now. You can run commands from root for your backend like this: To do things across all workspaces, you run This change includes switching over to Yarn 2 (aka Yarn modern) from npm. Migration should be relatively straightforward with https://yarnpkg.com/migration/guide. It's just the first few steps. But I want to make sure this is okay before springing it on you. |
We can go further if we need to, but this gives us the whole-project capabilities that I was looking for. It uses npm workspaces which are documented here: https://docs.npmjs.com/cli/v7/using-npm/workspaces. I also found this blog post helpful.
In order for this to work, I added a package.json at the project root, and then I had to delete all package-lock.json files from the rest of the project. But you are allowed to keep using your own package.json for better modularity. In general, install dependencies in your own package.json files and not the root one. The only dependency I included at root was ts-node to make it easy to run scripts from root since the other commands require you to be in root as well.
To compile all sub-projects:
npm exec --ws -- tsc
To run tests (or other scripts) for all sub-projects:
npm run test --workspaces --if-present
@cdcyang I made some changes to your tsconfig file to write the compiled JS to a
build/
directory – not sure how you were compiling/running things before, but this is what RA does and it keeps things tidy. I also removed the dummytest
script since it was causing errors (as intended, but it was starting to get annoying).