Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ include fmt.mk
.PHONY: docs-server check-docs-links
.PHONY: storybook storybook-build test-storybook chromatic
.PHONY: benchmark-terminal
.PHONY: ensure-deps rebuild-native
.PHONY: ensure-deps rebuild-native mux
.PHONY: check-eager-imports check-bundle-size check-startup

# Build tools
Expand Down Expand Up @@ -107,6 +107,17 @@ rebuild-native: node_modules/.installed ## Rebuild native modules (node-pty) for
@npx @electron/rebuild -f -m node_modules/node-pty
@echo "Native modules rebuilt successfully"

# Run compiled CLI with trailing arguments (builds only if missing)
mux: ## Run the compiled mux CLI (e.g., make mux server --port 3000)
@test -f dist/cli/index.js || $(MAKE) build-main
@node dist/cli/index.js $(filter-out $@,$(MAKECMDGOALS))

# Catch unknown targets passed to mux (prevents "No rule to make target" errors)
ifneq ($(filter mux,$(MAKECMDGOALS)),)
%:
@:
endif

## Help
help: ## Show this help message
@echo 'Usage: make [target]'
Expand Down Expand Up @@ -163,13 +174,25 @@ start: node_modules/.installed build-main build-preload build-static ## Build an
## Build targets (can run in parallel)
build: node_modules/.installed src/version.ts build-renderer build-main build-preload build-icons build-static ## Build all targets

build-main: node_modules/.installed dist/cli/index.js ## Build main process
build-main: node_modules/.installed dist/cli/index.js dist/cli/api.mjs ## Build main process

dist/cli/index.js: src/cli/index.ts src/desktop/main.ts src/cli/server.ts src/version.ts tsconfig.main.json tsconfig.json $(TS_SOURCES)
@echo "Building main process..."
@NODE_ENV=production $(TSGO) -p tsconfig.main.json
@NODE_ENV=production bun x tsc-alias -p tsconfig.main.json

# Build API CLI as ESM bundle (trpc-cli requires ESM with top-level await)
dist/cli/api.mjs: src/cli/api.ts src/cli/proxifyOrpc.ts $(TS_SOURCES)
@echo "Building API CLI (ESM)..."
@bun x esbuild src/cli/api.ts \
--bundle \
--format=esm \
--platform=node \
--outfile=dist/cli/api.mjs \
--external:zod \
--external:commander \
--external:@trpc/server

build-preload: node_modules/.installed dist/preload.js ## Build preload script

dist/preload.js: src/desktop/preload.ts $(TS_SOURCES)
Expand Down
8 changes: 5 additions & 3 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ if (subcommand === "run") {
require("./server");
} else if (subcommand === "api") {
process.argv.splice(2, 1);
// Dynamic import required: trpc-cli is ESM-only and can't be require()'d
// eslint-disable-next-line no-restricted-syntax
void import("./api");
// Must use native import() to load ESM module - trpc-cli requires ESM with top-level await.
// Using Function constructor prevents TypeScript from converting this to require().
// The .mjs extension is critical for Node.js to treat it as ESM.
// eslint-disable-next-line @typescript-eslint/no-implied-eval, @typescript-eslint/no-unsafe-call
void new Function("return import('./api.mjs')")();
} else if (
subcommand === "desktop" ||
(isElectron && (subcommand === undefined || isElectronLaunchArg))
Expand Down