Skip to content

Commit

Permalink
Merge branch 'canary' into shu/4d3c
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 23, 2023
2 parents abffcf3 + a65e5c0 commit 907b413
Show file tree
Hide file tree
Showing 47 changed files with 980 additions and 874 deletions.
238 changes: 119 additions & 119 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ next-transform-dynamic = { path = "packages/next-swc/crates/next-transform-dynam
next-transform-strip-page-exports = { path = "packages/next-swc/crates/next-transform-strip-page-exports" }

# SWC crates
swc_core = { version = "0.86.1", features = [
swc_core = { version = "0.86.10", features = [
"ecma_loader_lru",
"ecma_loader_parking_lot",
] }
testing = { version = "0.35.0" }

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

# General Deps

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "13.5.7-canary.14"
"version": "13.5.7-canary.16"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "13.5.7-canary.14",
"@next/eslint-plugin-next": "13.5.7-canary.16",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"description": "ESLint plugin for Next.js.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "13.5.7-canary.14",
"version": "13.5.7-canary.16",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
7 changes: 1 addition & 6 deletions packages/next-swc/crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ impl Project {
#[turbo_tasks::function]
pub(super) async fn client_compile_time_info(&self) -> Result<Vc<CompileTimeInfo>> {
Ok(get_client_compile_time_info(
self.mode,
self.browserslist_query.clone(),
self.define_env.client(),
))
Expand All @@ -485,22 +484,19 @@ impl Project {
pub(super) async fn server_compile_time_info(self: Vc<Self>) -> Result<Vc<CompileTimeInfo>> {
let this = self.await?;
Ok(get_server_compile_time_info(
this.mode,
self.env(),
self.server_addr(),
this.define_env.nodejs(),
self.next_config(),
))
}

#[turbo_tasks::function]
pub(super) async fn edge_compile_time_info(self: Vc<Self>) -> Result<Vc<CompileTimeInfo>> {
let this = self.await?;
Ok(get_edge_compile_time_info(
this.mode,
self.project_path(),
self.server_addr(),
this.define_env.nodejs(),
this.define_env.edge(),
))
}

Expand Down Expand Up @@ -534,7 +530,6 @@ impl Project {
get_edge_chunking_context(
self.project_path(),
self.node_root(),
self.client_relative_path(),
self.edge_compile_time_info().environment(),
)
}
Expand Down
11 changes: 3 additions & 8 deletions packages/next-swc/crates/next-build/src/next_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,11 @@ pub(crate) async fn next_build(options: TransientInstance<BuildOptions>) -> Resu

let client_define_env = Vc::cell(options.define_env.client.iter().cloned().collect());
let client_compile_time_info =
get_client_compile_time_info(mode, browserslist_query, client_define_env);
get_client_compile_time_info(browserslist_query, client_define_env);

let server_define_env = Vc::cell(options.define_env.nodejs.iter().cloned().collect());
let server_compile_time_info = get_server_compile_time_info(
mode,
env,
ServerAddr::empty(),
server_define_env,
next_config,
);
let server_compile_time_info =
get_server_compile_time_info(env, ServerAddr::empty(), server_define_env);

// TODO(alexkirsz) Pages should build their own routes, outside of a FS.
let next_router_fs = Vc::upcast::<Box<dyn FileSystem>>(VirtualFileSystem::new());
Expand Down
44 changes: 18 additions & 26 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use turbopack_binding::{
turbo::{tasks_env::EnvMap, tasks_fs::FileSystemPath},
turbopack::{
core::{
compile_time_defines,
compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReference,
FreeVarReferences,
Expand Down Expand Up @@ -64,40 +63,34 @@ use crate::{
util::foreign_code_context_condition,
};

fn defines(mode: NextMode, define_env: &IndexMap<String, String>) -> CompileTimeDefines {
// Need the empty NEXT_RUNTIME here for compile time evaluation.
let mut defines = compile_time_defines!(
process.turbopack = true,
process.env.NEXT_RUNTIME = "",
process.env.NODE_ENV = mode.node_env(),
process.env.TURBOPACK = true,
);
fn defines(define_env: &IndexMap<String, String>) -> CompileTimeDefines {
let mut defines = IndexMap::new();

for (k, v) in define_env {
defines
.0
.entry(k.split('.').map(|s| s.to_string()).collect())
.or_insert_with(|| CompileTimeDefineValue::JSON(v.clone()));
.entry(k.split('.').map(|s| s.to_string()).collect::<Vec<String>>())
.or_insert_with(|| {
let val = serde_json::from_str(v);
match val {
Ok(serde_json::Value::Bool(v)) => CompileTimeDefineValue::Bool(v),
Ok(serde_json::Value::String(v)) => CompileTimeDefineValue::String(v),
_ => CompileTimeDefineValue::JSON(v.clone()),
}
});
}

defines
CompileTimeDefines(defines)
}

#[turbo_tasks::function]
async fn next_client_defines(
mode: NextMode,
define_env: Vc<EnvMap>,
) -> Result<Vc<CompileTimeDefines>> {
Ok(defines(mode, &*define_env.await?).cell())
async fn next_client_defines(define_env: Vc<EnvMap>) -> Result<Vc<CompileTimeDefines>> {
Ok(defines(&*define_env.await?).cell())
}

#[turbo_tasks::function]
async fn next_client_free_vars(
mode: NextMode,
define_env: Vc<EnvMap>,
) -> Result<Vc<FreeVarReferences>> {
async fn next_client_free_vars(define_env: Vc<EnvMap>) -> Result<Vc<FreeVarReferences>> {
Ok(free_var_references!(
..defines(mode, &*define_env.await?).into_iter(),
..defines(&*define_env.await?).into_iter(),
Buffer = FreeVarReference::EcmaScriptModule {
request: "node:buffer".to_string(),
lookup_path: None,
Expand All @@ -114,7 +107,6 @@ async fn next_client_free_vars(

#[turbo_tasks::function]
pub fn get_client_compile_time_info(
mode: NextMode,
browserslist_query: String,
define_env: Vc<EnvMap>,
) -> Vc<CompileTimeInfo> {
Expand All @@ -127,8 +119,8 @@ pub fn get_client_compile_time_info(
}
.into(),
))))
.defines(next_client_defines(mode, define_env))
.free_var_references(next_client_free_vars(mode, define_env))
.defines(next_client_defines(define_env))
.free_var_references(next_client_free_vars(define_env))
.cell()
}

Expand Down
48 changes: 21 additions & 27 deletions packages/next-swc/crates/next-core/src/next_edge/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use turbopack_binding::{
turbo::{tasks_env::EnvMap, tasks_fs::FileSystemPath},
turbopack::{
core::{
compile_time_defines,
compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReference,
FreeVarReferences,
Expand All @@ -22,7 +21,6 @@ use turbopack_binding::{

use crate::{
mode::NextMode,
next_client::context::get_client_assets_path,
next_config::NextConfig,
next_import_map::get_next_edge_import_map,
next_server::context::ServerContextType,
Expand All @@ -33,40 +31,37 @@ use crate::{
util::foreign_code_context_condition,
};

fn defines(mode: NextMode, define_env: &IndexMap<String, String>) -> CompileTimeDefines {
let mut defines = compile_time_defines!(
process.turbopack = true,
process.env.NEXT_RUNTIME = "edge",
process.env.NODE_ENV = mode.node_env(),
process.env.TURBOPACK = true,
);
fn defines(define_env: &IndexMap<String, String>) -> CompileTimeDefines {
let mut defines = IndexMap::new();

for (k, v) in define_env {
defines
.0
.entry(k.split('.').map(|s| s.to_string()).collect())
.or_insert_with(|| CompileTimeDefineValue::JSON(v.clone()));
.entry(k.split('.').map(|s| s.to_string()).collect::<Vec<String>>())
.or_insert_with(|| {
let val = serde_json::from_str(v);
match val {
Ok(serde_json::Value::Bool(v)) => CompileTimeDefineValue::Bool(v),
Ok(serde_json::Value::String(v)) => CompileTimeDefineValue::String(v),
_ => CompileTimeDefineValue::JSON(v.clone()),
}
});
}

defines
CompileTimeDefines(defines)
}

#[turbo_tasks::function]
async fn next_edge_defines(
mode: NextMode,
define_env: Vc<EnvMap>,
) -> Result<Vc<CompileTimeDefines>> {
Ok(defines(mode, &*define_env.await?).cell())
async fn next_edge_defines(define_env: Vc<EnvMap>) -> Result<Vc<CompileTimeDefines>> {
Ok(defines(&*define_env.await?).cell())
}

#[turbo_tasks::function]
async fn next_edge_free_vars(
mode: NextMode,
project_path: Vc<FileSystemPath>,
define_env: Vc<EnvMap>,
) -> Result<Vc<FreeVarReferences>> {
Ok(free_var_references!(
..defines(mode, &*define_env.await?).into_iter(),
..defines(&*define_env.await?).into_iter(),
Buffer = FreeVarReference::EcmaScriptModule {
request: "next/dist/compiled/buffer".to_string(),
lookup_path: Some(project_path),
Expand All @@ -83,16 +78,15 @@ async fn next_edge_free_vars(

#[turbo_tasks::function]
pub fn get_edge_compile_time_info(
mode: NextMode,
project_path: Vc<FileSystemPath>,
server_addr: Vc<ServerAddr>,
define_env: Vc<EnvMap>,
) -> Vc<CompileTimeInfo> {
CompileTimeInfo::builder(Environment::new(Value::new(
ExecutionEnvironment::EdgeWorker(EdgeWorkerEnvironment { server_addr }.into()),
)))
.defines(next_edge_defines(mode, define_env))
.free_var_references(next_edge_free_vars(mode, project_path, define_env))
.defines(next_edge_defines(define_env))
.free_var_references(next_edge_free_vars(project_path, define_env))
.cell()
}

Expand Down Expand Up @@ -155,15 +149,15 @@ pub async fn get_edge_resolve_options_context(
pub fn get_edge_chunking_context(
project_path: Vc<FileSystemPath>,
node_root: Vc<FileSystemPath>,
client_root: Vc<FileSystemPath>,
environment: Vc<Environment>,
) -> Vc<Box<dyn EcmascriptChunkingContext>> {
let output_root = node_root.join("server/edge".to_string());
Vc::upcast(
DevChunkingContext::builder(
project_path,
node_root.join("server/edge".to_string()),
node_root.join("server/edge/chunks".to_string()),
get_client_assets_path(client_root),
output_root,
output_root.join("chunks".to_string()),
output_root.join("assets".to_string()),
environment,
)
.reference_chunk_source_maps(should_debug("edge"))
Expand Down
Loading

0 comments on commit 907b413

Please sign in to comment.