diff --git a/lib/src/package.dart b/lib/src/package.dart index 4edf7e524..e29088997 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -513,7 +513,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 9539fb96f..5e5212c0d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,23 +5,23 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - sha256: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab" + sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77" url: "https://pub.dev" source: hosted - version: "76.0.0" + version: "73.0.0" _macros: dependency: transitive description: dart source: sdk - version: "0.3.3" + version: "0.3.2" analyzer: dependency: "direct main" description: name: analyzer - sha256: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e" + sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a" url: "https://pub.dev" source: hosted - version: "6.11.0" + version: "6.8.0" args: 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');