Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable mdx parsing in turbotrace #3304

Merged
merged 9 commits into from
Jan 17, 2023
Merged
14 changes: 11 additions & 3 deletions crates/node-file-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ pub struct CommonArgs {
#[cfg_attr(feature = "cli", clap(short, long))]
#[cfg_attr(feature = "node-api", serde(default))]
exact: bool,

/// Whether to enable mdx parsing while tracing dependencies
#[cfg_attr(feature = "cli", clap(short, long))]
#[cfg_attr(feature = "node-api", serde(default))]
enable_mdx: bool,
}

#[cfg_attr(feature = "cli", derive(Parser))]
Expand Down Expand Up @@ -230,6 +235,7 @@ async fn input_to_modules<'a>(
input: Vec<String>,
process_cwd: Option<String>,
exact: bool,
enable_mdx: bool,
) -> Result<AssetsVc> {
let root = fs.root();
let env = EnvironmentVc::new(
Expand Down Expand Up @@ -259,6 +265,7 @@ async fn input_to_modules<'a>(
env,
ModuleOptionsContext {
enable_types: true,
enable_mdx,
..Default::default()
}
.cell(),
Expand Down Expand Up @@ -513,6 +520,7 @@ async fn main_operation(
ref input,
watch,
exact,
enable_mdx,
ref context_directory,
ref process_cwd,
..
Expand All @@ -526,7 +534,7 @@ async fn main_operation(
let input = process_input(&dir, &context, input).unwrap();
let mut result = BTreeSet::new();
let fs = create_fs("context directory", &context, watch).await?;
let modules = input_to_modules(fs, input, process_cwd, exact).await?;
let modules = input_to_modules(fs, input, process_cwd, exact, enable_mdx).await?;
for module in modules.iter() {
let set = all_assets(*module);
IssueVc::attach_context(module.path(), "gathering list of assets".to_string(), set)
Expand All @@ -544,7 +552,7 @@ async fn main_operation(
let fs = create_fs("context directory", &context, watch).await?;
let mut output_nft_assets = Vec::new();
let mut emits = Vec::new();
for module in input_to_modules(fs, input, process_cwd, exact)
for module in input_to_modules(fs, input, process_cwd, exact, enable_mdx)
.await?
.iter()
{
Expand All @@ -570,7 +578,7 @@ async fn main_operation(
let input_dir = fs.root();
let output_dir = out_fs.root();
let mut emits = Vec::new();
for module in input_to_modules(fs, input, process_cwd, exact)
for module in input_to_modules(fs, input, process_cwd, exact, enable_mdx)
.await?
.iter()
{
Expand Down
16 changes: 10 additions & 6 deletions crates/turbopack/src/module_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl ModuleOptionsVc {
enable_styled_components,
enable_types,
enable_typescript_transform,
enable_mdx,
ref enable_postcss_transform,
ref enable_webpack_loaders,
preset_env_versions,
Expand Down Expand Up @@ -128,12 +129,6 @@ impl ModuleOptionsVc {
ModuleRuleCondition::ResourcePathEndsWith(".json".to_string()),
vec![ModuleRuleEffect::ModuleType(ModuleType::Json)],
),
ModuleRule::new(
ModuleRuleCondition::ResourcePathEndsWith(".mdx".to_string()),
vec![ModuleRuleEffect::ModuleType(ModuleType::Mdx(
mdx_transforms,
))],
),
ModuleRule::new(
ModuleRuleCondition::ResourcePathEndsWith(".css".to_string()),
[
Expand Down Expand Up @@ -238,6 +233,15 @@ impl ModuleOptionsVc {
),
];

if enable_mdx {
rules.push(ModuleRule::new(
ModuleRuleCondition::ResourcePathEndsWith(".mdx".to_string()),
vec![ModuleRuleEffect::ModuleType(ModuleType::Mdx(
mdx_transforms,
))],
));
}

if let Some(webpack_loaders_options) = enable_webpack_loaders {
let execution_context = execution_context
.context("execution_context is required for webpack_loaders")?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct ModuleOptionsContext {
pub enable_webpack_loaders: Option<WebpackLoadersOptions>,
pub enable_types: bool,
pub enable_typescript_transform: bool,
pub enable_mdx: bool,
pub preset_env_versions: Option<EnvironmentVc>,
pub custom_ecmascript_app_transforms: Vec<EcmascriptInputTransform>,
pub custom_ecmascript_transforms: Vec<EcmascriptInputTransform>,
Expand Down
1 change: 1 addition & 0 deletions crates/turbopack/tests/node-file-trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static ALLOC: turbo_malloc::TurboMalloc = turbo_malloc::TurboMalloc;
#[case::mailgun("integration/mailgun.js")]
#[case::mariadb("integration/mariadb.js")]
#[case::memcached("integration/memcached.js")]
#[case::mdx("integration/mdx/index.js")]
#[case::mongoose("integration/mongoose.js")]
#[case::mysql("integration/mysql.js")]
#[case::npm("integration/npm.js")]
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Chart} from './snowfall.jsx'
export const year = 2018

# Last year’s snowfall

In {year}, the snowfall was above average.
It was followed by a warm spring which caused
flood conditions in many of the nearby rivers.

<Chart year={year} color="#fcb32c" />
14 changes: 14 additions & 0 deletions crates/turbopack/tests/node-file-trace/integration/mdx/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const moduleAlias = require("module-alias");
const os = require("os");

require("./empty");

moduleAlias.addAlias("./example.mdx", __dirname + "/empty.js");

const Example = require("./example.mdx");

const { existsSync } = eval("require")("fs");

if (__dirname.startsWith(os.tmpdir()) && existsSync("./snowfall.jsx")) {
throw new Error("snowfall.jsx should not exist");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function Chart({ year, color }) {
return (
<div>
{year} - {color}
</div>
);
}
1 change: 1 addition & 0 deletions crates/turbopack/tests/node-file-trace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"mailgun": "^0.5.0",
"mariadb": "^2.0.5",
"memcached": "^2.2.2",
"module-alias": "^2.2.2",
"mongoose": "^5.7.5",
"mysql": "^2.17.1",
"npm": "^6.14.6",
Expand Down
Loading