Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with TypeScript v5 (author's note) #93

Closed
nonara opened this issue Mar 16, 2023 · 53 comments · Fixed by #96
Closed

Not working with TypeScript v5 (author's note) #93

nonara opened this issue Mar 16, 2023 · 53 comments · Fixed by #96

Comments

@nonara
Copy link
Owner

nonara commented Mar 16, 2023

Update

Beta version is out! See the message below for detail:

@nonara nonara pinned this issue Mar 16, 2023
@moshest
Copy link

moshest commented Mar 19, 2023

Thank you for all the effort you put on this.

I just want to raise a point that waiting until the end of April can be too much of a delay for some projects (mine in particular). Given the fact that the beta was released 2 months ago the current situation isn't promising and it may push users to seek for other solutions (including myself).

There is any way we can speed up the migration? 🙏
Can we at least share what's the progress being done and what's still missing?

@nonara
Copy link
Owner Author

nonara commented Mar 19, 2023

@moshest

A few points...

  1. This is FOSS. In the years this and my other large libraries have been active, I believe $75 in total has been donated from users.

  2. I run a company, work 6 days per week, and generally work over 40hrs per week.

  3. I will be surrendering significant revenue and time to get this done. As of the last few months, I simply (and literally) could not do this, for reasons which are personal.

Notably, I also had three people who claimed to be willing to help lined up months ago, and all backed out.

I say this with personal respect, but also with the due response to such a message - if you'd like to take your "business" elsewhere, you're more than welcome to do so. However, at present, this is a problem that is not yet solved and is, as I've said, non-trivial.

Lastly, I also think this is important to point out -

If this was an issue that prevented current libraries from working, that is one thing, but rewriting everything to support a new major version is another. The latter is nice to have early, but the worst case scenario is you wait an additional month to use the latest features. It's not ideal, but it may happen from time to time.

Demanding a maintainer work more quickly for free so that you can use the newest features is precisely the sort of thing that I've seen embitter and contribute to the burnout of so many formerly enthusiastic maintainers.

Frankly, I've always tried and have succeeded in keeping up with the changes in the past, but I simply couldn't do it this cycle, because of the extent of changes and personal situations which demanded beyond even normal working hours.

I say this in the hope that you will more carefully consider your tone and demands in the future in this regard.

Lastly, if you'd like a temporary (or permanent) solution, I can suggest writing a script which uses the compiler API, which will allow you to use transformers.

@moshest
Copy link

moshest commented Mar 19, 2023

Hi @nonara,

Thank you for the detailed response. As an open-source contributor and library maintainer I know exactly how you feel.

I never meant to ask you to "work faster" and I apologize for the misunderstanding. Please note I asked how can "we" release it faster.

My main feedback is that it's not clear what needed to be done in order to support version 5, nor a clear tasks or milestones that can help a community member such myself to hop on and contribute a few hours on the weekend.

@nonara
Copy link
Owner Author

nonara commented Mar 19, 2023

@moshest I appreciate that. Neuledge looks nice, btw!

Unfortunately, this may be a complicated problem. I believe I have an approach worked out, though it's a bit in depth as well.

There's a chance we can do it more simply, similar to how we have been. The MSFT engineer who made the changes isn't sure it will be that easy.

One quick thing that would help to investigate that angle — if you want to see if you can get TS v5 to build without tree shaking and send me the compiled typescript.js and tsc.js files, I will be able to take a look and see if the simple approach will work.

I do have one other person who's interested in helping with support and the rewrite. If you're interested, I can send a slack invite.

@AlCalzone
Copy link

If you're interested, I can send a slack invite.

You can send me one. I'm relying heavily on ts-patch and should be able to spare some time to help out.

@moshest
Copy link

moshest commented Mar 21, 2023

@nonara I think I manage to build Typescript without tree shaking but the differences aren't big so maybe I only manage to do so partially:

  • tsc.js - 5.7MB instead of 5.8MB
  • typescript.js - same size 8.2MB

What I did is update the file Herebyfile.mjs:

+ treeShaking: false,
- treeShaking: taskOptions.treeShaking,

And built it using the command:

npm run build:compiler

I hope it helps.

@nonara
Copy link
Owner Author

nonara commented Mar 21, 2023

@moshest Thank you. I sent you a slack invite if you'd like to join. @AlCalzone built it with shaking disabled and sent the files on slack.

Good news — I managed to get it to augment the new tsc. It runs properly and seem to be good. We need to test to be sure. Next steps are easier. Feel free to accept the invite and join in.

@sunrabbit123
Copy link

How long until ts-patch supports V5? If it's still a ways off, I would like to contribute as well.

Could you share the code blocks for the tests that need to pass and the work that needs to be done?

In ttsc, we hacked createProgram.

@nonara
Copy link
Owner Author

nonara commented Mar 23, 2023

How long until ts-patch supports V5? If it's still a ways off, I would like to contribute as well.

Thank you. It's almost there. We've overcome the large hurdle. Will update in this thread shortly.

@nonara
Copy link
Owner Author

nonara commented Mar 29, 2023

Hi all. I've updated the body of the original post with the latest update. We're close to release.

@TankOs
Copy link

TankOs commented Apr 6, 2023

@nonara I really don't want to bug you, but any info on the release? We're currently thinking about downgrading from TS 5 to 4, or just waiting for a couple of days until your new release hits the road. 🙂

@nonara
Copy link
Owner Author

nonara commented Apr 6, 2023

@TankOs I appreciate that! I know everyone is ready, and I'm with you on that. I finished everything for the beta last night, and I'm working on some high level e2e tests right now so I can push out a beta. Shooting for today, but it definitely won't be long now.

@nonara
Copy link
Owner Author

nonara commented Apr 8, 2023

Hi all. We have a beta ready that works for both ts-patch and ttypescript projects! 🔥

I'd really appreciate you trying it out and letting me know if it works for you.

For now, you can use yarn add -D ts-patch@v3-beta. I will keep that tag up to date with the latest beta

  • If it works in your ts-patch based project, please leave a 🚀 emoji on this message
  • If it works in your ttypescript based project, please leave a 🎉 emoji
  • If anything doesn't work, please leave a comment

Please note that this is an early release, intended to get everyone going. Everything should work, but I will be doing some more tuning and adding more comprehensive tests over the coming days.

Thank you for helping to beta test!

ttypescript migration

If you want to try with a ttypescript project, you can use:

  • tspc to compile (instead of ttsc)
  • { 'compiler': 'ts-patch/compiler' } in a config (instead of { 'compiler': 'ttypescript' })

Or with ts-node, etc. via cli arg:

--compiler ts-patch/compiler

Helping out

If anyone would like to help build tests, please leave a comment on the v3-beta PR. I'm planning to organize how to approach those next week and would appreciate any help available.

@jakebailey
Copy link

Oh wow, to be clear, this branch is taking the same approach as prettier and using the // src/compiler/... comments as a region marker to try and apply patches? Hope we never move anything, or stop using esbuild... I almost guaranteet that the order of these modules in the output bundle is going to change in TS 5.1 just through refactors, not to mention that I am hoping to use ESM for our executables (like tsc.js), which will end up looking quite different.

Have you considered taking yarn's approach to patching, and instead fork TS, make the changes in-tree, then diff the output packages to produce a patch? I feel like that would end up safer... and also maybe provide a baseline for a PR into TS itself if we want to eventually accept plugins upstream.

@nonara
Copy link
Owner Author

nonara commented Apr 10, 2023

@jakebailey Hey Jake! Thanks for taking a look. I'm going to respond in the v3 thread, so we can discuss there:

@samchon
Copy link
Contributor

samchon commented Apr 11, 2023

When try to run on ts-node using -C ts-patch argument, such error occurs.

Same error be occured even when loading ts-node in JS file like below:

const runner = require("ts-node");

runner.register({
    project: __dirname + "/tsconfig.issue.json",
    compiler: "ts-patch",
});
require(`./issues/${process.argv[2]}.ts`);
D:\github\samchon\typia\node_modules\ts-node\dist\configuration.js:91
    const { fileExists = ts.sys.fileExists, readFile = ts.sys.readFile, skipProject = index_1.DEFAULTS.skipProject, project = index_1.DEFAULTS.project, tsTrace = index_1.DEFAULTS.tsTrace, } = rawApiOptions;
                                ^

TypeError: Cannot read properties of undefined (reading 'fileExists')
    at readConfig (D:\github\samchon\typia\node_modules\ts-node\dist\configuration.js:91:33)
    at findAndReadConfig (D:\github\samchon\typia\node_modules\ts-node\dist\configuration.js:50:84)
    at create (D:\github\samchon\typia\node_modules\ts-node\dist\index.js:146:69)
    at Object.register (D:\github\samchon\typia\node_modules\ts-node\dist\index.js:127:19)
    at Object.<anonymous> (D:\github\samchon\typia\test\issue.js:6:8)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

samchon added a commit to samchon/ts-patch-bug-report-93 that referenced this issue Apr 11, 2023
@samchon
Copy link
Contributor

samchon commented Apr 11, 2023

https://github.com/samchon/ts-patch-bug-report-93

git clone https://github.com/samchon/ts-patch-bug-report-93
cd ts-patch-bug-report-93
npm install
npm run build
npm run start

@nonara, you can reproduce the bug from above repo and commands.

@hi-zhaolei
Copy link

hi-zhaolei commented Apr 13, 2023

@nonara Hi. I just now replaced ttypescript with this beta version to solve the previous problem. It works.
but see another error

image

it seems a syntax error.

@nonara
Copy link
Owner Author

nonara commented Apr 13, 2023

@hi-zhaolei Thanks for the report. We just discovered the same issue. That happens with lower Node versions, like Node 14. We'll be publishing a fix in a few hours.

@yf-yang
Copy link

yf-yang commented Apr 14, 2023

Hello, I am using [email protected] with ts-patch@v3-beta, but the transformer typescript-transform-paths is not working correctly. Not sure which part fails, but I see you are the maintainer of both projects. Would you please take a look? Thanks 😄

https://github.com/yf-yang/ts-patch-not-working

@yf-yang
Copy link

yf-yang commented Apr 14, 2023

Hello, I am using [email protected] with ts-patch@v3-beta, but the transformer typescript-transform-paths is not working correctly. Not sure which part fails, but I see you are the maintainer of both projects. Would you please take a look? Thanks 😄

https://github.com/yf-yang/ts-patch-not-working

I'm sorry, that is my own fault, I didn't add "afterDeclarations": true. Thanks for your attention!

@samchon
Copy link
Contributor

samchon commented Apr 14, 2023

@nonara When can I download regular v3?

If there're som problem in tspc, I think it would better to publish only ts-patch install first and tspc later.

@MeirionHughes
Copy link

MeirionHughes commented Apr 14, 2023

Cannot read properties of undefined (reading 'fileExists')

Same happens when using env cross-env TS_NODE_COMPILER=ts-patch ... as well as ts-node --compiler ts-patch ...

node -v = 16.17.0

@robert-w-gries
Copy link

Hi @nonara it appears I got booted out of the Slack channel due to not having Slack pro (it's unclear why I needed Pro to stay in the channel), so I'd like to check in and see what the v3 changes will entail.

I saw your comment here and was interested in this part in particular:

The short version is, you'll be able to bundle language service plugins and transformers in addition to two new features, which are middleware "hooks" and compiler transformers. The latter are applied at patch time on the compiler code itself. This should open up some unique opportunities, which I'm excited to explore.

Is there anything in v3 that I can experiment with in terms of these middleware hooks? Or is that a future, planned feature?

Either way I'll test the v3 branch, hopefully tomorrow, to help out with the release. Thanks for all your work!

@frankie303
Copy link

for those who try to install it: yarn add -D ts-patch@v3-beta --> yarn add -D [email protected]

@CarsonF

This comment was marked as resolved.

@donflopez
Copy link

It'd be awesome if ts directly supported this feature or facilitated this libs work, have you seen this?

microsoft/TypeScript#52953

@mindplay-dk
Copy link

It'd be awesome if ts directly supported this feature or facilitated this libs work, have you seen this?

microsoft/TypeScript#52953

Someone is now taking the initiative and pushing for this feature:

microsoft/TypeScript#54278

@nonara would you care to stop by and see what they're doing? 🙂

@samchon
Copy link
Contributor

samchon commented May 17, 2023

@mindplay-dk Unfortunately, transform API of TS 5.2 does not support full spec of TypeScript.

For an example, you can't get detailed type info, due to TS 5.2 transform API does not support it. Most of properties and methods in ts.Node are removed. Also, no more you can get the ts.Type info from TS 5.2 transform API. I asked why, but be answered for performance reason.

Therefore, if such diet policy being kept, I think ts-patch is still required.

@jakebailey
Copy link

jakebailey commented May 17, 2023

@samchon I am utterly confused by your description of the situation. Yes, tsc has fewer helpers included, but it's preposterous to state that tsc "does not support the full spec of TypeScript".

Your continued misrepresentation of the way TypeScript works is extremely frustrating; I don't even know why I'm even bothering.

@samchon
Copy link
Contributor

samchon commented May 17, 2023

@samchon I am utterly confused by your description of the situation. Yes, tsc has fewer helpers included, but it's preposterous to state that tsc "does not support the full spec of TypeScript".

Your continued misrepresentation of the way TypeScript works is extremely frustrating; I don't even know why I'm even bothering.

microsoft/TypeScript#54276 (comment)

This is my answer. Sorry for bothering you, but it is a break and critical change for 3rd party libraries.

@sinclairzx81
Copy link

@samchon This workbench thing is implemented without any 3rd party libraries at all. Of the functions you've listed on microsoft/TypeScript#54276 (comment) as missing, most of them are provided as default exports on the compiler API (and there's enough there to generate runtime assertion logic)

@samchon
Copy link
Contributor

samchon commented May 17, 2023

@samchon This workbench thing is implemented without any 3rd party libraries at all. Of the functions you've listed on microsoft/TypeScript#54276 (comment) as missing, most of them are provided as default exports on the compiler API (and there's enough there to generate runtime assertion logic)

Thanks for reference. It is time to study for me.

@samchon
Copy link
Contributor

samchon commented May 17, 2023

@nonara
Copy link
Owner Author

nonara commented May 17, 2023

Hi all,

To answer the question — I did see the proposal. You can see my responses on that thread, starting with this one:

@mgabeler-lee-6rs
Copy link

Running into this error trying to convert from ttypescript to [email protected] (or beta3, same error either way):

evalmachine.<anonymous>:370
                            throw error;
                            ^

RangeError: Maximum call stack size exceeded
    at Object.<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:10:23)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Module.requireCjs (evalmachine.<anonymous>:377:35)
    at Module.require (evalmachine.<anonymous>:363:75)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8:17)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Module.requireCjs (evalmachine.<anonymous>:377:35)
    at Module.require (evalmachine.<anonymous>:363:75)
    at require (node:internal/modules/cjs/helpers:108:18)

