Skip to content

Commit

Permalink
Add package-lock lockfileVersion 3 support and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MeesterDev committed Nov 6, 2023
1 parent e806e45 commit fa55430
Show file tree
Hide file tree
Showing 21 changed files with 1,495 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Parse composer/npm package locks into a list of packages with some basic information.",
"minimum-stability": "stable",
"license": "MIT",
"version": "1.0.1",
"version": "1.1.0",
"authors": [
{
"name": "Thomas Meester",
Expand Down
7 changes: 7 additions & 0 deletions src/Parsers/PackageLockVersion3Parser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace MeesterDev\PackageParser\Parsers;

class PackageLockVersion3Parser extends PackageLockVersion2Parser {
// currently no need to override anything
}
9 changes: 7 additions & 2 deletions src/Parsers/ParserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ public static function createForFile(File $file): AbstractParser {
return new PackageLockVersion1Parser($contentObject, $file);
}

if (isset($contentObject->lockfileVersion, $contentObject->packages) && $contentObject->lockfileVersion === 2) {
return new PackageLockVersion2Parser($contentObject, $file);
if (isset($contentObject->lockfileVersion, $contentObject->packages)) {
if ($contentObject->lockfileVersion === 2) {
return new PackageLockVersion2Parser($contentObject, $file);
}
elseif ($contentObject->lockfileVersion === 3) {
return new PackageLockVersion3Parser($contentObject, $file);
}
}

throw new UnknownPackageFileFormatException($file->path);
Expand Down
2 changes: 1 addition & 1 deletion tests/PackageLockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use MeesterDev\PackageParser\Entities\PackageInformation;

class PackageLockTest extends BaseTestCase {
private const PACKAGE_LOCK_VERSIONS = [1, 2];
private const PACKAGE_LOCK_VERSIONS = [1, 2, 3];

public function testPackageLockWithoutDependencies(): void {
foreach (static::PACKAGE_LOCK_VERSIONS as $packageLockVersion) {
Expand Down
6 changes: 6 additions & 0 deletions tests/packagefiles/empty-project-npm-3/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/packagefiles/empty-project-npm-3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/packagefiles/public-domain-project-npm-3/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/packagefiles/public-domain-project-npm-3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"quattro-stagioni": "^0.1.0"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fa55430

Please sign in to comment.