Skip to content

Improve standalone emulator run cli #146

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

baileyluTCD
Copy link

Recently (in #143), the npm start script gained the ability to have a --image flag passed. I believe this functionality would be quite useful as a standalone packaged program, and hence am in the process of packaging for nix.

To that end, this pull request implements:

  • --help and --version flags for demo/emulator-run.ts to improve the general user experience from the command line.
  • A npm run build:demo script with it's own tsconfig.demo.json for building/running demo scripts as their own programs.

@urish
Copy link
Contributor

urish commented Jun 8, 2025

Thanks for the PR!

Note that there are some formatting issues with the modified code, please run prettier to fix them.

Also, note that we are not married to minimist - alternatives such as Commander.js or meow do stuff like handling --help automatically.

@urish urish added the enhancement New feature or request label Jun 8, 2025
@baileyluTCD baileyluTCD force-pushed the improve-standalone-emulator-run-cli branch from 8a6c19c to 8a4074e Compare June 8, 2025 20:05
@baileyluTCD
Copy link
Author

Note that there are some formatting issues with the modified code, please run prettier to fix them.

Should be fixed now, prettier did not support the with { type: "json" } addendum for imports hence I removed it.

Also, note that we are not married to minimist - alternatives such as Commander.js or meow do stuff like handling --help automatically.

In light of this I switched over to sade which does have automatic handling of --help and --version and as a bonus actually a smaller bundle size than minimist did.

Additionally you should note that if the original tsconfig.json and build scripts are modified a bit you could support npx rp2040js with the bin field of the package.json with very little effort, I'm happy to implement this here too if desired to make it easier for others to use directly from npm.

@baileyluTCD
Copy link
Author

I also applied similar changes to the micropython-run file too and did a minor bit of code refactoring

@urish
Copy link
Contributor

urish commented Jun 26, 2025

Thanks for switching, and sorry about the long response times.

Looks like the new version has some issue with --expect-text, causing the tests to fail. Can you please look into it?

@baileyluTCD baileyluTCD force-pushed the improve-standalone-emulator-run-cli branch 8 times, most recently from 7e60ec1 to 8a49c5d Compare June 30, 2025 22:53
@baileyluTCD baileyluTCD force-pushed the improve-standalone-emulator-run-cli branch from 8a49c5d to 3d2f68e Compare June 30, 2025 22:53
@baileyluTCD
Copy link
Author

Thanks for switching, and sorry about the long response times.

No worries, these things happen.

I have corrected the issue with expect-text by using the javascript built in TextDecoder object instead of parsing it manually and it seems to work in CI for every micropython version tested bar the 20210618-v1.16 version, do you have any insight as to why this may happen?

@urish
Copy link
Contributor

urish commented Jul 1, 2025

Thanks! The serial data arrives in chunks, which do not necessarily align with line boundries. So the code needs to keep track of either the current line as it's being received, or the entire text received (could be simpler to implement), in order to make text matching work in all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants