Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions astro/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd astro
npx lint-staged
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use node --run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimised in 2574c92

Copy link
Member

@jonchurch jonchurch Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjohansebas was the goal to avoid using npm? this approach requires we add a passthrough "lint-staged": "lint-staged" script, which isnt something Im used to seeing.

I wanted to suggest using the --cwd arg to lint-staged and dropping the lint-staged script, but npm exec (npx replacement) wont be able to detect the installed bin if we don't help it discover a package.json

npm exec lint-staged --cwd astro

Im being pedantic here a bit, but we could instead drop the cd and the script by setting the npm prefix, which is how you tell npm to act as if it is in that dir and do its resolution from there:

npm exec --prefix astro lint-staged

but lint-staged does care about cwd for its config lookup, so to avoid cd we'd need...

npm exec --prefix astro lint-staged -- --cwd astro

That sucks though and is cursed lol, so cd is fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accepted this because of performance. Since we are on Node 24, it is significantly faster than npx or npm run (it avoids the npm CLI startup overhead).

You're right that it requires the 'passthrough' script in package.json which is the trade off for that speed boost. I agree that the --prefix and --cwd alternatives feel a bit 'cursed' the current cd approach keeps it readable while staying fast. Once we move everything to the root, we can simplify this even further.

41 changes: 31 additions & 10 deletions astro/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"format": "prettier --write .",
"format:check": "prettier --check .",
"check": "npm run format:check && npm run lint",
"fix": "npm run format && npm run lint:fix"
"fix": "npm run format && npm run lint:fix",
"prepare": "cd .. && husky astro/.husky"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This automatically setup git hook using husky right after the dependencies are finished installing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the site is in the root, won’t this be necessary anymore? I think Husky already handles that for us. I just want to confirm that this is temporary and not something that will always stay there, because in all the Husky configurations I’ve had, this is the first time I’ve seen it done this way (or maybe my memory is failing me already 😅 the exhaustion haha).

Copy link
Member Author

@ShubhamOulkar ShubhamOulkar Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is temporary. Right now the project uses a subfolder structure, so Husky needs the path to the .git root. Once the site is moved to the root, we'll switch to the standard "prepare": "husky" command.

This will help to anyone contributing to redesign branch gets their local environment setup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjohansebas is your question whether the prepare script is temporary? Or the cd .. part of it?

prepare is necessary for husky to configure git to be aware of the git hooks. its something you can't keep in version control, the repo gitconfig to point to the script location (.husky). Their docs show this specific cd example for when the package.json is not at git root: https://typicode.github.io/husky/how-to.html#project-not-in-git-root-directory

It is one time setup, but setup that needs to be run whenever someone clones the repo fresh (like when a new contributor forks the repo).

It's one of the downsides to these kinda of git hook tools, there is setup that cannot be checked in and must be run on clone.

},
"dependencies": {
"@astrojs/mdx": "^4.3.13",
Expand All @@ -39,12 +40,22 @@
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-astro": "^1.5.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"husky": "^9.1.7",
"lint-staged": "^16.2.7",
"postcss-custom-media": "^12.0.0",
"postcss-nested": "^7.0.2",
"prettier": "^3.8.1",
"prettier-plugin-astro": "^0.14.1",
"typescript": "^5.9.3",
"typescript-eslint": "^8.53.1"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,astro}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,css}": [
"prettier --write"
]
}
}