Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .config/eslintignore.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default globalIgnores([
'packages/next/src/bundles/webpack/packages/*.runtime.js',
'packages/next/src/bundles/webpack/packages/lazy-compilation-*.js',
'packages/next/src/compiled/**/*',
'packages/next/src/webpack/bundles/webpack/packages/*.runtime.js',
'packages/next/src/webpack/bundles/webpack/packages/lazy-compilation-*.js',
'packages/next/src/webpack/compiled/**/*',
'packages/next/wasm/@next',
'packages/react-refresh-utils/**/*.js',
'packages/react-dev-overlay/lib/**/*',
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pnpm-lock.yaml

packages/next/src/bundles/webpack/packages/*.runtime.js
packages/next/src/bundles/webpack/packages/lazy-compilation-*.js
packages/next/src/webpack/bundles/webpack/packages/*.runtime.js
packages/next/src/webpack/bundles/webpack/packages/lazy-compilation-*.js
packages/next/src/webpack/compiled/**/*
packages/next/wasm/@next
packages/next/errors.json

Expand Down
1 change: 1 addition & 0 deletions crates/next-api/src/next_server_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ impl ServerNftJsonAsset {
"**/*.map",
"**/next/dist/pages/**/*",
"**/next/dist/compiled/next-server/**/*.dev.js",
"**/next/dist/webpack/load-webpack-hook.js",
"**/next/dist/compiled/webpack/*",
"**/node_modules/webpack5/**/*",
"**/next/dist/server/lib/route-resolver*",
Expand Down
8 changes: 4 additions & 4 deletions crates/next-core/src/next_app/metadata/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ async fn dynamic_text_route_source(path: FileSystemPath) -> Result<Vc<Box<dyn So

let content_type = get_content_type(path.clone()).await?;

// refer https://github.com/vercel/next.js/blob/7b2b9823432fb1fa28ae0ac3878801d638d93311/packages/next/src/build/webpack/loaders/next-metadata-route-loader.ts#L84
// refer https://github.com/vercel/next.js/blob/7b2b9823432fb1fa28ae0ac3878801d638d93311/packages/next/src/webpack/build/webpack/loaders/next-metadata-route-loader.ts#L84
// for the original template.
let code = formatdoc! {
r#"
import {{ NextResponse }} from 'next/server'
import handler from {resource_path}
import {{ resolveRouteData }} from
'next/dist/build/webpack/loaders/metadata/resolve-route-data'
'next/dist/webpack/build/webpack/loaders/metadata/resolve-route-data'

const contentType = {content_type}
const cacheControl = {cache_control}
Expand Down Expand Up @@ -276,7 +276,7 @@ async fn dynamic_sitemap_route_with_generate_source(
r#"
import {{ NextResponse }} from 'next/server'
import {{ default as handler, generateSitemaps }} from {resource_path}
import {{ resolveRouteData }} from 'next/dist/build/webpack/loaders/metadata/resolve-route-data'
import {{ resolveRouteData }} from 'next/dist/webpack/build/webpack/loaders/metadata/resolve-route-data'

const contentType = {content_type}
const cache_control = {cache_control}
Expand Down Expand Up @@ -365,7 +365,7 @@ async fn dynamic_sitemap_route_without_generate_source(
r#"
import {{ NextResponse }} from 'next/server'
import {{ default as handler }} from {resource_path}
import {{ resolveRouteData }} from 'next/dist/build/webpack/loaders/metadata/resolve-route-data'
import {{ resolveRouteData }} from 'next/dist/webpack/build/webpack/loaders/metadata/resolve-route-data'

const contentType = {content_type}
const cacheControl = {cache_control}
Expand Down
14 changes: 9 additions & 5 deletions crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,21 +1111,23 @@ async fn insert_next_shared_aliases(
rcstr!("private-next-rsc-server-reference"),
request_to_import_mapping(
project_path.clone(),
rcstr!("next/dist/build/webpack/loaders/next-flight-loader/server-reference"),
rcstr!("next/dist/webpack/build/webpack/loaders/next-flight-loader/server-reference"),
),
);
import_map.insert_exact_alias(
rcstr!("private-next-rsc-action-client-wrapper"),
request_to_import_mapping(
project_path.clone(),
rcstr!("next/dist/build/webpack/loaders/next-flight-loader/action-client-wrapper"),
rcstr!(
"next/dist/webpack/build/webpack/loaders/next-flight-loader/action-client-wrapper"
),
),
);
import_map.insert_exact_alias(
rcstr!("private-next-rsc-action-validate"),
request_to_import_mapping(
project_path.clone(),
rcstr!("next/dist/build/webpack/loaders/next-flight-loader/action-validate"),
rcstr!("next/dist/webpack/build/webpack/loaders/next-flight-loader/action-validate"),
),
);
import_map.insert_exact_alias(
Expand All @@ -1139,14 +1141,16 @@ async fn insert_next_shared_aliases(
rcstr!("private-next-rsc-cache-wrapper"),
request_to_import_mapping(
project_path.clone(),
rcstr!("next/dist/build/webpack/loaders/next-flight-loader/cache-wrapper"),
rcstr!("next/dist/webpack/build/webpack/loaders/next-flight-loader/cache-wrapper"),
),
);
import_map.insert_exact_alias(
rcstr!("private-next-rsc-track-dynamic-import"),
request_to_import_mapping(
project_path.clone(),
rcstr!("next/dist/build/webpack/loaders/next-flight-loader/track-dynamic-import"),
rcstr!(
"next/dist/webpack/build/webpack/loaders/next-flight-loader/track-dynamic-import"
),
),
);

Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/next_shared/webpack_rules/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub async fn get_sass_loader_rules(
),
};
let resolve_url_loader = WebpackLoaderItem {
loader: rcstr!("next/dist/build/webpack/loaders/resolve-url-loader/index"),
loader: rcstr!("next/dist/build/resolve-url-loader/index"),
options: take(
serde_json::json!({
// https://github.com/vercel/turbo/blob/d527eb54be384a4658243304cecd547d09c05c6b/crates/turbopack-node/src/transforms/webpack.rs#L191
Expand Down
1 change: 1 addition & 0 deletions eslint.cli.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig([
'examples/**/*',
'test/**/*',
'**/*.d.ts',
'packages/next/src/webpack/**/*',
'turbopack/**/*',
],
languageOptions: {
Expand Down
10 changes: 6 additions & 4 deletions packages/next-plugin-storybook/preset.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
const { findPagesDir } = require('next/dist/lib/find-pages-dir')
const loadConfig = require('next/dist/server/config').default
const getWebpackConfig = require('next/dist/build/webpack-config').default
const {
getBaseWebpackConfig: getWebpackConfig,
loadWebpackHook,
} = require('next/dist/webpack/next-integration')

const CWD = process.cwd()

async function webpackFinal(config) {
loadWebpackHook()
const nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, CWD)
const { pagesDir } = findPagesDir(CWD, !!nextConfig.experimental.appDir)
const nextWebpackConfig = await getWebpackConfig(CWD, {
Expand All @@ -31,9 +35,7 @@ async function webpackFinal(config) {
// we need to resolve next-babel-loader since it's not available
// relative with storybook's config
if (rule.use && rule.use.loader === 'next-babel-loader') {
rule.use.loader = require.resolve(
'next/dist/build/webpack/loaders/next-babel-loader'
)
rule.use.loader = require.resolve('next/dist/build/babel/loader')
}
return rule
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/next/next-devtools.webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = ({ dev, ...rest }) => {
// Keep using `styleTag` to ensure when new styles injected the style can also be updated.
injectType: 'styleTag',
insert: require.resolve(
'./src/build/webpack/loaders/devtool/devtool-style-inject.js'
'next/dist/webpack/build/webpack/loaders/devtool/devtool-style-inject.js'
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/next/next-runtime.webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function makeAppAliases({ experimental, bundler }) {
'react/compiler-runtime$': `next/dist/compiled/react${reactChannel}/compiler-runtime`,
'react-dom/client$': `next/dist/compiled/react-dom${reactChannel}/client`,
// optimizations to ignore the legacy APIs in react-dom/server
'react-dom/server$': `next/dist/build/webpack/alias/react-dom-server${reactChannel}.js`,
'react-dom/server$': `next/dist/webpack/build/webpack/alias/react-dom-server${reactChannel}.js`,
'react-dom/static$': `next/dist/compiled/react-dom${reactChannel}/static.node`,
// react-server-dom-webpack alias
'react-server-dom-turbopack/client$': `next/dist/compiled/react-server-dom-turbopack${reactChannel}/client.node`,
Expand Down
8 changes: 3 additions & 5 deletions packages/next/src/build/adapter/build-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import {
convertHeaders,
} from 'next/dist/compiled/@vercel/routing-utils'

import type {
MiddlewareManifest,
EdgeFunctionDefinition,
} from '../webpack/plugins/middleware-plugin'
import type { MiddlewareManifest, EdgeFunctionDefinition } from '../manifests'

import type {
RoutesManifest,
Expand Down Expand Up @@ -2203,7 +2200,8 @@ async function getSharedNodeAssets({

const sharedTraceIgnores = [
'**/next/dist/compiled/next-server/**/*.dev.js',
'**/next/dist/compiled/webpack/*',
'**/next/dist/webpack/load-webpack-hook.js',
'**/next/dist/webpack/compiled/webpack/*',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/route-resolver*',
'next/dist/compiled/semver/semver/**/*.js',
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '../warn-about-edge-runtime'
import { RSC_MODULE_TYPES } from '../../shared/lib/constants'
import { escapeStringRegexp } from '../../shared/lib/escape-regexp'
import type { RSCMeta } from '../webpack/loaders/get-module-build-info'
import type { RSCMeta } from '../manifests'
import { PAGE_TYPES } from '../../lib/page-types'
import {
AppSegmentConfigSchemaKeys,
Expand Down
23 changes: 13 additions & 10 deletions packages/next/src/build/babel/loader/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
type SourceMap,
type BabelLoaderTransformOptions,
} from './util'
import * as Log from '../../output/log'
import { isReactCompilerRequired } from '../../swc'
import { installBindings } from '../../swc/install-bindings'
import * as Log from 'next/dist/build/output/log'
import { isReactCompilerRequired } from 'next/dist/build/swc'
import { installBindings } from 'next/dist/build/swc/install-bindings'

/**
* An internal (non-exported) type used by babel.
Expand Down Expand Up @@ -165,7 +165,7 @@ function getPlugins(

const applyCommonJsItem = hasModuleExports
? createConfigItem(
require('../plugins/commonjs') as typeof import('../plugins/commonjs'),
require('next/dist/build/babel/plugins/commonjs') as typeof import('next/dist/build/babel/plugins/commonjs'),
{ type: 'plugin' }
)
: null
Expand All @@ -182,7 +182,7 @@ function getPlugins(
!isServer && isPageFile
? createConfigItem(
[
require('../plugins/next-page-config') as typeof import('../plugins/next-page-config'),
require('next/dist/build/babel/plugins/next-page-config') as typeof import('next/dist/build/babel/plugins/next-page-config'),
],
{
type: 'plugin',
Expand All @@ -193,7 +193,7 @@ function getPlugins(
!isServer && isPageFile
? createConfigItem(
[
require('../plugins/next-page-disallow-re-export-all-exports') as typeof import('../plugins/next-page-disallow-re-export-all-exports'),
require('next/dist/build/babel/plugins/next-page-disallow-re-export-all-exports') as typeof import('next/dist/build/babel/plugins/next-page-disallow-re-export-all-exports'),
],
{ type: 'plugin' }
)
Expand All @@ -212,9 +212,12 @@ function getPlugins(
)
const nextSsgItem =
!isServer && isPageFile
? createConfigItem([require.resolve('../plugins/next-ssg-transform')], {
type: 'plugin',
})
? createConfigItem(
[require.resolve('next/dist/build/babel/plugins/next-ssg-transform')],
{
type: 'plugin',
}
)
: null
const commonJsItem = isNextDist
? createConfigItem(
Expand All @@ -224,7 +227,7 @@ function getPlugins(
: null
const nextFontUnsupported = createConfigItem(
[
require('../plugins/next-font-unsupported') as typeof import('../plugins/next-font-unsupported'),
require('next/dist/build/babel/plugins/next-font-unsupported') as typeof import('next/dist/build/babel/plugins/next-font-unsupported'),
],
{ type: 'plugin' }
)
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/build/babel/loader/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Span } from '../../../trace'
import type { Span } from 'next/dist/trace'
import transform from './transform'
import type { NextJsLoaderContext } from './types'
import type { SourceMap } from './util'
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import type { webpack } from 'next/dist/webpack/compiled/webpack/webpack'

async function nextBabelLoader(
ctx: NextJsLoaderContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/build/babel/loader/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PluginPass from 'next/dist/compiled/babel/core-lib-plugin-pass'

import getConfig from './get-config'
import { consumeIterator } from './util'
import type { Span } from '../../../trace'
import type { Span } from 'next/dist/trace'
import type { NextJsLoaderContext } from './types'
import type { SourceMap } from './util'

Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/build/babel/loader/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import type { JSONValue } from '../../../server/config-shared'
import type { Span } from '../../../trace'
import type { webpack } from 'next/dist/webpack/compiled/webpack/webpack'
import type { JSONValue } from 'next/dist/server/config-shared'
import type { Span } from 'next/dist/trace'

export interface NextJsLoaderContext extends webpack.LoaderContext<{}> {
currentTraceSpan: Span
Expand Down
7 changes: 2 additions & 5 deletions packages/next/src/build/build-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { Rewrite, Redirect } from '../lib/load-custom-routes'
import type { __ApiPreviewProps } from '../server/api-utils'
import type { NextConfigComplete } from '../server/config-shared'
import type { Span } from '../trace'
import type getBaseWebpackConfig from './webpack-config'
import type { TelemetryPluginState } from './webpack/plugins/telemetry-plugin/telemetry-plugin'
import type { TelemetryPluginState } from './manifests'
import type { Telemetry } from '../telemetry/storage'

// A layer for storing data that is used by plugins to communicate with each
Expand Down Expand Up @@ -87,9 +86,7 @@ export const NextBuildContext: Partial<{
reactProductionProfiling: boolean
noMangling: boolean
appDirOnly: boolean
clientRouterFilters: Parameters<
typeof getBaseWebpackConfig
>[1]['clientRouterFilters']
clientRouterFilters: any
previewModeId: string
fetchCacheKeyPrefix?: string
allowedRevalidateHeaderKeys?: string[]
Expand Down
10 changes: 4 additions & 6 deletions packages/next/src/build/collect-build-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import '../server/lib/cpu-profile'
import { Span } from '../trace'
import type { NextConfigComplete } from '../server/config-shared'

import {
TRACE_IGNORES,
type BuildTraceContext,
getFilesMapFromReasons,
} from './webpack/plugins/next-trace-entrypoints-plugin'
import type { BuildTraceContext } from './manifests'
import { TRACE_IGNORES, getFilesMapFromReasons } from './trace-utils'

import path from 'path'
import { resolveCacheHandlerPathToFilesystem } from '../lib/format-dynamic-import-path'
Expand Down Expand Up @@ -223,7 +220,8 @@ export async function collectBuildTraces({
const sharedIgnores = [
'**/next/dist/compiled/next-server/**/*.dev.js',
...(isStandalone ? [] : ['**/next/dist/compiled/jest-worker/**/*']),
'**/next/dist/compiled/webpack/*',
'**/next/dist/webpack/load-webpack-hook.js',
'**/next/dist/webpack/compiled/webpack/*',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/route-resolver*',
'next/dist/compiled/semver/semver/**/*.js',
Expand Down
Loading
Loading