fix(sdk): parse JSONC comments in version sync

This commit is contained in:
Kayshen-X 2026-07-15 21:10:08 +08:00
parent 1f789095a9
commit bb905db75c
2 changed files with 45 additions and 1 deletions

View file

@ -148,7 +148,15 @@ function skipJsoncValue(source, start) {
}
let index = valueStart;
while (index < source.length && !',}]'.includes(source[index])) {
while (index < source.length) {
const afterTrivia = skipTrivia(source, index);
if (afterTrivia !== index) {
index = afterTrivia;
continue;
}
if (',}]'.includes(source[index])) {
break;
}
index += 1;
}
return index;

View file

@ -98,6 +98,42 @@ test('Bun lock inspection finds every versioned SDK workspace and ignores the ro
});
});
test('Bun lock inspection ignores structural delimiters in block comments after primitive values', () => {
const lockfile = `{
"lockfileVersion": 1 /* comma, brace }, bracket ] */,
"workspaces": {
"op-web-sdk": { "version": "1.0.0" },
},
}`;
assert.deepEqual(inspectBunLockWorkspaceVersions(lockfile), {
'op-web-sdk': '1.0.0',
});
});
test('Bun lock inspection ignores structural delimiters in line comments after primitive values', () => {
const lockfile = `{
"lockfileVersion": 1 // comma, brace }, bracket ]
,
"workspaces": {
"op-web-sdk": { "version": "1.0.0" },
},
}`;
assert.deepEqual(inspectBunLockWorkspaceVersions(lockfile), {
'op-web-sdk': '1.0.0',
});
});
test('Bun lock inspection still rejects unterminated block comments after primitive values', () => {
const lockfile = `{
"lockfileVersion": 1 /* unterminated }, ],
"workspaces": {},
}`;
assert.throws(() => inspectBunLockWorkspaceVersions(lockfile), /unterminated block comment/i);
});
test('drift collection reports each stale path with expected and actual versions', () => {
assert.deepEqual(
collectVersionDrift('2.3.4', [