Skip to content

Commit 7a895fd

Browse files
committed
feat(scripts): Make version sync script error by default
The `verify-version-sync.js` script now errors and exits with a non-zero status code if a version mismatch is detected between `package.json` and `source.extension.vsixmanifest`. Previously, the script would automatically update the manifest, which could hide versioning issues in CI environments. The new behavior ensures that verification steps fail as expected. To retain the auto-fixing functionality, a `--fix` flag has been introduced. A corresponding `npm run fix:version` script has been added to `package.json` for convenience. Additionally, this commit includes: - Refactoring in `MockFileService` to use a more robust path comparison method. - Improved error handling in the integration test runner.
1 parent c095beb commit 7a895fd

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@
415415
"bundle": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --platform=node --format=cjs --external:vscode --sourcemap",
416416
"package": "echo 'vsce not installed in offline env'",
417417
"verify:version": "node scripts/verify-version-sync.js",
418+
"fix:version": "node scripts/verify-version-sync.js --fix",
418419
"test": "npm run compile && node ./dist/test/runVscodeTests.js",
419420
"compile": "tsc -p ./",
420421
"test:unit": "node dist/test/runTest.js",

scripts/verify-version-sync.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ if(!manifestVersion){
1919
process.exit(2);
2020
}
2121

22+
const shouldFix = process.argv.includes('--fix');
23+
2224
if(pkg.version !== manifestVersion){
23-
console.log(`Version mismatch detected. package.json=${pkg.version}, manifest=${manifestVersion}. Updating manifest...`);
24-
const updatedXml = xml.replace(/(<Identity[^>]*Version=")([^"]+)(")/i, `$1${pkg.version}$3`);
25-
fs.writeFileSync(manifestPath, updatedXml, 'utf8');
26-
console.log(`Successfully updated ${manifestPath} to version ${pkg.version}`);
25+
if (shouldFix) {
26+
console.log(`Version mismatch detected. package.json=${pkg.version}, manifest=${manifestVersion}. Updating manifest...`);
27+
const updatedXml = xml.replace(/(<Identity[^>]*Version=")([^"]+)(")/i, `$1${pkg.version}$3`);
28+
fs.writeFileSync(manifestPath, updatedXml, 'utf8');
29+
console.log(`Successfully updated ${manifestPath} to version ${pkg.version}`);
30+
} else {
31+
console.error(`ERROR: Version mismatch. package.json is ${pkg.version}, but vsixmanifest is ${manifestVersion}.`);
32+
console.error('Run with --fix to automatically update the manifest.');
33+
process.exit(1);
34+
}
2735
} else {
2836
console.log(`Version sync OK: ${pkg.version}`);
2937
}

test/fileService.mock.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ export class MockFileService implements IFileService {
2727
async rm(p: string, options?: { recursive?: boolean; force?: boolean }): Promise<void> {
2828
const norm = path.resolve(p);
2929
if (options?.recursive) {
30-
const normWithSep = norm + path.sep;
3130
for (const file of this.files.keys()) {
32-
if (file === norm || file.startsWith(normWithSep)) {
31+
if (file === norm || this.isChildPath(file, norm)) {
3332
this.files.delete(file);
3433
}
3534
}
3635
for (const dir of this.dirs.keys()) {
37-
if (dir === norm || dir.startsWith(normWithSep)) {
36+
if (dir === norm || this.isChildPath(dir, norm)) {
3837
this.dirs.delete(dir);
3938
}
4039
}
@@ -43,4 +42,9 @@ export class MockFileService implements IFileService {
4342
this.dirs.delete(norm);
4443
}
4544
}
45+
46+
private isChildPath(childPath: string, parentPath: string): boolean {
47+
const relative = path.relative(parentPath, childPath);
48+
return relative.length > 0 && !relative.startsWith('..') && !path.isAbsolute(relative);
49+
}
4650
}

test/real.integration.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,17 @@ async function runRealIntegrationTests() {
9292

9393
// Run tests if this file is executed directly
9494
if (require.main === module) {
95-
runRealIntegrationTests().catch(err => {
96-
console.error(err);
97-
process.exit(1);
98-
});
95+
(async () => {
96+
try {
97+
await runRealIntegrationTests();
98+
} catch (err) {
99+
console.error('Unhandled error in real integration tests:', err);
100+
process.exit(1);
101+
}
102+
})().catch(err => {
103+
console.error('Critical error in test execution:', err);
104+
process.exit(1);
105+
});
99106
}
100107

101108
export { runRealIntegrationTests };

0 commit comments

Comments
 (0)