Skip to content

feat: provide more friendly diagnostics if could not read path from a resolveId hook#1866

Merged
IWANABETHATGUY merged 10 commits intorolldown:mainfrom
shulaoda:feat/friendly-diagnostic-for-unresolved-import
Aug 6, 2024
Merged

feat: provide more friendly diagnostics if could not read path from a resolveId hook#1866
IWANABETHATGUY merged 10 commits intorolldown:mainfrom
shulaoda:feat/friendly-diagnostic-for-unresolved-import

Conversation

@shulaoda
Copy link
Copy Markdown
Member

@shulaoda shulaoda commented Aug 5, 2024

Description

Closes #1851

I don't know if it should be simply regarded as a rolldown internal error.

At first, I tried to implement the incorrect format of esbuild, but later I found that rolldown is not enough to support me in doing so.
wecom-temp-17469-893230717fe496ece769b4a6e33e9aeb

Therefore, I attempted to implement the incorrect format of rollup.
wecom-temp-92390-a41e8d41a7c53c93daa4c7e305564416

Due to the current lack of support for plugins in rolldown testing, I am unable to conduct testing on rust. In addition, testing in fixtures can lead to build errors, so currently I can only ignore it.
image

@netlify
Copy link
Copy Markdown

netlify bot commented Aug 5, 2024

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit fd04bbc
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/66b251c35358d900088b2f82

@IWANABETHATGUY
Copy link
Copy Markdown
Member

I think the pr still needs some refactoring and basic infra to be merged, it should not cost too much time.

@shulaoda
Copy link
Copy Markdown
Member Author

shulaoda commented Aug 5, 2024

I think the pr still needs some refactoring and basic infra to be merged, it should not cost too much time.

What should I do? What should be the expected effect?

@IWANABETHATGUY
Copy link
Copy Markdown
Member

IWANABETHATGUY commented Aug 5, 2024

I think the pr still needs some refactoring and basic infra to be merged, it should not cost too much time.

What should I do? What should be the expected effect?

It is not related to your pull request, resolve ID should not be String, It will cause none trivial overhead. you could continue when I refactor the related type.

@IWANABETHATGUY
Copy link
Copy Markdown
Member

Also we lack the test infra to diagnostics in js side, if there is no test guaranteed, implementation is somehow meaningless(except it is a hotfix).

@hyf0 hyf0 self-assigned this Aug 5, 2024
github-merge-queue bot pushed a commit that referenced this pull request Aug 5, 2024
<!-- Thank you for contributing! -->

### Description
1. replace `Arc<str>` with `ArcStr`
2. replace `String` with `ArcStr`
3. Normalize type related to module id

related to #1866
<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
@shulaoda shulaoda marked this pull request as draft August 5, 2024 11:43
@shulaoda shulaoda marked this pull request as ready for review August 5, 2024 13:13
@IWANABETHATGUY
Copy link
Copy Markdown
Member

after #1871, you could acquire module_request and module_request_span, can you use module_request instead of resolved id?I think now, we have nothing to block aligning diagnostic with esbuild.

github-merge-queue bot pushed a commit that referenced this pull request Aug 5, 2024
<!-- Thank you for contributing! -->

### Description
1. This pr add the ability to get the span of `module_request`.
2. Aiming to keep the type size unchanged, I did some refactors, If I
add `Span` directly the type size will increase from `40` to `48` bytes.
This time, I'm sticking with the current impl, since `8` bytes for each
`RawImportRecord` is none trivial, think about it, for a medium-size
project (10000 ~ 20000 modules with minimum import records only one),
this could save about (80 ~ 150MB) memory.
Related to #1866
<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
@shulaoda
Copy link
Copy Markdown
Member Author

shulaoda commented Aug 5, 2024

after #1871, you could acquire module_request and module_request_span, can you use module_request instead of resolved id?I think now, we have nothing to block aligning diagnostic with esbuild.

Let me start to try it. 😀

@shulaoda
Copy link
Copy Markdown
Member Author

shulaoda commented Aug 6, 2024

Due to my inability to intercept Rust's error output on the js side, it is a bit difficult to perform diagnostic test on the js side. Currently, I have only implemented onerror to obtain Build failed.
image

@IWANABETHATGUY
Copy link
Copy Markdown
Member

diff --git a/crates/rolldown/tests/rolldown/mod.rs b/crates/rolldown/tests/rolldown/mod.rs
index 9ef19e33..936bf634 100644
--- a/crates/rolldown/tests/rolldown/mod.rs
+++ b/crates/rolldown/tests/rolldown/mod.rs
@@ -1,2 +1,3 @@
 mod errors;
 mod issues;
