Skip to content

Commit 58de642

Browse files
authored
Don't iterate above the root dir when finding stray pubspecs (#4469)
1 parent 7745ee7 commit 58de642

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

lib/src/package.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,10 @@ Package `$override` at `${overriddenWorkspacePackage.presentationDir}` is overri
513513
// By adding this to visited we will never go above the workspaceRoot.dir.
514514
p.canonicalize(root.dir),
515515
};
516-
for (final package in root.transitiveWorkspace) {
516+
for (final package in root.transitiveWorkspace
517+
// We don't want to look at the roots parents. The first package is always
518+
// the root, so skip that.
519+
.skip(1)) {
517520
// Run through all parent directories until we meet another workspace
518521
// package.
519522
for (final dir in parentDirs(package.dir).skip(1)) {

pubspec.lock

+7-7
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: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab"
8+
sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77"
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "76.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: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e"
21+
sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a"
2222
url: "https://pub.dev"
2323
source: hosted
24-
version: "6.11.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

+66
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,72 @@ Consider removing one of the overrides.''',
14911491
);
14921492
});
14931493

1494+
test(
1495+
'rejects workspace with non-workspace between root and workspace package',
1496+
() async {
1497+
await dir(appPath, [
1498+
libPubspec(
1499+
'myapp',
1500+
'1.2.3',
1501+
extras: {
1502+
'workspace': ['pkgs/a'],
1503+
},
1504+
sdk: '^3.5.0',
1505+
),
1506+
dir('pkgs', [
1507+
libPubspec(
1508+
'in_the_way',
1509+
'1.0.0',
1510+
),
1511+
dir('a', [
1512+
libPubspec(
1513+
'a',
1514+
'1.0.0',
1515+
resolutionWorkspace: true,
1516+
),
1517+
]),
1518+
]),
1519+
]).create();
1520+
await pubGet(
1521+
environment: {'_PUB_TEST_SDK_VERSION': '3.5.0'},
1522+
error: contains(
1523+
'The file `.${s}pkgs${s}pubspec.yaml` is located in a directory '
1524+
'between the workspace root at',
1525+
),
1526+
);
1527+
});
1528+
1529+
test('Doesn\t complain about pubspecs above the workspace', () async {
1530+
// Regression test for https://github.com/dart-lang/pub/issues/4463
1531+
await dir(appPath, [
1532+
libPubspec(
1533+
'not_in_the_way',
1534+
'1.0.0',
1535+
),
1536+
dir('pkgs', [
1537+
libPubspec(
1538+
'myapp',
1539+
'1.2.3',
1540+
extras: {
1541+
'workspace': ['a'],
1542+
},
1543+
sdk: '^3.5.0',
1544+
),
1545+
dir('a', [
1546+
libPubspec(
1547+
'a',
1548+
'1.0.0',
1549+
resolutionWorkspace: true,
1550+
),
1551+
]),
1552+
]),
1553+
]).create();
1554+
await pubGet(
1555+
environment: {'_PUB_TEST_SDK_VERSION': '3.5.0'},
1556+
workingDirectory: p.join(sandbox, appPath, 'pkgs'),
1557+
);
1558+
});
1559+
14941560
test('overrides are applied', () async {
14951561
final server = await servePackages();
14961562
server.serve('foo', '1.0.0');

0 commit comments

Comments
 (0)