summaryrefslogtreecommitdiff
path: root/cli/tools/registry/tar.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-01-23 12:40:23 +0100
committerGitHub <noreply@github.com>2024-01-23 12:40:23 +0100
commit052fd786906eef7d1583030a1370cf2f2be1907d (patch)
treef633a10c1dd47c3bfda3701e3087166f17a3100b /cli/tools/registry/tar.rs
parente49973d96d6817378c71bf1875b03b77d083f1d3 (diff)
refactor: use parsed source cache when unfurling import map (#22001)
Diffstat (limited to 'cli/tools/registry/tar.rs')
-rw-r--r--cli/tools/registry/tar.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs
index 6eaaf1095..0f6edbc3a 100644
--- a/cli/tools/registry/tar.rs
+++ b/cli/tools/registry/tar.rs
@@ -31,8 +31,7 @@ pub struct PublishableTarball {
pub fn create_gzipped_tarball(
dir: &Path,
- // TODO(bartlomieju): this is too specific, factor it out into a callback that
- // returns data
+ source_cache: &dyn deno_graph::ParsedSourceStore,
unfurler: &ImportMapUnfurler,
exclude_patterns: &PathOrPatternSet,
) -> Result<PublishableTarball, AnyError> {
@@ -71,12 +70,15 @@ pub fn create_gzipped_tarball(
path: relative_path.to_path_buf(),
size: data.len(),
});
- let (content, unfurl_diagnostics) =
- unfurler.unfurl(&url, data).with_context(|| {
- format!("Unable to unfurl file '{}'", entry.path().display())
- })?;
-
- diagnostics.extend_from_slice(&unfurl_diagnostics);
+ let content = match source_cache.get_parsed_source(&url) {
+ Some(parsed_source) => {
+ let (content, unfurl_diagnostics) =
+ unfurler.unfurl(&url, &parsed_source);
+ diagnostics.extend_from_slice(&unfurl_diagnostics);
+ content.into_bytes()
+ }
+ None => data,
+ };
tar
.add_file(relative_path_str.to_string(), &content)
.with_context(|| {