Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/rs_lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/rs_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ path = "../../deno/libs/npm_cache"
path = "../../deno/libs/npm_installer"
default-features = false

[dependencies.deno_package_json]
path = "../../deno/libs/package_json"
features = ["sync"]


Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

[dependencies.deno_resolver]
path = "../../deno/libs/resolver"
features = ["deno_ast","graph","sync"]
Expand All @@ -80,4 +85,4 @@ features = ["real","wasm"]
codegen-units = 1
incremental = true
lto = true
opt-level = "z"
opt-level = 3
32 changes: 27 additions & 5 deletions src/rs_lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::Mutex;
use std::sync::OnceLock;

use anyhow::Context;
Expand All @@ -31,6 +32,8 @@ use deno_npm_installer::NpmInstallerFactory;
use deno_npm_installer::NpmInstallerFactoryOptions;
use deno_npm_installer::Reporter;
use deno_npm_installer::lifecycle_scripts::NullLifecycleScriptsExecutor;
use deno_package_json::PackageJsonCacheResult;
use deno_package_json::PackageJsonRc;
use deno_resolver::DenoResolveError;
use deno_resolver::DenoResolveErrorKind;
use deno_resolver::cache::ParsedSourceCache;
Expand Down Expand Up @@ -71,7 +74,6 @@ use log::Metadata;
use log::Record;
use node_resolver::NodeConditionOptions;
use node_resolver::NodeResolverOptions;
use node_resolver::PackageJsonThreadLocalCache;
use node_resolver::analyze::NodeCodeTranslatorMode;
use node_resolver::cache::NodeResolutionThreadLocalCache;
use node_resolver::errors::NodeJsErrorCode;
Expand Down Expand Up @@ -188,9 +190,29 @@ pub struct DenoWorkspace {
workspace_factory: Arc<WorkspaceFactory<RealSys>>,
}

impl Drop for DenoWorkspace {
fn drop(&mut self) {
PackageJsonThreadLocalCache::clear();
#[derive(Debug)]
pub struct PackageJsonOwnedCache {
map: Mutex<std::collections::HashMap<PathBuf, Option<PackageJsonRc>>>,
}

impl PackageJsonOwnedCache {
pub fn new() -> Self {
Self {
map: Mutex::new(std::collections::HashMap::new()),
}
}
}

impl deno_package_json::PackageJsonCache for PackageJsonOwnedCache {
fn get(&self, path: &Path) -> PackageJsonCacheResult {
self.map.lock().unwrap().get(path).cloned().map_or_else(
|| PackageJsonCacheResult::NotCached,
|value| PackageJsonCacheResult::Hit(value),
)
}

fn set(&self, path: PathBuf, package_json: Option<PackageJsonRc>) {
self.map.lock().unwrap().insert(path, package_json);
}
}

Expand Down Expand Up @@ -301,7 +323,7 @@ impl DenoWorkspace {
node_analysis_cache: None,
node_code_translator_mode: NodeCodeTranslatorMode::Disabled,
node_resolution_cache: Some(Arc::new(NodeResolutionThreadLocalCache)),
package_json_cache: Some(Arc::new(PackageJsonThreadLocalCache)),
package_json_cache: Some(Arc::new(PackageJsonOwnedCache::new())),
package_json_dep_resolution: None,
specified_import_map: None,
bare_node_builtins: true,
Expand Down
Loading