Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into lsp-cancellation-fo…
Browse files Browse the repository at this point in the history
…r-blocking
  • Loading branch information
nayeemrmn committed Feb 7, 2025
2 parents 85fca86 + 615bf8a commit 2560c0a
Show file tree
Hide file tree
Showing 13 changed files with 4,696 additions and 1,015 deletions.
35 changes: 20 additions & 15 deletions cli/standalone/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use capacity_builder::BytesAppendable;
use deno_ast::MediaType;
use deno_ast::ModuleKind;
use deno_ast::ModuleSpecifier;
use deno_cache_dir::CACHE_PERM;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
Expand Down Expand Up @@ -46,6 +47,7 @@ use deno_lib::util::hash::FastInsecureHasher;
use deno_lib::version::DENO_VERSION_INFO;
use deno_npm::resolution::SerializedNpmResolutionSnapshot;
use deno_npm::NpmSystemInfo;
use deno_path_util::fs::atomic_write_file_with_retries;
use deno_path_util::url_from_directory_path;
use deno_path_util::url_to_file_path;
use deno_resolver::workspace::WorkspaceResolver;
Expand Down Expand Up @@ -285,17 +287,17 @@ impl<'a> DenoCompileBinaryWriter<'a> {
let download_directory = self.deno_dir.dl_folder_path();
let binary_path = download_directory.join(&binary_path_suffix);

if !binary_path.exists() {
self
.download_base_binary(&download_directory, &binary_path_suffix)
.await
.context("Setting up base binary.")?;
}

let read_file = |path: &Path| -> Result<Vec<u8>, AnyError> {
std::fs::read(path).with_context(|| format!("Reading {}", path.display()))
};
let archive_data = read_file(&binary_path)?;
let archive_data = if binary_path.exists() {
read_file(&binary_path)?
} else {
self
.download_base_binary(&binary_path, &binary_path_suffix)
.await
.context("Setting up base binary.")?
};
let temp_dir = tempfile::TempDir::new()?;
let base_binary_path = archive::unpack_into_dir(archive::UnpackArgs {
exe_name: "denort",
Expand All @@ -311,9 +313,9 @@ impl<'a> DenoCompileBinaryWriter<'a> {

async fn download_base_binary(
&self,
output_directory: &Path,
output_path: &Path,
binary_path_suffix: &str,
) -> Result<(), AnyError> {
) -> Result<Vec<u8>, AnyError> {
let download_url = format!("https://dl.deno.land/{binary_path_suffix}");
let maybe_bytes = {
let progress_bars = ProgressBar::new(ProgressBarStyle::DownloadBars);
Expand All @@ -340,12 +342,15 @@ impl<'a> DenoCompileBinaryWriter<'a> {
std::fs::create_dir_all(dir)
.with_context(|| format!("Creating {}", dir.display()))
};
create_dir_all(output_directory)?;
let output_path = output_directory.join(binary_path_suffix);
create_dir_all(output_path.parent().unwrap())?;
std::fs::write(&output_path, bytes)
.with_context(|| format!("Writing {}", output_path.display()))?;
Ok(())
atomic_write_file_with_retries(
&CliSys::default(),
output_path,
&bytes,
CACHE_PERM,
)
.with_context(|| format!("Writing {}", output_path.display()))?;
Ok(bytes)
}

/// This functions creates a standalone deno binary by appending a bundle
Expand Down
35 changes: 17 additions & 18 deletions cli/tools/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ pub async fn compile(
let binary_writer = factory.create_compile_binary_writer().await?;
let http_client = factory.http_client_provider();
let entrypoint = cli_options.resolve_main_module()?;
let (module_roots, include_files) = get_module_roots_and_include_files(
entrypoint,
&compile_flags,
cli_options.initial_cwd(),
)?;

let output_path = resolve_compile_executable_output_path(
http_client,
&compile_flags,
cli_options.initial_cwd(),
)
.await?;
let (module_roots, include_files) = get_module_roots_and_include_files(
entrypoint,
&url_from_file_path(&cli_options.initial_cwd().join(&output_path))?,
&compile_flags,
cli_options.initial_cwd(),
)?;

let graph = Arc::try_unwrap(
module_graph_creator
Expand Down Expand Up @@ -198,6 +198,7 @@ fn validate_output_path(output_path: &Path) -> Result<(), AnyError> {

fn get_module_roots_and_include_files(
entrypoint: &ModuleSpecifier,
output_url: &ModuleSpecifier,
compile_flags: &CompileFlags,
initial_cwd: &Path,
) -> Result<(Vec<ModuleSpecifier>, Vec<ModuleSpecifier>), AnyError> {
Expand Down Expand Up @@ -226,9 +227,8 @@ fn get_module_roots_and_include_files(

fn analyze_path(
url: &ModuleSpecifier,
module_roots: &mut Vec<ModuleSpecifier>,
include_files: &mut Vec<ModuleSpecifier>,
searched_paths: &mut HashSet<PathBuf>,
mut add_url: impl FnMut(ModuleSpecifier),
) -> Result<(), AnyError> {
let Ok(path) = url_to_file_path(url) else {
return Ok(());
Expand All @@ -240,10 +240,7 @@ fn get_module_roots_and_include_files(
}
if !path.is_dir() {
let url = url_from_file_path(&path)?;
include_files.push(url.clone());
if is_module_graph_module(&url) {
module_roots.push(url);
}
add_url(url);
continue;
}
for entry in std::fs::read_dir(&path).with_context(|| {
Expand All @@ -270,12 +267,14 @@ fn get_module_roots_and_include_files(
include_files.push(url);
}
} else {
analyze_path(
&url,
&mut module_roots,
&mut include_files,
&mut searched_paths,
)?;
analyze_path(&url, &mut searched_paths, |file_url| {
if file_url != *output_url {
include_files.push(file_url.clone());
if is_module_graph_module(&file_url) {
module_roots.push(file_url);
}
}
})?;
}
}
Ok((module_roots, include_files))
Expand Down
16 changes: 16 additions & 0 deletions cli/tools/lint/ast_buffer/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,22 @@ impl SerializeCtx {
};
}

/// Helper for writing optional node offsets with undefined as empty value
pub fn write_maybe_undef_ref<P>(
&mut self,
prop: P,
parent: &PendingRef,
value: Option<NodeRef>,
) where
P: Into<u8> + Display + Clone,
{
if let Some(v) = value {
self.write_ref(prop, parent, v);
} else {
self.write_undefined(prop);
};
}

/// Write a vec of node offsets into the property. The necessary space
/// has been reserved earlier.
pub fn write_ref_vec<P>(
Expand Down
Loading

0 comments on commit 2560c0a

Please sign in to comment.