lukeed / tsm

TypeScript Module Loader
MIT License
1.18k stars 19 forks source link

Upgrade `esbuild` for const type parameters? #48

Open karlhorky opened 1 year ago

karlhorky commented 1 year ago

Hey @lukeed πŸ‘‹ hope you're well!

It seems that esbuild@0.17.14 added support for TS 5.0 const type parameters

Currently, tsm@2.3.0 depends on esbuild@^0.15.16, and runs into errors like Expected identifier but found "const":

✘ [ERROR] Expected identifier but found "const"

    /Users/k/p/project/index.ts:29:40:
      29 β”‚ export async function getProjectFixture<const Fixture extends { id: number }>(
         β•΅                                         ~~~~~

/Users/k/p/project/node_modules/tsm/node_modules/esbuild/lib/main.js:1575
  let error = new Error(`${text}${summary}`);
              ^

Error: Transform failed with 1 error:
/Users/k/p/project/index.ts:29:40: ERROR: Expected identifier but found "const"
    at failureErrorWithLog (/Users/k/p/project/node_modules/tsm/node_modules/esbuild/lib/main.js:1575:15)
    at /Users/k/p/project/node_modules/tsm/node_modules/esbuild/lib/main.js:814:29
    at responseCallbacks.<computed> (/Users/k/p/project/node_modules/tsm/node_modules/esbuild/lib/main.js:680:9)
    at handleIncomingPacket (/Users/k/p/project/node_modules/tsm/node_modules/esbuild/lib/main.js:735:9)
    at Socket.readFromStdout (/Users/k/p/project/node_modules/tsm/node_modules/esbuild/lib/main.js:656:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Proposed Solution

What do you think about upgrading to esbuild@^0.18.6?

Seems like forcing the upgrade to the transitive esbuild dependency via Yarn Resolutions works in our project and enables the const type parameters πŸ‘

karlhorky commented 1 year ago

Workaround

To upgrade tsm's transitive dependency esbuild@^0.15.16 to something newer, you can try using Yarn Resolutions like in the example below (or modify the example below for pnpm Overrides or npm Overrides):

package.json

{
  "resolutions": {
    "esbuild": "0.18.6"
  }
}
lukeed commented 1 year ago

Hi there, thanks :)

I wanted to cut a new major release today to include this (because of esbuild breaking changes), but I think that it should include support for Node 20.x (#46) which will probably also include some breaking changes. (Thanks Node team)

Please stick with the workaround for now :/ If there's no likely progress on Node-side with the process.argv issue within a few weeks, then I'll cut 3.0 and then another 4.0 once Node has act together.

iliocatallo commented 6 months ago

Hi!

Any news on this side?

Thanks!