This sadly is a re-throw losing the original stack trace. After some trial & error, I was able to observer more or less what the underlying call stack is. This is from before it crashes, but you can see the loop:

nasty long stack trace
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:10)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:16)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:16)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:16)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:16)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:16)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/asyncify.js:16)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/wrapAsync.js:8)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/internal/eachOfLimit.js:19)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/eachOfLimit.js:7)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/eachOf.js:15)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/async/forEach.js:7)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/winston/lib/winston/logger.js:11)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/winston/lib/winston/create-logger.js:12)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/winston/lib/winston.js:42)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
7773 (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
r (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
8674 (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
r (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
5090 (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
r (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
7124 (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
r (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
5831 (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
r (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
5250 (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
r (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
2698 (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
r (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected][email protected]/node_modules/ts-auto-mock/transformer/index.js:1)
Module._compile (internal/modules/cjs/loader:1196)
requireCjs (<node_internals>/evalmachine.<anonymous>:377)
Module.require (<node_internals>/evalmachine.<anonymous>:363)
require (internal/modules/cjs/helpers:108)
resolveFactory (<node_internals>/evalmachine.<anonymous>:312)
createTransformers (<node_internals>/evalmachine.<anonymous>:172)
newEmit (<node_internals>/evalmachine.<anonymous>:102)
computeDtsSignature (<node_internals>/evalmachine.<anonymous>:119455)
updateShapeSignature (<node_internals>/evalmachine.<anonymous>:119485)
getFilesAffectedByWithOldState (<node_internals>/evalmachine.<anonymous>:119443)
getNextAffectedFile (<node_internals>/evalmachine.<anonymous>:119897)
getSemanticDiagnosticsOfNextAffectedFile (<node_internals>/evalmachine.<anonymous>:120653)
getSemanticDiagnostics (<node_internals>/evalmachine.<anonymous>:120689)
emitFilesAndReportErrors (<node_internals>/evalmachine.<anonymous>:122075)
emitFilesAndReportErrorsAndGetExitStatus (<node_internals>/evalmachine.<anonymous>:122106)
performIncrementalCompilation (<node_internals>/evalmachine.<anonymous>:122262)
performIncrementalCompilation2 (<node_internals>/evalmachine.<anonymous>:170589)
executeCommandLineWorker (<node_internals>/evalmachine.<anonymous>:170366)
executeCommandLine (<node_internals>/evalmachine.<anonymous>:170456)
tsp.execTsc (<node_internals>/evalmachine.<anonymous>:170978)
<anonymous> (<node_internals>/evalmachine.<anonymous>:170982)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/ts-patch/compiler/tsc.js:19)
Module._compile (internal/modules/cjs/loader:1196)
Module._extensions..js (internal/modules/cjs/loader:1250)
Module.load (internal/modules/cjs/loader:1074)
Module._load (internal/modules/cjs/loader:909)
Module.require (internal/modules/cjs/loader:1098)
require (internal/modules/cjs/helpers:108)
<anonymous> (CENSORED/common/temp/node_modules/.pnpm/[email protected]/node_modules/ts-patch/bin/tspc.js:9)
Module._compile (internal/modules/cjs/loader:1196)
Module._extensions..js (internal/modules/cjs/loader:1250)
Module.load (internal/modules/cjs/loader:1074)
Module._load (internal/modules/cjs/loader:909)
executeUserEntryPoint (internal/modules/run_main:81)
<anonymous> (internal/main/run_main_module:22)

The trace above is from my "real" app, but I can reproduce the same problem with this minimal setup:

reproducer files

tsconfig.json:

{
  "compilerOptions": {
    "allowUnreachableCode": false,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noImplicitReturns": true,
    "preserveConstEnums": true,
    "removeComments": false,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "declarationMap": true,
    "strict": true,
    "target": "es2021",
    "types": ["node"],
    "lib": ["es2021"],

    "rootDir": ".",
    "outDir": "dist",
    "plugins": [{ "transform": "ts-auto-mock/transformer" }]
  }
}

package.json:

{
  "dependencies": {
    "@types/async": "^3.2.20",
    "@types/node": "^14",
    "async": "^3.2.4",
    "ts-auto-mock": "^3.7.0",
    "ts-patch": "3.0.0-rc2",
    "typescript": "~5.0.4"
  }
}

index.ts:

import { createMock } from 'ts-auto-mock';

interface X {
        x(): void;
}

const mockX = createMock<X>();

@robert-w-gries
Copy link

robert-w-gries commented May 20, 2023

Hi, I've finally gotten some time to work on my project using ts-patch, and rc2 looks to work perfectly when running patched tsc.

However, I ran into an issue with patched tsserver where the transformer runs as expected, but the patched host code does not seem to be executed. I've confirmed that the transformer runs as expected in VS Code by adding a console.log here:

export default function programTransformer(
    program: Program,
    host: CompilerHost | undefined,
    config: PluginConfig,
    { ts: tsInstance }: ProgramTransformerExtras,
  ): Program {
    const compilerOptions = program.getCompilerOptions();
    const compilerHost = getPatchedHost(host, tsInstance, compilerOptions);
    const rootFileNames = program.getRootFileNames().map(tsInstance.normalizePath);
    console.log("CREATING PROGRAM")
    return tsInstance.createProgram(rootFileNames, compilerOptions, compilerHost);
};

However, I've added console logs inside the return of the getPatchedHost object, and it doesn't seem like the patched host object is used in tsserver.

Here is my settings.json:

  {
    "typescript.tsdk": "./node_modules/typescript/lib",
    "typescript.tsserver.log": "verbose", // to debug, set to "verbose"
    "typescript.enablePromptUseWorkspaceTsdk": true
  }

I have verified the patch is installed for all js files:

$ ./node_modules/.bin/ts-patch check
Checking TypeScript v5.0.4 installation in $PROJECT\demo\node_modules\typescript

[+] tsc.js is patched with ts-patch version 3.0.0-rc2 
[+] tsserver.js is patched with ts-patch version 3.0.0-rc2
[+] tsserverlibrary.js is patched with ts-patch version 3.0.0-rc2 
[+] typescript.js is patched with ts-patch version 3.0.0-rc2 

If needed, I can add more details about my project's weird use of ts-patch in the slack as I don't want to derail this issue.

@jeka2100
Copy link

Hello, I migrating from ttypescript:

  1. install ts-patch@v3-beta
  2. Run "tspc --build"

And has error:
<--- Last few GCs --->

[70676:0x7fc848008000] 49489 ms: Scavenge (reduce) 4078.7 (4102.0) -> 4078.5 (4102.5) MB, 2.8 / 0.0 ms (average mu = 0.253, current mu = 0.145) allocation failure
[70676:0x7fc848008000] 50861 ms: Mark-sweep (reduce) 4095.1 (4118.2) -> 4092.3 (4118.4) MB, 1251.9 / 0.0 ms (+ 2.3 ms in 1 steps since start of marking, biggest step 2.3 ms, walltime since start of marking 1260 ms) (average mu = 0.176, current mu = 0.

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0x10f2193a5 node::Abort() (.cold.1) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
2: 0x10def4869 node::Abort() [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
3: 0x10def49df node::OnFatalError(char const*, char const*) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
4: 0x10e073347 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
5: 0x10e0732e3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
6: 0x10e2322e5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
7: 0x10e230d06 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
8: 0x10e23d240 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
9: 0x10e23d2c1 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
10: 0x10e202b9e v8::internal::FactoryBasev8::internal::Factory::NewWeakFixedArrayWithMap(v8::internal::Map, int, v8::internal::AllocationType) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
11: 0x10e133c8c v8::internal::Handlev8::internal::SharedFunctionInfo v8::internal::(anonymous namespace)::CreateTopLevelSharedFunctionInfov8::internal::Isolate(v8::internal::ParseInfo*, v8::internal::Handlev8::internal::Script, v8::internal::Isolate*) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
12: 0x10e13053b v8::internal::(anonymous namespace)::CompileToplevel(v8::internal::ParseInfo*, v8::internal::Handlev8::internal::Script, v8::internal::MaybeHandlev8::internal::ScopeInfo, v8::internal::Isolate*, v8::internal::IsCompiledScope*) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
13: 0x10e132f1a v8::internal::Compiler::GetWrappedFunction(v8::internal::Handlev8::internal::String, v8::internal::Handlev8::internal::FixedArray, v8::internal::Handlev8::internal::Context, v8::internal::Compiler::ScriptDetails const&, v8::ScriptOriginOptions, v8::internal::ScriptData*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
14: 0x10e07ddf7 v8::ScriptCompiler::CompileFunctionInContext(v8::Localv8::Context, v8::ScriptCompiler::Source*, unsigned long, v8::Localv8::String, unsigned long, v8::Localv8::Object, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason, v8::Localv8::ScriptOrModule) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
15: 0x10dee695b node::contextify::ContextifyContext::CompileFunction(v8::FunctionCallbackInfov8::Value const&) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
16: 0x10e0db54e v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
17: 0x10e0dac46 v8::internal::MaybeHandlev8::internal::Object v8::internal::(anonymous namespace)::HandleApiCallHelper(v8::internal::Isolate
, v8::internal::Handlev8::internal::HeapObject, v8::internal::Handlev8::internal::HeapObject, v8::internal::Handlev8::internal::FunctionTemplateInfo, v8::internal::Handlev8::internal::Object, v8::internal::BuiltinArguments) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
18: 0x10e0da39f v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
19: 0x10e95b3d9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/user/.nvm/versions/node/v16.9.1/bin/node]
sh: line 1: 70676 Abort trap: 6 tspc

Repository owner deleted a comment from AlCalzone May 25, 2023
Repository owner deleted a comment from AlCalzone May 25, 2023
@nonara

This comment was marked as outdated.

@samchon
Copy link
Contributor

samchon commented May 26, 2023

@nonara Works on beta3, but fallen into infinite error loop on rc3

When you clone and try to build my project typia, you can see that below error message be repeated infinitey.

Also, until beta3 version (including previous versions like [email protected]), it was possible to configuring ts transformer file directly, therefore it made trasformer library development conveniently. However, since rc3 update, using ts transformer file became impossible.

{
  "compilerOptions": {
    "plugins": [
      { "transform": "../src/transform.ts" } // possible until beta3, but impossible since rc3
      { "transform": "../lib/trasnform.js" } // therefore, must target to compiled JS fil
    ]
  }
}

Reproduce

git clone https://github.com/samchon/typia -b features/ts-patch-3.0.0-rc3
cd typia
npm install
npm run build
npm run build:test

Error Message

Error
    at tspWrappedFactory (/home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:348:33)
    at /home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:10[9](https://github.com/samchon/typia/actions/runs/5087037428/jobs/9142042595#step:7:10)318:33
    at /home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:[10](https://github.com/samchon/typia/actions/runs/5087037428/jobs/9142042595#step:7:11)9405:61
    at Array.map (<anonymous>)
    at transformNodes (/home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:109405:50)
    at emitJsFileOrBundle (/home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:[11](https://github.com/samchon/typia/actions/runs/5087037428/jobs/9142042595#step:7:12)0003:26)
    at emitSourceFileOrBundle (/home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:109938:7)
    at forEachEmittedFile (/home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:109692:26)
    at emitFiles (/home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:1099[12](https://github.com/samchon/typia/actions/runs/5087037428/jobs/9142042595#step:7:13):5)
    at emitWorker (/home/runner/work/typia/typia/node_modules/typescript/lib/tsc.js:117[15](https://github.com/samchon/typia/actions/runs/5087037428/jobs/9142042595#step:7:16)2:30)

@nonara
Copy link
Owner Author

nonara commented May 26, 2023

@samchon Thanks for trying it out and for your report! The rc does support ts transformers, but your case brought some edge cases to light.

One of the more ambitious aspects of the new version is replacing need for ts-node, by doing ts compilation natively. Looks like I need to cover more edge cases in the require hook to cover implicit extensions, etc.

I'm going to look closer at what ts-node is doing for the require hook, and hopefully I'll have it sorted in the next day or two.

@AlCalzone
Copy link

@nonara I'm getting the same too, but that just looks like you forgot to remove debug logging from the finally here:

} finally {
unhookRequire();
const err = new Error();
console.log(err.stack);
}

@TimUnderhay
Copy link

TimUnderhay commented Jun 4, 2023

Not sure if this helps, @nonara, but the same error is logged many times with Typescript 5.1.3, with both beta3 or rc3. Reverting to TS 5.0.4 makes the errors go away.

    at tspWrappedFactory (evalmachine.<anonymous>:350:33)
    at evalmachine.<anonymous>:110045:33
    at evalmachine.<anonymous>:110132:61
    at Array.map (<anonymous>)
    at transformNodes (evalmachine.<anonymous>:110132:50)
    at emitJsFileOrBundle (evalmachine.<anonymous>:110730:26)
    at emitSourceFileOrBundle (evalmachine.<anonymous>:110665:7)
    at forEachEmittedFile (evalmachine.<anonymous>:110419:26)
    at emitFiles (evalmachine.<anonymous>:110639:5)
    at emitWorker (evalmachine.<anonymous>:117945:30)

PS Correction, the messages are there with rc3 regardless of TS version. Assuming it's due to the above console.log statement.

@nonara nonara mentioned this issue Jun 13, 2023
Merged
@nonara nonara closed this as completed in cd69c1c Jun 13, 2023
@nonara nonara unpinned this issue Jun 13, 2023
@nonara
Copy link
Owner Author

nonara commented Jun 13, 2023

Finally got the time to sit down with this for a few days and wrap it up. Thank you all for your patience and for helping with testing!

If there are any issues, go ahead and file as a new issue.

@shaulb-sn
Copy link

shaulb-sn commented Oct 15, 2024

Hi, I'm a little late to this party. I'm trying to upgrade my project to TS5, and getting the error described here:

TypeError: Cannot set property createProgram of #<Object> which has only a getter
    at patchCreateProgram (/Users/shaul.behr/src/squall/node_modules/ttypescript/lib/patchCreateProgram.js:84:23)
...

I tried the reccommended fix:

yarn add -D [email protected]

and it appears to make no difference at all; ttsc -b src still coughs up the same compiler error.
Did I miss a trick somewhere?

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 a pull request may close this issue.