sindresorhus / ansi-escapes

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

Failing to compile correctly when built under Vite? #35

Open Rohaq opened 1 year ago

Rohaq commented 1 year ago

process.env calls don't compile under Vite, so it's odd to see it in the compiled code:

From uncompiled index.js

import process from 'node:process';

const ESC = '\u001B[';
const OSC = '\u001B]';
const BEL = '\u0007';
const SEP = ';';

/* global window */
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';

const isTerminalApp = !isBrowser && process.env.TERM_PROGRAM === 'Apple_Terminal';
const isWindows = !isBrowser && process.platform === 'win32';
const cwdFunction = isBrowser ? () => {
    throw new Error('`process.cwd()` only works in Node.js, not the browser.');
} : process.cwd;

const ansiEscapes = {};
// and so on...

Compiled output in browser:

const ESC = '\u001B[';
const OSC = '\u001B]';
const BEL = '\u0007';
const SEP = ';';
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';

const ansiEscapes = {};
// and so on...

I'm guessing that the inBrowser check on line 9 probably isn't suitable for detecting a bundler like Vite

(or perhaps I have something set up wrong...)