mirror of
https://github.com/garrytan/gstack.git
synced 2026-07-11 02:13:47 +02:00
Merge remote-tracking branch 'origin/main' into garrytan/fix-headed-browser-shutdown
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user