sindresorhus / ansi-escapes

ANSI escape codes for manipulating the terminal
MIT License
494 stars 44 forks source link

Support in-browser uses #31

Closed Reverier-Xu closed 1 year ago

Reverier-Xu commented 1 year ago

Hi, thank you for your awesome work!

I'd like to developing a fake shell based on xterm.js in frontend. I found that Vite dev server gives a warning like that:

Module "node:process" has been externalized for browser compatibility. Cannot access "node:process.env" in client code. See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
get @ browser-external:node:process:9

The TERM_PROGRAM env variable also does not exist in browser:

TypeError: Cannot read properties of undefined (reading 'TERM_PROGRAM')

According to the Node | Webpack documentation, the webpack can make polyfills for different node functions, but it appears as the node.process is a "mock";

"mock": Provide a mock that implements the expected interface but has little or no functionality.

So I added some code to judge the current running environment in advance, and moved some code related to Node to conditional judgment.

countfak commented 1 year ago

Hi, is this getting merged soon by any chance?

Reverier-Xu commented 1 year ago

Hi, is this getting merged soon by any chance?

I published an alternative package isomorphic-ansi-escapes to temporarily replace this. You can use it before this pr gets merged.

countfak commented 1 year ago

Hi, thank you!

sindresorhus commented 1 year ago

Maybe also mention in the readme that it can be used in the browser with xterm.js

countfak commented 1 year ago

You're great, thanks.