-
Notifications
You must be signed in to change notification settings - Fork 2
Description
We have been using tracing-hooks to instrument the @langchain/core library. Langchain uses conditional exports in their package.json which translates a package/file being required/imported into a different file path.
tracing-hooks handles this already, but there should be tests to assert that this slightly more complicated use case continues to work. I will create a PR to add these tests.
Acceptance Criteria
- A third test package,
pkg-3, is created that has conditional exports and contains both CJS and ESM files. - A correct
InstrumentationConfigis supplied and code transformation works as expected
Example
Imagine a package named test-package with class Foo. It is required/imported as 'test-package/foo'. test-package has conditional exports as described by its package.json:
test-package/package.json:
...
"exports": {
"./foo": {
"require": {
"default": ""./some/other/path/foo.cjs"
},
"import": {
"default": "./some/other/path/foo.js"
}
}
}
...
test-package/some/other/path/foo.cjs:
class Foo {
constructor() {}
bar() {}
}
module.exports = Foo
test-package/some/other/path/foo.js:
class Foo {
constructor() {}
bar() {}
}
export default Foo
The correct InstrumentationConfig should be defined as below and the tests will assert that this works (which it already does in practice).
{
channelName: 'Foo_bar ',
module: { name: 'test-package', versionRange: '>=0.0.0', filePath: "some/other/path/foo.js" },
functionQuery: {
className: 'Foo',
methodName: 'bar',
kind: 'Sync'
}
}