@hamedb89/localghost 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -1
- package/dist/cli.js +133 -39
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +57 -22
- package/dist/index.js.map +1 -1
- package/docs/flows.md +11 -0
- package/docs/localghost.1.md +2 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ declare function unregisterLocalghostSetup(options: {
|
|
|
72
72
|
declare function renderLocalghostBanner(): string;
|
|
73
73
|
declare function renderCompactLocalghostBanner(): string;
|
|
74
74
|
|
|
75
|
-
declare const LOCALGHOST_AGENT_GUIDE = "# Localghost agent guide\n\nLocalghost owns the local development proxy and the app process boundary.\n\n## Preferred repository setup\n\nFor a normal repository, use this package script:\n\n \"dev\": \"localghost\"\n\nFor an explicit app command, keep the raw command separate:\n\n \"dev\": \"localghost run -- vite\"\n \"dev:raw\": \"vite\"\n\nUse `localghost dev` only when the Caddy proxy should run without starting the app.\n\n## Useful commands\n\n- `localghost`: detect and run the repository development command.\n- `localghost run -- <command>`: wrap an explicit app command.\n- `localghost dev`: run only the local Caddy proxy.\n- `localghost status --ready`: check project setup.\n- `localghost repair`: repair managed hosts and Caddy setup.\n- `localghost ps --json`: inspect Localghost-managed repositories, instances, and ports.\n- `localghost routes`: inspect hostname-to-port routing.\n- `localghost doctor`: check machine prerequisites, ports, and registry state.\n- `localghost repair --reallocate-port`: move an occupied project port to a stable available port.\n\n## Configuration\n\n- Commit repository defaults in `localghost.config.mjs`.\n- Keep hostname and requested-port routes in `.localghost`.\n- CLI flags override repository configuration for one invocation.\n- Localghost remembers active project and instance port assignments in user state under `~/.localghost`.\n- Do not edit the registry manually and do not start Caddy separately.\n\n## Port behavior\n\nLocalghost remembers ports by canonical repository path and instance key. Concurrent Localghost instances receive distinct ports. The operating-system bind check remains authoritative when another tool already owns a port.\n";
|
|
75
|
+
declare const LOCALGHOST_AGENT_GUIDE = "# Localghost agent guide\n\nLocalghost owns the local development proxy and the app process boundary.\n\n## Preferred repository setup\n\nFor a normal repository with Localghost installed as a dev dependency, use this package script:\n\n \"dev\": \"localghost\"\n\nIf the repository does not have a local CLI yet, use the package-manager launcher:\n\n npm exec --yes --package=@hamedb89/localghost -- localghost\n pnpm dlx @hamedb89/localghost\n yarn dlx @hamedb89/localghost\n bunx --package @hamedb89/localghost localghost\n\nFor an explicit app command, keep the raw command separate:\n\n \"dev\": \"localghost run -- vite\"\n \"dev:raw\": \"vite\"\n\nUse `localghost dev` only when the Caddy proxy should run without starting the app.\n\n## Useful commands\n\n- `localghost`: detect and run the repository development command.\n- `localghost run -- <command>`: wrap an explicit app command.\n- `localghost dev`: run only the local Caddy proxy.\n- `localghost status --ready`: check project setup.\n- `localghost repair`: repair managed hosts and Caddy setup.\n- `localghost ps --json`: inspect Localghost-managed repositories, instances, and ports.\n- `localghost routes`: inspect hostname-to-port routing.\n- `localghost doctor`: check machine prerequisites, ports, and registry state.\n- `localghost repair --reallocate-port`: move an occupied project port to a stable available port.\n\n- `localghost update`: check npm for a newer Localghost release.\n- `localghost upgrade`: install or update Localghost as a repository dev dependency.\n\nUse `localghost` directly when the package is installed locally. Use `npm exec --yes --package=@hamedb89/localghost -- localghost <command>`, `pnpm dlx @hamedb89/localghost <command>`, `yarn dlx @hamedb89/localghost <command>`, or `bunx --package @hamedb89/localghost localghost <command>` when it is not.\n\n## Configuration\n\n- Commit repository defaults in `localghost.config.mjs`.\n- Keep hostname and requested-port routes in `.localghost`.\n- CLI flags override repository configuration for one invocation.\n- Localghost remembers active project and instance port assignments in user state under `~/.localghost`.\n- Do not edit the registry manually and do not start Caddy separately.\n\n## Port behavior\n\nLocalghost remembers ports by canonical repository path and instance key. Concurrent Localghost instances receive distinct ports. The operating-system bind check remains authoritative when another tool already owns a port.\n";
|
|
76
76
|
declare function formatLocalghostAgentGuide(format?: "text" | "json"): string;
|
|
77
77
|
|
|
78
78
|
declare const LOCALGHOST_GHOST_TUNNEL_FILE = ".ghosttunnel";
|
|
@@ -685,7 +685,7 @@ type CreateVercelGhostTunnelHandlerOptions = {
|
|
|
685
685
|
declare function createVercelGhostTunnelHandler(options: CreateVercelGhostTunnelHandlerOptions): (request: VercelGhostTunnelRequestLike, response: VercelGhostTunnelResponseLike) => Promise<void>;
|
|
686
686
|
|
|
687
687
|
declare const LOCALGHOST_PACKAGE_NAME = "@hamedb89/localghost";
|
|
688
|
-
declare const LOCALGHOST_VERSION = "0.
|
|
688
|
+
declare const LOCALGHOST_VERSION = "0.4.0";
|
|
689
689
|
declare const UPDATE_CHECK_CACHE_TTL_MS: number;
|
|
690
690
|
declare const UPDATE_CHECK_NOTIFY_TTL_MS: number;
|
|
691
691
|
declare const UPDATE_CHECK_TIMEOUT_MS = 900;
|
package/dist/index.js
CHANGED
|
@@ -282,10 +282,17 @@ Localghost owns the local development proxy and the app process boundary.
|
|
|
282
282
|
|
|
283
283
|
## Preferred repository setup
|
|
284
284
|
|
|
285
|
-
For a normal repository, use this package script:
|
|
285
|
+
For a normal repository with Localghost installed as a dev dependency, use this package script:
|
|
286
286
|
|
|
287
287
|
"dev": "localghost"
|
|
288
288
|
|
|
289
|
+
If the repository does not have a local CLI yet, use the package-manager launcher:
|
|
290
|
+
|
|
291
|
+
npm exec --yes --package=@hamedb89/localghost -- localghost
|
|
292
|
+
pnpm dlx @hamedb89/localghost
|
|
293
|
+
yarn dlx @hamedb89/localghost
|
|
294
|
+
bunx --package @hamedb89/localghost localghost
|
|
295
|
+
|
|
289
296
|
For an explicit app command, keep the raw command separate:
|
|
290
297
|
|
|
291
298
|
"dev": "localghost run -- vite"
|
|
@@ -305,6 +312,11 @@ Use \`localghost dev\` only when the Caddy proxy should run without starting the
|
|
|
305
312
|
- \`localghost doctor\`: check machine prerequisites, ports, and registry state.
|
|
306
313
|
- \`localghost repair --reallocate-port\`: move an occupied project port to a stable available port.
|
|
307
314
|
|
|
315
|
+
- \`localghost update\`: check npm for a newer Localghost release.
|
|
316
|
+
- \`localghost upgrade\`: install or update Localghost as a repository dev dependency.
|
|
317
|
+
|
|
318
|
+
Use \`localghost\` directly when the package is installed locally. Use \`npm exec --yes --package=@hamedb89/localghost -- localghost <command>\`, \`pnpm dlx @hamedb89/localghost <command>\`, \`yarn dlx @hamedb89/localghost <command>\`, or \`bunx --package @hamedb89/localghost localghost <command>\` when it is not.
|
|
319
|
+
|
|
308
320
|
## Configuration
|
|
309
321
|
|
|
310
322
|
- Commit repository defaults in \`localghost.config.mjs\`.
|
|
@@ -321,6 +333,14 @@ function formatLocalghostAgentGuide(format = "text") {
|
|
|
321
333
|
if (format === "json") {
|
|
322
334
|
return JSON.stringify({
|
|
323
335
|
preferredScript: "localghost",
|
|
336
|
+
packageInstall: "npm install -D @hamedb89/localghost",
|
|
337
|
+
packageUpgrade: "localghost upgrade",
|
|
338
|
+
packageLaunchers: {
|
|
339
|
+
npm: "npm exec --yes --package=@hamedb89/localghost -- localghost",
|
|
340
|
+
pnpm: "pnpm dlx @hamedb89/localghost",
|
|
341
|
+
yarn: "yarn dlx @hamedb89/localghost",
|
|
342
|
+
bun: "bunx --package @hamedb89/localghost localghost"
|
|
343
|
+
},
|
|
324
344
|
explicitScript: "localghost run -- <command>",
|
|
325
345
|
proxyOnlyCommand: "localghost dev",
|
|
326
346
|
inspectionCommands: ["localghost status --ready", "localghost ps --json", "localghost routes", "localghost doctor"],
|
|
@@ -2452,30 +2472,44 @@ function shellQuote(value) {
|
|
|
2452
2472
|
function getConfigFlag(configFile) {
|
|
2453
2473
|
return configFile === LOCALGHOST_CONFIG_FILE ? "" : ` --config ${shellQuote(configFile)}`;
|
|
2454
2474
|
}
|
|
2455
|
-
function
|
|
2475
|
+
function hasLocalghostDependency(pkg) {
|
|
2476
|
+
return ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"].some((field) => {
|
|
2477
|
+
const dependencies = pkg[field];
|
|
2478
|
+
return typeof dependencies === "object" && dependencies !== null && "@hamedb89/localghost" in dependencies;
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
function localghostCommand(packageManager, installed) {
|
|
2482
|
+
if (installed) return "localghost";
|
|
2483
|
+
if (packageManager === "pnpm") return "pnpm dlx @hamedb89/localghost";
|
|
2484
|
+
if (packageManager === "yarn") return "yarn dlx @hamedb89/localghost";
|
|
2485
|
+
if (packageManager === "bun") return "bunx --package @hamedb89/localghost localghost";
|
|
2486
|
+
return "npm exec --yes --package=@hamedb89/localghost -- localghost";
|
|
2487
|
+
}
|
|
2488
|
+
function updatePackageScripts(packageJsonPath, configFile, packageManager) {
|
|
2456
2489
|
const pkg = readPackageJson2(packageJsonPath);
|
|
2457
2490
|
if (!pkg) return false;
|
|
2458
2491
|
const scripts = typeof pkg.scripts === "object" && pkg.scripts ? pkg.scripts : {};
|
|
2459
2492
|
const configFlag = getConfigFlag(configFile);
|
|
2493
|
+
const command = localghostCommand(packageManager, hasLocalghostDependency(pkg));
|
|
2460
2494
|
const nextScripts = {
|
|
2461
2495
|
...scripts,
|
|
2462
|
-
"localghost:setup": scripts["localghost:setup"] ??
|
|
2463
|
-
"localghost:proxy": scripts["localghost:proxy"] ??
|
|
2464
|
-
"localghost:proxy:https": scripts["localghost:proxy:https"] ??
|
|
2465
|
-
"localghost:run": scripts["localghost:run"] ??
|
|
2466
|
-
"localghost:ready": scripts["localghost:ready"] ??
|
|
2467
|
-
"localghost:repair": scripts["localghost:repair"] ??
|
|
2468
|
-
"localghost:trust": scripts["localghost:trust"] ??
|
|
2469
|
-
"localghost:ps": scripts["localghost:ps"] ??
|
|
2470
|
-
"localghost:print": scripts["localghost:print"] ??
|
|
2471
|
-
"localghost:routes": scripts["localghost:routes"] ??
|
|
2472
|
-
"localghost:status": scripts["localghost:status"] ??
|
|
2473
|
-
"localghost:reset": scripts["localghost:reset"] ??
|
|
2474
|
-
"localghost:teardown": scripts["localghost:teardown"] ??
|
|
2475
|
-
"localghost:doctor": scripts["localghost:doctor"] ??
|
|
2476
|
-
"localghost:update": scripts["localghost:update"] ??
|
|
2477
|
-
"caddy:setup": scripts["caddy:setup"] ??
|
|
2478
|
-
"caddy:dev": scripts["caddy:dev"] ??
|
|
2496
|
+
"localghost:setup": scripts["localghost:setup"] ?? `${command} setup${configFlag}`,
|
|
2497
|
+
"localghost:proxy": scripts["localghost:proxy"] ?? `${command} dev${configFlag}`,
|
|
2498
|
+
"localghost:proxy:https": scripts["localghost:proxy:https"] ?? `${command} dev${configFlag} --https`,
|
|
2499
|
+
"localghost:run": scripts["localghost:run"] ?? `${command} run${configFlag} --`,
|
|
2500
|
+
"localghost:ready": scripts["localghost:ready"] ?? `${command} status${configFlag} --ready`,
|
|
2501
|
+
"localghost:repair": scripts["localghost:repair"] ?? `${command} repair${configFlag}`,
|
|
2502
|
+
"localghost:trust": scripts["localghost:trust"] ?? `${command} trust${configFlag}`,
|
|
2503
|
+
"localghost:ps": scripts["localghost:ps"] ?? `${command} ps`,
|
|
2504
|
+
"localghost:print": scripts["localghost:print"] ?? `${command} print${configFlag}`,
|
|
2505
|
+
"localghost:routes": scripts["localghost:routes"] ?? `${command} routes${configFlag}`,
|
|
2506
|
+
"localghost:status": scripts["localghost:status"] ?? `${command} status`,
|
|
2507
|
+
"localghost:reset": scripts["localghost:reset"] ?? `${command} reset`,
|
|
2508
|
+
"localghost:teardown": scripts["localghost:teardown"] ?? `${command} teardown`,
|
|
2509
|
+
"localghost:doctor": scripts["localghost:doctor"] ?? `${command} doctor`,
|
|
2510
|
+
"localghost:update": scripts["localghost:update"] ?? `${command} update`,
|
|
2511
|
+
"caddy:setup": scripts["caddy:setup"] ?? `${command} setup${configFlag}`,
|
|
2512
|
+
"caddy:dev": scripts["caddy:dev"] ?? `${command} dev${configFlag}`
|
|
2479
2513
|
};
|
|
2480
2514
|
const changed = JSON.stringify(scripts) !== JSON.stringify(nextScripts);
|
|
2481
2515
|
if (!changed) return false;
|
|
@@ -2511,7 +2545,7 @@ function initLocalghost(options = {}) {
|
|
|
2511
2545
|
}
|
|
2512
2546
|
writeTextFile(configPath, renderConfig({ host, port, apiHost, apiPort }));
|
|
2513
2547
|
const packageJsonPath = join8(cwd, "package.json");
|
|
2514
|
-
const packageJsonChanged = options.writeScripts ? updatePackageScripts(packageJsonPath, configFile) : false;
|
|
2548
|
+
const packageJsonChanged = options.writeScripts ? updatePackageScripts(packageJsonPath, configFile, packageManager) : false;
|
|
2515
2549
|
return {
|
|
2516
2550
|
configPath,
|
|
2517
2551
|
configCreated: true,
|
|
@@ -2865,7 +2899,7 @@ import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as rea
|
|
|
2865
2899
|
import { homedir as homedir3 } from "os";
|
|
2866
2900
|
import { dirname as dirname4, join as join10 } from "path";
|
|
2867
2901
|
var LOCALGHOST_PACKAGE_NAME = "@hamedb89/localghost";
|
|
2868
|
-
var LOCALGHOST_VERSION = "0.
|
|
2902
|
+
var LOCALGHOST_VERSION = "0.4.0";
|
|
2869
2903
|
var UPDATE_CHECK_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
2870
2904
|
var UPDATE_CHECK_NOTIFY_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
2871
2905
|
var UPDATE_CHECK_TIMEOUT_MS = 900;
|
|
@@ -2993,7 +3027,8 @@ function formatUpdateMessage(result) {
|
|
|
2993
3027
|
if (!result.updateAvailable || !result.latestVersion) return null;
|
|
2994
3028
|
return [
|
|
2995
3029
|
`localghost ${result.latestVersion} is available. Current: ${result.currentVersion}`,
|
|
2996
|
-
|
|
3030
|
+
"Update a repository with: npm exec --yes --package=@hamedb89/localghost -- localghost upgrade",
|
|
3031
|
+
"If Localghost is already installed locally, run: localghost upgrade"
|
|
2997
3032
|
].join("\n");
|
|
2998
3033
|
}
|
|
2999
3034
|
function shouldNotifyAboutUpdate(result, cachePath = getUpdateCheckCachePath(), now = Date.now()) {
|