fix(plugin): the review's smaller findings
CI / installer (macos-14) (pull_request) Successful in 4s
CI / check (pull_request) Failing after 29s
CI / starter (bun) (pull_request) Successful in 32s
CI / starter (deno) (pull_request) Successful in 33s
CI / starter (edge) (pull_request) Successful in 37s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Successful in 11s
CI / starter (node) (pull_request) Successful in 34s

- `--package` takes a directory only as `--package=DIR`, so
  `create plugin --package algo` names the plugin instead of writing
  into ./algo.
- A NAME passed on the command line is checked before any question.
- The package directory is named in its errors, a file there is
  reported as a file, and a failed write lists what was already written.
- An in-app plugin folder is removed again if the entry cannot be
  written, so the rerun does not stop on "already exists".
- `--folder .` and `./plugins/` give clean import paths.
- Flags for the other mode are named as ignored; plugin flags on
  another create kind are an error.
- Array elements are read from the parse tree, so `algo({ a, b })` is
  one element when checking for a duplicate.
- Scopes follow JSR's rule: 2 to 20 characters, no leading hyphen.
- Packages ship a LICENSE (MIT, which the README says to change), the
  license field in both manifests, and @types/node for the test file.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-09-24 13:26:29 -05:00
1 parent 4358091d07
commit ecdc46cac3
8 files changed
+460 -86

No files matched your search

+36 -1
View File
@@ -261,7 +261,7 @@ pub fn add_to_createapp_modules(src: &str, symbol: &str) -> Option<String> {
fn insert_into_object_array(src: &str, object: Node, key: &str, symbol: &str) -> Option<String> {
if let Some((open, close)) = find_key_array_span(object, src, key) {
let inner = &src[open + 1..close];
if inner.split(',').map(str::trim).any(|s| s == symbol) {
if array_elements(object, src, key).iter().any(|e| e == symbol) {
return Some(src.to_string()); // idempotent
}
let joined = if inner.trim().is_empty() {
@@ -305,6 +305,32 @@ fn insert_into_object_array(src: &str, object: Node, key: &str, symbol: &str) ->
}
}
/// The text of each element of `object`'s `key: [...]` array, read from the
/// parse tree: `algo({ a: 1, b: 2 })` is one element, which a split on `,` is not.
fn array_elements(object: Node, src: &str, key: &str) -> Vec<String> {
let mut c = object.walk();
for pair in object.named_children(&mut c) {
let is_key = pair.kind() == "pair"
&& pair
.child_by_field_name("key")
.and_then(|k| k.utf8_text(src.as_bytes()).ok())
== Some(key);
let Some(array) = pair
.child_by_field_name("value")
.filter(|v| is_key && v.kind() == "array")
else {
continue;
};
let mut ac = array.walk();
return array
.named_children(&mut ac)
.filter_map(|e| e.utf8_text(src.as_bytes()).ok())
.map(|t| t.split_whitespace().collect::<Vec<_>>().join(" "))
.collect();
}
Vec::new()
}
/// True when `object` has any direct `pair` child whose key text equals `key`,
/// regardless of the value's kind. Used to avoid creating a duplicate key when
/// an existing pair's value isn't an array literal.
@@ -473,6 +499,15 @@ fn find_module_object<'a>(root: &Node<'a>, src: &str) -> Option<Node<'a>> {
#[cfg(test)]
mod tests {
#[test]
fn an_element_with_commas_inside_is_still_one_element() {
let src = "const app = createApp({ plugins: [algo({ a: 1, b: 2 })] });\n";
assert_eq!(
add_to_createapp(src, "plugins", "algo({ a: 1, b: 2 })").as_deref(),
Some(src)
);
}
#[test]
fn binds_sees_identifiers_not_strings_or_comments() {
let src = "import { createApp } from '@green-tea/core';\n// green tea\nexport const app = createApp({});\n";