Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a5b73c3f
Unverified
Commit
a5b73c3f
authored
Jul 22, 2025
by
Niklas Mischkulnig
Committed by
GitHub
Jul 22, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport: Turbopack: fix dist dir on Windows (#81758) (#81925)
parent
1617b266
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
134 additions
and
91 deletions
+134
-91
build_and_test.yml
.github/workflows/build_and_test.yml
+3
-2
project.rs
crates/napi/src/next_api/project.rs
+20
-17
project.rs
crates/next-api/src/project.rs
+44
-32
generated-native.d.ts
packages/next/src/build/swc/generated-native.d.ts
+21
-10
index.ts
packages/next/src/build/swc/index.ts
+5
-2
types.ts
packages/next/src/build/swc/types.ts
+8
-4
impl.ts
packages/next/src/build/turbopack-build/impl.ts
+3
-1
utils.ts
...es/next/src/build/webpack/loaders/css-loader/src/utils.ts
+1
-4
normalize-path.ts
packages/next/src/lib/normalize-path.ts
+5
-0
hot-reloader-turbopack.ts
packages/next/src/server/dev/hot-reloader-turbopack.ts
+8
-6
setup-dev-bundler.ts
...ges/next/src/server/lib/router-utils/setup-dev-bundler.ts
+7
-0
next-rs-api.test.ts
test/development/basic/next-rs-api.test.ts
+8
-13
lib.rs
turbopack/crates/turbo-tasks-fs/src/lib.rs
+1
-0
No files found.
.github/workflows/build_and_test.yml
View file @
a5b73c3f
...
@@ -705,10 +705,11 @@ jobs:
...
@@ -705,10 +705,11 @@ jobs:
afterBuild
:
|
afterBuild
:
|
export NEXT_TEST_MODE=start
export NEXT_TEST_MODE=start
node run-tests.js \
node run-tests.js
--type production
\
test/e2e/app-dir/app/index.test.ts \
test/e2e/app-dir/app/index.test.ts \
test/e2e/app-dir/app-edge/app-edge.test.ts \
test/e2e/app-dir/app-edge/app-edge.test.ts \
test/e2e/app-dir/metadata-edge/index.test.ts
test/e2e/app-dir/metadata-edge/index.test.ts \
test/e2e/app-dir/non-root-project-monorepo/non-root-project-monorepo.test.ts
stepName
:
'
test-prod-windows'
stepName
:
'
test-prod-windows'
runs_on_labels
:
'
["windows","self-hosted","x64"]'
runs_on_labels
:
'
["windows","self-hosted","x64"]'
buildNativeTarget
:
'
x86_64-pc-windows-msvc'
buildNativeTarget
:
'
x86_64-pc-windows-msvc'
...
...
crates/napi/src/next_api/project.rs
View file @
a5b73c3f
...
@@ -122,15 +122,18 @@ pub struct NapiWatchOptions {
...
@@ -122,15 +122,18 @@ pub struct NapiWatchOptions {
#[napi(object)]
#[napi(object)]
pub
struct
NapiProjectOptions
{
pub
struct
NapiProjectOptions
{
/// A root path from which all files must be nested under. Trying to access
/// An absolute root path (Unix or Windows path) from which all files must be nested under.
/// a file outside this root will fail. Think of this as a chroot.
/// Trying to access a file outside this root will fail, so think of this as a chroot.
/// E.g. `/home/user/projects/my-repo`.
pub
root_path
:
RcStr
,
pub
root_path
:
RcStr
,
/// A path inside the root_path which contains the app/pages directories.
/// A path which contains the app/pages directories, relative to [`Project::root_path`], always
/// Unix path. E.g. `apps/my-app`
pub
project_path
:
RcStr
,
pub
project_path
:
RcStr
,
/// next.config's distDir. Project initialization occurs earlier than
/// A path where to emit the build outputs, relative to [`Project::project_path`], always Unix
/// deserializing next.config, so passing it as separate option.
/// path. Corresponds to next.config.js's `distDir`.
/// E.g. `.next`
pub
dist_dir
:
RcStr
,
pub
dist_dir
:
RcStr
,
/// Filesystem watcher options.
/// Filesystem watcher options.
...
@@ -176,15 +179,19 @@ pub struct NapiProjectOptions {
...
@@ -176,15 +179,19 @@ pub struct NapiProjectOptions {
/// [NapiProjectOptions] with all fields optional.
/// [NapiProjectOptions] with all fields optional.
#[napi(object)]
#[napi(object)]
pub
struct
NapiPartialProjectOptions
{
pub
struct
NapiPartialProjectOptions
{
/// A root path from which all files must be nested under. Trying to access
/// An absolute root path (Unix or Windows path) from which all files must be nested under.
/// a file outside this root will fail. Think of this as a chroot.
/// Trying to access a file outside this root will fail, so think of this as a chroot.
/// E.g. `/home/user/projects/my-repo`.
pub
root_path
:
Option
<
RcStr
>
,
pub
root_path
:
Option
<
RcStr
>
,
/// A path inside the root_path which contains the app/pages directories.
/// A path which contains the app/pages directories, relative to [`Project::root_path`], always
/// a Unix path.
/// E.g. `apps/my-app`
pub
project_path
:
Option
<
RcStr
>
,
pub
project_path
:
Option
<
RcStr
>
,
/// next.config's distDir. Project initialization occurs earlier than
/// A path where to emit the build outputs, relative to [`Project::project_path`], always a
/// deserializing next.config, so passing it as separate option.
/// Unix path. Corresponds to next.config.js's `distDir`.
/// E.g. `.next`
pub
dist_dir
:
Option
<
Option
<
RcStr
>>
,
pub
dist_dir
:
Option
<
Option
<
RcStr
>>
,
/// Filesystem watcher options.
/// Filesystem watcher options.
...
@@ -1416,13 +1423,9 @@ pub async fn get_source_map_rope(
...
@@ -1416,13 +1423,9 @@ pub async fn get_source_map_rope(
Err
(
_
)
=>
(
file_path
.to_string
(),
None
),
Err
(
_
)
=>
(
file_path
.to_string
(),
None
),
};
};
let
Some
(
chunk_base
)
=
file
.strip_prefix
(
let
Some
(
chunk_base
)
=
&
(
format!
(
file
.strip_prefix
(
container
.project
()
.dist_dir_absolute
()
.await
?
.as_str
())
"{}/{}/"
,
else
{
container
.project
()
.await
?
.project_path
,
container
.project
()
.dist_dir
()
.await
?
)),
)
else
{
// File doesn't exist within the dist dir
// File doesn't exist within the dist dir
return
Ok
(
OptionStringifiedSourceMap
::
none
());
return
Ok
(
OptionStringifiedSourceMap
::
none
());
};
};
...
...
crates/next-api/src/project.rs
View file @
a5b73c3f
use
std
::
{
path
::
MAIN_SEPARATOR
,
time
::
Duration
}
;
use
std
::
time
::
Duration
;
use
anyhow
::{
Context
,
Result
,
bail
};
use
anyhow
::{
Context
,
Result
,
bail
};
use
indexmap
::
map
::
Entry
;
use
indexmap
::
map
::
Entry
;
...
@@ -37,8 +37,8 @@ use turbo_tasks::{
...
@@ -37,8 +37,8 @@ use turbo_tasks::{
};
};
use
turbo_tasks_env
::{
EnvMap
,
ProcessEnv
};
use
turbo_tasks_env
::{
EnvMap
,
ProcessEnv
};
use
turbo_tasks_fs
::{
use
turbo_tasks_fs
::{
DiskFileSystem
,
FileSystem
,
FileSystemPath
,
VirtualFileSystem
,
get_relative_path_to
,
DiskFileSystem
,
FileSystem
,
FileSystemPath
,
VirtualFileSystem
,
invalidation
,
invalidation
,
util
::{
join_path
,
unix_to_sys
}
,
};
};
use
turbopack
::{
use
turbopack
::{
ModuleAssetContext
,
evaluate_context
::
node_build_environment
,
ModuleAssetContext
,
evaluate_context
::
node_build_environment
,
...
@@ -149,11 +149,13 @@ pub struct WatchOptions {
...
@@ -149,11 +149,13 @@ pub struct WatchOptions {
)]
)]
#[serde(rename_all
=
"camelCase"
)]
#[serde(rename_all
=
"camelCase"
)]
pub
struct
ProjectOptions
{
pub
struct
ProjectOptions
{
/// A root path from which all files must be nested under. Trying to access
/// An absolute root path (Unix or Windows path) from which all files must be nested under.
/// a file outside this root will fail. Think of this as a chroot.
/// Trying to access a file outside this root will fail, so think of this as a chroot.
/// E.g. `/home/user/projects/my-repo`.
pub
root_path
:
RcStr
,
pub
root_path
:
RcStr
,
/// A path inside the root_path which contains the app/pages directories.
/// A path which contains the app/pages directories, relative to [`Project::root_path`], always
/// Unix path. E.g. `apps/my-app`
pub
project_path
:
RcStr
,
pub
project_path
:
RcStr
,
/// The contents of next.config.js, serialized to JSON.
/// The contents of next.config.js, serialized to JSON.
...
@@ -538,15 +540,20 @@ impl ProjectContainer {
...
@@ -538,15 +540,20 @@ impl ProjectContainer {
#[turbo_tasks
::
value]
#[turbo_tasks
::
value]
pub
struct
Project
{
pub
struct
Project
{
/// A root path from which all files must be nested under. Trying to access
/// An absolute root path (Windows or Unix path) from which all files must be nested under.
/// a file outside this root will fail. Think of this as a chroot.
/// Trying to access a file outside this root will fail, so think of this as a chroot.
/// E.g. `/home/user/projects/my-repo`.
root_path
:
RcStr
,
root_path
:
RcStr
,
/// A path where to emit the build outputs. next.config.js's distDir.
/// A path which contains the app/pages directories, relative to [`Project::root_path`], always
dist_dir
:
RcStr
,
/// a Unix path.
/// E.g. `apps/my-app`
project_path
:
RcStr
,
/// A path inside the root_path which contains the app/pages directories.
/// A path where to emit the build outputs, relative to [`Project::project_path`], always a
pub
project_path
:
RcStr
,
/// Unix path. Corresponds to next.config.js's `distDir`.
/// E.g. `.next`
dist_dir
:
RcStr
,
/// Filesystem watcher options.
/// Filesystem watcher options.
watch
:
WatchOptions
,
watch
:
WatchOptions
,
...
@@ -685,21 +692,30 @@ impl Project {
...
@@ -685,21 +692,30 @@ impl Project {
}
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
fn
dist_dir
(
&
self
)
->
Vc
<
RcStr
>
{
pub
fn
dist_dir_absolute
(
&
self
)
->
Result
<
Vc
<
RcStr
>>
{
Vc
::
cell
(
self
.dist_dir
.clone
())
Ok
(
Vc
::
cell
(
format!
(
"{}{}{}"
,
self
.root_path
,
std
::
path
::
MAIN_SEPARATOR
,
unix_to_sys
(
&
join_path
(
&
self
.project_path
,
&
self
.dist_dir
)
.context
(
"expected project_path to be inside of root_path"
)
?
)
)
.into
(),
))
}
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
node_root
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
FileSystemPath
>>
{
pub
async
fn
node_root
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
FileSystemPath
>>
{
let
this
=
self
.await
?
;
let
this
=
self
.await
?
;
let
relative_from_root_to_project_path
=
get_relative_path_to
(
&
this
.root_path
,
&
this
.project_path
);
Ok
(
self
Ok
(
self
.output_fs
()
.output_fs
()
.root
()
.root
()
.await
?
.await
?
.join
(
&
relative_from_root_to_
project_path
)
?
.join
(
&
this
.
project_path
)
?
.join
(
&
this
.dist_dir
.clone
()
)
?
.join
(
&
this
.dist_dir
)
?
.cell
())
.cell
())
}
}
...
@@ -726,28 +742,24 @@ impl Project {
...
@@ -726,28 +742,24 @@ impl Project {
.cell
())
.cell
())
}
}
/// Returns the relative path from the node root to the output root.
/// E.g. from `[project]/test/e2e/app-dir/non-root-project-monorepo/apps/web/app/
/// import-meta-url-ssr/page.tsx` to `[project]/`.
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
node_root_to_root_path
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
RcStr
>>
{
pub
async
fn
node_root_to_root_path
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
RcStr
>>
{
let
this
=
self
.await
?
;
Ok
(
Vc
::
cell
(
let
output_root_to_root_path
=
self
self
.node_root
()
.project_path
()
.await
?
.await
?
.get_relative_path_to
(
&*
self
.output_fs
()
.root
()
.await
?
)
.join
(
&
this
.dist_dir
.clone
())
?
.context
(
"Expected node root to be inside of output fs"
)
?
,
.get_relative_path_to
(
&*
self
.project_root_path
()
.await
?
)
))
.context
(
"Project path need to be in root path"
)
?
;
Ok
(
Vc
::
cell
(
output_root_to_root_path
))
}
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
project_path
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
FileSystemPath
>>
{
pub
async
fn
project_path
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
FileSystemPath
>>
{
let
this
=
self
.await
?
;
let
this
=
self
.await
?
;
let
root
=
self
.project_root_path
()
.await
?
;
let
root
=
self
.project_root_path
()
.await
?
;
let
project_relative
=
this
.project_path
.strip_prefix
(
&*
this
.root_path
)
.unwrap
();
Ok
(
root
.join
(
&
this
.project_path
)
?
.cell
())
let
project_relative
=
project_relative
.strip_prefix
(
MAIN_SEPARATOR
)
.unwrap_or
(
project_relative
)
.replace
(
MAIN_SEPARATOR
,
"/"
);
Ok
(
root
.join
(
&
project_relative
)
?
.cell
())
}
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
...
...
packages/next/src/build/swc/generated-native.d.ts
View file @
a5b73c3f
...
@@ -100,15 +100,20 @@ export interface NapiWatchOptions {
...
@@ -100,15 +100,20 @@ export interface NapiWatchOptions {
}
}
export
interface
NapiProjectOptions
{
export
interface
NapiProjectOptions
{
/**
/**
* A root path from which all files must be nested under. Trying to access
* An absolute root path (Unix or Windows path) from which all files must be nested under.
* a file outside this root will fail. Think of this as a chroot.
* Trying to access a file outside this root will fail, so think of this as a chroot.
* E.g. `/home/user/projects/my-repo`.
*/
*/
rootPath
:
RcStr
rootPath
:
RcStr
/** A path inside the root_path which contains the app/pages directories. */
/**
* A path which contains the app/pages directories, relative to [`Project::root_path`], always
* Unix path. E.g. `apps/my-app`
*/
projectPath
:
RcStr
projectPath
:
RcStr
/**
/**
* next.config's distDir. Project initialization occurs earlier than
* A path where to emit the build outputs, relative to [`Project::project_path`], always Unix
* deserializing next.config, so passing it as separate option.
* path. Corresponds to next.config.js's `distDir`.
* E.g. `.next`
*/
*/
distDir
:
RcStr
distDir
:
RcStr
/** Filesystem watcher options. */
/** Filesystem watcher options. */
...
@@ -146,15 +151,21 @@ export interface NapiProjectOptions {
...
@@ -146,15 +151,21 @@ export interface NapiProjectOptions {
/** [NapiProjectOptions] with all fields optional. */
/** [NapiProjectOptions] with all fields optional. */
export
interface
NapiPartialProjectOptions
{
export
interface
NapiPartialProjectOptions
{
/**
/**
* A root path from which all files must be nested under. Trying to access
* An absolute root path (Unix or Windows path) from which all files must be nested under.
* a file outside this root will fail. Think of this as a chroot.
* Trying to access a file outside this root will fail, so think of this as a chroot.
* E.g. `/home/user/projects/my-repo`.
*/
*/
rootPath
?:
RcStr
rootPath
?:
RcStr
/** A path inside the root_path which contains the app/pages directories. */
/**
* A path which contains the app/pages directories, relative to [`Project::root_path`], always
* a Unix path.
* E.g. `apps/my-app`
*/
projectPath
?:
RcStr
projectPath
?:
RcStr
/**
/**
* next.config's distDir. Project initialization occurs earlier than
* A path where to emit the build outputs, relative to [`Project::project_path`], always a
* deserializing next.config, so passing it as separate option.
* Unix path. Corresponds to next.config.js's `distDir`.
* E.g. `.next`
*/
*/
distDir
?:
RcStr
|
undefined
|
null
distDir
?:
RcStr
|
undefined
|
null
/** Filesystem watcher options. */
/** Filesystem watcher options. */
...
...
packages/next/src/build/swc/index.ts
View file @
a5b73c3f
...
@@ -634,7 +634,7 @@ function bindingToApi(
...
@@ -634,7 +634,7 @@ function bindingToApi(
...
options
,
...
options
,
nextConfig
:
await
serializeNextConfig
(
nextConfig
:
await
serializeNextConfig
(
options
.
nextConfig
,
options
.
nextConfig
,
options
.
projectPath
!
path
.
join
(
options
.
rootPath
,
options
.
projectPath
)
),
),
jsConfig
:
JSON
.
stringify
(
options
.
jsConfig
),
jsConfig
:
JSON
.
stringify
(
options
.
jsConfig
),
env
:
rustifyEnv
(
options
.
env
),
env
:
rustifyEnv
(
options
.
env
),
...
@@ -648,7 +648,10 @@ function bindingToApi(
...
@@ -648,7 +648,10 @@ function bindingToApi(
...
options
,
...
options
,
nextConfig
:
nextConfig
:
options
.
nextConfig
&&
options
.
nextConfig
&&
(
await
serializeNextConfig
(
options
.
nextConfig
,
options
.
projectPath
!
)),
(
await
serializeNextConfig
(
options
.
nextConfig
,
path
.
join
(
options
.
rootPath
!
,
options
.
projectPath
!
)
)),
jsConfig
:
options
.
jsConfig
&&
JSON
.
stringify
(
options
.
jsConfig
),
jsConfig
:
options
.
jsConfig
&&
JSON
.
stringify
(
options
.
jsConfig
),
env
:
options
.
env
&&
rustifyEnv
(
options
.
env
),
env
:
options
.
env
&&
rustifyEnv
(
options
.
env
),
}
}
...
...
packages/next/src/build/swc/types.ts
View file @
a5b73c3f
...
@@ -346,18 +346,22 @@ export type WrittenEndpoint =
...
@@ -346,18 +346,22 @@ export type WrittenEndpoint =
export
interface
ProjectOptions
{
export
interface
ProjectOptions
{
/**
/**
* A root path from which all files must be nested under. Trying to access
* An absolute root path (Unix or Windows path) from which all files must be nested under. Trying
* a file outside this root will fail. Think of this as a chroot.
* to access a file outside this root will fail, so think of this as a chroot.
* E.g. `/home/user/projects/my-repo`.
*/
*/
rootPath
:
string
rootPath
:
string
/**
/**
* A path inside the root_path which contains the app/pages directories.
* A path which contains the app/pages directories, relative to `root_path`, always a Unix path.
* E.g. `apps/my-app`
*/
*/
projectPath
:
string
projectPath
:
string
/**
/**
* The path to the .next directory.
* A path where to emit the build outputs, relative to [`Project::project_path`], always a Unix
* path. Corresponds to next.config.js's `distDir`.
* E.g. `.next`
*/
*/
distDir
:
string
distDir
:
string
...
...
packages/next/src/build/turbopack-build/impl.ts
View file @
a5b73c3f
...
@@ -22,6 +22,7 @@ import { setGlobal } from '../../trace'
...
@@ -22,6 +22,7 @@ import { setGlobal } from '../../trace'
import
{
isCI
}
from
'../../server/ci-info'
import
{
isCI
}
from
'../../server/ci-info'
import
{
backgroundLogCompilationEvents
}
from
'../../shared/lib/turbopack/compilation-events'
import
{
backgroundLogCompilationEvents
}
from
'../../shared/lib/turbopack/compilation-events'
import
{
getSupportedBrowsers
}
from
'../utils'
import
{
getSupportedBrowsers
}
from
'../utils'
import
{
normalizePath
}
from
'../../lib/normalize-path'
export
async
function
turbopackBuild
():
Promise
<
{
export
async
function
turbopackBuild
():
Promise
<
{
duration
:
number
duration
:
number
...
@@ -52,10 +53,11 @@ export async function turbopackBuild(): Promise<{
...
@@ -52,10 +53,11 @@ export async function turbopackBuild(): Promise<{
const
supportedBrowsers
=
await
getSupportedBrowsers
(
dir
,
dev
)
const
supportedBrowsers
=
await
getSupportedBrowsers
(
dir
,
dev
)
const
persistentCaching
=
isPersistentCachingEnabled
(
config
)
const
persistentCaching
=
isPersistentCachingEnabled
(
config
)
const
rootPath
=
config
.
turbopack
?.
root
||
config
.
outputFileTracingRoot
||
dir
const
project
=
await
bindings
.
turbo
.
createProject
(
const
project
=
await
bindings
.
turbo
.
createProject
(
{
{
projectPath
:
dir
,
rootPath
:
config
.
turbopack
?.
root
||
config
.
outputFileTracingRoot
||
dir
,
rootPath
:
config
.
turbopack
?.
root
||
config
.
outputFileTracingRoot
||
dir
,
projectPath
:
normalizePath
(
path
.
relative
(
rootPath
,
dir
)
||
'.'
),
distDir
,
distDir
,
nextConfig
:
config
,
nextConfig
:
config
,
jsConfig
:
await
getTurbopackJsConfig
(
dir
,
config
),
jsConfig
:
await
getTurbopackJsConfig
(
dir
,
config
),
...
...
packages/next/src/build/webpack/loaders/css-loader/src/utils.ts
View file @
a5b73c3f
...
@@ -11,6 +11,7 @@ import localByDefault from 'next/dist/compiled/postcss-modules-local-by-default'
...
@@ -11,6 +11,7 @@ import localByDefault from 'next/dist/compiled/postcss-modules-local-by-default'
import
extractImports
from
'next/dist/compiled/postcss-modules-extract-imports'
import
extractImports
from
'next/dist/compiled/postcss-modules-extract-imports'
import
modulesScope
from
'next/dist/compiled/postcss-modules-scope'
import
modulesScope
from
'next/dist/compiled/postcss-modules-scope'
import
camelCase
from
'./camelcase'
import
camelCase
from
'./camelcase'
import
{
normalizePath
}
from
'../../../../../lib/normalize-path'
const
whitespace
=
'[
\\
x20
\\
t
\\
r
\\
n
\\
f]'
const
whitespace
=
'[
\\
x20
\\
t
\\
r
\\
n
\\
f]'
const
unescapeRegExp
=
new
RegExp
(
const
unescapeRegExp
=
new
RegExp
(
...
@@ -39,10 +40,6 @@ function unescape(str: string) {
...
@@ -39,10 +40,6 @@ function unescape(str: string) {
})
})
}
}
function
normalizePath
(
file
:
string
)
{
return
path
.
sep
===
'
\
\'
? file.replace(/
\\
/g, '
/
') : file
}
function
fixedEncodeURIComponent
(
str
:
string
)
{
function
fixedEncodeURIComponent
(
str
:
string
)
{
return
str
.
replace
(
/
[
!'()*
]
/g
,
(
c
)
=>
`%
${
c
.
charCodeAt
(
0
).
toString
(
16
)}
`
)
return
str
.
replace
(
/
[
!'()*
]
/g
,
(
c
)
=>
`%
${
c
.
charCodeAt
(
0
).
toString
(
16
)}
`
)
}
}
...
...
packages/next/src/lib/normalize-path.ts
0 → 100644
View file @
a5b73c3f
import
path
from
'path'
export
function
normalizePath
(
file
:
string
)
{
return
path
.
sep
===
'
\
\'
? file.replace(/
\\
/g, '
/
') : file
}
packages/next/src/server/dev/hot-reloader-turbopack.ts
View file @
a5b73c3f
import
type
{
Socket
}
from
'net'
import
type
{
Socket
}
from
'net'
import
{
mkdir
,
writeFile
}
from
'fs/promises'
import
{
mkdir
,
writeFile
}
from
'fs/promises'
import
{
join
,
extname
}
from
'path'
import
{
join
,
extname
,
relative
}
from
'path'
import
{
pathToFileURL
}
from
'url'
import
{
pathToFileURL
}
from
'url'
import
ws
from
'next/dist/compiled/ws'
import
ws
from
'next/dist/compiled/ws'
...
@@ -99,6 +99,7 @@ import { getRestartDevServerMiddleware } from '../../next-devtools/server/restar
...
@@ -99,6 +99,7 @@ import { getRestartDevServerMiddleware } from '../../next-devtools/server/restar
import
{
backgroundLogCompilationEvents
}
from
'../../shared/lib/turbopack/compilation-events'
import
{
backgroundLogCompilationEvents
}
from
'../../shared/lib/turbopack/compilation-events'
import
{
getSupportedBrowsers
}
from
'../../build/utils'
import
{
getSupportedBrowsers
}
from
'../../build/utils'
import
{
receiveBrowserLogsTurbopack
}
from
'./browser-logs/receive-logs'
import
{
receiveBrowserLogsTurbopack
}
from
'./browser-logs/receive-logs'
import
{
normalizePath
}
from
'../../lib/normalize-path'
const
wsServer
=
new
ws
.
Server
({
noServer
:
true
})
const
wsServer
=
new
ws
.
Server
({
noServer
:
true
})
const
isTestMode
=
!!
(
const
isTestMode
=
!!
(
...
@@ -207,13 +208,14 @@ export async function createHotReloaderTurbopack(
...
@@ -207,13 +208,14 @@ export async function createHotReloaderTurbopack(
const
supportedBrowsers
=
await
getSupportedBrowsers
(
projectPath
,
dev
)
const
supportedBrowsers
=
await
getSupportedBrowsers
(
projectPath
,
dev
)
const
currentNodeJsVersion
=
process
.
versions
.
node
const
currentNodeJsVersion
=
process
.
versions
.
node
const
rootPath
=
opts
.
nextConfig
.
turbopack
?.
root
||
opts
.
nextConfig
.
outputFileTracingRoot
||
projectPath
const
project
=
await
bindings
.
turbo
.
createProject
(
const
project
=
await
bindings
.
turbo
.
createProject
(
{
{
projectPath
:
projectPath
,
rootPath
,
rootPath
:
projectPath
:
normalizePath
(
relative
(
rootPath
,
projectPath
)
||
'.'
),
opts
.
nextConfig
.
turbopack
?.
root
||
opts
.
nextConfig
.
outputFileTracingRoot
||
projectPath
,
distDir
,
distDir
,
nextConfig
:
opts
.
nextConfig
,
nextConfig
:
opts
.
nextConfig
,
jsConfig
:
await
getTurbopackJsConfig
(
projectPath
,
nextConfig
),
jsConfig
:
await
getTurbopackJsConfig
(
projectPath
,
nextConfig
),
...
...
packages/next/src/server/lib/router-utils/setup-dev-bundler.ts
View file @
a5b73c3f
...
@@ -83,6 +83,7 @@ import {
...
@@ -83,6 +83,7 @@ import {
TurbopackInternalError
,
TurbopackInternalError
,
}
from
'../../../shared/lib/turbopack/utils'
}
from
'../../../shared/lib/turbopack/utils'
import
{
getDefineEnv
}
from
'../../../build/define-env'
import
{
getDefineEnv
}
from
'../../../build/define-env'
import
{
normalizePath
}
from
'../../../lib/normalize-path'
export
type
SetupOpts
=
{
export
type
SetupOpts
=
{
renderServer
:
LazyRenderServerInstance
renderServer
:
LazyRenderServerInstance
...
@@ -664,6 +665,10 @@ async function startWatcher(
...
@@ -664,6 +665,10 @@ async function startWatcher(
opts
.
fsChecker
.
rewrites
.
beforeFiles
.
length
>
0
||
opts
.
fsChecker
.
rewrites
.
beforeFiles
.
length
>
0
||
opts
.
fsChecker
.
rewrites
.
fallback
.
length
>
0
opts
.
fsChecker
.
rewrites
.
fallback
.
length
>
0
const
rootPath
=
opts
.
nextConfig
.
turbopack
?.
root
||
opts
.
nextConfig
.
outputFileTracingRoot
||
opts
.
dir
await
hotReloader
.
turbopackProject
.
update
({
await
hotReloader
.
turbopackProject
.
update
({
defineEnv
:
createDefineEnv
({
defineEnv
:
createDefineEnv
({
isTurbopack
:
true
,
isTurbopack
:
true
,
...
@@ -679,6 +684,8 @@ async function startWatcher(
...
@@ -679,6 +684,8 @@ async function startWatcher(
projectPath
:
opts
.
dir
,
projectPath
:
opts
.
dir
,
rewrites
:
opts
.
fsChecker
.
rewrites
,
rewrites
:
opts
.
fsChecker
.
rewrites
,
}),
}),
rootPath
,
projectPath
:
normalizePath
(
path
.
relative
(
rootPath
,
dir
)),
})
})
}
}
...
...
test/development/basic/next-rs-api.test.ts
View file @
a5b73c3f
...
@@ -187,26 +187,21 @@ describe('next.rs api', () => {
...
@@ -187,26 +187,21 @@ describe('next.rs api', () => {
let
project
:
Project
let
project
:
Project
let
projectUpdateSubscription
:
AsyncIterableIterator
<
UpdateInfo
>
let
projectUpdateSubscription
:
AsyncIterableIterator
<
UpdateInfo
>
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
console
.
log
(
next
.
testDir
)
const
nextConfig
=
await
loadConfig
(
PHASE_DEVELOPMENT_SERVER
,
next
.
testDir
)
const
nextConfig
=
await
loadConfig
(
PHASE_DEVELOPMENT_SERVER
,
next
.
testDir
)
const
bindings
=
await
loadBindings
()
const
bindings
=
await
loadBindings
()
const
distDir
=
path
.
join
(
const
rootPath
=
process
.
env
.
NEXT_SKIP_ISOLATE
process
.
env
.
NEXT_SKIP_ISOLATE
?
path
.
resolve
(
__dirname
,
'../../..'
)
?
path
.
resolve
(
__dirname
,
'../../..'
)
:
next
.
testDir
:
next
.
testDir
,
const
distDir
=
'.next'
'.next'
)
project
=
await
bindings
.
turbo
.
createProject
({
project
=
await
bindings
.
turbo
.
createProject
({
env
:
{},
env
:
{},
jsConfig
:
{
jsConfig
:
{
compilerOptions
:
{},
compilerOptions
:
{},
},
},
nextConfig
:
nextConfig
,
nextConfig
:
nextConfig
,
projectPath
:
next
.
testDir
,
rootPath
,
projectPath
:
path
.
relative
(
rootPath
,
next
.
testDir
)
||
'.'
,
distDir
,
distDir
,
rootPath
:
process
.
env
.
NEXT_SKIP_ISOLATE
?
path
.
resolve
(
__dirname
,
'../../..'
)
:
next
.
testDir
,
watch
:
{
watch
:
{
enable
:
true
,
enable
:
true
,
},
},
...
@@ -217,7 +212,7 @@ describe('next.rs api', () => {
...
@@ -217,7 +212,7 @@ describe('next.rs api', () => {
clientRouterFilters
:
undefined
,
clientRouterFilters
:
undefined
,
config
:
nextConfig
,
config
:
nextConfig
,
dev
:
true
,
dev
:
true
,
distDir
:
distDir
,
distDir
:
path
.
join
(
rootPath
,
distDir
)
,
fetchCacheKeyPrefix
:
undefined
,
fetchCacheKeyPrefix
:
undefined
,
hasRewrites
:
false
,
hasRewrites
:
false
,
middlewareMatchers
:
undefined
,
middlewareMatchers
:
undefined
,
...
@@ -265,7 +260,7 @@ describe('next.rs api', () => {
...
@@ -265,7 +260,7 @@ describe('next.rs api', () => {
expect
(
normalizeDiagnostics
(
entrypoints
.
value
.
diagnostics
)).
toMatchSnapshot
(
expect
(
normalizeDiagnostics
(
entrypoints
.
value
.
diagnostics
)).
toMatchSnapshot
(
'diagnostics'
'diagnostics'
)
)
entrypointsSubscription
.
return
()
await
entrypointsSubscription
.
return
()
})
})
const
routes
=
[
const
routes
=
[
...
...
turbopack/crates/turbo-tasks-fs/src/lib.rs
View file @
a5b73c3f
...
@@ -997,6 +997,7 @@ impl ValueToString for DiskFileSystem {
...
@@ -997,6 +997,7 @@ impl ValueToString for DiskFileSystem {
}
}
}
}
/// Note: this only works for Unix-style paths (with `/` as a separator).
pub
fn
get_relative_path_to
(
path
:
&
str
,
other_path
:
&
str
)
->
String
{
pub
fn
get_relative_path_to
(
path
:
&
str
,
other_path
:
&
str
)
->
String
{
fn
split
(
s
:
&
str
)
->
impl
Iterator
<
Item
=
&
str
>
{
fn
split
(
s
:
&
str
)
->
impl
Iterator
<
Item
=
&
str
>
{
let
empty
=
s
.is_empty
();
let
empty
=
s
.is_empty
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment