Skip to content

Commit

Permalink
Merge branch 'canary' into kdy1/swc-core-0-90-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Feb 20, 2024
2 parents a4aa66b + b63196f commit e7486f6
Show file tree
Hide file tree
Showing 68 changed files with 1,923 additions and 1,605 deletions.
26 changes: 26 additions & 0 deletions docs/02-app/02-api-reference/05-next-config-js/turbo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,30 @@ This aliases imports of the `underscore` package to the `lodash` package. In oth

Turbopack also supports conditional aliasing through this field, similar to Node.js's [conditional exports](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports). At the moment only the `browser` condition is supported. In the case above, imports of the `mocha` module will be aliased to `mocha/browser-entry.js` when Turbopack targets browser environments.

## Resolve Extensions

Through `next.config.js`, Turbopack can be configured to resolve modules with custom extensions, similar to webpack's [`resolve.extensions`](https://webpack.js.org/configuration/resolve/#resolveextensions) configuration.

To configure resolve extension, use the `resolveExtensions` field in `next.config.js`:

```js filename="next.config.js"
module.exports = {
experimental: {
turbo: {
resolveExtensions: [
'.mdx',
'.tsx',
'.ts',
'.jsx',
'.js',
'.mjs',
'.json',
],
},
},
}
```

This overwrites the original resolve extensions with the provided list. Make sure to include the default extensions.

For more information and guidance for how to migrate your app to Turbopack from webpack, see [Turbopack's documentation on webpack compatibility](https://turbo.build/pack/docs/migrating-from-webpack).
45 changes: 45 additions & 0 deletions errors/next-dynamic-api-wrong-context.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Dynamic API was called outside request
---

#### Why This Error Occurred

A Dynamic API was called outside a request scope. (Eg.: Global scope).

Note that Dynamic APIs could have been called deep inside other modules/functions (eg.: third-party libraries) that are not immediately visible.

#### Possible Ways to Fix It

Make sure that all Dynamic API calls happen in a request scope.

Example:

```diff
// app/page.ts
import { cookies } from 'next/headers'

- const cookieStore = cookies()
export default function Page() {
+ const cookieStore = cookies()
return ...
}
```

```diff
// app/foo/route.ts
import { headers } from 'next/headers'

- const headersList = headers()
export async function GET() {
+ const headersList = headers()
return ...
}
```

### Useful Links

- [`headers()` function](https://nextjs.org/docs/app/api-reference/functions/headers)
- [`cookies()` function](https://nextjs.org/docs/app/api-reference/functions/cookies)
- [`draftMode()` function](https://nextjs.org/docs/app/api-reference/functions/draft-mode)
- [`unstable_noStore()` function](https://nextjs.org/docs/app/api-reference/functions/unstable_noStore)
- [`unstable_cache()` function](https://nextjs.org/docs/app/api-reference/functions/unstable_cache)
1 change: 1 addition & 0 deletions examples/with-jest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"jsx": "preserve",
"incremental": true,
"baseUrl": ".",
"types": ["@testing-library/jest-dom"],
"paths": {
"@/components/*": ["components/*"],
"@/pages/*": ["pages/*"],
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": "14.1.1-canary.61"
"version": "14.1.1-canary.62"
}
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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"@next/eslint-plugin-next": "14.1.1-canary.62",
"@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": "14.1.1-canary.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"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.61",
"version": "14.1.1-canary.62",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
43 changes: 33 additions & 10 deletions packages/next-swc/crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,27 @@ pub async fn project_update(

#[napi(object)]
#[derive(Default)]
struct NapiRoute {
struct AppPageNapiRoute {
/// The relative path from project_path to the route file
pub original_name: Option<String>,

pub html_endpoint: Option<External<ExternalEndpoint>>,
pub rsc_endpoint: Option<External<ExternalEndpoint>>,
}

#[napi(object)]
#[derive(Default)]
struct NapiRoute {
/// The router path
pub pathname: String,
/// The relative path from project_path to the route file
pub original_name: Option<String>,

/// The type of route, eg a Page or App
pub r#type: &'static str,

pub pages: Option<Vec<AppPageNapiRoute>>,

// Different representations of the endpoint
pub endpoint: Option<External<ExternalEndpoint>>,
pub html_endpoint: Option<External<ExternalEndpoint>>,
Expand Down Expand Up @@ -349,18 +363,27 @@ impl NapiRoute {
endpoint: convert_endpoint(endpoint),
..Default::default()
},
Route::AppPage {
html_endpoint,
rsc_endpoint,
} => NapiRoute {
Route::AppPage(pages) => NapiRoute {
pathname,
r#type: "app-page",
html_endpoint: convert_endpoint(html_endpoint),
rsc_endpoint: convert_endpoint(rsc_endpoint),
pages: Some(
pages
.into_iter()
.map(|page_route| AppPageNapiRoute {
original_name: Some(page_route.original_name),
html_endpoint: convert_endpoint(page_route.html_endpoint),
rsc_endpoint: convert_endpoint(page_route.rsc_endpoint),
})
.collect(),
),
..Default::default()
},
Route::AppRoute { endpoint } => NapiRoute {
Route::AppRoute {
original_name,
endpoint,
} => NapiRoute {
pathname,
original_name: Some(original_name),
r#type: "app-route",
endpoint: convert_endpoint(endpoint),
..Default::default()
Expand Down Expand Up @@ -481,8 +504,8 @@ pub fn project_entrypoints_subscribe(
routes: entrypoints
.routes
.iter()
.map(|(pathname, &route)| {
NapiRoute::from_route(pathname.clone(), route, &turbo_tasks)
.map(|(pathname, route)| {
NapiRoute::from_route(pathname.clone(), route.clone(), &turbo_tasks)
})
.collect::<Vec<_>>(),
middleware: entrypoints
Expand Down

0 comments on commit e7486f6

Please sign in to comment.