Skip to content

Commit 6f98d4f

Browse files
committed
refactor: cleanup compiler plugins
1 parent b399683 commit 6f98d4f

19 files changed

+389
-533
lines changed

apps/test-bot/src/app/commands/(interactions)/commandkit.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CommandKit, {
33
ActionRow,
44
CommandData,
55
OnButtonKitClick,
6-
SlashCommandContext,
6+
ChatInputCommandContext,
77
} from 'commandkit';
88
import { MessageFlags } from 'discord.js';
99

@@ -40,7 +40,7 @@ function ButtonGrid() {
4040
);
4141
}
4242

43-
export async function chatInput({ interaction }: SlashCommandContext) {
43+
export async function chatInput({ interaction }: ChatInputCommandContext) {
4444
await interaction.deferReply();
4545

4646
await interaction.editReply({

apps/test-bot/src/app/commands/(interactions)/confirmation.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CommandKit, {
22
Button,
33
ActionRow,
4-
SlashCommandContext,
4+
ChatInputCommandContext,
55
CommandData,
66
OnButtonKitClick,
77
} from 'commandkit';
@@ -30,7 +30,7 @@ const handleCancel: OnButtonKitClick = async (interaction, context) => {
3030
context.dispose();
3131
};
3232

33-
export async function chatInput({ interaction }: SlashCommandContext) {
33+
export async function chatInput({ interaction }: ChatInputCommandContext) {
3434
const buttons = (
3535
<ActionRow>
3636
<Button onClick={handleCancel} style={ButtonStyle.Primary}>

apps/test-bot/src/app/commands/(interactions)/prompt.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CommandKit, {
55
ParagraphInput,
66
OnModalKitSubmit,
77
MessageCommandContext,
8-
SlashCommandContext,
8+
ChatInputCommandContext,
99
} from 'commandkit';
1010
import { MessageFlags } from 'discord.js';
1111

@@ -26,7 +26,7 @@ const handleSubmit: OnModalKitSubmit = async (interaction, context) => {
2626
context.dispose();
2727
};
2828

29-
export async function chatInput(ctx: SlashCommandContext) {
29+
export async function chatInput(ctx: ChatInputCommandContext) {
3030
const modal = (
3131
<Modal title={'Modal'} onSubmit={handleSubmit}>
3232
<ShortInput customId="name" label="Name" placeholder="John" required />

apps/test-bot/src/app/commands/(select menu)/select-channel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CommandKit, {
33
ChannelSelectMenu,
44
CommandData,
55
OnChannelSelectMenuKitSubmit,
6-
SlashCommand,
6+
ChatInputCommand,
77
} from 'commandkit';
88

99
export const command: CommandData = {
@@ -24,7 +24,7 @@ const handleSelect: OnChannelSelectMenuKitSubmit = async (
2424
context.dispose();
2525
};
2626

27-
export const chatInput: SlashCommand = async (ctx) => {
27+
export const chatInput: ChatInputCommand = async (ctx) => {
2828
const select = (
2929
<ActionRow>
3030
<ChannelSelectMenu onSelect={handleSelect} />

apps/test-bot/src/app/commands/(select menu)/select-mentionable.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CommandKit, {
33
CommandData,
44
MentionableSelectMenu,
55
OnMentionableSelectMenuKitSubmit,
6-
SlashCommand,
6+
ChatInputCommand,
77
} from 'commandkit';
88

99
export const command: CommandData = {
@@ -25,7 +25,7 @@ const handleSelect: OnMentionableSelectMenuKitSubmit = async (
2525
context.dispose();
2626
};
2727

28-
export const chatInput: SlashCommand = async (ctx) => {
28+
export const chatInput: ChatInputCommand = async (ctx) => {
2929
const select = (
3030
<ActionRow>
3131
<MentionableSelectMenu onSelect={handleSelect} />

apps/test-bot/src/app/commands/(select menu)/select-role.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CommandKit, {
33
CommandData,
44
OnRoleSelectMenuKitSubmit,
55
RoleSelectMenu,
6-
SlashCommand,
6+
ChatInputCommand,
77
} from 'commandkit';
88

99
export const command: CommandData = {
@@ -24,7 +24,7 @@ const handleSelect: OnRoleSelectMenuKitSubmit = async (
2424
context.dispose();
2525
};
2626

27-
export const chatInput: SlashCommand = async (ctx) => {
27+
export const chatInput: ChatInputCommand = async (ctx) => {
2828
const select = (
2929
<ActionRow>
3030
<RoleSelectMenu onSelect={handleSelect} />

apps/test-bot/src/app/commands/(select menu)/select-string-multi.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import CommandKit, {
22
ActionRow,
33
CommandData,
44
OnStringSelectMenuKitSubmit,
5-
SlashCommand,
5+
ChatInputCommand,
66
StringSelectMenu,
77
StringSelectMenuOption,
88
} from 'commandkit';
@@ -25,7 +25,7 @@ const handleSelect: OnStringSelectMenuKitSubmit = async (
2525
context.dispose();
2626
};
2727

28-
export const chatInput: SlashCommand = async (ctx) => {
28+
export const chatInput: ChatInputCommand = async (ctx) => {
2929
const select = (
3030
<ActionRow>
3131
<StringSelectMenu onSelect={handleSelect} maxValues={9} minValues={1}>

apps/test-bot/src/app/commands/(select menu)/select-string.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import CommandKit, {
22
ActionRow,
33
CommandData,
44
OnStringSelectMenuKitSubmit,
5-
SlashCommand,
5+
ChatInputCommand,
66
StringSelectMenu,
77
StringSelectMenuOption,
88
} from 'commandkit';
@@ -25,7 +25,7 @@ const handleSelect: OnStringSelectMenuKitSubmit = async (
2525
context.dispose();
2626
};
2727

28-
export const chatInput: SlashCommand = async (ctx) => {
28+
export const chatInput: ChatInputCommand = async (ctx) => {
2929
const select = (
3030
<ActionRow>
3131
<StringSelectMenu onSelect={handleSelect}>

apps/test-bot/src/app/commands/(select menu)/select-user.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import CommandKit, {
22
ActionRow,
33
CommandData,
44
OnUserSelectMenuKitSubmit,
5-
SlashCommand,
5+
ChatInputCommand,
66
UserSelectMenu,
77
} from 'commandkit';
88

@@ -24,7 +24,7 @@ const handleSelect: OnUserSelectMenuKitSubmit = async (
2424
context.dispose();
2525
};
2626

27-
export const chatInput: SlashCommand = async (ctx) => {
27+
export const chatInput: ChatInputCommand = async (ctx) => {
2828
const select = (
2929
<ActionRow>
3030
<UserSelectMenu onSelect={handleSelect} />

packages/commandkit/package.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@
3030
"event handler"
3131
],
3232
"dependencies": {
33-
"@babel/generator": "^7.26.5",
34-
"@babel/parser": "^7.26.5",
35-
"@babel/traverse": "^7.26.5",
36-
"@babel/types": "^7.26.5",
3733
"chokidar": "^4.0.3",
3834
"commander": "^12.1.0",
35+
"directive-to-hof": "^0.0.2",
3936
"dotenv": "^16.4.7",
4037
"ms": "^2.1.3",
4138
"ora": "^8.0.1",
@@ -46,8 +43,6 @@
4643
"use-macro": "^1.1.0"
4744
},
4845
"devDependencies": {
49-
"@types/babel__generator": "^7.6.8",
50-
"@types/babel__traverse": "^7.20.6",
5146
"@types/ms": "^0.7.34",
5247
"@types/node": "^22.10.2",
5348
"@types/yargs": "^17.0.32",

packages/commandkit/src/cache/use-cache.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,5 @@ export function isCachedFunction(fn: GenericFunction): boolean {
309309
* @private
310310
* @internal
311311
*/
312-
export const zxcvbnm____: any = useCache;
312+
export const __SECRET_USE_CACHE_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: any =
313+
useCache;

packages/commandkit/src/cli/generators.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { mkdir, writeFile, readdir } from 'fs/promises';
22
import { join } from 'path';
3-
import { Locale } from 'discord.js';
43
import { panic } from './common';
54
import { existsSync } from 'fs';
65
import colors from '../utils/colors';

packages/commandkit/src/config/default.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CachePlugin } from '../plugins/plugin-runtime/builtin/cache/CachePlugin';
1+
import { CachePlugin } from '../plugins/plugin-runtime/builtin/CachePlugin';
22
import { MacroPlugin } from '../plugins/plugin-runtime/builtin/MacroPlugin';
33
import { ResolvedCommandKitConfig } from './utils';
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
CommonDirectiveTransformer,
3+
CommonDirectiveTransformerOptions,
4+
} from './CommonDirectiveTransformer';
5+
6+
export class CachePlugin extends CommonDirectiveTransformer {
7+
public readonly name = 'CachePlugin';
8+
9+
public constructor(options?: Partial<CommonDirectiveTransformerOptions>) {
10+
super({
11+
...options,
12+
directive: 'use cache',
13+
importPath: 'commandkit',
14+
importName: '__SECRET_USE_CACHE_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED',
15+
asyncOnly: true,
16+
});
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { DirectiveTransformerOptions } from 'directive-to-hof';
2+
import {
3+
CompilerPlugin,
4+
CompilerPluginRuntime,
5+
MaybeFalsey,
6+
PluginTransformParameters,
7+
TransformedResult,
8+
} from '../..';
9+
10+
export type CommonDirectiveTransformerOptions = DirectiveTransformerOptions & {
11+
enabled?: boolean;
12+
};
13+
14+
export abstract class CommonDirectiveTransformer extends CompilerPlugin<CommonDirectiveTransformerOptions> {
15+
private transformer: ReturnType<
16+
typeof import('directive-to-hof').createDirectiveTransformer
17+
> | null = null;
18+
19+
public async activate(ctx: CompilerPluginRuntime): Promise<void> {
20+
const { createDirectiveTransformer } = await import('directive-to-hof');
21+
this.transformer = createDirectiveTransformer(this.options);
22+
}
23+
24+
public async deactivate(ctx: CompilerPluginRuntime): Promise<void> {
25+
this.transformer = null;
26+
}
27+
28+
public async transform(
29+
params: PluginTransformParameters,
30+
): Promise<MaybeFalsey<TransformedResult>> {
31+
if (!this.options.enabled) return null;
32+
if (!this.transformer) return null;
33+
34+
const result = await this.transformer(
35+
params.contents.toString(),
36+
params.path,
37+
);
38+
39+
return {
40+
contents: result.contents,
41+
loader: result.loader,
42+
};
43+
}
44+
}

packages/commandkit/src/plugins/plugin-runtime/builtin/cache/CachePlugin.ts

-27
This file was deleted.

packages/commandkit/src/plugins/plugin-runtime/builtin/cache/UseCacheTransformer.ts

-8
This file was deleted.

0 commit comments

Comments
 (0)