Skip to content

Commit

Permalink
feat: call PluginDriver transform (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Nov 9, 2023
1 parent 01b3563 commit 42cdd61
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
15 changes: 12 additions & 3 deletions crates/rolldown/src/bundler/module_loader/normal_module_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
visitors::scanner::{self, ScanResult},
},
error::BatchedResult,
HookLoadArgs,
HookLoadArgs, HookTransformArgs,
};
pub struct NormalModuleTask<'task, T: FileSystemExt + Default> {
ctx: &'task ModuleTaskContext<'task, T>,
Expand Down Expand Up @@ -59,14 +59,23 @@ impl<'task, T: FileSystemExt + Default + 'static> NormalModuleTask<'task, T> {
tracing::trace!("process {:?}", self.path);

// Run plugin load to get content first, if it is None using read fs as fallback.
let source = if let Some(r) =
let mut source = if let Some(r) =
self.ctx.plugin_driver.load(&HookLoadArgs { id: self.path.as_ref() }).await?
{
r.code
} else {
self.ctx.fs.read_to_string(self.path.as_path())?
};
// TODO: transform

// Run plugin transform.
if let Some(r) = self
.ctx
.plugin_driver
.transform(&HookTransformArgs { id: self.path.as_ref(), code: &source })
.await?
{
source = r.code;
}

let (ast, scope, scan_result, ast_symbol, namespace_symbol) = self.scan(source);

Expand Down
2 changes: 1 addition & 1 deletion crates/rolldown/src/bundler/plugin_driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl PluginDriver {
Ok(None)
}

pub async fn _transform(&self, args: &HookTransformArgs<'_>) -> HookTransformReturn {
pub async fn transform(&self, args: &HookTransformArgs<'_>) -> HookTransformReturn {
for plugin in &self.plugins {
if let Some(r) = plugin.transform(&mut PluginContext::new(), args).await? {
return Ok(Some(r));
Expand Down
2 changes: 1 addition & 1 deletion crates/rolldown/src/plugin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct HookResolveIdArgs<'a> {

#[derive(Debug)]
pub struct HookTransformArgs<'a> {
pub id: &'a RawPath,
pub id: &'a str,
pub code: &'a String,
}

Expand Down
1 change: 1 addition & 0 deletions packages/rollup-tests/src/failed-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@
"rollup@function@logging@log-from-plugin-simple: prints logs from plugins via input options if there are no handlers",
"rollup@function@logging@loglevel-debug: shows all logs for logLevel:debug",
"rollup@function@logging@loglevel-info: does not show debug logs for logLevel:info",
"rollup@function@logging@loglevel-silent: does not show logs for logLevel:silent",
"rollup@function@logging@loglevel-warn: only shows warning logs for logLevel:warn",
"rollup@function@logging@no-log-with-position: does not support passing a position to this.warn/info/debug outside the transform hook",
"rollup@function@logging@plugin-order: allows to order plugins when logging",
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup-tests/src/status.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"total": 901,
"failed": 0,
"skipFailed": 647,
"skipFailed": 648,
"ignored": 7,
"skipped": 0,
"passed": 247
"passed": 246
}
4 changes: 2 additions & 2 deletions packages/rollup-tests/src/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
|----| ---- |
| total | 901|
| failed | 0|
| skipFailed | 647|
| skipFailed | 648|
| ignored | 7|
| skipped | 0|
| passed | 247|
| passed | 246|

0 comments on commit 42cdd61

Please sign in to comment.