-
Notifications
You must be signed in to change notification settings - Fork 260
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
Overhaul monorepo tooling #201
Overhaul monorepo tooling #201
Conversation
I'm all for improving the monorepo setup (it's in a poor state right now), but why do we need to switch to Turbo repo over pnpm? What benefits would that deliver and what are the cons? |
Turbo is a layer on top of pnpm to start so the core remains, but the main benefits are dependency tracking in builds so package A depends on B used by app C, second is caching policies so avoiding continual rebuilds but tracking when a rebuild is needed for all downstream dependents, also applies to things like type checks, tests, etc. also provides a clear set structure for adding new tasks and making sure they get linked together along with a good TUI for looking at logs and behaviour across a few builds at once for example, other smaller wins include remote caching if configured. especially becomes more helpful as things scale for example having 20 plugin packages at some point |
Example of smoother process so far, synced branch with main,
|
Sweet! I'm not too opinionated on the build tooling / monorepo setup, so if this delivers tangible benefits with minimal maintenance overhead, I'm excited to get it checked in! 🙏🏻 |
@benjreinhart Are you okay if I setup proper packaging instead of doing a pile of tsc and cp moves to make things easier to track as regular packages since the way |
Yes, that would be great. Most of our tooling was setup in a rush without much thought so if you see concrete areas of improvement I'm happy to accept. |
Alright great, thank you for the quick feedback |
@benjreinhart Can I get a quick meeting with you to go over restructuring the internal packages inside |
Officially ready to go as simple as turbo dev
# or
turbo start |
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 is a great improvement, over all of the relative path and custom building.
(Let's wait for @benjreinhart stamp to merge though, he is running final checks on building)
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 looks super awesome. Everything for dev seems 👌🏻 . Still need to test that the builds and deploys to NPM do everything expected (e.g., migrations), but I'm expecting this is to work great.
Thank you so much for this, will follow up with a once we test the npm deploys.
🙏🏻
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.
Found two more issues. I think once these get fixed we'll likely be good.
My acceptance criteria here includes:
- If I run
pnpm start
from a clean slate (no~/.srcbook
directory), it should work. - If I have an existing
~/srcbook
directory with srcbook state and runpnpm start
, it should work and I should see all my existing srcbooks / data.
packages/web/package.json
Outdated
@@ -6,7 +6,7 @@ | |||
"scripts": { | |||
"dev": "vite", | |||
"prebuild": "rm -rf ./dist", | |||
"build": "tsc && vite build", | |||
"build": "tsc && vite build && cp -R ./dist ../../srcbook/public", |
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 copies dist
into public
such that it's public/dist/{files}
but the express server is expecting public/{files}
.
I think changing it to cp -R ./dist/. ../../srcbook/public
will work
srcbook/src/server.mjs
Outdated
|
||
// This is important. It will create and setup the database. Import this second. | ||
import '../lib/db/index.mjs'; | ||
configureDB(); |
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 something with these changes has caused an error when starting srcbook for the first time. If I delete my ~/.srcbook
directory, and run pnpm start
, then I see the following:
srcbook:start: cache miss, executing b8b61b96f22ab5f1
srcbook:start:
srcbook:start:
srcbook:start: > [email protected] start /Users/ben/Desktop/axflow/srcbook/srcbook
srcbook:start: > ./bin/cli.mjs start
srcbook:start:
srcbook:start: /Users/ben/Desktop/axflow/srcbook/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:65
srcbook:start: throw new TypeError('Cannot open database because the directory does not exist');
srcbook:start: ^
srcbook:start:
srcbook:start: TypeError: Cannot open database because the directory does not exist
srcbook:start: at new Database (/Users/ben/Desktop/axflow/srcbook/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:65:9)
srcbook:start: at file:///Users/ben/Desktop/axflow/srcbook/packages/api/dist/db/index.mjs:15:16
srcbook:start: at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
srcbook:start: at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)
srcbook:start: at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:119:5)
srcbook:start:
srcbook:start: Node.js v22.1.0
srcbook:start: ELIFECYCLE Command failed with exit code 1.
srcbook:start: ERROR: command finished with error: command (/Users/ben/Desktop/axflow/srcbook/srcbook) /Users/ben/.nvm/versions/node/v22.1.0/bin/pnpm run start exited (1)
srcbook#start: command (/Users/ben/Desktop/axflow/srcbook/srcbook) /Users/ben/.nvm/versions/node/v22.1.0/bin/pnpm run start exited (1)
Unfortunately, I remember this being a weird sequence of events to get right when we coded this up. Perhaps that's what ended up making some of this code confusing / gross.
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.
@benjreinhart Most annoying thing ever to debug relative import order through compilation and how it gets ranked but solved it by doing initialization inside db before creating the db instance like so
import path from 'node:path';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';
import * as schema from './schema.mjs';
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
import { DIST_DIR, SRCBOOKS_DIR } from '../constants.mjs';
import fs from 'node:fs';
// We can't use a relative directory for drizzle since this application
// can get run from anywhere, so use DIST_DIR as ground truth.
const drizzleFolder = path.join(DIST_DIR, 'drizzle');
const DB_PATH = `${process.env.HOME}/.srcbook/srcbook.db`;
// Creates the HOME/.srcbook/srcbooks dir
fs.mkdirSync(SRCBOOKS_DIR, { recursive: true });
export const db = drizzle(new Database(DB_PATH), { schema });
migrate(db, { migrationsFolder: drizzleFolder });
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 haven't attempted an npm publish yet, but I feel pretty confident about these changes and everything is working great locally.
Thank you for this!!
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.
Whoops, I just noticed that the dev command (pnpm run dev) is not working. I think it's cause of the deletion of initialization.mts.
@benjreinhart Fixed it missed that because it's a call on a pre script to another scrip, fixed now my bad |
I tried deploying and have found a weird issue: the Debugging now, but wanted to add convo here for context:
Update: I see the issue. This now requires us to deploy |
Deploying the api package aside, I don't understand why that error happened but I would also use |
I can definitely look into it, I haven't seen the issue yet but always try running force as a fallback, but this means some set of the dependency tracking might not be working. |
Checklist