Skip to content

Commit

Permalink
refactor(next-core): reduce duplicated decl
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Apr 26, 2023
1 parent e1d0367 commit dfc1c1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub async fn get_server_resolve_options_context(
get_next_server_import_map(project_path, ty, next_config, execution_context);
let foreign_code_context_condition = foreign_code_context_condition(next_config).await?;
let root_dir = project_path.root().resolve().await?;
let unsupported_modules_resolve_plugin = UnsupportedModulesResolvePluginVc::new(project_path);

Ok(match ty.into_value() {
ServerContextType::Pages { .. } | ServerContextType::PagesData { .. } => {
Expand All @@ -82,7 +83,7 @@ pub async fn get_server_resolve_options_context(
import_map: Some(next_server_import_map),
plugins: vec![
external_cjs_modules_plugin.into(),
UnsupportedModulesResolvePluginVc::new(project_path).into(),
unsupported_modules_resolve_plugin.into(),
],
..Default::default()
};
Expand All @@ -104,7 +105,7 @@ pub async fn get_server_resolve_options_context(
module: true,
custom_conditions: vec!["development".to_string()],
import_map: Some(next_server_import_map),
plugins: vec![UnsupportedModulesResolvePluginVc::new(project_path).into()],
plugins: vec![unsupported_modules_resolve_plugin.into()],
..Default::default()
};
ResolveOptionsContext {
Expand All @@ -125,7 +126,7 @@ pub async fn get_server_resolve_options_context(
module: true,
custom_conditions: vec!["development".to_string(), "react-server".to_string()],
import_map: Some(next_server_import_map),
plugins: vec![UnsupportedModulesResolvePluginVc::new(project_path).into()],
plugins: vec![unsupported_modules_resolve_plugin.into()],
..Default::default()
};
ResolveOptionsContext {
Expand All @@ -144,7 +145,7 @@ pub async fn get_server_resolve_options_context(
module: true,
custom_conditions: vec!["development".to_string()],
import_map: Some(next_server_import_map),
plugins: vec![UnsupportedModulesResolvePluginVc::new(project_path).into()],
plugins: vec![unsupported_modules_resolve_plugin.into()],
..Default::default()
};
ResolveOptionsContext {
Expand All @@ -163,7 +164,7 @@ pub async fn get_server_resolve_options_context(
enable_node_externals: true,
module: true,
custom_conditions: vec!["development".to_string()],
plugins: vec![UnsupportedModulesResolvePluginVc::new(project_path).into()],
plugins: vec![unsupported_modules_resolve_plugin.into()],
..Default::default()
};
ResolveOptionsContext {
Expand Down
8 changes: 4 additions & 4 deletions packages/next-swc/crates/next-core/src/next_shared/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use turbo_binding::{
use turbo_tasks_fs::glob::GlobVc;

lazy_static! {
static ref UNSUPPORTED_PACKAGES: HashSet<String> = ["@vercel/og".to_owned()].into();
static ref UNSUPPORTED_PACKAGE_PATHS: HashSet<(String, String)> = [].into();
static ref UNSUPPORTED_PACKAGES: HashSet<&'static str> = ["@vercel/og"].into();
static ref UNSUPPORTED_PACKAGE_PATHS: HashSet<(&'static str, &'static str)> = [].into();
}

#[turbo_tasks::value]
Expand Down Expand Up @@ -55,7 +55,7 @@ impl ResolvePlugin for UnsupportedModulesResolvePlugin {
} = &*request.await?
{
// Warn if the package is known not to be supported by Turbopack at the moment.
if UNSUPPORTED_PACKAGES.contains(module) {
if UNSUPPORTED_PACKAGES.contains(module.as_str()) {
UnsupportedModuleIssue {
context,
package: module.into(),
Expand All @@ -67,7 +67,7 @@ impl ResolvePlugin for UnsupportedModulesResolvePlugin {
}

if let Pattern::Constant(path) = path {
if UNSUPPORTED_PACKAGE_PATHS.contains(&(module.to_string(), path.to_owned())) {
if UNSUPPORTED_PACKAGE_PATHS.contains(&(module, path)) {
UnsupportedModuleIssue {
context,
package: module.into(),
Expand Down

0 comments on commit dfc1c1e

Please sign in to comment.