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

(cherry picked from commit a6129a6)
  • Loading branch information
alan-agius4 committed Mar 15, 2024
1 parent 79c44ad commit cf17331
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .ng-dev/commit-message.mjs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 package.json
Original file line number Diff line number Diff line change
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 Down
15 changes: 9 additions & 6 deletions packages/angular/cli/src/commands/command-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ export const RootCommands: Record<
},
};

export const RootCommandsAliases = Object.values(RootCommands).reduce((prev, current) => {
current.aliases?.forEach((alias) => {
prev[alias] = current;
});
export const RootCommandsAliases = Object.values(RootCommands).reduce(
(prev, current) => {
current.aliases?.forEach((alias) => {
prev[alias] = current;
});

return prev;
}, {} as Record<string, CommandConfig>);
return prev;
},
{} as Record<string, CommandConfig>,
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { NodePackageName, NodePackageTaskOptions } from './options';
export class NodePackageLinkTask implements TaskConfigurationGenerator<NodePackageTaskOptions> {
quiet = true;

constructor(public packageName?: string, public workingDirectory?: string) {}
constructor(
public packageName?: string,
public workingDirectory?: string,
) {}

toConfiguration(): TaskConfiguration<NodePackageTaskOptions> {
return {
Expand Down
7 changes: 3 additions & 4 deletions scripts/release-checks/dependency-ranges/index.mts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 cf17331

Please sign in to comment.