1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

refactor: suggest entrypoint on missing 'exports' (#21549)

This commit is contained in:
Bartek Iwańczuk 2023-12-12 19:18:02 +01:00 committed by GitHub
parent ece78cfb8a
commit 0ceae7a490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,6 +71,9 @@ pub struct PublishingTask {
pub error: Option<PublishingTaskError>,
}
static SUGGESTED_ENTRYPOINTS: [&str; 4] =
["mod.ts", "mod.js", "index.ts", "index.js"];
async fn prepare_publish(
initial_cwd: &Path,
directory: PathBuf,
@ -92,6 +95,34 @@ async fn prepare_publish(
let Some(name) = deno_json.json.name.clone() else {
bail!("{} is missing 'name' field", deno_json_path.display());
};
if deno_json.json.exports.is_none() {
let mut suggested_entrypoint = None;
for entrypoint in SUGGESTED_ENTRYPOINTS {
if directory_path.join(entrypoint).exists() {
suggested_entrypoint = Some(entrypoint);
break;
}
}
let exports_content = format!(
r#"{{
"name": "{}",
"version": "{}",
"exports": "{}"
}}"#,
name,
version,
suggested_entrypoint.unwrap_or("<path_to_entrypoint>")
);
bail!(
"You did not specify an entrypoint to \"{}\" package in {}. Add `exports` mapping in the configuration file, eg:\n{}",
name,
deno_json_path.display(),
exports_content
);
}
let Some(name) = name.strip_prefix('@') else {
bail!("Invalid package name, use '@<scope_name>/<package_name> format");
};