fix(Rspack): use loaderContext.utils.contextify to replace ModuleFilenameHelpers.createFilename (#82104)

Co-authored-by: Sebastian Sebbie Silbermann <[email protected]>
This commit is contained in:
Cong-Cong Pan
2025-07-28 13:23:12 +02:00
committed by GitHub
co-authored by Sebastian Sebbie Silbermann
parent 14c5d67328
commit 29ae22be86
2 changed files with 1146 additions and 1190 deletions
@@ -1,8 +1,9 @@
import type {
javascript,
LoaderContext,
NormalModule,
webpack,
import {
ModuleFilenameHelpers,
type javascript,
type LoaderContext,
type NormalModule,
type webpack,
} from 'next/dist/compiled/webpack/webpack'
import { RSC_MOD_REF_PROXY_ALIAS } from '../../../../lib/constants'
import {
@@ -13,7 +14,6 @@ import { warnOnce } from '../../../../shared/lib/utils/warn-once'
import { getRSCModuleInformation } from '../../../analysis/get-page-static-info'
import { formatBarrelOptimizedResource } from '../../utils'
import { getModuleBuildInfo } from '../get-module-build-info'
import { ModuleFilenameHelpers } from 'next/dist/compiled/webpack/webpack'
type SourceType = javascript.JavascriptParser['sourceType'] | 'commonjs'
@@ -148,19 +148,21 @@ ${JSON.stringify(ref)},
}
const compilation = this._compilation!
const originalSourceURL = ModuleFilenameHelpers.createFilename(
module,
{
moduleFilenameTemplate:
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.mjs',
namespace: '_N_E',
},
{
requestShortener: compilation.requestShortener,
chunkGraph: compilation.chunkGraph,
hashFunction: compilation.outputOptions.hashFunction,
}
)
const originalSourceURL = process.env.NEXT_RSPACK
? `webpack://_N_E/${this.utils.contextify(this.context || this.rootContext, this.resourcePath)}/__nextjs-internal-proxy.mjs`
: ModuleFilenameHelpers.createFilename(
module,
{
moduleFilenameTemplate:
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.mjs',
namespace: '_N_E',
},
{
requestShortener: compilation.requestShortener,
chunkGraph: compilation.chunkGraph,
hashFunction: compilation.outputOptions.hashFunction,
}
)
return this.callback(null, esmSource, {
version: 3,
@@ -179,19 +181,21 @@ module.exports = createProxy(${stringifiedResourceKey})
`
const compilation = this._compilation!
const originalSourceURL = ModuleFilenameHelpers.createFilename(
module,
{
moduleFilenameTemplate:
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.cjs',
namespace: '_N_E',
},
{
requestShortener: compilation.requestShortener,
chunkGraph: compilation.chunkGraph,
hashFunction: compilation.outputOptions.hashFunction,
}
)
const originalSourceURL = process.env.NEXT_RSPACK
? `webpack://_N_E/${this.utils.contextify(this.context || this.rootContext, this.resourcePath)}/__nextjs-internal-proxy.cjs`
: ModuleFilenameHelpers.createFilename(
module,
{
moduleFilenameTemplate:
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.cjs',
namespace: '_N_E',
},
{
requestShortener: compilation.requestShortener,
chunkGraph: compilation.chunkGraph,
hashFunction: compilation.outputOptions.hashFunction,
}
)
return this.callback(null, cjsSource, {
version: 3,
File diff suppressed because it is too large Load Diff