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

Skip postcss config location resolving in node_modules #60697

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ swc_core = { version = "0.87.16", features = [
testing = { version = "0.35.14" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240117.1" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", branch = "01-16-Allow_skipping_postcss_relative_config_resolving" } # last tag: "turbopack-240117.1"
# [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-240117.1" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", branch = "01-16-Allow_skipping_postcss_relative_config_resolving" } # last tag: "turbopack-240117.1"
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240117.1" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", branch = "01-16-Allow_skipping_postcss_relative_config_resolving" } # last tag: "turbopack-240117.1"

# General Deps

Expand Down
27 changes: 20 additions & 7 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ use turbopack_binding::{
},
dev::{react_refresh::assert_can_resolve_react_refresh, DevChunkingContext},
ecmascript::{chunk::EcmascriptChunkingContext, TreeShakingMode},
node::execution_context::ExecutionContext,
node::{
execution_context::ExecutionContext,
transforms::postcss::{PostCssConfigLocation, PostCssTransformOptions},
},
turbopack::{
condition::ContextCondition,
module_options::{
module_options_context::ModuleOptionsContext, CustomEcmascriptTransformPlugins,
JsxTransformOptions, MdxTransformModuleOptions, PostCssTransformOptions,
TypescriptTransformOptions, WebpackLoadersOptions,
JsxTransformOptions, MdxTransformModuleOptions, TypescriptTransformOptions,
WebpackLoadersOptions,
},
resolve_options_context::ResolveOptionsContext,
},
Expand Down Expand Up @@ -258,23 +261,34 @@ pub async fn get_client_module_options_context(
},
));

let postcss_transform_options = Some(PostCssTransformOptions {
let postcss_transform_options = PostCssTransformOptions {
postcss_package: Some(get_postcss_package_mapping(project_path)),
config_location: PostCssConfigLocation::ProjectPathOrLocalPath,
..Default::default()
});
};
let postcss_foreign_transform_options = PostCssTransformOptions {
// For node_modules we don't want to resolve postcss config relative to the file being
// compiled, instead it only uses the project root postcss config.
config_location: PostCssConfigLocation::ProjectPath,
..postcss_transform_options.clone()
};
let enable_postcss_transform = Some(postcss_transform_options.cell());
let enable_foreign_postcss_transform = Some(postcss_foreign_transform_options.cell());

let module_options_context = ModuleOptionsContext {
preset_env_versions: Some(env),
execution_context: Some(execution_context),
custom_ecma_transform_plugins,
tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly),
enable_postcss_transform,
..Default::default()
};

// node_modules context
let foreign_codes_options_context = ModuleOptionsContext {
enable_webpack_loaders: foreign_webpack_loaders,
enable_postcss_transform: enable_foreign_postcss_transform,
// NOTE(WEB-1016) PostCSS transforms should also apply to foreign code.
enable_postcss_transform: postcss_transform_options.clone(),
..module_options_context.clone()
};

Expand All @@ -284,7 +298,6 @@ pub async fn get_client_module_options_context(
// the modules.
enable_jsx: Some(jsx_runtime_options),
enable_webpack_loaders,
enable_postcss_transform: postcss_transform_options,
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs,
decorators: Some(decorators_options),
Expand Down
Loading