add support for pageExtensions in next.config.js (vercel/turbo#3499)
This commit is contained in:
parent
ff69c0f4e0
commit
dc13baf6e7
2 changed files with 58 additions and 50 deletions
|
@ -37,18 +37,19 @@ use crate::embed_js::next_asset;
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct NextConfig {
|
pub struct NextConfig {
|
||||||
pub cross_origin: Option<String>,
|
|
||||||
pub config_file: Option<String>,
|
pub config_file: Option<String>,
|
||||||
pub config_file_name: String,
|
pub config_file_name: String,
|
||||||
|
|
||||||
pub react_strict_mode: Option<bool>,
|
|
||||||
pub experimental: ExperimentalConfig,
|
|
||||||
pub env: IndexMap<String, String>,
|
pub env: IndexMap<String, String>,
|
||||||
pub compiler: Option<CompilerConfig>,
|
pub experimental: ExperimentalConfig,
|
||||||
pub images: ImageConfig,
|
pub images: ImageConfig,
|
||||||
|
pub page_extensions: Vec<String>,
|
||||||
|
pub react_strict_mode: Option<bool>,
|
||||||
pub transpile_packages: Option<Vec<String>>,
|
pub transpile_packages: Option<Vec<String>>,
|
||||||
|
|
||||||
// unsupported
|
// unsupported
|
||||||
|
cross_origin: Option<String>,
|
||||||
|
compiler: Option<CompilerConfig>,
|
||||||
amp: AmpConfig,
|
amp: AmpConfig,
|
||||||
analytics_id: String,
|
analytics_id: String,
|
||||||
asset_prefix: String,
|
asset_prefix: String,
|
||||||
|
@ -72,7 +73,6 @@ pub struct NextConfig {
|
||||||
optimize_fonts: bool,
|
optimize_fonts: bool,
|
||||||
output: Option<OutputType>,
|
output: Option<OutputType>,
|
||||||
output_file_tracing: bool,
|
output_file_tracing: bool,
|
||||||
page_extensions: Vec<String>,
|
|
||||||
powered_by_header: bool,
|
powered_by_header: bool,
|
||||||
production_browser_source_maps: bool,
|
production_browser_source_maps: bool,
|
||||||
public_runtime_config: IndexMap<String, serde_json::Value>,
|
public_runtime_config: IndexMap<String, serde_json::Value>,
|
||||||
|
@ -382,6 +382,11 @@ impl NextConfigVc {
|
||||||
Ok(self.await?.images.clone().cell())
|
Ok(self.await?.images.clone().cell())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[turbo_tasks::function]
|
||||||
|
pub async fn page_extensions(self) -> Result<StringsVc> {
|
||||||
|
Ok(StringsVc::cell(self.await?.page_extensions.clone()))
|
||||||
|
}
|
||||||
|
|
||||||
#[turbo_tasks::function]
|
#[turbo_tasks::function]
|
||||||
pub async fn transpile_packages(self) -> Result<StringsVc> {
|
pub async fn transpile_packages(self) -> Result<StringsVc> {
|
||||||
Ok(StringsVc::cell(
|
Ok(StringsVc::cell(
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use turbo_tasks::{
|
use turbo_tasks::{
|
||||||
primitives::{BoolVc, StringVc},
|
primitives::{BoolVc, StringVc, StringsVc},
|
||||||
trace::TraceRawVcs,
|
trace::TraceRawVcs,
|
||||||
Value,
|
Value,
|
||||||
};
|
};
|
||||||
|
@ -230,6 +230,7 @@ pub async fn create_page_source(
|
||||||
server_data_context,
|
server_data_context,
|
||||||
client_context,
|
client_context,
|
||||||
pages_dir,
|
pages_dir,
|
||||||
|
next_config.page_extensions(),
|
||||||
SpecificityVc::exact(),
|
SpecificityVc::exact(),
|
||||||
0,
|
0,
|
||||||
pages_dir,
|
pages_dir,
|
||||||
|
@ -410,6 +411,7 @@ async fn create_page_source_for_directory(
|
||||||
server_data_context: AssetContextVc,
|
server_data_context: AssetContextVc,
|
||||||
client_context: AssetContextVc,
|
client_context: AssetContextVc,
|
||||||
pages_dir: FileSystemPathVc,
|
pages_dir: FileSystemPathVc,
|
||||||
|
page_extensions: StringsVc,
|
||||||
specificity: SpecificityVc,
|
specificity: SpecificityVc,
|
||||||
position: u32,
|
position: u32,
|
||||||
input_dir: FileSystemPathVc,
|
input_dir: FileSystemPathVc,
|
||||||
|
@ -421,6 +423,8 @@ async fn create_page_source_for_directory(
|
||||||
intermediate_output_path: FileSystemPathVc,
|
intermediate_output_path: FileSystemPathVc,
|
||||||
output_root: FileSystemPathVc,
|
output_root: FileSystemPathVc,
|
||||||
) -> Result<CombinedContentSourceVc> {
|
) -> Result<CombinedContentSourceVc> {
|
||||||
|
let page_extensions_raw = &*page_extensions.await?;
|
||||||
|
|
||||||
let mut sources = vec![];
|
let mut sources = vec![];
|
||||||
let dir_content = input_dir.read_dir().await?;
|
let dir_content = input_dir.read_dir().await?;
|
||||||
if let DirectoryContent::Entries(entries) = &*dir_content {
|
if let DirectoryContent::Entries(entries) = &*dir_content {
|
||||||
|
@ -435,51 +439,49 @@ async fn create_page_source_for_directory(
|
||||||
match entry {
|
match entry {
|
||||||
DirectoryEntry::File(file) => {
|
DirectoryEntry::File(file) => {
|
||||||
if let Some((basename, extension)) = name.rsplit_once('.') {
|
if let Some((basename, extension)) = name.rsplit_once('.') {
|
||||||
match extension {
|
if page_extensions_raw
|
||||||
// pageExtensions option from next.js
|
.iter()
|
||||||
// defaults: https://github.com/vercel/next.js/blob/611e13f5159457fedf96d850845650616a1f75dd/packages/next/server/config-shared.ts#L499
|
.any(|allowed| allowed == extension)
|
||||||
"js" | "ts" | "jsx" | "tsx" | "mdx" => {
|
{
|
||||||
let (dev_server_path, intermediate_output_path, specificity) =
|
let (dev_server_path, intermediate_output_path, specificity) =
|
||||||
if basename == "index" {
|
if basename == "index" {
|
||||||
(
|
(
|
||||||
server_path.join("index.html"),
|
server_path.join("index.html"),
|
||||||
intermediate_output_path,
|
|
||||||
specificity,
|
|
||||||
)
|
|
||||||
} else if basename == "404" {
|
|
||||||
(
|
|
||||||
server_path.join("[...].html"),
|
|
||||||
intermediate_output_path.join(basename),
|
|
||||||
specificity.with_fallback(position),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(
|
|
||||||
server_path.join(basename).join("index.html"),
|
|
||||||
intermediate_output_path.join(basename),
|
|
||||||
specificity,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
sources.push((
|
|
||||||
name,
|
|
||||||
create_page_source_for_file(
|
|
||||||
context_path,
|
|
||||||
server_context,
|
|
||||||
server_data_context,
|
|
||||||
client_context,
|
|
||||||
pages_dir,
|
|
||||||
specificity,
|
|
||||||
*file,
|
|
||||||
runtime_entries,
|
|
||||||
fallback_page,
|
|
||||||
server_root,
|
|
||||||
dev_server_path,
|
|
||||||
dev_server_path.is_inside(server_api_path),
|
|
||||||
intermediate_output_path,
|
intermediate_output_path,
|
||||||
output_root,
|
specificity,
|
||||||
),
|
)
|
||||||
));
|
} else if basename == "404" {
|
||||||
}
|
(
|
||||||
_ => {}
|
server_path.join("[...].html"),
|
||||||
|
intermediate_output_path.join(basename),
|
||||||
|
specificity.with_fallback(position),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
server_path.join(basename).join("index.html"),
|
||||||
|
intermediate_output_path.join(basename),
|
||||||
|
specificity,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
sources.push((
|
||||||
|
name,
|
||||||
|
create_page_source_for_file(
|
||||||
|
context_path,
|
||||||
|
server_context,
|
||||||
|
server_data_context,
|
||||||
|
client_context,
|
||||||
|
pages_dir,
|
||||||
|
specificity,
|
||||||
|
*file,
|
||||||
|
runtime_entries,
|
||||||
|
fallback_page,
|
||||||
|
server_root,
|
||||||
|
dev_server_path,
|
||||||
|
dev_server_path.is_inside(server_api_path),
|
||||||
|
intermediate_output_path,
|
||||||
|
output_root,
|
||||||
|
),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,6 +494,7 @@ async fn create_page_source_for_directory(
|
||||||
server_data_context,
|
server_data_context,
|
||||||
client_context,
|
client_context,
|
||||||
pages_dir,
|
pages_dir,
|
||||||
|
page_extensions,
|
||||||
specificity,
|
specificity,
|
||||||
position + 1,
|
position + 1,
|
||||||
*dir,
|
*dir,
|
||||||
|
|
Loading…
Reference in a new issue