Skip to content

Commit 3362b8f

Browse files
committed
build: clean up build scripts
Several cleanups to build scripts
1 parent 2fb4b24 commit 3362b8f

22 files changed

+126
-401
lines changed

.ng-dev/commit-message.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getReleasablePackages } from '../lib/packages.mjs';
1+
import { packages } from '../lib/packages.mjs';
22

33
/**
44
* The configuration for `ng-dev commit-message` commands.
@@ -10,5 +10,5 @@ export const commitMessage = {
1010
minBodyLength: 0,
1111
minBodyLengthTypeExcludes: ['docs'],
1212
// Note: When changing this logic, also change the `contributing.ejs` file.
13-
scopes: getReleasablePackages().map(({ name }) => name),
13+
scopes: packages.map(({ name }) => name),
1414
};

.ng-dev/release.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import semver from 'semver';
2-
import { getReleasablePackages } from '../lib/packages.mjs';
3-
4-
const packages = getReleasablePackages();
2+
import { releasePackages } from '../lib/packages.mjs';
53

64
/**
75
* Configuration for the `ng-dev release` command.
@@ -10,7 +8,7 @@ const packages = getReleasablePackages();
108
*/
119
export const release = {
1210
representativeNpmPackage: '@angular/cli',
13-
npmPackages: packages.map(({ name, experimental }) => ({ name, experimental })),
11+
npmPackages: releasePackages.map(({ name, experimental }) => ({ name, experimental })),
1412
buildPackages: async () => {
1513
// The `performNpmReleaseBuild` function is loaded at runtime to avoid loading additional
1614
// files and dependencies unless a build is required.
@@ -23,7 +21,7 @@ export const release = {
2321
'../scripts/release-checks/dependency-ranges/index.mjs'
2422
);
2523

26-
await assertValidDependencyRanges(newVersion, packages);
24+
await assertValidDependencyRanges(newVersion, releasePackages);
2725
},
2826
releaseNotes: {
2927
groupOrder: [

bin/README.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

bin/architect

Lines changed: 0 additions & 15 deletions
This file was deleted.

bin/ng

Lines changed: 0 additions & 15 deletions
This file was deleted.

bin/schematics

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/bootstrap-local.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ require.extensions['.ejs'] = function (m, filename) {
8282
};
8383

8484
const builtinModules = Object.keys(process.binding('natives'));
85-
const packages = require('./packages').packages;
85+
const { packages } = require('./packages');
8686
// If we're running locally, meaning npm linked. This is basically "developer mode".
8787
if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
8888
// We mock the module loader so that we can fake our packages when running locally.
@@ -98,17 +98,24 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
9898
exception = e;
9999
}
100100

101-
if (request in packages) {
102-
return packages[request].main;
103-
} else if (builtinModules.includes(request)) {
101+
if (request[0] === '@') {
102+
const pkg = packages.find(({ name }) => name === request);
103+
const main = pkg?.packageJson?.main.replace(/\.js$/, '.ts');
104+
if (main) {
105+
return path.join(pkg.root, main);
106+
}
107+
}
108+
109+
if (builtinModules.includes(request)) {
104110
// It's a native Node module.
105111
return oldResolve.call(this, request, parent);
106-
} else if (resolved && resolved.match(/[\\\/]node_modules[\\\/]/)) {
112+
} else if (resolved && resolved.match(/[\\/]node_modules[\\/]/)) {
107113
return resolved;
108114
} else {
109-
const match = Object.keys(packages).find((pkgName) => request.startsWith(pkgName + '/'));
115+
const match = packages.find(({ name }) => request.startsWith(name + '/'));
110116
if (match) {
111-
const p = path.join(packages[match].root, request.slice(match.length));
117+
const p = path.join(match.root, request.slice(match.name.length));
118+
112119
return oldResolve.call(this, p, parent);
113120
} else if (!resolved) {
114121
if (exception) {

lib/packages.mjs

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/packages.mts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 fastGlob from 'fast-glob';
10+
import { readFileSync } from 'node:fs';
11+
import { dirname } from 'node:path';
12+
13+
// NB: This is a copy of packages.ts
14+
15+
export interface PackageInfo {
16+
name: string;
17+
root: string;
18+
experimental: boolean;
19+
packageJson: Record<string, boolean | number | string | object>;
20+
}
21+
22+
function getPackages(): PackageInfo[] {
23+
const packages: PackageInfo[] = [];
24+
const monorepoData = JSON.parse(readFileSync('./.monorepo.json', 'utf-8'));
25+
26+
for (const pkg of fastGlob.sync('./packages/*/*/package.json', { absolute: true })) {
27+
const packageJson = JSON.parse(readFileSync(pkg, 'utf-8'));
28+
29+
if (!(packageJson.name in monorepoData.packages)) {
30+
throw new Error(`${packageJson.name} does not exist in .monorepo.json`);
31+
}
32+
33+
packages.push({
34+
name: packageJson.name,
35+
experimental: !!packageJson.experimental,
36+
root: dirname(pkg),
37+
packageJson,
38+
});
39+
}
40+
41+
return packages;
42+
}
43+
44+
export const packages = getPackages();
45+
export const releasePackages = packages.filter(({ packageJson }) => !packageJson.private);

0 commit comments

Comments
 (0)