Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29ae22b

Browse files
SyMindeps1lon
andauthored
fix(Rspack): use loaderContext.utils.contextify to replace ModuleFilenameHelpers.createFilename (#82104)
Co-authored-by: Sebastian Sebbie Silbermann <[email protected]>
1 parent 14c5d67 commit 29ae22b

File tree

2 files changed

+1146
-1190
lines changed

2 files changed

+1146
-1190
lines changed

packages/next/src/build/webpack/loaders/next-flight-loader/index.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type {
2-
javascript,
3-
LoaderContext,
4-
NormalModule,
5-
webpack,
1+
import {
2+
ModuleFilenameHelpers,
3+
type javascript,
4+
type LoaderContext,
5+
type NormalModule,
6+
type webpack,
67
} from 'next/dist/compiled/webpack/webpack'
78
import { RSC_MOD_REF_PROXY_ALIAS } from '../../../../lib/constants'
89
import {
@@ -13,7 +14,6 @@ import { warnOnce } from '../../../../shared/lib/utils/warn-once'
1314
import { getRSCModuleInformation } from '../../../analysis/get-page-static-info'
1415
import { formatBarrelOptimizedResource } from '../../utils'
1516
import { getModuleBuildInfo } from '../get-module-build-info'
16-
import { ModuleFilenameHelpers } from 'next/dist/compiled/webpack/webpack'
1717

1818
type SourceType = javascript.JavascriptParser['sourceType'] | 'commonjs'
1919

@@ -148,19 +148,21 @@ ${JSON.stringify(ref)},
148148
}
149149

150150
const compilation = this._compilation!
151-
const originalSourceURL = ModuleFilenameHelpers.createFilename(
152-
module,
153-
{
154-
moduleFilenameTemplate:
155-
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.mjs',
156-
namespace: '_N_E',
157-
},
158-
{
159-
requestShortener: compilation.requestShortener,
160-
chunkGraph: compilation.chunkGraph,
161-
hashFunction: compilation.outputOptions.hashFunction,
162-
}
163-
)
151+
const originalSourceURL = process.env.NEXT_RSPACK
152+
? `webpack://_N_E/${this.utils.contextify(this.context || this.rootContext, this.resourcePath)}/__nextjs-internal-proxy.mjs`
153+
: ModuleFilenameHelpers.createFilename(
154+
module,
155+
{
156+
moduleFilenameTemplate:
157+
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.mjs',
158+
namespace: '_N_E',
159+
},
160+
{
161+
requestShortener: compilation.requestShortener,
162+
chunkGraph: compilation.chunkGraph,
163+
hashFunction: compilation.outputOptions.hashFunction,
164+
}
165+
)
164166

165167
return this.callback(null, esmSource, {
166168
version: 3,
@@ -179,19 +181,21 @@ module.exports = createProxy(${stringifiedResourceKey})
179181
`
180182

181183
const compilation = this._compilation!
182-
const originalSourceURL = ModuleFilenameHelpers.createFilename(
183-
module,
184-
{
185-
moduleFilenameTemplate:
186-
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.cjs',
187-
namespace: '_N_E',
188-
},
189-
{
190-
requestShortener: compilation.requestShortener,
191-
chunkGraph: compilation.chunkGraph,
192-
hashFunction: compilation.outputOptions.hashFunction,
193-
}
194-
)
184+
const originalSourceURL = process.env.NEXT_RSPACK
185+
? `webpack://_N_E/${this.utils.contextify(this.context || this.rootContext, this.resourcePath)}/__nextjs-internal-proxy.cjs`
186+
: ModuleFilenameHelpers.createFilename(
187+
module,
188+
{
189+
moduleFilenameTemplate:
190+
'webpack://[namespace]/[resource-path]/__nextjs-internal-proxy.cjs',
191+
namespace: '_N_E',
192+
},
193+
{
194+
requestShortener: compilation.requestShortener,
195+
chunkGraph: compilation.chunkGraph,
196+
hashFunction: compilation.outputOptions.hashFunction,
197+
}
198+
)
195199

196200
return this.callback(null, cjsSource, {
197201
version: 3,

0 commit comments

Comments
 (0)