-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print a warning when importing Sass files (vercel/turborepo#4789)
### Description ![image](https://user-images.githubusercontent.com/1621758/235940115-a8958bbb-76df-4353-b3e7-231231960623.png) ### Testing Instructions See [Next.js PR](#49151) link WEB-981
- Loading branch information
Showing
3 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//! TODO(WEB-741) Remove this file once Sass is supported. | ||
use anyhow::Result; | ||
use turbo_tasks::primitives::StringVc; | ||
use turbo_tasks_fs::{glob::GlobVc, FileSystemPathVc}; | ||
use turbopack_core::{ | ||
issue::{Issue, IssueSeverity, IssueSeverityVc, IssueVc}, | ||
resolve::{ | ||
parse::RequestVc, | ||
plugin::{ResolvePlugin, ResolvePluginConditionVc, ResolvePluginVc}, | ||
ResolveResultOptionVc, | ||
}, | ||
}; | ||
|
||
/// Resolve plugins that warns when importing a sass file. | ||
#[turbo_tasks::value] | ||
pub(crate) struct UnsupportedSassResolvePlugin { | ||
root: FileSystemPathVc, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl UnsupportedSassResolvePluginVc { | ||
#[turbo_tasks::function] | ||
pub fn new(root: FileSystemPathVc) -> Self { | ||
UnsupportedSassResolvePlugin { root }.cell() | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ResolvePlugin for UnsupportedSassResolvePlugin { | ||
#[turbo_tasks::function] | ||
fn after_resolve_condition(&self) -> ResolvePluginConditionVc { | ||
ResolvePluginConditionVc::new(self.root.root(), GlobVc::new("**/*.{sass,scss}")) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
async fn after_resolve( | ||
&self, | ||
fs_path: FileSystemPathVc, | ||
context: FileSystemPathVc, | ||
request: RequestVc, | ||
) -> Result<ResolveResultOptionVc> { | ||
let extension = fs_path.extension().await?; | ||
if ["sass", "scss"].iter().any(|ext| ext == &*extension) { | ||
UnsupportedSassModuleIssue { context, request } | ||
.cell() | ||
.as_issue() | ||
.emit(); | ||
} | ||
|
||
Ok(ResolveResultOptionVc::none()) | ||
} | ||
} | ||
|
||
#[turbo_tasks::value(shared)] | ||
struct UnsupportedSassModuleIssue { | ||
context: FileSystemPathVc, | ||
request: RequestVc, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl Issue for UnsupportedSassModuleIssue { | ||
#[turbo_tasks::function] | ||
fn severity(&self) -> IssueSeverityVc { | ||
IssueSeverity::Warning.into() | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn category(&self) -> StringVc { | ||
StringVc::cell("resolve".to_string()) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
async fn title(&self) -> Result<StringVc> { | ||
Ok(StringVc::cell(format!( | ||
"Unsupported Sass request: {}", | ||
self.request.await?.request().as_deref().unwrap_or("N/A") | ||
))) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn context(&self) -> FileSystemPathVc { | ||
self.context | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn description(&self) -> StringVc { | ||
StringVc::cell("Turbopack does not yet support importing Sass modules.".to_string()) | ||
} | ||
} |