Skip to content

node-api: preserve URL filenames without conversion #58578

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mertcanaltin
Copy link
Member

allows us to process filenames that are already URLs by passing them unchanged

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/node-api

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. labels Jun 4, 2025
@mertcanaltin mertcanaltin force-pushed the mert/fix/filename-url-handling branch from 6b4b308 to 0df3eb0 Compare June 4, 2025 20:09
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 90.14%. Comparing base (641653b) to head (6b50c57).
Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
src/node_api.cc 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58578      +/-   ##
==========================================
- Coverage   90.21%   90.14%   -0.07%     
==========================================
  Files         635      636       +1     
  Lines      187494   187895     +401     
  Branches    36838    36879      +41     
==========================================
+ Hits       169144   169375     +231     
- Misses      11145    11287     +142     
- Partials     7205     7233      +28     
Files with missing lines Coverage Δ
src/node_api.cc 75.91% <40.00%> (-0.26%) ⬇️

... and 63 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

src/node_api.cc Outdated
// receive it as a URL already.
module_filename = node::url::FromFilePath(filename.ToStringView());
const auto filename_view = filename.ToStringView();
if (filename_view.find("://") != std::string_view::npos) {
Copy link
Member

Choose a reason for hiding this comment

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

This is not a valid way to test whether the input is a URL or not

Copy link
Member Author

@mertcanaltin mertcanaltin Jun 5, 2025

Choose a reason for hiding this comment

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

@addaleax thanks, I wonder if using node::url::URL::Parse() would be a good solution here

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello @anonrig

We're trying to improve URL detection in module loading. Currently using:
if (filename_view.find("://") != std::string_view::npos)

Would ada::can_parse(filename_view) be a better/healthier approach here?

Context: We need to distinguish between file paths and URLs to decide whether to:

  • Use the string directly (if URL)
  • Convert via node::url::FromFilePath() (if file path)

Copy link
Member

Choose a reason for hiding this comment

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

Yes you can use can parse to check if an input is url.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks I will use this

@legendecas legendecas moved this from Need Triage to In Progress in Node-API Team Project Jun 6, 2025
@anonrig anonrig requested a review from addaleax June 8, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants