Skip to content

Commit abb3e5e

Browse files
committed
fix: add test to check versions
1 parent ba3ba9a commit abb3e5e

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

.husky/check-versions.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import fs from 'node:fs';
22
import semver from 'semver';
33

4+
const SFDX_LOCAL_DEV_DIST_BASE = '@lwc/sfdx-local-dev-dist';
5+
const SFDX_LOCAL_DEV_DIST_PATTERN = /^@lwc\/sfdx-local-dev-dist-([\d.]+)$/;
6+
47
/**
58
* This script ensures that the aliased dependencies in package.json stay in sync
69
* with the versions defined in apiVersionMetadata.
10+
* It also ensures @lwc/sfdx-local-dev-dist matches the version of the highest-numbered
11+
* @lwc/sfdx-local-dev-dist-<number> alias.
712
*/
813

914
// Read package.json
@@ -17,6 +22,34 @@ if (!apiVersionMetadata) {
1722

1823
let hasError = false;
1924

25+
// Check that @lwc/sfdx-local-dev-dist version matches the highest-numbered alias
26+
const baseVersion = packageJson.dependencies[SFDX_LOCAL_DEV_DIST_BASE];
27+
if (baseVersion) {
28+
const aliasedDeps = Object.keys(packageJson.dependencies).filter((key) => SFDX_LOCAL_DEV_DIST_PATTERN.test(key));
29+
if (aliasedDeps.length > 0) {
30+
const highestAlias = aliasedDeps
31+
.map((key) => {
32+
const m = key.match(SFDX_LOCAL_DEV_DIST_PATTERN);
33+
return { key, number: m ? parseFloat(m[1]) : -1 };
34+
})
35+
.sort((a, b) => b.number - a.number)[0];
36+
37+
const highestAliasValue = packageJson.dependencies[highestAlias.key];
38+
const highestMatch = highestAliasValue?.match(/@([^@]+)$/);
39+
const highestRange = highestMatch ? highestMatch[1] : null;
40+
41+
if (!highestRange) {
42+
console.error(`Error: Could not parse version range from '${highestAlias.key}': ${highestAliasValue}`);
43+
hasError = true;
44+
} else if (baseVersion !== highestRange) {
45+
console.error(
46+
`Error: Version of '${SFDX_LOCAL_DEV_DIST_BASE}' (${baseVersion}) must be the same as the version of the highest-numbered alias '${highestAlias.key}' (${highestRange}).`,
47+
);
48+
hasError = true;
49+
}
50+
}
51+
}
52+
2053
// Iterate through each API version defined in metadata
2154
for (const [apiVersion, metadata] of Object.entries(apiVersionMetadata)) {
2255
const expectedDeps = metadata.dependencies;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@inquirer/prompts": "^5.3.8",
99
"@inquirer/select": "^2.4.7",
10-
"@lwc/sfdx-local-dev-dist": "~13.3.16-alpha.0",
10+
"@lwc/sfdx-local-dev-dist": "~13.3.18",
1111
"@lwc/sfdx-local-dev-dist-65.0": "npm:@lwc/sfdx-local-dev-dist@~13.1.7",
1212
"@lwc/sfdx-local-dev-dist-66.0": "npm:@lwc/sfdx-local-dev-dist@~13.2.22",
1313
"@lwc/sfdx-local-dev-dist-67.0": "npm:@lwc/sfdx-local-dev-dist@~13.3.18",

0 commit comments

Comments
 (0)