mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-04-08 12:50:55 +01:00
parent
2aeee9de34
commit
a4d7b4d6e0
3 changed files with 46 additions and 36 deletions
|
@ -48,9 +48,34 @@ pub struct PublishCommand {
|
||||||
/// The index to publish to
|
/// The index to publish to
|
||||||
#[arg(short, long, default_value_t = DEFAULT_INDEX_NAME.to_string())]
|
#[arg(short, long, default_value_t = DEFAULT_INDEX_NAME.to_string())]
|
||||||
index: String,
|
index: String,
|
||||||
|
|
||||||
|
/// Whether to skip syntax validation
|
||||||
|
#[arg(long)]
|
||||||
|
no_verify: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PublishCommand {
|
impl PublishCommand {
|
||||||
|
fn validate_luau_file(&self, name: &str, contents: &str) -> anyhow::Result<()> {
|
||||||
|
if self.no_verify {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(err) = full_moon::parse(contents) {
|
||||||
|
eprintln!(
|
||||||
|
"{}: {name} is not a valid Luau file:\n{}",
|
||||||
|
"error".red().bold(),
|
||||||
|
err.into_iter()
|
||||||
|
.map(|err| format!("\t- {err}"))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n")
|
||||||
|
);
|
||||||
|
|
||||||
|
anyhow::bail!("failed to validate Luau file");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn run_impl(
|
async fn run_impl(
|
||||||
self,
|
self,
|
||||||
project: &Project,
|
project: &Project,
|
||||||
|
@ -226,14 +251,7 @@ info: otherwise, the file was deemed unnecessary, if you don't understand why, p
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.with_context(|| format!("failed to canonicalize {name}"))?;
|
.with_context(|| format!("failed to canonicalize {name}"))?;
|
||||||
|
|
||||||
if let Err(err) = full_moon::parse(&contents).map_err(|errs| {
|
self.validate_luau_file(&format!("file at {name}"), &contents)?;
|
||||||
errs.into_iter()
|
|
||||||
.map(|err| err.to_string())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
}) {
|
|
||||||
anyhow::bail!("{name} is not a valid Luau file: {err}");
|
|
||||||
}
|
|
||||||
|
|
||||||
let first_part = relative_export_path
|
let first_part = relative_export_path
|
||||||
.components()
|
.components()
|
||||||
|
@ -318,14 +336,7 @@ info: otherwise, the file was deemed unnecessary, if you don't understand why, p
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.with_context(|| format!("failed to canonicalize script {name}"))?;
|
.with_context(|| format!("failed to canonicalize script {name}"))?;
|
||||||
|
|
||||||
if let Err(err) = full_moon::parse(&contents).map_err(|errs| {
|
self.validate_luau_file(&format!("the `{name}` script"), &contents)?;
|
||||||
errs.into_iter()
|
|
||||||
.map(|err| err.to_string())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
}) {
|
|
||||||
anyhow::bail!("script {name} is not a valid Luau file: {err}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if paths.insert(
|
if paths.insert(
|
||||||
script_path
|
script_path
|
||||||
|
|
|
@ -41,13 +41,25 @@ impl Visitor for TypeVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the types exported by a file
|
pub(crate) fn get_file_types(file: &str) -> Vec<String> {
|
||||||
pub fn get_file_types(file: &str) -> Result<Vec<String>, Vec<full_moon::Error>> {
|
let ast = match full_moon::parse(file) {
|
||||||
let ast = full_moon::parse(file)?;
|
Ok(ast) => ast,
|
||||||
|
Err(err) => {
|
||||||
|
tracing::error!(
|
||||||
|
"failed to parse file to extract types:\n{}",
|
||||||
|
err.into_iter()
|
||||||
|
.map(|err| format!("\t- {err}"))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n")
|
||||||
|
);
|
||||||
|
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
};
|
||||||
let mut visitor = TypeVisitor { types: vec![] };
|
let mut visitor = TypeVisitor { types: vec![] };
|
||||||
visitor.visit_ast(&ast);
|
visitor.visit_ast(&ast);
|
||||||
|
|
||||||
Ok(visitor.types)
|
visitor.types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a linking module for a library
|
/// Generate a linking module for a library
|
||||||
|
|
|
@ -99,18 +99,9 @@ impl Project {
|
||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let types = match spawn_blocking(move || get_file_types(&contents))
|
let types = spawn_blocking(move || get_file_types(&contents))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap();
|
||||||
{
|
|
||||||
Ok(types) => types,
|
|
||||||
Err(e) => {
|
|
||||||
return Err(errors::LinkingError::FullMoon(
|
|
||||||
lib_file.display().to_string(),
|
|
||||||
e,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
tracing::debug!("contains {} exported types", types.len());
|
tracing::debug!("contains {} exported types", types.len());
|
||||||
|
|
||||||
|
@ -145,7 +136,7 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((version_id, types))
|
Ok((version_id, types))
|
||||||
}.instrument(tracing::debug_span!("extract types", name = name.to_string(), version_id = version_id.to_string()))))
|
}.instrument(tracing::info_span!("extract types", name = name.to_string(), version_id = version_id.to_string()))))
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<HashMap<_, _>>(),
|
.collect::<HashMap<_, _>>(),
|
||||||
|
@ -384,10 +375,6 @@ pub mod errors {
|
||||||
#[error("library file at {0} not found")]
|
#[error("library file at {0} not found")]
|
||||||
LibFileNotFound(String),
|
LibFileNotFound(String),
|
||||||
|
|
||||||
/// An error occurred while parsing a Luau script
|
|
||||||
#[error("error parsing Luau script at {0}")]
|
|
||||||
FullMoon(String, Vec<full_moon::Error>),
|
|
||||||
|
|
||||||
/// An error occurred while generating a Roblox sync config
|
/// An error occurred while generating a Roblox sync config
|
||||||
#[error("error generating roblox sync config for {0}")]
|
#[error("error generating roblox sync config for {0}")]
|
||||||
GenerateRobloxSyncConfig(String, #[source] std::io::Error),
|
GenerateRobloxSyncConfig(String, #[source] std::io::Error),
|
||||||
|
|
Loading…
Add table
Reference in a new issue