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(npm): use original node regex in npm resolution #17404

Merged
merged 3 commits into from Jan 13, 2023

Conversation

wontem
Copy link
Contributor

@wontem wontem commented Jan 13, 2023

Closes #17403

@CLAassistant
Copy link

CLAassistant commented Jan 13, 2023

CLA assistant check
All committers have signed the CLA.

@@ -339,7 +339,7 @@ fn resolve_package_target_string(
));
}
let invalid_segment_re =
Regex::new(r"(^|\|/)(..?|node_modules)(\|/|$)").expect("bad regex");
Regex::new(r"(^|\\|/)(\.\.?|node_modules)?(\\|/|$)").expect("bad regex");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The corresponding regex in the node codebase:

https://github.com/nodejs/node/blob/f5dc92cff34933fc4a4685765afbba085f081b36/lib/internal/modules/esm/resolve.js#L299

After cleanup I found that not only escaping symbols are missed but also the question mark

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted the optional regex group change because I found that it was introduced in this PR (related to double slash deprecation), after the deno impelementation so I guess, it's enough to have the deprecated version for now

@bartlomieju
Copy link
Member

Cool, thanks for the fix! Any chance you could add some tests that exercise this changed regex? I believe they should be added to cli/tests/testdata/npm/conditional_exports/main.js and cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json. You can run the test by doing cargo test npm::conditional_exports

@wontem
Copy link
Contributor Author

wontem commented Jan 13, 2023

Sure! Just wanted to ask about tests. Thanks for the quick comment!

@wontem
Copy link
Contributor Author

wontem commented Jan 13, 2023

Added a test case and reverted the optional regex group change, see #17404 (comment)

@wontem
Copy link
Contributor Author

wontem commented Jan 13, 2023

The failed test seems to be unrelated. Can it be flaky?

@bartlomieju
Copy link
Member

The failed test seems to be unrelated. Can it be flaky?

That's possible, I restarted the CI

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM! I confirmed the test fails on main but this PR fixes it. Very nice first contribution @wontem, thanks!

@bartlomieju bartlomieju merged commit 934ed8e into denoland:main Jan 13, 2023
bartlomieju pushed a commit that referenced this pull request Jan 16, 2023
Fixes regex for matching conditional exports in a package.
Updated to the same regex Node.js uses.
MierenManz added a commit to MierenManz/oned that referenced this pull request Jan 20, 2023
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.

Node modules resolution fails for a valid exports configuration
3 participants