diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 8ab2718..102b13d 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -1,7 +1,5 @@ -import { expect, test, beforeAll, afterAll } from "bun:test"; +import { expect, test } from "bun:test"; import SSSG, { Plugin } from "../index"; -import { mkdirSync, existsSync, rmSync } from "fs"; -import { before } from "node:test"; import { INPUT_FOLDER, nuke, OUTPUT_FOLDER } from "./util"; class DummyPlugin extends Plugin { diff --git a/src/index.ts b/src/index.ts index 2cd536b..68240bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,9 @@ export default class SSSG { } try { fs.rmSync(this.outputFolder, { recursive: true }); - } catch {} + } catch { + // I dont car 🌧️ + } const sourceFiles = fs.readdirSync(this.inputFolder, { recursive: true, @@ -102,7 +104,7 @@ export default class SSSG { data = rewritten; } - let rewrite = await plugin.rewriteFile(data, oldPath); + const rewrite = await plugin.rewriteFile(data, oldPath); if (!rewrite) continue; diff --git a/src/plugins/__tests__/compile-time-js.test.ts b/src/plugins/__tests__/compile-time-js.test.ts index 0b8d266..9fc8373 100644 --- a/src/plugins/__tests__/compile-time-js.test.ts +++ b/src/plugins/__tests__/compile-time-js.test.ts @@ -4,7 +4,7 @@ import CompileTimeJS from "../compile-time-js"; test("CompileTimeJS evaluates JS expressions in curly braces", async () => { const plugin = new CompileTimeJS(); const input = "Hello {& 2+2 &} World"; - const output = await plugin.rewriteFile(input, "test.html"); + const output = await plugin.rewriteFile(input); expect(output).toBe("Hello 4 World"); }); @@ -12,13 +12,13 @@ test("CompileTimeJS handles multiple expressions", async () => { const plugin = new CompileTimeJS(); const input = "{& 1+1 &} and {& 3*3 &}"; console.log(input) - const output = await plugin.rewriteFile(input, "test.html"); + const output = await plugin.rewriteFile(input); expect(output).toBe("2 and 9"); }); test("CompileTimeJS leaves input unchanged if no expressions", async () => { const plugin = new CompileTimeJS(); const input = "No expressions here."; - const output = await plugin.rewriteFile(input, "test.html"); + const output = await plugin.rewriteFile(input); expect(output).toBe("No expressions here."); }); diff --git a/src/plugins/__tests__/markdown-compiler.test.ts b/src/plugins/__tests__/markdown-compiler.test.ts index 96ca18d..72c9182 100644 --- a/src/plugins/__tests__/markdown-compiler.test.ts +++ b/src/plugins/__tests__/markdown-compiler.test.ts @@ -11,16 +11,16 @@ const mockParseMetadata = (file: string) => { return undefined; }; -// @ts-expect-error +// @ts-expect-error Mocked. MarkdownCompiler.prototype["marked"] = mockMarked; -// @ts-expect-error +// @ts-expect-error Mocked. MarkdownCompiler.prototype["parseMetadata"] = mockParseMetadata; test("MarkdownCompiler compiles markdown to HTML", async () => { const plugin = new MarkdownCompiler(); const input = "# Hello World"; - const output = await plugin.rewriteFile(input, "test.md"); + const output = await plugin.rewriteFile(input); expect(typeof output).toBe("string"); expect(output).toContain("Hello World"); }); @@ -28,7 +28,7 @@ test("MarkdownCompiler compiles markdown to HTML", async () => { test("MarkdownCompiler uses metadata title if present", async () => { const plugin = new MarkdownCompiler(); const input = "title=Hello\n=+\n# Some Content"; - const output = await plugin.rewriteFile(input, "test.md"); + const output = await plugin.rewriteFile(input); expect(output).toContain("Hello"); expect(output).toContain("Some Content"); }); @@ -36,6 +36,6 @@ test("MarkdownCompiler uses metadata title if present", async () => { test("MarkdownCompiler returns HTML for markdown without metadata", async () => { const plugin = new MarkdownCompiler(); const input = "# Just Markdown"; - const output = await plugin.rewriteFile(input, "test.md"); + const output = await plugin.rewriteFile(input); expect(output).toContain("Just Markdown"); }); diff --git a/src/plugins/__tests__/postcss.test.ts b/src/plugins/__tests__/postcss.test.ts index 828653c..afb1dfb 100644 --- a/src/plugins/__tests__/postcss.test.ts +++ b/src/plugins/__tests__/postcss.test.ts @@ -17,14 +17,14 @@ uppercasePlugin.postcss = true; test("PostCSS applies plugins to CSS", async () => { const plugin = new PostCSS([uppercasePlugin()]); const input = "body { color: red; }"; - const output = await plugin.rewriteFile(input); + const output = await plugin.rewriteFile(input, "test"); expect(output).toContain("COLOR: RED;"); }); test("PostCSS returns unchanged CSS if no plugins", async () => { const plugin = new PostCSS([]); const input = "body { color: blue; }"; - const output = await plugin.rewriteFile(input); + const output = await plugin.rewriteFile(input, "test"); expect(output).toBe(input); }); @@ -43,6 +43,6 @@ test("PostCSS handles multiple plugins", async () => { const plugin = new PostCSS([replaceRedPlugin(), uppercasePlugin()]); const input = "body { color: red; }"; - const output = await plugin.rewriteFile(input); + const output = await plugin.rewriteFile(input, "test"); expect(output).toContain("COLOR: GREEN;"); }); diff --git a/src/plugins/__tests__/ts-compiler.test.ts b/src/plugins/__tests__/ts-compiler.test.ts index 1be754a..f7eca28 100644 --- a/src/plugins/__tests__/ts-compiler.test.ts +++ b/src/plugins/__tests__/ts-compiler.test.ts @@ -27,7 +27,7 @@ TSCompiler.prototype["rewriteFile"] = async function ( minify: this.minify, ...this.esbuildOptions, }); - } catch (e) { + } catch { return; } if (result.errors.length != 0) { @@ -51,6 +51,6 @@ test("TSCompiler returns undefined on build error", async () => { }; const plugin = new TSCompiler(false); const output = await plugin.rewriteFile("invalid code", "test.ts"); - //@ts-expect-error + //@ts-expect-error Argument of type undefined is not assignable to parameter of type string. (ts 2345) expect(output).toBe(undefined); }); diff --git a/src/plugins/compile-time-js.ts b/src/plugins/compile-time-js.ts index ae82271..46ec0a7 100644 --- a/src/plugins/compile-time-js.ts +++ b/src/plugins/compile-time-js.ts @@ -6,9 +6,9 @@ export default class CompileTimeJS extends Plugin { longLasting = false; build = undefined; - async rewriteFile(file: string, filePath: string): Promise { + async rewriteFile(file: string): Promise { let input = file; - const regex = /\{\&([\s\S]*?)\&\}/gms; + const regex = /\{&([\s\S]*?)&\}/gms; let m; while ((m = regex.exec(input)) !== null) { diff --git a/src/plugins/dev.ts b/src/plugins/dev.ts index 5d7c00b..c429668 100644 --- a/src/plugins/dev.ts +++ b/src/plugins/dev.ts @@ -43,7 +43,7 @@ export default class DevPlugin extends Plugin { if (cleanedPath == "/") cleanedPath = "/index.html"; if (cleanedPath.endsWith("/")) cleanedPath = cleanedPath.slice(0, -1); - let fsPath = sssg.outputFolder + cleanedPath; + const fsPath = sssg.outputFolder + cleanedPath; if (fsPath.match(/\.\.\//g) !== null) { return undefined; @@ -81,7 +81,7 @@ export default class DevPlugin extends Plugin { this.allConnections.push(ws); }, - message(ws, message) {}, + message() {}, close: (ws) => { this.allConnections = this.allConnections.filter( (z) => z.data != ws.data, @@ -92,7 +92,7 @@ export default class DevPlugin extends Plugin { }); } - async rewriteFile(file: string, filePath: string) { + async rewriteFile() { return undefined; } } diff --git a/src/plugins/markdown-compiler.ts b/src/plugins/markdown-compiler.ts index 6ec9e4b..ab30e38 100644 --- a/src/plugins/markdown-compiler.ts +++ b/src/plugins/markdown-compiler.ts @@ -10,11 +10,11 @@ export default class MarkdownCompiler extends Plugin { renameTo = "html"; longLasting = false; - async rewriteFile(file: string, filePath: string) { + async rewriteFile(file: string) { let text = file; const metadata = parseMetadata(text); if (metadata) { - let textSplit = text.split("\n"); + const textSplit = text.split("\n"); textSplit.splice(0, Object.keys(metadata).length); textSplit.unshift(metadata.title); text = textSplit.join("\n"); diff --git a/src/plugins/markdown-metadata.ts b/src/plugins/markdown-metadata.ts index 655246f..dee046a 100644 --- a/src/plugins/markdown-metadata.ts +++ b/src/plugins/markdown-metadata.ts @@ -23,7 +23,7 @@ export default class MarkdownMetadataGenerator extends Plugin { renameTo = "json"; longLasting = false; - async rewriteFile(file: string, filePath: string) { + async rewriteFile(file: string) { const metadata = parseMetadata(file); if (!metadata) return; return JSON.stringify(metadata); diff --git a/src/plugins/postcss.ts b/src/plugins/postcss.ts index b4ca98c..d877032 100644 --- a/src/plugins/postcss.ts +++ b/src/plugins/postcss.ts @@ -15,8 +15,8 @@ export default class PostCSS extends Plugin { this.plugins = plugins; } - async rewriteFile(file: string) { - const data = await postcss(this.plugins).process(file, { from: undefined }); + async rewriteFile(file: string, filePath: string) { + const data = await postcss(this.plugins).process(file, { from: filePath }); return data.css; } } diff --git a/src/plugins/variables.ts b/src/plugins/variables.ts index bc940da..a1b6262 100644 --- a/src/plugins/variables.ts +++ b/src/plugins/variables.ts @@ -18,7 +18,7 @@ export default class Variables extends Plugin { this.variables = this.varBuild(); } - async rewriteFile(file: string, filePath: string): Promise { + async rewriteFile(file: string): Promise { let prevfile = file; for (const a of Object.entries(this.variables)) { prevfile = prevfile.replaceAll(a[0], a[1]);