summaryrefslogtreecommitdiff
path: root/cli/tools/run
diff options
context:
space:
mode:
authorhaturau <135221985+haturatu@users.noreply.github.com>2024-11-20 01:20:47 +0900
committerGitHub <noreply@github.com>2024-11-20 01:20:47 +0900
commit85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch)
treeface0aecaac53e93ce2f23b53c48859bcf1a36ec /cli/tools/run
parent67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff)
parent186b52731c6bb326c4d32905c5e732d082e83465 (diff)
Merge branch 'denoland:main' into main
Diffstat (limited to 'cli/tools/run')
-rw-r--r--cli/tools/run/hmr.rs18
-rw-r--r--cli/tools/run/mod.rs21
2 files changed, 30 insertions, 9 deletions
diff --git a/cli/tools/run/hmr.rs b/cli/tools/run/hmr.rs
index 6ccf8e344..373c207d6 100644
--- a/cli/tools/run/hmr.rs
+++ b/cli/tools/run/hmr.rs
@@ -1,9 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-use crate::cdp;
-use crate::emit::Emitter;
-use crate::util::file_watcher::WatcherCommunicator;
-use crate::util::file_watcher::WatcherRestartMode;
+use std::collections::HashMap;
+use std::path::PathBuf;
+use std::sync::Arc;
+
use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::futures::StreamExt;
@@ -12,11 +12,13 @@ use deno_core::serde_json::{self};
use deno_core::url::Url;
use deno_core::LocalInspectorSession;
use deno_terminal::colors;
-use std::collections::HashMap;
-use std::path::PathBuf;
-use std::sync::Arc;
use tokio::select;
+use crate::cdp;
+use crate::emit::Emitter;
+use crate::util::file_watcher::WatcherCommunicator;
+use crate::util::file_watcher::WatcherRestartMode;
+
fn explain(status: &cdp::Status) -> &'static str {
match status {
cdp::Status::Ok => "OK",
@@ -139,7 +141,7 @@ impl crate::worker::HmrRunner for HmrRunner {
};
let source_code = self.emitter.load_and_emit_for_hmr(
- &module_url
+ &module_url,
).await?;
let mut tries = 1;
diff --git a/cli/tools/run/mod.rs b/cli/tools/run/mod.rs
index 152e2650b..8fab544ec 100644
--- a/cli/tools/run/mod.rs
+++ b/cli/tools/run/mod.rs
@@ -30,6 +30,16 @@ To grant permissions, set them before the script argument. For example:
}
}
+fn set_npm_user_agent() {
+ static ONCE: std::sync::Once = std::sync::Once::new();
+ ONCE.call_once(|| {
+ std::env::set_var(
+ crate::npm::NPM_CONFIG_USER_AGENT_ENV_VAR,
+ crate::npm::get_npm_config_user_agent(),
+ );
+ });
+}
+
pub async fn run_script(
mode: WorkerExecutionMode,
flags: Arc<Flags>,
@@ -58,6 +68,10 @@ pub async fn run_script(
let main_module = cli_options.resolve_main_module()?;
+ if main_module.scheme() == "npm" {
+ set_npm_user_agent();
+ }
+
maybe_npm_install(&factory).await?;
let worker_factory = factory.create_cli_main_worker_factory().await?;
@@ -110,7 +124,8 @@ async fn run_with_watch(
!watch_flags.no_clear_screen,
),
WatcherRestartMode::Automatic,
- move |flags, watcher_communicator, _changed_paths| {
+ move |flags, watcher_communicator, changed_paths| {
+ watcher_communicator.show_path_changed(changed_paths.clone());
Ok(async move {
let factory = CliFactory::from_flags_for_watcher(
flags,
@@ -119,6 +134,10 @@ async fn run_with_watch(
let cli_options = factory.cli_options()?;
let main_module = cli_options.resolve_main_module()?;
+ if main_module.scheme() == "npm" {
+ set_npm_user_agent();
+ }
+
maybe_npm_install(&factory).await?;
let _ = watcher_communicator.watch_paths(cli_options.watch_paths());