|
12 | 12 | import fs from 'fs'; |
13 | 13 | import path from 'path'; |
14 | 14 |
|
| 15 | +const getMinEslintVersion = () => { |
| 16 | + const packageJson = JSON.parse( |
| 17 | + fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'), |
| 18 | + ) as {version: string}; |
| 19 | + const isV5Package = Number(packageJson.version.split('.')[0]) >= 5; |
| 20 | + |
| 21 | + try { |
| 22 | + const {NoReactInternals} = require('remotion/no-react') as { |
| 23 | + NoReactInternals: { |
| 24 | + ENABLE_V5_BREAKING_CHANGES: boolean; |
| 25 | + MIN_ESLINT_VERSION: string; |
| 26 | + }; |
| 27 | + }; |
| 28 | + if (NoReactInternals.ENABLE_V5_BREAKING_CHANGES) { |
| 29 | + return NoReactInternals.MIN_ESLINT_VERSION; |
| 30 | + } |
| 31 | + } catch { |
| 32 | + // @remotion/eslint-config can be installed without remotion. |
| 33 | + } |
| 34 | + |
| 35 | + return isV5Package ? '8.57.0' : null; |
| 36 | +}; |
| 37 | + |
15 | 38 | export const allowESLintShareableConfig = () => { |
16 | 39 | const isModuleResolutionError: (ex: unknown) => boolean = (ex) => |
17 | 40 | typeof ex === 'object' && |
@@ -228,12 +251,29 @@ export const allowESLintShareableConfig = () => { |
228 | 251 | .toString(); |
229 | 252 | const eslintPackageObject = JSON.parse(eslintPackageJson); |
230 | 253 | const eslintPackageVersion = eslintPackageObject.version; |
231 | | - const versionMatch = /^([0-9]+)\./.exec(eslintPackageVersion); // parse the SemVer MAJOR part |
| 254 | + const versionMatch = /^([0-9]+)\.([0-9]+)\./.exec(eslintPackageVersion); |
232 | 255 | if (!versionMatch) { |
233 | 256 | throw new Error('Unable to parse ESLint version: ' + eslintPackageVersion); |
234 | 257 | } |
235 | 258 |
|
236 | 259 | const eslintMajorVersion = Number(versionMatch[1]); |
| 260 | + const eslintMinorVersion = Number(versionMatch[2]); |
| 261 | + const minEslintVersion = getMinEslintVersion(); |
| 262 | + if (minEslintVersion !== null) { |
| 263 | + const minVersionMatch = /^([0-9]+)\.([0-9]+)\./.exec(minEslintVersion)!; |
| 264 | + const minMajorVersion = Number(minVersionMatch[1]); |
| 265 | + const minMinorVersion = Number(minVersionMatch[2]); |
| 266 | + if ( |
| 267 | + eslintMajorVersion < minMajorVersion || |
| 268 | + (eslintMajorVersion === minMajorVersion && |
| 269 | + eslintMinorVersion < minMinorVersion) |
| 270 | + ) { |
| 271 | + throw new Error( |
| 272 | + `Remotion 5 requires ESLint ${minEslintVersion} or later. You currently have ESLint ${eslintPackageVersion}.`, |
| 273 | + ); |
| 274 | + } |
| 275 | + } |
| 276 | + |
237 | 277 | if (!(eslintMajorVersion >= 6 && eslintMajorVersion <= 9)) { |
238 | 278 | throw new Error( |
239 | 279 | 'The patch-eslint.js script has only been tested with ESLint version 6.x, 7.x, and 8.x, and 9.x.' + |
|
0 commit comments