fix(plugin): close the review's gaps in names, prompts and the generated test

The collision check scanned the whole file as text, so every scaffolded
app refused `core`, `tea` or `module` because they appear inside import
strings. It now reads identifiers from the parse tree.

Typing `npm` at the registry question silently produced a JSR-only
package. An answer that is not offered is now asked again.

The generated test only awaited boot(); it now checks the plugin's token
is in app.graph(), and fails if it is not. engines.node moves to
>=22.18, the first Node that runs `node --test` on .ts unflagged.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-09-24 13:11:55 -05:00
1 parent e4a350fcbf
commit 4358091d07
6 files changed
+163 -29

No files matched your search

+63
View File
@@ -63,6 +63,32 @@ impl<R: BufRead, W: Write> Ask<R, W> {
})
}
/// One of `choices`, each `(key, value)`: the answer may be the key or the
/// value, and Enter takes `default`. Anything else is asked again. Quietly
/// taking the default would turn a typed `npm` into a JSR-only package.
pub fn choice(
&mut self,
question: &str,
choices: &[(&str, &'static str)],
default: &'static str,
flag: &str,
) -> io::Result<&'static str> {
if !self.interactive {
return Ok(default);
}
let keys: Vec<&str> = choices.iter().map(|(k, _)| *k).collect();
loop {
let answer = self.line(question)?.to_lowercase();
if answer.is_empty() {
return Ok(default);
}
if let Some((_, v)) = choices.iter().find(|(k, v)| answer == *k || answer == *v) {
return Ok(v);
}
writeln!(self.output, "answer {} (or pass {flag})", keys.join(" or "))?;
}
}
/// `flag` names what to pass instead, for the error off a TTY.
pub fn text(
&mut self,
@@ -145,6 +171,43 @@ mod tests {
assert_eq!(err.kind(), std::io::ErrorKind::UnexpectedEof);
}
#[test]
fn choice_asks_again_on_an_answer_that_is_not_offered() {
let mut ask = scripted("npm\n3\n2\n");
let picked = ask
.choice(
"Publish to:",
&[("1", "jsr"), ("2", "both")],
"jsr",
"--registry",
)
.unwrap();
assert_eq!(picked, "both");
let shown = String::from_utf8(ask.output.clone()).unwrap();
assert!(shown.contains("answer 1 or 2"), "{shown}");
}
#[test]
fn choice_takes_the_default_on_enter_and_off_a_tty() {
let choices = [("1", "jsr"), ("2", "both")];
assert_eq!(
scripted("\n")
.choice("P?", &choices, "jsr", "--registry")
.unwrap(),
"jsr"
);
assert_eq!(
scripted("both\n")
.choice("P?", &choices, "jsr", "--registry")
.unwrap(),
"both"
);
assert_eq!(
piped().choice("P?", &choices, "jsr", "--registry").unwrap(),
"jsr"
);
}
#[test]
fn off_a_tty_nothing_is_asked() {
let mut ask = piped();