Skip to content

Commit 7ea67db

Browse files
committed
Try to fix devserver tests failing
1 parent 25bc826 commit 7ea67db

File tree

26 files changed

+216
-152
lines changed

26 files changed

+216
-152
lines changed

README.md

Lines changed: 39 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,45 @@
1-
# Modules
1+
# Source Academy Modules Repository
22

3-
![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/source-academy/modules/github%20pages?label=Build)
3+
![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen) [![pages-build-deployment](https://github.com/source-academy/modules/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/source-academy/modules/actions/workflows/pages/pages-build-deployment)
44

5-
This repository contains the default modules of the Source Academy and their documentation, deployed to the default module site at <https://source-academy.github.io/modules>.
5+
This repository contains the default modules of the Source Academy and their documentation, alongside all the libraries and tooling required for development.
66

77
The [Source Academy](https://sourceacademy.org) and [Source Academy @ NUS](https://sourceacademy.nus.edu.sg) are configured to access the default module site when evaluating `import` directives.
88

9-
[Documentation of Source Academy modules](https://source-academy.github.io/modules/documentation).
10-
11-
## Information for Module Developers
12-
13-
See the modules [wiki](https://github.com/source-academy/modules/wiki) for more details.
14-
15-
### Terminology
16-
17-
| **Term** | **Description** |
18-
| ---------- | ------------------------------------------------------------------ |
19-
| **Module** | A set of **one** bundle _with the same name_ and **some/no** tabs. |
20-
| **Bundle** | The suite of functions that are provided by the module. |
21-
| **Tab** | A user interface used by the module. |
22-
23-
### Getting Started
24-
25-
The following set of instructions explain how to clone and set up a copy of the `modules` code repository on your local development machine. Following the steps below will create a `modules` directory in your local development machine and install the necessary dependencies of the project.
26-
27-
The recommended version of [Node.js](https://nodejs.org/en/) for local development is Node.js 20. You may use a Node.js version manager such as [nvm](https://github.com/creationix/nvm#installation) _(macOS/Linux)_ or [nvm-windows](https://github.com/coreybutler/nvm-windows#node-version-manager-nvm-for-windows) to switch Node.js versions between different projects.
28-
29-
This project also uses [Yarn](https://yarnpkg.com/) as a package manager. You may install and enable Yarn by running the following command.
30-
```bash
31-
corepack enable
32-
```
33-
34-
If the above does not work, you can manually install the Yarn package manager through [NPM](https://www.npmjs.com/) using the following command.
35-
36-
```bash
37-
npm install -g yarn
38-
```
39-
40-
You may also require [Python](https://www.python.org/downloads/) to run build scripts and install project dependencies. We recommend either using Python 2.7 or Python 3.8-3.11.
41-
42-
Clone the repository on your local development machine and navigate to it using your favourite command line or shell tool.
43-
44-
```bash
45-
git clone https://github.com/source-academy/modules.git
46-
cd modules
47-
```
48-
49-
Install all the dependencies of the project into `node_modules` in the root folder of your project directory.
50-
51-
```bash
52-
yarn install
53-
```
54-
55-
If you encounter errors with esbuild dependencies like the following while building:
56-
57-
```plaintext
58-
Error: The package "@esbuild/darwin-arm64" could not be found, and is needed by esbuild.
9+
## Quick Links
10+
| Site | Link |
11+
| ---- | ---- |
12+
| Source Academy | https://sourceacademy.org |
13+
| Default Modules Deployment | https://source-academy.github.io/modules |
14+
| Default Modules Documentation | https://source-academy.github.io/modules/documentation |
15+
| Developer Wiki | https://github.com/source-academy/modules/wiki |
16+
| `js-slang` | https://github.com/source-academy/js-slang |
17+
| Frontend | https://github.com/source-academy/frontend |
18+
19+
If you are looking for the documentation for the default modules, they can be found [here](https://source-academy.github.io/modules/documentation).
20+
21+
If you are a developer working with this repository, the developer documentation can be found [here](https://github.com/source-academy/modules/wiki)
22+
23+
## Repository Structure
24+
The repository is designed as a monorepo, managed using Yarn workspaces.
25+
26+
```txt
27+
.
28+
├── .github // Configuration for issue templates and workflows
29+
├── .husky // Configuration for code that runs on Git Hooks
30+
├── .vscode // Configuration for VSCode integration
31+
├── build // Output directory for compiled assets
32+
├── devserver // Modules Development Server
33+
├── docs // Developer Documentation and Server
34+
├── lib
35+
│ ├── buildtools // Scripts for compiling bundles and tabs
36+
│ ├── lintplugin // ESLint Plugin for SA Modules
37+
│ └── modules-lib // Common utilities and React components for SA Modules
38+
├── src
39+
│ ├── bundles // Source code for Bundles
40+
│ ├── tabs // Source code for Tabs
41+
│ └── java // Assets for Source Java
42+
├── eslint.config.js // ESLint configuration for the entire repository
43+
├── vitest.config.js // Vitest configuration for the entire repository
44+
└── yarn.config.cjs // Yarn constraints configuration
5945
```
60-
61-
You will need to delete the `node_modules` folder and rerun `yarn install` to fix the issue.
62-
63-
### Serve Modules
64-
65-
The following set of instructions explain how to transpile and serve the modules from your local development machine's code repository. Following the steps below will transpile all the modules in your project directory into JavaScript files located in the `build` folder. Thereafter, you will serve all the contents of the build folder in a server on your local development machine.
66-
67-
To transpile the modules' files from `src` into JavaScript files in `build`, run the following command.
68-
69-
```bash
70-
yarn run build:all
71-
```
72-
73-
To start the server that serves all the contents of the `build` folder in the root directory of the project, run the following command. By default, running this command serves the contents of the `build` folder on <http://localhost:8022>.
74-
75-
```bash
76-
yarn run serve
77-
```
78-
79-
### Development with Source Academy `frontend`
80-
81-
The following set of instructions explains how to use a local copy of the Source Academy [frontend](https://github.com/source-academy/frontend) with a local copy of the modules code repository. Following the steps below will configure the environment of the Source Academy frontend to use your locally served modules instead of the publicly available ones. Doing this will allow you to develop and modify modules without affecting the currently publicly available ones.
82-
83-
You will need to already have a local instance of Source Academy frontend set up. If you do not, you can follow the instructions [here](https://github.com/source-academy/frontend#getting-started) to setup an instance of Source Academy frontend on your local development machine.
84-
85-
Ensure that the environment variable `REACT_APP_MODULE_BACKEND_URL` in the `.env` file of the Source Academy frontend is configured to the URL of the module site that you are trying to retrieve modules from. At the same time, make sure that the server hosting the modules site is running. By default, the local server started by running `yarn run serve` is on <http://localhost:8022>. The default modules are implemented in the repository <https://github.com/source-academy/modules> and deployed to the modules site <https://source-academy.github.io/modules>.
86-
87-
Upon starting the local instance of Source Academy frontend, the Source Academy will connect to the configured modules site.
88-
89-
### Development Guide
90-
91-
Please refer to the Modules Development Guide located in the modules wiki [here](https://github.com/source-academy/modules/wiki/Development-Guide) for more information regarding how to create your own module including its own bundle and tab.
92-
93-
## License
94-
95-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
96-
97-
All sources in this repository are licensed under the [Apache License Version 2][apache2].
98-
99-
[apache2]: https://www.apache.org/licenses/LICENSE-2.0.txt

devserver/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export default defineConfig(({ mode }) => {
6969
"vite-plugin-node-polyfills/shims/buffer",
7070
"vite-plugin-node-polyfills/shims/global",
7171
"vite-plugin-node-polyfills/shims/process",
72+
],
73+
exclude: [
74+
'../build/tabs/*.js'
7275
]
7376
},
7477
test: {

docs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"version": "1.0.0",
66
"type": "module",
77
"devDependencies": {
8+
"@sourceacademy/modules-lib": "workspace:^",
89
"vitepress": "^1.6.3",
910
"vitepress-sidebar": "^1.31.1"
1011
},
1112
"scripts": {
1213
"build": "vitepress build .",
1314
"dev": "vitepress dev .",
14-
"preview": "vitepress preview ."
15+
"preview": "vitepress preview .",
16+
"prepare": "yarn workspaces foreach -A --include \"@sourceacademy/modules-lib\" run docs"
1517
}
1618
}

docs/src/index.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
layout: home
44

55
hero:
6-
name: "Modules Developer Documentation"
7-
text: "Developer documentation for the Source Academy modules repository"
8-
tagline: My great project tagline
6+
name: Modules Developer Documentation
7+
tagline: Developer documentation for the Source Academy modules repository
98
actions:
109
- theme: brand
1110
text: Get Started
@@ -17,15 +16,18 @@ hero:
1716
link: /api-examples
1817

1918
features:
20-
- title: Creating a bundle or tab
19+
- title: Your first bundle or tab
2120
details: Instructions for creating a bundle or tab
22-
link: /modules/getting-started/start
21+
link: /modules/1-getting-started/1-overview
2322

24-
- title: Common Modules Library
25-
details: idk
23+
- title: Common Modules Libraries
24+
details: Libraries intended to be shared between SA Modules
2625
link: /lib
2726

2827
- title: Build Tools
29-
details: Details behind the tooling that compiles Source Academy modules
28+
details: Details behind the tooling that compiles SA Modules
3029
link: /buildtools
30+
31+
- title: Repository Tools
32+
details: Details for the tools used to aid in developing SA Modules
3133
---

docs/src/lib/lintplugin.md renamed to docs/src/lib/lintplugin/1-overview.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
title: Overview
3+
---
14
# Modules ESLint Plugin
25
`@sourceacademy/modules-lintplugin` provides the ability for developers to write their own custom linting rules for SA Modules.
36

docs/src/lib/lintplugin/2-rules.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Rules Reference
2+
3+
## `tab-type`
4+
5+
Enforces that types have a default export using the `defineTab` helper.
6+
7+
Examples of **incorrect** code for this rule:
8+
```tsx
9+
export default 0;
10+
11+
export default {
12+
body: () => <Component />,
13+
toSpawn: () => false,
14+
iconName: 'icon',
15+
label: 'tab'
16+
}
17+
```
18+
Examples of **correct** code for this rule:
19+
```tsx
20+
import { defineTab } from '@sourceacademy/modules-lib/tabs';
21+
22+
export default defineTab{
23+
body: () => <Component />,
24+
toSpawn: () => false,
25+
iconName: 'icon',
26+
label: 'tab'
27+
});
28+
```
29+
30+
The rule considers the code below **correct** even if the import is aliased:
31+
```tsx
32+
import { defineTab as tabHelper } from '@sourceacademy/modules-lib/tabs';
33+
34+
export default tabHelper({
35+
body: () => <Component />,
36+
toSpawn: () => false,
37+
iconName: 'icon',
38+
label: 'tab'
39+
});
40+
```
41+
42+
## Options
43+
This rule accepts a configuration array with two elements:
44+
- The first option represents the expected import source. This is by default `@sourceacademy/modules-lib/tabs` but can be changed to whatever is in use
45+
- The second option is the name of the imported helper. This is by default `defineTab`.
46+
47+
Examples of **correct** code using these options:
48+
```tsx
49+
/* eslint @sourceacademy/tab-type: ['error', '@sourceacademy/modules-lib/tabs/utils', 'tabHelper'] */
50+
import { tabHelper } from '@sourceacademy/modules-lib/tabs/utils';
51+
52+
export default tabHelper({
53+
body: () => <Component />,
54+
toSpawn: () => false,
55+
iconName: 'icon',
56+
label: 'tab'
57+
});
58+
```

docs/src/lib/lintplugin/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: ESLint Plugin
3+
---

docs/src/modules/1-getting-started/1-overview.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Modules Overview
2-
This page contains information regarding the overview of the Source Modules system.
2+
This page contains information regarding the overview of the Source Modules system. If you want to skip this overview, navigate to the bottom of the page
3+
where the **next page** button is located.
4+
5+
## Terminology
36

47
The module system imitates ESM Javascript, allowing the use of `import` statements to import external code into Source programs:
58

@@ -9,8 +12,6 @@ import { draw_connected } from 'curve';
912
> [!NOTE]
1013
> If you're familiar with the Javascript ecosystem, you may know that there are other module formats that are in common use. Source Modules are written in the ECMAScript _(ESM)_ format (i.e using `import` and `export`). However, there are limitations. For example, top-level await is not supported.
1114
12-
## Terminology
13-
1415
These are the 3 main terms the project will be using to refer to the individual components of the Source Modules system. Please follow the set of definitions below to avoid any inconsistencies.
1516
| **Term** | **Description** | **Links** |
1617
| ---------- | ------------------------------------------------------------------ | ---------------- |

docs/src/modules/2-bundle/1-overview/1-overview.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ This file controls the behaviour of Typescript. By default, it should look like
134134
```
135135
In general, there should not be a need for you to modify this file. A full explanation on how to use `tsconfig.json` can be found [here](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). Note that the `typedocOptions` field is a custom field used by `typedoc` for its configuration. Refer to [here](https://typedoc.org/documents/Options.Configuration.html#compileroptions) for more information.
136136

137+
> [!WARNING]
138+
> You should not remove or modify the `typedocOptions` section from your `tsconfig.json` unless you provide the name of your bundle to Typedoc via its other configuration methods. Generating documentation for your bundle
139+
> requires that the name of your bundle be set correctly.
140+
137141
::: details Missing types for dependencies and overriding `tsconfig.json`
138142
Sometimes, your bundle might depend on packages that have published their types differently. For example, the `communication` bundle requires `mqtt`:
139143
```ts

docs/src/repotools/devserver/index.md

Whitespace-only changes.

0 commit comments

Comments
 (0)