From cf57d082c76c4f1fccc8e5ee9a02158386d03f03 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 22 Mar 2024 07:46:07 +0000 Subject: [PATCH] build: update ng-dev config to work with Node.js 18.19 Update ng-dev setup to work with 18.19 For more details, refer to: https://github.com/TypeStrong/ts-node/issues/2094 (cherry picked from commit a6129a6f5fd6d6e1c3ad30f7e754cfd1376a3dea) --- .ng-dev/{caretaker.mts => caretaker.mjs} | 10 +++--- ...{commit-message.mts => commit-message.mjs} | 9 +++--- .ng-dev/{config.mts => config.mjs} | 0 .ng-dev/{format.mts => format.mjs} | 6 ++-- .ng-dev/{github.mts => github.mjs} | 8 ++--- .../{pull-request.mts => pull-request.mjs} | 6 ++-- .ng-dev/{release.mts => release.mjs} | 22 ++++++------- .ng-dev/tsconfig.json | 5 ++- lib/packages.mjs | 32 +++++++++++++++++++ package.json | 4 +-- .../dependency-ranges/index.mts | 7 ++-- .../dependency-ranges/peer-deps-check.mts | 14 +++----- yarn.lock | 6 ++-- 13 files changed, 80 insertions(+), 49 deletions(-) rename .ng-dev/{caretaker.mts => caretaker.mjs} (65%) rename .ng-dev/{commit-message.mts => commit-message.mjs} (52%) rename .ng-dev/{config.mts => config.mjs} (100%) rename .ng-dev/{format.mts => format.mjs} (63%) rename .ng-dev/{github.mts => github.mjs} (58%) rename .ng-dev/{pull-request.mts => pull-request.mjs} (72%) rename .ng-dev/{release.mts => release.mjs} (65%) create mode 100644 lib/packages.mjs diff --git a/.ng-dev/caretaker.mts b/.ng-dev/caretaker.mjs similarity index 65% rename from .ng-dev/caretaker.mts rename to .ng-dev/caretaker.mjs index aeea38ccf355..5aba349b1e89 100644 --- a/.ng-dev/caretaker.mts +++ b/.ng-dev/caretaker.mjs @@ -1,7 +1,9 @@ -import { CaretakerConfig } from '@angular/ng-dev'; - -/** The configuration for `ng-dev caretaker` commands. */ -export const caretaker: CaretakerConfig = { +/** + * The configuration for `ng-dev caretaker` commands. + * + * @type { import("@angular/ng-dev").CaretakerConfig } + */ +export const caretaker = { githubQueries: [ { name: 'Merge Queue', diff --git a/.ng-dev/commit-message.mts b/.ng-dev/commit-message.mjs similarity index 52% rename from .ng-dev/commit-message.mts rename to .ng-dev/commit-message.mjs index 2dd960387eac..acf372245104 100644 --- a/.ng-dev/commit-message.mts +++ b/.ng-dev/commit-message.mjs @@ -1,13 +1,14 @@ -import { CommitMessageConfig } from '@angular/ng-dev'; -import packages from '../lib/packages.js'; +import { getReleasablePackages } from '../lib/packages.mjs'; /** * The configuration for `ng-dev commit-message` commands. + * + * @type { import("@angular/ng-dev").CommitMessageConfig } */ -export const commitMessage: CommitMessageConfig = { +export const commitMessage = { maxLineLength: Infinity, minBodyLength: 0, minBodyLengthTypeExcludes: ['docs'], // Note: When changing this logic, also change the `contributing.ejs` file. - scopes: [...Object.keys(packages.packages)], + scopes: getReleasablePackages().map(({ name }) => name), }; diff --git a/.ng-dev/config.mts b/.ng-dev/config.mjs similarity index 100% rename from .ng-dev/config.mts rename to .ng-dev/config.mjs diff --git a/.ng-dev/format.mts b/.ng-dev/format.mjs similarity index 63% rename from .ng-dev/format.mts rename to .ng-dev/format.mjs index 3cba8e9830a9..c14489066455 100644 --- a/.ng-dev/format.mts +++ b/.ng-dev/format.mjs @@ -1,9 +1,9 @@ -import { FormatConfig } from '@angular/ng-dev'; - /** * Configuration for the `ng-dev format` command. + * + * @type { import("@angular/ng-dev").FormatConfig } */ -export const format: FormatConfig = { +export const format = { 'prettier': { matchers: ['**/*.{ts,js,json,yml,yaml,md}'], }, diff --git a/.ng-dev/github.mts b/.ng-dev/github.mjs similarity index 58% rename from .ng-dev/github.mts rename to .ng-dev/github.mjs index 408c672bb8a4..22b092df2f10 100644 --- a/.ng-dev/github.mts +++ b/.ng-dev/github.mjs @@ -1,10 +1,10 @@ -import { GithubConfig } from '@angular/ng-dev'; - /** * Github configuration for the ng-dev command. This repository is - * uses as remote for the merge script. + * used as remote for the merge script. + * + * @type { import("@angular/ng-dev").GithubConfig } */ -export const github: GithubConfig = { +export const github = { owner: 'angular', name: 'angular-cli', mainBranchName: 'main', diff --git a/.ng-dev/pull-request.mts b/.ng-dev/pull-request.mjs similarity index 72% rename from .ng-dev/pull-request.mts rename to .ng-dev/pull-request.mjs index 1bf246fdcdce..ba49c73703e3 100644 --- a/.ng-dev/pull-request.mts +++ b/.ng-dev/pull-request.mjs @@ -1,10 +1,10 @@ -import { PullRequestConfig } from '@angular/ng-dev'; - /** * Configuration for the merge tool in `ng-dev`. This sets up the labels which * are respected by the merge script (e.g. the target labels). + * + * @type { import("@angular/ng-dev").PullRequestConfig } */ -export const pullRequest: PullRequestConfig = { +export const pullRequest = { githubApiMerge: { default: 'rebase', labels: [{ pattern: 'merge: squash commits', method: 'squash' }], diff --git a/.ng-dev/release.mts b/.ng-dev/release.mjs similarity index 65% rename from .ng-dev/release.mts rename to .ng-dev/release.mjs index 3bea8ad359c2..4871f71aac31 100644 --- a/.ng-dev/release.mts +++ b/.ng-dev/release.mjs @@ -1,29 +1,29 @@ import semver from 'semver'; -import { ReleaseConfig } from '@angular/ng-dev'; -import packages from '../lib/packages.js'; +import { getReleasablePackages } from '../lib/packages.mjs'; -const npmPackages = Object.entries(packages.releasePackages).map(([name, { experimental }]) => ({ - name, - experimental, -})); +const packages = getReleasablePackages(); -/** Configuration for the `ng-dev release` command. */ -export const release: ReleaseConfig = { +/** + * Configuration for the `ng-dev release` command. + * + * @type { import("@angular/ng-dev").ReleaseConfig } + */ +export const release = { representativeNpmPackage: '@angular/cli', - npmPackages, + npmPackages: packages.map(({ name, experimental }) => ({ name, experimental })), buildPackages: async () => { // The `performNpmReleaseBuild` function is loaded at runtime to avoid loading additional // files and dependencies unless a build is required. const { performNpmReleaseBuild } = await import('../scripts/build-packages-dist.mjs'); return performNpmReleaseBuild(); }, - prereleaseCheck: async (newVersionStr: string) => { + prereleaseCheck: async (newVersionStr) => { const newVersion = new semver.SemVer(newVersionStr); const { assertValidDependencyRanges } = await import( '../scripts/release-checks/dependency-ranges/index.mjs' ); - await assertValidDependencyRanges(newVersion, packages.releasePackages); + await assertValidDependencyRanges(newVersion, packages); }, releaseNotes: { groupOrder: [ diff --git a/.ng-dev/tsconfig.json b/.ng-dev/tsconfig.json index 2a26627bc905..9f0a0f84be18 100644 --- a/.ng-dev/tsconfig.json +++ b/.ng-dev/tsconfig.json @@ -1,11 +1,14 @@ { "extends": "../tsconfig.json", "compilerOptions": { + "resolveJsonModule": true, + "allowJs": true, "module": "Node16", "moduleResolution": "Node16", + "checkJs": true, "noEmit": true, "types": [] }, - "include": ["**/*.mts"], + "include": ["**/*.mjs"], "exclude": [] } diff --git a/lib/packages.mjs b/lib/packages.mjs new file mode 100644 index 000000000000..defd9c4dbec6 --- /dev/null +++ b/lib/packages.mjs @@ -0,0 +1,32 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import fastGlob from 'fast-glob'; +import { readFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; + +const require = createRequire(import.meta.url); +const monorepoData = require('../.monorepo.json'); + +export function getReleasablePackages() { + const packages = []; + for (const pkg of fastGlob.sync('./packages/*/*/package.json')) { + const data = JSON.parse(readFileSync(pkg, 'utf-8')); + if (!(data.name in monorepoData.packages)) { + throw new Error(`${data.name} does not exist in .monorepo.json`); + } + + if (data.private) { + continue; + } + + packages.push(data); + } + + return packages; +} diff --git a/package.json b/package.json index 0ff91f4bf86c..a3d95d874220 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,13 @@ "build:bazel": "node ./bin/devkit-admin build-bazel", "build-tsc": "tsc -p tsconfig.json", "lint": "eslint --cache --max-warnings=0 \"**/*.ts\"", - "ng-dev": "ts-node --esm --project .ng-dev/tsconfig.json --transpile-only node_modules/@angular/ng-dev/bundles/cli.mjs", "templates": "node ./bin/devkit-admin templates", "validate": "node ./bin/devkit-admin validate", "postinstall": "yarn webdriver-update && yarn husky install", "//webdriver-update-README": "ChromeDriver version must match Puppeteer Chromium version, see https://github.com/GoogleChrome/puppeteer/releases http://chromedriver.chromium.org/downloads", "webdriver-update": "webdriver-manager update --standalone false --gecko false --versions.chrome 106.0.5249.21", "public-api:check": "node goldens/public-api/manage.js test", + "ng-dev": "node --no-warnings=ExperimentalWarning --loader ts-node/esm/transpile-only node_modules/@angular/ng-dev/bundles/cli.mjs", "public-api:update": "node goldens/public-api/manage.js accept", "ts-circular-deps:check": "yarn -s ng-dev ts-circular-deps check --config ./packages/circular-deps-test.conf.js", "ts-circular-deps:approve": "yarn -s ng-dev ts-circular-deps approve --config ./packages/circular-deps-test.conf.js", @@ -75,7 +75,7 @@ "@angular/forms": "15.2.0-rc.0", "@angular/localize": "15.2.0-rc.0", "@angular/material": "15.1.4", - "@angular/ng-dev": "https://github.com/angular/dev-infra-private-ng-dev-builds.git#fa4d4694084d46886ca28fd09768a7df69b5b84d", + "@angular/ng-dev": "https://github.com/angular/dev-infra-private-ng-dev-builds.git#262c6ede0815bb2ba6fbe6f1790eaaa77ce84c9c", "@angular/platform-browser": "15.2.0-rc.0", "@angular/platform-browser-dynamic": "15.2.0-rc.0", "@angular/platform-server": "15.2.0-rc.0", diff --git a/scripts/release-checks/dependency-ranges/index.mts b/scripts/release-checks/dependency-ranges/index.mts index 764f2c9bfbb4..b9dfbc98e186 100644 --- a/scripts/release-checks/dependency-ranges/index.mts +++ b/scripts/release-checks/dependency-ranges/index.mts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ +import { Log, ReleasePrecheckError, bold } from '@angular/ng-dev'; import semver from 'semver'; -import { Log, bold, ReleasePrecheckError } from '@angular/ng-dev'; -import { checkPeerDependencies } from './peer-deps-check.mjs'; import { checkSchematicsAngularLatestVersion } from './latest-versions-check.mjs'; -import { PackageMap } from '../../../lib/packages.js'; +import { PackageJson, checkPeerDependencies } from './peer-deps-check.mjs'; /** Environment variable that can be used to skip this pre-check. */ const skipEnvVar = 'SKIP_DEPENDENCY_RANGE_PRECHECK'; @@ -26,7 +25,7 @@ const skipEnvVar = 'SKIP_DEPENDENCY_RANGE_PRECHECK'; */ export async function assertValidDependencyRanges( newVersion: semver.SemVer, - allPackages: PackageMap, + allPackages: PackageJson[], ) { if (process.env[skipEnvVar] === '1') { return; diff --git a/scripts/release-checks/dependency-ranges/peer-deps-check.mts b/scripts/release-checks/dependency-ranges/peer-deps-check.mts index 088c63118d65..005af8404150 100644 --- a/scripts/release-checks/dependency-ranges/peer-deps-check.mts +++ b/scripts/release-checks/dependency-ranges/peer-deps-check.mts @@ -6,26 +6,20 @@ * found in the LICENSE file at https://angular.io/license */ -import path from 'path'; -import url from 'url'; import semver from 'semver'; -import { PackageMap } from '../../../lib/packages.js'; /** Path to the current directory. */ -const currentDir = path.dirname(url.fileURLToPath(import.meta.url)); -/** Path to the project directory. */ -const projectDir = path.join(currentDir, '../../../'); /** Describes a parsed `package.json` file. */ -interface PackageJson { +export interface PackageJson { name?: string; peerDependencies?: Record; } export async function checkPeerDependencies( newVersion: semver.SemVer, - allPackages: PackageMap, + allPackages: PackageJson[], ): Promise { const { major, minor } = newVersion; const isPrerelease = !!newVersion.prerelease[0]; @@ -39,8 +33,8 @@ export async function checkPeerDependencies( } const failures: string[] = []; - for (const pkgInfo of Object.values(allPackages)) { - failures.push(...checkPackage(pkgInfo.packageJson, expectedFwPeerDep)); + for (const pkgInfo of allPackages) { + failures.push(...checkPackage(pkgInfo, expectedFwPeerDep)); } return failures; diff --git a/yarn.lock b/yarn.lock index ca5789231a63..75fa2ef9a5d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -304,9 +304,9 @@ "@material/typography" "15.0.0-canary.684e33d25.0" tslib "^2.3.0" -"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#fa4d4694084d46886ca28fd09768a7df69b5b84d": - version "0.0.0-98bdad2a2ff3cd66c78048a3d2f48d50389c494a" - resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#fa4d4694084d46886ca28fd09768a7df69b5b84d" +"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#262c6ede0815bb2ba6fbe6f1790eaaa77ce84c9c": + version "0.0.0-96a8277d21eb61a2370061717ffa8dee5668caa0" + resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#262c6ede0815bb2ba6fbe6f1790eaaa77ce84c9c" dependencies: "@yarnpkg/lockfile" "^1.1.0" typescript "~4.9.0"