Show parent pubspecs when a pubspec could not be found. (#4197)
diff --git a/lib/src/package.dart b/lib/src/package.dart index 5685679..d7f8642 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart
@@ -123,7 +123,7 @@ } } - /// 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). /// @@ -162,20 +162,29 @@ 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 0ff5d4b..7bf8638 100644 --- a/test/workspace_test.dart +++ b/test/workspace_test.dart
@@ -296,7 +296,7 @@ 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`.', ), ); }); @@ -355,6 +355,38 @@ ); }); + 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, + ); + }); + test('`pub deps` lists dependencies for all members of workspace', () async { final server = await servePackages(); server.serve(