Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deprecate JavaScript API (part 2) #6859

Merged
merged 4 commits into from
Jun 19, 2024
Merged
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
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
Loading