- Multi-architecture Docker image (ARM64 + AMD64) - Kubernetes manifests for 3-replica deployment - Traefik ingress configuration - NGINX Proxy Manager integration - ConfigMap-based configuration - Automated build and deployment scripts - Session monitoring tools
6.9 KiB
xterm.js Upgrade Documentation
Overview
This document describes the upgrade of xterm.js from version 3.14.5 to 5.5.0 (latest).
Changes Made
1. Package Dependencies
Before (package.json):
{
"dependencies": {
"xterm": "^3.14.5"
}
}
After (package.json):
{
"dependencies": {
"@xterm/xterm": "^5.3.0",
"@xterm/addon-fit": "^0.10.0"
}
}
Installed Versions:
@xterm/xterm: 5.5.0@xterm/addon-fit: 0.10.0
2. Package Namespace Change
xterm.js moved from the xterm package to the scoped @xterm/xterm package. The old package is now deprecated.
3. Addon System Overhaul
Old Addon System (v3.x):
- Addons loaded via
<script>tags from/dist/addons/*/ - Applied using
Terminal.applyAddon(addonName) - Methods added directly to Terminal prototype
- Example:
term.fit()after applying fit addon
New Addon System (v5.x):
- Addons are separate npm packages under
@xterm/addon-* - Loaded using
term.loadAddon(new AddonClass()) - Implements
ITerminalAddoninterface - Methods accessed through addon instance
- Example:
fitAddon.fit()instead ofterm.fit()
4. Terminado Protocol Addon
Created a custom TerminadoAddon class compatible with xterm 5.x that implements the Terminado WebSocket protocol.
Location: static/terminado-addon.js (also copied to node_modules/ for serving)
Features:
- Implements modern
ITerminalAddoninterface - Handles bidirectional communication over WebSocket
- Supports JSON message format:
["stdin", data],["stdout", data],["set_size", rows, cols] - Buffered output for better performance
- Automatic cleanup on dispose
- Public methods:
attach(),detach(),sendSize(),sendCommand()
API Usage:
const terminadoAddon = new TerminadoAddon();
term.loadAddon(terminadoAddon);
// Attach to WebSocket
terminadoAddon.attach(socket, bidirectional=true, buffered=true);
// Send size update
terminadoAddon.sendSize(rows, cols);
// Send command
terminadoAddon.sendCommand("socktop -P local\r");
// Detach when done
terminadoAddon.detach();
5. HTML Template Updates
File: templates/term.html
Script Loading Changes:
<!-- OLD (v3.x) -->
<link rel="stylesheet" href="/static/xterm/dist/xterm.css" />
<script src="/static/xterm/dist/xterm.js"></script>
<script src="/static/xterm/dist/addons/attach/attach.js"></script>
<script src="/static/xterm/dist/addons/terminado/terminado.js"></script>
<script src="/static/xterm/dist/addons/fit/fit.js"></script>
<script src="/static/xterm/dist/addons/search/search.js"></script>
<!-- NEW (v5.x) -->
<link rel="stylesheet" href="/static/@xterm/xterm/css/xterm.css" />
<script src="/static/@xterm/xterm/lib/xterm.js"></script>
<script src="/static/@xterm/addon-fit/lib/addon-fit.js"></script>
<script src="/static/terminado-addon.js"></script>
JavaScript API Changes:
// OLD (v3.x)
if (typeof Terminal !== 'undefined' && typeof Terminal.applyAddon === 'function') {
Terminal.applyAddon(terminado);
Terminal.applyAddon(fit);
}
var term = new Terminal();
term.open(terminalContainer);
term.terminadoAttach(sock);
term.fit();
// NEW (v5.x)
var term = new Terminal();
var fitAddon = new FitAddon.FitAddon();
term.loadAddon(fitAddon);
var terminadoAddon = new TerminadoAddon();
term.loadAddon(terminadoAddon);
term.open(terminalContainer);
fitAddon.fit();
terminadoAddon.attach(sock, true, true);
6. Rust Backend
No changes required - The Rust backend (src/server.rs, src/lib.rs, src/terminado.rs) continues to work without modification because:
- The Terminado protocol remains unchanged
- WebSocket communication is the same
- PTY handling is identical
Migration Guide
For Developers Using This Project
-
Update npm packages:
npm install -
Copy custom addon to node_modules:
cp static/terminado-addon.js node_modules/ -
Build and run:
cargo build cargo run -
Access the terminal: Open
http://localhost:8082/in your browser
For Projects Forking This Code
If you're building a similar project, here's what you need to know:
- Use scoped packages: Install
@xterm/xterminstead ofxterm - Install addon packages separately: Each addon is now its own npm package
- Implement ITerminalAddon: Custom addons must implement the modern interface:
class MyAddon { activate(terminal) { /* ... */ } dispose() { /* ... */ } } - Update your HTML: Change script paths to point to new locations
- Refactor addon usage: Replace
applyAddon()withloadAddon()
Breaking Changes from v3.x to v5.x
- No backward compatibility: The old addon API is completely removed
- Package names changed: Must use
@xterm/*scoped packages - Addon methods moved: Methods like
fit()now belong to addon instances - File locations changed: Scripts moved from
dist/tolib/orcss/ - No global addon objects: Addons no longer register themselves globally
Benefits of Upgrading
- Modern API: Cleaner, more maintainable code structure
- Better TypeScript support: Improved type definitions
- Performance improvements: Better rendering and memory management
- Security updates: Patches for known vulnerabilities
- Active development: v3.x is no longer maintained
- New features: Access to all features added since v3.x
- Better addon ecosystem: Separate packages allow independent versioning
Testing
A test file is provided to verify the upgrade: test_xterm.html
Open it in a browser (served via a local web server) to verify:
- xterm.js loads correctly
- FitAddon works properly
- Terminal renders and accepts input
- Modern API is functional
Known Issues
None at this time. The upgrade was successful with no breaking changes to functionality.
Resources
- xterm.js Official Documentation
- xterm.js GitHub Repository
- Migration Guide (v3 to v4)
- Addon API Documentation
Future Considerations
-
Additional addons: Consider adding more xterm addons:
@xterm/addon-search: Search functionality@xterm/addon-web-links: Clickable URLs@xterm/addon-webgl: WebGL renderer for better performance@xterm/addon-unicode11: Full Unicode 11 support
-
WebAssembly backend: xterm.js v5.x supports WebAssembly for improved performance
-
Ligature support: New versions support font ligatures for better code display
-
Image support: Experimental support for inline images (Sixel protocol)
Conclusion
The upgrade to xterm.js 5.5.0 was successful. All original functionality is preserved, the codebase is now more maintainable, and we have access to the latest features and security updates.