# 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):**
```json
{
"dependencies": {
"xterm": "^3.14.5"
}
}
```
**After (package.json):**
```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 `
```
**JavaScript API Changes:**
```javascript
// 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
1. **Update npm packages:**
```bash
npm install
```
2. **Copy custom addon to node_modules:**
```bash
cp static/terminado-addon.js node_modules/
```
3. **Build and run:**
```bash
cargo build
cargo run
```
4. **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:
1. **Use scoped packages:** Install `@xterm/xterm` instead of `xterm`
2. **Install addon packages separately:** Each addon is now its own npm package
3. **Implement ITerminalAddon:** Custom addons must implement the modern interface:
```javascript
class MyAddon {
activate(terminal) { /* ... */ }
dispose() { /* ... */ }
}
```
4. **Update your HTML:** Change script paths to point to new locations
5. **Refactor addon usage:** Replace `applyAddon()` with `loadAddon()`
## Breaking Changes from v3.x to v5.x
1. **No backward compatibility:** The old addon API is completely removed
2. **Package names changed:** Must use `@xterm/*` scoped packages
3. **Addon methods moved:** Methods like `fit()` now belong to addon instances
4. **File locations changed:** Scripts moved from `dist/` to `lib/` or `css/`
5. **No global addon objects:** Addons no longer register themselves globally
## Benefits of Upgrading
1. **Modern API:** Cleaner, more maintainable code structure
2. **Better TypeScript support:** Improved type definitions
3. **Performance improvements:** Better rendering and memory management
4. **Security updates:** Patches for known vulnerabilities
5. **Active development:** v3.x is no longer maintained
6. **New features:** Access to all features added since v3.x
7. **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](https://xtermjs.org/)
- [xterm.js GitHub Repository](https://github.com/xtermjs/xterm.js)
- [Migration Guide (v3 to v4)](https://github.com/xtermjs/xterm.js/blob/master/MIGRATION.md)
- [Addon API Documentation](https://github.com/xtermjs/xterm.js/tree/master/addons)
## Future Considerations
1. **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
2. **WebAssembly backend:** xterm.js v5.x supports WebAssembly for improved performance
3. **Ligature support:** New versions support font ligatures for better code display
4. **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.