Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c447ff4

Browse filesBrowse files
authored
fix: use require.resolve to find ghostty-web package (#56)
1 parent f775ecc commit c447ff4
Copy full SHA for c447ff4

File tree

Expand file treeCollapse file tree

1 file changed

+24
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-25
lines changed
Open diff view settings
Collapse file

‎demo/bin/demo.js‎

Copy file name to clipboardExpand all lines: demo/bin/demo.js
+24-25Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3033
function 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(/[/\\]dist[/\\].*$/, ''));
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.