Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support package-lock.json version 3 #1940

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions __snapshots__/package-lock-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ exports['PackageLockJson updateContent v2 updates the package version 1'] = `
}

`

exports['PackageLockJson updateContent v3 updates the package version 1'] = `
{
"name": "release-please",
"version": "14.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "release-please",
"version": "14.0.0"
}
}
}

`
2 changes: 1 addition & 1 deletion src/updaters/node/package-lock-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class PackageLockJson extends DefaultUpdater {
const parsed = JSON.parse(content) as LockFileV2;
logger.info(`updating from ${parsed.version} to ${this.version}`);
parsed.version = this.version.toString();
if (parsed.lockfileVersion === 2) {
if (parsed.lockfileVersion === 2 || parsed.lockfileVersion === 3) {
parsed.packages[''].version = this.version.toString();
}
return jsonStringify(parsed, content);
Expand Down
12 changes: 12 additions & 0 deletions test/updaters/fixtures/package-lock-v3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "release-please",
"version": "11.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "release-please",
"version": "11.1.0"
}
}
}
14 changes: 14 additions & 0 deletions test/updaters/package-lock-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,18 @@ describe('PackageLockJson', () => {
snapshot(newContent.replace(/\r\n/g, '\n'));
});
});

describe('updateContent v3', () => {
it('updates the package version', async () => {
const oldContent = readFileSync(
resolve(fixturesPath, './package-lock-v3.json'),
'utf8'
);
const packageJson = new PackageLockJson({
version: Version.parse('14.0.0'),
});
const newContent = packageJson.updateContent(oldContent);
snapshot(newContent.replace(/\r\n/g, '\n'));
});
});
});