Commit b2a40693 authored by Tim Neutkens's avatar Tim Neutkens

Development: Speed up ready in time

parent 1b5f518a
...@@ -147,9 +147,6 @@ pub struct NapiProjectOptions { ...@@ -147,9 +147,6 @@ pub struct NapiProjectOptions {
/// The contents of next.config.js, serialized to JSON. /// The contents of next.config.js, serialized to JSON.
pub next_config: RcStr, pub next_config: RcStr,
/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: RcStr,
/// A map of environment variables to use when compiling code. /// A map of environment variables to use when compiling code.
pub env: Vec<NapiEnvVar>, pub env: Vec<NapiEnvVar>,
...@@ -205,9 +202,6 @@ pub struct NapiPartialProjectOptions { ...@@ -205,9 +202,6 @@ pub struct NapiPartialProjectOptions {
/// The contents of next.config.js, serialized to JSON. /// The contents of next.config.js, serialized to JSON.
pub next_config: Option<RcStr>, pub next_config: Option<RcStr>,
/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: Option<RcStr>,
/// A map of environment variables to use when compiling code. /// A map of environment variables to use when compiling code.
pub env: Option<Vec<NapiEnvVar>>, pub env: Option<Vec<NapiEnvVar>>,
...@@ -277,7 +271,6 @@ impl From<NapiProjectOptions> for ProjectOptions { ...@@ -277,7 +271,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
project_path: val.project_path, project_path: val.project_path,
watch: val.watch.into(), watch: val.watch.into(),
next_config: val.next_config, next_config: val.next_config,
js_config: val.js_config,
env: val env: val
.env .env
.into_iter() .into_iter()
...@@ -302,7 +295,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions { ...@@ -302,7 +295,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
project_path: val.project_path, project_path: val.project_path,
watch: val.watch.map(From::from), watch: val.watch.map(From::from),
next_config: val.next_config, next_config: val.next_config,
js_config: val.js_config,
env: val env: val
.env .env
.map(|env| env.into_iter().map(|var| (var.name, var.value)).collect()), .map(|env| env.into_iter().map(|var| (var.name, var.value)).collect()),
......
...@@ -193,7 +193,6 @@ impl HmrBenchmark { ...@@ -193,7 +193,6 @@ impl HmrBenchmark {
root_path: RcStr::from(root_path), root_path: RcStr::from(root_path),
project_path: RcStr::from(project_path.clone()), project_path: RcStr::from(project_path.clone()),
next_config: load_next_config(), next_config: load_next_config(),
js_config: rcstr!("{}"),
env: vec![], env: vec![],
define_env: DefineEnv { define_env: DefineEnv {
client: vec![], client: vec![],
......
...@@ -13,7 +13,7 @@ use next_core::{ ...@@ -13,7 +13,7 @@ use next_core::{
next_client::{ next_client::{
ClientChunkingContextOptions, get_client_chunking_context, get_client_compile_time_info, ClientChunkingContextOptions, get_client_chunking_context, get_client_compile_time_info,
}, },
next_config::{JsConfig, ModuleIds as ModuleIdStrategyConfig, NextConfig}, next_config::{ModuleIds as ModuleIdStrategyConfig, NextConfig},
next_edge::context::EdgeChunkingContextOptions, next_edge::context::EdgeChunkingContextOptions,
next_server::{ next_server::{
ServerChunkingContextOptions, ServerContextType, get_server_chunking_context, ServerChunkingContextOptions, ServerContextType, get_server_chunking_context,
...@@ -159,9 +159,6 @@ pub struct ProjectOptions { ...@@ -159,9 +159,6 @@ pub struct ProjectOptions {
/// The contents of next.config.js, serialized to JSON. /// The contents of next.config.js, serialized to JSON.
pub next_config: RcStr, pub next_config: RcStr,
/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: RcStr,
/// A map of environment variables to use when compiling code. /// A map of environment variables to use when compiling code.
pub env: Vec<(RcStr, RcStr)>, pub env: Vec<(RcStr, RcStr)>,
...@@ -211,9 +208,6 @@ pub struct PartialProjectOptions { ...@@ -211,9 +208,6 @@ pub struct PartialProjectOptions {
/// The contents of next.config.js, serialized to JSON. /// The contents of next.config.js, serialized to JSON.
pub next_config: Option<RcStr>, pub next_config: Option<RcStr>,
/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: Option<RcStr>,
/// A map of environment variables to use when compiling code. /// A map of environment variables to use when compiling code.
pub env: Option<Vec<(RcStr, RcStr)>>, pub env: Option<Vec<(RcStr, RcStr)>>,
...@@ -340,7 +334,6 @@ impl ProjectContainer { ...@@ -340,7 +334,6 @@ impl ProjectContainer {
root_path, root_path,
project_path, project_path,
next_config, next_config,
js_config,
env, env,
define_env, define_env,
watch, watch,
...@@ -367,9 +360,6 @@ impl ProjectContainer { ...@@ -367,9 +360,6 @@ impl ProjectContainer {
if let Some(next_config) = next_config { if let Some(next_config) = next_config {
new_options.next_config = next_config; new_options.next_config = next_config;
} }
if let Some(js_config) = js_config {
new_options.js_config = js_config;
}
if let Some(env) = env { if let Some(env) = env {
new_options.env = env; new_options.env = env;
} }
...@@ -442,7 +432,6 @@ impl ProjectContainer { ...@@ -442,7 +432,6 @@ impl ProjectContainer {
let env_map: Vc<EnvMap>; let env_map: Vc<EnvMap>;
let next_config; let next_config;
let define_env; let define_env;
let js_config;
let root_path; let root_path;
let project_path; let project_path;
let watch; let watch;
...@@ -466,7 +455,6 @@ impl ProjectContainer { ...@@ -466,7 +455,6 @@ impl ProjectContainer {
} }
.cell(); .cell();
next_config = NextConfig::from_string(Vc::cell(options.next_config.clone())); next_config = NextConfig::from_string(Vc::cell(options.next_config.clone()));
js_config = JsConfig::from_string(Vc::cell(options.js_config.clone()));
root_path = options.root_path.clone(); root_path = options.root_path.clone();
project_path = options.project_path.clone(); project_path = options.project_path.clone();
watch = options.watch; watch = options.watch;
...@@ -490,7 +478,6 @@ impl ProjectContainer { ...@@ -490,7 +478,6 @@ impl ProjectContainer {
project_path, project_path,
watch, watch,
next_config: next_config.to_resolved().await?, next_config: next_config.to_resolved().await?,
js_config: js_config.to_resolved().await?,
dist_dir, dist_dir,
env: ResolvedVc::upcast(env_map.to_resolved().await?), env: ResolvedVc::upcast(env_map.to_resolved().await?),
define_env: define_env.to_resolved().await?, define_env: define_env.to_resolved().await?,
...@@ -561,9 +548,6 @@ pub struct Project { ...@@ -561,9 +548,6 @@ pub struct Project {
/// Next config. /// Next config.
next_config: ResolvedVc<NextConfig>, next_config: ResolvedVc<NextConfig>,
/// Js/Tsconfig read by load-jsconfig
js_config: ResolvedVc<JsConfig>,
/// A map of environment variables to use when compiling code. /// A map of environment variables to use when compiling code.
env: ResolvedVc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
...@@ -788,11 +772,6 @@ impl Project { ...@@ -788,11 +772,6 @@ impl Project {
Ok(Vc::cell(*self.mode.await? == NextMode::Development)) Ok(Vc::cell(*self.mode.await? == NextMode::Development))
} }
#[turbo_tasks::function]
pub(super) fn js_config(&self) -> Vc<JsConfig> {
*self.js_config
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) fn encryption_key(&self) -> Vc<RcStr> { pub(super) fn encryption_key(&self) -> Vc<RcStr> {
Vc::cell(self.encryption_key.clone()) Vc::cell(self.encryption_key.clone())
...@@ -1128,21 +1107,6 @@ impl Project { ...@@ -1128,21 +1107,6 @@ impl Project {
// it is always using SWC so we don't check swc here. // it is always using SWC so we don't check swc here.
emit_event(env!("VERGEN_CARGO_TARGET_TRIPLE"), true); emit_event(env!("VERGEN_CARGO_TARGET_TRIPLE"), true);
// Go over jsconfig and report enabled features.
let compiler_options = self.js_config().compiler_options().await?;
let compiler_options = compiler_options.as_object();
let experimental_decorators_enabled = compiler_options
.as_ref()
.and_then(|compiler_options| compiler_options.get("experimentalDecorators"))
.is_some();
let jsx_import_source_enabled = compiler_options
.as_ref()
.and_then(|compiler_options| compiler_options.get("jsxImportSource"))
.is_some();
emit_event("swcExperimentalDecorators", experimental_decorators_enabled);
emit_event("swcImportSource", jsx_import_source_enabled);
// Go over config and report enabled features. // Go over config and report enabled features.
// [TODO]: useSwcLoader is not being reported as it is not directly corresponds (it checks babel config existence) // [TODO]: useSwcLoader is not being reported as it is not directly corresponds (it checks babel config existence)
// need to confirm what we'll do with turbopack. // need to confirm what we'll do with turbopack.
......
...@@ -169,7 +169,6 @@ fn main() { ...@@ -169,7 +169,6 @@ fn main() {
dev: true, dev: true,
encryption_key: rcstr!("deadbeef"), encryption_key: rcstr!("deadbeef"),
env: vec![], env: vec![],
js_config: include_str!("../jsConfig.json").into(),
next_config: include_str!("../nextConfig.json").into(), next_config: include_str!("../nextConfig.json").into(),
preview_props: next_api::project::DraftModeOptions { preview_props: next_api::project::DraftModeOptions {
preview_mode_encryption_key: rcstr!("deadbeef"), preview_mode_encryption_key: rcstr!("deadbeef"),
......
...@@ -10,13 +10,14 @@ use turbopack::{ ...@@ -10,13 +10,14 @@ use turbopack::{
}; };
use turbopack_browser::react_refresh::assert_can_resolve_react_refresh; use turbopack_browser::react_refresh::assert_can_resolve_react_refresh;
use turbopack_core::{ use turbopack_core::{
diagnostics::DiagnosticExt,
file_source::FileSource, file_source::FileSource,
resolve::{FindContextFileResult, find_context_file, node::node_cjs_resolve_options}, resolve::{FindContextFileResult, find_context_file, node::node_cjs_resolve_options},
source::Source, source::Source,
}; };
use turbopack_ecmascript::typescript::resolve::{read_from_tsconfigs, read_tsconfigs, tsconfig}; use turbopack_ecmascript::typescript::resolve::{read_from_tsconfigs, read_tsconfigs, tsconfig};
use crate::{mode::NextMode, next_config::NextConfig}; use crate::{mode::NextMode, next_config::NextConfig, next_telemetry::NextFeatureTelemetry};
async fn get_typescript_options( async fn get_typescript_options(
project_path: FileSystemPath, project_path: FileSystemPath,
...@@ -52,6 +53,13 @@ pub async fn get_typescript_transform_options( ...@@ -52,6 +53,13 @@ pub async fn get_typescript_transform_options(
false false
}; };
NextFeatureTelemetry::new(
"swcExperimentalDecorators".into(),
use_define_for_class_fields,
)
.resolved_cell()
.emit();
let ts_transform_options = TypescriptTransformOptions { let ts_transform_options = TypescriptTransformOptions {
use_define_for_class_fields, use_define_for_class_fields,
}; };
...@@ -60,7 +68,7 @@ pub async fn get_typescript_transform_options( ...@@ -60,7 +68,7 @@ pub async fn get_typescript_transform_options(
} }
/// Build the transform options for the decorators. /// Build the transform options for the decorators.
/// **TODO** Currnently only typescript's legacy decorators are supported /// **TODO** Currently only typescript's legacy decorators are supported
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get_decorators_transform_options( pub async fn get_decorators_transform_options(
project_path: FileSystemPath, project_path: FileSystemPath,
...@@ -176,6 +184,10 @@ pub async fn get_jsx_transform_options( ...@@ -176,6 +184,10 @@ pub async fn get_jsx_transform_options(
.as_str() .as_str()
.map(|s| s.into()); .map(|s| s.into());
NextFeatureTelemetry::new("swcImportSource".into(), jsx_import_source.is_some())
.resolved_cell()
.emit();
Some(JsxTransformOptions { Some(JsxTransformOptions {
import_source: if jsx_import_source.is_some() { import_source: if jsx_import_source.is_some() {
jsx_import_source jsx_import_source
......
...@@ -34,12 +34,6 @@ export declare class ExternalObject<T> { ...@@ -34,12 +34,6 @@ export declare class ExternalObject<T> {
[K: symbol]: T [K: symbol]: T
} }
} }
export interface TransformOutput {
code: string
map?: string
output?: string
diagnostics: Array<string>
}
export declare function mdxCompile( export declare function mdxCompile(
value: string, value: string,
option: Buffer, option: Buffer,
...@@ -120,8 +114,6 @@ export interface NapiProjectOptions { ...@@ -120,8 +114,6 @@ export interface NapiProjectOptions {
watch: NapiWatchOptions watch: NapiWatchOptions
/** The contents of next.config.js, serialized to JSON. */ /** The contents of next.config.js, serialized to JSON. */
nextConfig: RcStr nextConfig: RcStr
/** The contents of ts/config read by load-jsconfig, serialized to JSON. */
jsConfig: RcStr
/** A map of environment variables to use when compiling code. */ /** A map of environment variables to use when compiling code. */
env: Array<NapiEnvVar> env: Array<NapiEnvVar>
/** /**
...@@ -172,8 +164,6 @@ export interface NapiPartialProjectOptions { ...@@ -172,8 +164,6 @@ export interface NapiPartialProjectOptions {
watch?: NapiWatchOptions watch?: NapiWatchOptions
/** The contents of next.config.js, serialized to JSON. */ /** The contents of next.config.js, serialized to JSON. */
nextConfig?: RcStr nextConfig?: RcStr
/** The contents of ts/config read by load-jsconfig, serialized to JSON. */
jsConfig?: RcStr
/** A map of environment variables to use when compiling code. */ /** A map of environment variables to use when compiling code. */
env?: Array<NapiEnvVar> env?: Array<NapiEnvVar>
/** /**
......
...@@ -625,7 +625,6 @@ function bindingToApi( ...@@ -625,7 +625,6 @@ function bindingToApi(
options.nextConfig, options.nextConfig,
path.join(options.rootPath, options.projectPath) path.join(options.rootPath, options.projectPath)
), ),
jsConfig: JSON.stringify(options.jsConfig),
env: rustifyEnv(options.env), env: rustifyEnv(options.env),
} }
} }
...@@ -641,7 +640,6 @@ function bindingToApi( ...@@ -641,7 +640,6 @@ function bindingToApi(
options.nextConfig, options.nextConfig,
path.join(options.rootPath!, options.projectPath!) path.join(options.rootPath!, options.projectPath!)
)), )),
jsConfig: options.jsConfig && JSON.stringify(options.jsConfig),
env: options.env && rustifyEnv(options.env), env: options.env && rustifyEnv(options.env),
} }
} }
......
...@@ -378,17 +378,6 @@ export interface ProjectOptions { ...@@ -378,17 +378,6 @@ export interface ProjectOptions {
*/ */
nextConfig: NextConfigComplete nextConfig: NextConfigComplete
/**
* Jsconfig, or tsconfig contents.
*
* Next.js implicitly requires to read it to support few options
* https://nextjs.org/docs/architecture/nextjs-compiler#legacy-decorators
* https://nextjs.org/docs/architecture/nextjs-compiler#importsource
*/
jsConfig: {
compilerOptions: object
}
/** /**
* A map of environment variables to use when compiling code. * A map of environment variables to use when compiling code.
*/ */
......
...@@ -2,7 +2,6 @@ import path from 'path' ...@@ -2,7 +2,6 @@ import path from 'path'
import { validateTurboNextConfig } from '../../lib/turbopack-warning' import { validateTurboNextConfig } from '../../lib/turbopack-warning'
import { import {
formatIssue, formatIssue,
getTurbopackJsConfig,
isPersistentCachingEnabled, isPersistentCachingEnabled,
isRelevantWarning, isRelevantWarning,
} from '../../shared/lib/turbopack/utils' } from '../../shared/lib/turbopack/utils'
...@@ -60,7 +59,6 @@ export async function turbopackBuild(): Promise<{ ...@@ -60,7 +59,6 @@ export async function turbopackBuild(): Promise<{
projectPath: normalizePath(path.relative(rootPath, dir) || '.'), projectPath: normalizePath(path.relative(rootPath, dir) || '.'),
distDir, distDir,
nextConfig: config, nextConfig: config,
jsConfig: await getTurbopackJsConfig(dir, config),
watch: { watch: {
enable: false, enable: false,
}, },
......
...@@ -1307,7 +1307,7 @@ export default async function loadConfig( ...@@ -1307,7 +1307,7 @@ export default async function loadConfig(
} }
// Original implementation continues below... // Original implementation continues below...
if (!process.env.__NEXT_PRIVATE_RENDER_WORKER) { if (!process.env.__NEXT_PRIVATE_RENDER_WORKER && !process.env.TURBOPACK) {
try { try {
loadWebpackHook() loadWebpackHook()
} catch (err) { } catch (err) {
......
import { getPathMatch } from '../../shared/lib/router/utils/path-match'
import { parseVersionInfo, type VersionInfo } from './parse-version-info'
export const matchNextPageBundleRequest = getPathMatch(
'/_next/static/chunks/pages/:path*.js(\\.map|)'
)
export async function getVersionInfo(): Promise<VersionInfo> {
let installed = '0.0.0'
try {
installed = require('next/package.json').version
let res
try {
// use NPM registry regardless user using Yarn
res = await fetch('https://registry.npmjs.org/-/package/next/dist-tags')
} catch {
// ignore fetch errors
}
if (!res || !res.ok) return { installed, staleness: 'unknown' }
const { latest, canary } = await res.json()
return parseVersionInfo({ installed, latest, canary })
} catch (e: any) {
console.error(e)
return { installed, staleness: 'unknown' }
}
}
...@@ -29,7 +29,7 @@ import * as Log from '../../build/output/log' ...@@ -29,7 +29,7 @@ import * as Log from '../../build/output/log'
import { import {
getVersionInfo, getVersionInfo,
matchNextPageBundleRequest, matchNextPageBundleRequest,
} from './hot-reloader-webpack' } from './hot-reloader-shared-utils'
import { BLOCKED_PAGES } from '../../shared/lib/constants' import { BLOCKED_PAGES } from '../../shared/lib/constants'
import { import {
getOverlayMiddleware, getOverlayMiddleware,
...@@ -84,7 +84,6 @@ import { setBundlerFindSourceMapImplementation } from '../patch-error-inspect' ...@@ -84,7 +84,6 @@ import { setBundlerFindSourceMapImplementation } from '../patch-error-inspect'
import { getNextErrorFeedbackMiddleware } from '../../next-devtools/server/get-next-error-feedback-middleware' import { getNextErrorFeedbackMiddleware } from '../../next-devtools/server/get-next-error-feedback-middleware'
import { import {
formatIssue, formatIssue,
getTurbopackJsConfig,
isPersistentCachingEnabled, isPersistentCachingEnabled,
isWellKnownError, isWellKnownError,
processIssues, processIssues,
...@@ -224,7 +223,6 @@ export async function createHotReloaderTurbopack( ...@@ -224,7 +223,6 @@ export async function createHotReloaderTurbopack(
projectPath: normalizePath(relative(rootPath, projectPath) || '.'), projectPath: normalizePath(relative(rootPath, projectPath) || '.'),
distDir, distDir,
nextConfig: opts.nextConfig, nextConfig: opts.nextConfig,
jsConfig: await getTurbopackJsConfig(projectPath, nextConfig),
watch: { watch: {
enable: dev, enable: dev,
pollIntervalMs: nextConfig.watchOptions?.pollIntervalMs, pollIntervalMs: nextConfig.watchOptions?.pollIntervalMs,
......
...@@ -42,7 +42,6 @@ import { ...@@ -42,7 +42,6 @@ import {
RSC_MODULE_TYPES, RSC_MODULE_TYPES,
} from '../../shared/lib/constants' } from '../../shared/lib/constants'
import type { __ApiPreviewProps } from '../api-utils' import type { __ApiPreviewProps } from '../api-utils'
import { getPathMatch } from '../../shared/lib/router/utils/path-match'
import { findPageFile } from '../lib/find-page-file' import { findPageFile } from '../lib/find-page-file'
import { import {
BUILDING, BUILDING,
...@@ -66,7 +65,6 @@ import { getProperError } from '../../lib/is-error' ...@@ -66,7 +65,6 @@ import { getProperError } from '../../lib/is-error'
import ws from 'next/dist/compiled/ws' import ws from 'next/dist/compiled/ws'
import { existsSync, promises as fs } from 'fs' import { existsSync, promises as fs } from 'fs'
import type { UnwrapPromise } from '../../lib/coalesced-function' import type { UnwrapPromise } from '../../lib/coalesced-function'
import { parseVersionInfo } from './parse-version-info'
import type { VersionInfo } from './parse-version-info' import type { VersionInfo } from './parse-version-info'
import { isAPIRoute } from '../../lib/is-api-route' import { isAPIRoute } from '../../lib/is-api-route'
import { getRouteLoaderEntry } from '../../build/webpack/loaders/next-route-loader' import { getRouteLoaderEntry } from '../../build/webpack/loaders/next-route-loader'
...@@ -95,6 +93,10 @@ import { ...@@ -95,6 +93,10 @@ import {
devToolsConfigMiddleware, devToolsConfigMiddleware,
getDevToolsConfig, getDevToolsConfig,
} from '../../next-devtools/server/devtools-config-middleware' } from '../../next-devtools/server/devtools-config-middleware'
import {
matchNextPageBundleRequest,
getVersionInfo,
} from './hot-reloader-shared-utils'
const MILLISECONDS_IN_NANOSECOND = BigInt(1_000_000) const MILLISECONDS_IN_NANOSECOND = BigInt(1_000_000)
...@@ -156,10 +158,6 @@ function addCorsSupport(req: IncomingMessage, res: ServerResponse) { ...@@ -156,10 +158,6 @@ function addCorsSupport(req: IncomingMessage, res: ServerResponse) {
return { preflight: false } return { preflight: false }
} }
export const matchNextPageBundleRequest = getPathMatch(
'/_next/static/chunks/pages/:path*.js(\\.map|)'
)
// Iteratively look up the issuer till it ends up at the root // Iteratively look up the issuer till it ends up at the root
function findEntryModule( function findEntryModule(
module: webpack.Module, module: webpack.Module,
...@@ -202,32 +200,6 @@ function erroredPages(compilation: webpack.Compilation) { ...@@ -202,32 +200,6 @@ function erroredPages(compilation: webpack.Compilation) {
return failedPages return failedPages
} }
export async function getVersionInfo(): Promise<VersionInfo> {
let installed = '0.0.0'
try {
installed = require('next/package.json').version
let res
try {
// use NPM registry regardless user using Yarn
res = await fetch('https://registry.npmjs.org/-/package/next/dist-tags')
} catch {
// ignore fetch errors
}
if (!res || !res.ok) return { installed, staleness: 'unknown' }
const { latest, canary } = await res.json()
return parseVersionInfo({ installed, latest, canary })
} catch (e: any) {
console.error(e)
return { installed, staleness: 'unknown' }
}
}
export default class HotReloaderWebpack implements NextJsHotReloaderInterface { export default class HotReloaderWebpack implements NextJsHotReloaderInterface {
private hasAmpEntrypoints: boolean private hasAmpEntrypoints: boolean
private hasAppRouterEntrypoints: boolean private hasAppRouterEntrypoints: boolean
......
import type { NextConfigComplete } from '../../config-shared' import type { NextConfigComplete } from '../../config-shared'
import type { FilesystemDynamicRoute } from './filesystem' import type { FilesystemDynamicRoute } from './filesystem'
import type { UnwrapPromise } from '../../../lib/coalesced-function' import type { UnwrapPromise } from '../../../lib/coalesced-function'
import {
getPageStaticInfo,
type MiddlewareMatcher,
} from '../../../build/analysis/get-page-static-info'
import type { RoutesManifest } from '../../../build' import type { RoutesManifest } from '../../../build'
import type { MiddlewareRouteMatch } from '../../../shared/lib/router/utils/middleware-route-matcher' import type { MiddlewareRouteMatch } from '../../../shared/lib/router/utils/middleware-route-matcher'
import type { PropagateToWorkersField } from './types' import type { PropagateToWorkersField } from './types'
import type { NextJsHotReloaderInterface } from '../../dev/hot-reloader-types' import type { NextJsHotReloaderInterface } from '../../dev/hot-reloader-types'
import type { Telemetry } from '../../../telemetry/storage'
import type { IncomingMessage, ServerResponse } from 'http'
import type { MiddlewareMatcher } from '../../../build/analysis/get-page-static-info'
import { createDefineEnv } from '../../../build/swc' import { createDefineEnv } from '../../../build/swc'
import fs from 'fs' import fs from 'fs'
...@@ -20,11 +19,7 @@ import { loadEnvConfig } from '@next/env' ...@@ -20,11 +19,7 @@ import { loadEnvConfig } from '@next/env'
import findUp from 'next/dist/compiled/find-up' import findUp from 'next/dist/compiled/find-up'
import { buildCustomRoute } from './filesystem' import { buildCustomRoute } from './filesystem'
import * as Log from '../../../build/output/log' import * as Log from '../../../build/output/log'
import HotReloaderWebpack from '../../dev/hot-reloader-webpack'
import { setGlobal } from '../../../trace/shared' import { setGlobal } from '../../../trace/shared'
import type { Telemetry } from '../../../telemetry/storage'
import type { IncomingMessage, ServerResponse } from 'http'
import loadJsConfig from '../../../build/load-jsconfig'
import { createValidFileMatcher } from '../find-page-file' import { createValidFileMatcher } from '../find-page-file'
import { import {
EVENT_BUILD_FEATURE_USAGE, EVENT_BUILD_FEATURE_USAGE,
...@@ -69,7 +64,6 @@ import { devPageFiles } from '../../../build/webpack/plugins/next-types-plugin/s ...@@ -69,7 +64,6 @@ import { devPageFiles } from '../../../build/webpack/plugins/next-types-plugin/s
import type { LazyRenderServerInstance } from '../router-server' import type { LazyRenderServerInstance } from '../router-server'
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../dev/hot-reloader-types' import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../dev/hot-reloader-types'
import { PAGE_TYPES } from '../../../lib/page-types' import { PAGE_TYPES } from '../../../lib/page-types'
import { createHotReloaderTurbopack } from '../../dev/hot-reloader-turbopack'
import { generateEncryptionKeyBase64 } from '../../app-render/encryption-utils-server' import { generateEncryptionKeyBase64 } from '../../app-render/encryption-utils-server'
import { isMetadataRouteFile } from '../../../lib/metadata/is-metadata-route' import { isMetadataRouteFile } from '../../../lib/metadata/is-metadata-route'
import { normalizeMetadataPageToRoute } from '../../../lib/metadata/get-metadata-route' import { normalizeMetadataPageToRoute } from '../../../lib/metadata/get-metadata-route'
...@@ -192,8 +186,23 @@ async function startWatcher( ...@@ -192,8 +186,23 @@ async function startWatcher(
}) })
const hotReloader: NextJsHotReloaderInterface = opts.turbo const hotReloader: NextJsHotReloaderInterface = opts.turbo
? await createHotReloaderTurbopack(opts, serverFields, distDir, resetFetch) ? await (() => {
: new HotReloaderWebpack(opts.dir, { // Only require Turbopack when it is used.
const { createHotReloaderTurbopack } =
require('../../dev/hot-reloader-turbopack') as typeof import('../../dev/hot-reloader-turbopack')
return createHotReloaderTurbopack(
opts,
serverFields,
distDir,
resetFetch
)
})()
: await (async () => {
// Only require webpack when it is used.
const HotReloaderWebpack = (
require('../../dev/hot-reloader-webpack') as typeof import('../../dev/hot-reloader-webpack')
).default
return new HotReloaderWebpack(opts.dir, {
isSrcDir: opts.isSrcDir, isSrcDir: opts.isSrcDir,
appDir, appDir,
pagesDir, pagesDir,
...@@ -209,6 +218,7 @@ async function startWatcher( ...@@ -209,6 +218,7 @@ async function startWatcher(
previewProps: opts.fsChecker.prerenderManifest.preview, previewProps: opts.fsChecker.prerenderManifest.preview,
resetFetch, resetFetch,
}) })
})()
await hotReloader.start() await hotReloader.start()
...@@ -501,6 +511,9 @@ async function startWatcher( ...@@ -501,6 +511,9 @@ async function startWatcher(
true true
) )
) { ) {
const getPageStaticInfo = (
require('../../../build/analysis/get-page-static-info') as typeof import('../../../build/analysis/get-page-static-info')
).getPageStaticInfo
const staticInfo = await getPageStaticInfo({ const staticInfo = await getPageStaticInfo({
pageFilePath: fileName, pageFilePath: fileName,
nextConfig: {}, nextConfig: {},
...@@ -748,16 +761,23 @@ async function startWatcher( ...@@ -748,16 +761,23 @@ async function startWatcher(
]) ])
} }
let tsconfigResult: let tsconfigResult:
| UnwrapPromise<ReturnType<typeof loadJsConfig>> | UnwrapPromise<
ReturnType<typeof import('../../../build/load-jsconfig').default>
>
| undefined | undefined
if (!hotReloader.turbopackProject) {
if (tsconfigChange) { if (tsconfigChange) {
try { try {
const loadJsConfig = (
require('../../../build/load-jsconfig') as typeof import('../../../build/load-jsconfig')
).default
tsconfigResult = await loadJsConfig(dir, nextConfig) tsconfigResult = await loadJsConfig(dir, nextConfig)
} catch (_) { } catch (_) {
/* do we want to log if there are syntax errors in tsconfig while editing? */ /* do we want to log if there are syntax errors in tsconfig while editing? */
} }
} }
}
if (hotReloader.turbopackProject) { if (hotReloader.turbopackProject) {
const hasRewrites = const hasRewrites =
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
import './cpu-profile' import './cpu-profile'
import { getNetworkHost } from '../../lib/get-network-host' import { getNetworkHost } from '../../lib/get-network-host'
debugger
if (performance.getEntriesByName('next-start').length === 0) { if (performance.getEntriesByName('next-start').length === 0) {
performance.mark('next-start') performance.mark('next-start')
} }
......
...@@ -14,7 +14,6 @@ import { ...@@ -14,7 +14,6 @@ import {
import type { EntryKey } from './entry-key' import type { EntryKey } from './entry-key'
import * as Log from '../../../build/output/log' import * as Log from '../../../build/output/log'
import type { NextConfigComplete } from '../../../server/config-shared' import type { NextConfigComplete } from '../../../server/config-shared'
import loadJsConfig from '../../../build/load-jsconfig'
type IssueKey = `${Issue['severity']}-${Issue['filePath']}-${string}-${string}` type IssueKey = `${Issue['severity']}-${Issue['filePath']}-${string}-${string}`
export type IssuesMap = Map<IssueKey, Issue> export type IssuesMap = Map<IssueKey, Issue>
...@@ -53,14 +52,6 @@ export function getIssueKey(issue: Issue): IssueKey { ...@@ -53,14 +52,6 @@ export function getIssueKey(issue: Issue): IssueKey {
)}-${JSON.stringify(issue.description)}` )}-${JSON.stringify(issue.description)}`
} }
export async function getTurbopackJsConfig(
dir: string,
nextConfig: NextConfigComplete
) {
const { jsConfig } = await loadJsConfig(dir, nextConfig)
return jsConfig ?? { compilerOptions: {} }
}
export function processIssues( export function processIssues(
currentEntryIssues: EntryIssuesMap, currentEntryIssues: EntryIssuesMap,
key: EntryKey, key: EntryKey,
......
import type { NextConfigComplete } from '../../server/config-shared' import type { NextConfigComplete } from '../../server/config-shared'
import path from 'path'
const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED' const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED'
...@@ -43,28 +42,8 @@ type EventCliSessionStarted = { ...@@ -43,28 +42,8 @@ type EventCliSessionStarted = {
reactCompilerPanicThreshold: string | null reactCompilerPanicThreshold: string | null
} }
function hasBabelConfig(dir: string): boolean {
try {
const noopFile = path.join(dir, 'noop.js')
const res = (
require('next/dist/compiled/babel/core') as typeof import('next/dist/compiled/babel/core')
).loadPartialConfig({
cwd: dir,
filename: noopFile,
sourceFileName: noopFile,
}) as any
const isForTooling =
res.options?.presets?.every(
(e: any) => e?.file?.request === 'next/babel'
) && res.options?.plugins?.length === 0
return res.hasFilesystemConfig() && !isForTooling
} catch {
return false
}
}
export function eventCliSession( export function eventCliSession(
dir: string, _dir: string,
nextConfig: NextConfigComplete, nextConfig: NextConfigComplete,
event: Omit< event: Omit<
EventCliSessionStarted, EventCliSessionStarted,
...@@ -116,7 +95,7 @@ export function eventCliSession( ...@@ -116,7 +95,7 @@ export function eventCliSession(
hasNextConfig: nextConfig.configOrigin !== 'default', hasNextConfig: nextConfig.configOrigin !== 'default',
buildTarget: 'default', buildTarget: 'default',
hasWebpackConfig: typeof nextConfig?.webpack === 'function', hasWebpackConfig: typeof nextConfig?.webpack === 'function',
hasBabelConfig: hasBabelConfig(dir), hasBabelConfig: false,
imageEnabled: !!images, imageEnabled: !!images,
imageFutureEnabled: !!images, imageFutureEnabled: !!images,
basePathEnabled: !!nextConfig?.basePath, basePathEnabled: !!nextConfig?.basePath,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment