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

Add prompts to ask user about installing additional but required packages #653

Closed

Conversation

dawiidio
Copy link

It's just a small change but can improve flow while using cli.

When using devs devtools src/main.ts with "native" OS transports (eg: usb or serial - not via dashboard and WebUSB) user must specify transport by passing one of the following options

-u, --usb             listen to Jacdac over USB (requires usb)
-s, --serial          listen to Jacdac over SERIAL (requires serialport)
-i, --spi             listen to Jacdac over SPI (requires rpio, experimental)

all the above options require additional packages, that's why now you can install required package without leaving current process. Cli will detect if any of native transports is enabled and if required package is not installed will prompt question like the below one:

...
Install package "serialport" (Y/n)?
Installing package "serialport" ...
Package "serialport" installed!
...

after installation normal process flow will be restored with installed dependencies ready to use.

@dawiidio
Copy link
Author

@microsoft-github-policy-service agree

let resolve: () => void
let reject: () => void

const installProcess = spawn('npm', ['install', '--save', '--no-workspaces', packageName], {
Copy link
Member

Choose a reason for hiding this comment

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

I think we have some code to detect users that rely on yarn

Copy link
Author

@dawiidio dawiidio Oct 29, 2023

Choose a reason for hiding this comment

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

sure, detection added in this commit d806288 and small refactor to use the same function in this commit 11cd434

@@ -573,7 +591,7 @@ async function buildOnce(file: string, options: BuildOptions) {
.forEach(fn => {
log(` ${fn.name} (${prettySize(fn.size)})`)
fn.users.forEach(user =>
debug(` <-- ${resolver.posToString(user[0])}`)
debug(` <-- ${resolver.posToString(user[0])}`),
Copy link
Member

Choose a reason for hiding this comment

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

is this , added by prettier? it kind of add noise to the PR

Copy link
Author

Choose a reason for hiding this comment

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

yeah, must be prettier. Do you want to remove it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in general this kind of formatting changes really add noise to a PR and makes the review harder. If you have user settings overriding the repo .prettierrc file, you should disable them.

function createSPI() {
log(`adding SPI transport (requires "rpio" package)`)
async function createSPI() {
await askForPackageInstallation('rpio');
Copy link
Member

Choose a reason for hiding this comment

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

We need a non-interactive mode in CI build mode.

Copy link
Author

Choose a reason for hiding this comment

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

Good point! Flag added globally to the cli in this commit ddf9c15

@pelikhan
Copy link
Member

This is a great start! My advice is to keep you PRs very focused on a single feature. If you find a bug along the way, move it out to a different PR so that it can be merged separately.

The formatting issue is annoying (the added ,) maybe we can fix this before this PR so that it is "just a formatting PR".

A few more comments:

  • when the native package is missing and the cli is in vscode mode, we should send a side channel message to vscode so that the install flow is gone through vscode UI (future PR)
  • need a flag to disable all interactions behavior for CI scenarios

👍 keep going!

@dawiidio
Copy link
Author

@pelikhan

when the native package is missing and the cli is in vscode mode, we should send a side channel message to vscode so that the install flow is gone through vscode UI (future PR)

sure, I can add this communication in next pr. Maybe you know, when cli is in vscode mode it opens some additional socket channel to communicate with plugin?

@pelikhan
Copy link
Member

@pelikhan

when the native package is missing and the cli is in vscode mode, we should send a side channel message to vscode so that the install flow is gone through vscode UI (future PR)

sure, I can add this communication in next pr. Maybe you know, when cli is in vscode mode it opens some additional socket channel to communicate with plugin?

Search for export function sendEvent<T extends SideEvent>( to see how to send an event from the CLI, and subSideEvent<SideOutputEvent> to receive that even on the vscode side

@pelikhan
Copy link
Member

I've added a common linting task in package.json and also a dep on prettier so that we run the same version. You should be able to merge origin/main and it'll fix the whitespace/comma changes.

_ => null
)
if (prelude[fn] != ex) await writeFile(fnpath, prelude[fn])
if (!existsSync(libpath))
Copy link
Member

Choose a reason for hiding this comment

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

don't sneak in unrelated changes.

cli/src/build.ts Outdated
const converter = converters()[lang]
let constants = ""
for (const srv of customServices) {
constants += converter(srv) + "\n"
}
const dir = join(pref, GENDIR, lang)
await mkdirp(dir)
return writeFile(join(dir, `constants.${lang}`), constants, {
if (!existsSync(dir))
Copy link
Member

Choose a reason for hiding this comment

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

unrelated changes, move to differfent PR

encoding: "utf-8",
})
}))
// json specs
{
const dir = join(pref, GENDIR)
await mkdirp(dir)
if (!existsSync(dir))
Copy link
Member

Choose a reason for hiding this comment

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

unrelated changes, move to different PR

@@ -430,6 +430,8 @@ async function rebuild(args: BuildReqArgs) {
opts.verify = false
opts.quiet = true

await compileFile(args.filename, opts);
Copy link
Member

Choose a reason for hiding this comment

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

are we compiling twice now?

@pelikhan pelikhan self-requested a review October 30, 2023 16:13
@pelikhan
Copy link
Member

Merge origin/main, run yarn install and run yarn lint to run prettier

@pelikhan
Copy link
Member

pelikhan commented Nov 2, 2023

@dawiidio i've added a commit (4372a14) to prep for this change. You can squeeze in the interactive piece of your changes in the TODO I left. Might be easier to start a new PR though.

pelikhan added a commit that referenced this pull request Nov 6, 2023
pelikhan added a commit that referenced this pull request Nov 6, 2023
@pelikhan
Copy link
Member

pelikhan commented Nov 6, 2023

Thank you @dawiidio , your PR has made it into #656

@pelikhan pelikhan closed this Nov 6, 2023
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.

2 participants