-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[New] Support "detect" option for React version setting #1978
[New] Support "detect" option for React version setting #1978
Conversation
lib/util/version.js
Outdated
const reactPath = resolve.sync('react', {basedir: process.cwd()}); | ||
const react = require(reactPath); | ||
settingsVer = react.version; | ||
} catch (e) { |
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.
Not sure what (if anything) needs to happen here, basically made a best guess.
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 LGTM but is there any way to test for this?
lib/util/version.js
Outdated
let settingsVer = context.settings.react.version; | ||
if (settingsVer === 'detect') { | ||
try { | ||
const reactPath = resolve.sync('react', {basedir: process.cwd()}); |
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.
i think this basedir is the default? probably best to specify it either way tho
lib/util/version.js
Outdated
try { | ||
const reactPath = resolve.sync('react', {basedir: process.cwd()}); | ||
const react = require(reactPath); | ||
settingsVer = react.version; |
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.
@ljharb does it make sense to cache this value for subsequent access?
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.
yes, absolutely - good call.
I was gonna ask 😄 |
hm, i don't think there is a good way :-/ however, you could construct a test directory with a package.json and a node_modules and a react dir with its own package.json, and require that? |
Ah, I think I saw babel do something like that 👍 |
The import plugin does it in its tests, as well. |
cc451e8
to
25b3662
Compare
I added a couple of tests. |
9b27370
to
c110d5c
Compare
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.
LGTM
This comment has been minimized.
This comment has been minimized.
c110d5c
to
87f4236
Compare
87f4236
to
dc28d26
Compare
This looks great. Any idea on when this might be published to NPM? |
I'd love to see it published too 😄 but see #2026 (comment)
|
v7.12.0 is released. |
I think this resolves #1955.