Skip to content

Commit 6269da1

Browse files
authored
Merge pull request #13 from Rexios80/feature/workspace-out-of-scope
Feature/workspace out of scope
2 parents 7a21e12 + ab382e6 commit 6269da1

File tree

10 files changed

+100
-27
lines changed

10 files changed

+100
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.38.2
2+
3+
- Does not skip `pub get` in workspace members if the workspace is out of scope
4+
15
## 1.38.1
26

37
- Fixes FVM version not installed detection

bin/link.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Future<int> linkDependencies({
2222

2323
for (final project in projects) {
2424
// Skip workspace members (the workspace will resolve them)
25-
if (project.type == ProjectType.workspaceMember) {
25+
if (project.type == ProjectType.workspaceMember &&
26+
project.workspaceInScope) {
2627
print(yellow.wrap('Skipping workspace member: ${project.path}'));
2728
continue;
2829
}

bin/projects.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,29 @@ List<Project> findProjects({Directory? directory}) {
9898
return packagesMap.keys.cast<String>().toSet();
9999
}
100100

101+
final bool workspaceInScope;
101102
if (projectLockFile.existsSync()) {
102103
dependencies = dependenciesFromLockFile(projectLockFile);
104+
workspaceInScope = false;
103105
} else if (workspaceRefFile.existsSync()) {
104106
final workspaceRefContent = workspaceRefFile.readAsStringSync();
105107
final json = jsonDecode(workspaceRefContent) as Map<String, dynamic>;
106108
final workspaceRoot = json['workspaceRoot'] as String;
109+
final absoluteWorkspaceRoot =
110+
p.normalize(p.join(workspaceRefParent, workspaceRoot));
107111
final workspaceLockFile =
108-
File(p.join(workspaceRefParent, workspaceRoot, 'pubspec.lock'));
112+
File(p.join(absoluteWorkspaceRoot, 'pubspec.lock'));
109113
if (workspaceLockFile.existsSync()) {
110114
dependencies = dependenciesFromLockFile(workspaceLockFile);
111115
} else {
112116
dependencies = pubspecDependencies;
113117
}
118+
119+
workspaceInScope =
120+
projectIntermediates.containsKey(absoluteWorkspaceRoot);
114121
} else {
115122
dependencies = pubspecDependencies;
123+
workspaceInScope = false;
116124
}
117125

118126
final fvm = fvmPaths.any(absolutePath.startsWith);
@@ -132,6 +140,7 @@ List<Project> findProjects({Directory? directory}) {
132140
fvm: fvm,
133141
type: type,
134142
parentType: parentType,
143+
workspaceInScope: workspaceInScope,
135144
);
136145

137146
projects.add(project);
@@ -195,8 +204,11 @@ extension ProjectExtension on Project {
195204
// Do not skip if parent is a workspace member
196205
message = 'Skipping example project: $path';
197206
skip = true;
198-
} else if (isPubGet && type == ProjectType.workspaceMember) {
207+
} else if (isPubGet &&
208+
type == ProjectType.workspaceMember &&
209+
workspaceInScope) {
199210
// Skip pub get in workspace members since they resolve with the workspace
211+
// Unless the workspace is out of scope
200212
message = 'Skipping workspace member: $path';
201213
skip = true;
202214
} else if (dartRunPackage != null &&

lib/project.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class Project {
5757
/// The parent project's type
5858
final ProjectType? parentType;
5959

60+
/// If this project's workspace is in scope
61+
final bool workspaceInScope;
62+
6063
/// The arguments to prefix to any commands run in this project
6164
List<String> get prefixArgs => [
6265
if (fvm) 'fvm',
@@ -75,6 +78,7 @@ class Project {
7578
required this.fvm,
7679
required this.type,
7780
this.parentType,
81+
required this.workspaceInScope,
7882
});
7983

8084
/// Create a copy of this [Project] with the specified changes
@@ -90,6 +94,7 @@ class Project {
9094
fvm: fvm ?? this.fvm,
9195
type: type,
9296
parentType: parentType,
97+
workspaceInScope: workspaceInScope,
9398
);
9499
}
95100
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: puby
22
description: Run commands in all projects in the current directory. Handle monorepos with ease.
3-
version: 1.38.1
3+
version: 1.38.2
44
homepage: https://github.com/Rexios80/puby
55

66
environment:

test/link_test.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void main() {
5656
expect(
5757
File(
5858
path.join(
59-
result.workingDirectory,
59+
result.testDirectory,
6060
'fvm_puby_test',
6161
'.dart_tool',
6262
'version',
@@ -75,6 +75,8 @@ void main() {
7575
'pubspec.yaml': workspacePubspec,
7676
...dartProject(workspace: true),
7777
},
78+
// Must link for workspace ref to exist
79+
link: true,
7880
);
7981
final stdout = result.stdout;
8082

@@ -87,5 +89,23 @@ void main() {
8789
isNot(contains('Resolved dependencies for dart_puby_test\n')),
8890
);
8991
});
92+
93+
test('does not skip workspace members if workspace out of scope', () async {
94+
final result = await testCommand(
95+
['link'],
96+
entities: {
97+
'pubspec.yaml': workspacePubspec,
98+
...dartProject(workspace: true),
99+
},
100+
workingPath: 'dart_puby_test',
101+
// Must link for workspace ref to exist
102+
link: true,
103+
);
104+
final stdout = result.stdout;
105+
106+
expect(result.exitCode, ExitCode.success.code);
107+
108+
expectLine(stdout, ['Resolved dependencies for .']);
109+
});
90110
});
91111
}

test/no_fvm_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void main() {
2020
expect(
2121
File(
2222
path.join(
23-
result.workingDirectory,
23+
result.testDirectory,
2424
'fvm_puby_test',
2525
'.dart_tool',
2626
'version',

test/projects_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void main() {
4949
);
5050

5151
final dependencies =
52-
findProjects(directory: Directory(result.workingDirectory))
52+
findProjects(directory: Directory(result.testDirectory))
5353
.first
5454
.dependencies;
5555
expect(dependencies, contains('rexios_lints'));
@@ -91,7 +91,7 @@ void main() {
9191
);
9292

9393
final dependencies =
94-
findProjects(directory: Directory(result.workingDirectory))
94+
findProjects(directory: Directory(result.testDirectory))
9595
.firstWhere((e) => e.type == ProjectType.workspaceMember)
9696
.dependencies;
9797
expect(dependencies, contains('rexios_lints'));

test/pub_test.dart

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,52 @@ void main() {
141141
});
142142
});
143143

144-
test('workspace members', () async {
145-
final result = await testCommand(
146-
['get'],
147-
entities: {
148-
'pubspec.yaml': workspacePubspec,
149-
...dartProject(workspace: true),
150-
},
151-
);
152-
final stdout = result.stdout;
144+
group('workspace members', () {
145+
test('if workspace in scope', () async {
146+
final result = await testCommand(
147+
['get'],
148+
entities: {
149+
'pubspec.yaml': workspacePubspec,
150+
...dartProject(workspace: true),
151+
},
152+
// Must link for workspace ref to exist
153+
link: true,
154+
);
155+
final stdout = result.stdout;
153156

154-
expect(result.exitCode, ExitCode.success.code);
157+
expect(result.exitCode, ExitCode.success.code);
158+
159+
// Pub get should run in the workspace
160+
expectLine(
161+
stdout,
162+
['Running "dart pub get" in current directory...'],
163+
);
164+
165+
// Pub get should NOT run in workspace members
166+
expectLine(stdout, ['dart_puby_test', 'Skip']);
167+
});
168+
169+
test('NOT if workspace out of scope', () async {
170+
final result = await testCommand(
171+
['get'],
172+
entities: {
173+
'pubspec.yaml': workspacePubspec,
174+
...dartProject(workspace: true),
175+
},
176+
workingPath: 'dart_puby_test',
177+
// Must link for workspace ref to exist
178+
link: true,
179+
);
180+
final stdout = result.stdout;
155181

156-
// Pub get should run in the workspace
157-
expectLine(stdout, ['Running "dart pub get" in current directory...']);
182+
expect(result.exitCode, ExitCode.success.code);
158183

159-
// Pub get should NOT run in workspace members
160-
expectLine(stdout, ['dart_puby_test', 'Skip']);
184+
// Pub get should run in the workspace member
185+
expectLine(
186+
stdout,
187+
['Running "dart pub get" in current directory...'],
188+
);
189+
});
161190
});
162191
});
163192
});

test/test_utils.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import 'package:path/path.dart' as path;
77
final _decoder = Utf8Decoder();
88

99
class PubyProcessResult {
10-
final String workingDirectory;
10+
final String testDirectory;
1111
final int exitCode;
1212
final String stdout;
1313
final String stderr;
1414

1515
PubyProcessResult(
16-
this.workingDirectory,
16+
this.testDirectory,
1717
this.exitCode,
1818
this.stdout,
1919
this.stderr,
@@ -25,16 +25,18 @@ Future<PubyProcessResult> testCommand(
2525
Map<String, Object>? entities,
2626
bool link = false,
2727
bool debug = false,
28+
String workingPath = '',
2829
}) async {
29-
final workingDirectory = createTestResources(entities ?? defaultProjects());
30+
final testDirectory = createTestResources(entities ?? defaultProjects());
31+
final workingDirectory = path.join(testDirectory, workingPath);
3032
final puby = File(path.join('bin', 'puby.dart')).absolute.path;
3133

3234
if (link) {
3335
// puby link was not working in the test environment
3436
await Process.run(
3537
'dart',
3638
[puby, 'get'],
37-
workingDirectory: workingDirectory,
39+
workingDirectory: testDirectory,
3840
);
3941
}
4042

@@ -55,7 +57,7 @@ Future<PubyProcessResult> testCommand(
5557

5658
final exitCode = await process.exitCode;
5759
return PubyProcessResult(
58-
workingDirectory,
60+
testDirectory,
5961
exitCode,
6062
await processStdout,
6163
await processStderr,

0 commit comments

Comments
 (0)