Skip to content

Commit

Permalink
feat: deprecate JavaScript API (part 2) (#6859)
Browse files Browse the repository at this point in the history
* feat: init

* fix

* fix

* fix
  • Loading branch information
h-a-n-a authored Jun 19, 2024
1 parent 7f9b563 commit 87a73c3
Show file tree
Hide file tree
Showing 199 changed files with 363 additions and 386 deletions.
2 changes: 1 addition & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export interface JsChunk {
hash?: string
contentHash: Record<string, string>
renderedHash?: string
chunkReasons: Array<string>
chunkReason: Array<string>
auxiliaryFiles: Array<string>
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_binding_values/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct JsChunk {
pub hash: Option<String>,
pub content_hash: HashMap<String, String>,
pub rendered_hash: Option<String>,
pub chunk_reasons: Vec<String>,
pub chunk_reason: Vec<String>,
pub auxiliary_files: Vec<String>,
}

Expand All @@ -48,7 +48,7 @@ impl JsChunk {
hash,
rendered_hash,
content_hash,
chunk_reasons,
chunk_reason,
} = chunk;
let mut files = Vec::from_iter(files.iter().cloned());
files.sort_unstable();
Expand Down Expand Up @@ -82,7 +82,7 @@ impl JsChunk {
.map(|(key, v)| (key.to_string(), v.encoded().to_string()))
.collect::<std::collections::HashMap<String, String>>(),
rendered_hash: rendered_hash.as_ref().map(|hash| hash.to_string()),
chunk_reasons: chunk_reasons.clone(),
chunk_reason: chunk_reason.clone(),
auxiliary_files,
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<'me> CodeSplitter<'me> {
if let Some(filename) = &entry_data.options.filename {
chunk.filename_template = Some(filename.clone().into());
}
chunk.chunk_reasons.push(format!("Entrypoint({name})",));
chunk.chunk_reason.push(format!("Entrypoint({name})",));

self.compilation.chunk_graph.add_chunk(chunk.ukey);

Expand Down Expand Up @@ -582,7 +582,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
self.mask_by_chunk.insert(chunk_ukey, BigUint::from(0u32));
let chunk = self.compilation.chunk_by_ukey.expect_get_mut(&chunk_ukey);
chunk.prevent_integration = true;
chunk.chunk_reasons.push(format!("RuntimeChunk({name})",));
chunk.chunk_reason.push(format!("RuntimeChunk({name})",));
self.compilation.chunk_graph.add_chunk(chunk.ukey);
runtime_chunks.insert(chunk.ukey);
chunk
Expand Down Expand Up @@ -1181,7 +1181,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
chunk.filename_template = Some(filename.clone().into());
}
chunk
.chunk_reasons
.chunk_reason
.push(format!("AsyncEntrypoint({:?})", block_id));
let mut entrypoint = ChunkGroup::new(ChunkGroupKind::new_entrypoint(
false,
Expand Down Expand Up @@ -1276,7 +1276,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
let mut chunk_group = add_chunk_in_group(block.get_group_options());
let chunk = self.compilation.chunk_by_ukey.expect_get_mut(&chunk_ukey);
chunk
.chunk_reasons
.chunk_reason
.push(format!("DynamicImport({:?})", block_id));

let info = ChunkGroupInfo::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Chunk {
pub hash: Option<RspackHashDigest>,
pub rendered_hash: Option<Arc<str>>,
pub content_hash: ChunkContentHash,
pub chunk_reasons: Vec<String>,
pub chunk_reason: Vec<String>,
}

impl DatabaseItem for Chunk {
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Chunk {
hash: None,
rendered_hash: None,
content_hash: HashMap::default(),
chunk_reasons: Default::default(),
chunk_reason: Default::default(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_split_chunks/src/plugin/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl SplitChunksPlugin {
);
let new_chunk = compilation.chunk_by_ukey.expect_get_mut(&new_chunk_ukey);
new_chunk
.chunk_reasons
.chunk_reason
.push("Create by split chunks".to_string());
compilation.chunk_graph.add_chunk(new_chunk.ukey);
new_chunk.ukey
Expand All @@ -116,7 +116,7 @@ impl SplitChunksPlugin {
let new_chunk_ukey = Compilation::add_chunk(&mut compilation.chunk_by_ukey);
let new_chunk = compilation.chunk_by_ukey.expect_get_mut(&new_chunk_ukey);
new_chunk
.chunk_reasons
.chunk_reason
.push("Create by split chunks".to_string());
compilation.chunk_graph.add_chunk(new_chunk.ukey);
new_chunk.ukey
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_split_chunks/src/plugin/max_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl SplitChunksPlugin {
if max_size_setting.is_none()
&& !(fallback_cache_group.chunks_filter)(chunk, chunk_group_db)?
{
tracing::debug!("Chunk({}) skips `maxSize` checking. Reason: max_size_setting.is_none() and chunks_filter is false", chunk.chunk_reasons.join("~"));
tracing::debug!("Chunk({}) skips `maxSize` checking. Reason: max_size_setting.is_none() and chunks_filter is false", chunk.chunk_reason.join("~"));
return Ok(None);
}

Expand Down Expand Up @@ -257,7 +257,7 @@ impl SplitChunksPlugin {
if allow_max_size.is_empty() {
tracing::debug!(
"Chunk({}) skips the `maxSize` checking. Reason: allow_max_size is empty",
chunk.chunk_reasons.join("~")
chunk.chunk_reason.join("~")
);
return Ok(None);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_split_chunks/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ impl SplitChunksPlugin {
);

let new_chunk_mut = new_chunk.as_mut(&mut compilation.chunk_by_ukey);
tracing::trace!("{module_group_key}, get Chunk {} with is_reuse_existing_chunk: {is_reuse_existing_chunk:?} and {is_reuse_existing_chunk_with_all_modules:?}", new_chunk_mut.chunk_reasons.join("~"));
tracing::trace!("{module_group_key}, get Chunk {} with is_reuse_existing_chunk: {is_reuse_existing_chunk:?} and {is_reuse_existing_chunk_with_all_modules:?}", new_chunk_mut.chunk_reason.join("~"));

new_chunk_mut
.chunk_reasons
.chunk_reason
.push(["(cache group: ", cache_group.key.as_str(), ")"].join(""));

if let Some(filename) = &cache_group.filename {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

## Manifest


## Update
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"c":["main"],"r":[],"m":[]}
```


## Update


Expand Down
20 changes: 11 additions & 9 deletions packages/rspack-test-tools/src/processor/hot-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
} from "../type";
import { HotProcessor, IHotProcessorOptions } from "./hot";

const NOOP_SET = new Set();

const escapeLocalName = (str: string) => str.split(/[-<>:"/|?*.]/).join("_");

type TModuleGetHandler = (
Expand Down Expand Up @@ -93,11 +95,11 @@ export class HotSnapshotProcessor<
assets: true,
chunks: true
});
for (let entry of ((stats?.compilation.chunks as Chunk[]) || []).filter(
i => i.hasRuntime()
)) {
// @ts-expect-error: Some chunk fields are missing from rspack
let chunks = Array.from(stats?.compilation.chunks || NOOP_SET);
for (let entry of chunks.filter(i => i.hasRuntime())) {
if (!this.entries[entry.id!]) {
this.entries[entry.id!] = entry.runtime!;
this.entries[entry.id!] = Array.from(entry.runtime);
}
}
this.matchStepSnapshot(
Expand Down Expand Up @@ -132,10 +134,10 @@ export class HotSnapshotProcessor<
return;
}
const statsJson = stats.toJson({ assets: true, chunks: true });
for (let entry of ((stats?.compilation.chunks as Chunk[]) || []).filter(i =>
i.hasRuntime()
)) {
this.entries[entry.id!] = entry.runtime!;
// @ts-expect-error: Some chunk fields are missing from rspack
let chunks = Array.from(stats?.compilation.chunks || NOOP_SET);
for (let entry of chunks.filter(i => i.hasRuntime())) {
this.entries[entry.id!] = Array.from(entry.runtime);
}
let matchFailed: Error | null = null;
try {
Expand Down Expand Up @@ -302,7 +304,7 @@ ${i.content}
`
)
.join("\n\n")}
## Update
${hotUpdateFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MyPlugin {

compilation.hooks.afterOptimizeModules.tap("MyPlugin", modules => {
expect(a).toBeGreaterThan(1);
modules = [...modules];
expect(modules.length).toEqual(1);
expect(modules[0].resource.includes("d.js")).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class MyPlugin {
apply(compiler) {
compiler.hooks.compilation.tap("MyPlugin", compilation => {
compilation.hooks.optimizeModules.tap("MyPlugin", modules => {
modules = [...modules]
expect(modules.length).toEqual(1);
expect(modules[0].resource.includes("d.js")).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ module.exports = {
apply(compiler) {
compiler.hooks.thisCompilation.tap(
"ensure-chunk.groupsIterable-and-group.getParents-work",
complation => {
complation.hooks.processAssets.tap(
compilation => {
compilation.hooks.processAssets.tap(
"ensure-chunk.groupsIterable-and-group.getParents-work",
() => {
assert(complation.chunks.length > 0);
for (const chunk of complation.chunks) {
let chunks = [...compilation.chunks];
assert(chunks.length > 0);
for (const chunk of chunks) {
assert(typeof chunk.groupsIterable !== "undefined");
for (const group of chunk.groupsIterable) {
assert(typeof group.index === "number");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Plugin {
let initial = true;
compiler.hooks.compilation.tap(pluginName, compilation => {
compilation.hooks.finishModules.tapPromise(pluginName, async modules => {
modules = [...modules]
const oldModule = modules.find(item => item.resource.endsWith("a.js"));
if (!oldModule) {
throw new Error("module not found");
Expand Down
Loading

3 comments on commit 87a73c3

@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 ✅ success
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ❌ failure
compat ✅ success
examples ✅ success

@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-06-19 35f8542) Current Change
10000_development-mode + exec 2.22 s ± 12 ms 2.21 s ± 27 ms -0.62 %
10000_development-mode_hmr + exec 732 ms ± 16 ms 715 ms ± 9.9 ms -2.34 %
10000_production-mode + exec 2.58 s ± 24 ms 2.55 s ± 35 ms -1.17 %
arco-pro_development-mode + exec 1.91 s ± 75 ms 1.93 s ± 70 ms +0.96 %
arco-pro_development-mode_hmr + exec 442 ms ± 1.9 ms 439 ms ± 2.9 ms -0.87 %
arco-pro_production-mode + exec 3.56 s ± 62 ms 3.46 s ± 73 ms -2.98 %
threejs_development-mode_10x + exec 1.47 s ± 19 ms 2.06 s ± 13 ms +40.12 %
threejs_development-mode_10x_hmr + exec 782 ms ± 6.8 ms 812 ms ± 6.8 ms +3.77 %
threejs_production-mode_10x + exec 4.77 s ± 21 ms 5.29 s ± 34 ms +10.91 %

Threshold exceeded: ["threejs_development-mode_10x + exec","threejs_production-mode_10x + exec"]

@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 ✅ success
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
compat ✅ success
examples ✅ success

Please sign in to comment.