diff options
| author | Shipwreckt <me@shipwreckt.co.uk> | 2025-10-31 20:02:14 +0000 |
|---|---|---|
| committer | Shipwreckt <me@shipwreckt.co.uk> | 2025-10-31 20:02:14 +0000 |
| commit | 7a52ddeba2a68388b544f529d2d92104420f77b0 (patch) | |
| tree | 15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/@11ty/eleventy/src/Util/Compatibility.js | |
| parent | 53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff) | |
Changed from static to 11ty!
Diffstat (limited to 'node_modules/@11ty/eleventy/src/Util/Compatibility.js')
| -rw-r--r-- | node_modules/@11ty/eleventy/src/Util/Compatibility.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/node_modules/@11ty/eleventy/src/Util/Compatibility.js b/node_modules/@11ty/eleventy/src/Util/Compatibility.js new file mode 100644 index 0000000..c90a9b3 --- /dev/null +++ b/node_modules/@11ty/eleventy/src/Util/Compatibility.js @@ -0,0 +1,59 @@ +import semver from "semver"; + +import { getEleventyPackageJson, getWorkingProjectPackageJson } from "./ImportJsonSync.js"; + +const pkg = getEleventyPackageJson(); + +// Used in user config versionCheck method. +class Compatibility { + static NORMALIZE_PRERELEASE_REGEX = /-canary\b/g; + + static #projectPackageJson; + + constructor(compatibleRange) { + this.compatibleRange = Compatibility.getCompatibilityValue(compatibleRange); + } + + static get projectPackageJson() { + if (!this.#projectPackageJson) { + this.#projectPackageJson = getWorkingProjectPackageJson(); + } + + return this.#projectPackageJson; + } + + static normalizeIdentifier(identifier) { + return identifier.replace(Compatibility.NORMALIZE_PRERELEASE_REGEX, "-alpha"); + } + + static getCompatibilityValue(compatibleRange) { + if (compatibleRange) { + return compatibleRange; + } + + // fetch from project’s package.json + if (this.projectPackageJson?.["11ty"]?.compatibility) { + return this.projectPackageJson["11ty"].compatibility; + } + } + + isCompatible() { + return Compatibility.satisfies(pkg.version, this.compatibleRange); + } + + static satisfies(version, compatibleRange) { + return semver.satisfies( + Compatibility.normalizeIdentifier(version), + Compatibility.normalizeIdentifier(compatibleRange), + { + includePrerelease: true, + }, + ); + } + + getErrorMessage() { + return `We found Eleventy version '${pkg.version}' which does not meet the required version range: '${this.compatibleRange}'. Use \`npm install @11ty/eleventy\` to upgrade your local project to the latest Eleventy version (or \`npm install @11ty/eleventy -g\` to upgrade the globally installed version).`; + } +} + +export default Compatibility; |
