Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ use_repo(rules_angular, rules_angular_configurable_deps = "dev_infra_rules_angul
pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")
pnpm.pnpm(
name = "pnpm",
pnpm_version = "10.16.1",
pnpm_version = "10.26.0",
pnpm_version_integrity = "sha512-Oz9scl6+cSUGwKsa1BM8+GsfS2h+/85iqbOLTXLjlUJC5kMZD8UfoWQpScc19APevUT1yw7dZXq+Y6i2p+HkAg==",
)
use_repo(pnpm, "pnpm")

Expand Down
8 changes: 4 additions & 4 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ng-dev/misc/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import {Argv} from 'yargs';

import {SyncModuleBazelModule} from './sync-module-bazel/cli.js';
import {BuildAndLinkCommandModule} from './build-and-link/cli.js';
import {GeneratedFilesModule} from './generated-files/cli.js';
import {GeneratedNodeJsToolchainModule} from './generate-nodejs-toolchain/cli.js';
Expand All @@ -16,6 +17,7 @@ export function buildMiscParser(localYargs: Argv) {
return localYargs
.help()
.strict()
.command(SyncModuleBazelModule)
.command(BuildAndLinkCommandModule)
.command(GeneratedFilesModule)
.command(GeneratedNodeJsToolchainModule);
Expand Down
120 changes: 120 additions & 0 deletions ng-dev/misc/sync-module-bazel/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @license
* Copyright Google LLC
*
* 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 {Argv, CommandModule} from 'yargs';
import {readFileSync, writeFileSync} from 'node:fs';
import {execSync} from 'node:child_process';
import {join} from 'node:path';
import {Log} from '../../utils/logging';

async function builder(argv: Argv) {
return argv;
}

async function handler() {
const rootDir = process.cwd();
const packageJsonPath = join(rootDir, 'package.json');
const moduleBazelPath = join(rootDir, 'MODULE.bazel');

interface PackageJson {
engines?: {
pnpm?: string;
};
dependencies?: {
typescript?: string;
};
devDependencies?: {
typescript?: string;
};
}

// Read package.json
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as PackageJson;
const pnpmVersion = packageJson.engines?.pnpm;
const tsVersion = packageJson.dependencies?.typescript || packageJson.devDependencies?.typescript;

if (!pnpmVersion) {
throw new Error('Could not find engines.pnpm in package.json');
}

if (!tsVersion) {
throw new Error('Could not find typescript in dependencies or devDependencies in package.json');
}

// Helper to get integrity
async function getIntegrity(pkg: string, version: string): Promise<string> {
const response = await fetch(`https://registry.npmjs.org/${pkg}/${version}`);
if (!response.ok) {
throw new Error(`Failed to request ${pkg}@${version}: ${response.statusText}`);
}

const {dist} = (await response.json()) as {dist: {integrity: string}};

return dist.integrity;
}

// Read MODULE.bazel
let originalBazelContent = readFileSync(moduleBazelPath, 'utf8');
let moduleBazelContent = originalBazelContent;

if (moduleBazelContent.includes('pnpm_version')) {
console.log(`Resolving integrity for pnpm@${pnpmVersion}...`);
const pnpmIntegrity = await getIntegrity('pnpm', pnpmVersion);

// Update pnpm version and integrity
moduleBazelContent = moduleBazelContent.replace(
/pnpm_version = ".*?"/,
`pnpm_version = "${pnpmVersion}"`,
);

if (moduleBazelContent.includes('pnpm_version_integrity =')) {
moduleBazelContent = moduleBazelContent.replace(
/pnpm_version_integrity = ".*?"/,
`pnpm_version_integrity = "${pnpmIntegrity}"`,
);
} else {
moduleBazelContent = moduleBazelContent.replace(
/pnpm_version = ".*?"/,
`$&,\n pnpm_version_integrity = "${pnpmIntegrity}"`,
);
}
}

// Update typescript version and integrity
if (moduleBazelContent.includes('ts_version')) {
console.log(`Resolving integrity for typescript@${tsVersion}...`);
const tsIntegrity = await getIntegrity('typescript', tsVersion);

moduleBazelContent = moduleBazelContent.replace(
/ts_version = ".*?"/,
`ts_version = "${tsVersion}"`,
);
moduleBazelContent = moduleBazelContent.replace(
/ts_integrity = ".*?"/,
`ts_integrity = "${tsIntegrity}"`,
);

if (originalBazelContent !== moduleBazelContent) {
writeFileSync(moduleBazelPath, moduleBazelContent);

try {
execSync('pnpm bazel mod deps --lockfile_mode=update', {stdio: 'inherit'});
} catch (e) {
Log.debug(e);
}
}
}
}

/** CLI command module. */
export const SyncModuleBazelModule: CommandModule = {
builder,
handler,
command: 'sync-module-bazel',
describe: 'Sync pnpm and typescript versions in MODULE.bazel with package.json.',
};
17 changes: 16 additions & 1 deletion renovate-presets/default.json5
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
// Workaround for https://github.com/renovatebot/renovate/issues/25557
{
postUpgradeTasks: {
matchManagers: ['bazel', 'bazel-module', 'bazelisk'],
commands: [
'git restore .npmrc || true', // In case `.npmrc` avoid a hard error.
'bazel mod deps --lockfile_mode=update',
Expand All @@ -56,7 +57,21 @@
// run when in the same branch there are mixtures of update types by different managers.
executionMode: 'update',
},
matchManagers: ['bazel', 'bazel-module', 'bazelisk'],
},

// Enable 'postUpdateTasks' for changes that effect the typescript and pnpm versions.
// This is to ensure that the `MODULE.bazel` is updated with the correct versions.
{
matchManagers: ['npm'],
matchDepNames: ['pnpm', 'typescript'],
postUpgradeTasks: {
commands: [
'git restore .npmrc || true', // In case `.npmrc` avoid a hard error.
'pnpm install --frozen-lockfile',
'pnpm ng-dev misc sync-module-bazel || true', // TODO(alanagius): Remove || true once all repos update to the latest ng-dev.
],
executionMode: 'branch',
},
},

// Rule to require manual approval for NPM updates on branches other than 'main'.
Expand Down
1 change: 1 addition & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"commands": [
"pnpm install --frozen-lockfile",
"pnpm bazel mod deps --lockfile_mode=update",
"pnpm ng-dev misc sync-module-bazel",
"pnpm update-generated-files"
],
"executionMode": "branch"
Expand Down
Loading