Unverified Commit dd27732f authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: enable `import with {type: 'text'}` by default (#95606)

It's time: https://github.com/tc39/proposal-import-text/issues/12
parent 3c0fd70f
...@@ -364,7 +364,6 @@ pub async fn get_client_module_options_context( ...@@ -364,7 +364,6 @@ pub async fn get_client_module_options_context(
esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Relative), esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Relative),
enable_typeof_window_inlining: Some(TypeofWindow::Object), enable_typeof_window_inlining: Some(TypeofWindow::Object),
enable_import_as_bytes: *next_config.turbopack_import_type_bytes().await?, enable_import_as_bytes: *next_config.turbopack_import_type_bytes().await?,
enable_import_as_text: *next_config.turbopack_import_type_text().await?,
source_maps, source_maps,
infer_module_side_effects: *next_config.turbopack_infer_module_side_effects().await?, infer_module_side_effects: *next_config.turbopack_infer_module_side_effects().await?,
preset_env_config, preset_env_config,
......
...@@ -1384,7 +1384,6 @@ pub struct ExperimentalConfig { ...@@ -1384,7 +1384,6 @@ pub struct ExperimentalConfig {
turbopack_client_side_nested_async_chunking: Option<bool>, turbopack_client_side_nested_async_chunking: Option<bool>,
turbopack_server_side_nested_async_chunking: Option<bool>, turbopack_server_side_nested_async_chunking: Option<bool>,
turbopack_import_type_bytes: Option<bool>, turbopack_import_type_bytes: Option<bool>,
turbopack_import_type_text: Option<bool>,
/// Disable automatic configuration of the sass loader. /// Disable automatic configuration of the sass loader.
#[serde(default)] #[serde(default)]
turbopack_use_builtin_sass: Option<bool>, turbopack_use_builtin_sass: Option<bool>,
...@@ -2540,15 +2539,6 @@ impl NextConfig { ...@@ -2540,15 +2539,6 @@ impl NextConfig {
) )
} }
#[turbo_tasks::function]
pub async fn turbopack_import_type_text(&self) -> Vc<bool> {
Vc::cell(
self.experimental
.turbopack_import_type_text
.unwrap_or(false),
)
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn lightningcss_feature_flags( pub fn lightningcss_feature_flags(
&self, &self,
......
...@@ -574,7 +574,6 @@ pub async fn get_server_module_options_context( ...@@ -574,7 +574,6 @@ pub async fn get_server_module_options_context(
ecmascript: EcmascriptOptionsContext { ecmascript: EcmascriptOptionsContext {
enable_typeof_window_inlining: Some(TypeofWindow::Undefined), enable_typeof_window_inlining: Some(TypeofWindow::Undefined),
enable_import_as_bytes: *next_config.turbopack_import_type_bytes().await?, enable_import_as_bytes: *next_config.turbopack_import_type_bytes().await?,
enable_import_as_text: *next_config.turbopack_import_type_text().await?,
import_externals: *next_config.import_externals().await?, import_externals: *next_config.import_externals().await?,
ignore_dynamic_requests: true, ignore_dynamic_requests: true,
source_maps, source_maps,
......
...@@ -397,7 +397,6 @@ export const experimentalSchema = { ...@@ -397,7 +397,6 @@ export const experimentalSchema = {
turbopackClientSideNestedAsyncChunking: z.boolean().optional(), turbopackClientSideNestedAsyncChunking: z.boolean().optional(),
turbopackServerSideNestedAsyncChunking: z.boolean().optional(), turbopackServerSideNestedAsyncChunking: z.boolean().optional(),
turbopackImportTypeBytes: z.boolean().optional(), turbopackImportTypeBytes: z.boolean().optional(),
turbopackImportTypeText: z.boolean().optional(),
turbopackUseBuiltinBabel: z.boolean().optional(), turbopackUseBuiltinBabel: z.boolean().optional(),
turbopackUseBuiltinSass: z.boolean().optional(), turbopackUseBuiltinSass: z.boolean().optional(),
turbopackLocalPostcssConfig: z.boolean().optional(), turbopackLocalPostcssConfig: z.boolean().optional(),
......
...@@ -759,11 +759,6 @@ export interface ExperimentalConfig { ...@@ -759,11 +759,6 @@ export interface ExperimentalConfig {
*/ */
turbopackImportTypeBytes?: boolean turbopackImportTypeBytes?: boolean
/**
* Enable support for `with {type: "text"}` for ESM imports.
*/
turbopackImportTypeText?: boolean
/** /**
* Enable scope hoisting. Defaults to true in build mode. Always disabled in development mode. * Enable scope hoisting. Defaults to true in build mode. Always disabled in development mode.
*/ */
......
...@@ -3,7 +3,6 @@ import type { NextConfig } from 'next' ...@@ -3,7 +3,6 @@ import type { NextConfig } from 'next'
const config: NextConfig = { const config: NextConfig = {
experimental: { experimental: {
turbopackImportTypeBytes: true, turbopackImportTypeBytes: true,
turbopackImportTypeText: true,
}, },
turbopack: { turbopack: {
rules: { rules: {
......
...@@ -243,7 +243,6 @@ impl ModuleOptions { ...@@ -243,7 +243,6 @@ impl ModuleOptions {
enable_typeof_window_inlining, enable_typeof_window_inlining,
enable_exports_info_inlining, enable_exports_info_inlining,
enable_import_as_bytes, enable_import_as_bytes,
enable_import_as_text,
source_maps: ecmascript_source_maps, source_maps: ecmascript_source_maps,
inline_helpers, inline_helpers,
infer_module_side_effects, infer_module_side_effects,
...@@ -413,20 +412,18 @@ impl ModuleOptions { ...@@ -413,20 +412,18 @@ impl ModuleOptions {
)); ));
} }
if enable_import_as_text { rules.push(ModuleRule::new(
rules.push(ModuleRule::new( RuleCondition::ReferenceType(ReferenceTypeCondition::EcmaScriptModules(Some(
RuleCondition::ReferenceType(ReferenceTypeCondition::EcmaScriptModules(Some( EcmaScriptModulesReferenceSubType::ImportWithType("text".into()),
EcmaScriptModulesReferenceSubType::ImportWithType("text".into()), ))),
))), if is_tracing {
if is_tracing { vec![ModuleRuleEffect::ModuleType(ModuleType::Raw)]
vec![ModuleRuleEffect::ModuleType(ModuleType::Raw)] } else {
} else { vec![ModuleRuleEffect::SourceTransforms(ResolvedVc::cell(vec![
vec![ModuleRuleEffect::SourceTransforms(ResolvedVc::cell(vec![ ResolvedVc::upcast(TextSourceTransform::new().to_resolved().await?),
ResolvedVc::upcast(TextSourceTransform::new().to_resolved().await?), ]))]
]))] },
}, ));
));
}
if let Some(webpack_loaders_options) = enable_webpack_loaders { if let Some(webpack_loaders_options) = enable_webpack_loaders {
let webpack_loaders_options = webpack_loaders_options.await?; let webpack_loaders_options = webpack_loaders_options.await?;
......
...@@ -275,9 +275,6 @@ pub struct EcmascriptOptionsContext { ...@@ -275,9 +275,6 @@ pub struct EcmascriptOptionsContext {
/// Whether to enable `import bytes from 'module' with { type: "bytes" }` syntax. /// Whether to enable `import bytes from 'module' with { type: "bytes" }` syntax.
pub enable_import_as_bytes: bool, pub enable_import_as_bytes: bool,
/// Whether to enable `import text from 'module' with { type: "text" }` syntax.
pub enable_import_as_text: bool,
// TODO should this be a part of Environment instead? // TODO should this be a part of Environment instead?
pub inline_helpers: bool, pub inline_helpers: bool,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment