Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/lyy_unused_spe…
Browse files Browse the repository at this point in the history
…cifier
  • Loading branch information
stormslowly committed Mar 25, 2024
2 parents 42a5601 + 8028e53 commit 1f4e5e9
Show file tree
Hide file tree
Showing 40 changed files with 324 additions and 136 deletions.
Empty file added .aci.yml
Empty file.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@

## 0.4.7

`2024-03-22`

> @alipay/bigfish@4.1.17
* 修复 fast refresh 在函数内生成组件时的边界场景 by [@sorrycc](https://github.com/sorrycc) in [#972](https://github.com/umijs/mako/pull/972)
* 修复引用 assets 带 query 时的场景 by [@sorrycc](https://github.com/sorrycc) in [#975](https://github.com/umijs/mako/pull/975)

## 0.4.6

`2024-03-20`

> @alipay/bigfish@4.1.17
* 修复 resolve fragment 问题,支持 a#b.ts 的场景 by [@sorrycc](https://github.com/sorrycc) in [#966](https://github.com/umijs/mako/pull/966)

## 0.4.5

`2024-03-20`

> @alipay/bigfish@4.1.17
* 重构 build 部分的代码 by [@sorrycc](https://github.com/sorrycc) in [#923](https://github.com/umijs/mako/pull/923)
* 新增 HMR Fast Refresh 支持匿名函数的场景 by [@JackGuiYang12](https://github.com/JackGuiYang12) in [#947](https://github.com/umijs/mako/pull/947)
* 新增 inline_css 配置,实现类 style-loader 的能力 by [@sorrycc](https://github.com/sorrycc) in [#957](https://github.com/umijs/mako/pull/957)
* 优化 rayon 使用,generate 复用 build 阶段的 rayon 线程 by [@xusd320](https://github.com/xusd320) in [#959](https://github.com/umijs/mako/pull/959)
* 优化 minifish inject 功能,支持 include 配置项 by [@stormslowly](https://github.com/stormslowly) in [#930](https://github.com/umijs/mako/pull/930)
* 修复 async chunk 不应该拆分 root module by [@PeachScript](https://github.com/PeachScript) in [#929](https://github.com/umijs/mako/pull/929)
* 修复 css url() 应该支持 # 前缀 by [@sorrycc](https://github.com/sorrycc) in [#949](https://github.com/umijs/mako/pull/949)
* 修复 async module 的实现 by [@stormslowly](https://github.com/stormslowly) in [#943](https://github.com/umijs/mako/pull/943)
* 修复 js 和 css resolve 依赖时对 # fragment 的支持 by [@sorrycc](https://github.com/sorrycc) in [#952](https://github.com/umijs/mako/pull/952)
* 修复非 ascii 路径的支持,比如空格和中文 by [@sorrycc](https://github.com/sorrycc) in [#958](https://github.com/umijs/mako/pull/958)
* 修复 ignored 模块应该被编译成空的 es 模块 by [@xusd320](https://github.com/xusd320) in [#946](https://github.com/umijs/mako/pull/946)
* 修复 context module 场景下 async import 应该被拆分的问题 by [@xusd320](https://github.com/xusd320) in [#940](https://github.com/umijs/mako/pull/940)
* 修复 sync chunk 的 stats 信息 by [@PeachScript](https://github.com/PeachScript) in [#928](https://github.com/umijs/mako/pull/928)

## 0.4.4

`2024-02-29`
Expand All @@ -10,6 +48,7 @@
- 优化 external 特性中正则表达式实例化的开销,m1 pro yuyanAssets build 稳定提升 3900ms 左右 by [@PeachScript](https://github.com/PeachScript) in [#916](https://github.com/umijs/mako/pull/916)
- 调用 onBuildComplete hook 时传入全量的 stats compilation 数据 by [@PeachScript](https://github.com/PeachScript) in [#917](https://github.com/umijs/mako/pull/917)
- 从 nodejs-resolver 切换至 oxc_resolver by [@xusd320](https://github.com/xusd320) in [#919](https://github.com/umijs/mako/pull/919)

## 0.4.3

`2024-02-01`
Expand Down
10 changes: 2 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Benchmark three10x.
$ just setup-bench
# default: --baseline master --case tmp/three10x
$ just bench
$ just bench --multiChunks
$ just bench --baseline v0.4.4
$ just bench --baseline v0.4.4 --case examples/with-antd
```
Expand Down Expand Up @@ -127,17 +128,10 @@ $ cargo install cargo-instruments
$ cargo instruments --list-templates
```

- Add the following section in ./crates/mako/Cargo.toml

```toml
[profile.release]
debug = true
```

- capture instruments trace with:

```bash
$ cargo instruments --release -t sys --package mako --bin mako examples/with-antd
$ cargo instruments -t sys --profile release-debug --package mako --bin mako examples/with-antd
```

- you can open the trace file with instruments again with:
Expand Down
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ serde = { version = "1.0.171", features = ["derive"] }
serde_json = "1.0.100"
swc_core = { version = "=0.83.19", default-features = false }
tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] }

[profile.release]
debug = false

# Use the `--profile release-debug` flag to show symbols in release mode.
# e.g. `cargo build --profile release-debug`
[profile.release-debug]
debug = true
inherits = "release"
22 changes: 17 additions & 5 deletions crates/mako/src/ast_2/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,19 @@ lazy_static! {
impl File {
pub fn new(path: String, context: Arc<Context>) -> Self {
let path = PathBuf::from(path);
let (pathname, search, params, fragment) = parse_path(&path.to_string_lossy()).unwrap();
// if path exists, it has no search and fragment
// support ./a#b.ts when a#b.ts is a real file
// e.g. https://unpkg.com/browse/[email protected]/string/
let (pathname, search, params, fragment) = if path.exists() {
(
path.to_string_lossy().to_string(),
"".to_string(),
vec![],
None,
)
} else {
parse_path(&path.to_string_lossy()).unwrap()
};
let pathname = PathBuf::from(pathname);
let is_virtual = path.starts_with(&*VIRTUAL) ||
// TODO: remove this specific logic
Expand Down Expand Up @@ -178,15 +190,15 @@ impl File {
}

pub fn get_file_size(&self) -> Result<u64> {
let metadata = std::fs::metadata(&self.path)?;
let metadata = std::fs::metadata(&self.pathname)?;
Ok(metadata.len())
}

pub fn get_base64(&self) -> Result<String> {
let content = std::fs::read(&self.path)?;
let content = std::fs::read(&self.pathname)?;
let engine = engine::GeneralPurpose::new(&STANDARD, engine::general_purpose::PAD);
let content = engine.encode(content);
let guess = mime_guess::from_path(&self.path);
let guess = mime_guess::from_path(&self.pathname);
if let Some(mime) = guess.first() {
Ok(format!(
"data:{};base64,{}",
Expand All @@ -201,7 +213,7 @@ impl File {
}

pub fn get_content_hash(&self) -> Result<String> {
let file = std::fs::File::open(&self.path)?;
let file = std::fs::File::open(&self.pathname)?;
let len = file.metadata()?.len();
// Decide on a reasonable buffer size (1MB in this case, fastest will depend on hardware)
let buf_len = len.min(1_000_000) as usize;
Expand Down
4 changes: 2 additions & 2 deletions crates/mako/src/ast_2/js_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::config::{DevtoolConfig, Mode};
use crate::module::Dependency;
use crate::plugin::PluginTransformJsParam;
use crate::sourcemap::build_source_map;
use crate::visitors::js_dep_analyzer::JSDepAnalyzer;
use crate::visitors::dep_analyzer::DepAnalyzer;

#[derive(Clone)]
pub struct JsAst {
Expand Down Expand Up @@ -194,7 +194,7 @@ impl JsAst {
}

pub fn analyze_deps(&self, context: Arc<Context>) -> Vec<Dependency> {
let mut visitor = JSDepAnalyzer::new(self.unresolved_mark);
let mut visitor = DepAnalyzer::new(self.unresolved_mark);
GLOBALS.set(&context.meta.script.globals, || {
self.ast.visit_with(&mut visitor);
visitor.dependencies
Expand Down
8 changes: 7 additions & 1 deletion crates/mako/src/ast_2/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mako_core::swc_ecma_transforms::resolver;
use mako_core::swc_ecma_visit::VisitMutWith;
use swc_core::common::GLOBALS;

use super::css_ast::CssAst;
use super::css_ast::{CSSAstGenerated, CssAst};
use super::file::{Content, File};
use super::js_ast::{JSAstGenerated, JsAst};
use crate::compiler::Context;
Expand Down Expand Up @@ -107,4 +107,10 @@ impl TestUtils {
let JSAstGenerated { code, sourcemap: _ } = ast.generate(self.context.clone()).unwrap();
code.trim_end().to_string()
}

pub fn css_ast_to_code(&mut self) -> String {
let ast = self.ast.css_mut();
let CSSAstGenerated { code, sourcemap: _ } = ast.generate(self.context.clone()).unwrap();
code.trim_end().to_string()
}
}
9 changes: 5 additions & 4 deletions crates/mako/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function moduleToDom(css) {
file.extname
);
context.emit_assets(
file.path.to_string_lossy().to_string(),
file.pathname.to_string_lossy().to_string(),
final_file_name.clone(),
);
return Ok(Content::Js(format!(
Expand Down Expand Up @@ -238,10 +238,11 @@ export function moduleToDom(css) {
inject_public_path: bool,
context: Arc<Context>,
) -> Result<String> {
let path = file.path.to_string_lossy().to_string();
let file_size = file
.get_file_size()
.map_err(|_| LoadError::ReadFileSizeError { path })?;
.map_err(|_| LoadError::ReadFileSizeError {
path: file.path.to_string_lossy().to_string(),
})?;
let emit_assets = || -> Result<String> {
let final_file_name = Self::emit_asset(file, context.clone());
if inject_public_path {
Expand Down Expand Up @@ -270,7 +271,7 @@ export function moduleToDom(css) {
}

pub fn emit_asset(file: &File, context: Arc<Context>) -> String {
let path = file.path.to_string_lossy().to_string();
let path = file.pathname.to_string_lossy().to_string();
let final_file_name = format!(
"{}.{}.{}",
file.get_file_stem(),
Expand Down
4 changes: 2 additions & 2 deletions crates/mako/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::compiler::Context;
use crate::module::ModuleAst;
use crate::plugin::PluginParseParam;
use crate::transform::Transform;
use crate::transformers::transform_css_handler::CssHandler;
use crate::visitors::css_imports::CSSImports;

#[derive(Debug, Error)]
pub enum ParseError {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Parse {
let ast = ast.as_css_mut();
// transform (remove @imports)
// TODO: Render::transform(&mut ast, &file, context.clone())?;
let mut css_handler = CssHandler {};
let mut css_handler = CSSImports {};
ast.ast.visit_mut_with(&mut css_handler);
// ast to code
let code = ast.generate(context.clone())?.code;
Expand Down
4 changes: 2 additions & 2 deletions crates/mako/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::transformers::transform_px2rem::Px2Rem;
use crate::transformers::transform_react::mako_react;
use crate::transformers::transform_try_resolve::TryResolve;
use crate::transformers::transform_virtual_css_modules::VirtualCSSModules;
use crate::visitors::named_export_default::NamedExportDefault;
use crate::visitors::default_export_namer::DefaultExportNamer;

pub struct Transform {}

Expand Down Expand Up @@ -65,7 +65,7 @@ impl Transform {
file.extname == "tsx" || file.extname == "jsx" || file.extname == "js";
if context.args.watch && !file.is_under_node_modules && could_be_react_component
{
visitors.push(Box::new(NamedExportDefault::new()));
visitors.push(Box::new(DefaultExportNamer::new()));
}
// TODO: refact mako_react
visitors.push(Box::new(mako_react(
Expand Down
4 changes: 2 additions & 2 deletions crates/mako/src/transform_in_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ use crate::config::OutputMode;
use crate::module::{Dependency, ModuleAst, ModuleId, ResolveType};
use crate::thread_pool;
use crate::transformers::transform_async_module::AsyncModule;
use crate::transformers::transform_css_handler::CssHandler;
use crate::transformers::transform_dep_replacer::{DepReplacer, DependenciesToReplace};
use crate::transformers::transform_dynamic_import::DynamicImport;
use crate::transformers::transform_mako_require::MakoRequire;
use crate::transformers::transform_meta_url_replacer::MetaUrlReplacer;
use crate::transformers::transform_optimize_define_utils::OptimizeDefineUtils;
use crate::visitors::css_imports::CSSImports;

impl Compiler {
pub fn transform_all(&self) -> Result<()> {
Expand Down Expand Up @@ -294,7 +294,7 @@ pub fn transform_js_generate(transform_js_param: TransformJsParam) -> Result<()>
pub fn transform_css_generate(ast: &mut swc_css_ast::Stylesheet, _context: &Arc<Context>) {
mako_core::mako_profile_function!();
// replace deps
let mut css_handler = CssHandler {};
let mut css_handler = CSSImports {};
ast.visit_mut_with(&mut css_handler);
}

Expand Down
1 change: 0 additions & 1 deletion crates/mako/src/transformers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod transform_async_module;
pub mod transform_css_flexbugs;
pub mod transform_css_handler;
pub mod transform_css_url_replacer;
pub mod transform_dep_replacer;
pub mod transform_dynamic_import;
Expand Down
4 changes: 2 additions & 2 deletions crates/mako/src/transformers/transform_async_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {
use crate::compiler::Context;
use crate::config::Config;
use crate::module::ModuleId;
use crate::visitors::js_dep_analyzer::JSDepAnalyzer;
use crate::visitors::dep_analyzer::DepAnalyzer;

#[test]
fn test_default_import_async_module() {
Expand Down Expand Up @@ -417,7 +417,7 @@ __mako_require__._async(module, async (handleAsyncDeps, asyncResult)=>{
false,
));

let mut dep_collector = JSDepAnalyzer::new(ast.unresolved_mark);
let mut dep_collector = DepAnalyzer::new(ast.unresolved_mark);
ast.ast.visit_with(&mut dep_collector);

let import_interop = ImportInterop::Swc;
Expand Down
6 changes: 4 additions & 2 deletions crates/mako/src/transformers/transform_react.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ import 'react-refresh';
pub fn react_refresh_module_postfix(context: &Arc<Context>) -> Box<dyn VisitMut> {
Box::new(PostfixCode {
context: context.clone(),
// why add if guard?
// ref: https://github.com/umijs/mako/issues/971
code: r#"
self.$RefreshReg$ = prevRefreshReg;
self.$RefreshSig$ = prevRefreshSig;
if (prevRefreshReg) self.$RefreshReg$ = prevRefreshReg;
if (prevRefreshSig) self.$RefreshSig$ = prevRefreshSig;
function $RefreshIsReactComponentLike$(moduleExports) {
if (RefreshRuntime.isLikelyComponentType(moduleExports.default || moduleExports)) {
return true;
Expand Down
Loading

0 comments on commit 1f4e5e9

Please sign in to comment.