Skip to content

Commit

Permalink
Fix TS warning and improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Neodymium7 committed Dec 17, 2024
1 parent cc67149 commit 73a63c7
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v5.0.1

- Fixed a Typescript warning and minor formatting issues.

# v5.0.0

- Removed Zere's Plugin Library support.
Expand Down
4 changes: 4 additions & 0 deletions bin/config/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import replace, { RollupReplaceOptions } from "@rollup/plugin-replace";
import svgr from "@svgr/rollup";
import esbuild from "rollup-plugin-esbuild";
import styles from "rollup-plugin-styles";
import cleanup from "rollup-plugin-cleanup";
import styleLoader from "../plugins/styleloader";
import text from "../plugins/text";
import moduleComments from "../plugins/modulecomments";
import constPlugin from "../plugins/const";
import expandedStyles from "../plugins/expandedstyles";
import compressedTemplates from "../plugins/compressedtemplates";

type AliasEntry = { find: RegExp; replacement: string };

Expand Down Expand Up @@ -157,6 +159,8 @@ export default function getRollupConfig(options: BundleBDOptions, pluginConfig:
}),
constPlugin({ regex: constRegex }),
replace(createReplaced(globals)),
cleanup({ extensions: ["js", "ts", "jsx", "tsx"] }),
compressedTemplates({ regex: /(\.jsx?$)|(\.tsx?$)/ }),
options.format.moduleComments && moduleComments({ root: entryDir, aliases: options.importAliases }),
options.importAliases &&
alias({
Expand Down
16 changes: 16 additions & 0 deletions bin/plugins/compressedtemplates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Plugin } from "rollup";

interface CompressedTemplatesOptions {
regex: RegExp;
}

export default function compressedTemplates(options: CompressedTemplatesOptions): Plugin {
return {
name: "compressed-templates",
transform(code: string, id: string) {
if (options.regex.test(id)) {
return code.replace(/`(.*?[^\\])`/gs, (_, contents) => `\`${contents.replace(/\n/g, "\\n")}\``);
}
},
};
}
3 changes: 2 additions & 1 deletion bin/plugins/expandedstyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default function expandedStyles(options: ExpandedStylesOptions): Plugin {
const unescaped: string = JSON.parse(JSON.stringify(code).replace(/\\\\/g, "\\"));
return unescaped
.replace(/\t/g, " ")
.replace(/css = "(.*\n.*)";/s, (_, contents) => `css = \`\n${contents.trimEnd()}\n\`;`)
.replace(/\n+/g, "\n")
.replace(/css = "(.*\n.*)";/s, (_, contents) => `css = \`\n${contents.trimEnd()}\`;`)
.replace(
/modules(.*) = ({.*});/,
(_, id, obj) => `modules${id} = ${JSON.stringify(JSON.parse(obj), null, " ")};`
Expand Down
114 changes: 108 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@types/bdapi": "github:zerthox/betterdiscord-types",
"less": "^4.1.3",
"rollup": "^2.79.1",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-esbuild": "^4.10.1",
"rollup-plugin-styles": "^4.0.0",
"sass": "^1.53.0",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"target": "es2022",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true
Expand Down
1 change: 1 addition & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare module "betterdiscord" {
import type { BoundBdApi } from "bdapi";
const BdApi: BoundBdApi;
// @ts-ignore
export = BdApi;
export * from "bdapi/plugin";
export {
Expand Down

0 comments on commit 73a63c7

Please sign in to comment.