Skip to content

Commit cb6aca7

Browse files
Lms24jrandolfAbhiPrasad
authored
fix(v8/core): Pass module into loadModule (#15139) (#15166)
backport of #15139 --------- Co-authored-by: Randolf J <[email protected]> Co-authored-by: Abhijeet Prasad <[email protected]>
1 parent 4a83c9a commit cb6aca7

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Now, there are two options to set up the SDK:
5454
);
5555
```
5656

57-
Work in this release was contributed by @jahands. Thank you for your contribution!
57+
Work in this release was contributed by @jahands and @jrandolf. Thank you for your contributions!
5858

5959
## 8.51.0
6060

packages/core/src/utils-hoist/node.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,26 @@ export function dynamicRequire(mod: any, request: string): any {
4242
* That is to mimic the behavior of `require.resolve` exactly.
4343
*
4444
* @param moduleName module name to require
45+
* @param existingModule module to use for requiring
4546
* @returns possibly required module
4647
*/
47-
export function loadModule<T>(moduleName: string): T | undefined {
48+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49+
export function loadModule<T>(moduleName: string, existingModule: any = module): T | undefined {
4850
let mod: T | undefined;
4951

5052
try {
5153
// eslint-disable-next-line deprecation/deprecation
52-
mod = dynamicRequire(module, moduleName);
54+
mod = dynamicRequire(existingModule, moduleName);
5355
} catch (e) {
5456
// no-empty
5557
}
5658

5759
if (!mod) {
5860
try {
5961
// eslint-disable-next-line deprecation/deprecation
60-
const { cwd } = dynamicRequire(module, 'process');
62+
const { cwd } = dynamicRequire(existingModule, 'process');
6163
// eslint-disable-next-line deprecation/deprecation
62-
mod = dynamicRequire(module, `${cwd()}/node_modules/${moduleName}`) as T;
64+
mod = dynamicRequire(existingModule, `${cwd()}/node_modules/${moduleName}`) as T;
6365
} catch (e) {
6466
// no-empty
6567
}

packages/nextjs/src/config/webpack.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export function constructWebpackConfigFunction(
332332
// Symbolication for dev-mode errors is done elsewhere.
333333
if (!isDev) {
334334
// eslint-disable-next-line @typescript-eslint/no-explicit-any
335-
const { sentryWebpackPlugin } = loadModule<{ sentryWebpackPlugin: any }>('@sentry/webpack-plugin') ?? {};
335+
const { sentryWebpackPlugin } = loadModule<{ sentryWebpackPlugin: any }>('@sentry/webpack-plugin', module) ?? {};
336336

337337
if (sentryWebpackPlugin) {
338338
if (!userSentryOptions.sourcemaps?.disable) {

packages/remix/src/utils/instrumentServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ const makeWrappedCreateRequestHandler = (options: RemixOptions) =>
448448
export function instrumentServer(options: RemixOptions): void {
449449
const pkg = loadModule<{
450450
createRequestHandler: CreateRequestHandlerFunction;
451-
}>('@remix-run/server-runtime');
451+
}>('@remix-run/server-runtime', module);
452452

453453
if (!pkg) {
454454
DEBUG_BUILD && logger.warn('Remix SDK was unable to require `@remix-run/server-runtime` package.');

0 commit comments

Comments
 (0)