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

module: use undefined if no main #18593

Closed
wants to merge 1 commit into from

Conversation

Trott
Copy link
Member

@Trott Trott commented Feb 6, 2018

If the package.json file does not have a "main" entry, return undefined
rather than an empty string. This is to make more consistent behavior.
For example, when package.json is a directory, "main" is undefined
rather than an empty string.

@bmeck @bnoordhuis Is this an acceptable resolution of the "package.json as a directory leaves main undefined if we land #18270, but package.json as a file without a main sets main to an empty string" disagreement? Opening a PR because I figure it would be easier to determine "yes" or "no" with an actual proposal to look at. I believe @bmeck would prefer the empty string for both scenarios, but I also believe that undefined is acceptable to them too as long as it applies to both scenarios. But I could be wrong...

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

module

If the package.json file does not have a "main" entry, return undefined
rather than an empty string. This is to make more consistent behavior.
For example, when package.json is a directory, "main" is undefined
rather than an empty string.
@Trott Trott added module Issues and PRs related to the module subsystem. semver-major PRs that contain breaking changes and should be released in the next major version. labels Feb 6, 2018
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. labels Feb 6, 2018
@jdalton
Copy link
Member

jdalton commented Feb 6, 2018

Would this naturally shake out of @guybedford's package.json reading work for the "mode":"esm"?
If so, since there's no rush, that could be a way to deal with it.

@bmeck
Copy link
Member

bmeck commented Feb 6, 2018

As long as they are the same that seems fine. I will still open up a PR to cache all the results unconditionally sometime in the future though.

@Trott
Copy link
Member Author

Trott commented Feb 6, 2018

I'm going to mark this as blocked because it should only land if #18270 lands first.

@Trott
Copy link
Member Author

Trott commented Feb 8, 2018

Landing #18270 as soon as I get green/yellow CI. Unblocking this. This could definitely use some more reviews. Ping @nodejs/collaborators

CI: https://ci.nodejs.org/job/node-test-pull-request/13028/

@Trott Trott removed the blocked PRs that are blocked by other issues or PRs. label Feb 8, 2018
@devsnek
Copy link
Member

devsnek commented Feb 8, 2018

seems like much saner behavior, lgtm

@Trott
Copy link
Member Author

Trott commented Feb 8, 2018

Ci is yellow. 🎉

@Trott
Copy link
Member Author

Trott commented Feb 8, 2018

This is semver-major so it needs two approvals from @nodejs/tsc before it can land. Please review! Thanks!

@Trott
Copy link
Member Author

Trott commented Feb 8, 2018

@jdalton
Copy link
Member

jdalton commented Feb 8, 2018

Just for context this change is sitting on top of other semver-major changes like InternalModuleReadJSON.

@Trott
Copy link
Member Author

Trott commented Feb 8, 2018

Just for context this change is sitting on top of other semver-major changes like InternalModuleReadJSON.

I only did a cursory look at first and saw this change affects the results of tests that are already in v9.x-staging. So it semver-major! But now I see that it may only change internal behavior and may not be observable by the end user without dipping into process.binding('fs'). So maybe not semver-major after all? In any event, I don't mind being cautious. I will certainly feel differently if this stalls, though. :-D

@benjamingr
Copy link
Member

@nodejs/modules

Copy link
Member

@hiroppy hiroppy left a comment

Choose a reason for hiding this comment

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

👍

@Trott
Copy link
Member Author

Trott commented Feb 9, 2018

Still needs one more @nodejs/tsc approval.

@Fishrock123
Copy link
Contributor

I don't have any strong feelings about this but would like to hear @bnoordhuis's opinion, if he has one.

@BridgeAR BridgeAR added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. and removed c++ Issues and PRs that require attention from people who are familiar with C++. labels Feb 10, 2018
@Trott
Copy link
Member Author

Trott commented Feb 11, 2018

Can someone familiar with CITGM review the CITGM results or point me to documentation that will explain how to review result? https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1266/ I looked over them but I'm not sure how to tell what's expected failures and what's not. @nodejs/citgm

@mcollina
Copy link
Member

@Trott that looks ok to me. I'm currently working on fixing some of those packages.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

Trott added a commit to Trott/io.js that referenced this pull request Feb 11, 2018
If the package.json file does not have a "main" entry, return undefined
rather than an empty string. This is to make more consistent behavior.
For example, when package.json is a directory, "main" is undefined
rather than an empty string.

PR-URL: nodejs#18593
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@Trott
Copy link
Member Author

Trott commented Feb 11, 2018

Landed in bd4773a.

@Trott Trott closed this Feb 11, 2018
@bnoordhuis
Copy link
Member

I don't have any strong feelings about this but would like to hear @bnoordhuis's opinion, if he has one.

Belated: this PR should have removed the if (json === '') check from lib/module.js, it's dead code now.

More importantly, it undoes the optimization that a package.json without a 'main' property isn't loaded from disk repeatedly.

That said, the logic in readPackage() looks kind of broken anyway. It's quite possibly no worse than before.

@Trott
Copy link
Member Author

Trott commented Feb 13, 2018

Belated: this PR should have removed the if (json === '') check from lib/module.js, it's dead code now.

Thanks. That can be fixed in a subsequent PR. I'll submit it shortly if no one else has done so already.

More importantly, it undoes the optimization that a package.json without a 'main' property isn't loaded from disk repeatedly.

If I understand correctly (which is a pretty big caveat), that would be fixed by caching negative results, which @bmeck intends to introduce. Not sure if that is likely to get much push-back or not.

@bmeck
Copy link
Member

bmeck commented Feb 13, 2018

@Trott pretty much, but I've been talking to @guybedford about some stuff we can do to make the cache a bit better and moved to C++ so that it can be used prior to crossing the C++/JS bridge and same as #18728 . Might be a little bit pending that.

Trott added a commit to Trott/io.js that referenced this pull request Feb 13, 2018
Remove unnecessary condition in lib/module.js.

Refs: nodejs#18593 (comment)
Trott added a commit to Trott/io.js that referenced this pull request Feb 16, 2018
Remove unnecessary condition in lib/module.js.

Refs: nodejs#18593 (comment)

PR-URL: nodejs#18768
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
If the package.json file does not have a "main" entry, return undefined
rather than an empty string. This is to make more consistent behavior.
For example, when package.json is a directory, "main" is undefined
rather than an empty string.

PR-URL: nodejs#18593
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Remove unnecessary condition in lib/module.js.

Refs: nodejs#18593 (comment)

PR-URL: nodejs#18768
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@Trott Trott deleted the empty-string-undefined branch January 13, 2022 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. module Issues and PRs related to the module subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.