Skip to content

Commit 2560c0a

Browse files
committed
Merge remote-tracking branch 'upstream/main' into lsp-cancellation-for-blocking
2 parents 85fca86 + 615bf8a commit 2560c0a

File tree

13 files changed

+4696
-1015
lines changed

13 files changed

+4696
-1015
lines changed

cli/standalone/binary.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use capacity_builder::BytesAppendable;
1616
use deno_ast::MediaType;
1717
use deno_ast::ModuleKind;
1818
use deno_ast::ModuleSpecifier;
19+
use deno_cache_dir::CACHE_PERM;
1920
use deno_core::anyhow::bail;
2021
use deno_core::anyhow::Context;
2122
use deno_core::error::AnyError;
@@ -46,6 +47,7 @@ use deno_lib::util::hash::FastInsecureHasher;
4647
use deno_lib::version::DENO_VERSION_INFO;
4748
use deno_npm::resolution::SerializedNpmResolutionSnapshot;
4849
use deno_npm::NpmSystemInfo;
50+
use deno_path_util::fs::atomic_write_file_with_retries;
4951
use deno_path_util::url_from_directory_path;
5052
use deno_path_util::url_to_file_path;
5153
use deno_resolver::workspace::WorkspaceResolver;
@@ -285,17 +287,17 @@ impl<'a> DenoCompileBinaryWriter<'a> {
285287
let download_directory = self.deno_dir.dl_folder_path();
286288
let binary_path = download_directory.join(&binary_path_suffix);
287289

288-
if !binary_path.exists() {
289-
self
290-
.download_base_binary(&download_directory, &binary_path_suffix)
291-
.await
292-
.context("Setting up base binary.")?;
293-
}
294-
295290
let read_file = |path: &Path| -> Result<Vec<u8>, AnyError> {
296291
std::fs::read(path).with_context(|| format!("Reading {}", path.display()))
297292
};
298-
let archive_data = read_file(&binary_path)?;
293+
let archive_data = if binary_path.exists() {
294+
read_file(&binary_path)?
295+
} else {
296+
self
297+
.download_base_binary(&binary_path, &binary_path_suffix)
298+
.await
299+
.context("Setting up base binary.")?
300+
};
299301
let temp_dir = tempfile::TempDir::new()?;
300302
let base_binary_path = archive::unpack_into_dir(archive::UnpackArgs {
301303
exe_name: "denort",
@@ -311,9 +313,9 @@ impl<'a> DenoCompileBinaryWriter<'a> {
311313

312314
async fn download_base_binary(
313315
&self,
314-
output_directory: &Path,
316+
output_path: &Path,
315317
binary_path_suffix: &str,
316-
) -> Result<(), AnyError> {
318+
) -> Result<Vec<u8>, AnyError> {
317319
let download_url = format!("https://dl.deno.land/{binary_path_suffix}");
318320
let maybe_bytes = {
319321
let progress_bars = ProgressBar::new(ProgressBarStyle::DownloadBars);
@@ -340,12 +342,15 @@ impl<'a> DenoCompileBinaryWriter<'a> {
340342
std::fs::create_dir_all(dir)
341343
.with_context(|| format!("Creating {}", dir.display()))
342344
};
343-
create_dir_all(output_directory)?;
344-
let output_path = output_directory.join(binary_path_suffix);
345345
create_dir_all(output_path.parent().unwrap())?;
346-
std::fs::write(&output_path, bytes)
347-
.with_context(|| format!("Writing {}", output_path.display()))?;
348-
Ok(())
346+
atomic_write_file_with_retries(
347+
&CliSys::default(),
348+
output_path,
349+
&bytes,
350+
CACHE_PERM,
351+
)
352+
.with_context(|| format!("Writing {}", output_path.display()))?;
353+
Ok(bytes)
349354
}
350355

351356
/// This functions creates a standalone deno binary by appending a bundle

cli/tools/compile.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ pub async fn compile(
3737
let binary_writer = factory.create_compile_binary_writer().await?;
3838
let http_client = factory.http_client_provider();
3939
let entrypoint = cli_options.resolve_main_module()?;
40-
let (module_roots, include_files) = get_module_roots_and_include_files(
41-
entrypoint,
42-
&compile_flags,
43-
cli_options.initial_cwd(),
44-
)?;
45-
4640
let output_path = resolve_compile_executable_output_path(
4741
http_client,
4842
&compile_flags,
4943
cli_options.initial_cwd(),
5044
)
5145
.await?;
46+
let (module_roots, include_files) = get_module_roots_and_include_files(
47+
entrypoint,
48+
&url_from_file_path(&cli_options.initial_cwd().join(&output_path))?,
49+
&compile_flags,
50+
cli_options.initial_cwd(),
51+
)?;
5252

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

199199
fn get_module_roots_and_include_files(
200200
entrypoint: &ModuleSpecifier,
201+
output_url: &ModuleSpecifier,
201202
compile_flags: &CompileFlags,
202203
initial_cwd: &Path,
203204
) -> Result<(Vec<ModuleSpecifier>, Vec<ModuleSpecifier>), AnyError> {
@@ -226,9 +227,8 @@ fn get_module_roots_and_include_files(
226227

227228
fn analyze_path(
228229
url: &ModuleSpecifier,
229-
module_roots: &mut Vec<ModuleSpecifier>,
230-
include_files: &mut Vec<ModuleSpecifier>,
231230
searched_paths: &mut HashSet<PathBuf>,
231+
mut add_url: impl FnMut(ModuleSpecifier),
232232
) -> Result<(), AnyError> {
233233
let Ok(path) = url_to_file_path(url) else {
234234
return Ok(());
@@ -240,10 +240,7 @@ fn get_module_roots_and_include_files(
240240
}
241241
if !path.is_dir() {
242242
let url = url_from_file_path(&path)?;
243-
include_files.push(url.clone());
244-
if is_module_graph_module(&url) {
245-
module_roots.push(url);
246-
}
243+
add_url(url);
247244
continue;
248245
}
249246
for entry in std::fs::read_dir(&path).with_context(|| {
@@ -270,12 +267,14 @@ fn get_module_roots_and_include_files(
270267
include_files.push(url);
271268
}
272269
} else {
273-
analyze_path(
274-
&url,
275-
&mut module_roots,
276-
&mut include_files,
277-
&mut searched_paths,
278-
)?;
270+
analyze_path(&url, &mut searched_paths, |file_url| {
271+
if file_url != *output_url {
272+
include_files.push(file_url.clone());
273+
if is_module_graph_module(&file_url) {
274+
module_roots.push(file_url);
275+
}
276+
}
277+
})?;
279278
}
280279
}
281280
Ok((module_roots, include_files))

cli/tools/lint/ast_buffer/buffer.rs

+16
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,22 @@ impl SerializeCtx {
485485
};
486486
}
487487

488+
/// Helper for writing optional node offsets with undefined as empty value
489+
pub fn write_maybe_undef_ref<P>(
490+
&mut self,
491+
prop: P,
492+
parent: &PendingRef,
493+
value: Option<NodeRef>,
494+
) where
495+
P: Into<u8> + Display + Clone,
496+
{
497+
if let Some(v) = value {
498+
self.write_ref(prop, parent, v);
499+
} else {
500+
self.write_undefined(prop);
501+
};
502+
}
503+
488504
/// Write a vec of node offsets into the property. The necessary space
489505
/// has been reserved earlier.
490506
pub fn write_ref_vec<P>(

0 commit comments

Comments
 (0)