Skip to content

Commit 3894534

Browse files
authored
Better error for duplicate workspace entries (#4385)
1 parent 65c42eb commit 3894534

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

lib/src/package.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,20 @@ void validateWorkspace(Package root) {
407407
for (final child in current.workspaceChildren) {
408408
final previous = includedFrom[p.canonicalize(child.dir)];
409409
if (previous != null) {
410+
if (previous == current.dir) {
411+
fail(
412+
'''
413+
Packages can only be included in the workspace once.
414+
415+
`${p.join(child.dir, 'pubspec.yaml')}` is included twice into the workspace of `${p.join(current.dir, 'pubspec.yaml')}`''',
416+
);
417+
}
410418
fail('''
411419
Packages can only be included in the workspace once.
412420
413421
`${p.join(child.dir, 'pubspec.yaml')}` is included in the workspace, both from:
414422
* `${p.join(current.dir, 'pubspec.yaml')}` and
415-
* ${p.join(previous, 'pubspec.yaml')}.''');
423+
* `${p.join(previous, 'pubspec.yaml')}`.''');
416424
}
417425
includedFrom[p.canonicalize(child.dir)] = current.dir;
418426
}

pubspec.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ packages:
55
dependency: transitive
66
description:
77
name: _fe_analyzer_shared
8-
sha256: f6dbf021f4b214d85c79822912c5fcd142a2c4869f01222ad371bc51f9f1c356
8+
sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77"
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "74.0.0"
11+
version: "73.0.0"
1212
_macros:
1313
dependency: transitive
1414
description: dart
1515
source: sdk
16-
version: "0.3.3"
16+
version: "0.3.2"
1717
analyzer:
1818
dependency: "direct main"
1919
description:
2020
name: analyzer
21-
sha256: f7e8caf82f2d3190881d81012606effdf8a38e6c1ab9e30947149733065f817c
21+
sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a"
2222
url: "https://pub.dev"
2323
source: hosted
24-
version: "6.9.0"
24+
version: "6.8.0"
2525
args:
2626
dependency: "direct main"
2727
description:
@@ -194,10 +194,10 @@ packages:
194194
dependency: transitive
195195
description:
196196
name: macros
197-
sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656"
197+
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
198198
url: "https://pub.dev"
199199
source: hosted
200-
version: "0.1.3-main.0"
200+
version: "0.1.2-main.4"
201201
matcher:
202202
dependency: transitive
203203
description:

test/workspace_test.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,44 @@ Packages can only be included in the workspace once.
791791
792792
`.${s}pkgs${s}a${s}pubspec.yaml` is included in the workspace, both from:
793793
* `.${s}pkgs${s}pubspec.yaml` and
794-
* .${s}pubspec.yaml.''',
794+
* `.${s}pubspec.yaml`.''',
795+
environment: {'_PUB_TEST_SDK_VERSION': '3.5.0'},
796+
);
797+
});
798+
799+
test('Reports error if workspace has repeat item', () async {
800+
await dir(appPath, [
801+
libPubspec(
802+
'myapp',
803+
'1.2.3',
804+
sdk: '^3.5.0',
805+
extras: {
806+
'workspace': ['pkgs/a', 'pkgs/a/'],
807+
},
808+
),
809+
dir('pkgs', [
810+
libPubspec(
811+
'a',
812+
'1.1.1',
813+
resolutionWorkspace: true,
814+
extras: {
815+
'workspace': ['a'],
816+
},
817+
),
818+
dir(
819+
'a',
820+
[
821+
libPubspec('a', '1.1.1', resolutionWorkspace: true),
822+
],
823+
),
824+
]),
825+
]).create();
826+
final s = p.separator;
827+
await pubGet(
828+
error: '''
829+
Packages can only be included in the workspace once.
830+
831+
`.${s}pkgs/a/pubspec.yaml` is included twice into the workspace of `.${s}pubspec.yaml`''',
795832
environment: {'_PUB_TEST_SDK_VERSION': '3.5.0'},
796833
);
797834
});

0 commit comments

Comments
 (0)