summaryrefslogtreecommitdiff
path: root/cli/npm
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-11-11 09:01:48 -0800
committerGitHub <noreply@github.com>2023-11-11 17:01:48 +0000
commit9f4a45561f4a01019cdbff86e2056de0296e791b (patch)
treea9c2c4b1664d6f4640115345882ae068c1a5a216 /cli/npm
parent56e76242f3d7082e412bc698ebc737d24910cb60 (diff)
perf: snapshot runtime ops (#21127)
Closes https://github.com/denoland/deno/issues/21135 ~1ms startup time improvement --------- Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com> Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
Diffstat (limited to 'cli/npm')
-rw-r--r--cli/npm/byonm.rs20
-rw-r--r--cli/npm/managed/mod.rs34
-rw-r--r--cli/npm/mod.rs3
3 files changed, 27 insertions, 30 deletions
diff --git a/cli/npm/byonm.rs b/cli/npm/byonm.rs
index da36e3b53..469f98828 100644
--- a/cli/npm/byonm.rs
+++ b/cli/npm/byonm.rs
@@ -82,6 +82,16 @@ impl ByonmCliNpmResolver {
}
impl NpmResolver for ByonmCliNpmResolver {
+ fn get_npm_process_state(&self) -> String {
+ serde_json::to_string(&NpmProcessState {
+ kind: NpmProcessStateKind::Byonm,
+ local_node_modules_path: Some(
+ self.root_node_modules_dir.to_string_lossy().to_string(),
+ ),
+ })
+ .unwrap()
+ }
+
fn resolve_package_folder_from_package(
&self,
name: &str,
@@ -248,16 +258,6 @@ impl CliNpmResolver for ByonmCliNpmResolver {
)
}
- fn get_npm_process_state(&self) -> String {
- serde_json::to_string(&NpmProcessState {
- kind: NpmProcessStateKind::Byonm,
- local_node_modules_path: Some(
- self.root_node_modules_dir.to_string_lossy().to_string(),
- ),
- })
- .unwrap()
- }
-
fn check_state_hash(&self) -> Option<u64> {
// it is very difficult to determine the check state hash for byonm
// so we just return None to signify check caching is not supported
diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs
index d59b81912..6cf7e6a32 100644
--- a/cli/npm/managed/mod.rs
+++ b/cli/npm/managed/mod.rs
@@ -492,6 +492,23 @@ impl ManagedCliNpmResolver {
}
impl NpmResolver for ManagedCliNpmResolver {
+ /// Gets the state of npm for the process.
+ fn get_npm_process_state(&self) -> String {
+ serde_json::to_string(&NpmProcessState {
+ kind: NpmProcessStateKind::Snapshot(
+ self
+ .resolution
+ .serialized_valid_snapshot()
+ .into_serialized(),
+ ),
+ local_node_modules_path: self
+ .fs_resolver
+ .node_modules_path()
+ .map(|p| p.to_string_lossy().to_string()),
+ })
+ .unwrap()
+ }
+
fn resolve_package_folder_from_package(
&self,
name: &str,
@@ -571,23 +588,6 @@ impl CliNpmResolver for ManagedCliNpmResolver {
self.resolve_pkg_folder_from_pkg_id(&pkg_id)
}
- /// Gets the state of npm for the process.
- fn get_npm_process_state(&self) -> String {
- serde_json::to_string(&NpmProcessState {
- kind: NpmProcessStateKind::Snapshot(
- self
- .resolution
- .serialized_valid_snapshot()
- .into_serialized(),
- ),
- local_node_modules_path: self
- .fs_resolver
- .node_modules_path()
- .map(|p| p.to_string_lossy().to_string()),
- })
- .unwrap()
- }
-
fn check_state_hash(&self) -> Option<u64> {
// We could go further and check all the individual
// npm packages, but that's probably overkill.
diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs
index c9f261ccd..f4ea08186 100644
--- a/cli/npm/mod.rs
+++ b/cli/npm/mod.rs
@@ -83,9 +83,6 @@ pub trait CliNpmResolver: NpmResolver {
referrer: &ModuleSpecifier,
) -> Result<PathBuf, AnyError>;
- /// Gets the state of npm for the process.
- fn get_npm_process_state(&self) -> String;
-
/// Returns a hash returning the state of the npm resolver
/// or `None` if the state currently can't be determined.
fn check_state_hash(&self) -> Option<u64>;