@arkstack/console 0.17.17 → 0.17.18

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.
Files changed (2) hide show
  1. package/dist/index.js +38 -19
  2. package/package.json +5 -4
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { Arkstack } from "@arkstack/contract";
11
11
  import { MakeResource, applyRuntimeConfig, getDefaultConfig } from "resora";
12
12
  import { Command, Kernel } from "@h3ravel/musket";
13
13
  import { spawn } from "node:child_process";
14
+ import ngrok from "@ngrok/ngrok";
14
15
  import { randomBytes } from "node:crypto";
15
16
  import { resolve as resolve$1 } from "path";
16
17
  import { writeFile } from "fs/promises";
@@ -61,6 +62,19 @@ var DevCommand = class DevCommand extends Command {
61
62
  const vars = DevCommand.devServerEnv(this.options());
62
63
  const rootDir = Arkstack.rootDir();
63
64
  const bin = DevCommand.resolveTsdownBin(rootDir);
65
+ let tunnel;
66
+ if (this.option?.("tunnel")) {
67
+ tunnel = await ngrok.forward({
68
+ addr: Number(env("APP_PORT", env("PORT", 3e3))),
69
+ authtoken: env("NGROK_AUTHTOKEN"),
70
+ domain: env("NGROK_DOMAIN")
71
+ });
72
+ const url = tunnel.url();
73
+ if (url) {
74
+ vars.TUNNEL_URL = url;
75
+ console.log(`Traffic has been tunnelled to ${url}`);
76
+ }
77
+ }
64
78
  const [command, args] = bin ? [process.execPath, [
65
79
  bin,
66
80
  "--log-level",
@@ -71,23 +85,27 @@ var DevCommand = class DevCommand extends Command {
71
85
  "--log-level",
72
86
  "silent"
73
87
  ]];
74
- await new Promise((resolve, reject) => {
75
- const child = spawn(command, args, {
76
- cwd: rootDir,
77
- stdio: "inherit",
78
- env: Object.assign(process.env, vars)
79
- });
80
- child.on("error", (error) => {
81
- reject(error);
82
- });
83
- child.on("exit", (code) => {
84
- if (code === 0 || code === null) {
85
- resolve();
86
- return;
87
- }
88
- reject(/* @__PURE__ */ new Error(`tsdown exited with code ${code}`));
88
+ try {
89
+ await new Promise((resolve, reject) => {
90
+ const child = spawn(command, args, {
91
+ cwd: rootDir,
92
+ stdio: "inherit",
93
+ env: Object.assign({}, process.env, vars)
94
+ });
95
+ child.on("error", (error) => {
96
+ reject(error);
97
+ });
98
+ child.on("exit", (code) => {
99
+ if (code === 0 || code === null) {
100
+ resolve();
101
+ return;
102
+ }
103
+ reject(/* @__PURE__ */ new Error(`tsdown exited with code ${code}`));
104
+ });
89
105
  });
90
- });
106
+ } finally {
107
+ await tunnel?.close();
108
+ }
91
109
  }
92
110
  /**
93
111
  * Resolve the absolute path to tsdown's executable so it can be run directly
@@ -112,7 +130,8 @@ var DevCommand = class DevCommand extends Command {
112
130
  *
113
131
  * The dev server binds `127.0.0.1` by default so it is local-only; `--host`
114
132
  * switches it to `0.0.0.0` to expose it on the local network. `--secure` flags
115
- * the driver to serve HTTPS, and `--tunnel` enables the Ngrok tunnel.
133
+ * the driver to serve HTTPS. The command itself owns the Ngrok tunnel so
134
+ * watcher-driven application restarts cannot replace its public URL.
116
135
  *
117
136
  * @param options
118
137
  * @returns
@@ -120,9 +139,9 @@ var DevCommand = class DevCommand extends Command {
120
139
  static devServerEnv(options) {
121
140
  const vars = {
122
141
  NODE_ENV: "development",
123
- APP_HOST: options.host ? "0.0.0.0" : "127.0.0.1"
142
+ APP_HOST: options.host ? "0.0.0.0" : "127.0.0.1",
143
+ ARKSTACK_ENV_RELOAD: "true"
124
144
  };
125
- if (options.tunnel) vars.TUNNEL = "true";
126
145
  if (options.secure) vars.APP_SECURE = "true";
127
146
  return vars;
128
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/console",
3
- "version": "0.17.17",
3
+ "version": "0.17.18",
4
4
  "type": "module",
5
5
  "description": "Console module for Arkstack, providing the command-line runtime and console integration layer.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/cli",
@@ -42,16 +42,17 @@
42
42
  "peerDependencies": {
43
43
  "arkormx": "^2.12.8",
44
44
  "clear-router": "^2.9.3",
45
- "@arkstack/database": "^0.17.17"
45
+ "@arkstack/database": "^0.17.18"
46
46
  },
47
47
  "dependencies": {
48
+ "@ngrok/ngrok": "^1.7.0",
48
49
  "@h3ravel/musket": "^2.2.13",
49
50
  "@h3ravel/support": "^2.2.7",
50
51
  "chalk": "^5.6.2",
51
52
  "resora": "^1.3.34",
52
53
  "ts-morph": "^28.0.0",
53
- "@arkstack/common": "^0.17.17",
54
- "@arkstack/contract": "^0.17.17"
54
+ "@arkstack/common": "^0.17.18",
55
+ "@arkstack/contract": "^0.17.18"
55
56
  },
56
57
  "peerDependenciesMeta": {
57
58
  "@arkstack/database": {