Skip to content

Commit

Permalink
feat: should have null as placeholder in stats chunks before chunkIds (
Browse files Browse the repository at this point in the history
…web-infra-dev#4549)

* Revert "revert: should have null as placeholder in stats chunks before chunkIds (web-infra-dev#4492)"

This reverts commit 7e92384.

* fix(napi): add codegen-units to 16
  • Loading branch information
JSerFeng authored Nov 7, 2023
1 parent 4c470d4 commit 64fe33b
Show file tree
Hide file tree
Showing 33 changed files with 490 additions and 122 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ swc_node_comments = { version = "=0.20.2" }
tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] }

[profile.dev]
debug = 2
incremental = true
codegen-units = 16 # debug build will cause runtime panic if codegen-unints is default
debug = 2
incremental = true

[profile.release]
codegen-units = 1
Expand Down
1 change: 1 addition & 0 deletions crates/node_binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ crate-type = ["cdylib"]
[dependencies]
rspack_binding_macros = { path = "../rspack_binding_macros" }
rspack_binding_options = { path = "../rspack_binding_options" }
rspack_binding_values = { path = "../rspack_binding_values" }
rspack_core = { path = "../rspack_core" }
rspack_error = { path = "../rspack_error" }
rspack_fs_node = { path = "../rspack_fs_node" }
Expand Down
27 changes: 22 additions & 5 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class JsStats {
getErrors(): Array<JsStatsError>
getWarnings(): Array<JsStatsWarning>
getLogging(acceptedTypes: number): Array<JsStatsLogging>
getHash(): string
getHash(): string | null
}

