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

refact: build #923

Merged
merged 48 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
67b7337
refact: build
sorrycc Feb 27, 2024
cbda24e
update
sorrycc Feb 28, 2024
bd6de61
update
sorrycc Feb 28, 2024
d77ff45
runnable
sorrycc Feb 29, 2024
fcd291c
remove files
sorrycc Feb 29, 2024
b19dcb9
remove task.rs
sorrycc Feb 29, 2024
aed7f56
Merge commit 'af9d44d404488a3187e2ad349ec38cd27796e5f4' into refact/b…
sorrycc Feb 29, 2024
0d694c5
remove build.rs
sorrycc Mar 4, 2024
319aa09
remove load.rs
sorrycc Mar 4, 2024
e8dc067
remove parse.rs
sorrycc Mar 4, 2024
0175b94
remove transform.rs
sorrycc Mar 4, 2024
be7d1fc
remove md.rs
sorrycc Mar 4, 2024
d4fcb90
remove css.rs
sorrycc Mar 4, 2024
e6460f4
remove _2 affix
sorrycc Mar 4, 2024
d069193
refact plugins/runtime
sorrycc Mar 5, 2024
47633ff
remove meta.rs
sorrycc Mar 5, 2024
80724d7
code style
sorrycc Mar 5, 2024
440d25b
fix find_export_source test cases
sorrycc Mar 5, 2024
350d1c2
fix clappy
sorrycc Mar 5, 2024
bbe1fef
fix: bundler-okam don't exit
sorrycc Mar 5, 2024
54cddce
fix: build won't end when last module build failed
sorrycc Mar 6, 2024
a780333
fix: css modules support
sorrycc Mar 6, 2024
fc26099
fix: css modules
sorrycc Mar 6, 2024
9fc3682
chore: update
sorrycc Mar 6, 2024
00141bc
fix config.platform.node case
sorrycc Mar 6, 2024
c7a4d4b
refactor: treats ignore module as normal module (#935)
xusd320 Mar 6, 2024
66cb651
fix: optimize.full-helpers testcase
sorrycc Mar 7, 2024
13b39ae
fix: error.resolve.module-not-found test case
sorrycc Mar 7, 2024
5baf2b0
fix: config.react.runtime.classic testcase
sorrycc Mar 7, 2024
558b271
fix: javascript.require-dynamic testcase
sorrycc Mar 7, 2024
1293b8a
fix: minifish testcases
sorrycc Mar 8, 2024
9a4a472
fix: raw_hash calculate when watch is on
sorrycc Mar 8, 2024
cb3f7c1
fix: entry with ?hmr
sorrycc Mar 8, 2024
6517f83
fix: css modules
sorrycc Mar 8, 2024
b753b9f
code style
sorrycc Mar 11, 2024
da54218
fix missing related test cases
sorrycc Mar 11, 2024
608fb6f
code style
sorrycc Mar 11, 2024
929066a
remove missing_deps in module.info
sorrycc Mar 11, 2024
194c96f
remove props under module.info
sorrycc Mar 11, 2024
d9594cf
add inject testcase back
sorrycc Mar 11, 2024
3436790
Merge commit '03a58a52042e7fed49e0821ec3903f143768181e' into refact/b…
sorrycc Mar 11, 2024
ff7ac79
code style
sorrycc Mar 11, 2024
6228229
add testcases
sorrycc Mar 11, 2024
acb9789
update pnpm-lock.yaml
sorrycc Mar 11, 2024
b6d6b12
code style
sorrycc Mar 11, 2024
0fcf429
code style
sorrycc Mar 11, 2024
9dd2edb
fix: let async imports bundled into separate chunks (#940)
xusd320 Mar 11, 2024
eab6512
refact: thread pool (#936)
xusd320 Mar 11, 2024
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
14 changes: 0 additions & 14 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"./crates/mako/test/**/*",
"./test/**/dist/*",
"./test/build/tmp/**/*",
"./e2e/**/*"
"./e2e/**",
"./tmp/**"
]
},
"formatter": {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ serde_json = { workspace = true }
serde_yaml = "0.9.22"
svgr-rs = "0.1.3"
thiserror = "1.0.43"
tokio = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["rt", "sync"] }
tokio-tungstenite = "0.19.0"
toml = "0.7.6"
tracing = "0.1.37"
Expand Down
142 changes: 112 additions & 30 deletions crates/mako/src/analyze_deps.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,122 @@
use std::collections::HashMap;
use std::sync::Arc;

use mako_core::anyhow::{anyhow, Result};
use mako_core::thiserror::Error;

use crate::ast_2::error;
use crate::ast_2::file::File;
use crate::compiler::Context;
use crate::module::{Dependency, ModuleAst};
use crate::plugin::PluginDepAnalyzeParam;

pub fn analyze_deps(
ast: &ModuleAst,
file_path: &String,
context: &Arc<Context>,
) -> Result<Vec<Dependency>> {
mako_core::mako_profile_function!();

let mut analyze_deps_param = PluginDepAnalyzeParam { ast };

let mut deps = context
.plugin_driver
.analyze_deps(&mut analyze_deps_param, context)?;

context.plugin_driver.before_resolve(&mut deps, context)?;

// check loader syntax
// e.g. file-loader!./file.txt
// e.g. file-loader?esModule=false!./src-noconflict/theme-kr_theme.js
for dep in &deps {
if dep.source.contains("-loader!")
|| (dep.source.contains("-loader?") && dep.source.contains('!'))
{
return Err(anyhow!(
"webpack loader syntax is not supported, since found dep {:?} in {:?}",
dep.source,
file_path
));
use crate::resolve::{resolve, ResolverResource};

#[derive(Debug, Error)]
pub enum AnalyzeDepsError {
#[error("{message:}")]
ModuleNotFound { message: String },
}

#[derive(Debug, Clone, Default)]
pub struct AnalyzeDepsResult {
pub resolved_deps: Vec<ResolvedDep>,
// why use hash map?
// since we need source as key to replace in generate step
pub missing_deps: HashMap<String, Dependency>,
}

#[derive(Debug, Clone)]
pub struct ResolvedDep {
pub resolver_resource: ResolverResource,
pub dependency: Dependency,
}

pub struct AnalyzeDeps {}

impl AnalyzeDeps {
pub fn analyze_deps(
ast: &ModuleAst,
file: &File,
context: Arc<Context>,
) -> Result<AnalyzeDepsResult> {
mako_core::mako_profile_function!();
let mut deps = match ast {
ModuleAst::Script(ast) => ast.analyze_deps(context.clone()),
ModuleAst::Css(ast) => ast.analyze_deps(),
_ => vec![],
};
context.plugin_driver.before_resolve(&mut deps, &context)?;
Self::check_deps(&deps, file)?;

let mut resolved_deps = vec![];
let mut missing_deps = HashMap::new();
let path = file.path.to_str().unwrap();
for dep in deps {
let result = resolve(
// .
path,
&dep,
&context.resolvers,
&context,
);
match result {
Ok(resolver_resource) => {
resolved_deps.push(ResolvedDep {
resolver_resource,
dependency: dep,
});
}
Err(_err) => {
missing_deps.insert(dep.source.clone(), dep);
}
}
}

if !missing_deps.is_empty() {
let messages = missing_deps
.values()
.map(|dep| Self::get_resolved_error(dep, context.clone()))
.collect::<Vec<String>>()
.join("\n");
// TODO:
// should we just throw an error here and decide whether to print or exit at the upper level?
if context.args.watch {
eprint!("{}", messages);
} else {
return Err(anyhow!(AnalyzeDepsError::ModuleNotFound {
message: messages
}));
}
}

Ok(AnalyzeDepsResult {
resolved_deps,
missing_deps,
})
}

fn check_deps(deps: &Vec<Dependency>, file: &File) -> Result<()> {
for dep in deps {
// webpack loader syntax is not supported
if dep.source.contains("-loader!")
|| (dep.source.contains("-loader?") && dep.source.contains('!'))
{
return Err(anyhow!(
"webpack loader syntax is not supported, since found dep {:?} in {:?}",
dep.source,
file.path.to_str().unwrap()
));
}
}
Ok(())
}

Ok(deps)
pub fn get_resolved_error(dep: &Dependency, context: Arc<Context>) -> String {
let message = format!("Module not found: Can't resolve '{}'", dep.source);
if dep.span.is_some() {
// TODO: support css resolved error
error::code_frame(error::ErrorSpan::Js(dep.span.unwrap()), &message, context)
} else {
message
}
}
}
7 changes: 3 additions & 4 deletions crates/mako/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub fn build_js_ast(path: &str, content: &str, context: &Arc<Context>) -> Result
})
}

#[allow(dead_code)]
pub fn build_css_ast(
path: &str,
content: &str,
Expand Down Expand Up @@ -310,16 +311,14 @@ mod tests {
use std::path::PathBuf;
use std::sync::Arc;

use mako_core::tokio;

use super::build_js_ast;
use crate::assert_debug_snapshot;
use crate::ast::js_ast_to_code;
use crate::compiler::Context;
use crate::test_helper::create_mock_module;

#[tokio::test(flavor = "multi_thread")]
async fn test_chinese_ascii() {
#[test]
fn test_chinese_ascii() {
let module = create_mock_module(
PathBuf::from("/path/to/test"),
r#"
Expand Down
1 change: 1 addition & 0 deletions crates/mako/src/ast_2/comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Loading
Loading