Skip to content
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

feat: Expose pub get's --offline flag on the bootstrap command #756

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading