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

fix: use file url to import tsx at runtime #1171

Merged
merged 2 commits into from
Aug 21, 2024
Merged

Conversation

mdonnalley
Copy link
Contributor

@mdonnalley mdonnalley commented Aug 19, 2024

  • Use file url to import tsx at runtime
  • debug errors caused by importing ts-node and/or tsx

QA

  • create new ESM cli on windows: oclif generate my-cli --yes
  • install tsx globally: npm install -g tsx
  • add tsx to my-cli: npm install --save-dev tsx
  • remove ts-node from my-cli: npm uninstall ts-node
  • update shebang in dev.js to #!/usr/bin/env -S npx tsx --no-warnings
  • update dev.cmd to use npx tsx instead of node --loader ts-node/esm --no-warnings=ExperimentalWarning
  • delete the dist directory
  • set DEBUG=*
  • run bin\dev.cmd hello world

The command should successfully run and the logs should indicate that tsx did not fail to be imported:

  oclif:config:ts-path registering tsx at C:\Users\username\code\tsx-bug-esm +7ms
  oclif:config:ts-path tsx path: C:\Users\username\code\tsx-bug-esm\node_modules\tsx\dist\esm\api\index.cjs +8ms
  oclif:config:ts-path Successfully imported tsx +0ms

It's probably worth repeating these steps on mac or linux too

Fixes #1170
@W-16530475@

@acerbisgianluca
Copy link

acerbisgianluca commented Aug 20, 2024

Hey @mdonnalley, thanks for the quick fix!

One note, since we're on Windows, in point 5 of the QA steps the tester should change the command in ./bin/dev.cmd as well in order to run tsx instead of ts-node, right?

Btw I found out why it wasn't loading the commands from the src folder. I mistakenly removed rootDir from the tsconfig, so it wasn't looking for commands in the src folder.

@mdonnalley
Copy link
Contributor Author

One note, since we're on Windows, in point 5 of the QA steps the tester should change the command in ./bin/dev.cmd as well in order to run tsx instead of ts-node, right?

Good catch. I've updated the description

Copy link

@acerbisgianluca acerbisgianluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested following the QA steps and it loads tsx correctly now.

@cristiand391
Copy link
Member

QA notes:

✅ macos: still works, can see tsx being registered in debug logs
also changed the apiPath on purpose and can see the error being logged

✅ windows

before

can't load tsx, throws Error: command hellow:world not found

Screenshot 2024-08-21 at 10 42 07 AM

Screenshot 2024-08-21 at 10 42 23 AM

after

ls dist shows no build, tsx is loaded and transpile command

Thanks @acerbisgianluca for the double check!
Screenshot 2024-08-21 at 10 45 56 AM

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 this pull request may close these issues.

tsx isn't being register correctly on Windows
3 participants