Skip to content

Commit 06102fb

Browse files
committed
More linting changes
1 parent 299c19c commit 06102fb

File tree

58 files changed

+1195
-724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1195
-724
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"fileMatch": ["src/bundles/**/manifest.json"],
66
"url": "./lib/buildtools/src/build/modules/manifest.schema.json"
7-
},
7+
},
88
{
99
"fileMatch": ["tsconfig.json", "tsconfig.*.json"],
1010
"schema": {

devserver/src/components/sideContent/importers/importers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function getCompiledTabs(context: Context) {
4949
if (manifest.tabs) {
5050
const tabsToSpawn = manifest.tabs as string[];
5151
return Promise.all(tabsToSpawn.map(async (tabName): Promise<ModuleSideContent> => {
52-
const { default: rawTab } = await import(`../../../../../build/tabs/${tabName}.js`);
52+
const { default: rawTab } = await import(/* @vite-ignore */ `../../../../../build/tabs/${tabName}.js`);
5353
const { default: content } = await (rawTab as RawTab)(requireProvider, React);
5454
return content;
5555
}));

devserver/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"verbatimModuleSyntax": true,
2626
"types": [
2727
"@vitest/browser/matchers",
28-
"@vitest/browser/providers/playwright"
28+
"@vitest/browser/providers/playwright"
2929
]
3030
},
3131
"include": ["src"],

docs/.vitepress/config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const vitepressOptions: UserConfig = {
1717
title: 'Modules Developer Documentation',
1818
themeConfig: {
1919
// https://vitepress.dev/reference/default-theme-config
20-
logo: './favicon.ico',
20+
logo: '/favicon.ico',
2121
nav: [
2222
{ text: 'Home', link: '/' },
2323
{
@@ -30,10 +30,28 @@ const vitepressOptions: UserConfig = {
3030
{
3131
text: 'Getting Started',
3232
link: '/modules/1-getting-started/2-start'
33+
},
34+
{
35+
text: 'Bundles',
36+
link: '/modules/2-bundle/1-overview/1-overview'
37+
},
38+
{
39+
text: 'Tabs',
40+
link: '/modules/3-tabs/1-overview'
3341
}
3442
]
3543
},
36-
{ text: 'Common Library', link: '/lib' },
44+
{
45+
text: 'Libraries',
46+
items: [
47+
{
48+
text: 'Common Libraries',
49+
link: '/lib'
50+
}, {
51+
text: 'Developer Docs',
52+
link: '/lib/dev'
53+
}]
54+
},
3755
{
3856
text: 'Dev Tools',
3957
items: [

docs/src/buildtools/2-command.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,31 @@ Command execution follows the following steps:
1515
## CI Pipeline Compatibility
1616
Since the buildtools need to be run as part of the CI pipeline, it is important that they return non-zero exit codes when appropriate so that
1717
the CI pipeline can detect that errors have occurred and halt the pipeline.
18+
19+
## Command Execution Flow
20+
21+
### Single Bundle/Tab
22+
For a command that processes a single bundle or tab, this is the flow of the command:
23+
```mermaid
24+
graph TD
25+
A[Resolve bundle/tab]
26+
C["Run prebuilds (if necessary)"]
27+
B[Run Command]
28+
D[Check if running in CI Mode]
29+
E[Display error and exit with code 1]
30+
F[Display success message]
31+
32+
A -- Is resolved --> C
33+
A -- Is not resolved --> E
34+
35+
C -- No errors or warnings --> B
36+
C -- Warnings present --> D
37+
C -- Errors present --> E
38+
39+
B -- Warnings present --> D
40+
B -- Errors present --> E
41+
42+
D -- Is CI Mode --> E
43+
D -- Not CI Mode --> F
44+
B -- No errors or warnings --> F
45+
```

docs/src/buildtools/6-prebuild.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ errors always cause a non-zero exit code.
1818
ESLint provides several [formatters](https://eslint.org/docs/latest/use/formatters/) for processing the results objects it returns. To produce the human readable output that is printed to the command line, the `stylish` formatter
1919
is loaded and used.
2020

21+
::: details Inspecting the Linting Config
22+
The entire repository's linting configuration is located at the root of the repository within `eslint.config.js`. If you want to view the view what rules are being applied to which files you can
23+
use the config inspector, which can be started using `yarn lint:inspect`
24+
:::
25+
2126
## Calling Typescript from Node
2227

2328
Most of the code for running Typescript functionality from Node was taken from [this](https://github.com/Microsoft/TypeScript/issues/6387) Github issue.
@@ -39,7 +44,7 @@ The first three steps in the process involve reading the raw text from the `tsco
3944
in use, as well as the file paths to the files that are to be processed.
4045

4146
### Type Checking
42-
The first time `ts.createProgram` is called, it is called with every single file as returned from `ts.parseJsonConfigFileContent`. However, it is called with `noEmit: true`. This prevents any Javascript and Typescript declaration files from being written.
47+
At step 4, `ts.createProgram` is called for the first time. It is called with every single file as returned from `ts.parseJsonConfigFileContent`. However, it is called with `noEmit: true`. This prevents any Javascript and Typescript declaration files from being written.
4348
This is important because we want test files to be type checked, but we don't want them to be compiled into Javascript and exported with the rest of the code. If they were included and the `tsconfig` was configured to produce outputs, the test files would end
4449
up being written to the `outDir`. `typecheckProgram.emit` is called to perform the type checking.
4550

docs/src/lib/dev/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ title: Modules Developer Docs
33
---
44

55
<script setup>
6-
import { data } from './devdocs.data.js'
6+
import { data } from './devdocs.data.ts'
77
</script>
88

99
<h1>Bundles Developer Documentation</h1>
10-
<p>This an the index page for bundles that have documentation for developers working them</p>
10+
<p>This an the index page for bundles that have documentation for developers working with them</p>
1111
<ul>
1212
<li v-for="doc of data">
1313
<a :href="doc.url">{{ doc.frontmatter.title }}</a>
Lines changed: 84 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,112 @@
1+
<script setup>
2+
import { data } from './scripts.data.ts';
3+
const { globalScripts, rootScripts } = data
4+
</script>
5+
16
# Commands Cheat Sheet
7+
All commands have a `-h` or `--help` option that can be used to get more information about the command.
8+
9+
## Icon Legend
10+
<table>
11+
<thead>
12+
<tr>
13+
<th>Icon</th>
14+
<th>Meaning</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
<tr>
19+
<td>💼</td>
20+
<td>Can be run from a bundle's directory or any of its subdirectories</td>
21+
</tr>
22+
<tr>
23+
<td>🖥</td>
24+
<td>Can be run from a tab's directory or any of its subdirectories</td>
25+
</tr>
26+
<tr>
27+
<td>🏠</td>
28+
<td>Can be run from the repository root</td>
29+
</tr>
30+
</tbody>
31+
</table>
232

333
## Installation Commands
434
<table>
535
<thead>
636
<tr>
737
<th>Command</th>
838
<th>Purpose</th>
39+
<th><a href="#icon-legend">💼</a></th>
40+
<th><a href="#icon-legend">🖥</a></th>
41+
<th><a href="#icon-legend">🏠</a></th>
942
</tr>
1043
</thead>
1144
<tbody>
1245
<tr>
1346
<td><code>yarn workspaces focus @sourceacademy/modules</code></td>
1447
<td>Installs the dependencies required for the repository <strong>only</strong> (like the build tools)</td>
48+
<td/>
49+
<td/>
50+
<td>✅</td>
1551
</tr>
1652
<tr>
1753
<td><code>yarn workspaces focus @sourceacademy/bundle-curve</code></td>
1854
<td>Installs the dependencies required for the `curve` bundle <strong>only</strong> </td>
55+
<td>✅</td>
56+
<td/>
57+
<td>✅</td>
1958
</tr>
2059
<tr>
2160
<td><code>yarn add &lt;package&gt;</code></td>
2261
<td>
2362
Adds a package to the current bundle or tab <br />
24-
(SHOULD ONLY BE RUN WITHIN THE BUNDLE OR TAB DIRECTORY)
2563
</td>
64+
<td>✅</td>
65+
<td>✅</td>
66+
<td>✅*</td>
2667
</tr>
2768
<tr>
2869
<td><code>yarn add -D &lt;package&gt;</code></td>
2970
<td>
3071
Adds a package to the current bundle or tab that will only be used during runtime <br />
31-
(SHOULD ONLY BE RUN WITHIN THE BUNDLE OR TAB DIRECTORY)
3272
</td>
73+
<td>✅</td>
74+
<td>✅</td>
75+
<td>✅*</td>
3376
</tr>
3477
</tbody>
3578
</table>
3679

80+
\* Will add packages to the root repository. Only do this if you are adding or updating a constraint for the entire repository.
81+
3782
## Bundle or Tab Specific Commands
83+
These commands are only applicable to bundles or tabs and should only be run from within the bundle or tab's directory.
3884

3985
### Compilation
40-
| Command | Purpose |
41-
|---------------------------|---------------------------------------------------------------|
42-
| `yarn build` | Compiles the bundle or tab to the `/build` directory |
43-
| `yarn build --tsc` | Same as `yarn build` but also runs `tsc` for type checking |
44-
| `yarn build --lint` | Same as `yarn build` but also runs ESLint for linting |
45-
| `yarn build --lint --tsc` | Run both ESLint and `tsc` simultaneously before running build |
86+
<table>
87+
<thead>
88+
<tr>
89+
<th>Command</th>
90+
<th>Purpose</th>
91+
</tr>
92+
</thead>
93+
<tbody>
94+
<tr>
95+
<td><code>yarn build</code></td>
96+
<td>Compiles the bundle or tab to the <code>/build</code> directory</td>
97+
</tr>
98+
<tr>
99+
<td><nobr><code>yarn build --tsc</code></nobr></td>
100+
<td>Same as <code>yarn build</code> but also runs <code>tsc</code> for type checking</td>
101+
</tr>
102+
<tr>
103+
<td><nobr><code>yarn build --lint</code></nobr></td>
104+
<td>Same as <code>yarn build</code> but also runs ESLint</td>
105+
</tr>
106+
</tbody>
107+
</table>
108+
109+
Both the `--tsc` and `--lint` options can be used togther to run `tsc` and ESLint simultaneously.
46110

47111
### Prebuild and Testing
48112
<ins>Prebuild</ins> refers to commands that are to be run **before** the build/compilation commands are executed.
@@ -65,13 +129,9 @@ These commands should only be run from the root of the Git repository.
65129
</tr>
66130
</thead>
67131
<tbody>
68-
<tr>
69-
<td><nobr><code>yarn devserver</code></nobr></td>
70-
<td>Start the modules development server</td>
71-
</tr>
72-
<tr>
73-
<td><nobr><code>yarn serve</code></nobr></td>
74-
<td>Run the modules server to serve modules to local copies of <code>js-slang</code> and the frontend </td>
132+
<tr v-for="cmd of rootScripts">
133+
<td><nobr><code>yarn {{ cmd.name }}</code></nobr></td>
134+
<td>{{ cmd.info }} </td>
75135
</tr>
76136
</tbody>
77137
</table>
@@ -80,6 +140,12 @@ These commands should only be run from the root of the Git repository.
80140
Yarn considers scripts with a ":" in their name to be a [global script](https://yarnpkg.com/features/workspaces#global-scripts) that can be run from anywhere,
81141
including child workspaces. In other words, these commands are available throughout the repository, not just at the root level.
82142

143+
In general, global scripts for this repository follow the same format.
144+
- `:all` will be run for all code in the respository
145+
- `:devserver` will only be run for the devserver.
146+
- `:libs` will be run for all code under the `lib` folder (common modules libraries)
147+
- `:modules` will be run for all bundle and tab code
148+
83149
<table>
84150
<thead>
85151
<tr>
@@ -88,17 +154,9 @@ including child workspaces. In other words, these commands are available through
88154
</tr>
89155
</thead>
90156
<tbody>
91-
<tr>
92-
<td><nobr><code>yarn build:modules</code></nobr></td>
93-
<td>Builds all bundles, tabs, JSONS and HTML documentation</td>
94-
</tr>
95-
<tr>
96-
<td><nobr><code>yarn build:docs</code></nobr></td>
97-
<td>Builds JSONS and HTML documentation for all bundles. <br /> Useful if you're only changing documentation.</td>
98-
</tr>
99-
<tr>
100-
<td><nobr><code>yarn template</code></nobr></td>
101-
<td>Starts the interactive bundle/tab creator</td>
157+
<tr v-for="cmd of globalScripts">
158+
<td><nobr><code>yarn {{ cmd.name }}</code></nobr></td>
159+
<td>{{ cmd.info }} </td>
102160
</tr>
103161
</tbody>
104162
</table>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import _package from '../../../../package.json' with { type: 'json' };
2+
3+
type Script = {
4+
name: string
5+
info: string
6+
};
7+
8+
export default {
9+
watch: ['../../../../package.json'],
10+
load() {
11+
const [globalScripts, rootScripts] = Object.keys(_package.scripts).reduce<[Script[], Script[]]>(([globals, roots], scriptNames) => {
12+
const scriptInfo = _package['scripts-info'][scriptNames];
13+
14+
if (scriptInfo === undefined) return [globals, roots];
15+
const script: Script = {
16+
name: scriptNames,
17+
info: scriptInfo
18+
};
19+
20+
if (scriptNames.includes(':')) {
21+
return [[...globals, script ], roots];
22+
} else {
23+
return [globals, [...roots, script]];
24+
}
25+
}, [[], []]);
26+
27+
return {
28+
globalScripts,
29+
rootScripts
30+
};
31+
}
32+
};

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ For example, the `binary_tree` module may want to provide an abstraction for Sou
88

99
The typical bundle structure for a bundle is shown below. Each section will have its own explanation.
1010
```txt
11-
bundle_name // Name of the root folder is the name of the bundle
11+
bundle_name // Name of the root folder is the name of the bundle
1212
├── src
13-
│ ├── index.ts // Entry Point
14-
│ ├── functions.ts // Example file
15-
│ └── .... // Other files your bundle may use
16-
├── package.json // Package Manifest
17-
├── manifest.json // Bundle Manifest
18-
└── tsconfig.json // Typescript Configuration
13+
│ ├── __tests__ // Folder containing unit tests
14+
│ │ └── index.ts // File containing unit tests
15+
│ ├── index.ts // Entry Point
16+
│ ├── functions.ts // Example file
17+
│ └── .... // Other files your bundle may use
18+
├── package.json // Package Manifest
19+
├── manifest.json // Bundle Manifest
20+
└── tsconfig.json // Typescript Configuration
1921
```
2022

2123
> [!NOTE]
@@ -95,8 +97,16 @@ The `package.json` file follows the same format as your typical `package.json` u
9597
```
9698
You can find more information about each of the fields and what they mean [here](https://docs.npmjs.com/cli/v11/configuring-npm/package-json#devdependencies).
9799

98-
> [!WARNING]
99-
> The `name` field must follow the format `@sourceacademy/bundle-[your bundle name]`.
100+
> [!WARNING] Bundle vs Package Name
101+
> The `name` field in `package.json` is the package name and must follow the format `@sourceacademy/bundle-[your bundle name]`.
102+
> The bundle name is what users will actually use to import your bundle from within Source code:
103+
> ```ts
104+
> import { whatever } from 'bundle_name';
105+
> ```
106+
> However, if people consuming your bundle from regular Javascript and Typescript need to use the full (scoped) package name:
107+
> ```ts
108+
> import { whatever } from '@sourceacademy/bundle-bundle_name';
109+
> ```
100110
101111
### `manifest.json`
102112
`manifest.json` contains the information required by `js-slang` to load your bundle.
@@ -114,7 +124,7 @@ Your bundle may rely on features that are only present in later Source Chapters.
114124
:::
115125

116126
>[!TIP] Verifying your manifest
117-
> You can use the `buildtools list` command to check that your bundle can be properly detected and has the correct format.
127+
> You can use the `buildtools list bundle` command to check that your bundle can be properly detected and has the correct format.
118128
119129
## `tsconfig.json`
120130
This file controls the behaviour of Typescript. By default, it should look like this:

0 commit comments

Comments
 (0)