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
2 changes: 2 additions & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"@types/babel__core": "7.20.5",
"@types/better-sqlite3": "7.6.13",
"@types/bun": "1.4.3",
"@types/css-tree": "3.2.0",
"@types/culori": "4.0.1",
"@types/express": "5.0.6",
"@types/lodash": "4.17.24",
Expand Down Expand Up @@ -222,6 +223,7 @@
"better-auth": "1.6.22",
"clsx": "2.1.1",
"cross-env": "10.1.0",
"css-tree": "3.2.1",
"culori": "4.0.2",
"date-fns": "4.1.0",
"default-shell": "2.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sanitizeThemeCss } from "shared/themes";
import type { UIColors } from "shared/themes/types";
import { sanitizeThemeCss } from "./sanitizeThemeCss";

/**
* Maps UI color keys to CSS variable names
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { sanitizeThemeCss } from "./sanitizeThemeCss";
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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";
import { MAX_THEME_CSS_LENGTH } from "shared/themes";
import { sanitizeThemeCss } from "./sanitizeThemeCss";

describe("sanitizeThemeCss", () => {
it("preserves supported colors, gradients and embedded raster images", () => {
Expand Down Expand Up @@ -93,19 +91,3 @@ 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,4 +1,3 @@
/// <reference path="./css-tree-esm.d.ts" />
import {
type CssNode,
generate,
Expand All @@ -7,9 +6,8 @@ import {
type ListItem,
parse,
walk,
} from "css-tree/dist/csstree.esm";

export const MAX_THEME_CSS_LENGTH = 64 * 1024;
} from "css-tree";
import { MAX_THEME_CSS_LENGTH } from "shared/themes";

const atRules = new Set([
"media",
Expand Down
20 changes: 13 additions & 7 deletions bun.lock

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

43 changes: 27 additions & 16 deletions packages/cli-framework/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { mkdirSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { loadConfig } from "./config";
import { type LoadedConfig, loadConfig } from "./config";
import { createCommandsPlugin } from "./plugin";

export async function runBuild(argv: string[]): Promise<void> {
const { config, configPath, root } = await loadConfig(process.cwd());
export function buildOptions({
config,
configPath,
root,
}: LoadedConfig): Pick<Bun.BuildConfig, "entrypoints" | "plugins" | "define"> {
const commandsDir = resolve(root, config.commandsDir);

let target: Bun.Build.CompileTarget | undefined;
let outfile = resolve(root, config.outfile ?? `./dist/${config.name}`);
for (const arg of argv) {
if (arg.startsWith("--target=")) {
target = arg.slice("--target=".length) as Bun.Build.CompileTarget;
} else if (arg.startsWith("--outfile=")) {
outfile = resolve(root, arg.slice("--outfile=".length));
}
}

const cacheDir = resolve(root, "node_modules/.cache/cli-framework");
mkdirSync(cacheDir, { recursive: true });
const entryPath = resolve(cacheDir, "entry.ts");
Expand All @@ -38,11 +30,30 @@ await run({
`,
);

const result = await Bun.build({
return {
entrypoints: [entryPath],
plugins: [createCommandsPlugin({ commandsDir }), ...(config.plugins ?? [])],
compile: target ? { target, outfile } : { outfile },
define: config.define,
};
}

export async function runBuild(argv: string[]): Promise<void> {
const loaded = await loadConfig(process.cwd());
const { config, root } = loaded;

let target: Bun.Build.CompileTarget | undefined;
let outfile = resolve(root, config.outfile ?? `./dist/${config.name}`);
for (const arg of argv) {
if (arg.startsWith("--target=")) {
target = arg.slice("--target=".length) as Bun.Build.CompileTarget;
} else if (arg.startsWith("--outfile=")) {
outfile = resolve(root, arg.slice("--outfile=".length));
}
}

const result = await Bun.build({
...buildOptions(loaded),
compile: target ? { target, outfile } : { outfile },
});

if (!result.success) {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-framework/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export { buildOptions } from "./build";
export type { Audience, CommandConfig, CommandResult } from "./command";
export { createCommand } from "./command";
export {
generateBashCompletion,
generateZshCompletion,
} from "./completion";
export type { CliConfig } from "./config";
export { defineConfig } from "./config";
export { defineConfig, loadConfig } from "./config";
export { CLIError, suggestSimilar } from "./errors";
export type { CliDescription, CommandNode } from "./help";
export {
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/cli.config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, it } from "bun:test";
import { buildOptions, loadConfig } from "@superset/cli-framework";

it("keeps css-tree out of the compiled CLI", async () => {
const build = await Bun.build({
...buildOptions(await loadConfig(import.meta.dir)),
target: "bun",
metafile: true,
});
expect(build.success).toBe(true);
const inputs = Object.keys(build.metafile?.inputs ?? {});
expect(inputs.length).toBeGreaterThan(0);
expect(
inputs.filter((path) => /node_modules\/(css-tree|mdn-data)\//.test(path)),
).toEqual([]);
});
2 changes: 1 addition & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"emitDeclarationOnly": false,
"noEmit": true
},
"include": ["src", "scripts", "cli.config.ts"],
"include": ["src", "scripts", "cli.config.ts", "cli.config.test.ts"],
"exclude": ["node_modules", "dist"]
}
2 changes: 0 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@
"@date-fns/tz": "1.4.1",
"@lingui/core": "6.12.0",
"@superset/i18n": "workspace:*",
"css-tree": "3.2.1",
"culori": "4.0.2",
"drizzle-orm": "0.45.2",
"friendly-words": "1.3.1",
Expand All @@ -595,7 +594,6 @@
},
"devDependencies": {
"@superset/typescript": "workspace:*",
"@types/css-tree": "3.2.0",
"@types/culori": "4.0.1",
"@types/friendly-words": "1.2.2",
"@types/semver": "7.7.1",
Expand Down
15 changes: 2 additions & 13 deletions packages/shared/src/themes/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ describe("parseThemeConfigFile", () => {
expect(result.ok).toBe(true);
if (!result.ok) return;

expect(result.themes[0]?.css).toBe(
"body{background:url(data:image/png;base64,AA==)}",
);
expect(result.themes[0]?.css).toBe(css);
});

it("returns an error for invalid JSON", () => {
Expand Down Expand Up @@ -162,16 +160,7 @@ describe("parseThemeConfigFile", () => {
});
});

it("filters unsafe CSS during import and rejects oversized stylesheets", () => {
const result = parseThemeConfigFile(
JSON.stringify({
name: "Filtered",
css: "body {display:none; background:url(https://example.invalid/track); color:red}",
}),
);
expect(result.ok).toBe(true);
if (result.ok)
expect(result.themes[0]?.css).toBe("body{display:none;color:red}");
it("rejects oversized stylesheets", () => {
const oversized = parseThemeConfigFile(
JSON.stringify({ name: "Too large", css: " ".repeat(65537) }),
);
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/themes/import.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { z } from "zod";
import { builtInThemes, darkTheme, lightTheme } from "./built-in";
import { getEditorTheme } from "./editor-theme";
import { MAX_THEME_CSS_LENGTH, sanitizeThemeCss } from "./sanitizeThemeCss";
import { getDefaultTerminalColors, type Theme } from "./types";

export const MAX_THEME_CSS_LENGTH = 64 * 1024;

const uiColorsSchema = z
.object({
background: z.string().optional(),
Expand Down Expand Up @@ -233,7 +234,7 @@ function parseThemeEntry(
...terminalOverrides,
}
: undefined,
css: config.css === undefined ? undefined : sanitizeThemeCss(config.css),
css: config.css,
};
const baseEditorTheme = getEditorTheme(resolvedThemeBase);

Expand Down
7 changes: 5 additions & 2 deletions packages/shared/src/themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export {
vellumTheme,
} from "./built-in";
export { getEditorTheme } from "./editor-theme";
export { parseThemeConfigFile, type ThemeConfigParseResult } from "./import";
export { MAX_THEME_CSS_LENGTH, sanitizeThemeCss } from "./sanitizeThemeCss";
export {
MAX_THEME_CSS_LENGTH,
parseThemeConfigFile,
type ThemeConfigParseResult,
} from "./import";
export type {
EditorColors,
EditorSyntaxColors,
Expand Down
3 changes: 0 additions & 3 deletions packages/shared/src/themes/sanitizeThemeCss/css-tree-esm.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/shared/src/themes/sanitizeThemeCss/index.ts

This file was deleted.

Loading