Skip to content

Commit

Permalink
build: clean up build scripts
Browse files Browse the repository at this point in the history
Several cleanups to build scripts
  • Loading branch information
alan-agius4 committed Mar 14, 2024
1 parent 2fb4b24 commit 3362b8f
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 401 deletions.
4 changes: 2 additions & 2 deletions .ng-dev/commit-message.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getReleasablePackages } from '../lib/packages.mjs';
import { packages } from '../lib/packages.mjs';

/**
* The configuration for `ng-dev commit-message` commands.
Expand All @@ -10,5 +10,5 @@ export const commitMessage = {
minBodyLength: 0,
minBodyLengthTypeExcludes: ['docs'],
// Note: When changing this logic, also change the `contributing.ejs` file.
scopes: getReleasablePackages().map(({ name }) => name),
scopes: packages.map(({ name }) => name),
};
8 changes: 3 additions & 5 deletions .ng-dev/release.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import semver from 'semver';
import { getReleasablePackages } from '../lib/packages.mjs';

const packages = getReleasablePackages();
import { releasePackages } from '../lib/packages.mjs';

/**
* Configuration for the `ng-dev release` command.
Expand All @@ -10,7 +8,7 @@ const packages = getReleasablePackages();
*/
export const release = {
representativeNpmPackage: '@angular/cli',
npmPackages: packages.map(({ name, experimental }) => ({ name, experimental })),
npmPackages: releasePackages.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 @@ -23,7 +21,7 @@ export const release = {
'../scripts/release-checks/dependency-ranges/index.mjs'
);

await assertValidDependencyRanges(newVersion, packages);
await assertValidDependencyRanges(newVersion, releasePackages);
},
releaseNotes: {
groupOrder: [
Expand Down
17 changes: 0 additions & 17 deletions bin/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions bin/architect

This file was deleted.

15 changes: 0 additions & 15 deletions bin/ng

This file was deleted.

15 changes: 0 additions & 15 deletions bin/schematics

This file was deleted.

11 changes: 0 additions & 11 deletions lib/README.md

This file was deleted.

21 changes: 14 additions & 7 deletions lib/bootstrap-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ require.extensions['.ejs'] = function (m, filename) {
};

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

if (request in packages) {
return packages[request].main;
} else if (builtinModules.includes(request)) {
if (request[0] === '@') {
const pkg = packages.find(({ name }) => name === request);
const main = pkg?.packageJson?.main.replace(/\.js$/, '.ts');
if (main) {
return path.join(pkg.root, main);
}
}

if (builtinModules.includes(request)) {
// It's a native Node module.
return oldResolve.call(this, request, parent);
} else if (resolved && resolved.match(/[\\\/]node_modules[\\\/]/)) {
} else if (resolved && resolved.match(/[\\/]node_modules[\\/]/)) {
return resolved;
} else {
const match = Object.keys(packages).find((pkgName) => request.startsWith(pkgName + '/'));
const match = packages.find(({ name }) => request.startsWith(name + '/'));
if (match) {
const p = path.join(packages[match].root, request.slice(match.length));
const p = path.join(match.root, request.slice(match.name.length));

return oldResolve.call(this, p, parent);
} else if (!resolved) {
if (exception) {
Expand Down
32 changes: 0 additions & 32 deletions lib/packages.mjs

This file was deleted.

45 changes: 45 additions & 0 deletions lib/packages.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @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 { dirname } from 'node:path';

// NB: This is a copy of packages.ts

export interface PackageInfo {
name: string;
root: string;
experimental: boolean;
packageJson: Record<string, boolean | number | string | object>;
}

function getPackages(): PackageInfo[] {
const packages: PackageInfo[] = [];
const monorepoData = JSON.parse(readFileSync('./.monorepo.json', 'utf-8'));

for (const pkg of fastGlob.sync('./packages/*/*/package.json', { absolute: true })) {
const packageJson = JSON.parse(readFileSync(pkg, 'utf-8'));

if (!(packageJson.name in monorepoData.packages)) {
throw new Error(`${packageJson.name} does not exist in .monorepo.json`);
}

packages.push({
name: packageJson.name,
experimental: !!packageJson.experimental,
root: dirname(pkg),
packageJson,
});
}

return packages;
}

export const packages = getPackages();
export const releasePackages = packages.filter(({ packageJson }) => !packageJson.private);
Loading

0 comments on commit 3362b8f

Please sign in to comment.