feat(desktop): grouped system events with collapsible UI

This commit is contained in:
Taylor Ho
2026-05-19 18:50:54 -07:00
parent 582cfc8885
commit 7637e557c3
11 changed files with 1286 additions and 22 deletions

View File

@@ -0,0 +1,54 @@
/**
* ESM resolve hook that maps `@/*` imports to `<projectRoot>/src/*`.
* Also resolves extensionless imports to `.ts` files (TypeScript convention).
*/
import { fileURLToPath, pathToFileURL } from "node:url";
import path from "node:path";
import fs from "node:fs";
const projectRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"..",
);
const srcDir = path.join(projectRoot, "src");
/**
* Try to resolve a file path that may be missing its extension.
* Returns the resolved file URL or null.
*/
function tryResolveFile(filePath) {
// Try exact path first
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
return pathToFileURL(filePath).href;
}
// Try with .ts extension
const withTs = `${filePath}.ts`;
if (fs.existsSync(withTs)) {
return pathToFileURL(withTs).href;
}
// Try with .tsx extension
const withTsx = `${filePath}.tsx`;
if (fs.existsSync(withTsx)) {
return pathToFileURL(withTsx).href;
}
// Try as directory with index.ts
const indexTs = path.join(filePath, "index.ts");
if (fs.existsSync(indexTs)) {
return pathToFileURL(indexTs).href;
}
return null;
}
export function resolve(specifier, context, nextResolve) {
if (specifier.startsWith("@/")) {
const bare = path.join(srcDir, specifier.slice(2));
const resolved = tryResolveFile(bare);
if (resolved) {
return nextResolve(resolved, context);
}
// Fallback — let Node try (will likely fail with a clear error)
return nextResolve(pathToFileURL(bare).href, context);
}
return nextResolve(specifier, context);
}

View File

@@ -0,0 +1,11 @@
/**
* Custom Node ESM loader that resolves `@/` path aliases to `./src/`
* relative to the desktop project root.
*
* Usage:
* node --experimental-strip-types --import ./scripts/test-loader.mjs --test src/path/to.test.mjs
*/
import { register } from "node:module";
register("./resolve-at-alias.mjs", import.meta.url);

View File

@@ -0,0 +1,35 @@
// Node.js customization hooks — resolves @/ path alias and .ts extensions.
// Loaded via: node --import ./scripts/test-loader.mjs
import { existsSync } from "node:fs";
import { resolve as pathResolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
const srcDir = pathResolve(fileURLToPath(import.meta.url), "../../src");
export function resolve(specifier, context, nextResolve) {
let mapped = specifier;
// Resolve @/ alias to src/
if (mapped.startsWith("@/")) {
mapped = pathToFileURL(pathResolve(srcDir, mapped.slice(2))).href;
}
// If the specifier (after alias resolution) looks like a local/file path
// without an extension, try appending .ts
if (
mapped.startsWith("file://") &&
!mapped.endsWith(".ts") &&
!mapped.endsWith(".mjs") &&
!mapped.endsWith(".js")
) {
const filePath = fileURLToPath(mapped);
if (!existsSync(filePath) && existsSync(`${filePath}.ts`)) {
mapped = `${mapped}.ts`;
}
}
if (mapped !== specifier) {
return nextResolve(mapped, context);
}
return nextResolve(specifier, context);
}