mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 14:05:47 -05:00
Add gitHead to package.json in all release workflows (#58135)
This commit is contained in:
24
scripts/addPackageJsonGitHead.mjs
Normal file
24
scripts/addPackageJsonGitHead.mjs
Normal file
@@ -0,0 +1,24 @@
|
||||
import { execFileSync } from "child_process";
|
||||
import {
|
||||
readFileSync,
|
||||
writeFileSync,
|
||||
} from "fs";
|
||||
import {
|
||||
dirname,
|
||||
resolve,
|
||||
} from "path";
|
||||
|
||||
const packageJsonFilePath = process.argv[2];
|
||||
if (!packageJsonFilePath) {
|
||||
console.error("Usage: node addPackageJsonGitHead.mjs <package.json location>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const packageJsonValue = JSON.parse(readFileSync(packageJsonFilePath, "utf8"));
|
||||
|
||||
const cwd = dirname(resolve(packageJsonFilePath));
|
||||
const gitHead = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
|
||||
|
||||
packageJsonValue.gitHead = gitHead;
|
||||
|
||||
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, undefined, 4) + "\n");
|
||||
@@ -1,5 +1,4 @@
|
||||
import assert from "assert";
|
||||
import { execFileSync } from "child_process";
|
||||
import {
|
||||
readFileSync,
|
||||
writeFileSync,
|
||||
@@ -18,7 +17,6 @@ const __filename = url.fileURLToPath(new URL(import.meta.url));
|
||||
name: string;
|
||||
version: string;
|
||||
keywords: string[];
|
||||
gitHead?: string;
|
||||
}} PackageJson
|
||||
*/
|
||||
|
||||
@@ -59,7 +57,6 @@ function main() {
|
||||
// Finally write the changes to disk.
|
||||
// Modify the package.json structure
|
||||
packageJsonValue.version = `${majorMinor}.${prereleasePatch}`;
|
||||
packageJsonValue.gitHead = execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf8" }).trim();
|
||||
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4));
|
||||
writeFileSync(tsFilePath, modifiedTsFileContents);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user