Skip to content

Commit

Permalink
Merge branch 'canary' into eslint-plugin-next
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle authored Jul 6, 2023
2 parents 9bcb3eb + 4b2eef4 commit 8e95cf7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 73 deletions.
14 changes: 4 additions & 10 deletions packages/next-swc/crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ async fn next_client_transition(
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);
let client_module_options_context = get_client_module_options_context(
project_path,
Expand Down Expand Up @@ -277,7 +276,7 @@ fn next_edge_route_transition(
project_path,
output_path.join("edge"),
output_path.join("edge/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("app_source"))
Expand Down Expand Up @@ -317,7 +316,7 @@ fn next_edge_page_transition(
project_path,
output_path.join("edge-pages"),
output_path.join("edge-pages/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.layer("ssr")
Expand Down Expand Up @@ -1112,7 +1111,7 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
project_path,
intermediate_output_path,
intermediate_output_path.join("chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
context.compile_time_info().environment(),
)
.layer("ssr")
Expand Down Expand Up @@ -1207,12 +1206,7 @@ impl AppRouteVc {
this.project_path,
this.intermediate_output_path,
this.intermediate_output_path.join("chunks"),
get_client_assets_path(
this.server_root,
Value::new(ClientContextType::App {
app_dir: this.app_dir,
}),
),
get_client_assets_path(this.server_root),
this.context.compile_time_info().environment(),
)
.layer("ssr")
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub async fn get_fallback_page(
project_path,
dev_server_root,
client_compile_time_info.environment(),
ty,
);
let entries =
get_client_runtime_entries(project_path, env, ty, mode, next_config, execution_context);
Expand Down
26 changes: 6 additions & 20 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,37 +312,23 @@ pub fn get_client_asset_context(
#[turbo_tasks::function]
pub fn get_client_chunking_context(
project_path: FileSystemPathVc,
server_root: FileSystemPathVc,
client_root: FileSystemPathVc,
environment: EnvironmentVc,
ty: Value<ClientContextType>,
) -> ChunkingContextVc {
DevChunkingContextVc::builder(
project_path,
server_root,
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => server_root.join("/_next/static/chunks"),
ClientContextType::Other => server_root.join("/_chunks"),
},
get_client_assets_path(server_root, ty),
client_root,
client_root.join("/_next/static/chunks"),
get_client_assets_path(client_root),
environment,
)
.hot_module_replacement()
.build()
}

#[turbo_tasks::function]
pub fn get_client_assets_path(
client_root: FileSystemPathVc,
ty: Value<ClientContextType>,
) -> FileSystemPathVc {
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => client_root.join("/_next/static/media"),
ClientContextType::Other => client_root.join("/_assets"),
}
pub fn get_client_assets_path(client_root: FileSystemPathVc) -> FileSystemPathVc {
client_root.join("/_next/static/media")
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl NextClientChunksTransitionVc {
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);

let client_module_options_context = get_client_module_options_context(
Expand Down
23 changes: 4 additions & 19 deletions packages/next-swc/crates/next-core/src/page_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ pub async fn create_page_source(
project_root,
client_root,
client_compile_time_info.environment(),
client_ty,
);

let client_runtime_entries = get_client_runtime_entries(
Expand Down Expand Up @@ -155,10 +154,7 @@ pub async fn create_page_source(
project_root,
node_root.join("edge"),
node_root.join("edge/chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand Down Expand Up @@ -360,10 +356,7 @@ async fn create_page_source_for_file(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -375,10 +368,7 @@ async fn create_page_source_for_file(
project_path,
data_node_path,
data_node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -388,7 +378,6 @@ async fn create_page_source_for_file(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);

let pathname = pathname_for_path(client_root, client_path, PathType::Page);
Expand Down Expand Up @@ -530,10 +519,7 @@ async fn create_not_found_page_source(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -543,7 +529,6 @@ async fn create_not_found_page_source(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);

let (page_asset, pathname) =
Expand Down
8 changes: 2 additions & 6 deletions packages/next-swc/crates/next-core/src/web_entry_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ pub async fn create_web_entry_source(
mode,
next_config,
);
let chunking_context = get_client_chunking_context(
project_root,
client_root,
compile_time_info.environment(),
ty,
);
let chunking_context =
get_client_chunking_context(project_root, client_root, compile_time_info.environment());
let entries = get_web_runtime_entries(project_root, ty, mode, next_config, execution_context);

let runtime_entries = entries.resolve_entries(context);
Expand Down
18 changes: 7 additions & 11 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,16 @@ async function createTreeCodeFromPath(
}

// We need to resolve all parallel routes in this level.
const files = await fs.readdir(absoluteSegmentPath)
const files = await fs.opendir(absoluteSegmentPath)

const parallelSegments: string[] = ['children']

await Promise.all(
files.map(async (file) => {
const filePath = path.join(absoluteSegmentPath, file)
const stat = await fs.stat(filePath)

if (stat.isDirectory() && file.startsWith('@')) {
parallelSegments.push(file)
}
})
)
for await (const dirent of files) {
// Make sure name starts with "@" and is a directory.
if (dirent.isDirectory() && dirent.name.charCodeAt(0) === 64) {
parallelSegments.push(dirent.name)
}
}

return parallelSegments
}
Expand Down
9 changes: 4 additions & 5 deletions packages/next/src/server/lib/recursive-readdir-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ export function recursiveReadDirSync(
/** Used to replace the initial path, only the relative path is left, it's faster than path.relative. */
rootDir = dir
): string[] {
const result = fs.readdirSync(dir)
const result = fs.readdirSync(dir, { withFileTypes: true })

result.forEach((part: string) => {
const absolutePath = join(dir, part)
const pathStat = fs.statSync(absolutePath)
result.forEach((part) => {
const absolutePath = join(dir, part.name)

if (pathStat.isDirectory()) {
if (part.isDirectory()) {
recursiveReadDirSync(absolutePath, arr, rootDir)
return
}
Expand Down

0 comments on commit 8e95cf7

Please sign in to comment.