Bundle whole project's types

This commit is contained in:
amsyarasyiq 2024-02-23 19:30:23 +08:00
parent 0ea0bbb69b
commit 6e4c6df1e5
13 changed files with 4759 additions and 31 deletions

View file

@ -28,7 +28,8 @@
"esbuild": "^0.17.16",
"esbuild-plugin-alias": "^0.2.1",
"moment": "2.22.2",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"typescript-transform-paths": "^3.4.7"
},
"dependencies": {
"@swc/helpers": "0.5.0",

View file

@ -1,5 +1,5 @@
\source ../../src/lib/windowObject.ts
\import ./src/lib/windowObject
\source ./dist/index.d.ts
\import ./index
@bunny from BunnyObject {
patcher

View file

@ -1,19 +1,33 @@
{
"name": "bunny-types",
"version": "0.0.1",
"version": "0.0.2",
"description": "Types for Bunny, a mod for Discord's mobile apps",
"author": "pylixonly",
"publishConfig": {
"directory": "dist",
"typings": "treetype.d.ts"
"typings": "index.d.ts"
},
"scripts": {
"prepublishOnly": "if [ -d dist ]; then rm -r dist; fi && tsc --project ../../tsconfig.json --outDir ./dist/src && cp package.json ./dist && cp LICENSE dist && pnpm treetype def.tt dist/treetype.d.ts"
"prepublishOnly": "node prepare.mjs"
},
"keywords": ["bunny-mod", "discord"],
"keywords": [
"bunny-mod",
"discord"
],
"license": "BSD-3-Clause",
"dependencies": {
"@types/chroma-js": "^2.4.0",
"@types/lodash": "^4.14.191",
"@types/react": "18.0.26",
"@types/react-native": "0.68.1",
"@react-native-clipboard/clipboard": "1.10.0",
"moment": "2.22.2",
"spitroast": "^1.4.2"
},
"devDependencies": {
"@uwu/treetype": "^1.1.0",
"dts-bundle-generator": "^9.3.1",
"ts-patch": "^3.1.2",
"typescript": "^5.3.3"
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,16 @@
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 });
}
await fs.mkdir("dist");
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');

View file

@ -0,0 +1,3 @@
{
"include": ["dist/*.ts"]
}

33
pnpm-lock.yaml generated
View file

@ -43,6 +43,9 @@ devDependencies:
typescript:
specifier: ^5.2.2
version: 5.2.2
typescript-transform-paths:
specifier: ^3.4.7
version: 3.4.7(typescript@5.2.2)
packages:
@ -405,6 +408,21 @@ packages:
resolution: {integrity: sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==}
dev: true
/balanced-match@1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: true
/brace-expansion@1.1.11:
resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==}
dependencies:
balanced-match: 1.0.2
concat-map: 0.0.1
dev: true
/concat-map@0.0.1:
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
dev: true
/csstype@3.1.2:
resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==}
dev: true
@ -443,6 +461,12 @@ packages:
'@esbuild/win32-x64': 0.17.16
dev: true
/minimatch@3.1.2:
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
dependencies:
brace-expansion: 1.1.11
dev: true
/moment@2.22.2:
resolution: {integrity: sha512-LRvkBHaJGnrcWvqsElsOhHCzj8mU39wLx5pQ0pc6s153GynCTsPdGdqsVNKAQD9sKnWj11iF7TZx9fpLwdD3fw==}
dev: true
@ -454,6 +478,15 @@ packages:
/tslib@2.6.2:
resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==}
/typescript-transform-paths@3.4.7(typescript@5.2.2):
resolution: {integrity: sha512-1Us1kdkdfKd2unbkBAOV2HHRmbRBYpSuk9nJ7cLD2hP4QmfToiM/VpxNlhJc1eezVwVqSKSBjNSzZsK/fWR/9A==}
peerDependencies:
typescript: '>=3.6.5'
dependencies:
minimatch: 3.1.2
typescript: 5.2.2
dev: true
/typescript@5.2.2:
resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==}
engines: {node: '>=14.17'}

4
src/global.d.ts vendored
View file

@ -1,4 +1,5 @@
import { MetroModules } from "./lib/metro/filters";
import { MetroModules } from "@lib/metro/filters";
import { BunnyObject } from "@lib/windowObject";
declare global {
type React = typeof import("react");
@ -8,6 +9,7 @@ declare global {
[key: string]: any;
modules: MetroModules;
vendetta: any;
bunny: BunnyObject;
React: typeof import("react");
}
}

View file

@ -24,7 +24,7 @@ export interface PluginManifest {
};
}
export interface Plugin {
export interface BunnyPlugin {
id: string;
manifest: PluginManifest;
enabled: boolean;
@ -32,7 +32,7 @@ export interface Plugin {
js: string;
}
export const plugins = wrapSync(createStorage<Record<string, Plugin>>(createMMKVBackend("VENDETTA_PLUGINS")));
export const plugins = wrapSync(createStorage<Record<string, BunnyPlugin>>(createMMKVBackend("VENDETTA_PLUGINS")));
const loadedPlugins: Record<string, EvaledPlugin> = {};
export async function fetchPlugin(id: string) {
@ -74,7 +74,7 @@ export async function installPlugin(id: string, enabled = true) {
if (enabled) await startPlugin(id);
}
export async function evalPlugin(plugin: Plugin) {
export async function evalPlugin(plugin: BunnyPlugin) {
const vendettaForPlugins = {
...window.vendetta,
plugin: {

View file

@ -26,26 +26,26 @@ function createBunnyObject(unloads: any[]) {
return {
patcher: utils.without(patcher, "unpatchAll"),
metro: { ...metro, common: { ...common } },
constants,
utils,
debug: utils.without(debug, "versionHash", "patchLogHook", "toggleSafeMode"),
constants: { ...constants },
utils: { ...utils },
debug: utils.without({ ...debug }, "versionHash", "patchLogHook", "toggleSafeMode"),
ui: {
components,
toasts,
alerts,
assets,
components: { ...components },
toasts: { ...toasts },
alerts: { ...alerts },
assets: { ...assets },
...color,
},
plugins: utils.without(plugins, "initPlugins", "evalPlugin"),
themes: utils.without(themes, "initThemes"),
commands: utils.without(commands, "patchCommands"),
storage,
settings,
plugins: utils.without({ ...plugins }, "initPlugins", "evalPlugin"),
themes: utils.without({ ...themes }, "initThemes"),
commands: utils.without({ ...commands }, "patchCommands"),
storage: { ...storage },
settings: settings,
loader: {
identity: window.__vendetta_loader,
config: loaderConfig,
},
logger,
logger: { ...logger },
version: debug.versionHash,
unload: () => {
unloads.filter(i => typeof i === "function").forEach(p => p());

View file

@ -1,5 +1,5 @@
import { NavigationNative, clipboard } from "@metro/common";
import { removePlugin, startPlugin, stopPlugin, getSettings, fetchPlugin, Plugin } from "@lib/plugins";
import { removePlugin, startPlugin, stopPlugin, getSettings, fetchPlugin, BunnyPlugin } from "@lib/plugins";
import { MMKVManager } from "@lib/native";
import { getAssetIDByName } from "@ui/assets";
import { showToast } from "@ui/toasts";
@ -8,13 +8,13 @@ import Card, { CardWrapper } from "@ui/settings/components/Card";
import { useProxy } from "@/lib/storage";
import { ButtonColors } from "@/lib/types";
async function stopThenStart(plugin: Plugin, callback: Function) {
async function stopThenStart(plugin: BunnyPlugin, callback: Function) {
if (plugin.enabled) stopPlugin(plugin.id, false);
callback();
if (plugin.enabled) await startPlugin(plugin.id);
}
export default function PluginCard({ item: plugin, index }: CardWrapper<Plugin>) {
export default function PluginCard({ item: plugin, index }: CardWrapper<BunnyPlugin>) {
useProxy(plugin);
const settings = getSettings(plugin.id);

View file

@ -1,5 +1,5 @@
import { useProxy } from "@lib/storage";
import { Plugin, installPlugin, plugins } from "@lib/plugins";
import { BunnyPlugin, installPlugin, plugins } from "@lib/plugins";
import settings from "@lib/settings";
import AddonPage from "@ui/settings/components/AddonPage";
import PluginCard from "@ui/settings/components/PluginCard";
@ -8,7 +8,7 @@ export default function Plugins() {
useProxy(settings)
return (
<AddonPage<Plugin>
<AddonPage<BunnyPlugin>
title="Plugin"
fetchFunction={installPlugin}
items={plugins}

View file

@ -1,5 +1,5 @@
{
"include": ["src"],
"include": ["src/**/*.ts"],
"exclude": ["node_modules"],
"compilerOptions": {
"baseUrl": ".",
@ -20,6 +20,9 @@
"@lib/*": ["src/lib/*"],
"@metro/*": ["src/lib/metro/*"],
"@ui/*": ["src/ui/*"]
}
},
"plugins": [
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
}