Skip to content

Commit 1dc4f78

Browse files
committed
feat: add make mux target to run compiled CLI
Adds a convenience target that runs the compiled CLI with trailing args: make mux server --port 4000 make mux -- --help Builds automatically if dist/cli/index.js is missing, otherwise instant.
1 parent 1fc5493 commit 1dc4f78

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

Makefile

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ include fmt.mk
5252
.PHONY: docs-server check-docs-links
5353
.PHONY: storybook storybook-build test-storybook chromatic
5454
.PHONY: benchmark-terminal
55-
.PHONY: ensure-deps rebuild-native
55+
.PHONY: ensure-deps rebuild-native mux
5656
.PHONY: check-eager-imports check-bundle-size check-startup
5757

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

110+
# Run compiled CLI with trailing arguments (builds only if missing)
111+
mux: ## Run the compiled mux CLI (e.g., make mux server --port 3000)
112+
@test -f dist/cli/index.js || $(MAKE) build-main
113+
@node dist/cli/index.js $(filter-out $@,$(MAKECMDGOALS))
114+
115+
# Catch unknown targets passed to mux (prevents "No rule to make target" errors)
116+
ifneq ($(filter mux,$(MAKECMDGOALS)),)
117+
%:
118+
@:
119+
endif
120+
110121
## Help
111122
help: ## Show this help message
112123
@echo 'Usage: make [target]'
@@ -163,13 +174,25 @@ start: node_modules/.installed build-main build-preload build-static ## Build an
163174
## Build targets (can run in parallel)
164175
build: node_modules/.installed src/version.ts build-renderer build-main build-preload build-icons build-static ## Build all targets
165176

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

168179
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)
169180
@echo "Building main process..."
170181
@NODE_ENV=production $(TSGO) -p tsconfig.main.json
171182
@NODE_ENV=production bun x tsc-alias -p tsconfig.main.json
172183

184+
# Build API CLI as ESM bundle (trpc-cli requires ESM with top-level await)
185+
dist/cli/api.mjs: src/cli/api.ts src/cli/proxifyOrpc.ts $(TS_SOURCES)
186+
@echo "Building API CLI (ESM)..."
187+
@bun x esbuild src/cli/api.ts \
188+
--bundle \
189+
--format=esm \
190+
--platform=node \
191+
--outfile=dist/cli/api.mjs \
192+
--external:zod \
193+
--external:commander \
194+
--external:@trpc/server
195+
173196
build-preload: node_modules/.installed dist/preload.js ## Build preload script
174197

175198
dist/preload.js: src/desktop/preload.ts $(TS_SOURCES)

src/cli/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ if (subcommand === "run") {
4040
require("./server");
4141
} else if (subcommand === "api") {
4242
process.argv.splice(2, 1);
43-
// Dynamic import required: trpc-cli is ESM-only and can't be require()'d
44-
// eslint-disable-next-line no-restricted-syntax
45-
void import("./api");
43+
// Must use native import() to load ESM module - trpc-cli requires ESM with top-level await.
44+
// Using Function constructor prevents TypeScript from converting this to require().
45+
// The .mjs extension is critical for Node.js to treat it as ESM.
46+
// eslint-disable-next-line @typescript-eslint/no-implied-eval, @typescript-eslint/no-unsafe-call
47+
void new Function("return import('./api.mjs')")();
4648
} else if (
4749
subcommand === "desktop" ||
4850
(isElectron && (subcommand === undefined || isElectronLaunchArg))

0 commit comments

Comments
 (0)