dialog-survey 1.6.2 → 1.6.3
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/package.json +1 -1
- package/scripts/cli.mjs +29 -9
- package/scripts/deploy.sh +1 -1
package/package.json
CHANGED
package/scripts/cli.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { homedir, tmpdir } from "node:os";
|
|
|
15
15
|
import { join, dirname } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
import http from "node:http";
|
|
18
|
+
import net from "node:net";
|
|
18
19
|
|
|
19
20
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
20
21
|
|
|
@@ -197,19 +198,35 @@ export function checkNodeVersion(version = process.versions.node) {
|
|
|
197
198
|
|
|
198
199
|
/**
|
|
199
200
|
* Check if PostgreSQL is reachable using the given DATABASE_URL.
|
|
201
|
+
* Uses a TCP socket connect instead of pg_isready for cross-platform
|
|
202
|
+
* support (pg_isready is unavailable on Windows by default).
|
|
200
203
|
* @param {string} databaseUrl
|
|
201
|
-
* @
|
|
204
|
+
* @param {number} [timeoutMs=3000]
|
|
205
|
+
* @returns {Promise<{ ok: boolean, message: string }>}
|
|
202
206
|
*/
|
|
203
|
-
export function checkPostgres(databaseUrl) {
|
|
207
|
+
export async function checkPostgres(databaseUrl, timeoutMs = 3000) {
|
|
204
208
|
if (!databaseUrl) {
|
|
205
209
|
return { ok: false, message: "DATABASE_URL not provided" };
|
|
206
210
|
}
|
|
207
211
|
try {
|
|
208
|
-
// Extract host and port from postgresql:// URL
|
|
209
212
|
const url = new URL(databaseUrl);
|
|
210
213
|
const host = url.hostname;
|
|
211
214
|
const port = url.port || "5432";
|
|
212
|
-
|
|
215
|
+
|
|
216
|
+
await new Promise((resolve, reject) => {
|
|
217
|
+
const socket = new net.Socket();
|
|
218
|
+
let settled = false;
|
|
219
|
+
const cleanup = () => {
|
|
220
|
+
settled = true;
|
|
221
|
+
socket.destroy();
|
|
222
|
+
};
|
|
223
|
+
socket.setTimeout(timeoutMs);
|
|
224
|
+
socket.on("connect", () => { cleanup(); resolve(); });
|
|
225
|
+
socket.on("error", (err) => { cleanup(); reject(err); });
|
|
226
|
+
socket.on("timeout", () => { cleanup(); reject(new Error("timeout")); });
|
|
227
|
+
socket.connect(Number(port), host);
|
|
228
|
+
});
|
|
229
|
+
|
|
213
230
|
return { ok: true, message: `PostgreSQL ${host}:${port} ✓` };
|
|
214
231
|
} catch {
|
|
215
232
|
return {
|
|
@@ -259,7 +276,7 @@ export async function checkPrerequisites(databaseUrl) {
|
|
|
259
276
|
messages.push(nodeCheck.message);
|
|
260
277
|
if (!nodeCheck.ok) allOk = false;
|
|
261
278
|
|
|
262
|
-
const pgCheck = checkPostgres(databaseUrl);
|
|
279
|
+
const pgCheck = await checkPostgres(databaseUrl);
|
|
263
280
|
messages.push(pgCheck.message);
|
|
264
281
|
if (!pgCheck.ok) allOk = false;
|
|
265
282
|
|
|
@@ -805,11 +822,14 @@ export async function main(argv) {
|
|
|
805
822
|
}
|
|
806
823
|
|
|
807
824
|
// Run if invoked directly
|
|
825
|
+
// Use path-based check instead of import.meta.resolve() which may return
|
|
826
|
+
// non-file URLs on Node.js >= 26, causing ERR_INVALID_URL_SCHEME.
|
|
808
827
|
const isMain =
|
|
809
|
-
process.argv[1] &&
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
process.argv[1].endsWith("
|
|
828
|
+
process.argv[1] && (
|
|
829
|
+
process.argv[1].endsWith("cli.mjs") ||
|
|
830
|
+
process.argv[1].endsWith("dialog-survey") ||
|
|
831
|
+
process.argv[1].endsWith(`dialog-survey${process.platform === "win32" ? ".cmd" : ""}`)
|
|
832
|
+
);
|
|
813
833
|
|
|
814
834
|
if (isMain) {
|
|
815
835
|
main(process.argv.slice(2));
|
package/scripts/deploy.sh
CHANGED
|
@@ -44,7 +44,7 @@ log_info "✓ Node.js $(node -v)"
|
|
|
44
44
|
if ! command -v psql &>/dev/null; then
|
|
45
45
|
log_warn "psql not found — skipping database check"
|
|
46
46
|
elif [ -n "${DATABASE_URL:-}" ]; then
|
|
47
|
-
if !
|
|
47
|
+
if ! psql "$DATABASE_URL" -c "SELECT 1" 2>/dev/null; then
|
|
48
48
|
log_error "PostgreSQL not reachable at DATABASE_URL"
|
|
49
49
|
exit 1
|
|
50
50
|
fi
|