Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Cynosphere authored Oct 10, 2024
2 parents 7926793 + 1e0ab85 commit c127fce
Show file tree
Hide file tree
Showing 95 changed files with 3,789 additions and 780 deletions.
20 changes: 19 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand Down Expand Up @@ -47,7 +48,24 @@
"@typescript-eslint/no-var-requires": "off",

// https://canary.discord.com/channels/1154257010532032512/1154275441788583996/1181760413231230976
"no-unused-labels": "off"
"no-unused-labels": "off",

// baseUrl being set to ./packages/ makes language server suggest "types/src" instead of "@moonlight-mod/types"
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": ["types/*"],
"message": "Use @moonlight-mod/types instead"
},
{
"group": ["core/*"],
"message": "Use @moonlight-mod/core instead"
}
]
}
]
},
"settings": {
"react": {
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/browser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Browser extension builds

on:
push:
branches:
- develop

jobs:
browser:
name: Browser extension builds
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 9
run_install: false
- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build moonlight
env:
NODE_ENV: production
run: pnpm run build

- name: Build MV3
run: pnpm run browser
- name: Build MV2
run: pnpm run browser-mv2

- name: Upload MV3
uses: actions/upload-artifact@v4
with:
name: browser
path: ./dist/browser
- name: Upload MV2
uses: actions/upload-artifact@v4
with:
name: browser-mv2
path: ./dist/browser-mv2
2 changes: 2 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
- name: Build moonlight
env:
NODE_ENV: production
MOONLIGHT_BRANCH: nightly
MOONLIGHT_VERSION: ${{ github.sha }}
run: pnpm run build

- name: Write ref/commit to file
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
- name: Build moonlight
env:
NODE_ENV: production
MOONLIGHT_BRANCH: stable
MOONLIGHT_VERSION: ${{ github.ref_name }}
run: pnpm run build
- name: Create archive
run: |
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<h3 align="center">
<img src="./img/wordmark.png" alt="moonlight" />
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./img/wordmark-light.png">
<source media="(prefers-color-scheme: light)" srcset="./img/wordmark.png">
<img src="./img/wordmark.png" alt="moonlight" />
</picture>

<a href="https://discord.gg/FdZBTFCP6F">Discord server</a>
\- <a href="https://github.com/moonlight-mod/moonlight">GitHub</a>
Expand All @@ -12,6 +16,6 @@

moonlight is heavily inspired by hh3 (a private client mod) and the projects before it that it is inspired by, namely EndPwn. All core code is original or used with permission from their respective authors where not copyleft.

**_This is an experimental passion project._** moonlight was not created out of malicious intent nor intended to seriously compete with other mods. Anything and everything is subject to change.
**_This is an experimental passion project._** Anything and everything is subject to change, but it is stable enough for developers to experiment with.

moonlight is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.html) (`LGPL-3.0-or-later`). See [the documentation](https://moonlight-mod.github.io/) for more information.
151 changes: 123 additions & 28 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ const config = {

const prod = process.env.NODE_ENV === "production";
const watch = process.argv.includes("--watch");
const browser = process.argv.includes("--browser");
const mv2 = process.argv.includes("--mv2");

const buildBranch = process.env.MOONLIGHT_BRANCH ?? "dev";
const buildVersion = process.env.MOONLIGHT_VERSION ?? "dev";

const external = [
"electron",
"fs",
"path",
"module",
"events",
"original-fs", // wtf asar?
"discord", // mappings

// Silence an esbuild warning
Expand Down Expand Up @@ -74,33 +77,91 @@ const taggedBuildLog = (tag) => ({
});

async function build(name, entry) {
const outfile = path.join("./dist", name + ".js");
let outfile = path.join("./dist", name + ".js");
const browserDir = mv2 ? "browser-mv2" : "browser";
if (name === "browser") outfile = path.join("./dist", browserDir, "index.js");

const dropLabels = [];
if (name !== "injector") dropLabels.push("injector");
if (name !== "node-preload") dropLabels.push("nodePreload");
if (name !== "web-preload") dropLabels.push("webPreload");
const labels = {
injector: ["injector"],
nodePreload: ["node-preload"],
webPreload: ["web-preload"],
browser: ["browser"],

webTarget: ["web-preload", "browser"],
nodeTarget: ["node-preload", "injector"]
};
for (const [label, targets] of Object.entries(labels)) {
if (!targets.includes(name)) {
dropLabels.push(label);
}
}

const define = {
MOONLIGHT_ENV: `"${name}"`,
MOONLIGHT_PROD: prod.toString()
MOONLIGHT_PROD: prod.toString(),
MOONLIGHT_BRANCH: `"${buildBranch}"`,
MOONLIGHT_VERSION: `"${buildVersion}"`
};

for (const iterName of Object.keys(config)) {
for (const iterName of [
"injector",
"node-preload",
"web-preload",
"browser"
]) {
const snake = iterName.replace(/-/g, "_").toUpperCase();
define[`MOONLIGHT_${snake}`] = (name === iterName).toString();
}

const nodeDependencies = ["glob"];
const ignoredExternal = name === "web-preload" ? nodeDependencies : [];

const plugins = [deduplicatedLogging, taggedBuildLog(name)];
if (name === "browser") {
plugins.push(
copyStaticFiles({
src: mv2
? "./packages/browser/manifestv2.json"
: "./packages/browser/manifest.json",
dest: `./dist/${browserDir}/manifest.json`
})
);

if (!mv2) {
plugins.push(
copyStaticFiles({
src: "./packages/browser/modifyResponseHeaders.json",
dest: `./dist/${browserDir}/modifyResponseHeaders.json`
})
);
plugins.push(
copyStaticFiles({
src: "./packages/browser/blockLoading.json",
dest: `./dist/${browserDir}/blockLoading.json`
})
);
}

plugins.push(
copyStaticFiles({
src: mv2
? "./packages/browser/src/background-mv2.js"
: "./packages/browser/src/background.js",
dest: `./dist/${browserDir}/background.js`
})
);
}

/** @type {import("esbuild").BuildOptions} */
const esbuildConfig = {
entryPoints: [entry],
outfile,

format: "cjs",
platform: name === "web-preload" ? "browser" : "node",
format: "iife",
globalName: "module.exports",

platform: ["web-preload", "browser"].includes(name) ? "browser" : "node",

treeShaking: true,
bundle: true,
Expand All @@ -113,9 +174,38 @@ async function build(name, entry) {
dropLabels,

logLevel: "silent",
plugins: [deduplicatedLogging, taggedBuildLog(name)]
plugins
};

if (name === "browser") {
const coreExtensionsJson = {};

// eslint-disable-next-line no-inner-declarations
function readDir(dir) {
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = dir + "/" + file;
const normalizedPath = filePath.replace("./dist/core-extensions/", "");
if (fs.statSync(filePath).isDirectory()) {
readDir(filePath);
} else {
coreExtensionsJson[normalizedPath] = fs.readFileSync(
filePath,
"utf8"
);
}
}
}

readDir("./dist/core-extensions");

esbuildConfig.banner = {
js: `window._moonlight_coreExtensionsStr = ${JSON.stringify(
JSON.stringify(coreExtensionsJson)
)};`
};
}

