Skip to content

Commit

Permalink
Merge pull request #51 from redstonekasi/swc-fixes
Browse files Browse the repository at this point in the history
Latest canary SWC fixes
  • Loading branch information
Cynosphere authored Jun 19, 2024
2 parents e098e37 + 5871f1f commit 503326d
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 127 deletions.
5 changes: 1 addition & 4 deletions packages/core-extensions/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export const webpackModules: ExtensionWebExports["webpackModules"] = {
},

flux: {
dependencies: [
{ ext: "spacepack", id: "spacepack" },
"useStateFromStores:function"
]
dependencies: [{ ext: "spacepack", id: "spacepack" }, "connectStores:"]
},

fluxDispatcher: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
const Components = spacepack.findByCode("MasonryList:function")[0].exports;
const MarkdownParser = spacepack.findByCode(
"parseAutoModerationSystemMessage:"
)[0].exports.default;
)[0].exports.Z;
const LegacyText = spacepack.findByCode(".selectable", ".colorStandard")[0]
.exports.default;
const Flex = spacepack.findByCode(".flex" + "GutterSmall,")[0].exports.Flex;
const Flex = Object.values(
spacepack.findByCode(".flex" + "GutterSmall,")[0].exports
)[0];
const CardClasses = spacepack.findByCode("card", "cardHeader", "inModal")[0]
.exports;
const ControlClasses = spacepack.findByCode(
Expand Down
30 changes: 26 additions & 4 deletions packages/core-extensions/src/common/webpackModules/flux.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import spacepack from "@moonlight-mod/wp/spacepack_spacepack";

module.exports = spacepack.findByCode(
["useStateFromStores", ":function"].join(""),
"Store:"
)[0].exports;
const mod = spacepack.findByCode("connectStores:")[0].exports;

const useStateFromStores = spacepack.findFunctionByStrings(
mod,
'"useStateFromStores"'
)!;

module.exports = {
BatchedStoreListener: spacepack.findFunctionByStrings(
mod,
" tried to load a non-existent store."
),
Dispatcher: spacepack.findFunctionByStrings(mod, "_dispatchWithDevtools("),
Store: spacepack.findFunctionByStrings(mod, "registerActionHandlers("),
default: mod.ZP,
statesWillNeverBeEqual: spacepack.findFunctionByStrings(mod, "return!1"),
useStateFromStores,
useStateFromStoresArray: spacepack.findFunctionByStrings(
mod,
new RegExp(`return ${useStateFromStores.name}\\(.+?\\.[^Z]\\)`)
),
useStateFromStoresObject: spacepack.findFunctionByStrings(
mod,
new RegExp(`return ${useStateFromStores.name}\\(.+?\\.Z\\)`)
)
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
module.exports = spacepack.findByExports(
"isDispatching",
"dispatch"
)[0].exports.default;
)[0].exports.Z;
5 changes: 4 additions & 1 deletion packages/core-extensions/src/contextMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const patches: Patch[] = [

export const webpackModules: Record<string, ExtensionWebpackModule> = {
contextMenu: {
dependencies: [{ ext: "spacepack", id: "spacepack" }, "MenuGroup:"]
dependencies: [
{ ext: "spacepack", id: "spacepack" },
"Menu API only allows Items and groups of Items as children."
]
},
evilMenu: {
dependencies: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,39 @@ function _saveProps(self: any, el: any) {
return el;
}

const MenuElements = spacepack.findByCode("return null", "MenuGroup:")[0]
.exports;

module.exports = {
...MenuElements,
addItem,
_patchMenu,
_saveProps
};

// Unmangle Menu elements
const code =
spacepack.require.m[
spacepack.findByCode(
"Menu API only allows Items and groups of Items as children."
)[0].id
].toString();

let MangledMenu;

const typeRegex = /if\(.\.type===(.)\.(.+?)\).+?type:"(.+?)"/g;
const typeMap: Record<string, string | undefined> = {
checkbox: "MenuCheckboxItem",
control: "MenuControlItem",
groupstart: "MenuGroup",
customitem: "MenuItem",
radio: "MenuRadioItem",
separator: "MenuSeparator"
};

for (const [, modIdent, mangled, type] of code.matchAll(typeRegex)) {
if (!MangledMenu) {
const modId = code.match(new RegExp(`${modIdent}=.\\((\\d+?)\\)`))![1];
MangledMenu = spacepack.require(modId);
}

const prop = typeMap[type];
if (!prop) continue;
module.exports[prop] = MangledMenu[mangled];
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const mod = new Function(
);
const exp: any = {};
mod({}, exp, require);
const Menu = spacepack.findFunctionByStrings(
exp,
"Menu API only allows Items and groups of Items as children."
)!;
module.exports = (el: any) => {
return exp.Menu({
return Menu({
children: el,
__contextMenu_evilMenu: true
});
Expand Down
14 changes: 7 additions & 7 deletions packages/core-extensions/src/disableSentry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ import { Patch, PatchReplaceType } from "@moonlight-mod/types";

export const patches: Patch[] = [
{
find: "DSN:function",
find: "profiledRootComponent:",
replace: {
type: PatchReplaceType.Normal,
match: /(?<=\.default=){.+?}}/,
match: /(?<=\.Z=){.+?}}/,
replacement: 'require("disableSentry_stub").proxy()'
}
},
{
find: "window.DiscordSentry.addBreadcrumb",
replace: {
type: PatchReplaceType.Normal,
match: /default:function\(\){return .}/,
match: /Z:function\(\){return .}/,
replacement:
'default:function(){return (...args)=>{moonlight.getLogger("disableSentry").debug("Sentry calling addBreadcrumb passthrough:", ...args);}}'
}
},
{
find: "initSentry:function",
find: "/error-reporting-proxy/web",
replace: {
type: PatchReplaceType.Normal,
match: /initSentry:function\(\){return .}/,
replacement: "default:function(){return ()=>{}}"
match: /(?<=function .\(\){var _;)/,
replacement: "return;"
}
},
{
find: "window.DiscordErrors=",
replace: {
type: PatchReplaceType.Normal,
match: /\(0,.\.usesClientMods\)\(\)/,
match: /(?<=uses_client_mods:)./,
replacement: "false"
}
}
Expand Down
7 changes: 1 addition & 6 deletions packages/core-extensions/src/moonbase/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ExtensionWebExports } from "@moonlight-mod/types";

import { CircleXIconSVG, DownloadIconSVG, TrashIconSVG } from "./types";

export const webpackModules: ExtensionWebExports["webpackModules"] = {
stores: {
dependencies: [
Expand All @@ -16,13 +14,10 @@ export const webpackModules: ExtensionWebExports["webpackModules"] = {
{ ext: "common", id: "react" },
{ ext: "common", id: "components" },
{ ext: "moonbase", id: "stores" },
DownloadIconSVG,
TrashIconSVG,
CircleXIconSVG,
"Masks.PANEL_BUTTON",
"removeButtonContainer:",
'"Missing channel in Channel.openChannelContextMenu"',
".default.HEADER_BAR"
".forumOrHome]:"
]
},

Expand Down
15 changes: 0 additions & 15 deletions packages/core-extensions/src/moonbase/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
import { DetectedExtension, ExtensionManifest } from "types/src";

export const DownloadIconSVG =
"M12 2a1 1 0 0 1 1 1v10.59l3.3-3.3a1 1 0 1 1 1.4 1.42l-5 5a1 1 0 0 1-1.4 0l-5-5a1 1 0 1 1 1.4-1.42l3.3 3.3V3a1 1 0 0 1 1-1ZM3 20a1 1 0 1 0 0 2h18a1 1 0 1 0 0-2H3Z";
export const TrashIconSVG =
"M5 6.99902V18.999C5 20.101 5.897 20.999 7 20.999H17C18.103 20.999 19 20.101 19 18.999V6.99902H5ZM11 17H9V11H11V17ZM15 17H13V11H15V17Z";
export const CircleXIconSVG =
"M7.02799 0.333252C3.346 0.333252 0.361328 3.31792 0.361328 6.99992C0.361328 10.6819 3.346 13.6666 7.02799 13.6666C10.71 13.6666 13.6947 10.6819 13.6947 6.99992C13.6947 3.31792 10.7093 0.333252 7.02799 0.333252ZM10.166 9.19525L9.22333 10.1379L7.02799 7.94325L4.83266 10.1379L3.89 9.19525L6.08466 6.99992L3.88933 4.80459L4.832 3.86259L7.02733 6.05792L9.22266 3.86259L10.1653 4.80459L7.97066 6.99992L10.166 9.19525Z";
export const DangerIconSVG =
"M12 23a11 11 0 1 0 0-22 11 11 0 0 0 0 22Zm1.44-15.94L13.06 14a1.06 1.06 0 0 1-2.12 0l-.38-6.94a1 1 0 0 1 1-1.06h.88a1 1 0 0 1 1 1.06Zm-.19 10.69a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Z";
export const ChevronSmallDownIconSVG =
"M16.59 8.59003L12 13.17L7.41 8.59003L6 10L12 16L18 10L16.59 8.59003Z";
export const ChevronSmallUpIconSVG =
"M7.41 16.0001L12 11.4201L16.59 16.0001L18 14.5901L12 8.59006L6 14.5901L7.41 16.0001Z";
export const ArrowsUpDownIconSVG =
"M3.81962 11.3333L3.81962 1.33325L5.52983 1.33325L5.52985 11.3333L7.46703 9.36658L8.66663 10.5916L4.67068 14.6666L0.666626 10.5916L1.86622 9.34158L3.81962 11.3333Z";

export type MoonbaseNatives = {
fetchRepositories(
repos: string[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function addSection(name: string, element: React.FunctionComponent) {
element: () => {
// Require it here because lazy loading SUX
const SettingsNotice =
spacepack.findByCode("onSaveButtonColor")[0].exports.default;
spacepack.findByCode("onSaveButtonColor")[0].exports.Z;
return (
<SettingsNotice
submitting={MoonbaseSettingsStore.submitting}
Expand All @@ -22,6 +22,7 @@ function addSection(name: string, element: React.FunctionComponent) {
onSave={() => {
MoonbaseSettingsStore.writeConfig();
}}
disabled={false}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LogLevel } from "@moonlight-mod/types";
import { CircleXIconSVG } from "../../../types";

const logLevels = Object.values(LogLevel).filter(
(v) => typeof v === "string"
Expand All @@ -19,6 +18,7 @@ import {
Tooltip,
Clickable
} from "@moonlight-mod/wp/common_components";
import CommonComponents from "@moonlight-mod/wp/common_components";

import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores";

Expand All @@ -27,7 +27,7 @@ const Margins = spacepack.findByCode("marginCenterHorz:")[0].exports;

const RemoveButtonClasses = spacepack.findByCode("removeButtonContainer")[0]
.exports;
const CircleXIcon = spacepack.findByCode(CircleXIconSVG)[0].exports.default;
const { CircleXIcon } = CommonComponents;
function RemoveEntryButton({ onClick }: { onClick: () => void }) {
return (
<div className={RemoveButtonClasses.removeButtonContainer}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
DangerIconSVG,
DownloadIconSVG,
ExtensionState,
TrashIconSVG
} from "../../../types";
import { ExtensionState } from "../../../types";
import { ExtensionLoadSource } from "@moonlight-mod/types";

import React from "@moonlight-mod/wp/common_react";
Expand All @@ -27,14 +22,10 @@ const UserProfileClasses = spacepack.findByCode(
"topSection"
)[0].exports;

const DownloadIcon =
spacepack.findByCode(DownloadIconSVG)[0].exports.DownloadIcon;
const TrashIcon = spacepack.findByCode(TrashIconSVG)[0].exports.default;
const DangerIcon =
spacepack.findByCode(DangerIconSVG)[0].exports.CircleExclamationPointIcon;
const { DownloadIcon, TrashIcon, CircleExclamationPointIcon } =
CommonComponents;

const PanelButton =
spacepack.findByCode("Masks.PANEL_BUTTON")[0].exports.default;
const PanelButton = spacepack.findByCode("Masks.PANEL_BUTTON")[0].exports.Z;

export default function ExtensionCard({ uniqueId }: { uniqueId: number }) {
const [tab, setTab] = React.useState(ExtensionPage.Info);
Expand Down Expand Up @@ -136,7 +127,7 @@ export default function ExtensionCard({ uniqueId }: { uniqueId: number }) {
{restartNeeded && (
<PanelButton
icon={() => (
<DangerIcon
<CircleExclamationPointIcon
color={CommonComponents.tokens.colors.STATUS_DANGER}
/>
)}
Expand Down
Loading

0 comments on commit 503326d

Please sign in to comment.