-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(next-core): emit unsupported package warning (#48837)
### What? WEB-953. This PR moves, bubbles up unsupported package warning from turbopack to next-core using resolve plugin. Featurewise it behaves same, however removes turbopack aware specific next.js package (`@vercel/og`) internally.
- Loading branch information
Showing
7 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub(crate) mod resolve; | ||
pub(crate) mod transforms; |
85 changes: 85 additions & 0 deletions
85
packages/next-swc/crates/next-core/src/next_shared/resolve.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::collections::HashSet; | ||
|
||
use anyhow::Result; | ||
use lazy_static::lazy_static; | ||
use turbo_binding::{ | ||
turbo::tasks_fs::FileSystemPathVc, | ||
turbopack::core::{ | ||
issue::unsupported_module::UnsupportedModuleIssue, | ||
resolve::{ | ||
parse::{Request, RequestVc}, | ||
pattern::Pattern, | ||
plugin::{ResolvePlugin, ResolvePluginConditionVc, ResolvePluginVc}, | ||
ResolveResultOptionVc, | ||
}, | ||
}, | ||
}; | ||
use turbo_tasks_fs::glob::GlobVc; | ||
|
||
lazy_static! { | ||
static ref UNSUPPORTED_PACKAGES: HashSet<&'static str> = ["@vercel/og"].into(); | ||
static ref UNSUPPORTED_PACKAGE_PATHS: HashSet<(&'static str, &'static str)> = [].into(); | ||
} | ||
|
||
#[turbo_tasks::value] | ||
pub(crate) struct UnsupportedModulesResolvePlugin { | ||
root: FileSystemPathVc, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl UnsupportedModulesResolvePluginVc { | ||
#[turbo_tasks::function] | ||
pub fn new(root: FileSystemPathVc) -> Self { | ||
UnsupportedModulesResolvePlugin { root }.cell() | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ResolvePlugin for UnsupportedModulesResolvePlugin { | ||
#[turbo_tasks::function] | ||
fn after_resolve_condition(&self) -> ResolvePluginConditionVc { | ||
ResolvePluginConditionVc::new(self.root.root(), GlobVc::new("**")) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
async fn after_resolve( | ||
&self, | ||
_fs_path: FileSystemPathVc, | ||
context: FileSystemPathVc, | ||
request: RequestVc, | ||
) -> Result<ResolveResultOptionVc> { | ||
if let Request::Module { | ||
module, | ||
path, | ||
query: _, | ||
} = &*request.await? | ||
{ | ||
// Warn if the package is known not to be supported by Turbopack at the moment. | ||
if UNSUPPORTED_PACKAGES.contains(module.as_str()) { | ||
UnsupportedModuleIssue { | ||
context, | ||
package: module.into(), | ||
package_path: None, | ||
} | ||
.cell() | ||
.as_issue() | ||
.emit(); | ||
} | ||
|
||
if let Pattern::Constant(path) = path { | ||
if UNSUPPORTED_PACKAGE_PATHS.contains(&(module, path)) { | ||
UnsupportedModuleIssue { | ||
context, | ||
package: module.into(), | ||
package_path: Some(path.to_owned()), | ||
} | ||
.cell() | ||
.as_issue() | ||
.emit(); | ||
} | ||
} | ||
} | ||
|
||
Ok(ResolveResultOptionVc::none()) | ||
} | ||
} |