export class Rspack {
Expand Down Expand Up @@ -96,6 +96,12 @@ export class Rspack {
unsafe_drop(): void
}

export function __chunk_inner_can_be_initial(jsChunk: JsChunk, compilation: JsCompilation): boolean

export function __chunk_inner_has_runtime(jsChunk: JsChunk, compilation: JsCompilation): boolean

export function __chunk_inner_is_only_initial(jsChunk: JsChunk, compilation: JsCompilation): boolean

export interface AfterResolveData {
request: string
context: string
Expand Down Expand Up @@ -198,8 +204,19 @@ export interface JsAssetInfoRelated {
}

export interface JsChunk {
__inner_ukey: number
name?: string
id?: string
ids: Array<string>
idNameHints: Array<string>
filenameTemplate?: string
cssFilenameTemplate?: string
files: Array<string>
runtime: Array<string>
hash?: string
contentHash: Record<string, string>
renderedHash?: string
chunkReasons: Array<string>
}

export interface JsChunkAssetArgs {
Expand Down Expand Up @@ -333,7 +350,7 @@ export interface JsStatsAsset {
type: string
name: string
size: number
chunks: Array<string>
chunks: Array<string | undefined | null>
chunkNames: Array<string>
info: JsStatsAssetInfo
emitted: boolean
Expand All @@ -354,7 +371,7 @@ export interface JsStatsChunk {
type: string
files: Array<string>
auxiliaryFiles: Array<string>
id: string
id?: string
entry: boolean
initial: boolean
names: Array<string>
Expand All @@ -368,7 +385,7 @@ export interface JsStatsChunk {
export interface JsStatsChunkGroup {
name: string
assets: Array<JsStatsChunkGroupAsset>
chunks: Array<string>
chunks: Array<string | undefined | null>
assetsSize: number
}

Expand Down Expand Up @@ -406,7 +423,7 @@ export interface JsStatsModule {
identifier: string
name: string
id?: string
chunks: Array<string>
chunks: Array<string | undefined | null>
size: number
issuer?: string
issuerName?: string
Expand Down
10 changes: 2 additions & 8 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#[macro_use]
extern crate napi_derive;

#[macro_use]
extern crate rspack_binding_macros;

use std::collections::HashSet;
use std::pin::Pin;
use std::sync::atomic::{AtomicU32, Ordering};
Expand All @@ -15,26 +12,23 @@ use std::sync::Mutex;
use napi::bindgen_prelude::*;
use once_cell::sync::Lazy;
use rspack_binding_options::BuiltinPlugin;
use rspack_binding_values::SingleThreadedHashMap;
use rspack_core::PluginExt;
use rspack_fs_node::{AsyncNodeWritableFileSystem, ThreadsafeNodeFS};
use rspack_napi_shared::NAPI_ENV;

mod hook;
mod js_values;
mod loader;
mod plugins;
mod utils;

use hook::*;
use js_values::*;
// Napi macro registered this successfully
#[allow(unused)]
use loader::*;
use plugins::*;
use rspack_binding_options::*;
use rspack_binding_values::*;
use rspack_tracing::chrome::FlushGuard;
use utils::*;

#[cfg(not(target_os = "linux"))]
#[global_allocator]
static GLOBAL: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;
Expand Down
8 changes: 4 additions & 4 deletions crates/node_binding/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use async_trait::async_trait;
pub use loader::JsLoaderResolver;
use napi::{Env, Result};
use rspack_binding_macros::js_fn_into_threadsafe_fn;
use rspack_binding_values::{
AfterResolveData, BeforeResolveData, JsAssetEmittedArgs, JsChunkAssetArgs, JsModule,
JsResolveForSchemeInput, JsResolveForSchemeResult, ToJsModule,
};
use rspack_core::{
ChunkAssetArgs, NormalModuleAfterResolveArgs, NormalModuleBeforeResolveArgs,
PluginNormalModuleFactoryAfterResolveOutput, PluginNormalModuleFactoryBeforeResolveOutput,
Expand All @@ -15,10 +19,6 @@ use rspack_error::internal_error;
use rspack_napi_shared::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode};
use rspack_napi_shared::NapiResultExt;

use crate::js_values::{
AfterResolveData, BeforeResolveData, JsAssetEmittedArgs, JsChunkAssetArgs, JsModule,
JsResolveForSchemeInput, JsResolveForSchemeResult, ToJsModule,
};
use crate::{DisabledHooks, Hook, JsCompilation, JsHooks};

pub struct JsHooksAdapter {
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.1.0"

[dependencies]
rspack_binding_macros = { path = "../rspack_binding_macros" }
rspack_binding_values = { path = "../rspack_binding_values" }
rspack_core = { path = "../rspack_core" }
rspack_error = { path = "../rspack_error" }
rspack_identifier = { path = "../rspack_identifier" }
Expand Down
32 changes: 0 additions & 32 deletions crates/rspack_binding_options/src/chunk.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/rspack_binding_options/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod chunk;
mod options;
pub use options::*;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{fmt::Debug, sync::Arc};
use derivative::Derivative;
use napi::{Env, JsFunction};
use napi_derive::napi;
use rspack_binding_values::JsChunk;
use rspack_error::internal_error;
use rspack_napi_shared::{
threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode},
Expand All @@ -13,8 +14,6 @@ use rspack_plugin_banner::{
};
use serde::Deserialize;

use crate::chunk::JsChunk;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
#[napi(object)]
Expand Down
62 changes: 62 additions & 0 deletions crates/rspack_binding_values/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[package]
edition = "2021"
license = "MIT"
name = "rspack_binding_values"
repository = "https://github.com/web-infra-dev/rspack"
version = "0.1.0"

[dependencies]
rspack_binding_macros = { path = "../rspack_binding_macros" }
rspack_core = { path = "../rspack_core" }
rspack_error = { path = "../rspack_error" }
rspack_identifier = { path = "../rspack_identifier" }
rspack_ids = { path = "../rspack_ids" }
rspack_loader_react_refresh = { path = "../rspack_loader_react_refresh" }
rspack_loader_runner = { path = "../rspack_loader_runner" }
rspack_loader_sass = { path = "../rspack_loader_sass" }
rspack_loader_swc = { path = "../rspack_loader_swc" }
rspack_napi_shared = { path = "../rspack_napi_shared" }
rspack_plugin_asset = { path = "../rspack_plugin_asset" }
rspack_plugin_banner = { path = "../rspack_plugin_banner" }
rspack_plugin_copy = { path = "../rspack_plugin_copy" }
rspack_plugin_css = { path = "../rspack_plugin_css" }
rspack_plugin_dev_friendly_split_chunks = { path = "../rspack_plugin_dev_friendly_split_chunks" }
rspack_plugin_devtool = { path = "../rspack_plugin_devtool" }
rspack_plugin_ensure_chunk_conditions = { path = "../rspack_plugin_ensure_chunk_conditions" }
rspack_plugin_entry = { path = "../rspack_plugin_entry" }
rspack_plugin_externals = { path = "../rspack_plugin_externals" }
rspack_plugin_hmr = { path = "../rspack_plugin_hmr" }
rspack_plugin_html = { path = "../rspack_plugin_html" }
rspack_plugin_javascript = { path = "../rspack_plugin_javascript" }
rspack_plugin_json = { path = "../rspack_plugin_json" }
rspack_plugin_library = { path = "../rspack_plugin_library" }
rspack_plugin_progress = { path = "../rspack_plugin_progress" }
rspack_plugin_real_content_hash = { path = "../rspack_plugin_real_content_hash" }
rspack_plugin_remove_empty_chunks = { path = "../rspack_plugin_remove_empty_chunks" }
rspack_plugin_runtime = { path = "../rspack_plugin_runtime" }
rspack_plugin_schemes = { path = "../rspack_plugin_schemes" }
rspack_plugin_split_chunks = { path = "../rspack_plugin_split_chunks" }
rspack_plugin_split_chunks_new = { path = "../rspack_plugin_split_chunks_new" }
rspack_plugin_swc_css_minimizer = { path = "../rspack_plugin_swc_css_minimizer" }
rspack_plugin_swc_js_minimizer = { path = "../rspack_plugin_swc_js_minimizer" }
rspack_plugin_wasm = { path = "../rspack_plugin_wasm" }
rspack_plugin_worker = { path = "../rspack_plugin_worker" }
rspack_regex = { path = "../rspack_regex" }
rspack_swc_visitors = { path = "../rspack_swc_visitors" }

anyhow = { workspace = true, features = ["backtrace"] }
async-trait = { workspace = true }
better_scoped_tls = { workspace = true }
dashmap = { workspace = true }
derivative = { workspace = true }
futures = { workspace = true }
glob = { workspace = true }
napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] }
napi-derive = { workspace = true }
napi-sys = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
swc_core = { workspace = true, default-features = false, features = ["ecma_transforms_react"] }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros", "test-util", "parking_lot"] }
tracing = { workspace = true }
22 changes: 22 additions & 0 deletions crates/rspack_binding_values/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2022-present Bytedance, Inc. and its affiliates.


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 64fe33b

Please sign in to comment.