Merge remote-tracking branch 'origin/main' into garrytan/fix-headed-browser-shutdown

This commit is contained in:
Garry Tan
2026-04-17 05:27:27 +08:00
6 changed files with 54 additions and 5 deletions
+7 -1
View File
@@ -14,13 +14,19 @@ DIST_DIR="$GSTACK_DIR/browse/dist"
echo "Building Node-compatible server bundle..."
# Step 1: Transpile server.ts to a single .mjs bundle (externalize runtime deps)
#
# Externalize packages with native addons, dynamic imports, or runtime resolution.
# If you add a new dependency that uses `await import()` or has a .node addon,
# add it here. Otherwise `bun build --outfile` will fail with
# "cannot write multiple output files without an output directory".
bun build "$SRC_DIR/server.ts" \
--target=node \
--outfile "$DIST_DIR/server-node.mjs" \
--external playwright \
--external playwright-core \
--external diff \
--external "bun:sqlite"
--external "bun:sqlite" \
--external "@ngrok/ngrok"
# Step 2: Post-process
# Replace import.meta.dir with a resolvable reference
+28
View File
@@ -0,0 +1,28 @@
import { describe, test, expect } from 'bun:test';
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
const DIST_DIR = path.resolve(__dirname, '..', 'dist');
const SERVER_NODE = path.join(DIST_DIR, 'server-node.mjs');
describe('build: server-node.mjs', () => {
test('passes node --check if present', () => {
if (!fs.existsSync(SERVER_NODE)) {
// browse/dist is gitignored; no build has run in this checkout.
// Skip rather than fail so plain `bun test` without a prior build passes.
return;
}
expect(() => execSync(`node --check ${SERVER_NODE}`, { stdio: 'pipe' })).not.toThrow();
});
test('does not inline @ngrok/ngrok (must be external)', () => {
if (!fs.existsSync(SERVER_NODE)) return;
const bundle = fs.readFileSync(SERVER_NODE, 'utf-8');
// Dynamic imports of externalized packages show up as string literals in the bundle,
// not as inlined module code. The heuristic: ngrok's native binding loader would
// reference its own internals. If any ngrok internal identifier appears, the module
// got inlined despite the --external flag.
expect(bundle).not.toMatch(/ngrok_napi|ngrokNapi|@ngrok\/ngrok-darwin|@ngrok\/ngrok-linux|@ngrok\/ngrok-win32/);
});
});