-
Notifications
You must be signed in to change notification settings - Fork 173
feat(dart_frog_cli): support for Dart workspaces #1825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ce6cbdb
feat(dart_frog_cli): support for Dart workspaces
felangel 0695bdb
chore: update barrel
felangel c1978a3
fix: use workspace lockfile in production build
felangel be60632
chore: adjust comment
felangel 47779f4
chore: regenerate bundle
felangel 46517a3
chore: more doc fixes
felangel d06d4a7
test: fix broken tests and add missing unit tests
felangel d34ad3d
test: add more tests
felangel 63fb96b
more test fixes
felangel acff678
cleanup
felangel b390948
fix coverage
felangel e3db437
chore: coverage
felangel 359538e
revert post_gen changes
felangel eeed72b
ci: use updated workflow
felangel 60031d5
revert ci changes
felangel 08478fd
chore: regenerate bundle
felangel b080916
refactor: go back to lockfiles
felangel 29ed861
cleanup
felangel b7adf48
chore: regen bundle
felangel 22cc6ff
minimize diff
felangel 3d26766
regen bundle
felangel a3b8d81
fix analysis warning
felangel ff77d3b
various fixes
felangel be5d71d
regen bundles
felangel c64b055
refactor: simplify approach
felangel c44d129
chore: remove unnecessary dep
felangel 64f1c28
regen bundle
felangel 776f154
refactor: improve pubspec_overrides handling
felangel 8ada490
more edge case fixes
felangel b3ccf5b
cleanup
felangel fa0834a
Merge branch 'main' into feat/workspaces
felangel 6c110f4
chore: use `VoidCallback`
felangel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
bricks/dart_frog_prod_server/hooks/lib/dart_frog_prod_server_hooks.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| export 'src/create_bundle.dart'; | ||
| export 'src/create_external_packages_folder.dart'; | ||
| export 'src/dart_pub_get.dart'; | ||
| export 'src/disable_workspace_resolution.dart'; | ||
| export 'src/exit_overrides.dart'; | ||
| export 'src/get_internal_path_dependencies.dart'; | ||
| export 'src/get_pubspec_lock.dart'; | ||
| export 'src/uses_workspace_resolution.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
bricks/dart_frog_prod_server/hooks/lib/src/disable_workspace_resolution.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import 'dart:io'; | ||
| import 'package:mason/mason.dart'; | ||
| import 'package:path/path.dart' as path; | ||
| import 'package:yaml/yaml.dart'; | ||
| import 'package:yaml_edit/yaml_edit.dart'; | ||
|
|
||
| /// A void callback function (e.g. `void Function()`). | ||
| typedef VoidCallback = void Function(); | ||
|
|
||
| /// Opts out of dart workspaces until we can generate per package lockfiles. | ||
| /// https://github.com/dart-lang/pub/issues/4594 | ||
| VoidCallback disableWorkspaceResolution( | ||
| HookContext context, { | ||
| required String projectDirectory, | ||
| required void Function(int exitCode) exit, | ||
| }) { | ||
| try { | ||
| return overrideResolutionInPubspecOverrides(projectDirectory); | ||
| } on Exception catch (e) { | ||
| context.logger.err('$e'); | ||
| exit(1); | ||
| return () {}; // no-op | ||
| } | ||
| } | ||
|
|
||
| void Function() overrideResolutionInPubspecOverrides(String projectDirectory) { | ||
| final pubspecOverridesFile = File( | ||
| path.join(projectDirectory, 'pubspec_overrides.yaml'), | ||
| ); | ||
|
|
||
| if (!pubspecOverridesFile.existsSync()) { | ||
| pubspecOverridesFile.writeAsStringSync('resolution: null'); | ||
| return pubspecOverridesFile.deleteSync; | ||
| } | ||
|
|
||
| final contents = pubspecOverridesFile.readAsStringSync(); | ||
| final pubspecOverrides = loadYaml(contents) as YamlMap?; | ||
|
|
||
| if (pubspecOverrides == null) { | ||
| pubspecOverridesFile.writeAsStringSync('resolution: null'); | ||
| return () => pubspecOverridesFile.writeAsStringSync(contents); | ||
| } | ||
|
|
||
| if (pubspecOverrides['resolution'] == 'null') return () {}; // no-op | ||
|
|
||
| final editor = YamlEditor(contents)..update(['resolution'], null); | ||
| pubspecOverridesFile.writeAsStringSync(editor.toString()); | ||
|
|
||
| return () => pubspecOverridesFile.writeAsStringSync(contents); | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
bricks/dart_frog_prod_server/hooks/lib/src/uses_workspace_resolution.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import 'dart:io'; | ||
| import 'package:mason/mason.dart'; | ||
| import 'package:path/path.dart' as path; | ||
| import 'package:yaml/yaml.dart'; | ||
|
|
||
| /// Determines whether the project in the provided [workingDirectory] | ||
| /// is configured to use `resolution: workspace`. | ||
| bool usesWorkspaceResolution( | ||
| HookContext context, { | ||
| required String workingDirectory, | ||
| required void Function(int exitCode) exit, | ||
| }) { | ||
| final pubspecFile = File(path.join(workingDirectory, 'pubspec.yaml')); | ||
| if (!pubspecFile.existsSync()) return false; | ||
|
|
||
| final YamlMap pubspec; | ||
| try { | ||
| final yaml = loadYaml(pubspecFile.readAsStringSync()); | ||
| if (yaml is! YamlMap) { | ||
| throw Exception('Unable to parse ${pubspecFile.path}'); | ||
| } | ||
| pubspec = yaml; | ||
| } on Exception catch (e) { | ||
| context.logger.err('$e'); | ||
| exit(1); | ||
| return false; | ||
| } | ||
|
|
||
| return pubspec['resolution'] == 'workspace'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.