bootstrap method

Future<void> bootstrap({
  1. GlobalOptions? global,
  2. PackageFilters? packageFilters,
  3. bool noExample = false,
  4. bool enforceLockfile = false,
  5. bool skipLinking = false,
})
inherited

Implementation

Future<void> bootstrap({
  GlobalOptions? global,
  PackageFilters? packageFilters,
  bool noExample = false,
  bool enforceLockfile = false,
  bool skipLinking = false,
}) async {
  final workspace =
      await createWorkspace(global: global, packageFilters: packageFilters);

  return _runLifecycle(
    workspace,
    CommandWithLifecycle.bootstrap,
    () async {
      final bootstrapCommandConfig = workspace.config.commands.bootstrap;
      late final hasLockFile =
          File(p.join(workspace.path, 'pubspec.lock')).existsSync();
      final enforceLockfileConfigValue =
          workspace.config.commands.bootstrap.enforceLockfile;
      final shouldEnforceLockfile =
          (enforceLockfileConfigValue || enforceLockfile) && hasLockFile;

      final pubCommandForLogging = [
        ...pubCommandExecArgs(
          useFlutter: workspace.isFlutterWorkspace,
          workspace: workspace,
        ),
        'get',
        if (noExample) '--no-example',
        if (bootstrapCommandConfig.runPubGetOffline) '--offline',
        if (shouldEnforceLockfile) '--enforce-lockfile',
      ].join(' ');

      logger
        ..command('melos bootstrap')
        ..child(targetStyle(workspace.path))
        ..newLine();

      if (!utils.isCI && workspace.filteredPackages.keys.length > 20) {
        logger.warning(
          'Note: this may take a while in large workspaces such as this one.',
          label: false,
        );
      }

      try {
        if (bootstrapCommandConfig.environment != null ||
            bootstrapCommandConfig.dependencies != null ||
            bootstrapCommandConfig.devDependencies != null) {
          logger.log('Updating common dependencies in workspace packages...');

          final filteredPackages = workspace.filteredPackages.values;
          await Stream.fromIterable(filteredPackages).parallel((package) {
            return _setSharedDependenciesForPackage(
              package,
              environment: bootstrapCommandConfig.environment,
              dependencies: bootstrapCommandConfig.dependencies,
              devDependencies: bootstrapCommandConfig.devDependencies,
            );
          }).drain<void>();

          logger
            ..child(successLabel, prefix: '> ')
            ..newLine();
        }

        if (!skipLinking) {
          logger.log(
            'Running "$pubCommandForLogging" in workspace packages...',
          );

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

          logger
            ..child(successLabel, prefix: '> ')
            ..newLine();
        }
      } on BootstrapException catch (exception) {
        _logBootstrapException(exception, workspace);
        rethrow;
      }

      if (workspace.config.ide.intelliJ.enabled) {
        logger.log('Generating IntelliJ IDE files...');

        await cleanIntelliJ(workspace);
        await workspace.ide.intelliJ.generate();
        logger
          ..child(successLabel, prefix: '> ')
          ..newLine();
      }
      logger.log(
        ' -> ${workspace.filteredPackages.length} packages bootstrapped',
      );
    },
  );
}