Skip to content

Commit

Permalink
chore: update xterm imports to use @xterm/xterm package (#4036) (#4068)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxps authored Oct 10, 2024
1 parent a08cb41 commit c4bf2ff
Show file tree
Hide file tree
Showing 32 changed files with 101 additions and 97 deletions.
4 changes: 2 additions & 2 deletions packages/ai-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
"@opensumi/ide-theme": "workspace:*",
"@opensumi/ide-utils": "workspace:*",
"@opensumi/ide-workspace": "workspace:*",
"@xterm/xterm": "5.5.0",
"ansi-regex": "^2.0.0",
"dom-align": "^1.7.0",
"js-tiktoken": "1.0.12",
"react-chat-elements": "^12.0.10",
"react-highlight": "^0.15.0",
"web-tree-sitter": "0.22.6",
"xterm": "5.3.0"
"web-tree-sitter": "0.22.6"
},
"devDependencies": {
"@opensumi/ide-core-browser": "workspace:*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IMarker } from 'xterm';
import { IMarker } from '@xterm/xterm';

import { Autowired, Injectable } from '@opensumi/di';
import { AIActionItem } from '@opensumi/ide-core-browser/lib/components/ai-native';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDecoration, IMarker, Terminal } from '@xterm/xterm';
import React from 'react';
import { Root, createRoot } from 'react-dom/client';
import { IDecoration, IMarker, Terminal } from 'xterm';

import { Autowired, Injectable } from '@opensumi/di';
import { AIActionItem } from '@opensumi/ide-core-browser/lib/components/ai-native';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IDecoration, IDisposable, IMarker, Terminal } from '@xterm/xterm';
import domAlign from 'dom-align';
import React from 'react';
import { Root, createRoot } from 'react-dom/client';
import { IDecoration, IDisposable, IMarker, Terminal } from 'xterm';

import { Autowired, Injectable } from '@opensumi/di';
import { localize } from '@opensumi/ide-core-browser';
Expand Down
11 changes: 7 additions & 4 deletions packages/terminal-next/__tests__/browser/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { injector } from './inject';
import { createProxyServer, createWsServer } from './proxy';
import { createBufferLineArray, delay } from './utils';

import type { ITerminalAddon } from 'xterm';
import type { ITerminalAddon } from '@xterm/xterm';

function createDOMContainer() {
const div = document.createElement('div');
Expand All @@ -41,13 +41,16 @@ class MockXTermAddonWebgl {
}
}

