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:
parent
ece78cfb8a
commit
0ceae7a490
1 changed files with 31 additions and 0 deletions
|
@ -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");
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue