MCPcopy Create free account
hub / github.com/angular/dev-infra / updateProjectVersion

Function updateProjectVersion

ng-dev/release/publish/actions.ts:131–153  ·  view source on GitHub ↗

* Updates the version in the project top-level `package.json` file. * * @param newVersion New SemVer version to be set in the file. * @param additionalUpdateFn Optional update function that runs before * the version update. Can be used to update other fields.

(
    newVersion: semver.SemVer,
    additionalUpdateFn?: (pkgJson: PackageJson) => void,
  )

Source from the content-addressed store, hash-verified

129 * the version update. Can be used to update other fields.
130 */
131 protected async updateProjectVersion(
132 newVersion: semver.SemVer,
133 additionalUpdateFn?: (pkgJson: PackageJson) => void,
134 ) {
135 const pkgJsonPath = join(this.projectDir, workspaceRelativePackageJsonPath);
136 const pkgJson = JSON.parse(await fs.readFile(pkgJsonPath, 'utf8')) as {
137 version: string;
138 [key: string]: any;
139 };
140 if (additionalUpdateFn !== undefined) {
141 additionalUpdateFn(pkgJson);
142 }
143 pkgJson.version = newVersion.format();
144 // Write the `package.json` file. Note that we add a trailing new line
145 // to avoid unnecessary diff. IDEs usually add a trailing new line.
146 await fs.writeFile(pkgJsonPath, `${JSON.stringify(pkgJson, null, 2)}\n`);
147 Log.info(green(` ✓ Updated project version to ${pkgJson.version}`));
148
149 // TODO: remove when Angular version 19 is no longer in LTS.
150 if (existsSync(join(this.projectDir, '.aspect'))) {
151 await ExternalCommands.invokeBazelUpdateAspectLockFiles(this.projectDir);
152 }
153 }
154
155 /*
156 * Get the modified Aspect lock files if `rulesJsInteropMode` is enabled.

Callers

nothing calls this directly

Calls 2

formatMethod · 0.45
stringifyMethod · 0.45

Tested by

no test coverage detected