diff --git a/packages/scripts/sync-version.mjs b/packages/scripts/sync-version.mjs index 7328bafd5..a865b9709 100644 --- a/packages/scripts/sync-version.mjs +++ b/packages/scripts/sync-version.mjs @@ -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; diff --git a/packages/scripts/sync-version.test.mjs b/packages/scripts/sync-version.test.mjs index f98738d61..194c014cf 100644 --- a/packages/scripts/sync-version.test.mjs +++ b/packages/scripts/sync-version.test.mjs @@ -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', [