-
-
Save trentm/809410f18c1ef3b0e70f8d70621d480c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/index.js b/index.js | |
index 1aa1210..134dd9a 100644 | |
--- a/index.js | |
+++ b/index.js | |
@@ -232,6 +232,7 @@ function Hook (modules, options, onrequire) { | |
// success. Basically, we take a required module like | |
// `../dist/foo/bar.cjs` and narrow it down to what is likely present | |
// in the package exports. | |
+ console.log('\nXXX doWork section: attempt to map `require(id=%j)` in %j (filename=%j, moduleName=%j, fullModuleName=%j)', id, this.filename, filename, moduleName, fullModuleName) | |
let doWork = true | |
const parts = id.split('/') | |
const fileName = parts[parts.length - 1] | |
@@ -247,13 +248,17 @@ function Hook (modules, options, onrequire) { | |
} | |
const exportName = moduleName + '/' + parts.join('/') | |
+ // console.log('XXX try require.resolve(exportName=%j)', exportName) | |
require.resolve(exportName) | |
moduleName = exportName | |
if (modules.includes(exportName) === true) { | |
+ console.log('XXX matchFound: mapped filename=%j to allowlisted moduleName=%j', filename, moduleName); | |
matchFound = true | |
} | |
doWork = false | |
- } catch {} | |
+ } catch (err) { | |
+ // console.log('XXX ignore err:', err.message) | |
+ } | |
} while (doWork === true) | |
} else if (!id.startsWith('.') && modules.includes(id)) { | |
// Not starting with '.' means `id` is identifying a module path, | |
diff --git a/test/mapped-exports.js b/test/mapped-exports.js | |
index b18b52b..62164ec 100644 | |
--- a/test/mapped-exports.js | |
+++ b/test/mapped-exports.js | |
@@ -7,41 +7,7 @@ const { Hook } = require('../') | |
// Mapped export tests require Node.js >=12.17.0 for "exports" support in package.json. | |
const nodeSupportsExports = semver.lt(process.version, '12.17.0') | |
-test('handles mapped exports: mapped-exports/foo', { skip: nodeSupportsExports }, function (t) { | |
- t.plan(2) | |
- | |
- const hook = new Hook(['mapped-exports/foo'], function (exports, name) { | |
- t.equal(name, 'mapped-exports/foo') | |
- const answer = exports.answer | |
- exports.answer = function wrappedAnswer () { | |
- return 'wrapped-' + answer() | |
- } | |
- return exports | |
- }) | |
- | |
- const foo = require('mapped-exports/foo') | |
- t.equal(foo.answer(), 'wrapped-42') | |
- | |
- hook.unhook() | |
-}) | |
- | |
-test('handles mapped exports: mapped-exports/bar', { skip: nodeSupportsExports }, function (t) { | |
- t.plan(2) | |
- | |
- const hook = new Hook(['mapped-exports/bar'], function (exports, name) { | |
- t.equal(name, 'mapped-exports/bar') | |
- const answer = exports.answer | |
- exports.answer = function wrappedAnswer () { | |
- return 'wrapped-' + answer() | |
- } | |
- return exports | |
- }) | |
- | |
- const bar = require('mapped-exports/bar') | |
- t.equal(bar.answer(), 'wrapped-42') | |
- | |
- hook.unhook() | |
-}) | |
+// XXX elided tests | |
test('handles mapped exports: picks up allow listed resolved module', { skip: nodeSupportsExports }, function (t) { | |
t.plan(3) | |
@@ -50,6 +16,7 @@ test('handles mapped exports: picks up allow listed resolved module', { skip: no | |
const hook = new Hook(['@langchain/core/callbacks/manager'], function (exports, name) { | |
t.equal(name, '@langchain/core/callbacks/manager', 'hook name matches') | |
hookHit = true | |
+ console.log('XXX exports for @langchain/core/callbacks/manager:', exports); | |
return exports | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment