Skip to content

Commit

Permalink
build: update ng-dev config to work with Node.js 18.19
Browse files Browse the repository at this point in the history
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094
  • Loading branch information
alan-agius4 committed Mar 12, 2024
1 parent 51debcd commit bb08763
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .ng-dev/commit-message.mjs
@@ -1,14 +1,14 @@
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 = {
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),
};
15 changes: 6 additions & 9 deletions .ng-dev/release.mjs
@@ -1,19 +1,16 @@
import semver from 'semver';
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.
*
*
* @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.
Expand All @@ -26,7 +23,7 @@ export const release = {
'../scripts/release-checks/dependency-ranges/index.mjs'
);

await assertValidDependencyRanges(newVersion, packages.releasePackages);
await assertValidDependencyRanges(newVersion, packages);
},
releaseNotes: {
groupOrder: [
Expand Down
2 changes: 2 additions & 0 deletions .ng-dev/tsconfig.json
@@ -1,9 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"allowJs": true,
"module": "Node16",
"moduleResolution": "Node16",
"checkJs": true,
"noEmit": true,
"types": []
},
Expand Down
32 changes: 32 additions & 0 deletions 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;
}
2 changes: 1 addition & 1 deletion lib/packages.ts
Expand Up @@ -85,7 +85,7 @@ function loadPackageJson(p: string) {
// Overwrite engines to a common default.
case 'engines':
pkg['engines'] = {
'node': '^16.14.0 || >=18.10.0',
'node': '^18.19.1 || ^20.11.1',
'npm': '^6.11.0 || ^7.5.6 || >=8.0.0',
'yarn': '>= 1.13.0',
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -22,13 +22,13 @@
"build": "node ./bin/devkit-admin build",
"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 && patch-package --patch-dir tools/postinstall/patches",
"//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",
Expand All @@ -39,7 +39,7 @@
"url": "https://github.com/angular/angular-cli.git"
},
"engines": {
"node": "^18.13.0 || ^20.9.0",
"node": "^18.19.1 || ^20.11.1",
"yarn": ">=1.21.1 <2",
"npm": "Please use yarn instead of NPM to install dependencies"
},
Expand Down
7 changes: 3 additions & 4 deletions scripts/release-checks/dependency-ranges/index.mts
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions scripts/release-checks/dependency-ranges/peer-deps-check.mts
Expand Up @@ -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<string, string>;
}

export async function checkPeerDependencies(
newVersion: semver.SemVer,
allPackages: PackageMap,
allPackages: PackageJson[],
): Promise<string[]> {
const { major, minor } = newVersion;
const isPrerelease = !!newVersion.prerelease[0];
Expand All @@ -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;
Expand Down

0 comments on commit bb08763

Please sign in to comment.