Skip to content

Commit

Permalink
Add preinstall script to fix yarn workspaces issue on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
frontend210 committed Jul 22, 2019
1 parent 26b4403 commit 86fe190
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"main": "__generated__/AppEntry.js",
"scripts": {
"preinstall": "node ./patch-yarn.js",
"postinstall": "expo-yarn-workspaces postinstall",
"start": "expo start",
"ios": "expo start --ios",
Expand Down
32 changes: 32 additions & 0 deletions packages/app/patch-yarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Yarn has (v1.17.3) still 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.
// GitHub issue: https://github.com/yarnpkg/yarn/issues/4564#issuecomment-414613939,
// Pull Request: https://github.com/mullvad/mullvadvpn-app/pull/369

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);
}

0 comments on commit 86fe190

Please sign in to comment.