Skip to content

Commit 621dfc1

Browse files
committed
Fix more broken tests and add documentation for repo tools
1 parent a3cec8e commit 621dfc1

File tree

11 files changed

+148
-16
lines changed

11 files changed

+148
-16
lines changed

.vscode/settings.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66
"url": "./lib/buildtools/src/build/modules/manifest.schema.json"
77
},
88
{
9-
"fileMatch": ["tsconfig.*.json"],
10-
"url": "http://json.schemastore.org/tsconfig"
9+
"fileMatch": ["tsconfig.json", "tsconfig.*.json"],
10+
"schema": {
11+
"allOf": [{ "$ref": "http://json.schemastore.org/tsconfig" }],
12+
"properties": {
13+
"typedocOptions": {
14+
"allOf": [{ "$ref": "https://typedoc.org/schema.json" }]
15+
}
16+
}
17+
}
1118
}
1219
]
1320
}

docs/.vitepress/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const sidebarConfigs: Record<string, VitePressSidebarOptions> = {
4646
buildtools: {},
4747
modules: {},
4848
lib: {},
49-
'/lib/modules-lib': {}
49+
'lib/modules-lib': {},
50+
repotools: {}
5051
};
5152

5253
const sideBarOptions = Object.entries(sidebarConfigs).map(([startPath, options]): VitePressSidebarOptions => ({

docs/src/index.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ layout: home
55
hero:
66
name: Modules Developer Documentation
77
tagline: Developer documentation for the Source Academy modules repository
8-
actions:
9-
- theme: brand
10-
text: Get Started
11-
link: /modules/1_getting-started
12-
- theme: brand
13-
text: Repo Overview
14-
- theme: alt
15-
text: Developer Instructions
16-
link: /api-examples
178

189
features:
1910
- title: Your first bundle or tab
@@ -30,4 +21,5 @@ features:
3021

3122
- title: Repository Tools
3223
details: Details for the tools used to aid in developing SA Modules
24+
link: /repotools
3325
---
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Modules Development Server
2+
3+
This server relies on [`Vite`](https://vitejs.dev) to create a server that automatically reloads when it detects file system changes. This allows Source Academy developers to make changes to their tabs without having to use the frontend, and have it render code changes live.
4+
5+
The components here were copied from the frontend's playground and then simplified.
6+
7+
## Compiled Tabs vs Hot Reload
8+
Normally, the Source Academy frontend uses the bundled version of the tabs. However, the development server relies on the raw Typescript files by default so as to enable hot reloading. If you wish to test the compiled versions, use the settings button to toggle using compiled tabs.
9+
10+
## `mockModuleContext.ts`
11+
For compiled tabs, `js-slang/context` is not an import that should be required. However, in hot-reload mode, because some tabs rely on their corresponding bundles, `js-slang/context` is an import that needs to be provided.
12+
13+
The `vite` config aliases `js-slang/context` to the `mockModuleContext.ts` file, which can then be used to simulate the evaluation context.
14+
15+
## Vitest Testing
16+
The `vitest` framework integrates with `playwright` and allows us to actually simulate user actions on the browser page. This is used to test the functionality of the development server.
17+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Developer Documentation Server
2+
3+
Originally most of the developer documentation was contained within the Github repository's wiki. However, as the documentation became more comprehensive in scope and complex in design,
4+
it was necessary to migrate to a more advanced and configurable solution.
5+
6+
This documentation server is powered by [Vitepress](https://vitepress.dev), which takes Markdown files and renders them into a static site.
7+
8+
## File Structure
9+
All pages for the server are contained under `src`.
10+
11+
[`vitepress-sidebar`](https://vitepress-sidebar.cdget.com) is being used to generate the sidebar for the server. This means that entries in the sidebar appear sorted according to the file/folder names from which they originate. This is why
12+
some folder have contents that are labelled `1-something`, `2-something` etc. Each item's value is taken from file's frontmatter, or if not present, the file's first header.
13+
14+
Folders produce item groups, the name of which can be customized using an `index.md` file within that folder.
15+
16+
```txt
17+
bundles
18+
├── index.md
19+
├── 1-getting-started
20+
│ ├── 1-overview.md
21+
│ ├── 2-start.md
22+
│ ├── 3.cheat.md
23+
│ ├── 4-faq.md
24+
│ └── index.md
25+
└── 2-bundle
26+
├── 1-overview
27+
│ └── 1-overview.md
28+
├── 2-creating
29+
│ └── 2-creating.md
30+
├── 3-editing.md
31+
├── 4-documentation
32+
│ └── 4-documentation.md
33+
├── 5-type_map.md
34+
├── 6-compiling.md
35+
└── index.md
36+
```
37+
38+
The above file structure produces the menu below:
39+
![image](./menu.png)
40+
41+
Each item takes its title value from either the frontmatter (if available) or the first heading of each page.
42+
43+
`index.md` files are only used to title the menus, they are not intended for navigation, though are navigable to if the user enters the address manually, so it is still recommended to keep some basic
44+
documentation in those pages or create rewrites so that users are automatically redirected away from those pages. Here are the contents of `2-bundle/index.md`:
45+
46+
<<< ../../modules/2-bundle/index.md
47+
48+
Instead, the links in the sidebar link to the page (if it is a markdown file), or to a child within the folder that has the same name as that folder.
49+
50+
The specific configuration for this behaviour can be found in the Vitepress config file, and the documentation for those options can be found on the Vitepress website:
51+
52+
<<< ../../../.vitepress/config.ts {33-43}
53+
54+
## Documentation for `modules-lib`
55+
The documentation for `@sourceacademy/modules-lib` is automatically generated by Typedoc. The configuration options for this generation are found in that folder. The documentation for `@sourceacademy/modules-lib` should be built before this server is built.
56+
57+
::: details help pls
58+
Supposedly Vitepress can embed React components, which would be nice for us to have working demonstrations of our React components. Unfortunately, I have never
59+
been able to get that to work. You can start [here](https://github.com/vuejs/vitepress/discussions/2183) if you want to help figure this out.
60+
:::

docs/src/repotools/docserver/index.md

Whitespace-only changes.
14 KB
Loading

docs/src/repotools/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Repository Development Tools
2+
3+
- [Development Server](./devserver/)
4+
- [Docs Server](./docserver/docserver)
5+
- [Yarn](./yarn)

docs/src/repotools/vscode.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# VSCode Integration
2+
This page is dedicated to explaining all the VSCode integrations available from this repository.
3+
4+
Since most developers here are assumed to be using Visual Studio Code, this repository automatically provides some extra tooling that integrates with VSCode, all found within the `.vscode` folder.
5+
6+
## JSON Schemas
7+
By default, VSCode doesn't apply any kind of validation to JSON files that don't have explicit schemas. Using the `settings.json` file, we can apply JSON schemas to specific JSON files.
8+
9+
For this repository, this has been configured for `tsconfig.*.json` files to extend both the original `tsconfig` schema, but also to include the Typedoc schema. Bundle manifest files
10+
should also automatically receive validation and IntelliSense autocompletion.

docs/src/repotools/yarn.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Yarn
2+
3+
This page is dedicated to explaing how Yarn has been configured to work in this repository.
4+
5+
## Workspaces
6+
Yarn, this repository's package manager, supports a feature called [workspaces](https://yarnpkg.com/features/workspaces#global-scripts), which are a way for packages to refer to one another within the same repository.
7+
8+
This has several benefits:
9+
- **Reduced install size.** Yarn workspaces support focused installs, which means that a single team working on a single bundle or tab won't have to install the entire repository's worth of packages that won't be relevant to them
10+
- **Dependency Management.** If tabs (or other bundles) rely on a specific bundle, Yarn's dependency resolution automatically determines what needs to be rebuilt and in what order.
11+
- **Automatic Worktree Detection.** If so desired, Yarn automatically detects which bundles/tabs have changed with respect to the main git branch and won't rebuild those that haven't.
12+
- **More Configurability:** Each bundle/tab can maintain its own set of dependencies now, separate from other bundles. This allows us to have patches local to a specific bundle (like the `@jscad/modeling` patch for `csg`). Also each bundle/tab can customize its own `tsconfig` etc..
13+
14+
At the root repository, this is defined using the `workspaces` field in `package.json`.
15+
16+
## Yarn Constraints
17+
Yarn also supports a feature known as [constraints](https://yarnpkg.com/features/workspaces#constraints) for workspaces. As of this moment, the feature can be used to ensure that all workspaces within a repository have fields in their `package.json`s set to specific values. We use this feature to ensure that:
18+
19+
### 1. All workspaces have `"type": "module"`.
20+
As part of ensuring consistency, everything in this repository has been designed to use ESM first and to move away from legacy reliance on CommonJS modules.
21+
22+
### 2. Dependencies, if shared, have the correct versions.
23+
Tabs, for example, should all be using the same versions of `react` and `react-dom`: the one in use by the frontend. If a dependency is specified in the root `package.json`, then the constraints file
24+
requires that all child workspaces use the version of that dependency.
25+
26+
For example, the root package specifies `react@^18.3.1` as a depdendency, so all workspaces that require React must also use that version spec.
27+
28+
This validation is not carried out across child workspaces, however. Two different bundles could use two different versions of the same package. This should not cause an issue **unless** the bundles are somehow dependendent on each other.
29+
30+
## Parallel Execution of Scripts
31+
Using the various options of the `yarn workspaces foreach` command, you can execute multiple tasks in parallel, which is how many of the commands in the root repository have been set up.
32+
33+
The `-t` option runs the scripts in topological order, which means you don't have to manually figure out which packages have to be built before others; Yarn figures it out for you.
34+
35+
::: details ESLint out of memory?
36+
For some reason when I migrated this repository over to Yarn workspaces, I kept finding that linting all the bundles at once in parallel
37+
would cause NodeJS to exceed its default memory limit of 4906MB. I guess if you wanted to run linting for all bundles in parallel you could
38+
just run NodeJS with `--max-old-space-size`, but I just found that limiting the number of jobs running in parallel using `-j` to 5 was
39+
sufficient to get around this issue.
40+
:::

0 commit comments

Comments
 (0)