summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/args/flags.rs4
-rw-r--r--cli/build.rs4
-rw-r--r--cli/cache/check.rs20
-rw-r--r--cli/cache/emit.rs12
-rw-r--r--cli/cache/incremental.rs25
-rw-r--r--cli/cache/node.rs2
-rw-r--r--cli/cache/parsed_source.rs23
-rw-r--r--cli/file_fetcher.rs11
-rw-r--r--cli/standalone.rs8
-rw-r--r--cli/tools/upgrade.rs10
-rw-r--r--cli/version.rs33
-rw-r--r--cli/worker.rs8
-rw-r--r--ext/fetch/lib.rs6
-rw-r--r--runtime/inspector_server.rs4
14 files changed, 91 insertions, 79 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 236352f24..e85938822 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -641,7 +641,7 @@ To evaluate code in the shell:
/// Main entry point for parsing deno's command line flags.
pub fn flags_from_vec(args: Vec<String>) -> clap::Result<Flags> {
let version = crate::version::deno();
- let mut app = clap_root(&version);
+ let mut app = clap_root(version);
let matches = app.try_get_matches_from_mut(&args)?;
let mut flags = Flags::default();
@@ -712,7 +712,7 @@ fn handle_repl_flags(flags: &mut Flags, repl_flags: ReplFlags) {
flags.subcommand = DenoSubcommand::Repl(repl_flags);
}
-fn clap_root(version: &str) -> Command {
+fn clap_root(version: &'static str) -> Command {
clap::Command::new("deno")
.bin_name("deno")
.color(ColorChoice::Never)
diff --git a/cli/build.rs b/cli/build.rs
index a4f8ee92d..bcf5a0a38 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -459,6 +459,10 @@ fn main() {
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH");
+ println!(
+ "cargo:rustc-env=GIT_COMMIT_HASH_SHORT={}",
+ &git_commit_hash()[..7]
+ );
let ts_version = ts::version();
debug_assert_eq!(ts_version, "5.0.2"); // bump this assertion when it changes
diff --git a/cli/cache/check.rs b/cli/cache/check.rs
index c8b5717ec..1bd410013 100644
--- a/cli/cache/check.rs
+++ b/cli/cache/check.rs
@@ -58,7 +58,7 @@ impl TypeCheckCache {
fn from_connection(
conn: Connection,
- cli_version: String,
+ cli_version: &'static str,
) -> Result<Self, AnyError> {
initialize(&conn, cli_version)?;
@@ -157,7 +157,10 @@ impl TypeCheckCache {
}
}
-fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
+fn initialize(
+ conn: &Connection,
+ cli_version: &'static str,
+) -> Result<(), AnyError> {
// INT doesn't store up to u64, so use TEXT for check_hash
let query = format!(
"{INITIAL_PRAGMAS}
@@ -184,12 +187,12 @@ fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
|row| row.get(0),
)
.ok();
- if data_cli_version.as_deref() != Some(&cli_version) {
+ if data_cli_version.as_deref() != Some(cli_version) {
conn.execute("DELETE FROM checkcache", params![])?;
conn.execute("DELETE FROM tsbuildinfo", params![])?;
let mut stmt = conn
.prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?;
- stmt.execute(params!["CLI_VERSION", &cli_version])?;
+ stmt.execute(params!["CLI_VERSION", cli_version])?;
}
Ok(())
@@ -202,8 +205,7 @@ mod test {
#[test]
pub fn check_cache_general_use() {
let conn = Connection::open_in_memory().unwrap();
- let cache =
- TypeCheckCache::from_connection(conn, "1.0.0".to_string()).unwrap();
+ let cache = TypeCheckCache::from_connection(conn, "1.0.0").unwrap();
assert!(!cache.has_check_hash(1));
cache.add_check_hash(1);
@@ -217,8 +219,7 @@ mod test {
// try changing the cli version (should clear)
let conn = cache.0.unwrap();
- let cache =
- TypeCheckCache::from_connection(conn, "2.0.0".to_string()).unwrap();
+ let cache = TypeCheckCache::from_connection(conn, "2.0.0").unwrap();
assert!(!cache.has_check_hash(1));
cache.add_check_hash(1);
assert!(cache.has_check_hash(1));
@@ -228,8 +229,7 @@ mod test {
// recreating the cache should not remove the data because the CLI version is the same
let conn = cache.0.unwrap();
- let cache =
- TypeCheckCache::from_connection(conn, "2.0.0".to_string()).unwrap();
+ let cache = TypeCheckCache::from_connection(conn, "2.0.0").unwrap();
assert!(cache.has_check_hash(1));
assert!(!cache.has_check_hash(2));
assert_eq!(cache.get_tsbuildinfo(&specifier1), Some("test".to_string()));
diff --git a/cli/cache/emit.rs b/cli/cache/emit.rs
index 89ff496fd..dd7b9e662 100644
--- a/cli/cache/emit.rs
+++ b/cli/cache/emit.rs
@@ -22,7 +22,7 @@ struct EmitMetadata {
#[derive(Clone)]
pub struct EmitCache {
disk_cache: DiskCache,
- cli_version: String,
+ cli_version: &'static str,
}
impl EmitCache {
@@ -58,7 +58,7 @@ impl EmitCache {
// load and verify the emit is for the meta data
let emit_bytes = self.disk_cache.get(&emit_filename).ok()?;
- if meta.emit_hash != compute_emit_hash(&emit_bytes, &self.cli_version) {
+ if meta.emit_hash != compute_emit_hash(&emit_bytes, self.cli_version) {
return None;
}
@@ -113,7 +113,7 @@ impl EmitCache {
// save the metadata
let metadata = EmitMetadata {
source_hash: source_hash.to_string(),
- emit_hash: compute_emit_hash(code.as_bytes(), &self.cli_version),
+ emit_hash: compute_emit_hash(code.as_bytes(), self.cli_version),
};
self
.disk_cache
@@ -162,7 +162,7 @@ mod test {
let disk_cache = DiskCache::new(temp_dir.path());
let cache = EmitCache {
disk_cache: disk_cache.clone(),
- cli_version: "1.0.0".to_string(),
+ cli_version: "1.0.0",
};
let specifier1 =
@@ -188,7 +188,7 @@ mod test {
// try changing the cli version (should not load previous ones)
let cache = EmitCache {
disk_cache: disk_cache.clone(),
- cli_version: "2.0.0".to_string(),
+ cli_version: "2.0.0",
};
assert_eq!(cache.get_emit_code(&specifier1, 10), None);
cache.set_emit_code(&specifier1, 5, &emit_code1);
@@ -196,7 +196,7 @@ mod test {
// recreating the cache should still load the data because the CLI version is the same
let cache = EmitCache {
disk_cache,
- cli_version: "2.0.0".to_string(),
+ cli_version: "2.0.0",
};
assert_eq!(cache.get_emit_code(&specifier1, 5), Some(emit_code1));
diff --git a/cli/cache/incremental.rs b/cli/cache/incremental.rs
index 88520a031..d5298071f 100644
--- a/cli/cache/incremental.rs
+++ b/cli/cache/incremental.rs
@@ -172,7 +172,7 @@ impl SqlIncrementalCache {
fn from_connection(
conn: Connection,
state_hash: u64,
- cli_version: String,
+ cli_version: &'static str,
) -> Result<Self, AnyError> {
initialize(&conn, cli_version)?;
@@ -237,7 +237,10 @@ impl SqlIncrementalCache {
}
}
-fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
+fn initialize(
+ conn: &Connection,
+ cli_version: &'static str,
+) -> Result<(), AnyError> {
// INT doesn't store up to u64, so use TEXT for source_hash
let query = format!(
"{INITIAL_PRAGMAS}
@@ -261,11 +264,11 @@ fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
|row| row.get(0),
)
.ok();
- if data_cli_version.as_deref() != Some(&cli_version) {
+ if data_cli_version.as_deref() != Some(cli_version) {
conn.execute("DELETE FROM incrementalcache", params![])?;
let mut stmt = conn
.prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?;
- stmt.execute(params!["CLI_VERSION", &cli_version])?;
+ stmt.execute(params!["CLI_VERSION", cli_version])?;
}
Ok(())
@@ -280,9 +283,7 @@ mod test {
#[test]
pub fn sql_cache_general_use() {
let conn = Connection::open_in_memory().unwrap();
- let cache =
- SqlIncrementalCache::from_connection(conn, 1, "1.0.0".to_string())
- .unwrap();
+ let cache = SqlIncrementalCache::from_connection(conn, 1, "1.0.0").unwrap();
let path = PathBuf::from("/mod.ts");
assert_eq!(cache.get_source_hash(&path), None);
@@ -292,8 +293,7 @@ mod test {
// try changing the cli version (should clear)
let conn = cache.conn;
let mut cache =
- SqlIncrementalCache::from_connection(conn, 1, "2.0.0".to_string())
- .unwrap();
+ SqlIncrementalCache::from_connection(conn, 1, "2.0.0").unwrap();
assert_eq!(cache.get_source_hash(&path), None);
// add back the file to the cache
@@ -310,9 +310,7 @@ mod test {
// recreating the cache should not remove the data because the CLI version and state hash is the same
let conn = cache.conn;
- let cache =
- SqlIncrementalCache::from_connection(conn, 1, "2.0.0".to_string())
- .unwrap();
+ let cache = SqlIncrementalCache::from_connection(conn, 1, "2.0.0").unwrap();
assert_eq!(cache.get_source_hash(&path), Some(2));
// now try replacing and using another path
@@ -328,8 +326,7 @@ mod test {
pub async fn incremental_cache_general_use() {
let conn = Connection::open_in_memory().unwrap();
let sql_cache =
- SqlIncrementalCache::from_connection(conn, 1, "1.0.0".to_string())
- .unwrap();
+ SqlIncrementalCache::from_connection(conn, 1, "1.0.0").unwrap();
let file_path = PathBuf::from("/mod.ts");
let file_text = "test";
let file_hash = FastInsecureHasher::new().write_str(file_text).finish();
diff --git a/cli/cache/node.rs b/cli/cache/node.rs
index e010c0dcd..19ac45d6b 100644
--- a/cli/cache/node.rs
+++ b/cli/cache/node.rs
@@ -102,7 +102,7 @@ impl NodeAnalysisCache {
None => {
let maybe_inner = match NodeAnalysisCacheInner::new(
self.db_file_path.as_deref(),
- crate::version::deno(),
+ crate::version::deno().to_string(),
) {
Ok(cache) => Some(cache),
Err(err) => {
diff --git a/cli/cache/parsed_source.rs b/cli/cache/parsed_source.rs
index 7b183ce86..2f27f0533 100644
--- a/cli/cache/parsed_source.rs
+++ b/cli/cache/parsed_source.rs
@@ -54,7 +54,7 @@ impl deno_graph::ParsedSourceStore for ParsedSourceCacheSources {
#[derive(Clone)]
pub struct ParsedSourceCache {
db_cache_path: Option<PathBuf>,
- cli_version: String,
+ cli_version: &'static str,
sources: ParsedSourceCacheSources,
}
@@ -70,7 +70,7 @@ impl ParsedSourceCache {
pub fn reset_for_file_watcher(&self) -> Self {
Self {
db_cache_path: self.db_cache_path.clone(),
- cli_version: self.cli_version.clone(),
+ cli_version: self.cli_version,
sources: Default::default(),
}
}
@@ -116,7 +116,7 @@ impl ParsedSourceCache {
pub fn as_analyzer(&self) -> Box<dyn deno_graph::ModuleAnalyzer> {
match ParsedSourceCacheModuleAnalyzer::new(
self.db_cache_path.as_deref(),
- self.cli_version.clone(),
+ self.cli_version,
self.sources.clone(),
) {
Ok(analyzer) => Box::new(analyzer),
@@ -146,7 +146,7 @@ struct ParsedSourceCacheModuleAnalyzer {
impl ParsedSourceCacheModuleAnalyzer {
pub fn new(
db_file_path: Option<&Path>,
- cli_version: String,
+ cli_version: &'static str,
sources: ParsedSourceCacheSources,
) -> Result<Self, AnyError> {
log::debug!("Loading cached module analyzer.");
@@ -159,7 +159,7 @@ impl ParsedSourceCacheModuleAnalyzer {
fn from_connection(
conn: Connection,
- cli_version: String,
+ cli_version: &'static str,
sources: ParsedSourceCacheSources,
) -> Result<Self, AnyError> {
initialize(&conn, cli_version)?;
@@ -287,7 +287,10 @@ impl deno_graph::ModuleAnalyzer for ParsedSourceCacheModuleAnalyzer {
}
}
-fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
+fn initialize(
+ conn: &Connection,
+ cli_version: &'static str,
+) -> Result<(), AnyError> {
let query = format!(
"{INITIAL_PRAGMAS}
-- INT doesn't store up to u64, so use TEXT for source_hash
@@ -314,7 +317,7 @@ fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
|row| row.get(0),
)
.ok();
- if data_cli_version.as_deref() != Some(&cli_version) {
+ if data_cli_version.as_deref() != Some(cli_version) {
conn.execute("DELETE FROM moduleinfocache", params![])?;
let mut stmt = conn
.prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?;
@@ -340,7 +343,7 @@ mod test {
let conn = Connection::open_in_memory().unwrap();
let cache = ParsedSourceCacheModuleAnalyzer::from_connection(
conn,
- "1.0.0".to_string(),
+ "1.0.0",
Default::default(),
)
.unwrap();
@@ -403,7 +406,7 @@ mod test {
let conn = cache.conn;
let cache = ParsedSourceCacheModuleAnalyzer::from_connection(
conn,
- "1.0.0".to_string(),
+ "1.0.0",
Default::default(),
)
.unwrap();
@@ -420,7 +423,7 @@ mod test {
let conn = cache.conn;
let cache = ParsedSourceCacheModuleAnalyzer::from_connection(
conn,
- "1.0.1".to_string(),
+ "1.0.1",
Default::default(),
)
.unwrap();
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index b1c601b9a..75c2c608f 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -1746,15 +1746,8 @@ mod tests {
fn create_test_client() -> HttpClient {
HttpClient::from_client(
- create_http_client(
- "test_client".to_string(),
- None,
- vec![],
- None,
- None,
- None,
- )
- .unwrap(),
+ create_http_client("test_client", None, vec![], None, None, None)
+ .unwrap(),
)
}
diff --git a/cli/standalone.rs b/cli/standalone.rs
index 254cb9de5..527e8d975 100644
--- a/cli/standalone.rs
+++ b/cli/standalone.rs
@@ -258,10 +258,10 @@ fn create_web_worker_callback(
location: Some(args.main_module.clone()),
no_color: !colors::use_color(),
is_tty: colors::is_tty(),
- runtime_version: version::deno(),
+ runtime_version: version::deno().to_string(),
ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.options.unstable(),
- user_agent: version::get_user_agent(),
+ user_agent: version::get_user_agent().to_string(),
inspect: ps.options.is_inspecting(),
},
extensions: ops::cli_exts(ps.clone()),
@@ -347,10 +347,10 @@ pub async fn run(
location: metadata.location,
no_color: !colors::use_color(),
is_tty: colors::is_tty(),
- runtime_version: version::deno(),
+ runtime_version: version::deno().to_string(),
ts_version: version::TYPESCRIPT.to_string(),
unstable: metadata.unstable,
- user_agent: version::get_user_agent(),
+ user_agent: version::get_user_agent().to_string(),
inspect: ps.options.is_inspecting(),
},
extensions: ops::cli_exts(ps.clone()),
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs
index 7ce9e77b9..933dad095 100644
--- a/cli/tools/upgrade.rs
+++ b/cli/tools/upgrade.rs
@@ -226,7 +226,7 @@ pub fn check_for_upgrades(http_client: HttpClient, cache_file_path: PathBuf) {
"{}",
colors::italic_gray("Run `deno upgrade` to install it.")
);
- print_release_notes(&version::deno(), &upgrade_version);
+ print_release_notes(version::deno(), &upgrade_version);
}
update_checker.store_prompted();
@@ -330,7 +330,7 @@ pub async fn upgrade(
let latest_hash = latest_version.clone();
crate::version::GIT_COMMIT_HASH == latest_hash
} else if !crate::version::is_canary() {
- let current = Version::parse_standard(&crate::version::deno()).unwrap();
+ let current = Version::parse_standard(crate::version::deno()).unwrap();
let latest = Version::parse_standard(&latest_version).unwrap();
current >= latest
} else {
@@ -344,7 +344,7 @@ pub async fn upgrade(
log::info!(
"Local deno version {} is the most recent release",
if upgrade_flags.canary {
- crate::version::GIT_COMMIT_HASH.to_string()
+ crate::version::GIT_COMMIT_HASH
} else {
crate::version::deno()
}
@@ -388,7 +388,7 @@ pub async fn upgrade(
fs::remove_file(&new_exe_path)?;
log::info!("Upgraded successfully (dry run)");
if !upgrade_flags.canary {
- print_release_notes(&version::deno(), &install_version);
+ print_release_notes(version::deno(), &install_version);
}
} else {
let output_exe_path =
@@ -422,7 +422,7 @@ pub async fn upgrade(
}
log::info!("Upgraded successfully");
if !upgrade_flags.canary {
- print_release_notes(&version::deno(), &install_version);
+ print_release_notes(version::deno(), &install_version);
}
}
diff --git a/cli/version.rs b/cli/version.rs
index 88dc9ffc7..f13baa1f2 100644
--- a/cli/version.rs
+++ b/cli/version.rs
@@ -3,11 +3,30 @@
pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
pub const TYPESCRIPT: &str = env!("TS_VERSION");
-pub fn deno() -> String {
- let version = env!("CARGO_PKG_VERSION");
- option_env!("DENO_CANARY")
- .map(|_| format!("{}+{}", version, &GIT_COMMIT_HASH[..7]))
- .unwrap_or_else(|| version.to_string())
+pub fn deno() -> &'static str {
+ if is_canary() {
+ concat!(
+ env!("CARGO_PKG_VERSION"),
+ "+",
+ env!("GIT_COMMIT_HASH_SHORT")
+ )
+ } else {
+ env!("CARGO_PKG_VERSION")
+ }
+}
+
+// Keep this in sync with `deno()` above
+pub fn get_user_agent() -> &'static str {
+ if is_canary() {
+ concat!(
+ "Deno/",
+ env!("CARGO_PKG_VERSION"),
+ "+",
+ env!("GIT_COMMIT_HASH_SHORT")
+ )
+ } else {
+ concat!("Deno/", env!("CARGO_PKG_VERSION"))
+ }
}
pub fn is_canary() -> bool {
@@ -21,7 +40,3 @@ pub fn release_version_or_canary_commit_hash() -> &'static str {
env!("CARGO_PKG_VERSION")
}
}
-
-pub fn get_user_agent() -> String {
- format!("Deno/{}", deno())
-}
diff --git a/cli/worker.rs b/cli/worker.rs
index a0168a1f3..23dd63119 100644
--- a/cli/worker.rs
+++ b/cli/worker.rs
@@ -517,10 +517,10 @@ async fn create_main_worker_internal(
location: ps.options.location_flag().clone(),
no_color: !colors::use_color(),
is_tty: colors::is_tty(),
- runtime_version: version::deno(),
+ runtime_version: version::deno().to_string(),
ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.options.unstable(),
- user_agent: version::get_user_agent(),
+ user_agent: version::get_user_agent().to_string(),
inspect: ps.options.is_inspecting(),
},
extensions,
@@ -685,10 +685,10 @@ fn create_web_worker_callback(
location: Some(args.main_module.clone()),
no_color: !colors::use_color(),
is_tty: colors::is_tty(),
- runtime_version: version::deno(),
+ runtime_version: version::deno().to_string(),
ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.options.unstable(),
- user_agent: version::get_user_agent(),
+ user_agent: version::get_user_agent().to_string(),
inspect: ps.options.is_inspecting(),
},
extensions,
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs
index 9ed73161d..17f30d8ed 100644
--- a/ext/fetch/lib.rs
+++ b/ext/fetch/lib.rs
@@ -114,7 +114,7 @@ deno_core::extension!(deno_fetch,
state.put::<Options>(options.options.clone());
state.put::<reqwest::Client>({
create_http_client(
- options.options.user_agent,
+ &options.options.user_agent,
options.options.root_cert_store,
vec![],
options.options.proxy,
@@ -631,7 +631,7 @@ where
.collect::<Vec<_>>();
let client = create_http_client(
- options.user_agent.clone(),
+ &options.user_agent,
options.root_cert_store.clone(),
ca_certs,
args.proxy,
@@ -646,7 +646,7 @@ where
/// Create new instance of async reqwest::Client. This client supports
/// proxies and doesn't follow redirects.
pub fn create_http_client(
- user_agent: String,
+ user_agent: &str,
root_cert_store: Option<RootCertStore>,
ca_certs: Vec<Vec<u8>>,
proxy: Option<Proxy>,
diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs
index e5f3a4f09..d65e813cb 100644
--- a/runtime/inspector_server.rs
+++ b/runtime/inspector_server.rs
@@ -40,7 +40,7 @@ pub struct InspectorServer {
}
impl InspectorServer {
- pub fn new(host: SocketAddr, name: String) -> Self {
+ pub fn new(host: SocketAddr, name: &'static str) -> Self {
let (register_inspector_tx, register_inspector_rx) =
mpsc::unbounded::<InspectorInfo>();
@@ -220,7 +220,7 @@ async fn server(
host: SocketAddr,
register_inspector_rx: UnboundedReceiver<InspectorInfo>,
shutdown_server_rx: oneshot::Receiver<()>,
- name: String,
+ name: &str,
) {
let inspector_map_ =
Rc::new(RefCell::new(HashMap::<Uuid, InspectorInfo>::new()));