From 4ef6ca4b62f093e52fe5cff998bd4865dc2ac7a9 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 25 Mar 2024 10:50:54 +0000 Subject: [PATCH 1/3] Show parent pubspecs when a pubspec could not be found. --- lib/src/package.dart | 28 ++++++++++++++++++++-------- test/workspace_test.dart | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/lib/src/package.dart b/lib/src/package.dart index 568567917..d4ec1542f 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -140,6 +140,9 @@ class Package { /// This mechanism can be used to avoid loading pubspecs twice. It can also be /// used to override a pubspec in memory for trying out an alternative /// resolution. + /// + /// [referringPubspec] is the path to the pubspec that includes this one in + /// the workspace. factory Package.load( String dir, SourceRegistry sources, { @@ -162,20 +165,29 @@ class Package { withPubspecOverrides: withPubspecOverrides, expectedName: expectedName, ); - final workspacePackages = pubspec.workspace - .map( - (e) => Package.load( - p.join(dir, e), + + final workspacePackages = pubspec.workspace.map( + (workspacePath) { + try { + return Package.load( + p.join(dir, workspacePath), sources, loadPubspec: loadPubspec, withPubspecOverrides: withPubspecOverrides, - ), - ) - .toList(); + ); + } on FileException catch (e) { + throw FileException( + '${e.message}\n' + 'That was included in the workspace of ${p.join(dir, 'pubspec.yaml')}.', + e.path, + ); + } + }, + ).toList(); for (final package in workspacePackages) { if (package.pubspec.resolution != Resolution.workspace) { fail(''' -${package.pubspecPath} is inluded in the workspace from ${p.join(dir, 'pubspec.yaml')}, but does not have `resolution: workspace`. +${package.pubspecPath} is included in the workspace from ${p.join(dir, 'pubspec.yaml')}, but does not have `resolution: workspace`. See $workspacesDocUrl for more information. '''); diff --git a/test/workspace_test.dart b/test/workspace_test.dart index d603f5da5..f86727b46 100644 --- a/test/workspace_test.dart +++ b/test/workspace_test.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'package:path/path.dart' as p; +import 'package:pub/src/exit_codes.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; @@ -180,7 +181,9 @@ void main() { ); }); - test('reports errors in workspace pubspec.yamls correctly', () async { + test( + 'ignores the source of dependencies on root packages. (Uses the local version instead)', + () async { await dir(appPath, [ libPubspec( 'myapp', @@ -259,4 +262,36 @@ void main() { output: contains('Resolving dependencies in `..`...'), ); }); + + test('reports missing pubspec.yaml of workspace member correctly', () async { + await dir(appPath, [ + libPubspec( + 'myapp', + '1.2.3', + extras: { + 'workspace': ['a'], + }, + sdk: '^3.7.0', + ), + dir('a', [ + libPubspec( + 'a', + '1.0.0', + resolutionWorkspace: true, + extras: { + 'workspace': ['b'], // Doesn't exist. + }, + ), + ]), + ]).create(); + await pubGet( + environment: {'_PUB_TEST_SDK_VERSION': '3.7.0'}, + error: contains( + 'Could not find a file named "pubspec.yaml" in "${p.join(sandbox, appPath, 'a', 'b')}".\n' + 'That was included in the workspace of ${p.join('.', 'a', 'pubspec.yaml')}.\n' + 'That was included in the workspace of ${p.join('.', 'pubspec.yaml')}.', + ), + exitCode: NO_INPUT, + ); + }); } From 8f0241c2b9bdd81659602fcc152aa829a9839d04 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Fri, 5 Apr 2024 11:25:05 +0000 Subject: [PATCH 2/3] Address review --- lib/src/package.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/src/package.dart b/lib/src/package.dart index d4ec1542f..d7f8642cc 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -123,7 +123,7 @@ class Package { } } - /// Loads the package whose root directory is [packageDir]. + /// Loads the package whose root directory is [dir]. /// /// Will also load the workspace sub-packages of this package (recursively). /// @@ -140,9 +140,6 @@ class Package { /// This mechanism can be used to avoid loading pubspecs twice. It can also be /// used to override a pubspec in memory for trying out an alternative /// resolution. - /// - /// [referringPubspec] is the path to the pubspec that includes this one in - /// the workspace. factory Package.load( String dir, SourceRegistry sources, { From f970f6e3aeb30e5740b07db364e9d7270681ab65 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Fri, 5 Apr 2024 13:44:28 +0000 Subject: [PATCH 3/3] Update expectation --- test/workspace_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/workspace_test.dart b/test/workspace_test.dart index 001cadf6a..7bf863834 100644 --- a/test/workspace_test.dart +++ b/test/workspace_test.dart @@ -296,7 +296,7 @@ void main() { await pubGet( environment: {'_PUB_TEST_SDK_VERSION': '3.7.0'}, error: contains( - 'pkgs${s}a${s}pubspec.yaml is inluded in the workspace from .${s}pubspec.yaml, but does not have `resolution: workspace`.', + 'pkgs${s}a${s}pubspec.yaml is included in the workspace from .${s}pubspec.yaml, but does not have `resolution: workspace`.', ), ); });