-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
module: warn on invalid package.json type field #60180
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
base: main
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this 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++
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
src/node_modules.cc
Outdated
} | ||
|
||
if (field_value != "commonjs" && field_value != "module") { | ||
fprintf(stderr, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/node_modules.cc
Outdated
if (package_json == nullptr) { | ||
return; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} |
|
||
}); | ||
|
||
describe('package.json type field validation', () => { |
There was a problem hiding this comment.
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
node/doc/contributing/writing-tests.md
Lines 30 to 32 in 3983ef6
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 |
There was a problem hiding this comment.
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.
lint errors in some lines |
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