Skip to content

Create a node.js target for xterm.js#3212

Merged
Tyriar merged 39 commits intoxtermjs:masterfrom
joyceerhl:nodetarget
Aug 12, 2021
Merged

Create a node.js target for xterm.js#3212
Tyriar merged 39 commits intoxtermjs:masterfrom
joyceerhl:nodetarget

Conversation

@joyceerhl
Copy link
Copy Markdown
Contributor

Hey @Tyriar, here's an attempt at what you described in #2749 (comment). This PR:

  • Duplicates src/browser/public/Terminal.ts --> src/common/public/Terminal.ts.
  • Duplicates src/browser/Terminal.ts --> src/common/public/TerminalCore.ts since src/browser/public/Terminal.ts wraps src/browser/Terminal.ts.
  • Removes DOM/UI references and src/browser imports from src/common/public/Terminal.ts and src/common/public/TerminalCore.ts. I took a guess at what to remove based on what I thought would still be meaningful in the Node environment and on the discussion in Create a node.js target for xterm.js #2749, but I'd appreciate feedback here.
  • Adds a separate webpack config and tsconfig as well as a small 'testcase', node-test/index.js, which I used to verify that the changes described above can be compiled, built, and used in a Node project based on the included README.
  • I only checked in xterm-core.d.ts in the first commit in this PR to get the project compiling, since I expect that I've either taken out too much or not enough from src/common/public/Terminal.ts. Changes to that file should be disregarded for now.

I'm expecting this to need lots of work—looking forward to your feedback!

Copy link
Copy Markdown
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, some high level comments below 🙂

Comment thread core-webpack.config.js Outdated
Comment thread src/common/public/tsconfig.json Outdated
Comment thread src/common/public/tsconfig.json Outdated
"include": [
"../**/*",
"../../../typings/xterm-core.d.ts",
"../../../typings/xterm.d.ts", // common/Types.d.ts imports from 'xterm'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a problem, we can't import from xterm if we want it to run for node because it touches DOM types which will throw for tsconfig targets without the dom lib.

Comment thread src/common/public/Terminal.ts Outdated
Comment thread typings/xterm-core.d.ts Outdated
* to be stable and consumed by external programs.
*/

declare module 'xterm-core' {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another problem I'd like for us to solve is the sharing of these typings, I think having xterm.d.ts import from xterm-core.d.ts will cause problems because of this module declaration. We may need separate .d.ts that just export the core types without the module wrapping them to be able to share.

Comment thread package.json Outdated
@Tyriar Tyriar changed the title [WIP] Create a node.js target for xterm.js Create a node.js target for xterm.js Aug 10, 2021
@Tyriar Tyriar marked this pull request as ready for review August 10, 2021 19:21
@Tyriar Tyriar added this to the 4.14.0 milestone Aug 10, 2021
@Tyriar Tyriar merged commit 46aa8de into xtermjs:master Aug 12, 2021
Tyriar added a commit to Tyriar/xterm.js that referenced this pull request Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants