Skip to content

Commit

Permalink
Automatic babel-loader followup (vercel/turborepo#3944)
Browse files Browse the repository at this point in the history
This:
* Addresses feedback from vercel/turborepo#3862
* Exempts VirtualAssets from webpack loaders. This addresses a bug where
next-hydrate.tsx could not be read.
	* Adds `ModuleRuleCondition::ResourceIsVirtualAsset` to filter these

---------

Co-authored-by: Justin Ridgewell <[email protected]>
  • Loading branch information
wbinnssmith and jridgewell authored Feb 27, 2023
1 parent 2b863a4 commit 0d8a5a7
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/next-core/src/babel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use turbo_tasks::{
primitives::{BoolVc, StringVc},
Value,
};
use turbo_tasks_fs::FileSystemPathVc;
use turbo_tasks_fs::{FileSystemEntryType, FileSystemPathVc};
use turbopack::{
module_options::WebpackLoadersOptionsVc, resolve_options,
resolve_options_context::ResolveOptionsContext,
Expand Down Expand Up @@ -37,8 +37,8 @@ pub async fn maybe_add_babel_loader(
let has_babel_config = {
let mut has_babel_config = false;
for filename in BABEL_CONFIG_FILES {
let metadata = project_root.join(filename).metadata().await;
if metadata.is_ok() {
let filetype = *project_root.join(filename).get_type().await?;
if matches!(filetype, FileSystemEntryType::File) {
has_babel_config = true;
break;
}
Expand All @@ -48,6 +48,7 @@ pub async fn maybe_add_babel_loader(

if has_babel_config {
let mut options = (*webpack_options.await?).clone();
let mut has_emitted_babel_resolve_issue = false;
for ext in [".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"] {
let configs = options.extension_to_loaders.get(ext);
let has_babel_loader = match configs {
Expand All @@ -73,7 +74,9 @@ pub async fn maybe_add_babel_loader(
};

if !has_babel_loader {
if !*(is_babel_loader_available(project_root).await?) {
if !has_emitted_babel_resolve_issue
&& !*is_babel_loader_available(project_root).await?
{
BabelIssue {
path: project_root,
title: StringVc::cell(
Expand All @@ -88,7 +91,9 @@ pub async fn maybe_add_babel_loader(
}
.cell()
.as_issue()
.emit()
.emit();

has_emitted_babel_resolve_issue = true;
}

let loader = WebpackLoaderConfigItem::LoaderName("babel-loader".to_owned());
Expand Down

0 comments on commit 0d8a5a7

Please sign in to comment.