Skip to content

Commit 4114de4

Browse files
committed
Fix regression for entirely missing package
1 parent 4a6e487 commit 4114de4

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

common/scripts/InstallRushOnlyIfNeeded.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,23 @@ if (fs.existsSync(npmrcPath)) {
8383

8484
// Check for the Rush version
8585
let installedVersion = undefined;
86+
let installedVersionValid = false
8687
console.log(os.EOL + `Expected Rush version is ${expectedVersion}`);
8788

8889
try {
8990
const spawnResult = child_process.spawnSync(npmPath, ['list', packageName, 'version'],
9091
{ cwd: rushPath, stdio: ['pipe', 'pipe', 'pipe'] });
92+
const output = spawnResult.output.toString();
9193
const matches = /@microsoft\/rush\@([0-9a-zA-Z.+\-]+)/.exec(spawnResult.output);
92-
if (matches && matches.length === 2) {
94+
// If NPM finds the wrong version in node_modules, that version will be in matches[1].
95+
// But if it's not installed at all, then NPM instead uselessly tells us all about
96+
// the version that we DON'T have ("missing:")
97+
if (matches && matches.length === 2 && !output.match(/missing\:/g)) {
9398
installedVersion = matches[1];
99+
100+
if (spawnResult.status === 0) {
101+
installedVersionValid = true
102+
}
94103
}
95104
}
96105
catch (error) {
@@ -103,7 +112,7 @@ if (installedVersion) {
103112
console.log(os.EOL + 'Rush does not appear to be installed');
104113
}
105114

106-
if (installedVersion !== expectedVersion) {
115+
if (!installedVersionValid || installedVersion !== expectedVersion) {
107116
console.log(os.EOL + 'Installing Rush...');
108117
child_process.execSync(`"${npmPath}" install ${packageName}@${expectedVersion}`, { cwd: rushPath });
109118
console.log(os.EOL + `Successfully installed Rush ${expectedVersion}`);

0 commit comments

Comments
 (0)