jest.mock('xterm', () => {
jest.mock('@xterm/xterm', () => {
const Terminal = class MockXTerminal {
private _text = '';
public options = {};
get cols() {
return 0;
}
get onLineFeed() {
return Event.None;
}
get onResize() {
return Event.None;
}
Expand Down Expand Up @@ -109,11 +112,11 @@ jest.mock('xterm', () => {
}
};
return {
...jest.requireActual('xterm'),
...jest.requireActual('@xterm/xterm'),
Terminal,
};
});
jest.mock('xterm-addon-webgl', () => MockXTermAddonWebgl);
jest.mock('@xterm/addon-webgl', () => MockXTermAddonWebgl);

describe('Terminal Client', () => {
let client: ITerminalClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ILink, Terminal } from 'xterm';
import { ILink, Terminal } from '@xterm/xterm';

import { createBrowserInjector } from '@opensumi/ide-dev-tool/src/injector-helper';

import { createBrowserInjector } from '../../../../../tools/dev-tool/src/injector-helper';
import { TerminalProtocolLinkProvider } from '../../../src/browser/links/protocol-link-provider';

describe('Workbench - TerminalWebLinkProvider', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ILink, Terminal } from 'xterm';
import { ILink, Terminal } from '@xterm/xterm';

import { OperatingSystem, URI } from '@opensumi/ide-core-common';
import { createBrowserInjector } from '@opensumi/ide-dev-tool/src/injector-helper';

import { createBrowserInjector } from '../../../../../tools/dev-tool/src/injector-helper';
import { TerminalValidatedLocalLinkProvider } from '../../../src/browser/links/validated-local-link-provider';

const unixLinks = ['/foo', '~/foo', './foo', '../foo', '/foo/bar', '/foo/bar+more', 'foo/bar', 'foo/bar+more'];
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/__tests__/browser/mock.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Terminal } from '@xterm/xterm';
import WebSocket from 'ws';
import { Terminal } from 'xterm';

import { Injectable } from '@opensumi/di';
import { WSChannel } from '@opensumi/ide-connection';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import { IViewportRange, Terminal } from 'xterm';
import { IViewportRange, Terminal } from '@xterm/xterm';

import { Injector } from '@opensumi/di';
import { LayoutState } from '@opensumi/ide-core-browser/lib/layout/layout-state';
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/__tests__/browser/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBufferCell, IBufferLine } from 'xterm';
import { IBufferCell, IBufferLine } from '@xterm/xterm';

export async function delay(ms: number) {
return new Promise<void>((resolve) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/terminal-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"@opensumi/ide-core-node": "workspace:*",
"@opensumi/ide-file-service": "workspace:*",
"@opensumi/ide-utils": "workspace:*",
"@xterm/addon-canvas": "0.7.0",
"@xterm/addon-fit": "0.10.0",
"@xterm/addon-search": "0.15.0",
"@xterm/addon-webgl": "0.18.0",
"@xterm/xterm": "5.5.0",
"node-pty": "1.0.0",
"os-locale": "^4.0.0",
"xterm": "5.3.0",
"xterm-addon-canvas": "0.4.0",
"xterm-addon-fit": "0.8.0",
"xterm-addon-search": "0.12.0",
"xterm-addon-webgl": "0.15.0"
"os-locale": "^4.0.0"
},
"devDependencies": {
"@opensumi/ide-components": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ResizeView, { ResizeDirection } from './resize.view';
import styles from './terminal.module.less';
import TerminalWidget from './terminal.widget';

import 'xterm/css/xterm.css';
import '@xterm/xterm/css/xterm.css';

export default observer(() => {
const controller = useInjectable<ITerminalController>(ITerminalController);
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/links/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TerminalLink } from './link';

import type { ILink, ILinkProvider } from 'xterm';
import type { ILink, ILinkProvider } from '@xterm/xterm';

export abstract class TerminalBaseLinkProvider implements ILinkProvider {
private _activeLinks: TerminalLink[] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { convertLinkRangeToBuffer, getXtermLineContent } from './helpers';
import { TerminalLink } from './link';
import { XtermLinkMatcherHandler } from './link-manager';

import type { IBufferLine, IViewportRange, Terminal } from 'xterm';
import type { IBufferLine, IViewportRange, Terminal } from '@xterm/xterm';

/**
* An adapter to convert a simple external link provider into an internal link provider that
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/links/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { IRange } from '@opensumi/ide-core-common/lib/types';

import type { IBuffer, IBufferCellPosition, IBufferLine, IBufferRange, IViewportRange } from 'xterm';
import type { IBuffer, IBufferCellPosition, IBufferLine, IBufferRange, IViewportRange } from '@xterm/xterm';

export function convertLinkRangeToBuffer(lines: IBufferLine[], bufferWidth: number, range: IRange, startLine: number) {
const bufferRange: IBufferRange = {
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/links/link-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ILinkProvider, IViewportRange, Terminal } from 'xterm';
import { ILinkProvider, IViewportRange, Terminal } from '@xterm/xterm';

import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
import { IOpenerService, PreferenceService } from '@opensumi/ide-core-browser';
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/links/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

import { convertBufferRangeToViewport } from './helpers';

import type { IBufferRange, ILink, ILinkDecorations, IViewportRange, Terminal } from 'xterm';
import type { IBufferRange, ILink, ILinkDecorations, IViewportRange, Terminal } from '@xterm/xterm';

// default delay time (ms) for showing tooltip when mouse is over a link
const DEFAULT_HOVER_DELAY = 500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TerminalBaseLinkProvider } from './base';
import { convertLinkRangeToBuffer, getXtermLineContent } from './helpers';
import { TerminalLink } from './link';

import type { IBufferLine, IViewportRange, Terminal } from 'xterm';
import type { IBufferLine, IViewportRange, Terminal } from '@xterm/xterm';

@Injectable({ multiple: true })
export class TerminalProtocolLinkProvider extends TerminalBaseLinkProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FOLDER_IN_WORKSPACE_LABEL, FOLDER_NOT_IN_WORKSPACE_LABEL, OPEN_FILE_LAB
import { XtermLinkMatcherHandler } from './link-manager';

import type { TerminalClient } from '../terminal.client';
import type { IBufferLine, IViewportRange, Terminal } from 'xterm';
import type { IBufferLine, IViewportRange, Terminal } from '@xterm/xterm';

const pathPrefix = '(\\.\\.?|\\~)';
const pathSeparatorClause = '\\/';
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/terminal.addon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITerminalAddon, Terminal } from 'xterm';
import { ITerminalAddon, Terminal } from '@xterm/xterm';

import { Disposable, Emitter } from '@opensumi/ide-core-common';

Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/terminal.preference.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ITerminalOptions } from '@xterm/xterm';
import pickBy from 'lodash/pickBy';
import { ITerminalOptions } from 'xterm';

import { Autowired, Injectable } from '@opensumi/di';
import { PreferenceService } from '@opensumi/ide-core-browser';
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/terminal.theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ITerminalTheme } from '../common';

import * as TERMINAL_COLOR from './terminal.color';

import type { ITheme } from 'xterm';
import type { ITheme } from '@xterm/xterm';

@Injectable()
export class TerminalTheme extends Themable implements ITerminalTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { CodeTerminalSettingId } from '../common/preference';
import { Color, RGBA } from './terminal.typeAhead.ext';
import { IXtermCore, XtermAttributes } from './xterm-private';

import type { IBuffer, IBufferCell, IDisposable, ITerminalAddon, Terminal } from 'xterm';
import type { IBuffer, IBufferCell, IDisposable, ITerminalAddon, Terminal } from '@xterm/xterm';

export const DEFAULT_LOCAL_ECHO_EXCLUDE: ReadonlyArray<string> = ['vim', 'vi', 'nano', 'tmux'];

Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/browser/xterm-private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-disable @typescript-eslint/naming-convention */

import { IBufferCell } from 'xterm';
import { IBufferCell } from '@xterm/xterm';

export type XtermAttributes = Omit<IBufferCell, 'getWidth' | 'getChars' | 'getCode'> & { clone?(): XtermAttributes };

Expand Down
14 changes: 7 additions & 7 deletions packages/terminal-next/src/browser/xterm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { ITerminalOptions, ITheme, Terminal } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { ISearchOptions, SearchAddon } from 'xterm-addon-search';
import { FitAddon } from '@xterm/addon-fit';
import { ISearchOptions, SearchAddon } from '@xterm/addon-search';
import { ITerminalOptions, ITheme, Terminal } from '@xterm/xterm';

import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
import { IClipboardService } from '@opensumi/ide-core-browser';
Expand All @@ -26,8 +26,8 @@ import {
TERMINAL_OVERVIEW_RULER_FIND_MATCH_FOREGROUND_COLOR,
} from './terminal.color';

import type { CanvasAddon as CanvasAddonType } from 'xterm-addon-canvas';
import type { WebglAddon as WebglAddonType } from 'xterm-addon-webgl';
import type { CanvasAddon as CanvasAddonType } from '@xterm/addon-canvas';
import type { WebglAddon as WebglAddonType } from '@xterm/addon-webgl';

export interface XTermOptions {
cwd?: string;
Expand Down Expand Up @@ -85,7 +85,7 @@ export class XTerm extends Disposable implements IXTerm {
try {
if (!this._canvasAddon) {
// @ts-ignore
this._canvasAddon = new (await import('xterm-addon-canvas')).CanvasAddon();
this._canvasAddon = new (await import('@xterm/addon-canvas')).CanvasAddon();
}

this.addDispose(this._canvasAddon);
Expand All @@ -104,7 +104,7 @@ export class XTerm extends Disposable implements IXTerm {
try {
if (!this._webglAddon) {
// @ts-ignore
this._webglAddon = new (await import('xterm-addon-webgl')).WebglAddon();
this._webglAddon = new (await import('@xterm/addon-webgl')).WebglAddon();
}

this.addDispose(this._webglAddon);
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/common/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Terminal } from 'xterm';
import { Terminal } from '@xterm/xterm';

import { Deferred, Disposable, Event, IDisposable } from '@opensumi/ide-core-common';

Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/common/pty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Terminal as XTerm } from '@xterm/xterm';
import { IPty as INodePty } from 'node-pty';
import * as pty from 'node-pty';
import { Terminal as XTerm } from 'xterm';

import { IThemeColor, MaybePromise, OperatingSystem, Uri } from '@opensumi/ide-core-common';

Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/common/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITerminalOptions as IXtermTerminalOptions } from 'xterm';
import { ITerminalOptions as IXtermTerminalOptions } from '@xterm/xterm';

import { IDisposable, OperatingSystem } from '@opensumi/ide-core-common';

Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/common/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITheme } from 'xterm';
import { ITheme } from '@xterm/xterm';

export const ITerminalTheme = Symbol('ITerminalTheme');
export interface ITerminalTheme {
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/common/xterm-private.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBufferCell } from 'xterm';
import { IBufferCell } from '@xterm/xterm';

export type XTermAttributes = Omit<IBufferCell, 'getWidth' | 'getChars' | 'getCode'> & { clone?(): XTermAttributes };

Expand Down
2 changes: 1 addition & 1 deletion packages/terminal-next/src/common/xterm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITerminalOptions, ITheme, Terminal } from 'xterm';
import { ITerminalOptions, ITheme, Terminal } from '@xterm/xterm';

import { SupportedOptions } from './preference';

Expand Down
Loading

0 comments on commit c4bf2ff

Please sign in to comment.