Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin no longer crashes in rollup only scenarios #68

Merged
merged 3 commits into from
May 3, 2024

Conversation

xenobytezero
Copy link
Contributor

Tasks

  • I've read the CONTRIBUTING guide
  • Necessary tests have been added

The plugin currently crashes when used in a Rollup only context.

The registerTools() function does a require.resolve at the top level, which will fail if the requested package does not exist. This commit reworks the registerTools function to wrap it in a try/catch.

While doing this, we also found that the code will not resolve packages like Rollup correctly. So this has also been fixed.

A require.resolve on rollup (tested with 4.14.3) will resolve to the rollup/dist/rollup.js path. The current code will then try and find a package.json at dist/package.json which will fail and so not include the package.

I attempted to add a rollup fixture for the testing purposes, but the current structure of the tests means that the code will traverse all the way up to the workspace root from the fixture folders and find both rollup and vite, regardless of which fixture is being used. I have the fixture locally but have not included it in this PR to reduce complexity.

@xenobytezero xenobytezero requested a review from janbiasi as a code owner April 25, 2024 15:19
Copy link
Owner

@janbiasi janbiasi left a comment

Choose a reason for hiding this comment

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

Hey @xenobytezero! Thanks a lot for the various fixes and adjustments, appreciate it 😃

You've mentioned that you prepared a fixture for the test, but it will always resolve the root packages, right? We could disable hoisting in general as we only have one single production package in the "monorepo" itself.

Let me know what you think :)

src/builder.ts Outdated Show resolved Hide resolved
src/helpers.ts Show resolved Hide resolved
@janbiasi janbiasi added the 🐛 bug Something isn't working as expected or stated label Apr 26, 2024
@xenobytezero
Copy link
Contributor Author

Hey @xenobytezero! Thanks a lot for the various fixes and adjustments, appreciate it 😃

You've mentioned that you prepared a fixture for the test, but it will always resolve the root packages, right? We could disable hoisting in general as we only have one single production package in the "monorepo" itself.

I had thought about this, but disabling the hoisting wont on it's own help.

In a Rollup scenario, Vite is still as a direct dependency in the root workspace, and the request.resolve() code will continue to travel all the way up regardless. The code could maybe be changed to use the getCorrespondingPackageFromModuleId code which could be set to a very specific traversal limit for the tests, but that seems a bit brittle and doesnt actually work for all scenarios (Vite would need a max traversal of 1, Rollup needs 2 because of the mentioned export map problem). It's doable, but I feel there has to be a better solution out there. If I come up with anything I'll let you know.

@xenobytezero xenobytezero force-pushed the tool-detection-fails branch from f097e9f to 0afaf42 Compare April 30, 2024 10:05
@xenobytezero
Copy link
Contributor Author

Apologies for the extra commits, had to do some author fixing.

@xenobytezero
Copy link
Contributor Author

I also added some additional filtering to the moduleParsed analysis to ignore Rollup virtual modules (where the IDs start with \0) as I noticed a lot of resolutions that were traversing all the way up the directory tree because they couldn't resolve a package.json due to the strange character at the start of the path. All the tests continue to pass.

@janbiasi
Copy link
Owner

janbiasi commented May 3, 2024

@all-contributors please add @xenobytezero for bug reports and code

Copy link
Contributor

@janbiasi

I've put up a pull request to add @xenobytezero! 🎉

@janbiasi
Copy link
Owner

janbiasi commented May 3, 2024

@xenobytezero thanks a lot for your efforts on the bugs! I'm now fine merging it even without tests as it seems quite hard to implemented (did some fiddling tonight but couldn't find a way to declare sufficient test cases neither). I'd be fine moving forward and merging your PR - is everything included from your side?

I will also merge #70 after this PR got merged.

@xenobytezero
Copy link
Contributor Author

Yep, that's now everything from my side. Happy to have the PR merged.

@janbiasi janbiasi merged commit a38f798 into janbiasi:main May 3, 2024
4 of 5 checks passed
Copy link

github-actions bot commented May 3, 2024

🎉 This PR is included in version 1.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@xenobytezero xenobytezero deleted the tool-detection-fails branch December 13, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working as expected or stated released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants