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

[Fix] version detection: support processor virtual filename #2949

Merged
merged 1 commit into from Mar 24, 2021
Merged

[Fix] version detection: support processor virtual filename #2949

merged 1 commit into from Mar 24, 2021

Conversation

@JounQin
Copy link
Contributor

@JounQin JounQin commented Mar 23, 2021

close #2948

cc @ljharb

lib/util/version.js Outdated Show resolved Hide resolved
tests/util/version.js Outdated Show resolved Hide resolved
tests/util/version.js Show resolved Hide resolved
@ljharb
Copy link
Collaborator

@ljharb ljharb commented Mar 23, 2021

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;
@JounQin
Copy link
Contributor Author

@JounQin JounQin commented Mar 23, 2021

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?

@ljharb
Copy link
Collaborator

@ljharb ljharb commented Mar 23, 2021

Indeed; my implementation isn't ideal, i just meant the overall approach of using fs methods.

@JounQin
Copy link
Contributor Author

@JounQin JounQin commented Mar 23, 2021

@ljharb Done!

lib/util/version.js Outdated Show resolved Hide resolved
lib/util/version.js Outdated Show resolved Hide resolved
@JounQin
Copy link
Contributor Author

@JounQin JounQin commented Mar 24, 2021

@ljharb Although I disagree with your opinion, but these changes are just simple, so Done!

@JounQin JounQin requested a review from ljharb Mar 24, 2021
@ljharb
ljharb approved these changes Mar 24, 2021
Copy link
Collaborator

@ljharb ljharb left a comment

Thanks, this looks great

@ljharb ljharb changed the title fix: support processor virtual filename [Fix] version detection: support processor virtual filename … Mar 24, 2021
@ljharb ljharb changed the title [Fix] version detection: support processor virtual filename … [Fix] version detection: support processor virtual filename Mar 24, 2021
@ljharb ljharb merged commit bc37220 into yannickcr:master Mar 24, 2021
43 checks passed
43 checks passed
@github-actions
Automatic Rebase
Details
@github-actions
Require “Allow Edits”
Details
@github-actions
matrix
Details
@github-actions
pretest
Details
@github-actions
readme
Details
@github-actions
latest majors (15, 7)
Details
@github-actions
posttest
Details
@github-actions
latest majors (15, 6)
Details
@github-actions
latest majors (15, 5)
Details
@github-actions
latest majors (15, 4)
Details
@github-actions
latest majors (14, 7)
Details
@github-actions
latest majors (14, 6)
Details
@github-actions
latest majors (14, 5)
Details
@github-actions
latest majors (14, 4)
Details
@github-actions
latest majors (13, 7)
Details
@github-actions
latest majors (13, 6)
Details
@github-actions
latest majors (13, 5)
Details
@github-actions
latest majors (13, 4)
Details
@github-actions
latest majors (12, 7)
Details
@github-actions
latest majors (12, 6)
Details
@github-actions
latest majors (12, 5)
Details
@github-actions
latest majors (12, 4)
Details
@github-actions
latest majors (11, 7)
Details
@github-actions
latest majors (11, 6)
Details
@github-actions
latest majors (11, 5)
Details
@github-actions
latest majors (11, 4)
Details
@github-actions
latest majors (10, 7)
Details
@github-actions
latest majors (10, 6)
Details
@github-actions
latest majors (10, 5)
Details
@github-actions
latest majors (10, 4)
Details
@github-actions
latest majors (9, 6)
Details
@github-actions
latest majors (9, 5)
Details
@github-actions
latest majors (9, 4)
Details
@github-actions
latest majors (8, 6)
Details
@github-actions
latest majors (8, 5)
Details
@github-actions
latest majors (8, 4)
Details
@github-actions
latest majors (7, 5)
Details
@github-actions
latest majors (7, 4)
Details
@github-actions
latest majors (6, 5)
Details
@github-actions
latest majors (6, 4)
Details
@github-actions
latest majors (5, 4)
Details
@github-actions
latest majors (4, 4)
Details
@github-actions
node 4+
Details
@JounQin JounQin deleted the JounQin:fix/virtual_filename branch Mar 24, 2021
@JounQin
Copy link
Contributor Author

@JounQin JounQin commented Mar 24, 2021

@ljharb Is there a schedule to release a patch version? I think it is a serious issue because the original version breaks.

@ljharb
Copy link
Collaborator

@ljharb ljharb commented Mar 24, 2021

I've just published v7.23.1.

@JounQin
Copy link
Contributor Author

@JounQin JounQin commented Mar 24, 2021

Thanks, although the CHANGELOG seems incorrect.

image

@ljharb
Copy link
Collaborator

@ljharb ljharb commented Mar 24, 2021

That's quite correct. There's nothing unreleased at the moment.

@JounQin
Copy link
Contributor Author

@JounQin JounQin commented Mar 24, 2021

@ljharb I mean [7.23.1], see #2950

@ljharb
Copy link
Collaborator

@ljharb ljharb commented Mar 24, 2021

ah yes, thanks, a copypaste error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants