Skip to content

Commit e28fbef

Browse files
stefanvrowanc1
andauthored
Advice on how to grep myst codebase (#2488)
Co-authored-by: Rowan Cockett <[email protected]>
1 parent b8ed7ca commit e28fbef

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

docs/developer.md

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ If you are familiar with these tools, you should not find many surprises in the
6969
That said, there are a couple of concepts used _only_ in this project, that won't be familiar. These are detailed below:
7070

7171
(develop-renderers-themes)=
72+
7273
### Concepts: Renderers, themes, and templates
7374

7475
In the diagram above, we saw that `mystmd` produces websites by:
@@ -107,6 +108,7 @@ MyST has multiple renderers, themes, and templates that allow it to transform My
107108
- describe the render loop, and how render blocks are registered
108109
- explain the ThemeProvider
109110
- explain styling
111+
110112
:::
111113

112114
#### Example: Adding an "edit this page" button
@@ -247,7 +249,6 @@ During the **Transformations** phase, a number of [enumeration transforms](https
247249
html_id: label
248250
```
249251

250-
251252
## Tools used in development
252253

253254
`mystmd` is built and developed using:
@@ -264,6 +265,7 @@ These are simply aliases for other commands, defined in the [`package.json` file
264265
```
265266

266267
(developer:mystmd)=
268+
267269
## Local development: `mystmd`
268270

269271
The `mystmd` libraries and command line tools are written in [TypeScript](https://www.typescriptlang.org/), and require [NodeJS and npm](https://nodejs.org) for local development.
@@ -374,7 +376,7 @@ Note that you can run `npm run dev` from within any folder if you'd like to watc
374376

375377
### Approach 2: Static build
376378

377-
No content or theme server is required for a static site build. Steps are:
379+
No content or theme server is required for a static site build. Steps are:
378380

379381
1. Build the theme for production
380382
2. Point your site config to the built theme
@@ -384,7 +386,7 @@ We'll use the mystmd docs site as an example.
384386

385387
#### Build theme
386388

387-
To build a static site against a local theme, the theme must be built as it would be for production. For that we will use the "make" target
389+
To build a static site against a local theme, the theme must be built as it would be for production. For that we will use the "make" target
388390
instead of `npm run`:
389391

390392
```{code} bash
@@ -395,7 +397,7 @@ make build-book # because mystmd docs site uses the book theme
395397
That should produce a production ready version of the book theme under `.deploy/book`.
396398

397399
:::{tip}
398-
While debugging, it helps to work with a theme built against the "development" version of React, which results in unminimized build artifacts (ie preserving whitespace and variable/function names) and more detailed React errors and warnings. For this, tell remix to run in node "development" mode:
400+
While debugging, it helps to work with a theme built against the "development" version of React, which results in unminimized build artifacts (ie preserving whitespace and variable/function names) and more detailed React errors and warnings. For this, tell remix to run in node "development" mode:
399401

400402
```{code} json
401403
:filename: myst-theme/themes/book/package.json
@@ -404,11 +406,12 @@ While debugging, it helps to work with a theme built against the "development" v
404406
"prod:build": "... && NODE_ENV=development remix build",
405407
^
406408
```
409+
407410
:::
408411

409412
#### Configure site
410413

411-
Building a static site against a local theme requires configuring your site's `myst.yml` to point to the built theme's `template.yml`. Using the mystmd docs site as
414+
Building a static site against a local theme requires configuring your site's `myst.yml` to point to the built theme's `template.yml`. Using the mystmd docs site as
412415
an example:
413416

414417
```{code} yaml
@@ -417,6 +420,7 @@ site:
417420
# assuming your mystmd and myst-theme working directories are siblings
418421
template: ../../myst-theme/.deploy/book/template.yml
419422
```
423+
420424
(NOTE: This is the _built_ template file, under `.deploy`, not the source template)
421425

422426
#### Build site
@@ -426,7 +430,8 @@ cd mystmd/docs
426430
mystmd build --html
427431
```
428432

429-
Then host the static site locally. An easy way is with Python's built-in http server:
433+
Then host the static site locally. An easy way is with Python's built-in http server:
434+
430435
```{code} bash
431436
cd _build/html
432437
python3 -m http.server # serves on port 8000 by default
@@ -436,18 +441,18 @@ Finally, browse the site at [http://localhost:8000](http://localhost:8000).
436441

437442
## Step Debugging
438443

439-
Sometimes the trusty `console.log` (aka print statement) is not sufficient for your debugging needs. In more involved situations, a proper step debugger can be your friend.
444+
Sometimes the trusty `console.log` (aka print statement) is not sufficient for your debugging needs. In more involved situations, a proper step debugger can be your friend.
440445
You may have used Firefox or Chrome developer tools to debug in-browser code by adding the `debugger` keyword into your javascript source.
441446
But what about code that runs in node engine on the server?
442-
Chrome and Firefox dev tools can _also_ debug server-side javascript. To do this, node must be invoked with the `--inspect`
443-
or `--inspect-brk` comand-line option. That will cause the node process to open a socket listening for a debugger to connect. If "inspect-brk" is used
444-
(vs "inspect"), then the process will immediately pause, awaiting a debugger connection. The `debugger` keyword in source will only pause the program if a
447+
Chrome and Firefox dev tools can _also_ debug server-side javascript. To do this, node must be invoked with the `--inspect`
448+
or `--inspect-brk` comand-line option. That will cause the node process to open a socket listening for a debugger to connect. If "inspect-brk" is used
449+
(vs "inspect"), then the process will immediately pause, awaiting a debugger connection. The `debugger` keyword in source will only pause the program if a
445450
debugger is connected when that keyword is reached.
446451

447452
To connect to an awaiting node debug socket, enter into the browser address bar:
448453

449454
- Firefox: `about:debugging`, or
450-
- Chrome: `chrome://inspect`
455+
- Chrome: `chrome://inspect`
451456

452457
That opens a debugger control panel in the browser which should list your awaiting node process as available to connect to (if it has been correctly invoked).
453458
(NOTE: other browsers and IDEs can also connect as debug inspectors - see Inspector Clients reference below)
@@ -465,6 +470,7 @@ For example, to debug myst-theme's book theme running as a dynamic application s
465470
// v
466471
"dev": "npm run dev:copy && npm run build:thebe && concurrently \"npm run dev:css\" \"NODE_OPTIONS=--inspect-brk remix dev\"",
467472
```
473+
468474
Now remove the turbo "--parallel" option, because when turbo runs the theme server in "parallel" (ie multiprocess) mode, each process will attempt to open its own debug socket on the same port, with all but the first failing.
469475
Then your debugger will only connect to the one that succeeded, with no guarantee any subsequent web request will hit the one process connected to the debugger.
470476

@@ -483,7 +489,7 @@ To debug myst-theme running server-side in service of a static build:
483489

484490
### Debug a mystmd subpackage test suite
485491

486-
This requires a handful of options to be passed to vitest to ensure it runs in a single process. For example, to connect a step debugger to a running `myst-transforms` test:
492+
This requires a handful of options to be passed to vitest to ensure it runs in a single process. For example, to connect a step debugger to a running `myst-transforms` test:
487493

488494
```{code} json
489495
:filename: mystmd/packages/myst-transforms/package.json
@@ -494,9 +500,10 @@ This requires a handful of options to be passed to vitest to ensure it runs in a
494500

495501
- [Node Inspector Clients](https://nodejs.org/en/learn/getting-started/debugging#inspector-clients)
496502

497-
498503
## Infrastructure we run
504+
499505
(myst-api-server)=
506+
500507
### The MyST API server
501508

502509
We run a lightweight server at [`api.mystmd.org`](https://api.mystmd.org/) to help users resolve and download templates. The code for this exists at [the `myst-templates/templates` repository](https://github.com/myst-templates/templates).
@@ -525,6 +532,7 @@ To publish a new release of `mystmd`, we do two things:
525532
We describe each below.
526533

527534
(release-npm)=
535+
528536
#### Publish a `mystmd` release to NPM
529537

530538
- Find the **changesets** PR. This contains a list of the version updates that will be included with this release. [Here's an example of a release PR](https://github.com/jupyter-book/mystmd/pull/1896).
@@ -536,6 +544,7 @@ We describe each below.
536544
- Next, [make a release on GitHub](#release-github).
537545

538546
(release-github)=
547+
539548
#### Automated releases on GitHub
540549

541550
After a successful NPM release, our [`release.yml` workflow](https://github.com/jupyter-book/mystmd/blob/main/.github/workflows/publish-github-release.yml) will automatically create a new GitHub Release. The release notes are generated using [`github-activity`](https://github.com/cheukting/github-activity) and include a summary of all merged PRs and commits since the previous release.
@@ -544,10 +553,11 @@ After a successful NPM release, our [`release.yml` workflow](https://github.com/
544553

545554
You can find the latest releases at: https://github.com/jupyter-book/mystmd/releases
546555

547-
When you've confirmed the release has been made, consider sharing it for others to discover!
556+
When you've confirmed the release has been made, consider sharing it for others to discover!
548557

549558
:::{note} Here's an announcement snippet you can copy/paste
550559
:class: dropdown
560+
551561
```md
552562
TITLE: 🚀 Release: MySTMD v1.3.26
553563

@@ -558,8 +568,8 @@ The [Jupyter Book project](https://compass.jupyterbook.org) recently made a new
558568

559569
See the link above for the release notes on GitHub! Many thanks to the [Jupyter Book team](https://compass.jupyterbook.org/team) for stewarding our development and this release.
560570
```
561-
:::
562571

572+
:::
563573

564574
**Here are a few Jupyter-adjacent spaces to share with** (you can just copy/paste the same text into each):
565575

@@ -569,6 +579,7 @@ See the link above for the release notes on GitHub! Many thanks to the [Jupyter
569579
- Social media spaces of your choosing.
570580

571581
(release-myst-theme)=
582+
572583
### Make a release of the `myst-theme`
573584

574585
The process for releasing `myst-theme` infrastructure is similar to the release process for `mystmd`. Here's a brief overview:
@@ -586,6 +597,7 @@ The process for releasing `myst-theme` infrastructure is similar to the release
586597
We use [Turbo](https://turborepo.com/) to manage our testing and build system.
587598

588599
(developer:testing)=
600+
589601
### Testing
590602

591603
We use [vitest](https://vitest.dev/guide/) for all tests in `mystmd`.
@@ -728,3 +740,20 @@ These packages are [ESM modules](https://gist.github.com/sindresorhus/a39789f988
728740
- `citation-js-utils`: utility functions to deal with citations.
729741
- `myst-cli-utils`: shared utils between jtex, and myst-cli.
730742
- `simple-validators`: validation utilities, that print all sorts of nice warnings.
743+
744+
## Tips and tricks
745+
746+
### Grepping the codebase
747+
748+
While developing, there are a lot of build artifacts lying around,
749+
making grepping the code harder than it needs to be. Assuming you
750+
have
751+
[ripgrep](https://github.com/BurntSushi/ripgrep?tab=readme-ov-file#installation)
752+
or a compatible alternative installed, you can define a customized
753+
"myst grep" in your shell config (`~/.zshrc`, `~/.bashrc`, etc.):
754+
755+
```sh
756+
alias mg="rg --exclude-dir=build --exclude-dir=_build -g '!*.js' -g '!tailwind.css'"
757+
```
758+
759+
Most notably, this excludes `.js` files, which are generated from TypeScript.

0 commit comments

Comments
 (0)