privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
8.6k stars 132 forks source link

REPL patch affects scripts #202

Open redstonekasi opened 1 year ago

redstonekasi commented 1 year ago

Bug description

I was trying out making a custom REPL using Node's repl module when I came across this bug that was presumably introduced in #125. When running a file using tsx the patch affects the script that was run.

Screenshot of expected and actual behaviour (repl.ts is the reproduction code below) image

Reproduction

import * as repl from "node:repl";

repl.start({
  eval: (cmd, ctx, file, cb) => cb(null, cmd),
});

Environment

System:
    OS: Linux 6.2 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 9.35 GB / 15.54 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
Binaries:
    Node: 18.14.1 - ~/.local/share/pnpm/node
    npm: 9.3.1 - ~/.local/share/pnpm/npm

Sorry this didn't run correctly on my system because I use pnpm, here's `tsx -v` instead:
> tsx -v
tsx v3.12.3
node v18.14.1

Can you work on a fix?

privatenumber commented 1 year ago

This will mainly be fixed via https://github.com/esbuild-kit/tsx/pull/205

Currently, it seems the patch affects custom REPL instances. Do you think it's expected for them to get TypeScript when executed with tsx?

I'm thinking not, and that the patch should only be applied to the Node.js REPL.

redstonekasi commented 1 year ago

I agree. While REPL instances are probably mainly going to be used for JS, they can also be used for other purposes when defining a custom evaluation function, which is why the patch should only be applied to the Node.js REPL.

redstonekasi commented 1 year ago

Also even ignoring that, there should not be a noticeable difference between running code through tsx and running compiled code using node.

andyfischer commented 1 month ago

I just hit a similar bug using tsx version 4.11.0 .

The bug I'm seeing is that input from the repl is transformed.

If I use a very simple script to see the output:

const repl = require('repl');

repl.start({
    eval: line => {
        console.log('The line was: ' + line);
    }
});

And I try entering input with dashes like: some-command

I'm expecting it to print:

The line was: some-command

What I actually see when running this inside TSX:

The line was: some - command;