From 93387d212e28f52d2355ecf4edd588bfdf1c2ed2 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Thu, 5 Oct 2023 15:12:18 +0200 Subject: [PATCH 1/3] keep this context for callbacks --- packages/commonjs/src/resolve-require-sources.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/commonjs/src/resolve-require-sources.js b/packages/commonjs/src/resolve-require-sources.js index 22d9e3f65..0e2d77f68 100644 --- a/packages/commonjs/src/resolve-require-sources.js +++ b/packages/commonjs/src/resolve-require-sources.js @@ -108,7 +108,7 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre setInitialParentType(parentId, parentMeta.initialCommonJSType); await Promise.all( parentRequires.map(({ resolved, isConditional }) => - analyzeRequiredModule(parentId, resolved, isConditional, this.load) + analyzeRequiredModule(parentId, resolved, isConditional, this.load.bind(this)) ) ); if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) { @@ -143,11 +143,11 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre ( await this.load({ id: resolved.id }) ).meta.commonjs.resolved, - this.load + this.load.bind(this) )) !== IS_WRAPPED_COMMONJS ); } - return (await getTypeForImportedModule(resolved, this.load)) === IS_WRAPPED_COMMONJS; + return (await getTypeForImportedModule(resolved, this.load.bind(this))) === IS_WRAPPED_COMMONJS; }) ) ).some((shouldTransform) => shouldTransform); @@ -182,7 +182,7 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false }; } parentMeta.requires.push({ resolved, isConditional }); - await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load); + await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load.bind(this); return { id: childId, allowProxy: true }; }) ); From 2d31405037b389e5b7f7f932feace2ac5531f0f5 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Sat, 25 Nov 2023 16:24:21 +0100 Subject: [PATCH 2/3] missing parenthesis --- packages/commonjs/src/resolve-require-sources.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/commonjs/src/resolve-require-sources.js b/packages/commonjs/src/resolve-require-sources.js index 0e2d77f68..b1466781c 100644 --- a/packages/commonjs/src/resolve-require-sources.js +++ b/packages/commonjs/src/resolve-require-sources.js @@ -182,7 +182,7 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false }; } parentMeta.requires.push({ resolved, isConditional }); - await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load.bind(this); + await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load.bind(this)); return { id: childId, allowProxy: true }; }) ); From b70ad2aab7912b8ece5faa8f74365b9d7234c92d Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Wed, 5 Jun 2024 09:42:47 +0200 Subject: [PATCH 3/3] fix prettier --- packages/commonjs/src/resolve-require-sources.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/commonjs/src/resolve-require-sources.js b/packages/commonjs/src/resolve-require-sources.js index b1466781c..0bc2d2b18 100644 --- a/packages/commonjs/src/resolve-require-sources.js +++ b/packages/commonjs/src/resolve-require-sources.js @@ -147,7 +147,10 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre )) !== IS_WRAPPED_COMMONJS ); } - return (await getTypeForImportedModule(resolved, this.load.bind(this))) === IS_WRAPPED_COMMONJS; + return ( + (await getTypeForImportedModule(resolved, this.load.bind(this))) === + IS_WRAPPED_COMMONJS + ); }) ) ).some((shouldTransform) => shouldTransform); @@ -182,7 +185,12 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false }; } parentMeta.requires.push({ resolved, isConditional }); - await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load.bind(this)); + await analyzeRequiredModule( + parentId, + resolved, + isConditional, + rollupContext.load.bind(this) + ); return { id: childId, allowProxy: true }; }) );