pgserve 1.0.2 → 1.0.5
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/Makefile +5 -2
- package/README.md +2 -2
- package/bin/pglite-server.js +2 -2
- package/knip.json +2 -1
- package/package.json +3 -1
- package/scripts/test-npx.sh +51 -0
- package/src/cluster.js +3 -3
- package/src/dashboard.js +2 -2
- package/src/postgres.js +3 -1
- package/src/router.js +1 -1
package/Makefile
CHANGED
|
@@ -111,10 +111,13 @@ check-npm: ## Check npm authentication
|
|
|
111
111
|
@echo "$(CYAN)🔍 Checking npm authentication...$(RESET)"
|
|
112
112
|
@if ! npm whoami >/dev/null 2>&1; then \
|
|
113
113
|
echo "$(RED)❌ Not logged in to npm!$(RESET)"; \
|
|
114
|
-
echo "$(YELLOW)Run: npm login$(RESET)"; \
|
|
114
|
+
echo "$(YELLOW)Run: npm login --auth-type=legacy$(RESET)"; \
|
|
115
115
|
exit 1; \
|
|
116
116
|
fi
|
|
117
117
|
@echo "$(GREEN)✅ Logged in as: $$(npm whoami)$(RESET)"
|
|
118
|
+
@if [ -z "$$NPM_TOKEN" ] && ! grep -q "_authToken" ~/.npmrc 2>/dev/null; then \
|
|
119
|
+
echo "$(YELLOW)⚠️ Consider using NPM_TOKEN or ~/.npmrc for non-interactive publish$(RESET)"; \
|
|
120
|
+
fi
|
|
118
121
|
|
|
119
122
|
check-version: ## Check if version tag exists
|
|
120
123
|
@echo "$(CYAN)🔍 Checking version $(VERSION)...$(RESET)"
|
|
@@ -178,7 +181,7 @@ publish: check-git check-npm check-files ## 🚀 Publish to npm (auto-bumps vers
|
|
|
178
181
|
fi; \
|
|
179
182
|
echo ""; \
|
|
180
183
|
echo "$(CYAN)📦 Publishing to npm...$(RESET)"; \
|
|
181
|
-
npm publish --access public; \
|
|
184
|
+
npm publish --access public || { echo "$(RED)❌ npm publish failed! Run manually: npm publish --access public$(RESET)"; exit 1; }; \
|
|
182
185
|
echo "$(GREEN)✅ Published to npm!$(RESET)"; \
|
|
183
186
|
echo ""; \
|
|
184
187
|
if command -v gh >/dev/null 2>&1; then \
|
package/README.md
CHANGED
|
@@ -99,7 +99,7 @@ npm install pgserve
|
|
|
99
99
|
pgserve [options]
|
|
100
100
|
|
|
101
101
|
Options:
|
|
102
|
-
--port <number> PostgreSQL port (default:
|
|
102
|
+
--port <number> PostgreSQL port (default: 8432)
|
|
103
103
|
--data <path> Data directory for persistence (default: in-memory)
|
|
104
104
|
--host <host> Host to bind to (default: 127.0.0.1)
|
|
105
105
|
--log <level> Log level: error, warn, info, debug (default: info)
|
|
@@ -139,7 +139,7 @@ pgserve --sync-to "postgresql://user:pass@db.example.com:5432/prod"
|
|
|
139
139
|
import { startMultiTenantServer } from 'pgserve';
|
|
140
140
|
|
|
141
141
|
const server = await startMultiTenantServer({
|
|
142
|
-
port:
|
|
142
|
+
port: 8432,
|
|
143
143
|
host: '127.0.0.1',
|
|
144
144
|
baseDir: null, // null = memory mode
|
|
145
145
|
logLevel: 'info',
|
package/bin/pglite-server.js
CHANGED
|
@@ -42,7 +42,7 @@ USAGE:
|
|
|
42
42
|
pgserve [options]
|
|
43
43
|
|
|
44
44
|
OPTIONS:
|
|
45
|
-
--port <number> PostgreSQL port (default:
|
|
45
|
+
--port <number> PostgreSQL port (default: 8432)
|
|
46
46
|
--data <path> Data directory for persistence (default: in-memory)
|
|
47
47
|
--host <host> Host to bind to (default: 127.0.0.1)
|
|
48
48
|
--log <level> Log level: error, warn, info, debug (default: info)
|
|
@@ -95,7 +95,7 @@ function parseArgs() {
|
|
|
95
95
|
const cpuCount = os.cpus().length;
|
|
96
96
|
|
|
97
97
|
const options = {
|
|
98
|
-
port:
|
|
98
|
+
port: 8432,
|
|
99
99
|
host: '127.0.0.1',
|
|
100
100
|
dataDir: null, // null = memory mode
|
|
101
101
|
logLevel: 'info',
|
package/knip.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"$schema": "https://unpkg.com/knip@5/schema.json",
|
|
3
3
|
"entry": ["src/index.js", "bin/pglite-server.js"],
|
|
4
4
|
"project": ["src/**/*.js", "bin/**/*.js"],
|
|
5
|
-
"ignore": ["tests/**", "helpers/**"],
|
|
5
|
+
"ignore": ["tests/**", "helpers/**", "scripts/**"],
|
|
6
6
|
"ignoreDependencies": ["pino-pretty"],
|
|
7
|
+
"ignoreBinaries": ["scripts/test-npx.sh"],
|
|
7
8
|
"ignoreExportsUsedInFile": true
|
|
8
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgserve",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Embedded PostgreSQL server with true concurrent connections - zero config, auto-provision databases",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
"lint": "eslint src/ bin/",
|
|
14
14
|
"lint:fix": "eslint src/ bin/ --fix",
|
|
15
15
|
"deadcode": "knip",
|
|
16
|
+
"test:npx": "scripts/test-npx.sh",
|
|
17
|
+
"prepublishOnly": "npm run lint && npm run deadcode && npm run test:npx",
|
|
16
18
|
"prepare": "husky"
|
|
17
19
|
},
|
|
18
20
|
"keywords": [
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Test that the package works with npx (simulates fresh install)
|
|
3
|
+
# This catches path resolution issues that static analysis can't detect
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
echo "=== Testing npx compatibility ==="
|
|
8
|
+
|
|
9
|
+
# Create temp directory
|
|
10
|
+
TEST_DIR=$(mktemp -d)
|
|
11
|
+
trap "rm -rf $TEST_DIR" EXIT
|
|
12
|
+
|
|
13
|
+
# Pack the current package
|
|
14
|
+
echo "Packing package..."
|
|
15
|
+
PACK_FILE=$(npm pack --pack-destination "$TEST_DIR" 2>/dev/null | tail -1)
|
|
16
|
+
|
|
17
|
+
# Extract and install in isolated environment
|
|
18
|
+
echo "Installing in isolated environment..."
|
|
19
|
+
cd "$TEST_DIR"
|
|
20
|
+
npm init -y > /dev/null 2>&1
|
|
21
|
+
npm install "$PACK_FILE" > /dev/null 2>&1
|
|
22
|
+
|
|
23
|
+
# Test that it starts (with timeout)
|
|
24
|
+
echo "Testing server startup..."
|
|
25
|
+
timeout 8 npx pgserve --no-cluster --port 15432 > output.log 2>&1 &
|
|
26
|
+
PID=$!
|
|
27
|
+
|
|
28
|
+
# Wait for ready signal
|
|
29
|
+
for i in {1..20}; do
|
|
30
|
+
if grep -q "READY" output.log 2>/dev/null; then
|
|
31
|
+
echo "✓ Server started successfully"
|
|
32
|
+
kill $PID 2>/dev/null || true
|
|
33
|
+
wait $PID 2>/dev/null || true
|
|
34
|
+
echo "=== npx test PASSED ==="
|
|
35
|
+
exit 0
|
|
36
|
+
fi
|
|
37
|
+
if ! kill -0 $PID 2>/dev/null; then
|
|
38
|
+
echo "✗ Server exited unexpectedly"
|
|
39
|
+
cat output.log
|
|
40
|
+
echo "=== npx test FAILED ==="
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
sleep 0.5
|
|
44
|
+
done
|
|
45
|
+
|
|
46
|
+
# Timeout
|
|
47
|
+
kill $PID 2>/dev/null || true
|
|
48
|
+
echo "✗ Server did not start within timeout"
|
|
49
|
+
cat output.log
|
|
50
|
+
echo "=== npx test FAILED ==="
|
|
51
|
+
exit 1
|
package/src/cluster.js
CHANGED
|
@@ -25,7 +25,7 @@ import { EventEmitter } from 'events';
|
|
|
25
25
|
class ClusterRouter extends EventEmitter {
|
|
26
26
|
constructor(options = {}) {
|
|
27
27
|
super();
|
|
28
|
-
this.port = options.port ||
|
|
28
|
+
this.port = options.port || 8432;
|
|
29
29
|
this.host = options.host || '127.0.0.1';
|
|
30
30
|
this.pgSocketPath = options.pgSocketPath; // From PRIMARY
|
|
31
31
|
this.pgPort = options.pgPort;
|
|
@@ -192,7 +192,7 @@ class ClusterRouter extends EventEmitter {
|
|
|
192
192
|
*/
|
|
193
193
|
export async function startClusterServer(options = {}) {
|
|
194
194
|
const numWorkers = options.workers || os.cpus().length;
|
|
195
|
-
const port = options.port ||
|
|
195
|
+
const port = options.port || 8432;
|
|
196
196
|
const host = options.host || '127.0.0.1';
|
|
197
197
|
const pgPort = options.pgPort || (port + 1000);
|
|
198
198
|
|
|
@@ -292,7 +292,7 @@ export async function startClusterServer(options = {}) {
|
|
|
292
292
|
} else {
|
|
293
293
|
// WORKER: Only run TCP routing, connect to PRIMARY's PostgreSQL
|
|
294
294
|
const router = new ClusterRouter({
|
|
295
|
-
port: parseInt(process.env.PGSERVE_PORT) ||
|
|
295
|
+
port: parseInt(process.env.PGSERVE_PORT) || 8432,
|
|
296
296
|
host: process.env.PGSERVE_HOST || '127.0.0.1',
|
|
297
297
|
pgSocketPath: process.env.PGSERVE_PG_SOCKET || null,
|
|
298
298
|
pgPort: parseInt(process.env.PGSERVE_PG_PORT) || 6432,
|
package/src/dashboard.js
CHANGED
|
@@ -56,7 +56,7 @@ export class Dashboard {
|
|
|
56
56
|
*/
|
|
57
57
|
showHeader(config = {}) {
|
|
58
58
|
const mode = config.memoryMode ? 'In-memory' : 'Persistent';
|
|
59
|
-
const port = config.port ||
|
|
59
|
+
const port = config.port || 8432;
|
|
60
60
|
const host = config.host || '127.0.0.1';
|
|
61
61
|
const syncTo = config.syncTo ? ` → ${this._maskUrl(config.syncTo)}` : '';
|
|
62
62
|
|
|
@@ -169,7 +169,7 @@ export class Dashboard {
|
|
|
169
169
|
* Show final ready message
|
|
170
170
|
*/
|
|
171
171
|
showReady(config = {}) {
|
|
172
|
-
const port = config.port ||
|
|
172
|
+
const port = config.port || 8432;
|
|
173
173
|
const host = config.host || '127.0.0.1';
|
|
174
174
|
|
|
175
175
|
console.log('');
|
package/src/postgres.js
CHANGED
|
@@ -37,10 +37,12 @@ function getBinaryPaths() {
|
|
|
37
37
|
throw new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
// Find the package in node_modules
|
|
40
|
+
// Find the package in node_modules (check multiple locations for npx/pnpm/npm compatibility)
|
|
41
41
|
const possiblePaths = [
|
|
42
42
|
path.join(process.cwd(), 'node_modules', pkgName, 'native', 'bin'),
|
|
43
43
|
path.join(import.meta.dirname, '..', 'node_modules', pkgName, 'native', 'bin'),
|
|
44
|
+
path.join(import.meta.dirname, '..', '..', pkgName, 'native', 'bin'), // Hoisted (npx flat structure)
|
|
45
|
+
path.join(import.meta.dirname, '..', '..', '..', pkgName, 'native', 'bin'), // Extra level for some package managers
|
|
44
46
|
];
|
|
45
47
|
|
|
46
48
|
for (const binDir of possiblePaths) {
|
package/src/router.js
CHANGED
|
@@ -27,7 +27,7 @@ import pino from 'pino';
|
|
|
27
27
|
export class MultiTenantRouter extends EventEmitter {
|
|
28
28
|
constructor(options = {}) {
|
|
29
29
|
super();
|
|
30
|
-
this.port = options.port ||
|
|
30
|
+
this.port = options.port || 8432;
|
|
31
31
|
this.host = options.host || '127.0.0.1';
|
|
32
32
|
this.baseDir = options.baseDir || null; // null = memory mode
|
|
33
33
|
this.memoryMode = !options.baseDir;
|