From 11ea42d6ea2bd02053f46dadf6fc1813e7d6cc24 Mon Sep 17 00:00:00 2001 From: mpr0xy Date: Wed, 4 Jan 2023 13:33:14 +0800 Subject: [PATCH] Fix scriptsBinPath is not a link In some cases, files in the .bin directory are not links, such as in projects generated by rushjs. --- .../src/helpers/getReactScriptsPath.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/preset-create-react-app/src/helpers/getReactScriptsPath.ts b/packages/preset-create-react-app/src/helpers/getReactScriptsPath.ts index 3654ba0..a57df19 100644 --- a/packages/preset-create-react-app/src/helpers/getReactScriptsPath.ts +++ b/packages/preset-create-react-app/src/helpers/getReactScriptsPath.ts @@ -1,4 +1,4 @@ -import { readFileSync, realpathSync } from 'fs'; +import { readFileSync, realpathSync, lstatSync } from 'fs'; import { join, dirname } from 'path'; export const getReactScriptsPath = (): string => { @@ -34,9 +34,15 @@ export const getReactScriptsPath = (): string => { * This won't work for Windows users, unless within WSL. */ try { - const resolvedBinPath = realpathSync(scriptsBinPath); - const scriptsPath = join(resolvedBinPath, '..', '..'); - return scriptsPath; + const scriptsBinPathStat = lstatSync(scriptsBinPath); + if (scriptsBinPathStat.isSymbolicLink() === true) { + const resolvedBinPath = realpathSync(scriptsBinPath); + const scriptsPath = join(resolvedBinPath, '..', '..'); + return scriptsPath; + } else if (scriptsBinPathStat.isFile() === true) { + const scriptsPath = join(cwd, '/node_modules/react-scripts'); + return scriptsPath; + } } catch (e) { // NOOP }