diff --git a/gui/packages/yarn-fixes/package.json b/gui/packages/yarn-fixes/package.json index 1a38b8e5fb9f..a884f240aae5 100644 --- a/gui/packages/yarn-fixes/package.json +++ b/gui/packages/yarn-fixes/package.json @@ -3,7 +3,6 @@ "name": "yarn-fixes", "version": "0.1.0", "scripts": { - "preinstall": "patch-yarn.bat" - }, - "os": ["win32"] + "preinstall": "node ./patch-yarn.js" + } } diff --git a/gui/packages/yarn-fixes/patch-yarn.bat b/gui/packages/yarn-fixes/patch-yarn.bat deleted file mode 100644 index f4c99cadef7f..000000000000 --- a/gui/packages/yarn-fixes/patch-yarn.bat +++ /dev/null @@ -1,27 +0,0 @@ -@echo off -setlocal - -rem Yarn 1.9.4 has a path lookup bug on Windows, when it looks for the binaries referenced in -rem scripts under '\gui\node_modules\node_modules' instead of '\gui\node_modules'. -rem This patch adds a junction between those two to keep that house of cards from falling apart. - -echo Applying a workspace patch for yarn on Windows... - -call :NORMALIZEPATH "%~dp0\..\.." -set ROOT_WORKSPACE_DIR=%RETVAL% - -echo Root workspace path: %ROOT_WORKSPACE_DIR% - -set NODE_MODULES_DIR="%ROOT_WORKSPACE_DIR%\node_modules" -set DOUBLE_NODE_MODULES_DIR="%ROOT_WORKSPACE_DIR%\node_modules\node_modules" - -if exist %DOUBLE_NODE_MODULES_DIR% ( - rmdir %DOUBLE_NODE_MODULES_DIR% -) - -mklink /j %DOUBLE_NODE_MODULES_DIR% %NODE_MODULES_DIR% - -rem Normalizes relative path to absolute -:NORMALIZEPATH - set RETVAL=%~dpfn1 - exit /B diff --git a/gui/packages/yarn-fixes/patch-yarn.js b/gui/packages/yarn-fixes/patch-yarn.js new file mode 100644 index 000000000000..7d54bb13a804 --- /dev/null +++ b/gui/packages/yarn-fixes/patch-yarn.js @@ -0,0 +1,30 @@ +// Yarn 1.9.4 has a path lookup bug on Windows, when it looks for the binaries referenced in +// scripts under '\gui\node_modules\node_modules' instead of '\gui\node_modules'. +// This patch adds a junction between those two to keep that house of cards from falling apart. + +const path = require('path'); +const fs = require('fs'); + +if (process.platform !== 'win32') { + return; +} + +const sourcePath = path.resolve(path.join(__dirname, '../../node_modules')); +const symlinkPath = path.join(__dirname, '../../node_modules/node_modules'); + +try { + console.log('Removing a symlink to node_modules/node_modules'); + fs.unlinkSync(symlinkPath); +} catch (error) { + if (error.code !== 'ENOENT') { + throw error; + } +} + +try { + console.log('Applying yarn workspaces patch for node_modules/node_modules'); + fs.symlinkSync(sourcePath, symlinkPath, 'junction'); + console.log('Done'); +} catch (error) { + console.error('Cannot symlink node_modules/node_modules: ' + error.message); +}