if (watch) {
const ctx = await esbuild.context(esbuildConfig);
await ctx.watch();
Expand Down Expand Up @@ -173,7 +263,8 @@ async function buildExt(ext, side, copyManifest, fileExt) {
entryPoints,
outdir,

format: "cjs",
format: "iife",
globalName: "module.exports",
platform: "node",

treeShaking: true,
Expand Down Expand Up @@ -211,23 +302,27 @@ async function buildExt(ext, side, copyManifest, fileExt) {

const promises = [];

for (const [name, entry] of Object.entries(config)) {
promises.push(build(name, entry));
}
if (browser) {
build("browser", "packages/browser/src/index.ts");
} else {
for (const [name, entry] of Object.entries(config)) {
promises.push(build(name, entry));
}

const coreExtensions = fs.readdirSync("./packages/core-extensions/src");
for (const ext of coreExtensions) {
let copiedManifest = false;

for (const fileExt of ["ts", "tsx"]) {
for (const type of ["index", "node", "host"]) {
if (
fs.existsSync(
`./packages/core-extensions/src/${ext}/${type}.${fileExt}`
)
) {
promises.push(buildExt(ext, type, !copiedManifest, fileExt));
copiedManifest = true;
const coreExtensions = fs.readdirSync("./packages/core-extensions/src");
for (const ext of coreExtensions) {
let copiedManifest = false;

for (const fileExt of ["ts", "tsx"]) {
for (const type of ["index", "node", "host"]) {
if (
fs.existsSync(
`./packages/core-extensions/src/${ext}/${type}.${fileExt}`
)
) {
promises.push(buildExt(ext, type, !copiedManifest, fileExt));
copiedManifest = true;
}
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c127fce

Please sign in to comment.