Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/shared/src/themes/sanitizeThemeCss/css-tree-esm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "css-tree/dist/csstree.esm" {
export * from "css-tree";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { describe, expect, it } from "bun:test";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { MAX_THEME_CSS_LENGTH, sanitizeThemeCss } from "./sanitizeThemeCss";

describe("sanitizeThemeCss", () => {
Expand Down Expand Up @@ -90,3 +93,19 @@ it("bounds output expanded by custom property namespacing", () => {
expect(output).toBe("");
expect(sanitizeThemeCss(output)).toBe(output);
});

it("runs from a Bun bundle, as in the compiled CLI", async () => {
const outdir = await mkdtemp(join(tmpdir(), "sanitize-theme-css-"));
try {
const build = await Bun.build({
entrypoints: [join(import.meta.dir, "sanitizeThemeCss.ts")],
target: "bun",
outdir,
});
expect(build.success).toBe(true);
const bundled = await import(join(outdir, "sanitizeThemeCss.js"));
expect(bundled.sanitizeThemeCss("a { color: red; }")).toBe("a{color:red}");
} finally {
await rm(outdir, { recursive: true, force: true });
}
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference path="./css-tree-esm.d.ts" />
import {
type CssNode,
generate,
Expand All @@ -6,7 +7,7 @@ import {
type ListItem,
parse,
walk,
} from "css-tree";
} from "css-tree/dist/csstree.esm";

export const MAX_THEME_CSS_LENGTH = 64 * 1024;

Expand Down
Loading