quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Building ”modern” tsc

Open helander opened this issue 2 years ago • 3 comments

Have anyone compiled a ”modern” version of tsc (typescript compiler) with qjsc? The patch file available in the tar mentioned in the documentation does not ”work” with the ”current” typescript package.

helander avatar Mar 27 '23 17:03 helander

tsc

tsc-5.0.3.patch

On macosx

> curl -OL https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz
> tar xf quickjs-2021-03-27.tar.xz && cd quickjs-2021-03-27
> make
> cd ..
> curl -OL https://globalcdn.nuget.org/packages/microsoft.typescript.msbuild.5.0.3.nupkg
> unzip microsoft.typescript.msbuild.5.0.3.nupkg -d tsc
> cd tsc/tools/tsc
> curl -OL https://github.com/bellard/quickjs/files/11146444/tsc-5.0.3.patch
> patch -p0 < tsc-5.0.3.patch && cd -
> ./quickjs-2021-03-27/qjsc -o tsc/tools/tsc/tsc tsc/tools/tsc/tsc.js
> echo 'console.log("hello");' > 1.ts
> ./tsc/tools/tsc/tsc 1.ts
> cat 1.js
console.log("hello");

zeromake avatar Apr 04 '23 11:04 zeromake

Thank you 😃

helander avatar Apr 13 '23 08:04 helander

We could also add to the returned getQuickJSSystem object the following methods:

    return {
      //...
      getWidthOfTerminal() {
        const [width, _height] = os.ttyGetWinSize(1);
        return width;
      },
      writeOutputIsTTY() {
        return os.isatty(1);
      },
      // readFile: function (path, _encoding) { ...
    }

to get the same output color/layout as node

Also, readFile and writeFile shall not fail silently in order for tsc to create intermediate folder when outputing file

      readFile: function (path, _encoding) {
        const f = std.open(path, "r");
        if (!f)return void 0;
        const ret = f.readAsString();
        f.close();
        return ret;
      },
      writeFile: function (path, data, writeByteOrderMark) {
        const f = std.open(path, "w+");
        if (!f)
          throw new Error(`Unable to write ${path}`);
        f.puts(data);
        f.close();
      },

I'll try to upstream the patch so (at least) the qjs --std tsc.js ... could work out of the box

@zeromake is the removal of "use strict"; to be in sloppy mode necessary ?

yne avatar Jul 15 '24 12:07 yne