Skip to content

Commit

Permalink
feat: Expose pub get's --offline flag on the bootstrap command (#756
Browse files Browse the repository at this point in the history
)

<!--
  Thanks for contributing!

Provide a description of your changes below and a general summary in the
title

Please look at the following checklist to ensure that your PR can be
accepted quickly:
-->

## Description

Adds the `--offline` flag to the bootstrap command.

Fixes: #714 

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [x] ✨ `feat` -- New feature (non-breaking change which adds
functionality)
- [ ] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 `refactor` -- Code refactor
- [ ] ✅ `ci` -- Build configuration change
- [ ] 📝 `docs` -- Documentation
- [ ] 🗑️ `chore` -- Chore
  • Loading branch information
spydon authored Oct 7, 2024
1 parent af46c7e commit b432749
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/commands/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ melos bootstrap --diff="main"
- The `--enforce-lockfile` flag is used to enforce versions from `.lock` files.
- Ensure .lock files exist, as failure may occur if they're not checked in.
- The `--skip-linking` flag is used to skip the local linking of workspace packages.
- The `--offline` flag is used to only resolve dependencies from the local cache by running
`pub get` with the `--offline` flag.


In addition to the above flags, the `melos bootstrap` command supports a few different flags that can be defined in
Expand Down
7 changes: 7 additions & 0 deletions packages/melos/lib/src/command_runner/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class BootstrapCommand extends MelosCommand {
negatable: false,
help: 'Skips locally linking workspace packages.',
);
argParser.addFlag(
'offline',
negatable: false,
help: 'Run pub get with --offline to resolve dependencies from local '
'cache.',
);
}

@override
Expand All @@ -44,6 +50,7 @@ class BootstrapCommand extends MelosCommand {
enforceLockfile: argResults?['enforce-lockfile'] as bool? ?? false,
noExample: argResults?['no-example'] as bool,
skipLinking: argResults?['skip-linking'] as bool,
offline: argResults?['offline'] as bool,
);
}
}
4 changes: 3 additions & 1 deletion packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mixin _BootstrapMixin on _CleanMixin {
bool noExample = false,
bool enforceLockfile = false,
bool skipLinking = false,
bool offline = false,
}) async {
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);
Expand All @@ -16,6 +17,7 @@ mixin _BootstrapMixin on _CleanMixin {
CommandWithLifecycle.bootstrap,
() async {
final bootstrapCommandConfig = workspace.config.commands.bootstrap;
final runOffline = bootstrapCommandConfig.runPubGetOffline || offline;
late final hasLockFile =
File(p.join(workspace.path, 'pubspec.lock')).existsSync();
final enforceLockfileConfigValue =
Expand All @@ -30,7 +32,7 @@ mixin _BootstrapMixin on _CleanMixin {
),
'get',
if (noExample) '--no-example',
if (bootstrapCommandConfig.runPubGetOffline) '--offline',
if (runOffline) '--offline',
if (shouldEnforceLockfile) '--enforce-lockfile',
].join(' ');

Expand Down
42 changes: 41 additions & 1 deletion packages/melos/test/commands/bootstrap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,42 @@ Updating common dependencies in workspace packages...
└> Updated environment
> SUCCESS
Generating IntelliJ IDE files...
> SUCCESS
-> 1 packages bootstrapped
''',
),
);
});
});

group('melos bs --offline', () {
test('should run pub get with --offline', () async {
final workspaceDir = await createTemporaryWorkspace();
await createProject(
workspaceDir,
const PubSpec(name: 'a'),
);

final logger = TestLogger();
final config = await MelosWorkspaceConfig.fromWorkspaceRoot(workspaceDir);
final melos = Melos(logger: logger, config: config);

await runMelosBootstrap(melos, logger, offline: true);

expect(
logger.output,
ignoringAnsii(
'''
melos bootstrap
└> ${workspaceDir.path}
Running "dart pub get --offline" in workspace packages...
✓ a
└> packages/a
> SUCCESS
Generating IntelliJ IDE files...
> SUCCESS
Expand All @@ -943,9 +979,13 @@ Future<void> runMelosBootstrap(
Melos melos,
TestLogger logger, {
bool skipLinking = false,
bool offline = false,
}) async {
try {
await melos.bootstrap(skipLinking: skipLinking);
await melos.bootstrap(
skipLinking: skipLinking,
offline: offline,
);
} on BootstrapException {
// ignore: avoid_print
print(logger.output);
Expand Down

0 comments on commit b432749

Please sign in to comment.