Skip to content

Conversation

jitsedesmet
Copy link

No description provided.

@jitsedesmet jitsedesmet marked this pull request as ready for review August 19, 2025 12:20
Copy link
Member

@rubensworks rubensworks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a unit test?

if (!fs.existsSync(result)) {
throw new Error(`Could not dereference path ${result}.
In case the listed package is not a Node.js type, you might have an issue with dual packaging:
Your export should list your package.json explicitly.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider adding an URL to the Node.js docs showing what they should do exactly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return rootFile.replace(/index\.d\.ts$/u, `${packageName}.d.ts`);
const result = rootFile.replace(/index\.d\.ts$/u, `${packageName}.d.ts`);
// eslint-disable-next-line no-sync
if (!fs.existsSync(result)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, resolvePackageIndex is a fast sync method, but this can make it quite slow.
Can you investigate if there is another way forward?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the method also calls require.resolve, I doubt we pay a big additional cost?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are still worried about this, I can look at adding some cache (since this code is only triggered for node modules, the cache size should not be to big). - I am not committed to finding a vastly different approach sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require.resolve works with a cache.
But if you think the performance impact will be insignificant, feel free to do some benchmarking.

@jitsedesmet
Copy link
Author

@rubensworks I noticed for the unit tests you test using @comunica/bus-rdf-parse, but it is not listed in your devDependencies? I assume you manually added it to your lock file or a transient dependency is present?
I added a test using @traqula/core V0.0.1 which did the export wrong. - I explicitly added the package as a devDep.

@rubensworks
Copy link
Member

I assume you manually added it to your lock file or a transient dependency is present?

Could be a mistake indeed. It's been a long time since I've touched this code.

@@ -130,6 +130,11 @@ describe('ResolutionContext', () => {
expect(resolutionContext.resolvePackageIndex('stream', joinFilePath(__dirname, '../../')))
.toEqual(joinFilePath(__dirname, '../../node_modules/@types/node/stream.d.ts'));
});

it('Should warn users when packages do not export their package.json', async() => {
expect(() => resolutionContext.resolvePackageIndex('@traqula/core', joinFilePath(__dirname, '../../')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this test with some basic mocking instead?
Adding traqula as dep seems like a lot of overhead for just a single test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants