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: Allow overriding enforceLockfile with --no-enforce-lockfile #758

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
9 changes: 6 additions & 3 deletions docs/commands/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,20 @@ melos bootstrap --diff="main"

## Bootstrap flags

- The `--no-example` flag is used to exclude flutter package's example's dependencies (https://github.com/dart-lang/pub/pull/3856)
- The `--no-example` flag is used to exclude flutter package's example's dependencies
(https://github.com/dart-lang/pub/pull/3856)
- This will run `pub get` with the `--no-example` flag.
- 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 `--no-enforce-lockfile` flag is used to disregard versions from `.lock` files if
`enforce-lockfile` is configured in the `melos.yaml` file.
- 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
your `melos.yaml` file.
In addition to the above flags, the `melos bootstrap` command supports a few different flags that
can be defined in your `melos.yaml` file.


### Shared dependencies
Expand Down
9 changes: 7 additions & 2 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,17 @@ The default is `false`.

### enforceLockfile

Whether to run `pub get` with the `--enforce-lockfile` option or not, to force getting the versions specified in the `pubspec.lock` file.
Whether to run `pub get` with the `--enforce-lockfile` option or not, to force getting the versions
specified in the `pubspec.lock` file.

This is useful in CI environments or when you want to ensure that all environments/machines are using the same package versions.
This is useful in CI environments or when you want to ensure that all environments/machines are
using the same package versions.

The default is `false`.

To temporarily override this `melos bootstrap --no-enforce-lockfile / --enforce-lockfile` can be
used.

## command/version

Configuration for the `version` command.
Expand Down
9 changes: 5 additions & 4 deletions packages/melos/lib/src/command_runner/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class BootstrapCommand extends MelosCommand {
);
argParser.addFlag(
'enforce-lockfile',
negatable: false,
help: 'Run pub get with --enforce-lockfile to enforce versions from .lock'
' files, ensure .lockfile exist for all packages.',
help: 'Run pub get with --enforce-lockfile to enforce versions from '
'.lock files, ensure .lockfile exist for all packages.\n'
'--no-enforce-lockfile can be used to temporarily disregard the '
'lockfile versions.',
);
argParser.addFlag(
'skip-linking',
Expand Down Expand Up @@ -47,7 +48,7 @@ class BootstrapCommand extends MelosCommand {
return melos.bootstrap(
global: global,
packageFilters: parsePackageFilters(config.path),
enforceLockfile: argResults?['enforce-lockfile'] as bool? ?? false,
enforceLockfile: argResults?['enforce-lockfile'] as bool?,
noExample: argResults?['no-example'] as bool,
skipLinking: argResults?['skip-linking'] as bool,
offline: argResults?['offline'] as bool,
Expand Down
6 changes: 3 additions & 3 deletions packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mixin _BootstrapMixin on _CleanMixin {
GlobalOptions? global,
PackageFilters? packageFilters,
bool noExample = false,
bool enforceLockfile = false,
bool? enforceLockfile,
bool skipLinking = false,
bool offline = false,
}) async {
Expand All @@ -23,7 +23,7 @@ mixin _BootstrapMixin on _CleanMixin {
final enforceLockfileConfigValue =
workspace.config.commands.bootstrap.enforceLockfile;
final shouldEnforceLockfile =
(enforceLockfileConfigValue || enforceLockfile) && hasLockFile;
(enforceLockfile ?? enforceLockfileConfigValue) && hasLockFile;

final pubCommandForLogging = [
...pubCommandExecArgs(
Expand Down Expand Up @@ -76,7 +76,7 @@ mixin _BootstrapMixin on _CleanMixin {

await _linkPackagesWithPubspecOverrides(
workspace,
enforceLockfile: enforceLockfile,
enforceLockfile: shouldEnforceLockfile,
noExample: noExample,
);

Expand Down
58 changes: 58 additions & 0 deletions packages/melos/test/commands/bootstrap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,62 @@ melos bootstrap
Running "${pubExecArgs.join(' ')} get --enforce-lockfile" in workspace packages...
> SUCCESS

Generating IntelliJ IDE files...
> SUCCESS

-> 0 packages bootstrapped
''',
),
);
});

test('can run pub get --no-enforce-lockfile when enforced in config',
() async {
final workspaceDir = await createTemporaryWorkspace(
configBuilder: (path) => MelosWorkspaceConfig.fromYaml(
createYamlMap(
{
'command': {
'bootstrap': {
'enforceLockfile': true,
},
},
},
defaults: configMapDefaults,
),
path: path,
),
createLockfile: true,
);

final logger = TestLogger();
final config = await MelosWorkspaceConfig.fromWorkspaceRoot(workspaceDir);
final workspace = await MelosWorkspace.fromConfig(
config,
logger: logger.toMelosLogger(),
);
final melos = Melos(logger: logger, config: config);
final pubExecArgs = pubCommandExecArgs(
useFlutter: workspace.isFlutterWorkspace,
workspace: workspace,
);

await runMelosBootstrap(
melos,
logger,
enforceLockfile: false,
);

expect(
logger.output,
ignoringAnsii(
'''
melos bootstrap
└> ${workspaceDir.path}

Running "${pubExecArgs.join(' ')} get" in workspace packages...
> SUCCESS

Generating IntelliJ IDE files...
> SUCCESS

Expand Down Expand Up @@ -979,11 +1035,13 @@ Future<void> runMelosBootstrap(
Melos melos,
TestLogger logger, {
bool skipLinking = false,
bool? enforceLockfile,
bool offline = false,
}) async {
try {
await melos.bootstrap(
skipLinking: skipLinking,
enforceLockfile: enforceLockfile,
offline: offline,
);
} on BootstrapException {
Expand Down
Loading