+mod warnings;
diff --git a/crates/rolldown/tests/rolldown/warnings/mod.rs b/crates/rolldown/tests/rolldown/warnings/mod.rs
new file mode 100644
index 00000000..5da035d2
--- /dev/null
+++ b/crates/rolldown/tests/rolldown/warnings/mod.rs
@@ -0,0 +1,2 @@
+#[path = "./unloadable_import/mod.rs"]
+mod unloadable_import;
diff --git a/crates/rolldown/tests/rolldown/warnings/unloadable_import/artifacts.snap b/crates/rolldown/tests/rolldown/warnings/unloadable_import/artifacts.snap
new file mode 100644
index 00000000..303153af
--- /dev/null
+++ b/crates/rolldown/tests/rolldown/warnings/unloadable_import/artifacts.snap
@@ -0,0 +1,17 @@
+---
+source: crates/rolldown_testing/src/integration_test.rs
+---
+# Errors
+
+## UNRESOLVED_IMPORT
+
+```text
+[UNRESOLVED_IMPORT] Error: Could not resolve test.js
+   ╭─[entry.js:1:8]
+
+ 1 │ import 'test.js'
+   │        ────┬────  
+   │            ╰────── No such file or directory (os error 2)
+───╯
+
+```
diff --git a/crates/rolldown/tests/rolldown/warnings/unloadable_import/entry.js b/crates/rolldown/tests/rolldown/warnings/unloadable_import/entry.js
new file mode 100644
index 00000000..0d98f1ed
--- /dev/null
+++ b/crates/rolldown/tests/rolldown/warnings/unloadable_import/entry.js
@@ -0,0 +1 @@
+import 'test.js'
diff --git a/crates/rolldown/tests/rolldown/warnings/unloadable_import/mod.rs b/crates/rolldown/tests/rolldown/warnings/unloadable_import/mod.rs
new file mode 100644
index 00000000..62029f1d
--- /dev/null
+++ b/crates/rolldown/tests/rolldown/warnings/unloadable_import/mod.rs
@@ -0,0 +1,53 @@
+use std::{borrow::Cow, sync::Arc};
+
+use rolldown::{BundlerOptions, InputItem};
+use rolldown_plugin::{
+  HookResolveIdArgs, HookResolveIdOutput, HookResolveIdReturn, Plugin, SharedPluginContext,
+};
+use rolldown_testing::{abs_file_dir, integration_test::IntegrationTest, test_config::TestMeta};
+
+#[derive(Debug)]
+struct UnLoadableImport;
+
+impl Plugin for UnLoadableImport {
+  fn name(&self) -> Cow<'static, str> {
+    "unloadable-import".into()
+  }
+
+  async fn resolve_id(
+    &self,
+    _ctx: &SharedPluginContext,
+    args: &HookResolveIdArgs<'_>,
+  ) -> HookResolveIdReturn {
+    if args.specifier == "test.js" {
+      return Ok(Some(HookResolveIdOutput {
+        id: args.specifier.to_string(),
+        ..Default::default()
+      }));
+    }
+    Ok(None)
+  }
+}
+
+#[tokio::test(flavor = "multi_thread")]
+async fn should_emit_diagnostic_when_could_not_load_dependency() {
+  let cwd = abs_file_dir!();
+
+  IntegrationTest::new(TestMeta {
+    expect_executed: false,
+    expect_error: true,
+    ..Default::default()
+  })
+  .run_with_plugins(
+    BundlerOptions {
+      input: Some(vec![InputItem {
+        name: Some("entry".to_string()),
+        import: "./entry.js".to_string(),
+      }]),
+      cwd: Some(cwd),
+      ..Default::default()
+    },
+    vec![Arc::new(UnLoadableImport)],
+  )
+  .await;
+}

@IWANABETHATGUY
Copy link
Copy Markdown
Member

IWANABETHATGUY commented Aug 6, 2024

Can you patch this rust test, and revert all modifications on the js side? The new JS tests seems meaningless.

@IWANABETHATGUY
Copy link
Copy Markdown
Member

Overall, LGTM, but I prefer the unloadable_dependency rather than unresolve_import, since the error happened in load_source phase, it is resolved by resolve hook already. cc @hyf0 what do you think?

@hyf0
Copy link
Copy Markdown
Member

hyf0 commented Aug 6, 2024

Overall, LGTM, but I prefer the unloadable_dependency rather than unresolve_import, since the error happened in load_source phase, it is resolved by resolve hook already. cc @hyf0 what do you think?

Yeah. A new error would be more proper.

auto-merge was automatically disabled August 6, 2024 16:38

Head branch was pushed to by a user without write access

@shulaoda shulaoda requested a review from hyf0 August 6, 2024 16:39
@IWANABETHATGUY
Copy link
Copy Markdown
Member

Thanks

@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Aug 6, 2024
Merged via the queue into rolldown:main with commit 690a63f Aug 6, 2024
@shulaoda shulaoda deleted the feat/friendly-diagnostic-for-unresolved-import branch August 9, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Provide more friendly diagnostics if could not read path from a resolveId hook

3 participants