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 all 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
27 changes: 18 additions & 9 deletions lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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).
///
Expand Down Expand Up @@ -162,20 +162,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
34 changes: 33 additions & 1 deletion test/workspace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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`.',
),
);
});
Expand Down 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