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
[Fix] version detection: support processor virtual filename #2949
Conversation
What I've been playing with is: diff --git a/lib/util/version.js b/lib/util/version.js
index c34b7c55..7f99dd96 100644
--- a/lib/util/version.js
+++ b/lib/util/version.js
@@ -7,6 +7,7 @@
const resolve = require('resolve');
const path = require('path');
+const fs = require('fs');
const error = require('./error');
let warnedForMissingVersion = false;
@@ -27,8 +28,20 @@ function detectReactVersion(context) {
return cachedDetectedReactVersion;
}
+ let basedir = process.cwd();
+ if (context) {
+ const filename = context.getFilename();
+ const fileDir = path.dirname(filename);
+ try {
+ const isFile = fs.statSync(filename).isFile();
+ const fileDirIsDir = fs.statSync(fileDir).isDirectory();
+ if (fileDirIsDir && isFile) {
+ basedir = fileDir;
+ }
+ } catch (e) { /**/ }
+ }
try {
- const reactPath = resolve.sync('react', {basedir: context ? path.dirname(context.getFilename()) : process.cwd()});
+ const reactPath = resolve.sync('react', {basedir});
const react = require(reactPath); // eslint-disable-line global-require, import/no-dynamic-require
cachedDetectedReactVersion = react.version;
return cachedDetectedReactVersion; |
There is a flow version test too, so an extra util function is preferred. @ljharb You implementation will not try the true dirname anymore but use cwd as fallback, I don't think this is expected? |
Indeed; my implementation isn't ideal, i just meant the overall approach of using |
@ljharb Done! |
@ljharb Although I disagree with your opinion, but these changes are just simple, so Done! |
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.
Thanks, this looks great
@ljharb Is there a schedule to release a patch version? I think it is a serious issue because the original version breaks. |
I've just published v7.23.1. |
That's quite correct. There's nothing unreleased at the moment. |
ah yes, thanks, a copypaste error. |
close #2948
cc @ljharb