Skip to content

Commit

Permalink
Fix ci wrong (web-infra-dev#617)
Browse files Browse the repository at this point in the history
chore: fix ci failed but exit 0
  • Loading branch information
hardfist authored Aug 25, 2022
1 parent 0b8d897 commit f3ec315
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 27 deletions.
1 change: 1 addition & 0 deletions crates/node_binding/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 crates/node_binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ napi = {git = "https://github.com/speedy-js/napi-rs", branch = "speedy", default
]}
napi-derive = {git = "https://github.com/speedy-js/napi-rs", branch = "speedy"}
once_cell = "1"
regex = "1.6.0"
rspack = {path = "../rspack"}
rspack_binding_options = {path = "../rspack_binding_options", features = ["node-api"]}
rspack_core = {path = "../rspack_core"}
rspack_error = {path = "../rspack_error"}
rspack_plugin_html = {path = "../rspack_plugin_html"}
regex = "1.6.0"
serde = {version = "1", features = ["derive"]}
serde_json = "1"
tokio = {version = "1.17.0", features = ["full"]}
Expand Down
42 changes: 28 additions & 14 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use napi::bindgen_prelude::*;
use napi::{Env, Result};
use napi_derive::napi;
// use nodejs_resolver::Resolver;
use rspack_error::Diagnostic;
use tokio::sync::Mutex;

// pub mod adapter;
// mod options;
mod utils;
Expand Down Expand Up @@ -36,15 +36,27 @@ pub struct RspackBindingContext {
pub rspack: Rspack,
// pub resolver: Arc<Resolver>,
}

#[napi(object)]
pub struct RspackError {
pub message: String,
}
#[napi(object)]
pub struct Stats {
// pub assets: Vec<String>,
pub errors: Vec<RspackError>,
}

impl<'a> From<rspack_core::Stats<'a>> for Stats {
fn from(_rspack_stats: rspack_core::Stats) -> Self {
Self {}
fn from(rspack_stats: rspack_core::Stats) -> Self {
Self {
errors: rspack_stats
.compilation
.diagnostic
.iter()
.map(|d| RspackError {
message: d.message.clone(),
})
.collect(),
}
}
}

Expand Down Expand Up @@ -99,22 +111,25 @@ pub fn new_rspack(

#[napi(
ts_args_type = "rspack: ExternalObject<RspackInternal>",
ts_return_type = "Promise<Record<string, string>>"
ts_return_type = "Promise<Stats>"
)]
pub fn build(env: Env, binding_context: External<RspackBindingContext>) -> Result<napi::JsObject> {
let compiler = binding_context.rspack.clone();
env.execute_tokio_future(
async move {
let mut compiler = compiler.lock().await;
let _rspack_stats = compiler
let rspack_stats = compiler
.run()
.await
.map_err(|e| Error::new(napi::Status::GenericFailure, format!("{:?}", e)))?;

// let stats: Stats = rspack_stats.into();
println!("build success");
// Ok(stats)
Ok(())
let stats: Stats = rspack_stats.into();
if stats.errors.is_empty() {
println!("build success");
} else {
println!("build failed");
}
Ok(stats)
},
|_env, ret| Ok(ret),
)
Expand All @@ -140,10 +155,9 @@ pub fn rebuild(
.await
.map_err(|e| Error::new(napi::Status::GenericFailure, format!("{:?}", e)))?;

// let stats: Stats = rspack_stats.into();
let stats: Stats = _rspack_stats.into();
println!("rebuild success");
// Ok(stats)
Ok(())
Ok(stats)
},
|_env, ret| Ok(ret),
)
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_core/src/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl Compilation {
diagnostic: vec![],
}
}

pub fn add_entry(&mut self, name: String, detail: EntryItem) {
self.entries.insert(name, detail);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{Compilation, CompilationAssets};

#[derive(Debug)]
pub struct Stats<'compilation> {
compilation: &'compilation Compilation,
pub compilation: &'compilation Compilation,
}

impl<'compilation> Stats<'compilation> {
Expand Down
6 changes: 4 additions & 2 deletions packages/rspack-dev-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2015",
"target": "ES2018",
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "dist",
"declaration": true
},
"include": ["src"]
"include": [
"src"
]
}
5 changes: 4 additions & 1 deletion packages/rspack/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Rspack } from ".";
export async function build(config: any) {
const rspack = new Rspack(config);
return await rspack.build();
const stats = await rspack.build();
if (stats.errors.length > 0) {
throw new Error(stats.errors[0].message);
}
}
8 changes: 5 additions & 3 deletions packages/rspack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2015",
"target": "ES2018",
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "dist",
"declaration": true
},
"include": ["src"]
}
"include": [
"src"
]
}
7 changes: 6 additions & 1 deletion webpack-examples/build-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ async function main() {
}
}
}
await build({ ...defaultEntry, ...config });
try{
await build({ ...defaultEntry, ...config });
}catch(err){
process.exit(1);
}

}
main();
4 changes: 1 addition & 3 deletions webpack-examples/buildAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ const list = examples
.forEach(function (dirname) {
console.log(dirname);
const build_path = `${dirname}/build.js`;
try {
cp.execSync(`node ${build_path}`); // use child-process to avoid require cache
} catch (err) {}
cp.execSync(`node ${build_path}`); // use child-process to avoid require cache
});

0 comments on commit f3ec315

Please sign in to comment.