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

Add preinstall script to fix yarn workspaces issue on windows #123

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}