Skip to content

Conversation

Shuklax
Copy link

@Shuklax Shuklax commented Oct 9, 2025

Add validation to warn users when the "type" field in package.json contains an invalid value. Previously, values like "CommonJS" (wrong case) would silently fall back to typeless behavior. Now a clear warning message is displayed indicating the expected values are "commonjs" or "module".

Fixes: #60085

Add validation to warn users when the "type" field in package.json
contains an invalid value. Previously, values like "CommonJS" (wrong
case) would silently fall back to typeless behavior. Now a clear
warning message is displayed indicating the expected values are
"commonjs" or "module".

Fixes: nodejs#60085
@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. labels Oct 9, 2025
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

tests look good to me, i'll let someone else review the C++

Copy link

codecov bot commented Oct 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.56%. Comparing base (7c85aa5) to head (e6223ee).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60180      +/-   ##
==========================================
+ Coverage   88.52%   88.56%   +0.03%     
==========================================
  Files         703      704       +1     
  Lines      207825   208092     +267     
  Branches    40003    40012       +9     
==========================================
+ Hits       183976   184294     +318     
+ Misses      15862    15811      -51     
  Partials     7987     7987              
Files with missing lines Coverage Δ
src/node_modules.cc 76.49% <100.00%> (+0.27%) ⬆️

... and 50 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.

}

if (field_value != "commonjs" && field_value != "module") {
fprintf(stderr,
Copy link
Member

Choose a reason for hiding this comment

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

This should be using the usual machinery (process.emitWarning() in JS, or ProcessEmitWarning() in C++) to emit warning so that it can be suppressed with NODE_NO_WARNINGS=1 etc. or captured through event listeners by users.

Copy link
Author

Choose a reason for hiding this comment

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

Done! Changed to use ProcessEmitWarning() instead of fprintf(). Let me know if the implementation looks correct.

if (package_json == nullptr) {
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}


});

describe('package.json type field validation', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a new test file instead of appending it to the same test file? See

In principle, when adding a new test, it should be placed in a new file.
Unless there is strong motivation to do so, refrain from appending
new test cases to an existing file. Similar to the reproductions we ask

Copy link
Author

Choose a reason for hiding this comment

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

Done! I've added a new test file.

@mertcanaltin
Copy link
Member

lint errors in some lines
you can make format-cpp command

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn when package.json contains an invalid "type" value

5 participants