Skip to content

Commit

Permalink
Don't iterate above the root dir when finding stray pubspecs (dart-la…
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm committed Dec 16, 2024
1 parent 8727c85 commit f383ae1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ packages:
dependency: transitive
description: dart
source: sdk
version: "0.3.3"
version: "0.3.2"
analyzer:
dependency: "direct main"
description:
Expand Down Expand Up @@ -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:
Expand Down
66 changes: 66 additions & 0 deletions test/workspace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit f383ae1

Please sign in to comment.