diff --git a/lib/src/package.dart b/lib/src/package.dart index e1e9f31e5..2bbd0c6b2 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -474,7 +474,10 @@ Package `$override` at `${overriddenWorkspacePackage.presentationDir}` is overri // By adding this to visited we will never go above the workspaceRoot.dir. p.canonicalize(root.dir), }; - for (final package in root.transitiveWorkspace) { + for (final package in root.transitiveWorkspace + // We don't want to look at the roots parents. The first package is always + // the root, so skip that. + .skip(1)) { // Run through all parent directories until we meet another workspace // package. for (final dir in parentDirs(package.dir).skip(1)) { diff --git a/pubspec.lock b/pubspec.lock index 85bff242b..95ad99caf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,7 +13,7 @@ packages: dependency: transitive description: dart source: sdk - version: "0.3.3" + version: "0.3.2" analyzer: dependency: "direct main" description: @@ -194,10 +194,10 @@ packages: dependency: transitive description: name: macros - sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656" + sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" url: "https://pub.dev" source: hosted - version: "0.1.3-main.0" + version: "0.1.2-main.4" matcher: dependency: transitive description: diff --git a/test/workspace_test.dart b/test/workspace_test.dart index 171ba7d07..94ce826ab 100644 --- a/test/workspace_test.dart +++ b/test/workspace_test.dart @@ -1491,6 +1491,72 @@ Consider removing one of the overrides.''', ); }); + test( + 'rejects workspace with non-workspace between root and workspace package', + () async { + await dir(appPath, [ + libPubspec( + 'myapp', + '1.2.3', + extras: { + 'workspace': ['pkgs/a'], + }, + sdk: '^3.5.0', + ), + dir('pkgs', [ + libPubspec( + 'in_the_way', + '1.0.0', + ), + dir('a', [ + libPubspec( + 'a', + '1.0.0', + resolutionWorkspace: true, + ), + ]), + ]), + ]).create(); + await pubGet( + environment: {'_PUB_TEST_SDK_VERSION': '3.5.0'}, + error: contains( + 'The file `.${s}pkgs${s}pubspec.yaml` is located in a directory ' + 'between the workspace root at', + ), + ); + }); + + test('Doesn\t complain about pubspecs above the workspace', () async { + // Regression test for https://github.com/dart-lang/pub/issues/4463 + await dir(appPath, [ + libPubspec( + 'not_in_the_way', + '1.0.0', + ), + dir('pkgs', [ + libPubspec( + 'myapp', + '1.2.3', + extras: { + 'workspace': ['a'], + }, + sdk: '^3.5.0', + ), + dir('a', [ + libPubspec( + 'a', + '1.0.0', + resolutionWorkspace: true, + ), + ]), + ]), + ]).create(); + await pubGet( + environment: {'_PUB_TEST_SDK_VERSION': '3.5.0'}, + workingDirectory: p.join(sandbox, appPath, 'pkgs'), + ); + }); + test('overrides are applied', () async { final server = await servePackages(); server.serve('foo', '1.0.0');