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

Show parent pubspecs when a pubspec could not be found. #4197

Merged
merged 5 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 20 additions & 8 deletions lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
jonasfj marked this conversation as resolved.
Show resolved Hide resolved
/// the workspace.
factory Package.load(
String dir,
jonasfj marked this conversation as resolved.
Show resolved Hide resolved
SourceRegistry sources, {
Expand All @@ -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.
''');
Expand Down
32 changes: 32 additions & 0 deletions test/workspace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,38 @@ void main() {
);
});

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(
Expand Down
Loading