From dd6bb0b75354b57d4f64e10160c5f25e09986583 Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:49:31 +0800 Subject: [PATCH] duh --- packages/bunny-types/def.tt | 4 +- packages/bunny-types/prepare.mjs | 9 ++- src/global.d.ts | 2 +- src/lib/api/patcher.ts | 10 +-- src/lib/api/storage/index.ts | 8 ++- src/lib/index.ts | 9 +++ src/lib/metro/index.ts | 15 ++++- src/lib/windowObject.ts | 104 +------------------------------ 8 files changed, 45 insertions(+), 116 deletions(-) create mode 100644 src/lib/index.ts diff --git a/packages/bunny-types/def.tt b/packages/bunny-types/def.tt index f6f25c4..83ac7ce 100644 --- a/packages/bunny-types/def.tt +++ b/packages/bunny-types/def.tt @@ -1,5 +1,5 @@ -\source ./dist/index.d.ts -\import ./index +\source ./dist/wrap.ts +\import ./wrap @bunny from BunnyObject { api { diff --git a/packages/bunny-types/prepare.mjs b/packages/bunny-types/prepare.mjs index e5f24d4..056a442 100644 --- a/packages/bunny-types/prepare.mjs +++ b/packages/bunny-types/prepare.mjs @@ -1,7 +1,7 @@ +import * as childProcess from "node:child_process"; import { existsSync } from "node:fs"; import * as fs from "node:fs/promises"; import * as util from "node:util"; -import * as childProcess from "node:child_process"; if (existsSync("dist")) { await fs.rm("dist", { recursive: true }); @@ -12,5 +12,8 @@ const exec = util.promisify(childProcess.exec); await fs.copyFile("package.json", "./dist/package.json"); await fs.copyFile("LICENSE", "./dist/LICENSE"); -await exec("pnpm dts-bundle-generator -o dist/index.d.ts --project ../../tsconfig.json --inline-declare-global ../../src/global.d.ts --no-check --sort --no-banner") -await exec('pnpm treetype def.tt dist/treetype.d.ts'); \ No newline at end of file +await exec("pnpm dts-bundle-generator -o dist/index.d.ts --project ../../tsconfig.json ../../src/lib/index.ts --no-check --sort --no-banner"); + +await fs.writeFile("./dist/wrap.ts", "export type BunnyObject = typeof import(\".\")"); + +await exec("pnpm treetype def.tt dist/treetype.d.ts"); diff --git a/src/global.d.ts b/src/global.d.ts index 07aad2d..7aa4ec6 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -13,4 +13,4 @@ declare global { } } -export {}; +export { }; diff --git a/src/lib/api/patcher.ts b/src/lib/api/patcher.ts index e32dae9..c3784a6 100644 --- a/src/lib/api/patcher.ts +++ b/src/lib/api/patcher.ts @@ -1,4 +1,6 @@ -import * as _spitroast from "spitroast"; - -export * from "spitroast"; -export default { ..._spitroast }; +export { + after, + before, + instead +} from "spitroast"; +export * as default from "spitroast"; diff --git a/src/lib/api/storage/index.ts b/src/lib/api/storage/index.ts index 157f18d..3f634f1 100644 --- a/src/lib/api/storage/index.ts +++ b/src/lib/api/storage/index.ts @@ -4,7 +4,7 @@ import { createEmitter, Emitter } from "@lib/utils/emitter"; const emitterSymbol = Symbol.for("vendetta.storage.emitter"); const syncAwaitSymbol = Symbol.for("vendetta.storage.accessor"); -export function createProxy(target: any = {}): { proxy: any; emitter: Emitter } { +export function createProxy(target: any = {}): { proxy: any; emitter: Emitter; } { const emitter = createEmitter(); function createProxy(target: any, path: string[]): any { @@ -113,4 +113,8 @@ export function wrapSync>(store: T): Awaited { export const awaitSyncWrapper = (store: any) => new Promise(res => store[syncAwaitSymbol](res)); -export * from "@lib/api/storage/backends"; +export { + createFileBackend, + createMMKVBackend, + purgeStorage +} from "@lib/api/storage/backends"; diff --git a/src/lib/index.ts b/src/lib/index.ts new file mode 100644 index 0000000..e7a669b --- /dev/null +++ b/src/lib/index.ts @@ -0,0 +1,9 @@ +import "../global.d.ts"; + +export * as api from "./api"; +export * as debug from "./debug"; +export * as managers from "./managers"; +export * as metro from "./metro"; +export * as settings from "./settings"; +export * as ui from "./ui"; +export * as utils from "./utils"; diff --git a/src/lib/metro/index.ts b/src/lib/metro/index.ts index 4c0681f..ebe4004 100644 --- a/src/lib/metro/index.ts +++ b/src/lib/metro/index.ts @@ -1,3 +1,16 @@ export * as common from "./common"; -export * from "./filters"; +export { + find, + findAll, + findByDisplayName, + findByDisplayNameAll, + findByName, + findByNameAll, + findByProps, + findByPropsAll, + findByStoreName, + findByTypeName, + findByTypeNameAll, + modules +} from "./filters"; export * as filters from "./filters"; diff --git a/src/lib/windowObject.ts b/src/lib/windowObject.ts index 8f99026..e63d32b 100644 --- a/src/lib/windowObject.ts +++ b/src/lib/windowObject.ts @@ -1,108 +1,6 @@ import { createVendettaObject } from "@core/vendettaObject"; -import * as api from "@lib/api"; -import patcher from "@lib/api/patcher"; -import * as debug from "@lib/debug"; -import * as managers from "@lib/managers"; -import * as metro from "@lib/metro"; -import * as settings from "@lib/settings"; -import * as ui from "@lib/ui"; -import * as utils from "@lib/utils"; -import { ExcludeInternalProperties } from "@lib/utils/types"; - -function createBunnyObject(unloads: any[]): BunnyObject { - return { - api: { - ...api, - patcher - }, - managers, - metro, - ui, - utils, - settings, - debug, - version: debug._versionHash, - unload: () => { - unloads.filter(i => typeof i === "function").forEach(p => p()); - // @ts-expect-error - delete window.bunny; - }, - }; -} export default function initWindowObject(unloads: any[]) { window.vendetta = createVendettaObject(unloads); - window.bunny = createBunnyObject(unloads); + window.bunny = require("."); } - -/* - (You may now worry about my mental state.) - This is a hack, apparently when you destruct a star-imported module, its type is deferenced - We need to do this for every module because the types bundler apparently does not support referencing star-imported modules(?) - I only have realized this after getting everything set up, thinking it'd go well :) - The API should be the same (or easy to migrate) even if we got alternatives in the future - Another cons: JSDocs are stripped and a lot of declaration duplicates - - See: https://github.com/timocov/dts-bundle-generator/issues/304 -*/ -export type BunnyObject = ExcludeInternalProperties>; -const _bunnyObject = () => ({ // this function is never used, only exists for typings - api: { - ...api, - flux: { ...api.flux }, - commands: { ...api.commands }, - native: { - ...api.native, - fs: { ...api.native.fs }, - modules: { ...api.native.modules }, - loader: { ...api.native.loader } - }, - storage: { ...api.storage }, - assets: { ...api.assets }, - patcher: utils.without({ - ...patcher, - unpatchAll: () => { } - }, "unpatchAll") - }, - managers: { - ...managers, - plugins: { ...managers.plugins }, - themes: { ...managers.themes } - }, - metro: { - ...metro, - common: { ...metro.common }, - filters: { ...metro.filters }, - ...metro.filters - }, - ui: { - ...ui, - components: { - ...ui.components, - discord: { - ...ui.components.discord, - Forms: { ...ui.components.discord.Forms }, - Redesign: { ...ui.components.discord.Redesign } - } - }, - alerts: { ...ui.alerts }, - color: { ...ui.color }, - toasts: { ...ui.toasts }, - styles: { ...ui.styles }, - settings: { ...ui.settings } - }, - utils: { - ...utils, - constants: { ...utils.constants }, - types: { ...utils.types }, - logger: { ...utils.logger }, - }, - settings: { - ...settings, - settings: settings.settings, - loaderConfig: { ...settings.loaderConfig } - }, - debug: { ...debug }, - version: debug._versionHash, - unload: () => { }, -});