Repository navigation
module: expose getPackageJSON utility
#55229
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
Changes from 1 commit
48ab696
dcddd1e
98c72f4
d4ede54
92f2c62
b83707b
e0beefa
6e715ec
458dcca
903d201
b567e9a
ed4db64
9a4b1d1
c23c8f1
c865d55
a9bf393
190e315
a9e3ded
926b2b0
485b1e3
f824ce9
7deeb7f
cf49f71
358486c
d9bdf23
bf5265d
3e1cda8
da29815
b531497
eef2b60
395cfa6
841848f
945c207
4adac4c
0064379
eed739c
864b98a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,9 @@ const { | |
| ArrayIsArray, | ||
| JSONParse, | ||
| ObjectDefineProperty, | ||
| StringPrototypeLastIndexOf, | ||
| StringPrototypeSlice, | ||
| } = primordials; | ||
| const modulesBinding = internalBinding('modules'); | ||
| const { resolve, sep } = require('path'); | ||
| const { resolve } = require('path'); | ||
| const { kEmptyObject } = require('internal/util'); | ||
| const { | ||
| codes: { | ||
|
|
@@ -131,7 +129,7 @@ function getNearestParentPackageJSON(startPath, everything = false) { | |
| throw new ERR_INVALID_ARG_TYPE('startPath', 'string', startPath); | ||
| } | ||
| if ( | ||
| everything != undefined && | ||
| everything !== undefined && | ||
| typeof everything !== 'boolean' | ||
| ) { | ||
| throw new ERR_INVALID_ARG_TYPE('everything', 'boolean', everything); | ||
|
|
@@ -143,10 +141,10 @@ function getNearestParentPackageJSON(startPath, everything = false) { | |
| return { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this also need to be null prototyped
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aduh95 please advise 🙏
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it's user-facing |
||
| data: { | ||
| __proto__: null, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having null-prototype object returned to the object feels weird
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. I did it for consistency between
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That feels like another reason not to expose
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason is because we've already done the work, and handled the caching. Doing it this way also provides better performance. Users having to do exactly the same thing is the whole reason we as engineers create utilities, and there is basically no chance any user would not subsequently parse it. Freezing seems like a good idea. |
||
| ...JSON.parse(result[0]), | ||
| ...JSONParse(result[0]), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes an unnecessary deep copy.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I need to spread here in order to void the prototype. Or is voiding the prototype here not necessary because it came from c-land? |
||
| }, | ||
| path: result[1], | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| const result = modulesBinding.getNearestParentPackageJSON(startPath); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.