Skip to content

Commit

Permalink
ci: enable node testing (rolldown#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Mar 5, 2024
1 parent 3b0b28b commit 6f01071
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 50 deletions.
66 changes: 33 additions & 33 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,39 +93,39 @@ jobs:
- name: Run Test
run: just test-rust

# node-test:
# name: Node Test
# runs-on: buildjet-2vcpu-ubuntu-2204
# timeout-minutes: 30
# strategy:
# fail-fast: false
# matrix:
# os:
# - ubuntu-latest
# # - windows-latest
# # - macos-latest
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: true # Pull submodules for additional files

# - name: Install Rust
# uses: moonrepo/setup-rust@v1
# with:
# bins: just
# cache-base: main

# - name: Install node
# uses: actions/setup-node@v4
# with:
# node-version: 20
# cache: yarn

# - name: Install dependencies
# run: yarn install

# - name: Test
# run: just test-node
node-test:
name: Node Test
runs-on: buildjet-2vcpu-ubuntu-2204
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
# - windows-latest
# - macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true # Pull submodules for additional files

- name: Install Rust
uses: moonrepo/setup-rust@v1
with:
bins: just
cache-base: main

- name: Install node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Install dependencies
run: yarn install

- name: Test
run: just test-node

node-format:
name: Node Format
Expand Down
30 changes: 20 additions & 10 deletions crates/rolldown/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,18 @@ impl<T: FileSystem + Default + 'static> Bundler<T> {

let ret = self.scan_inner().await;

self.call_build_end_hook(ret.err()).await?;
self.call_build_end_hook(&ret).await?;

ret?;

Ok(())
}

async fn call_build_end_hook(&mut self, ret: Option<BatchedErrors>) -> BatchedResult<()> {
if let Some(e) = ret {
async fn call_build_end_hook(
&mut self,
ret: &Result<ScanStageOutput, BatchedErrors>,
) -> BatchedResult<()> {
if let Err(e) = ret {
let error = e.get().expect("should have a error");
self
.plugin_driver
Expand All @@ -117,12 +122,12 @@ impl<T: FileSystem + Default + 'static> Bundler<T> {
error: error.to_string(),
}))
.await?;
return Err(e);
}
Ok(())
} else {
self.plugin_driver.build_end(None).await?;

self.plugin_driver.build_end(None).await?;

Ok(())
Ok(())
}
}

async fn scan_inner(&mut self) -> BatchedResult<ScanStageOutput> {
Expand All @@ -138,10 +143,15 @@ impl<T: FileSystem + Default + 'static> Bundler<T> {

#[tracing::instrument(skip_all)]
async fn try_build(&mut self) -> BatchedResult<LinkStageOutput> {
let build_info = self.scan_inner().await?;
self.plugin_driver.build_start().await?;

let link_stage = LinkStage::new(build_info, &self.input_options);
let scan_ret = self.scan_inner().await;

self.call_build_end_hook(&scan_ret).await?;

let build_info = scan_ret?;

let link_stage = LinkStage::new(build_info, &self.input_options);
Ok(link_stage.link())
}

Expand Down
12 changes: 7 additions & 5 deletions crates/rolldown_binding/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export interface ResolveOptions {
symlinks?: boolean
}
export interface InputOptions {
external?: (
source: string,
importer?: string,
isResolved?: boolean,
) => boolean
external?:
| undefined
| ((
source: string,
importer: string | undefined,
isResolved: boolean,
) => boolean)
input: Array<InputItem>
plugins: Array<PluginOptions>
resolve?: ResolveOptions
Expand Down
43 changes: 43 additions & 0 deletions crates/rolldown_binding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,49 @@ switch (platform) {
loadError = e
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'rolldown.linux-riscv64-musl.node'),
)
try {
if (localFileExisted) {
nativeBinding = require('./rolldown.linux-riscv64-musl.node')
} else {
nativeBinding = require('@rolldown/node-binding-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'rolldown.linux-riscv64-gnu.node'),
)
try {
if (localFileExisted) {
nativeBinding = require('./rolldown.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@rolldown/node-binding-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'rolldown.linux-s390x-gnu.node'),
)
try {
if (localFileExisted) {
nativeBinding = require('./rolldown.linux-s390x-gnu.node')
} else {
nativeBinding = require('@rolldown/node-binding-linux-s390x-gnu')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
Expand Down
4 changes: 3 additions & 1 deletion crates/rolldown_binding/src/options/input_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ pub struct InputOptions {
// experimentalCacheExpiry?: number;
#[derivative(Debug = "ignore")]
#[serde(skip_deserializing)]
#[napi(ts_type = "(source: string, importer?: string, isResolved?: boolean) => boolean")]
#[napi(
ts_type = "undefined | ((source: string, importer: string | undefined, isResolved: boolean) => boolean)"
)]
pub external: Option<JsFunction>,
pub input: Vec<InputItem>,
// makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource';
Expand Down
11 changes: 10 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test-rust:
cargo test --no-fail-fast

test-node:
yarn build --no-wasm
yarn build:node
yarn test

test:
Expand Down Expand Up @@ -89,6 +89,15 @@ smoke-rust:
just check-rust
just lint-rust

smoke-node:
just test-node
just check-node
just lint-node

smoke:
just smoke-rust
just smoke-node


# BENCHING

Expand Down

0 comments on commit 6f01071

Please sign in to comment.