Skip to content

Commit

Permalink
feat: expose added/removed compilation.*_dependencies to js side (#7522)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz authored Aug 9, 2024
1 parent d49b34f commit 3867fe0
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 100 deletions.
29 changes: 21 additions & 8 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ export class DependenciesBlockDto {
}
export type DependenciesBlockDTO = DependenciesBlockDto

export class DependenciesDto {
get fileDependencies(): Array<string>
get addedFileDependencies(): Array<string>
get removedFileDependencies(): Array<string>
get contextDependencies(): Array<string>
get addedContextDependencies(): Array<string>
get removedContextDependencies(): Array<string>
get missingDependencies(): Array<string>
get addedMissingDependencies(): Array<string>
get removedMissingDependencies(): Array<string>
get buildDependencies(): Array<string>
get addedBuildDependencies(): Array<string>
get removedBuildDependencies(): Array<string>
}
export type DependenciesDTO = DependenciesDto

export class DependencyDto {
get type(): string
get category(): string
Expand All @@ -33,8 +49,8 @@ export class DependencyDto {
export type DependencyDTO = DependencyDto

export class EntryDataDto {
get dependencies(): Array<DependencyDto>
get includeDependencies(): Array<DependencyDto>
get dependencies(): Array<DependencyDTO>
get includeDependencies(): Array<DependencyDTO>
get options(): EntryOptionsDto
}
export type EntryDataDTO = EntryDataDto
Expand Down Expand Up @@ -82,10 +98,7 @@ export class JsCompilation {
get entrypoints(): Record<string, JsChunkGroup>
get chunkGroups(): Array<JsChunkGroup>
get hash(): string | null
getFileDependencies(): Array<string>
getContextDependencies(): Array<string>
getMissingDependencies(): Array<string>
getBuildDependencies(): Array<string>
dependencies(): DependenciesDto
pushDiagnostic(diagnostic: JsDiagnostic): void
spliceDiagnostic(start: number, end: number, replaceWith: Array<JsDiagnostic>): void
pushNativeDiagnostics(diagnostics: ExternalObject<'Diagnostic[]'>): void
Expand Down Expand Up @@ -436,8 +449,8 @@ export interface JsDiagnostic {
}

export interface JsEntryData {
dependencies: Array<DependencyDto>
includeDependencies: Array<DependencyDto>
dependencies: Array<DependencyDTO>
includeDependencies: Array<DependencyDTO>
options: JsEntryOptions
}

Expand Down
128 changes: 128 additions & 0 deletions crates/rspack_binding_values/src/compilation/dependencies.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
use napi_derive::napi;
use rspack_core::Compilation;

#[napi]
pub struct DependenciesDTO {
pub(crate) compilation: &'static Compilation,
}

impl DependenciesDTO {
pub(crate) fn new(compilation: &'static Compilation) -> Self {
Self { compilation }
}
}

#[napi]
impl DependenciesDTO {
#[napi(getter)]
pub fn file_dependencies(&self) -> Vec<String> {
self
.compilation
.file_dependencies()
.0
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn added_file_dependencies(&self) -> Vec<String> {
self
.compilation
.file_dependencies()
.1
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn removed_file_dependencies(&self) -> Vec<String> {
self
.compilation
.file_dependencies()
.2
.map(|i| i.to_string_lossy().to_string())
.collect()
}

#[napi(getter)]
pub fn context_dependencies(&self) -> Vec<String> {
self
.compilation
.context_dependencies()
.0
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn added_context_dependencies(&self) -> Vec<String> {
self
.compilation
.context_dependencies()
.1
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn removed_context_dependencies(&self) -> Vec<String> {
self
.compilation
.context_dependencies()
.2
.map(|i| i.to_string_lossy().to_string())
.collect()
}

#[napi(getter)]
pub fn missing_dependencies(&self) -> Vec<String> {
self
.compilation
.missing_dependencies()
.0
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn added_missing_dependencies(&self) -> Vec<String> {
self
.compilation
.missing_dependencies()
.1
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn removed_missing_dependencies(&self) -> Vec<String> {
self
.compilation
.missing_dependencies()
.2
.map(|i| i.to_string_lossy().to_string())
.collect()
}

#[napi(getter)]
pub fn build_dependencies(&self) -> Vec<String> {
self
.compilation
.build_dependencies()
.0
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn added_build_dependencies(&self) -> Vec<String> {
self
.compilation
.build_dependencies()
.1
.map(|i| i.to_string_lossy().to_string())
.collect()
}
#[napi(getter)]
pub fn removed_build_dependencies(&self) -> Vec<String> {
self
.compilation
.build_dependencies()
.2
.map(|i| i.to_string_lossy().to_string())
.collect()
}
}
3 changes: 1 addition & 2 deletions crates/rspack_binding_values/src/compilation/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use napi_derive::napi;
use rspack_core::{ChunkLoading, Compilation, EntryData, EntryOptions, EntryRuntime};
use rspack_napi::napi::bindgen_prelude::*;

use super::dependency::DependencyDTO;
use crate::{entry::JsEntryOptions, library::JsLibraryOptions};
use crate::{dependency::DependencyDTO, entry::JsEntryOptions, library::JsLibraryOptions};

#[napi]
pub struct EntryOptionsDTO(EntryOptions);
Expand Down
39 changes: 4 additions & 35 deletions crates/rspack_binding_values/src/compilation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod dependency;
mod dependencies;
mod entries;

use std::cell::RefCell;
Expand All @@ -7,7 +7,7 @@ use std::ops::Deref;
use std::ops::DerefMut;
use std::path::PathBuf;

pub use dependency::*;
use dependencies::DependenciesDTO;
use entries::JsEntries;
use napi_derive::napi;
use rspack_collections::IdentifierSet;
Expand Down Expand Up @@ -305,39 +305,8 @@ impl JsCompilation {
}

#[napi]
pub fn get_file_dependencies(&self) -> Vec<String> {
self
.0
.file_dependencies()
.map(|i| i.to_string_lossy().to_string())
.collect()
}

#[napi]
pub fn get_context_dependencies(&self) -> Vec<String> {
self
.0
.context_dependencies()
.map(|i| i.to_string_lossy().to_string())
.collect()
}

#[napi]
pub fn get_missing_dependencies(&self) -> Vec<String> {
self
.0
.missing_dependencies()
.map(|i| i.to_string_lossy().to_string())
.collect()
}

#[napi]
pub fn get_build_dependencies(&self) -> Vec<String> {
self
.0
.build_dependencies()
.map(|i| i.to_string_lossy().to_string())
.collect()
pub fn dependencies(&'static self) -> DependenciesDTO {
DependenciesDTO::new(self.0)
}

#[napi]
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_binding_values/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod chunk_group;
mod codegen_result;
mod compilation;
mod context_module_factory;
mod dependency;
mod filename;
mod identifier;
mod module;
Expand All @@ -30,6 +31,7 @@ pub use chunk_group::*;
pub use codegen_result::*;
pub use compilation::*;
pub use context_module_factory::*;
pub use dependency::DependencyDTO;
pub use filename::*;
pub use module::*;
pub use normal_module_factory::*;
Expand Down
Loading

2 comments on commit 3867fe0

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ❌ failure
rsbuild ❌ failure
examples ❌ failure

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-08-08 2bd905d) Current Change
10000_development-mode + exec 2.32 s ± 27 ms 2.31 s ± 33 ms -0.39 %
10000_development-mode_hmr + exec 701 ms ± 7.3 ms 700 ms ± 6 ms -0.18 %
10000_production-mode + exec 2.85 s ± 23 ms 2.86 s ± 35 ms +0.40 %
arco-pro_development-mode + exec 1.89 s ± 75 ms 1.89 s ± 101 ms -0.02 %
arco-pro_development-mode_hmr + exec 434 ms ± 2.4 ms 435 ms ± 0.45 ms +0.25 %
arco-pro_production-mode + exec 3.52 s ± 286 ms 3.43 s ± 86 ms -2.52 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.54 s ± 235 ms 3.49 s ± 63 ms -1.46 %
threejs_development-mode_10x + exec 1.72 s ± 15 ms 1.7 s ± 17 ms -0.99 %
threejs_development-mode_10x_hmr + exec 826 ms ± 9.5 ms 818 ms ± 4.7 ms -1.01 %
threejs_production-mode_10x + exec 5.53 s ± 29 ms 5.48 s ± 19 ms -0.98 %

Please sign in to comment.