Skip to content

Commit

Permalink
Merge 46d21ec into e6b27e8
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Jan 13, 2023
2 parents e6b27e8 + 46d21ec commit 1c04f5d
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 46 deletions.
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.
10 changes: 10 additions & 0 deletions crates/turbopack/tests/node-file-trace/integration/mdx/example.mdx
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

0 comments on commit 1c04f5d

Please sign in to comment.