mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix: use correct import map in tar & upload (#21380)
This commit is contained in:
parent
e332fa4a83
commit
7e56a0466f
2 changed files with 20 additions and 23 deletions
|
@ -10,19 +10,18 @@ use base64::prelude::BASE64_STANDARD;
|
|||
use base64::Engine;
|
||||
use deno_config::ConfigFile;
|
||||
use deno_core::anyhow;
|
||||
use deno_core::anyhow::anyhow;
|
||||
use deno_core::anyhow::bail;
|
||||
use deno_core::anyhow::Context;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::url::Url;
|
||||
use deno_runtime::colors;
|
||||
use deno_runtime::deno_fetch::reqwest;
|
||||
use http::header::AUTHORIZATION;
|
||||
use http::header::CONTENT_ENCODING;
|
||||
use hyper::body::Bytes;
|
||||
use import_map::ImportMapWithDiagnostics;
|
||||
use import_map::ImportMap;
|
||||
use lsp_types::Url;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use sha2::Digest;
|
||||
|
@ -72,9 +71,8 @@ pub struct PublishingTask {
|
|||
async fn prepare_publish(
|
||||
initial_cwd: &Path,
|
||||
directory: PathBuf,
|
||||
import_map: &ImportMap,
|
||||
) -> Result<PreparedPublishPackage, AnyError> {
|
||||
// TODO: handle publishing without deno.json
|
||||
|
||||
let directory_path = initial_cwd.join(directory);
|
||||
// TODO: doesn't handle jsonc
|
||||
let deno_json_path = directory_path.join("deno.json");
|
||||
|
@ -98,17 +96,6 @@ async fn prepare_publish(
|
|||
bail!("Invalid package name, use '@<scope_name>/<package_name> format");
|
||||
};
|
||||
|
||||
// TODO: support `importMap` field in deno.json
|
||||
assert!(deno_json.to_import_map_path().is_none());
|
||||
|
||||
let deno_json_url = Url::from_file_path(&deno_json_path)
|
||||
.map_err(|_| anyhow!("deno.json path is not a valid file URL"))?;
|
||||
let ImportMapWithDiagnostics { import_map, .. } =
|
||||
import_map::parse_from_value(
|
||||
&deno_json_url,
|
||||
deno_json.to_import_map_value(),
|
||||
)?;
|
||||
|
||||
let unfurler = ImportMapUnfurler::new(import_map);
|
||||
|
||||
let tarball = tar::create_gzipped_tarball(directory_path, unfurler)
|
||||
|
@ -478,6 +465,14 @@ pub async fn publish(
|
|||
},
|
||||
};
|
||||
|
||||
let import_map = cli_factory
|
||||
.maybe_import_map()
|
||||
.await?
|
||||
.clone()
|
||||
.unwrap_or_else(|| {
|
||||
Arc::new(ImportMap::new(Url::parse("file:///dev/null").unwrap()))
|
||||
});
|
||||
|
||||
let initial_cwd =
|
||||
std::env::current_dir().with_context(|| "Failed getting cwd.")?;
|
||||
|
||||
|
@ -496,12 +491,14 @@ pub async fn publish(
|
|||
|
||||
let members = &deno_json.json.workspaces;
|
||||
if members.is_empty() {
|
||||
packages.push(prepare_publish(&initial_cwd, directory_path).await?);
|
||||
packages
|
||||
.push(prepare_publish(&initial_cwd, directory_path, &import_map).await?);
|
||||
} else {
|
||||
println!("Publishing a workspace...");
|
||||
for member in members {
|
||||
let member_dir = directory_path.join(member);
|
||||
packages.push(prepare_publish(&initial_cwd, member_dir).await?);
|
||||
packages
|
||||
.push(prepare_publish(&initial_cwd, member_dir, &import_map).await?);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ use deno_graph::MediaType;
|
|||
use deno_graph::TypeScriptReference;
|
||||
use import_map::ImportMap;
|
||||
|
||||
pub struct ImportMapUnfurler {
|
||||
import_map: ImportMap,
|
||||
pub struct ImportMapUnfurler<'a> {
|
||||
import_map: &'a ImportMap,
|
||||
}
|
||||
|
||||
impl ImportMapUnfurler {
|
||||
pub fn new(import_map: ImportMap) -> Self {
|
||||
impl<'a> ImportMapUnfurler<'a> {
|
||||
pub fn new(import_map: &'a ImportMap) -> Self {
|
||||
Self { import_map }
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ mod tests {
|
|||
});
|
||||
let ImportMapWithDiagnostics { import_map, .. } =
|
||||
import_map::parse_from_value(&deno_json_url, value).unwrap();
|
||||
let unfurler = ImportMapUnfurler::new(import_map);
|
||||
let unfurler = ImportMapUnfurler::new(&import_map);
|
||||
|
||||
// Unfurling TS file should apply changes.
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue