refactor: misc. changes

This commit is contained in:
ryan-0324 2024-08-09 17:05:06 -04:00
parent daaf205637
commit 8329b40448
24 changed files with 238 additions and 473 deletions

View file

@ -6,7 +6,6 @@ import eslintPluginReact from "eslint-plugin-react";
// @ts-expect-error: No types
import simpleHeader from "eslint-plugin-simple-header";
import simpleImportSort from "eslint-plugin-simple-import-sort";
// @ts-expect-error: No types
import unusedImports from "eslint-plugin-unused-imports";
import tseslint from "typescript-eslint";

View file

@ -44,14 +44,14 @@
"nanoid": "^5.0.7"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^2.6.1",
"@stylistic/eslint-plugin": "^2.6.2",
"@stylistic/stylelint-config": "^2.0.0",
"@stylistic/stylelint-plugin": "^3.0.0",
"@types/chrome": "^0.0.269",
"@types/diff": "^5.2.1",
"@types/html-minifier-terser": "^7.0.2",
"@types/lodash": "~4.17.7",
"@types/node": "^18.19.43",
"@types/node": "^18.19.44",
"@types/react": "~18.2.79",
"@types/react-dom": "~18.2.25",
"@types/yazl": "^2.4.5",
@ -59,22 +59,22 @@
"diff": "^5.2.0",
"discord-types": "latest",
"esbuild": "^0.23.0",
"eslint": "^9.8.0",
"eslint": "^9.9.0",
"eslint-plugin-path-alias": "^2.1.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-simple-header": "^1.1.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.0.1",
"eslint-plugin-unused-imports": "^4.1.2",
"highlight.js": "11.8.0",
"html-minifier-terser": "^7.2.0",
"moment": "2.22.2",
"puppeteer-core": "^23.0.1",
"puppeteer-core": "^23.0.2",
"standalone-electron-types": "^1.0.0",
"stylelint": "^16.8.1",
"stylelint-config-standard": "^36.0.1",
"ts-patch": "^3.2.1",
"tsx": "^4.16.5",
"type-fest": "^4.23.0",
"tsx": "^4.17.0",
"type-fest": "^4.24.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.1",
"typescript-transform-paths": "^3.4.10",
@ -83,9 +83,9 @@
"packageManager": "pnpm@9.7.0",
"pnpm": {
"patchedDependencies": {
"@stylistic/eslint-plugin-js@2.6.1": "patches/@stylistic__eslint-plugin-js@2.6.1.patch",
"@stylistic/eslint-plugin-js@2.6.2": "patches/@stylistic__eslint-plugin-js@2.6.2.patch",
"eslint-plugin-path-alias@2.1.0": "patches/eslint-plugin-path-alias@2.1.0.patch",
"eslint@9.8.0": "patches/eslint@9.8.0.patch",
"eslint@9.9.0": "patches/eslint@9.9.0.patch",
"standalone-electron-types@1.0.0": "patches/standalone-electron-types@1.0.0.patch"
},
"peerDependencyRules": {

View file

@ -6,7 +6,6 @@ import eslintPluginImport from "eslint-plugin-import-x";
import simpleHeader from "eslint-plugin-simple-header";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import eslintPluginUnicorn from "eslint-plugin-unicorn";
// @ts-expect-error: No types
import unusedImports from "eslint-plugin-unused-imports";
import tseslint from "typescript-eslint";

View file

@ -26,24 +26,24 @@
"@types/react": "~18.2.79",
"dependency-graph": "0.9.0",
"moment": "2.22.2",
"simple-markdown": "0.7.2",
"type-fest": "^4.23.0"
"simple-markdown": "0.7.2"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^2.6.1",
"@types/node": "^20.14.14",
"@stylistic/eslint-plugin": "^2.6.2",
"@types/node": "^20.14.15",
"@types/semver": "^7.5.8",
"@typescript-eslint/typescript-estree": "^8.0.1",
"eslint": "^9.8.0",
"eslint": "^9.9.0",
"eslint-plugin-check-file": "^2.8.0",
"eslint-plugin-import-x": "^3.1.0",
"eslint-plugin-simple-header": "^1.1.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-unused-imports": "^4.0.1",
"puppeteer-core": "^23.0.1",
"eslint-plugin-unused-imports": "^4.1.2",
"puppeteer-core": "^23.0.2",
"semver": "^7.6.3",
"tsx": "^4.16.5",
"tsx": "^4.17.0",
"type-fest": "^4.24.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.1"
}

View file

@ -11,7 +11,7 @@ import type { CR } from "../types.mts";
export function autoFindStore(this: typeof Vencord, name: string, source: CR.ClassMembers) {
const persistKeyRE = new RegExp(`^${name}(?:V\\d+)?$`);
const store: { constructor: CR.Class; } | undefined = this.Webpack.find((exp: any) => {
const store: { constructor: CR.Class; } | undefined = this.Webpack.find(exp => {
// Find stores from exported instances
const { constructor } = exp;
return typeof constructor === "function" && (
@ -29,7 +29,7 @@ export function autoFindClass(this: typeof Vencord, source: CR.ClassMembers) {
let lowestChangedCount = Infinity;
const checked = new WeakSet<CR.Class>();
this.Webpack.find((exps: any) => {
this.Webpack.find(exps => {
for (const name in exps) {
let constructor: CR.Class;
// Some getters throw errors

View file

@ -13,7 +13,7 @@ export function autoFindEnum(this: typeof Vencord, source: CR.EnumSource) {
let lowestChangedCount = Infinity;
const checked = new WeakSet();
this.Webpack.find((exps: any) => {
this.Webpack.find(exps => {
for (const name in exps) {
let exp: unknown;
// Some getters throw errors

View file

@ -6,6 +6,7 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import process from "node:process";
import puppeteer from "puppeteer-core";

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import console from "node:console";
import { writeFile } from "node:fs/promises";
import type { CR } from "../types.mts";

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import console from "node:console";
import type { CR } from "../types.mts";
import { codeBlock, formatChannel, getSummaryURL } from "./utils.mjs";

View file

@ -28,7 +28,7 @@ export async function getDependenciesReport(page: Page, filePath: string, config
let dependencies: JsonValue | undefined;
try {
({ dependencies } = JSON.parse(await readFile(filePath, "utf-8")));
dependencies = JSON.parse(await readFile(filePath, "utf-8"))?.dependencies;
} catch (error) {
fileReport.fileError = `Failed to read and parse file '${fileName}':\n` + error;
return fileReport;

View file

@ -38,7 +38,7 @@ const functionDeclarationOrArrowFunctionDefinitionRE = /^(?:async(?:[\t\v\f\uFEF
* Does not support getters, setters, static methods, private methods/getters/setters,
* or method definitions with symbol keys.
*/
export function funcToString(func: (...args: never[]) => unknown) {
export function funcToString(func: (...args: never) => unknown) {
const funcString = func.toString();
if (functionDeclarationOrArrowFunctionDefinitionRE.test(funcString))
return `(${funcString})`;

View file

@ -196,7 +196,7 @@ export namespace CR {
export interface Class {
/** Constructor function */
new (...args: never[]): unknown;
new (...args: never): unknown;
/** Static members */
[key: PropertyKey]: unknown;
/** Instance methods and accessors */

View file

@ -4,9 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import type { SnakeCasedProperties } from "type-fest";
import type { Nullish, Optional, PartialOnUndefined } from "../internal";
import type { Nullish, Optional, PartialOnUndefined, SnakeCasedProperties } from "../internal";
import type { CompanyRecord } from "./CompanyRecord";
import type { ImmutableRecord } from "./ImmutableRecord";
import type { IconSource } from "./misc";

View file

@ -4,8 +4,6 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import type { StringProperties } from "../internal";
// Original name: Record
// Renamed to avoid name conflicts with TypeScripts's Record utility type.
export declare abstract class ImmutableRecord<
@ -13,7 +11,7 @@ export declare abstract class ImmutableRecord<
> {
constructor(properties: OwnProperties);
merge(collection: Partial<StringProperties<OwnProperties>>): this;
merge(collection: Partial<Omit<OwnProperties, symbol>>): this;
set<Key extends keyof OwnProperties>(key: Key, value: OwnProperties[Key]): this;
toJS(): OwnProperties;
update<Key extends keyof OwnProperties>(

View file

@ -4,9 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import type { SnakeCasedProperties } from "type-fest";
import type { Nullish, Optional } from "../internal";
import type { Nullish, Optional, SnakeCasedProperties } from "../internal";
import type { ImmutableRecord } from "./ImmutableRecord";
import type { IconSource } from "./misc";

View file

@ -4,9 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import type { SnakeCasedProperties } from "type-fest";
import type { Nullish, Optional } from "../../internal";
import type { Nullish, Optional, SnakeCasedProperties } from "../../internal";
import type { PermissionOverwriteMap } from "../Permissions";
import type { AvatarDecorationData, UserClanData, UserFlags } from "../UserRecord";
import type { ForumChannelRecord } from "./ForumChannelRecord";

View file

@ -8,11 +8,11 @@ import type MessageFormat from "intl-messageformat";
import type { ReactElement, ReactNode } from "react";
import type { State } from "simple-markdown";
import type { IsAny, OmitOptional, Stringable, UnionToIntersection } from "../../internal";
import type { IsAny, IsStringLiteral, Stringable, UnionToIntersection } from "../../internal";
export declare class FormattedMessage<
Args extends GenericArgs = never,
Markdown extends boolean | undefined = boolean
Args extends GenericArgs = GenericArgs,
Markdown extends boolean | undefined = boolean | undefined
> {
/**
* @throws {SyntaxError} Argument `message` must be syntactically valid.
@ -23,7 +23,9 @@ export declare class FormattedMessage<
constructor(
message: string,
locales?: string | readonly string[] | undefined /* = MessageFormat.defaultLocale */,
hasMarkdown?: Markdown
...hasMarkdown: undefined extends Markdown
? [hasMarkdown?: Markdown]
: [hasMarkdown: Markdown]
);
/**
@ -38,9 +40,9 @@ export declare class FormattedMessage<
format(...args: FormatArgs<Args>): Markdown extends true
? (string | ReactElement)[]
: string;
getContext(values: ContextValues<Args>): [
{ [Key in keyof typeof values]: typeof values[Key] | number; },
Record<number, typeof values[keyof typeof values]>
getContext<Values extends RecordArgs>(values: Values): [
{ [Key in keyof Values]: Values[Key] | (Key & keyof MessageValues<Args> extends never ? never : number); },
Record<number, Values[keyof Values & keyof MessageValues<Args>]>
];
/**
* @throws {RangeError | TypeError}
@ -65,25 +67,19 @@ type FormatArgs<Args extends GenericArgs>
? [values?: RecordArgs]
: [Args] extends [never]
? []
: keyof FormatValues<Args> extends never
: keyof MessageValues<Args> extends never
? []
: [values: FormatValues<Args>];
: false extends IsStringLiteral<keyof MessageValues<Args> & string>
? [values: never]
: [values: MessageValues<Args>];
type FormatValues<Args extends GenericArgs> = UnionToIntersection<MessageValues<Args>>;
type ContextValues<Args extends GenericArgs>
= unknown extends IsAny<Args>
? RecordArgs
: [Args] extends [never]
? {}
: MessageValues<Args>;
type MessageValues<Args extends GenericArgs>
= Args extends string
? Record<string extends Args ? never : Args, Stringable>
: Args extends readonly [string, string]
type MessageValues<Args extends GenericArgs> = UnionToIntersection<
Args extends string
? Record<Args, Stringable>
: Args extends TupleArgs
? Record<Args[0], Stringable> & Record<Args[1], HookValue>
: OmitOptional<Args>;
: Required<Pick<Args, keyof Args & string>>
>;
/** @todo Add types for every type of ASTNode. */
export interface ASTNode<Type extends ASTNodeType = ASTNodeType> extends Record<string, any> {

View file

@ -6,9 +6,8 @@
import type { Duration, Moment } from "moment";
import type { ReactNode } from "react";
import type { SnakeCasedProperties } from "type-fest";
import type { Nullish, Optional, PartialOnUndefined } from "../../internal";
import type { Nullish, Optional, PartialOnUndefined, SnakeCasedProperties } from "../../internal";
import type { ApplicationCommand, ApplicationCommandType } from "../ApplicationCommand";
import type { ApplicationIntegrationType } from "../ApplicationRecord";
import type { ChannelRecord, ChannelType } from "../channels/ChannelRecord";

View file

@ -5,9 +5,8 @@
*/
import type { Moment } from "moment";
import type { SnakeCasedProperties } from "type-fest";
import type { Nullish, Optional } from "../../internal";
import type { Nullish, Optional, SnakeCasedProperties } from "../../internal";
import type { ChannelType } from "../channels/ChannelRecord";
import type { ImmutableRecord } from "../ImmutableRecord";

View file

@ -5,7 +5,7 @@
*/
/** @internal */
export type Bivariant<T extends (...args: never[]) => unknown>
export type Bivariant<T extends (...args: never) => unknown>
// eslint-disable-next-line @typescript-eslint/method-signature-style
= { _(...args: Parameters<T>): ReturnType<T>; }["_"];
@ -18,21 +18,23 @@ export type GenericConstructor = new (...args: any[]) => unknown;
/** @internal */
export type IsAny<T> = 0 extends 1 & T ? unknown : never;
/** @internal */
export type IsStringLiteral<T extends string>
= T extends unknown
? {} extends Record<T, unknown>
? false
: true
: never;
/** @internal */
export type Nullish = null | undefined;
/** @internal */
export type OmitOptional<T> = {
[Key in keyof T as {} extends Record<Key, unknown>
? never
: T extends Record<Key, unknown>
? Key
: never
]: T[Key];
};
export type OmitOptional<T>
= { [Key in keyof T as T extends Record<Key, unknown> ? Key : never]: T[Key]; };
/** @internal */
export type Optional<T, Value = undefined, Keys extends keyof T = keyof T, ExcludeKeys = false>
export type Optional<T, Value = undefined, Keys extends keyof T = keyof T, ExcludeKeys extends boolean = false>
= ExcludeKeys extends true
? Pick<T, Keys> & { [Key in Exclude<keyof T, Keys>]?: T[Key] | Value; }
: Omit<T, Keys> & { [Key in Keys]?: T[Key] | Value; };
@ -45,6 +47,25 @@ export type OptionalTuple<T extends readonly unknown[], Value = undefined>
export type PartialOnUndefined<T> = Partial<T>
& { [Key in keyof T as undefined extends T[Key] ? never : Key]: T[Key]; };
type SnakeCase<T extends string, InAcronym extends boolean = false>
= T extends `${infer First}${infer Second}${infer Rest}`
? InAcronym extends true
? Second extends Uppercase<string>
? `${Lowercase<First>}${SnakeCase<`${Second}${Rest}`, true>}`
: `_${Lowercase<First>}${SnakeCase<`${Second}${Rest}`>}`
: First extends Lowercase<string>
? Second extends Lowercase<string>
? `${First}${SnakeCase<`${Second}${Rest}`>}`
: `${First}_${SnakeCase<`${Second}${Rest}`>}`
: Second extends Uppercase<string>
? `${Lowercase<First>}${SnakeCase<`${Second}${Rest}`, true>}`
: `${Lowercase<First>}${SnakeCase<`${Second}${Rest}`>}`
: Lowercase<T>;
/** @internal */
export type SnakeCasedProperties<T>
= { [Key in keyof T as Key extends string ? SnakeCase<Key> : Key]: T[Key]; };
type StringablePrimitive = string | bigint | number | boolean | Nullish;
/** @internal */
@ -53,9 +74,6 @@ export type Stringable
| ({ toString: () => StringablePrimitive; } | { valueOf: () => StringablePrimitive; })
& { [Symbol.toPrimitive]?: Nullish; };
/** @internal */
export type StringProperties<T> = { [Key in Exclude<keyof T, symbol>]: T[Key]; };
/** @internal */
export type UnionToIntersection<Union> = (
Union extends unknown

View file

@ -17,18 +17,18 @@
"types": "./index.d.ts",
"dependencies": {
"@types/lodash": "~4.17.7",
"@types/node": "^18.19.43",
"@types/node": "^18.19.44",
"@types/react": "~18.2.79",
"@types/react-dom": "~18.2.25",
"@vencord/discord-types": "workspace:^",
"discord-types": "latest",
"standalone-electron-types": "^1.0.0",
"type-fest": "^4.23.0"
"type-fest": "^4.24.0"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"fs-extra": "^11.2.0",
"tsx": "^4.16.5",
"tsx": "^4.17.0",
"typescript": "^5.5.4"
}
}

File diff suppressed because it is too large Load diff