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

add support for globally providing mdx components to turbopack #49818

Merged
merged 5 commits into from May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 33 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -42,11 +42,11 @@ swc_core = { version = "0.75.41" }
testing = { version = "0.33.4" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.2" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.3" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.3" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.3" }

# General Deps

Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-core/js/package.json
Expand Up @@ -10,8 +10,8 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230511.2",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230511.2",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230515.3",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230515.3",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
Expand Down
8 changes: 7 additions & 1 deletion packages/next-swc/crates/next-core/src/fallback.rs
Expand Up @@ -57,7 +57,13 @@ pub async fn get_fallback_page(
let entries = get_client_runtime_entries(project_path, env, ty, next_config, execution_context);

let mut import_map = ImportMap::empty();
insert_next_shared_aliases(&mut import_map, project_path, execution_context).await?;
insert_next_shared_aliases(
&mut import_map,
project_path,
execution_context,
next_config,
)
.await?;

let context: AssetContextVc = ModuleAssetContextVc::new(
TransitionsByNameVc::cell(HashMap::new()),
Expand Down
19 changes: 14 additions & 5 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Expand Up @@ -30,8 +30,8 @@ use turbopack_binding::{
module_options::{
module_options_context::{ModuleOptionsContext, ModuleOptionsContextVc},
CustomEcmascriptTransformPlugins, CustomEcmascriptTransformPluginsVc,
JsxTransformOptions, PostCssTransformOptions, TypescriptTransformOptions,
WebpackLoadersOptions,
JsxTransformOptions, MdxTransformModuleOptions, PostCssTransformOptions,
TypescriptTransformOptions, WebpackLoadersOptions,
},
resolve_options_context::{ResolveOptionsContext, ResolveOptionsContextVc},
transition::TransitionsByNameVc,
Expand All @@ -50,7 +50,7 @@ use crate::{
next_config::NextConfigVc,
next_import_map::{
get_next_client_fallback_import_map, get_next_client_import_map,
get_next_client_resolved_map,
get_next_client_resolved_map, mdx_import_source_file,
},
next_shared::{
resolve::UnsupportedModulesResolvePluginVc, transforms::get_relay_transform_plugin,
Expand Down Expand Up @@ -173,7 +173,16 @@ pub async fn get_client_module_options_context(

let tsconfig = get_typescript_transform_options(project_path);
let decorators_options = get_decorators_transform_options(project_path);
let mdx_rs_options = *next_config.mdx_rs().await?;
let enable_mdx_rs = if *next_config.mdx_rs().await? {
Some(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not need to revise PR if there aren't else to update, but fyi we have https://github.com/vercel/next.js/blob/canary/packages/next-swc/crates/next-core/src/transform_options.rs consolidates fns to building options for the transforms.

MdxTransformModuleOptions {
provider_import_source: Some(mdx_import_source_file()),
}
.cell(),
)
} else {
None
};
let jsx_runtime_options =
get_jsx_transform_options(project_path, Some(resolve_options_context));
let enable_webpack_loaders = {
Expand Down Expand Up @@ -242,7 +251,7 @@ pub async fn get_client_module_options_context(
enable_postcss_transform: postcss_transform_options,
enable_webpack_loaders,
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs: mdx_rs_options,
enable_mdx_rs,
decorators: Some(decorators_options),
rules: vec![
(
Expand Down