From 073e14ee1c3c3fab6c741b47f3329001d2c74e9f Mon Sep 17 00:00:00 2001 From: Rexios Date: Fri, 17 Jan 2025 13:16:25 -0500 Subject: [PATCH 1/5] Add test --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- test/pub_test.dart | 53 ++++++++++++++++++++++++++++++++------------ test/test_utils.dart | 6 ++++- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb1bd9c..f647a54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.38.2 + +- Does not skip `pub get` in workspace members if the workspace is out of scope + ## 1.38.1 - Fixes FVM version not installed detection diff --git a/pubspec.yaml b/pubspec.yaml index 9bc216a..004f013 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: puby description: Run commands in all projects in the current directory. Handle monorepos with ease. -version: 1.38.1 +version: 1.38.2 homepage: https://github.com/Rexios80/puby environment: diff --git a/test/pub_test.dart b/test/pub_test.dart index 1579d83..ffe7b86 100644 --- a/test/pub_test.dart +++ b/test/pub_test.dart @@ -141,23 +141,48 @@ void main() { }); }); - test('workspace members', () async { - final result = await testCommand( - ['get'], - entities: { - 'pubspec.yaml': workspacePubspec, - ...dartProject(workspace: true), - }, - ); - final stdout = result.stdout; + group('workspace members', () { + test('if workspace in scope', () async { + final result = await testCommand( + ['get'], + entities: { + 'pubspec.yaml': workspacePubspec, + ...dartProject(workspace: true), + }, + ); + final stdout = result.stdout; - expect(result.exitCode, ExitCode.success.code); + expect(result.exitCode, ExitCode.success.code); + + // Pub get should run in the workspace + expectLine( + stdout, + ['Running "dart pub get" in current directory...'], + ); + + // Pub get should NOT run in workspace members + expectLine(stdout, ['dart_puby_test', 'Skip']); + }); + + test('NOT if workspace out of scope', () async { + final result = await testCommand( + ['get'], + entities: { + 'pubspec.yaml': workspacePubspec, + ...dartProject(workspace: true), + }, + workingPath: 'dart_puby_test', + ); + final stdout = result.stdout; - // Pub get should run in the workspace - expectLine(stdout, ['Running "dart pub get" in current directory...']); + expect(result.exitCode, ExitCode.success.code); - // Pub get should NOT run in workspace members - expectLine(stdout, ['dart_puby_test', 'Skip']); + // Pub get should run in the workspace member + expectLine( + stdout, + ['Running "dart pub get" in current directory...'], + ); + }); }); }); }); diff --git a/test/test_utils.dart b/test/test_utils.dart index b308af8..848e01a 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -25,8 +25,12 @@ Future testCommand( Map? entities, bool link = false, bool debug = false, + String workingPath = '', }) async { - final workingDirectory = createTestResources(entities ?? defaultProjects()); + final workingDirectory = path.join( + createTestResources(entities ?? defaultProjects()), + workingPath, + ); final puby = File(path.join('bin', 'puby.dart')).absolute.path; if (link) { From 7c9d4dbfe3b4f1d776e2399ec4343435d2c60f8c Mon Sep 17 00:00:00 2001 From: Rexios Date: Fri, 17 Jan 2025 13:35:14 -0500 Subject: [PATCH 2/5] Do not skip pub get if workspace is out of scope --- bin/projects.dart | 16 ++++++++++++++-- lib/project.dart | 5 +++++ test/link_test.dart | 2 +- test/no_fvm_test.dart | 2 +- test/projects_test.dart | 4 ++-- test/pub_test.dart | 4 ++++ test/test_utils.dart | 14 ++++++-------- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/bin/projects.dart b/bin/projects.dart index 0dbd067..a604bef 100644 --- a/bin/projects.dart +++ b/bin/projects.dart @@ -98,21 +98,29 @@ List findProjects({Directory? directory}) { return packagesMap.keys.cast().toSet(); } + final bool workspaceInScope; if (projectLockFile.existsSync()) { dependencies = dependenciesFromLockFile(projectLockFile); + workspaceInScope = false; } else if (workspaceRefFile.existsSync()) { final workspaceRefContent = workspaceRefFile.readAsStringSync(); final json = jsonDecode(workspaceRefContent) as Map; final workspaceRoot = json['workspaceRoot'] as String; + final absoluteWorkspaceRoot = + p.normalize(p.join(workspaceRefParent, workspaceRoot)); final workspaceLockFile = - File(p.join(workspaceRefParent, workspaceRoot, 'pubspec.lock')); + File(p.join(absoluteWorkspaceRoot, 'pubspec.lock')); if (workspaceLockFile.existsSync()) { dependencies = dependenciesFromLockFile(workspaceLockFile); } else { dependencies = pubspecDependencies; } + + workspaceInScope = + projectIntermediates.containsKey(absoluteWorkspaceRoot); } else { dependencies = pubspecDependencies; + workspaceInScope = false; } final fvm = fvmPaths.any(absolutePath.startsWith); @@ -132,6 +140,7 @@ List findProjects({Directory? directory}) { fvm: fvm, type: type, parentType: parentType, + workspaceInScope: workspaceInScope, ); projects.add(project); @@ -195,8 +204,11 @@ extension ProjectExtension on Project { // Do not skip if parent is a workspace member message = 'Skipping example project: $path'; skip = true; - } else if (isPubGet && type == ProjectType.workspaceMember) { + } else if (isPubGet && + type == ProjectType.workspaceMember && + workspaceInScope) { // Skip pub get in workspace members since they resolve with the workspace + // Unless the workspace is out of scope message = 'Skipping workspace member: $path'; skip = true; } else if (dartRunPackage != null && diff --git a/lib/project.dart b/lib/project.dart index 78816e6..5587bcf 100644 --- a/lib/project.dart +++ b/lib/project.dart @@ -57,6 +57,9 @@ class Project { /// The parent project's type final ProjectType? parentType; + /// If this project's workspace is in scope + final bool workspaceInScope; + /// The arguments to prefix to any commands run in this project List get prefixArgs => [ if (fvm) 'fvm', @@ -75,6 +78,7 @@ class Project { required this.fvm, required this.type, this.parentType, + required this.workspaceInScope, }); /// Create a copy of this [Project] with the specified changes @@ -90,6 +94,7 @@ class Project { fvm: fvm ?? this.fvm, type: type, parentType: parentType, + workspaceInScope: workspaceInScope, ); } } diff --git a/test/link_test.dart b/test/link_test.dart index 1d0cc6f..4862c2d 100644 --- a/test/link_test.dart +++ b/test/link_test.dart @@ -56,7 +56,7 @@ void main() { expect( File( path.join( - result.workingDirectory, + result.testDirectory, 'fvm_puby_test', '.dart_tool', 'version', diff --git a/test/no_fvm_test.dart b/test/no_fvm_test.dart index 393aa03..ca73387 100644 --- a/test/no_fvm_test.dart +++ b/test/no_fvm_test.dart @@ -20,7 +20,7 @@ void main() { expect( File( path.join( - result.workingDirectory, + result.testDirectory, 'fvm_puby_test', '.dart_tool', 'version', diff --git a/test/projects_test.dart b/test/projects_test.dart index 4909b46..942226c 100644 --- a/test/projects_test.dart +++ b/test/projects_test.dart @@ -49,7 +49,7 @@ void main() { ); final dependencies = - findProjects(directory: Directory(result.workingDirectory)) + findProjects(directory: Directory(result.testDirectory)) .first .dependencies; expect(dependencies, contains('rexios_lints')); @@ -91,7 +91,7 @@ void main() { ); final dependencies = - findProjects(directory: Directory(result.workingDirectory)) + findProjects(directory: Directory(result.testDirectory)) .firstWhere((e) => e.type == ProjectType.workspaceMember) .dependencies; expect(dependencies, contains('rexios_lints')); diff --git a/test/pub_test.dart b/test/pub_test.dart index ffe7b86..d073797 100644 --- a/test/pub_test.dart +++ b/test/pub_test.dart @@ -149,6 +149,8 @@ void main() { 'pubspec.yaml': workspacePubspec, ...dartProject(workspace: true), }, + // Must link for workspace ref to exist + link: true, ); final stdout = result.stdout; @@ -172,6 +174,8 @@ void main() { ...dartProject(workspace: true), }, workingPath: 'dart_puby_test', + // Must link for workspace ref to exist + link: true, ); final stdout = result.stdout; diff --git a/test/test_utils.dart b/test/test_utils.dart index 848e01a..c9e2df7 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -7,13 +7,13 @@ import 'package:path/path.dart' as path; final _decoder = Utf8Decoder(); class PubyProcessResult { - final String workingDirectory; + final String testDirectory; final int exitCode; final String stdout; final String stderr; PubyProcessResult( - this.workingDirectory, + this.testDirectory, this.exitCode, this.stdout, this.stderr, @@ -27,10 +27,8 @@ Future testCommand( bool debug = false, String workingPath = '', }) async { - final workingDirectory = path.join( - createTestResources(entities ?? defaultProjects()), - workingPath, - ); + final testDirectory = createTestResources(entities ?? defaultProjects()); + final workingDirectory = path.join(testDirectory, workingPath); final puby = File(path.join('bin', 'puby.dart')).absolute.path; if (link) { @@ -38,7 +36,7 @@ Future testCommand( await Process.run( 'dart', [puby, 'get'], - workingDirectory: workingDirectory, + workingDirectory: testDirectory, ); } @@ -59,7 +57,7 @@ Future testCommand( final exitCode = await process.exitCode; return PubyProcessResult( - workingDirectory, + testDirectory, exitCode, await processStdout, await processStderr, From dbb776be57fdde363f94c1c64d156ce91f8493e9 Mon Sep 17 00:00:00 2001 From: Rexios Date: Fri, 17 Jan 2025 13:52:55 -0500 Subject: [PATCH 3/5] Add test --- test/link_test.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/link_test.dart b/test/link_test.dart index 4862c2d..2f518ea 100644 --- a/test/link_test.dart +++ b/test/link_test.dart @@ -87,5 +87,23 @@ void main() { isNot(contains('Resolved dependencies for dart_puby_test\n')), ); }); + + test('does not skip workspace members if workspace out of scope', () async { + final result = await testCommand( + ['link'], + entities: { + 'pubspec.yaml': workspacePubspec, + ...dartProject(workspace: true), + }, + workingPath: 'dart_puby_test', + // Must link for workspace ref to exist + link: true, + ); + final stdout = result.stdout; + + expect(result.exitCode, ExitCode.success.code); + + expectLine(stdout, ['Resolved dependencies for .']); + }); }); } From f99010e863c7530127738c606a9a98aba9502989 Mon Sep 17 00:00:00 2001 From: Rexios Date: Fri, 17 Jan 2025 13:53:04 -0500 Subject: [PATCH 4/5] Fix test for link command --- bin/link.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/link.dart b/bin/link.dart index 1b1ef40..a835099 100644 --- a/bin/link.dart +++ b/bin/link.dart @@ -22,7 +22,8 @@ Future linkDependencies({ for (final project in projects) { // Skip workspace members (the workspace will resolve them) - if (project.type == ProjectType.workspaceMember) { + if (project.type == ProjectType.workspaceMember && + project.workspaceInScope) { print(yellow.wrap('Skipping workspace member: ${project.path}')); continue; } From ab382e6bbe653bdf1a8d678aba7691e42957dc25 Mon Sep 17 00:00:00 2001 From: Rexios Date: Fri, 17 Jan 2025 13:55:01 -0500 Subject: [PATCH 5/5] Fix test --- test/link_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/link_test.dart b/test/link_test.dart index 2f518ea..8aba6d7 100644 --- a/test/link_test.dart +++ b/test/link_test.dart @@ -75,6 +75,8 @@ void main() { 'pubspec.yaml': workspacePubspec, ...dartProject(workspace: true), }, + // Must link for workspace ref to exist + link: true, ); final stdout = result.stdout;