Skip to content

Commit

Permalink
Merge branch 'canary' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding authored Feb 28, 2024
2 parents ef7fe4d + 6b6575c commit e54c052
Show file tree
Hide file tree
Showing 96 changed files with 1,870 additions and 1,499 deletions.
325 changes: 163 additions & 162 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ next-core = { path = "packages/next-swc/crates/next-core" }
next-custom-transforms = { path = "packages/next-swc/crates/next-custom-transforms" }

# SWC crates
swc_core = { version = "0.90.10", features = [
swc_core = { version = "0.90.12", features = [
"ecma_loader_lru",
"ecma_loader_parking_lot",
] }
testing = { version = "0.35.18" }
testing = { version = "0.35.19" }

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

# General Deps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ export async function getUserData() {
data
)
experimental_taintUniqueValue(
"Do not pass the user's phone number to the client",
"Do not pass the user's address to the client",
data,
data.phoneNumber
data.address
)
return data
}
Expand All @@ -364,9 +364,9 @@ export async function getUserData() {
data
)
experimental_taintUniqueValue(
"Do not pass the user's phone number to the client",
"Do not pass the user's address to the client",
data,
data.phoneNumber
data.address
)
return data
}
Expand All @@ -380,7 +380,7 @@ export async function Page() {
return (
<ClientComponent
user={userData} // this will cause an error because of taintObjectReference
phoneNumber={userData.phoneNumber} // this will cause an error because of taintUniqueValue
address={userData.address} // this will cause an error because of taintUniqueValue
/>
)
}
Expand All @@ -394,7 +394,7 @@ export async function Page() {
return (
<ClientComponent
user={userData} // this will cause an error because of taintObjectReference
phoneNumber={userData.phoneNumber} // this will cause an error because of taintUniqueValue
address={userData.address} // this will cause an error because of taintUniqueValue
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,18 @@ Here's how to implement Middleware for authentication in Next.js:
Example Middleware file:

```ts filename="middleware.ts" switcher
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export function middleware(request: NextRequest) {
const currentUser = request.cookies.get('currentUser')?.value

if (currentUser) {
return NextResponse.redirect(new URL('/dashboard', request.url))
if (currentUser && !request.nextUrl.pathname.startsWith('/dashboard')) {
return Response.redirect(new URL('/dashboard', request.url))
}

if (!currentUser && !request.nextUrl.pathname.startsWith('/login')) {
return Response.redirect(new URL('/login', request.url))
}
return NextResponse.redirect(new URL('/login', request.url))
}

export const config = {
Expand All @@ -363,23 +365,24 @@ export const config = {
```

```js filename="middleware.js" switcher
import { NextResponse } from 'next/server'

export function middleware(request) {
const currentUser = request.cookies.get('currentUser')?.value

if (currentUser) {
return NextResponse.redirect(new URL('/dashboard', request.url))
if (currentUser && !request.nextUrl.pathname.startsWith('/dashboard')) {
return Response.redirect(new URL('/dashboard', request.url))
}

if (!currentUser && !request.nextUrl.pathname.startsWith('/login')) {
return Response.redirect(new URL('/login', request.url))
}
return NextResponse.redirect(new URL('/login', request.url))
}

export const config = {
matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'],
}
```
This example uses [`NextResponse.redirect`](/docs/app/api-reference/functions/next-response#redirect) for handling redirects early in the request pipeline, making it efficient and centralizing access control.
This example uses [`Response.redirect`](https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static) for handling redirects early in the request pipeline, making it efficient and centralizing access control.
<AppOnly>
Expand Down
2 changes: 1 addition & 1 deletion examples/with-cypress/components/about-component.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AboutComponent from "./components/about-component";
import AboutComponent from "./about-component";
/* eslint-disable */
// Disable ESLint to prevent failing linting inside the Next.js repo.
// If you're using ESLint on your project, we recommend installing the ESLint Cypress plugin instead:
Expand Down
2 changes: 1 addition & 1 deletion examples/with-cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"strictNullChecks": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "**/*.cy.*"]
}
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": "14.1.1-canary.74"
"version": "14.1.1-canary.78"
}
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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"@next/eslint-plugin-next": "14.1.1-canary.78",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0 || ^7.0.1",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"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": "14.1.1-canary.74",
"version": "14.1.1-canary.78",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/napi/src/next_api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub async fn get_diagnostics<T: Send>(source: Vc<T>) -> Result<Arc<Vec<ReadRef<P
#[napi(object)]
pub struct NapiIssue {
pub severity: String,
pub category: String,
pub stage: String,
pub file_path: String,
pub title: serde_json::Value,
pub description: Option<serde_json::Value>,
Expand All @@ -119,7 +119,7 @@ impl From<&PlainIssue> for NapiIssue {
.description
.as_ref()
.map(|styled| serde_json::to_value(StyledStringSerialize::from(styled)).unwrap()),
category: issue.category.clone(),
stage: issue.stage.to_string(),
file_path: issue.file_path.clone(),
detail: issue
.detail
Expand Down
37 changes: 27 additions & 10 deletions packages/next-swc/crates/napi/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,27 @@ pub enum Input {
pub struct TransformTask {
pub c: Arc<Compiler>,
pub input: Input,
pub options: Buffer,
pub options: Vec<u8>,
}

#[inline]
fn skip_filename() -> bool {
cfg!(debug_assertions)
}

fn run_in_context<F, Ret>(op: F) -> Ret
where
F: FnOnce() -> Ret,
{
GLOBALS.set(&Default::default(), op)
}

impl Task for TransformTask {
type Output = (TransformOutput, FxHashSet<String>);
type JsValue = Object;

fn compute(&mut self) -> napi::Result<Self::Output> {
GLOBALS.set(&Default::default(), || {
fn compute(&mut self) -> Result<Self::Output> {
run_in_context(|| {
let eliminated_packages: Rc<RefCell<fxhash::FxHashSet<String>>> = Default::default();
let res = catch_unwind(AssertUnwindSafe(|| {
try_with_handler(
Expand Down Expand Up @@ -161,18 +168,18 @@ impl Task for TransformTask {
&mut self,
env: Env,
(output, eliminated_packages): Self::Output,
) -> napi::Result<Self::JsValue> {
) -> Result<Self::JsValue> {
complete_output(&env, output, eliminated_packages)
}
}

#[napi]
pub fn transform(
env: Env,
src: Either3<String, Buffer, Undefined>,
_is_module: bool,
options: Buffer,
signal: Option<AbortSignal>,
) -> napi::Result<AsyncTask<TransformTask>> {
) -> Result<Object> {
let c = get_compiler();

let input = match src {
Expand All @@ -183,8 +190,14 @@ pub fn transform(
Either3::C(_) => Input::FromFilename,
};

let task = TransformTask { c, input, options };
Ok(AsyncTask::with_optional_signal(task, signal))
let options = options.to_vec();

let mut task = TransformTask { c, input, options };

env.execute_tokio_future(
async move { task.compute() },
|env, (output, eliminated_packages)| complete_output(env, output, eliminated_packages),
)
}

#[napi]
Expand All @@ -193,7 +206,7 @@ pub fn transform_sync(
src: Either3<String, Buffer, Undefined>,
_is_module: bool,
options: Buffer,
) -> napi::Result<Object> {
) -> Result<Object> {
let c = get_compiler();

let input = match src {
Expand All @@ -204,8 +217,12 @@ pub fn transform_sync(
Either3::C(_) => Input::FromFilename,
};

let options = options.to_vec();

let mut task = TransformTask { c, input, options };
let output = task.compute()?;

let output = block_on(async { task.compute() })?;

task.resolve(env, output)
}
#[test]
Expand Down
8 changes: 4 additions & 4 deletions packages/next-swc/crates/next-core/src/app_segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use turbopack_binding::{
file_source::FileSource,
ident::AssetIdent,
issue::{
Issue, IssueExt, IssueSeverity, IssueSource, OptionIssueSource, OptionStyledString,
StyledString,
Issue, IssueExt, IssueSeverity, IssueSource, IssueStage, OptionIssueSource,
OptionStyledString, StyledString,
},
source::Source,
},
Expand Down Expand Up @@ -173,8 +173,8 @@ impl Issue for NextSegmentConfigParsingIssue {
}

#[turbo_tasks::function]
fn category(&self) -> Vc<String> {
Vc::cell("parsing".to_string())
fn stage(&self) -> Vc<IssueStage> {
IssueStage::Parse.into()
}

#[turbo_tasks::function]
Expand Down
8 changes: 5 additions & 3 deletions packages/next-swc/crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use turbo_tasks::{
};
use turbopack_binding::{
turbo::tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath},
turbopack::core::issue::{Issue, IssueExt, IssueSeverity, OptionStyledString, StyledString},
turbopack::core::issue::{
Issue, IssueExt, IssueSeverity, IssueStage, OptionStyledString, StyledString,
},
};

use crate::{
Expand Down Expand Up @@ -1217,8 +1219,8 @@ impl Issue for DirectoryTreeIssue {
}

#[turbo_tasks::function]
fn category(&self) -> Vc<String> {
Vc::cell("next app".to_string())
fn stage(&self) -> Vc<IssueStage> {
IssueStage::AppStructure.cell()
}

#[turbo_tasks::function]
Expand Down
Loading

0 comments on commit e54c052

Please sign in to comment.