|
| 1 | +#!/usr/bin/env node |
| 2 | +/* eslint-disable no-process-exit, no-console, import/no-commonjs */ |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | + |
| 6 | +// This file does not use any dependencies, so that it can be ran before installing |
| 7 | + |
| 8 | +// It checks whether the versions of packages that should be versioned synchronously |
| 9 | +// are actually in sync. We need this as long as Lerna doesn't have a mixed mode. |
| 10 | +// see: https://github.com/lerna/lerna/issues/1159 |
| 11 | + |
| 12 | +let hasError = false; |
| 13 | +const expectedVersion = require('../../lerna.json').version; |
| 14 | +const packages = fs.readdirSync(path.join(__dirname, '../../packages')); |
| 15 | + |
| 16 | +const results = packages.map((package) => { |
| 17 | + const version = require(path.join( |
| 18 | + __dirname, |
| 19 | + `../../packages/${package}/package.json` |
| 20 | + )).version; |
| 21 | + return { isValid: version === expectedVersion, package, version }; |
| 22 | +}); |
| 23 | + |
| 24 | +if (results.some(({ isValid }) => !isValid)) { |
| 25 | + console.error( |
| 26 | + [ |
| 27 | + 'Package version mismatch detected!', |
| 28 | + `- Expected: ${expectedVersion}`, |
| 29 | + '- Received:', |
| 30 | + ].join('\n') |
| 31 | + ); |
| 32 | + console.error(results.filter(({ isValid }) => !isValid)); |
| 33 | + hasError = true; |
| 34 | +} else { |
| 35 | + console.log('Package versions are in sync.'); |
| 36 | +} |
| 37 | + |
| 38 | +console.log(''); |
| 39 | + |
| 40 | +const sharedVersion = fs.readFileSync( |
| 41 | + path.join(__dirname, '../../packages/autocomplete-shared/src/version.ts'), |
| 42 | + { encoding: 'utf-8' } |
| 43 | +); |
| 44 | + |
| 45 | +if (sharedVersion !== `export const version = '${expectedVersion}';\n`) { |
| 46 | + console.error( |
| 47 | + [ |
| 48 | + 'Shared version mismatch detected!', |
| 49 | + `- Expected: ${expectedVersion}`, |
| 50 | + `- Received: ${sharedVersion}`, |
| 51 | + ].join('\n') |
| 52 | + ); |
| 53 | + hasError = true; |
| 54 | +} else { |
| 55 | + console.log('Shared version file is in sync.'); |
| 56 | +} |
| 57 | + |
| 58 | +if (hasError) { |
| 59 | + process.exit(1); |
| 60 | +} |
0 commit comments