use std::fmt::Write as _;
use std::path::{Path, PathBuf};
use laravel::config::Section;
use laravel::console::{Console, clap};
use crate::config::{ComponentKind, LivewireConfig};
use crate::registry::normalize_name;
#[derive(Debug, clap::Parser)]
#[command(name = "make:livewire", about = "Create a Livewire component and its view")]
pub struct MakeLivewire {
pub name: String,
#[arg(long, conflicts_with_all = ["sfc", "inline"])]
pub class: bool,
#[arg(long, conflicts_with_all = ["mfc", "class", "inline"])]
pub sfc: bool,
#[arg(long, conflicts_with_all = ["sfc", "class", "inline"])]
pub mfc: bool,
#[arg(long, conflicts_with_all = ["mfc", "class", "sfc"])]
pub inline: bool,
#[arg(long)]
pub js: bool,
#[arg(long)]
pub css: bool,
#[arg(long)]
pub test: bool,
#[arg(long)]
pub force: bool,
#[arg(long)]
pub path: Option<PathBuf>,
}
#[derive(Debug, clap::Parser)]
#[command(name = "livewire:make", about = "Create a Livewire component and its view")]
pub struct LivewireMake {
pub name: String,
#[arg(long, conflicts_with_all = ["sfc", "inline"])]
pub class: bool,
#[arg(long, conflicts_with_all = ["mfc", "class", "inline"])]
pub sfc: bool,
#[arg(long, conflicts_with_all = ["sfc", "class", "inline"])]
pub mfc: bool,
#[arg(long, conflicts_with_all = ["mfc", "class", "sfc"])]
pub inline: bool,
#[arg(long)]
pub js: bool,
#[arg(long)]
pub css: bool,
#[arg(long)]
pub test: bool,
#[arg(long)]
pub force: bool,
#[arg(long)]
pub path: Option<PathBuf>,
}
#[derive(Debug, clap::Parser)]
#[command(name = "livewire:config", about = "Show the resolved Livewire configuration")]
pub struct LivewireConfigCommand;
#[derive(Debug, clap::Parser)]
#[command(
name = "livewire:configure-s3-upload-cleanup",
about = "Configure temporary file upload s3 directory to automatically cleanup files older than 24hrs"
)]
pub struct ConfigureS3UploadCleanup;
#[derive(Debug, clap::Parser)]
#[command(name = "livewire:layout", about = "Create a layout view for page components")]
pub struct Layout {
pub name: String,
#[arg(long)]
pub force: bool,
#[arg(long)]
pub path: Option<PathBuf>,
}
#[derive(Debug, clap::Parser)]
#[command(
name = "livewire:convert",
about = "Convert a component between single-file and multi-file"
)]
pub struct Convert {
pub name: String,
#[arg(long)]
pub remove_view: bool,
#[arg(long)]
pub path: Option<PathBuf>,
}
#[derive(Debug, clap::Parser)]
#[command(name = "livewire:publish", about = "Publish the Livewire front-end assets")]
pub struct Publish {
#[arg(long)]
pub assets: bool,
#[arg(long)]
pub force: bool,
#[arg(long)]
pub path: Option<PathBuf>,
}
#[derive(Debug, clap::Parser)]
#[command(name = "livewire:stubs", about = "Publish the component stubs make:livewire uses")]
pub struct Stubs {
#[arg(long)]
pub force: bool,
#[arg(long)]
pub path: Option<PathBuf>,
}
#[laravel::console::command]
impl MakeLivewire {
async fn handle(self, console: &mut Console, config: Section<LivewireConfig>) -> laravel::Result<()> {
let kind = if self.inline {
ComponentKind::Sfc
} else if self.class {
ComponentKind::Class
} else if self.mfc {
ComponentKind::Mfc
} else if self.sfc {
ComponentKind::Sfc
} else {
config.make_command.kind
};
let options = Options {
kind,
js: self.js || config.make_command.js,
css: self.css || config.make_command.css,
test: self.test || config.make_command.test,
base: self.path.clone(),
};
let plan = plan(&self.name, &options, &config)?;
let written = write(&plan, self.force)?;
for path in &written {
console.line(format!("created {}", path.display()));
}
Ok(())
}
}
#[laravel::console::command]
impl LivewireMake {
async fn handle(self, console: &mut Console, config: Section<LivewireConfig>) -> laravel::Result<()> {
let command = MakeLivewire {
name: self.name,
class: self.class,
sfc: self.sfc,
mfc: self.mfc,
inline: self.inline,
js: self.js,
css: self.css,
test: self.test,
force: self.force,
path: self.path,
};
MakeLivewire::handle(command, console, config).await
}
}
#[laravel::console::command]
impl Layout {
async fn handle(self, console: &mut Console) -> laravel::Result<()> {
let plan = plan_layout(&self.name, self.path.as_deref())?;
let written = write(&plan, self.force)?;
for path in &written {
console.line(format!("created {}", path.display()));
}
Ok(())
}
}
#[laravel::console::command]
impl Convert {
async fn handle(self, console: &mut Console, config: Section<LivewireConfig>) -> laravel::Result<()> {
let plan = plan_convert(&self.name, self.path.as_deref(), &config)?;
let written = write(&plan.files, true)?;
for path in &written {
console.line(format!("wrote {}", path.display()));
}
match (&plan.leftover_view, self.remove_view) {
(Some(view), true) => {
std::fs::remove_file(view)
.map_err(|error| laravel::Error::msg(format!("{} can't be removed: {error}", view.display())))?;
console.line(format!("removed {}", view.display()));
}
(Some(view), false) => console.line(format!(
"left {} in place: pass --remove-view to delete it",
view.display()
)),
(None, _) => {}
}
Ok(())
}
}
#[laravel::console::command]
impl Publish {
async fn handle(self, console: &mut Console) -> laravel::Result<()> {
let plan = plan_publish(self.path.as_deref());
let written = write(&plan, self.force)?;
for path in &written {
console.line(format!("published {}", path.display()));
}
Ok(())
}
}
#[laravel::console::command]
impl Stubs {
async fn handle(self, console: &mut Console) -> laravel::Result<()> {
let plan = plan_stubs(self.path.as_deref());
let written = write(&plan, self.force)?;
for path in &written {
console.line(format!("published {}", path.display()));
}
Ok(())
}
}
#[laravel::console::command]
impl ConfigureS3UploadCleanup {
async fn handle(self, console: &mut Console, config: Section<LivewireConfig>) -> laravel::Result<()> {
if config.temporary_file_upload.disk.as_deref() != Some("s3") {
console
.error("Configuration ['livewire.temporary_file_upload.disk'] is not set to a disk with an S3 driver.");
return Ok(());
}
console.error("This port does not talk to S3: schedule livewire::uploads::prune for the local disk instead.");
Ok(())
}
}
#[laravel::console::command]
impl LivewireConfigCommand {
async fn handle(self, console: &mut Console, config: Section<LivewireConfig>) -> laravel::Result<()> {
console.line(format!("{config:#?}"));
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct Options {
pub kind: ComponentKind,
pub js: bool,
pub css: bool,
pub test: bool,
pub base: Option<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Planned {
pub path: PathBuf,
pub contents: String,
}
pub fn plan(name: &str, options: &Options, config: &LivewireConfig) -> laravel::Result<Vec<Planned>> {
let name = normalize_name(name).map_err(|error| laravel::Error::msg(error.to_string()))?;
let parts: Vec<&str> = name.split(['.', ':']).filter(|part| !part.is_empty()).collect();
let Some(leaf) = parts.last() else {
return Err(laravel::Error::msg("the component name is empty"));
};
let struct_name = pascal_case(leaf);
let kebab = kebab_case(leaf);
let dotted = parts.join(".");
let relative: PathBuf = parts.iter().collect();
let base = options.base.clone();
let root = |path: &str| -> PathBuf {
match &base {
Some(base) => base.join(path),
None => PathBuf::from(path),
}
};
let component_path = root(&config.component_path).join(&relative).with_extension("rs");
let view_path = root(&config.view_path).join(&relative).with_extension("livewire");
let inline = matches!(options.kind, ComponentKind::Sfc);
let markup = format!("<div>\n <h2>{struct_name}</h2>\n</div>");
let module = match read_stub(&root("stubs/livewire/component.rs.stub")) {
Some(stub) => substitute(&stub, &struct_name, &kebab, &dotted),
None if inline => module_source(&struct_name, &kebab, &markup, None),
None => module_source(&struct_name, &kebab, "", Some(&dotted)),
};
let mut files = vec![Planned {
path: component_path,
contents: module,
}];
if !inline {
let view = match read_stub(&root("stubs/livewire/view.livewire.stub")) {
Some(stub) => substitute(&stub, &struct_name, &kebab, &dotted),
None => format!("<div>\n <h2>{struct_name}</h2>\n</div>\n"),
};
files.push(Planned {
path: view_path.clone(),
contents: view,
});
}
if options.js {
files.push(Planned {
path: view_path.with_extension("js"),
contents: format!("// The `{kebab}` component's browser module.\n"),
});
}
if options.css {
files.push(Planned {
path: view_path.with_extension("css"),
contents: format!("/* The `{kebab}` component's styles. */\n"),
});
}
if options.test {
files.push(Planned {
path: root("tests").join(format!("{kebab}.rs")),
contents: format!(
"//! Tests for the `{kebab}` component.\n\nuse laravel::testing::prelude::*;\n\n#[laravel::test]\nasync fn the_{snake}_component_renders(app: Application) {{\n app.get(\"/{kebab}\").await.assert_ok();\n}}\n",
snake = snake_case(leaf),
),
});
}
Ok(files)
}
pub fn write(plan: &[Planned], force: bool) -> laravel::Result<Vec<PathBuf>> {
let mut written = Vec::with_capacity(plan.len());
for file in plan {
if file.path.exists() && !force {
return Err(laravel::Error::msg(format!(
"{} already exists: pass --force to replace it",
file.path.display()
)));
}
if let Some(parent) = file.path.parent() {
std::fs::create_dir_all(parent)
.map_err(|error| laravel::Error::msg(format!("{} can't be created: {error}", parent.display())))?;
}
std::fs::write(&file.path, &file.contents)
.map_err(|error| laravel::Error::msg(format!("{} can't be written: {error}", file.path.display())))?;
written.push(file.path.clone());
}
Ok(written)
}
pub fn plan_layout(name: &str, base: Option<&Path>) -> laravel::Result<Vec<Planned>> {
let leaf = name.rsplit(['.', ':']).next().unwrap_or(name);
let valid = !leaf.is_empty()
&& leaf
.chars()
.all(|character| character.is_alphanumeric() || matches!(character, '-' | '_'));
if !valid {
return Err(laravel::Error::msg(format!(
"[{name}] is not a layout name: use letters, digits, dashes, or underscores"
)));
}
let root = base.map_or_else(
|| PathBuf::from("resources/views/layouts"),
|base| base.join("resources/views/layouts"),
);
Ok(vec![Planned {
path: root.join(leaf).with_extension("html"),
contents: layout_source(leaf),
}])
}
fn layout_source(name: &str) -> String {
format!(
r#"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{{{ csrf_token() }}}}">
<title>{{% block title %}}{name}{{% endblock %}} · {{{{ app_name }}}}</title>
{{{{ livewire_styles() }}}}
</head>
<body>
<main>
{{% block content %}}{{% endblock %}}
</main>
{{{{ livewire_scripts() }}}}
</body>
</html>
"#
)
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConvertPlan {
pub files: Vec<Planned>,
pub leftover_view: Option<PathBuf>,
}
pub fn plan_convert(name: &str, base: Option<&Path>, config: &LivewireConfig) -> laravel::Result<ConvertPlan> {
let name = normalize_name(name).map_err(|error| laravel::Error::msg(error.to_string()))?;
let parts: Vec<&str> = name.split(['.', ':']).filter(|part| !part.is_empty()).collect();
let Some(leaf) = parts.last() else {
return Err(laravel::Error::msg("the component name is empty"));
};
let relative: PathBuf = parts.iter().collect();
let dotted = parts.join(".");
let struct_name = pascal_case(leaf);
let kebab = kebab_case(leaf);
let root = |path: &str| -> PathBuf { base.map_or_else(|| PathBuf::from(path), |base| base.join(path)) };
let module_path = root(&config.component_path).join(&relative).with_extension("rs");
let view_path = root(&config.view_path).join(&relative).with_extension("livewire");
let source = std::fs::read_to_string(&module_path)
.map_err(|error| laravel::Error::msg(format!("{} can't be read: {error}", module_path.display())))?;
if let Some(markup) = inline_markup(&source) {
return Ok(ConvertPlan {
files: vec![
Planned {
path: module_path,
contents: source.replace(
&format!("#[livewire(inline = \"{markup}\")]"),
&format!("#[livewire(view = \"livewire.{dotted}\")]"),
),
},
Planned {
path: view_path,
contents: format!("{}\n", unescape_literal(&markup)),
},
],
leftover_view: None,
});
}
if source.contains("#[livewire(view = ") {
let markup = std::fs::read_to_string(&view_path)
.map_err(|error| laravel::Error::msg(format!("{} can't be read: {error}", view_path.display())))?;
let escaped = escape_literal(markup.trim_end());
let start = source.find("#[livewire(view = ").unwrap_or(0);
let end = source[start..].find(']').map_or(source.len(), |end| start + end + 1);
let mut converted = String::with_capacity(source.len());
converted.push_str(&source[..start]);
let _ = write!(converted, "#[livewire(inline = \"{escaped}\")]");
converted.push_str(&source[end..]);
let _ = (struct_name, kebab);
return Ok(ConvertPlan {
files: vec![Planned {
path: module_path,
contents: converted,
}],
leftover_view: Some(view_path),
});
}
Err(laravel::Error::msg(format!(
"{} declares neither #[livewire(inline = ..)] nor #[livewire(view = ..)]",
module_path.display()
)))
}
fn inline_markup(source: &str) -> Option<String> {
let start = source.find("#[livewire(inline = \"")? + "#[livewire(inline = \"".len();
let rest = &source[start..];
let mut escaped = false;
for (index, character) in rest.char_indices() {
match character {
'\\' if !escaped => escaped = true,
'"' if !escaped => return Some(rest[..index].to_owned()),
_ => escaped = false,
}
}
None
}
fn escape_literal(markup: &str) -> String {
markup.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n")
}
fn unescape_literal(literal: &str) -> String {
let mut out = String::with_capacity(literal.len());
let mut characters = literal.chars();
while let Some(character) = characters.next() {
if character != '\\' {
out.push(character);
continue;
}
match characters.next() {
Some('n') => out.push('\n'),
Some('t') => out.push('\t'),
Some(other) => out.push(other),
None => {}
}
}
out
}
pub fn plan_publish(base: Option<&Path>) -> Vec<Planned> {
use laravel_core::embed::EmbeddedInternals as _;
let mut files = Vec::new();
for (path, bytes) in DIST.files() {
let contents = String::from_utf8_lossy(bytes).into_owned();
files.push(Planned {
path: base
.map_or_else(
|| PathBuf::from("public/vendor/livewire"),
|base| base.join("public/vendor/livewire"),
)
.join(path),
contents,
});
}
files
}
pub fn plan_stubs(base: Option<&Path>) -> Vec<Planned> {
let root = base.map_or_else(|| PathBuf::from("stubs/livewire"), |base| base.join("stubs/livewire"));
vec![
Planned {
path: root.join("component.rs.stub"),
contents: module_source("Dummy", "dummy", "<div>\n <h2>Dummy</h2>\n</div>", Some("dummy")),
},
Planned {
path: root.join("view.livewire.stub"),
contents: "<div>\n <h2>Dummy</h2>\n</div>\n".to_owned(),
},
]
}
static DIST: laravel::embed::Embedded = laravel::embed!("dist");
fn read_stub(path: &Path) -> Option<String> {
std::fs::read_to_string(path).ok()
}
fn substitute(stub: &str, struct_name: &str, kebab: &str, dotted: &str) -> String {
stub.replace("livewire.dummy", &format!("livewire.{dotted}"))
.replace("Dummy", struct_name)
.replace("dummy", kebab)
}
fn module_source(struct_name: &str, kebab: &str, markup: &str, view: Option<&str>) -> String {
let view_attribute = match view {
Some(dotted) => format!("#[livewire(view = \"livewire.{dotted}\")]"),
None if markup.is_empty() => String::new(),
None => format!("#[livewire(inline = \"{}\")]", escape_literal(markup)),
};
format!(
r#"//! The `{kebab}` component.
use livewire::{{LivewireComponent, component}};
/// A component that {kebab}.
#[derive(Default, LivewireComponent)]
{view_attribute}
pub struct {struct_name} {{
/// The text the component shows.
pub title: String,
}}
#[component]
impl {struct_name} {{
/// Runs when the component first appears on the page.
pub fn mount(&mut self, title: Option<String>) {{
self.title = title.unwrap_or_else(|| "{struct_name}".to_owned());
}}
}}
"#
)
}
fn pascal_case(name: &str) -> String {
name.split(['-', '_'])
.filter(|part| !part.is_empty())
.map(|part| {
let mut characters = part.chars();
match characters.next() {
Some(first) => first.to_uppercase().collect::<String>() + characters.as_str(),
None => String::new(),
}
})
.collect()
}
fn kebab_case(name: &str) -> String {
let mut out = String::with_capacity(name.len() + 4);
for (index, character) in name.char_indices() {
if character.is_uppercase() {
if index > 0 {
out.push('-');
}
out.extend(character.to_lowercase());
} else if character == '_' {
out.push('-');
} else {
out.push(character);
}
}
out
}
fn snake_case(name: &str) -> String {
kebab_case(name).replace('-', "_")
}
#[cfg(test)]
mod tests {
use super::*;
fn options(kind: ComponentKind) -> Options {
Options {
kind,
js: false,
css: false,
test: false,
base: Some(PathBuf::from("/tmp/app")),
}
}
#[test]
fn a_single_file_component_carries_its_markup() {
let config = LivewireConfig::default();
let plan = plan("counter", &options(ComponentKind::Sfc), &config).expect("a plan");
assert_eq!(plan.len(), 1);
assert_eq!(plan[0].path, Path::new("/tmp/app/src/livewire/counter.rs"));
assert!(plan[0].contents.contains("pub struct Counter"));
assert!(plan[0].contents.contains("#[livewire(inline = \"<div>"));
assert!(!plan[0].contents.contains("view = "));
}
#[test]
fn a_module_and_view_component_writes_both_files() {
let config = LivewireConfig::default();
let plan = plan("pages.counter", &options(ComponentKind::Mfc), &config).expect("a plan");
assert_eq!(plan.len(), 2);
assert_eq!(plan[0].path, Path::new("/tmp/app/src/livewire/pages/counter.rs"));
assert!(
plan[0]
.contents
.contains("#[livewire(view = \"livewire.pages.counter\")]")
);
assert_eq!(
plan[1].path,
Path::new("/tmp/app/resources/views/livewire/pages/counter.livewire")
);
}
#[test]
fn a_namespace_through_colons_becomes_directories() {
let config = LivewireConfig::default();
let plan = plan("pages::counter", &options(ComponentKind::Mfc), &config).expect("a plan");
assert_eq!(plan[0].path, Path::new("/tmp/app/src/livewire/pages/counter.rs"));
}
#[test]
fn the_module_and_css_and_test_files_follow_the_flags() {
let config = LivewireConfig::default();
let mut options = options(ComponentKind::Mfc);
options.js = true;
options.css = true;
options.test = true;
let plan = plan("post-editor", &options, &config).expect("a plan");
assert_eq!(plan.len(), 5);
assert!(plan.iter().any(|file| file.path.ends_with("post-editor.js")));
assert!(plan.iter().any(|file| file.path.ends_with("post-editor.css")));
assert!(
plan.iter()
.any(|file| file.path == Path::new("/tmp/app/tests/post-editor.rs"))
);
assert!(plan[0].contents.contains("pub struct PostEditor"));
}
#[test]
fn a_name_that_would_escape_the_directory_is_rejected() {
let config = LivewireConfig::default();
assert!(plan("../../etc/passwd", &options(ComponentKind::Sfc), &config).is_err());
assert!(plan("", &options(ComponentKind::Sfc), &config).is_err());
}
#[test]
fn an_existing_file_is_refused_without_force() {
let directory = tempfile::tempdir().expect("a temporary directory");
let config = LivewireConfig::default();
let mut options = options(ComponentKind::Mfc);
options.base = Some(directory.path().to_path_buf());
let plan = plan("counter", &options, &config).expect("a plan");
let written = write(&plan, false).expect("the first write succeeds");
assert_eq!(written.len(), 2);
let error = write(&plan, false).expect_err("the second write is refused");
assert!(error.to_string().contains("--force"));
write(&plan, true).expect("force replaces it");
}
#[test]
fn a_layout_loads_the_runtime_and_renders_a_content_block() {
let plan = plan_layout("app", Some(Path::new("/tmp/app"))).expect("a plan");
assert_eq!(plan.len(), 1);
assert_eq!(plan[0].path, Path::new("/tmp/app/resources/views/layouts/app.html"));
assert!(plan[0].contents.contains("{% block content %}"));
assert!(plan[0].contents.contains("{{ livewire_styles() }}"));
assert!(plan[0].contents.contains("{{ livewire_scripts() }}"));
assert!(plan[0].contents.contains("csrf-token"));
}
#[test]
fn a_layout_name_cannot_escape_its_directory() {
assert!(plan_layout("../secret", None).is_err());
assert!(plan_layout("app/../x", None).is_err());
}
#[test]
fn convert_moves_the_markup_between_the_module_and_its_view() {
let directory = tempfile::tempdir().expect("a temporary directory");
let base = directory.path();
let config = LivewireConfig::default();
let mut options = options(ComponentKind::Sfc);
options.base = Some(base.to_path_buf());
write(&plan("counter", &options, &config).expect("a plan"), false).expect("written");
let converted = plan_convert("counter", Some(base), &config).expect("a conversion");
assert!(
converted.leftover_view.is_none(),
"converting to a view leaves nothing behind"
);
assert!(
converted.files[0]
.contents
.contains("#[livewire(view = \"livewire.counter\")]")
);
assert!(!converted.files[0].contents.contains("inline"));
assert_eq!(
converted.files[1].path,
base.join("resources/views/livewire/counter.livewire")
);
assert!(converted.files[1].contents.contains("<h2>Counter</h2>"));
write(&converted.files, true).expect("written");
let restored = plan_convert("counter", Some(base), &config).expect("a conversion");
assert!(restored.files[0].contents.contains("#[livewire(inline = "));
assert!(restored.files[0].contents.contains("\\n <h2>Counter</h2>"));
assert_eq!(
restored.leftover_view,
Some(base.join("resources/views/livewire/counter.livewire"))
);
}
#[test]
fn convert_refuses_a_component_that_declares_neither_form() {
let directory = tempfile::tempdir().expect("a temporary directory");
let base = directory.path();
let config = LivewireConfig::default();
std::fs::create_dir_all(base.join("src/livewire")).expect("a directory");
std::fs::write(base.join("src/livewire/broken.rs"), "pub struct Broken;\n").expect("a file");
let error = plan_convert("broken", Some(base), &config).expect_err("refused");
assert!(error.to_string().contains("neither"));
}
#[test]
fn publish_carries_the_bundles_and_the_manifest() {
let plan = plan_publish(Some(Path::new("/tmp/app")));
assert!(plan.iter().any(|file| file.path.ends_with("livewire.min.js")));
assert!(plan.iter().any(|file| file.path.ends_with("manifest.json")));
assert!(plan.iter().all(|file| !file.contents.is_empty()));
}
#[test]
fn a_published_stub_replaces_the_built_in_template() {
let directory = tempfile::tempdir().expect("a temporary directory");
let base = directory.path();
let config = LivewireConfig::default();
write(&plan_stubs(Some(base)), false).expect("stubs written");
let mut options = options(ComponentKind::Mfc);
options.base = Some(base.to_path_buf());
let plan = plan("counter", &options, &config).expect("a plan");
let module = &plan[0].contents;
assert!(module.contains("pub struct Counter"), "the stub's struct was renamed");
assert!(module.contains("#[livewire(view = \"livewire.counter\")]"));
}
#[test]
fn every_generated_module_parses_as_rust() {
let config = LivewireConfig::default();
for kind in [ComponentKind::Sfc, ComponentKind::Mfc, ComponentKind::Class] {
let plan = plan("pages.post-editor", &options(kind), &config).expect("a plan");
let module = &plan[0];
syn::parse_file(&module.contents)
.unwrap_or_else(|error| panic!("the {kind} module does not parse: {error}\n{}", module.contents));
}
}
#[test]
fn the_generated_module_names_the_component_after_its_file() {
let config = LivewireConfig::default();
let plan = plan("post-editor", &options(ComponentKind::Sfc), &config).expect("a plan");
assert!(plan[0].contents.contains("//! The `post-editor` component."));
assert!(plan[0].contents.contains("pub struct PostEditor"));
assert!(!plan[0].contents.contains("sergio"));
}
}