+34
-19
@@ -6,3 +6,3 @@ #!/usr/bin/env bun | ||
| // `tekir build` runs `Bun.build` directly, and because Bun is | ||
| // position-strict on its own `--env-file` flag — `--env-file=...` | ||
| // position-strict on its own `--env-file` flag, so `--env-file=...` | ||
| // tokens after the script path pass through to argv where this bin | ||
@@ -32,6 +32,6 @@ // can filter them, while Node's runtime greedily parses the same flag | ||
| // Env files load in two ways, both feeding the same manual dotenv loader: | ||
| // 1. `tekir.envFiles` (string array) in the cwd's `package.json` — | ||
| // recommended for monorepo dev scripts that need many `.env` files | ||
| // because the paths never enter the bin's argv. | ||
| // 2. `--env-file <path>` (multi) on the command line — convenient for | ||
| // 1. `tekir.envFiles` (string array) in the cwd's `package.json`. | ||
| // Recommended for monorepo dev scripts that need many `.env` | ||
| // files because the paths never enter the bin's argv. | ||
| // 2. `--env-file <path>` (multi) on the command line. Convenient for | ||
| // one-off invocations. | ||
@@ -42,3 +42,3 @@ // | ||
| // argv (including after the script path) AND hard-errors on missing | ||
| // files — the combination breaks the moment a single optional `.env` in | ||
| // files. The combination breaks the moment a single optional `.env` in | ||
| // a monorepo dev script is absent, even when this bin would otherwise | ||
@@ -70,3 +70,3 @@ // filter it out, because Node bails during its own argv parsing phase | ||
| * intercepts it first and hard-errors on a missing file before the bin | ||
| * even runs — so it works mainly for Bun-direct invocations where the | ||
| * even runs, so it works mainly for Bun-direct invocations where the | ||
| * runtime is position-strict and missing-tolerant. | ||
@@ -135,4 +135,4 @@ */ | ||
| * | ||
| * Missing files are warned and skipped — see the `--env-file` comment at | ||
| * the top of this file for why we never delegate this to the runtime. | ||
| * Missing files are warned and skipped (see the `--env-file` comment at | ||
| * the top of this file for why we never delegate this to the runtime). | ||
| */ | ||
@@ -259,7 +259,15 @@ function loadEnvFile(path, shellKeys) { | ||
| await import(pathToFileURL(absEntry).href) | ||
| // The entry usually calls `app.start()` (which keeps the event loop | ||
| // alive) or a CLI command (which calls `process.exit`). If the entry | ||
| // returned without doing either, exit cleanly so the shell prompt | ||
| // does not hang. | ||
| process.exit(0) | ||
| // Don't `process.exit(0)` here. The entry typically: | ||
| // - starts an HTTP server (`Bun.serve` keeps the event loop alive | ||
| // on its own; `process.exit` would kill it the instant `import` | ||
| // resolved, which is exactly what happened with the canonical | ||
| // fire-and-forget `server.start().catch(...)` pattern) | ||
| // - runs a CLI command that calls `process.exit` itself (e.g. the | ||
| // in-app `tekir({...})` build dispatcher does this once the | ||
| // bundle finishes) | ||
| // - has top-level async work the user awaited | ||
| // In every case the runtime exits naturally when the event loop | ||
| // drains. Forcing an early exit here was racing with all three paths | ||
| // and only helped the niche of a synchronous-only entry that left no | ||
| // pending work, and Node/Bun would already exit from on their own. | ||
| } | ||
@@ -295,3 +303,3 @@ | ||
| // JSON config sets the baseline), then any `--env-file` flags from the | ||
| // command line override / extend on top — matches the "later wins" | ||
| // command line override or extend on top, matching the "later wins" | ||
| // dotenv precedence. Shell-provided env always wins both. | ||
@@ -317,7 +325,14 @@ const jsonEnvFiles = Array.isArray(tekirCfg?.envFiles) | ||
| // From here on we are guaranteed to be running under Bun. | ||
| // | ||
| // Run the entry through `runEntry` (same path as `serve`) so the | ||
| // user's `tekir({...})` instance gets to register `onBuild` hooks | ||
| // before we bundle. Inside `tekir()` core, `argv[2] === 'build'` is | ||
| // detected and triggers `server.build()` (which fires the hooks, | ||
| // e.g. `@tekir/vite` builds the frontend into `dist/client/`) | ||
| // followed by the actual `Bun.build` for the backend bundle. Calling | ||
| // `runBuild` directly from this bin, as we did before, skipped the | ||
| // entry entirely and silently dropped any frontend build. | ||
| const entry = await findEntry(entryFlag, tekirCfg) | ||
| const flags = argv.slice(1) | ||
| const { runBuild } = await import('@tekir/core') | ||
| const ok = await runBuild(entry, flags) | ||
| process.exit(ok ? 0 : 1) | ||
| const rest = argv.slice(1) | ||
| await runEntry(entry, command, rest) | ||
| } | ||
@@ -324,0 +339,0 @@ |
+2
-2
| { | ||
| "name": "@tekir/cli", | ||
| "version": "0.1.2", | ||
| "version": "0.1.3", | ||
| "description": "tekir command-line tool: serve, build, generate-key, and provider-registered commands.", | ||
@@ -33,3 +33,3 @@ "author": "dev@tekir.io", | ||
| "dependencies": { | ||
| "@tekir/core": "^0.1.14" | ||
| "@tekir/core": "^0.1.21" | ||
| }, | ||
@@ -36,0 +36,0 @@ "peerDependencies": { |
18271
5.96%335
4.69%Updated