From 23e3d4f4a761867b1e3eded9a92a4290a01daadb Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Wed, 25 Sep 2024 10:26:45 +0200 Subject: [PATCH] Split out directDependencies and devDependencies in `pub deps` (#4383) --- lib/src/command/deps.dart | 12 ++- test/deps_test.dart | 47 +++++++-- ...formatting before printing executables.txt | 13 ++- .../executables_test/dev dependencies.txt | 7 +- ... Dart executables, without entrypoints.txt | 4 +- .../lists executables from a dependency.txt | 9 +- ...ables only from immediate dependencies.txt | 12 ++- .../overriden dependencies executables.txt | 9 +- .../skips executables in sub directories.txt | 4 +- .../skips non-Dart executables.txt | 4 +- test/workspace_test.dart | 97 +++++++++++++++++++ 11 files changed, 196 insertions(+), 22 deletions(-) diff --git a/lib/src/command/deps.dart b/lib/src/command/deps.dart index 212d5414b..e197f3328 100644 --- a/lib/src/command/deps.dart +++ b/lib/src/command/deps.dart @@ -126,7 +126,17 @@ class DepsCommand extends PubCommand { 'version': currentPackage.version.toString(), 'kind': kind, 'source': source, - 'dependencies': next, + // This field is kept for backwards compatibility with dart 3.5 and + // before. Clients should opt to consume directDependencies and + // devDependencies separately instead. + 'dependencies': (isRoot + ? currentPackage.dependencies + : currentPackage.immediateDependencies) + .keys + .toList(), + 'directDependencies': currentPackage.dependencies.keys.toList(), + if (isRoot) + 'devDependencies': currentPackage.devDependencies.keys.toList(), }); toVisit.addAll(next); } diff --git a/test/deps_test.dart b/test/deps_test.dart index 2faca202a..e90e5db2b 100644 --- a/test/deps_test.dart +++ b/test/deps_test.dart @@ -158,9 +158,15 @@ void main() { "dependencies": [ "normal", "overridden", - "from_path", - "unittest", - "override_only" + "from_path" + ], + "directDependencies": [ + "normal", + "overridden", + "from_path" + ], + "devDependencies": [ + "unittest" ] }, { @@ -168,7 +174,8 @@ void main() { "version": "1.2.3", "kind": "transitive", "source": "hosted", - "dependencies": [] + "dependencies": [], + "directDependencies": [] }, { "name": "unittest", @@ -178,6 +185,10 @@ void main() { "dependencies": [ "shared", "dev_only" + ], + "directDependencies": [ + "shared", + "dev_only" ] }, { @@ -185,7 +196,8 @@ void main() { "version": "1.2.3", "kind": "transitive", "source": "hosted", - "dependencies": [] + "dependencies": [], + "directDependencies": [] }, { "name": "shared", @@ -194,6 +206,9 @@ void main() { "source": "hosted", "dependencies": [ "other" + ], + "directDependencies": [ + "other" ] }, { @@ -203,6 +218,9 @@ void main() { "source": "hosted", "dependencies": [ "myapp" + ], + "directDependencies": [ + "myapp" ] }, { @@ -210,14 +228,16 @@ void main() { "version": "1.2.3", "kind": "direct", "source": "path", - "dependencies": [] + "dependencies": [], + "directDependencies": [] }, { "name": "overridden", "version": "2.0.0", "kind": "direct", "source": "hosted", - "dependencies": [] + "dependencies": [], + "directDependencies": [] }, { "name": "normal", @@ -227,6 +247,10 @@ void main() { "dependencies": [ "transitive", "circular_a" + ], + "directDependencies": [ + "transitive", + "circular_a" ] }, { @@ -236,6 +260,9 @@ void main() { "source": "hosted", "dependencies": [ "circular_b" + ], + "directDependencies": [ + "circular_b" ] }, { @@ -245,6 +272,9 @@ void main() { "source": "hosted", "dependencies": [ "circular_a" + ], + "directDependencies": [ + "circular_a" ] }, { @@ -254,6 +284,9 @@ void main() { "source": "hosted", "dependencies": [ "shared" + ], + "directDependencies": [ + "shared" ] } ], diff --git a/test/testdata/goldens/deps/executables_test/applies formatting before printing executables.txt b/test/testdata/goldens/deps/executables_test/applies formatting before printing executables.txt index 94e40bd23..f6b044819 100644 --- a/test/testdata/goldens/deps/executables_test/applies formatting before printing executables.txt +++ b/test/testdata/goldens/deps/executables_test/applies formatting before printing executables.txt @@ -48,21 +48,28 @@ $ pub deps --json "dependencies": [ "foo", "bar" - ] + ], + "directDependencies": [ + "foo", + "bar" + ], + "devDependencies": [] }, { "name": "bar", "version": "1.0.0", "kind": "direct", "source": "path", - "dependencies": [] + "dependencies": [], + "directDependencies": [] }, { "name": "foo", "version": "1.0.0", "kind": "direct", "source": "path", - "dependencies": [] + "dependencies": [], + "directDependencies": [] } ], "sdks": [ diff --git a/test/testdata/goldens/deps/executables_test/dev dependencies.txt b/test/testdata/goldens/deps/executables_test/dev dependencies.txt index fe0d91c70..d0b2ffa98 100644 --- a/test/testdata/goldens/deps/executables_test/dev dependencies.txt +++ b/test/testdata/goldens/deps/executables_test/dev dependencies.txt @@ -34,7 +34,9 @@ $ pub deps --json "version": "0.0.0", "kind": "root", "source": "root", - "dependencies": [ + "dependencies": [], + "directDependencies": [], + "devDependencies": [ "foo" ] }, @@ -43,7 +45,8 @@ $ pub deps --json "version": "1.0.0", "kind": "dev", "source": "path", - "dependencies": [] + "dependencies": [], + "directDependencies": [] } ], "sdks": [ diff --git a/test/testdata/goldens/deps/executables_test/lists Dart executables, without entrypoints.txt b/test/testdata/goldens/deps/executables_test/lists Dart executables, without entrypoints.txt index 4a9cf4051..89c4b0466 100644 --- a/test/testdata/goldens/deps/executables_test/lists Dart executables, without entrypoints.txt +++ b/test/testdata/goldens/deps/executables_test/lists Dart executables, without entrypoints.txt @@ -33,7 +33,9 @@ $ pub deps --json "version": "0.0.0", "kind": "root", "source": "root", - "dependencies": [] + "dependencies": [], + "directDependencies": [], + "devDependencies": [] } ], "sdks": [ diff --git a/test/testdata/goldens/deps/executables_test/lists executables from a dependency.txt b/test/testdata/goldens/deps/executables_test/lists executables from a dependency.txt index a2e04eaba..33c7a0499 100644 --- a/test/testdata/goldens/deps/executables_test/lists executables from a dependency.txt +++ b/test/testdata/goldens/deps/executables_test/lists executables from a dependency.txt @@ -36,14 +36,19 @@ $ pub deps --json "source": "root", "dependencies": [ "foo" - ] + ], + "directDependencies": [ + "foo" + ], + "devDependencies": [] }, { "name": "foo", "version": "1.0.0", "kind": "direct", "source": "path", - "dependencies": [] + "dependencies": [], + "directDependencies": [] } ], "sdks": [ diff --git a/test/testdata/goldens/deps/executables_test/lists executables only from immediate dependencies.txt b/test/testdata/goldens/deps/executables_test/lists executables only from immediate dependencies.txt index 5641ae5c7..cb13a57c3 100644 --- a/test/testdata/goldens/deps/executables_test/lists executables only from immediate dependencies.txt +++ b/test/testdata/goldens/deps/executables_test/lists executables only from immediate dependencies.txt @@ -40,7 +40,11 @@ $ pub deps --json "source": "root", "dependencies": [ "foo" - ] + ], + "directDependencies": [ + "foo" + ], + "devDependencies": [] }, { "name": "foo", @@ -49,6 +53,9 @@ $ pub deps --json "source": "path", "dependencies": [ "baz" + ], + "directDependencies": [ + "baz" ] }, { @@ -56,7 +63,8 @@ $ pub deps --json "version": "1.0.0", "kind": "transitive", "source": "path", - "dependencies": [] + "dependencies": [], + "directDependencies": [] } ], "sdks": [ diff --git a/test/testdata/goldens/deps/executables_test/overriden dependencies executables.txt b/test/testdata/goldens/deps/executables_test/overriden dependencies executables.txt index 45026732e..ad13621c8 100644 --- a/test/testdata/goldens/deps/executables_test/overriden dependencies executables.txt +++ b/test/testdata/goldens/deps/executables_test/overriden dependencies executables.txt @@ -41,14 +41,19 @@ $ pub deps --json "source": "root", "dependencies": [ "foo" - ] + ], + "directDependencies": [ + "foo" + ], + "devDependencies": [] }, { "name": "foo", "version": "2.0.0", "kind": "direct", "source": "path", - "dependencies": [] + "dependencies": [], + "directDependencies": [] } ], "sdks": [ diff --git a/test/testdata/goldens/deps/executables_test/skips executables in sub directories.txt b/test/testdata/goldens/deps/executables_test/skips executables in sub directories.txt index ce15a0217..044eb9bf3 100644 --- a/test/testdata/goldens/deps/executables_test/skips executables in sub directories.txt +++ b/test/testdata/goldens/deps/executables_test/skips executables in sub directories.txt @@ -34,7 +34,9 @@ $ pub deps --json "version": "0.0.0", "kind": "root", "source": "root", - "dependencies": [] + "dependencies": [], + "directDependencies": [], + "devDependencies": [] } ], "sdks": [ diff --git a/test/testdata/goldens/deps/executables_test/skips non-Dart executables.txt b/test/testdata/goldens/deps/executables_test/skips non-Dart executables.txt index 71c0fc210..6b8ffe198 100644 --- a/test/testdata/goldens/deps/executables_test/skips non-Dart executables.txt +++ b/test/testdata/goldens/deps/executables_test/skips non-Dart executables.txt @@ -31,7 +31,9 @@ $ pub deps --json "version": "0.0.0", "kind": "root", "source": "root", - "dependencies": [] + "dependencies": [], + "directDependencies": [], + "devDependencies": [] } ], "sdks": [ diff --git a/test/workspace_test.dart b/test/workspace_test.dart index 147c54381..e7d209565 100644 --- a/test/workspace_test.dart +++ b/test/workspace_test.dart @@ -539,6 +539,103 @@ dependencies: transitive dependencies: - transitive 1.0.0''', ); + await runPub( + args: ['deps', '--json'], + environment: {'_PUB_TEST_SDK_VERSION': '3.5.0'}, + output: ''' +{ + "root": "myapp", + "packages": [ + { + "name": "b", + "version": "1.1.1", + "kind": "root", + "source": "root", + "dependencies": [ + "myapp", + "both" + ], + "directDependencies": [ + "myapp", + "both" + ], + "devDependencies": [] + }, + { + "name": "both", + "version": "1.0.0", + "kind": "direct", + "source": "hosted", + "dependencies": [], + "directDependencies": [] + }, + { + "name": "myapp", + "version": "1.2.3", + "kind": "root", + "source": "root", + "dependencies": [ + "both", + "b" + ], + "directDependencies": [ + "both", + "b" + ], + "devDependencies": [] + }, + { + "name": "a", + "version": "1.1.1", + "kind": "root", + "source": "root", + "dependencies": [ + "myapp", + "foo" + ], + "directDependencies": [ + "myapp", + "foo" + ], + "devDependencies": [ + "both" + ] + }, + { + "name": "foo", + "version": "1.0.0", + "kind": "transitive", + "source": "hosted", + "dependencies": [ + "transitive" + ], + "directDependencies": [ + "transitive" + ] + }, + { + "name": "transitive", + "version": "1.0.0", + "kind": "transitive", + "source": "hosted", + "dependencies": [], + "directDependencies": [] + } + ], + "sdks": [ + { + "name": "Dart", + "version": "3.5.0" + } + ], + "executables": [ + ":myappmain", + "both:bothmain", + "b:bmain" + ] +} +''', + ); await runPub( args: ['deps', '--style=list', '--no-dev'],