|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import fs from 'fs'; |
| 10 | +import path from 'path'; |
| 11 | +import url from 'url'; |
| 12 | +import semver from 'semver'; |
| 13 | + |
| 14 | +/** Custom stamping on top of the default `ng-dev` release stamping. */ |
| 15 | +export default async function (mode) { |
| 16 | + const scriptDir = path.dirname(url.fileURLToPath(import.meta.url)); |
| 17 | + const projectDir = path.join(scriptDir, '../'); |
| 18 | + const packageJsonRaw = await fs.promises.readFile(path.join(projectDir, 'package.json')); |
| 19 | + const {version: versionRaw} = JSON.parse(packageJsonRaw); |
| 20 | + const version = semver.parse(versionRaw); |
| 21 | + |
| 22 | + console.info(`STABLE_FRAMEWORK_PEER_DEP_RANGE ${computeFrameworkPeerDependency(version)}`); |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | + * Computes the Angular peer dependency range. The following rules apply: |
| 27 | + * |
| 28 | + * `N.x.x` requires Angular `^N.0.0 || ^(N+1).0.0` |
| 29 | + * `N.x.x-x` requires Angular `^N.0.0-0 || ^N.1.0-0 || ^N.2.0-0 || ^N.3.0-0 || ^(N+1).0.0-0` |
| 30 | + * |
| 31 | + * The rationale is that we want to satisfy peer dependencies if we are publishing |
| 32 | + * pre-releases for a major while Angular framework cuts pre-releases as well. e.g. |
| 33 | + * Angular CDK v14.0.0-rc.1 should also work with `@angular/[email protected]`. |
| 34 | + * |
| 35 | + * Note: When we cut pre-releases, the peer dependency includes all anticipated |
| 36 | + * pre-releases because a range like `^15.0.0-0` itself would not allow for future minor |
| 37 | + * releases like `15.1.0-next.0`. NPM requires the explicit minors pre-release ranges. |
| 38 | + * |
| 39 | + * @param {semver.SemVer} version Current project version. |
| 40 | + * @returns {string} The NPM peer dependency for depending on framework. |
| 41 | + */ |
| 42 | +function computeFrameworkPeerDependency(version) { |
| 43 | + if (version.prerelease[0] !== undefined) { |
| 44 | + return ( |
| 45 | + `^${version.major}.0.0-0 || ` + |
| 46 | + `^${version.major}.1.0-0 || ` + |
| 47 | + `^${version.major}.2.0-0 || ` + |
| 48 | + `^${version.major}.3.0-0 || ` + |
| 49 | + `^${version.major + 1}.0.0-0` |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + return `^${version.major}.0.0 || ^${version.major + 1}.0.0`; |
| 54 | +} |
0 commit comments