Skip to content

Commit 3ceed63

Browse files
add check to soundness script for even numbered versions in the package.json
1 parent 9e0717d commit 3ceed63

File tree

4 files changed

+58
-16
lines changed

4 files changed

+58
-16
lines changed

scripts/check_package_json.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the VS Code Swift open source project
4+
//
5+
// Copyright (c) 2025 the VS Code Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
/* eslint-disable no-console */
15+
16+
import { getExtensionVersion, main } from "./lib/utilities";
17+
18+
main(async () => {
19+
const version = await getExtensionVersion();
20+
if (version.minor % 2 !== 0) {
21+
throw new Error(
22+
`Invalid version number in package.json. ${version.toString()} does not have an even numbered minor version.`
23+
);
24+
}
25+
});

scripts/lib/utilities.ts

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
/* eslint-disable no-console */
1515

1616
import * as child_process from "child_process";
17+
import { readFile } from "fs/promises";
18+
import * as path from "path";
19+
import * as semver from "semver";
1720

1821
/**
1922
* Executes the provided main function for the script while logging any errors.
@@ -31,6 +34,30 @@ export async function main(mainFn: () => Promise<void>): Promise<void> {
3134
}
3235
}
3336

37+
/**
38+
* Returns the root directory of the repository.
39+
*/
40+
export function getRootDirectory(): string {
41+
return path.join(__dirname, "..", "..");
42+
}
43+
44+
/**
45+
* Retrieves the version number from the package.json.
46+
*/
47+
export async function getExtensionVersion(): Promise<semver.SemVer> {
48+
const packageJSON = JSON.parse(
49+
await readFile(path.join(getRootDirectory(), "package.json"), "utf-8")
50+
);
51+
if (typeof packageJSON.version !== "string") {
52+
throw new Error("Version number in package.json is not a string");
53+
}
54+
const version = semver.parse(packageJSON.version);
55+
if (version === null) {
56+
throw new Error("Unable to parse version number in package.json");
57+
}
58+
return version;
59+
}
60+
3461
/**
3562
* Executes the given command, inheriting the current process' stdio.
3663
*

scripts/preview_package.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414
/* eslint-disable no-console */
1515

16-
import * as path from "path";
17-
import * as semver from "semver";
18-
import { readFile } from "fs/promises";
19-
import { exec, main } from "./lib/utilities";
16+
import { exec, getExtensionVersion, getRootDirectory, main } from "./lib/utilities";
2017

2118
/**
2219
* Formats the given date as a string in the form "YYYYMMddhhmm".
@@ -34,18 +31,8 @@ function formatDate(date: Date): string {
3431
}
3532

3633
main(async () => {
37-
const rootDirectory = path.join(__dirname, "..");
38-
// Grab the existing version number from the package.json
39-
const packageJSON = JSON.parse(
40-
await readFile(path.join(rootDirectory, "package.json"), "utf-8")
41-
);
42-
if (typeof packageJSON.version !== "string") {
43-
throw new Error("Version number in package.json is not a string");
44-
}
45-
const version = semver.parse(packageJSON.version);
46-
if (version === null) {
47-
throw new Error("Unable to parse version number in package.json");
48-
}
34+
const rootDirectory = getRootDirectory();
35+
const version = await getExtensionVersion();
4936
// Increment the minor version and set the patch version to today's date
5037
const minor = version.minor + 1;
5138
const patch = formatDate(new Date());

scripts/soundness.sh

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ function replace_acceptable_years() {
3636
sed -e 's/20[12][0123456789]-20[12][0123456789]/YEARS/' -e 's/20[12][0123456789]/YEARS/'
3737
}
3838

39+
printf "=> Checking package.json..."
40+
npm run check-package-json
41+
3942
printf "=> Checking license headers... "
4043
tmp=$(mktemp /tmp/.vscode-swift-soundness_XXXXXX)
4144

0 commit comments

Comments
 (0)