|
1 | 1 | const path = require('path'); |
2 | 2 | const fs = require('fs'); |
| 3 | +const cp = require('child_process'); |
| 4 | +const semver = require('semver'); |
3 | 5 |
|
4 | 6 | function main() { |
5 | 7 | const changedFiles = readChangedFilesFile(process.argv[2]); |
@@ -39,7 +41,7 @@ function displayList(header, list) { |
39 | 41 | } |
40 | 42 |
|
41 | 43 | function readChangedFilesFile(changedFilesFileName) { |
42 | | - return fs.readFileSync(path.join(__dirname, '..', '..', '..', changedFilesFileName), 'utf-8').split('\n').map(s => s.trim()); |
| 44 | + return fs.readFileSync(changedFilesFileName, 'utf-8').split('\n').map(s => s.trim()); |
43 | 45 | } |
44 | 46 |
|
45 | 47 | function identifyMeaningfullyChangedPackages(changedFiles) { |
@@ -74,18 +76,31 @@ function isFileInTestFolder(changedFile) { |
74 | 76 | function identifyIncorrectlyVersionedPackages(changedPackages) { |
75 | 77 | const incorrectlyVersionedPackages = []; |
76 | 78 | for (const changedPackage of changedPackages) { |
77 | | - //A temporary workaround for the rename of the flowtest-engine package to flow-engine |
78 | | - if (changedPackage === 'packages/code-analyzer-flowtest-engine') { |
79 | | - continue; |
80 | | - } |
81 | 79 | const packageVersion = getPackageVersion(changedPackage); |
82 | 80 | if (!packageVersion.endsWith('-SNAPSHOT')) { |
83 | 81 | incorrectlyVersionedPackages.push(`${changedPackage} (currently versioned as ${packageVersion}) lacks a trailing "-SNAPSHOT"`); |
| 82 | + continue; |
| 83 | + } |
| 84 | + const releasedPackageVersion = getLatestReleasedVersion(changedPackage); |
| 85 | + if (semver.lte(semver.parse(packageVersion.slice(0, packageVersion.length - 9)), semver.parse(releasedPackageVersion))) { |
| 86 | + incorrectlyVersionedPackages.push(`${changedPackage} (currently versioned as ${packageVersion}) is not semantically ahead of latest published release ${releasedPackageVersion}`); |
84 | 87 | } |
85 | 88 | } |
86 | 89 | return incorrectlyVersionedPackages; |
87 | 90 | } |
88 | 91 |
|
| 92 | +function getLatestReleasedVersion(changedPackage) { |
| 93 | + const publishedPackageName = JSON.parse(fs.readFileSync(path.join(changedPackage, 'package.json'), 'utf-8')).name; |
| 94 | + try { |
| 95 | + |
| 96 | + return cp.execSync(`npm view ${publishedPackageName} version`, { |
| 97 | + encoding: 'utf-8' |
| 98 | + }); |
| 99 | + } catch (e) { |
| 100 | + console.log(`NOTE: Could not fetch latest release version of ${publishedPackageName} (located in ${changedPackage}). Is that an error?`); |
| 101 | + return undefined; |
| 102 | + } |
| 103 | +} |
89 | 104 |
|
90 | 105 | function getPackageVersion(changedPackage) { |
91 | 106 | const packageJsonPath = path.join(changedPackage, 'package.json'); |
|
0 commit comments