Skip to content

Commit

Permalink
Inject only those methods that are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Davilarek committed Feb 20, 2024
1 parent 59bb527 commit e03ffb4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
26 changes: 14 additions & 12 deletions src/api/RuntimeGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export function createFunctionFromObjectProperty(objectName: string, property: s
return generatedFunction;
}

import { FunctionImplementation, implementationStores, initStores } from "../common/index.js";
import { FunctionImplementation, doesImplement, implementationStores, initStores } from "../common/index.js";
import { createJavaScriptFromObject } from "../utils.js";
import { parse } from "@babel/parser";
import { IModImplementation } from "./ModImplementation.js";
/**
* this is really wrong, TODO: fix this piece of... garbage
*/
export async function addCode() {
export async function addCode(mod: IModImplementation) {
// let rawCode = "globalThis.implementationStores = {\n"; // TODO: fix, this is awful
// for (const key in implementationStores) {
// if (Object.prototype.hasOwnProperty.call(implementationStores, key)) {
Expand All @@ -56,16 +57,17 @@ export async function addCode() {
} = {};
for (const key in implementationStores) {
if (Object.prototype.hasOwnProperty.call(implementationStores, key)) {
constructed[key] = {
...implementationStores[key].implementationStore,
};
// constructed[key] = {};
// for (const key2 in implementationStores[key].implementationStore) {
// if (Object.prototype.hasOwnProperty.call(implementationStores[key].implementationStore, key2)) {
// const element = implementationStores[key].implementationStore[key2];
// constructed[key][key2] = getMain(serializer).serialize(element);
// }
// }
// constructed[key] = {
// ...implementationStores[key].implementationStore,
// };
constructed[key] = {};
for (const key2 in implementationStores[key].implementationStore) {
if (Object.prototype.hasOwnProperty.call(implementationStores[key].implementationStore, key2)) {
const element = implementationStores[key].implementationStore[key2];
if (doesImplement(mod, key, key2)) continue;
constructed[key][key2] = element;
}
}
}
}
// const rawCode = "globalThis.implementationStores = {\n" + getMain(serializer).serialize(constructed) + "\n}";
Expand Down
2 changes: 1 addition & 1 deletion src/common/Webpack.ts → src/common/WebpackApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionImplementation, require } from "./index.js";
import { IModImplementation } from "../api/ModImplementation";
import { IModImplementation } from "../api/ModImplementation.js";

// const reservedData = {} as { [key: string]: any };

Expand Down
2 changes: 1 addition & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ export default async function (ast: ParseResult<File>, targetedDiscordModApiLibr
}
}
}
parsedBodyWithoutOurImports.unshift(...await addCode());
parsedBodyWithoutOurImports.unshift(...await addCode(targetedDiscordModApiLibrary.default));
return parsedBodyWithoutOurImports;
}

0 comments on commit e03ffb4

Please sign in to comment.