Skip to content

Commit 02c1221

Browse files
committed
More general docs cleanup
1 parent 52cd74d commit 02c1221

15 files changed

Lines changed: 326 additions & 113 deletions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Writing core extensions
3+
sidebar:
4+
order: 6
5+
---
6+
7+
Core extensions are extensions built into moonlight. They are usually libraries or important features.
8+
9+
Core extensions cannot be uninstalled, but they can be disabled. Some core extensions are enabled by default when moonlight is installed for the first time.
10+
11+
The biggest core extension is [Moonbase](https://github.com/moonlight-mod/moonlight/tree/main/packages/core-extensions/src/moonbase), which is responsible for installing and updating extensions, updating moonlight itself, and providing a UI to manage everything. moonlight's core does not contain any functionality for installing/updating extensions or updating moonlight, and it is instead implemented inside of Moonbase.
12+
13+
## Developing core extensions
14+
15+
Core extensions live in the `packages/core-extensions` folder in the moonlight repository. As such, adding new core extensions must be done in a [pull request](/dev/setup).
16+
17+
Keep in mind that moonlight currently [uses a separate build system](/dev/project-structure#build-system) from other external extensions, so there may be more bugs, and some changes may not apply until you [restart the development server](/ext-dev/getting-started#edit-and-reload-your-extension).
18+
19+
## Creating a new core extension
20+
21+
Before you create a core extension, consider if your extension idea is a good fit for a core extension. An extension is a good fit for a core extension if it's a library or development tool, but actual features or tweaks should usually be distributed on a extension repository instead. This isn't a hard rule, though, so feel free to ask if you're considering making a core extension!
22+
23+
After cloning moonlight, simply create a new folder with a `manifest.json` inside of it, and structure it like a normal moonlight extension. The extension manifest should not contain a `version` or `meta.source`.
24+
25+
## Adding types
26+
27+
The types for core extensions should be placed in the `types` package so other extensions can use them.
28+
29+
- Create a new file in the `coreExtensions` folder, and export the types from there.
30+
- Re-export the types in `coreExtensions.ts`.
31+
- Register the type in the Webpack require function in `discord/require.ts`.
32+
- Register the type for module imports in `import.d.ts`.

src/content/docs/dev/project-structure.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ The types package is published alongside moonlight releases, but some moonlight
5050

5151
## Core extensions
5252

53-
Core extensions are extensions built into moonlight. They cannot be uninstalled, but they can be disabled. A few core extensions are enabled by default when the config is created for the first time. An extension is a good fit for a core extension if it's a library or development tool, but actual features or tweaks should usually be distributed on a extension repository instead. This isn't a hard rule, though, so feel free to ask if you're considering making a core extension!
54-
55-
The biggest core extension is [Moonbase](https://github.com/moonlight-mod/moonlight/tree/main/packages/core-extensions/src/moonbase), which is responsible for installing and updating extensions, updating moonlight itself, and providing a UI to manage everything. Unlike other client mods, Moonbase is just implemented as another extension, and can be disabled if the user wants. The core does not contain any functionality for installing/updating extensions or updating moonlight, and it is instead implemented inside of Moonbase.
53+
Core extensions are extensions built into moonlight. This section has moved into its own dedicated page, which you can see [here](/dev/core-extensions).
5654

5755
## Load stages
5856

src/content/docs/dev/setup.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ sidebar:
55
order: 1
66
---
77

8+
moonlight requires [Node.js](https://nodejs.org) 22 and [pnpm](https://pnpm.io) 10.
89

9-
You will need [pnpm](https://pnpm.io) 10, as moonlight uses it for dependency and workspace management.
10-
11-
- Clone the repository.
12-
- Install dependencies with `pnpm i`.
13-
- Build the project with `pnpm run build`.
10+
- Clone the repository: `git clone https://github.com/moonlight-mod/moonlight.git`
11+
- Install dependencies: `pnpm install`.
12+
- Build the project: `pnpm run build`.
1413
- For working on moonlight, a watch mode is available with `pnpm run dev`.
1514

1615
For more information on project structure, [see the dedicated page](/dev/project-structure).
1716

1817
## Contribution guidelines
1918

2019
- Ensure your commits pass Prettier/ESLint. This is a requirement for merge.
21-
- moonlight uses [husky](https://typicode.github.io/husky/) to check lints on commit.
20+
- moonlight uses [husky](https://typicode.github.io/husky) to check lints on commit. This should have automatically been setup for you when running `pnpm install`.
2221
- Please make PRs to the `develop` branch instead of `main`.
2322
- `develop` is merged into `main` when moonlight updates happen. Our in-progress work resides on `develop`.
2423
- Don't break the existing API surface.

src/content/docs/ext-dev/api.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,74 @@ The global types are available [here](https://github.com/moonlight-mod/moonlight
1414
- `moonlightNode`: available in the web *and* Node.js environments
1515
- Contains configuration details, browser checks
1616
- Polyfilled in the browser extension
17-
- `moonlightNodeSandboxed`: available in the Node.js environments (`node.ts`)
17+
- `moonlightNodeSandboxed`: available in the host and Node.js environments (`host.ts`, `node.ts`)
1818
- Contains filesystem APIs
1919
- `moonlightHost`: available in the host environment (`host.ts`)
2020
- Contains configuration details, `.asar` path
2121

2222
## Extension libraries
2323

24-
Remember to [add the module as a dependency](/ext-dev/webpack#webpack-module-dependencies).
24+
These libraries are built into moonlight as [core extensions](/dev/core-extensions). Remember to [add the extension dependency](/ext-dev/cookbook#using-another-extension-as-a-library) and [add the module dependency](/ext-dev/webpack#webpack-module-dependencies) before using these libraries.
25+
26+
### App Panels
27+
28+
Add custom "app panels" next to the user area and mute buttons.
29+
30+
- Module ID: `appPanels_appPanels`
31+
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/appPanels.ts)
32+
33+
### Commands
34+
35+
Register slash commands and perform text manipulation.
36+
37+
- Module ID: `commands_commands`
38+
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/commands.ts)
39+
40+
### Common
41+
42+
Provides re-exports of Flux stores, and a custom error boundary component.
43+
44+
- Module IDs: `common_stores`, `common_ErrorBoundary`
45+
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/common.ts)
46+
47+
### Component Editor
48+
49+
Add custom elements to commonly edited components.
50+
51+
- Module IDs: `componentEditor_dmList`, `componentEditor_memberList`, `componentEditor_messages`
52+
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/componentEditor.ts)
2553

2654
### Context Menu
2755

56+
Create additional items on existing context menus.
57+
2858
- Module ID: `contextMenu_contextMenu`
2959
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/contextMenu.ts)
3060

3161
### Markdown
3262

63+
Register custom Markdown rules for rendering chat messages.
64+
3365
- Module ID: `markdown_markdown`
3466
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/markdown.ts)
3567

3668
### Notices
3769

70+
Add banners (known as "notices") to the top of the client window.
71+
3872
- Module ID: `notices_notices`
3973
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/notices.ts)
4074

4175
### Settings
4276

77+
Add custom entries to Discord's settings page.
78+
4379
- Module ID: `settings_settings`
4480
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/settings.ts)
4581

4682
### Spacepack
4783

84+
Find and inspect existing Webpack modules.
85+
4886
- Module ID: `spacepack_spacepack`
4987
- Types: [here](https://github.com/moonlight-mod/moonlight/blob/main/packages/types/src/coreExtensions/spacepack.ts)

src/content/docs/ext-dev/devtools.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ sidebar:
77

88
The Chrome DevTools is a panel/window that offers several utilities for web development. Normally, it is intended for the creators of the target application, but it also serves as an excellent tool for client modders.
99

10+
To open DevTools, press `Ctrl + Shift + I`. If this keybind doesn't do anything, you may need to [enable DevTools](#enabling-devtools) first.
11+
1012
## Enabling DevTools
1113

12-
In some branches of Discord, the following is required in the `settings.json` file (*not* the moonlight config file):
14+
In some branches of Discord, you must enable DevTools in Discord's config file. This is *not* the moonlight config file, and it is present in [Discord's config folder](/using/crash-recovery#finding-discords-logs). Add this entry to `settings.json`, then restart your client:
1315

1416
```json
1517
"DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING": true
1618
```
1719

18-
This can be located in `%AppData%/Discord` on Windows and `~/.config/discord` on Linux.
19-
2020
## Reading module sources
2121

22-
See the [helpful extensions](/ext-dev/helpful-exts) page first for `patchAll` and how to use Spacepack.
22+
See the [helpful extensions](/ext-dev/helpful-exts) page first. You should enable "Patch all" and configure Spacepack.
2323

2424
To see the source of a module, print the function with `spacepack.inspect`:
2525

@@ -35,7 +35,11 @@ You can chain `inspect` with `findByCode` (or an equivalent) when trying to find
3535
spacepack.inspect(spacepack.findByCode(/* finds */)[0].id)
3636
```
3737

38-
Also see [this page](/ext-dev/webpack#common-patterns) for common patterns to look out for.
38+
Some patterns may stick out when reading minified Discord source code:
39+
40+
- The pattern `n(/* some number */)` (or some other minified variable) represents a Webpack module require, and the function argument is the module ID. You can pass that module ID to `spacepack.inspect` to read the required module's source.
41+
- `Z` and `ZP` usually correspond to `default` exports. Despite being minified, these export names are stable.
42+
- Mentions of `jsx` and `createElement` imply construction of React components.
3943

4044
## Using the Sources tab
4145

@@ -53,7 +57,7 @@ You can set breakpoints on Webpack modules to inspect the variables at runtime.
5357

5458
React DevTools allows you to inspect the React component tree easier, instead of its representation with the DOM. You can view the sources of components and their props this way.
5559

56-
Either [use the rehosted version](https://moon.light.pm/files/reactdevtools.zip) or [download the extension and extract it yourself](https://react.dev/learn/react-developer-tools). Use the "DevTools Extensions" extension to load it - remember to restart Discord fully after configuring it. A new Components tab will appear in DevTools.
60+
Either [use the rehosted version](https://moon.light.pm/files/reactdevtools.zip) or [download the extension and extract it yourself](https://react.dev/learn/react-developer-tools). Use the "DevTools Extensions" extension to load it, and remember to restart Discord fully after configuring it. Once loaded, a new Components tab will appear in DevTools.
5761

5862
You can use the element picker to select components. Props are available on the right side. Click the bug icon to view data about the component. Click the bracket icon to view the source of the component.
5963

0 commit comments

Comments
 (0)