Skip to content

Commit

Permalink
fix(install): Rebuild native modules when node version changes (yarnp…
Browse files Browse the repository at this point in the history
…kg#4750)

**Summary**

Fixes yarnpkg#756. We have multiple versions of our app and each one uses a different version of node. 
Therefore we need to rebuild our `node-sass` module every time we move from one to another. 

This PR addresses that by saving the NODE version those artifacts were built with within the `.yarn-integrity` file and triggers forced scripts install (only if the node version is different ofc).

**Test plan**

```
1. Install Node.js 7.x
2. Add the node-sass dependency to the project via Yarn
3. Update Node.js to 8.x (new NODE_VERSION)
4. Run "yarn install" (you should see yarn downloading fresh scripts/binaries)
```
  • Loading branch information
romanschejbal authored and joaolucasl committed Oct 27, 2017
1 parent cfdd320 commit cbbcb53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ export class Install {
return false;
}

if (match.hardRefreshRequired) {
// e.g. node version doesn't match, force script installations
this.scripts.setForce(true);
return false;
}

if (!patterns.length && !match.integrityFileMissing) {
this.reporter.success(this.reporter.lang('nothingToInstall'));
await this.createEmptyManifestFolders();
Expand Down
8 changes: 8 additions & 0 deletions src/integrity-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const integrityErrors = {
LINKED_MODULES_DONT_MATCH: 'integrityCheckLinkedModulesDontMatch',
PATTERNS_DONT_MATCH: 'integrityPatternsDontMatch',
MODULES_FOLDERS_MISSING: 'integrityModulesFoldersMissing',
NODE_VERSION_DOESNT_MATCH: 'integrityNodeDoesntMatch',
};

type IntegrityError = $Keys<typeof integrityErrors>;
Expand All @@ -37,6 +38,7 @@ type IntegrityHashLocation = {
};

type IntegrityFile = {
nodeVersion: string,
flags: Array<string>,
modulesFolders: Array<string>,
linkedModules: Array<string>,
Expand All @@ -54,6 +56,7 @@ type IntegrityFlags = {
};

const INTEGRITY_FILE_DEFAULTS = () => ({
nodeVersion: process.version,
modulesFolders: [],
flags: [],
linkedModules: [],
Expand Down Expand Up @@ -295,6 +298,10 @@ export default class InstallationIntegrityChecker {
return 'LINKED_MODULES_DONT_MATCH';
}

if (actual.nodeVersion !== expected.nodeVersion) {
return 'NODE_VERSION_DOESNT_MATCH';
}

let relevantExpectedFlags = expected.flags.slice();

// If we run "yarn" after "yarn --check-files", we shouldn't fail the less strict validation
Expand Down Expand Up @@ -386,6 +393,7 @@ export default class InstallationIntegrityChecker {
integrityMatches: integrityMatches === 'OK',
integrityError: integrityMatches === 'OK' ? undefined : integrityMatches,
missingPatterns,
hardRefreshRequired: integrityMatches === 'NODE_VERSION_DOESNT_MATCH',
};
}

Expand Down

0 comments on commit cbbcb53

Please sign in to comment.