@@ -27,29 +27,31 @@ const WS_PORT = 3001;
2727// Locate ghostty-web assets
2828// ============================================================================
2929
30+ import { createRequire } from 'module' ;
31+ const require = createRequire ( import . meta. url ) ;
32+
3033function findGhosttyWeb ( ) {
31- const possiblePaths = [
32- // Development: running from repo root (demo/bin/demo.js -> ../../dist)
33- path . join ( __dirname , '..' , '..' , 'dist' ) ,
34- // When installed as dependency (demo/node_modules/ghostty-web/dist)
35- path . join ( __dirname , '..' , 'node_modules' , 'ghostty-web' , 'dist' ) ,
36- // When in a monorepo or hoisted
37- path . join ( __dirname , '..' , '..' , 'node_modules' , 'ghostty-web' , 'dist' ) ,
38- path . join ( __dirname , '..' , '..' , '..' , 'node_modules' , 'ghostty-web' , 'dist' ) ,
39- ] ;
40-
41- for ( const p of possiblePaths ) {
42- const jsPath = path . join ( p , 'ghostty-web.js' ) ;
43- if ( fs . existsSync ( jsPath ) ) {
44- // Find WASM file - check both dist/ and parent directory
45- let wasmPath = path . join ( p , 'ghostty-vt.wasm' ) ;
46- if ( ! fs . existsSync ( wasmPath ) ) {
47- wasmPath = path . join ( path . dirname ( p ) , 'ghostty-vt.wasm' ) ;
48- }
49- if ( fs . existsSync ( wasmPath ) ) {
50- return { distPath : p , wasmPath } ;
51- }
34+ // First, check for local development (repo root dist/)
35+ const localDist = path . join ( __dirname , '..' , '..' , 'dist' ) ;
36+ const localJs = path . join ( localDist , 'ghostty-web.js' ) ;
37+ const localWasm = path . join ( __dirname , '..' , '..' , 'ghostty-vt.wasm' ) ;
38+
39+ if ( fs . existsSync ( localJs ) && fs . existsSync ( localWasm ) ) {
40+ return { distPath : localDist , wasmPath : localWasm , isDev : true } ;
41+ }
42+
43+ // Use require.resolve to find the installed ghostty-web package
44+ try {
45+ const ghosttyWebMain = require . resolve ( 'ghostty-web' ) ;
46+ const ghosttyWebRoot = path . dirname ( ghosttyWebMain . replace ( / [ / \\ ] d i s t [ / \\ ] .* $ / , '' ) ) ;
47+ const distPath = path . join ( ghosttyWebRoot , 'dist' ) ;
48+ const wasmPath = path . join ( ghosttyWebRoot , 'ghostty-vt.wasm' ) ;
49+
50+ if ( fs . existsSync ( path . join ( distPath , 'ghostty-web.js' ) ) && fs . existsSync ( wasmPath ) ) {
51+ return { distPath, wasmPath, isDev : false } ;
5252 }
53+ } catch ( e ) {
54+ // require.resolve failed, package not found
5355 }
5456
5557 console . error ( 'Error: Could not find ghostty-web package.' ) ;
@@ -59,10 +61,7 @@ function findGhosttyWeb() {
5961 process . exit ( 1 ) ;
6062}
6163
62- const { distPath, wasmPath } = findGhosttyWeb ( ) ;
63- const isDev =
64- distPath . includes ( path . join ( 'demo' , '..' , 'dist' ) ) ||
65- distPath === path . join ( __dirname , '..' , '..' , 'dist' ) ;
64+ const { distPath, wasmPath, isDev } = findGhosttyWeb ( ) ;
6665
6766// ============================================================================
6867// HTML Template
0 commit comments