Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias authored Feb 28, 2024
2 parents 62980b9 + da62390 commit 143a6f6
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 139 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@
"contributions": [
"doc"
]
},
{
"login": "Bassiuz",
"name": "Bas de Vaan",
"avatar_url": "https://avatars.githubusercontent.com/u/8895636?v=4",
"profile": "https://github.com/Bassiuz",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 5,
Expand Down
22 changes: 2 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ on:
- "docs/**"
- "README.md"
- "CHANGELOG.md"
- ".github/**"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down Expand Up @@ -44,15 +43,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run DCM
uses: CQLabs/dcm-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
ci_key: oss
email: oss
folders: .
fatal_style: true
fatal_performance: true
fatal_warnings: true
run: dcm analyze lib

- name: Install lcov
run: sudo apt-get install lcov
Expand Down Expand Up @@ -87,13 +78,4 @@ jobs:
sdk-version: ${{ github.event.inputs.sdk-version }}

- name: Tests
uses: ./.github/actions/test

linkinator:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: JustinBeckwith/linkinator-action@v1
with:
concurrency: 3
markdown: true
uses: ./.github/actions/test
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.0.12

* Adds skipping version mismatch handling when using force or running with a custom fvm version. [#653](https://github.com/leoafarias/fvm/issues/653)
* Fixes parsing error of vscode settings when there are commas [#656](https://github.com/leoafarias/fvm/issues/656)
* Sets global as first default if Dart SDK is not found in the project.

## 3.0.11

* Removed `fvm update` command. Due to issue with brew and chocolatey install.
Expand Down
122 changes: 61 additions & 61 deletions docs/pages/documentation/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,81 @@ title: Configuration
---

import { Callout } from "nextra/components";
import { FileTree } from "nextra/components";

# Configuration

Configure FVM and IDEs for better support for different development environments.

## Project

FVM will create a relative symlink in your project from `.fvm/flutter_sdk` to the cache of the selected version. Add it to your `.gitignore`
There are two main parts for a project that has FVM configured. The `.fvmrc config file and the `.fvm` directory.

```yaml title=".gitignore"
.fvm/flutter_sdk
```

## FVM

### Cache Directory

You can configure the **fvm** cache directory by setting `FVM_HOME` environment variable. If nothing is set the default **fvm** path will be used. You are also able to change the directory by setting the `--cache-path` on the config. See below

### Config

There are some configurations which you can change on FVM. **All settings set on CLI are compatible with the Sidekick(GUI)**.
### Config File `.fvmrc`

### Different Flutter Repo
This contains version linked to the project. This file is automatically created when you run `fvm use {version}`. Here you can also find project specific settings, and flavors.

You can use a different Flutter repo, a fork or as a local cache, by setting the `FVM_GIT_CACHE` environment variable.

#### List config

```bash
> fvm config
```json
{
"flutter": "3.19.1",
"flavors": {
"development": "beta",
"production": "3.19.1"
},
"updateVscodeSettings": true,
"updateGitIgnore": true,
"runPubGetOnSdkChanges": true
}
```

#### Set cache path

Location where Flutter SDK versions will be stored. If nothing is set, the default will be used.

```bash
> fvm config --cache-path <CACHE_PATH>
```

## IDE

<Callout>
You might have to restart your IDE and the Flutter debugger to make sure it
uses the latest version of the configurations in some situations.
- `flutter`: The version of the Flutter SDK to be used, falling back to the flutter value if not explicitly set.
- `cachePath`: Defines the path to the project's cache directory.
- `useGitCache`: (default: true) Indicates whether the Git cache is used for dependencies.
- `gitCachePath`: Sets the path to the Git cache directory, applicable if useGitCache is true.
- `flutterUrl`: Specifies the URL to the Flutter SDK repository.
- `priviledgedAccess`:(default: true) Determines if configurations requiring elevated permissions are enabled.
- `flavors`: A map defining custom project flavors for different configurations.
- `updateVscodeSettings`: (default: true) Flags whether to auto-update VS Code settings on configuration changes.
- `updateGitIgnore`: (default:true) Indicates whether to auto-update the .gitignore file based on project configurations.
- `runPubGetOnSdkChanges`: (default: true) Triggers flutter pub get automatically upon Flutter SDK version changes.

### .fvm Directory

Inside the directory you will find the following files and directories:

<FileTree>
<FileTree.Folder name=".fvm" defaultOpen>
<FileTree.Folder name="versions" defaultOpen>
<FileTree.File name="stable" />
<FileTree.File name="beta" />
<FileTree.File name="3.19.1" />
</FileTree.Folder>
<FileTree.Folder name="flutter_sdk" />
<FileTree.File name="release" />
<FileTree.File name="version" />
</FileTree.Folder>
</FileTree>

- **flutter_sdk** - Symlink to the Flutter SDK version linked to the project.
- **versions** - Directory containing the Flutter SDK versions. This is similar to flutter_sdk, but is used for better VsCode compatibility.
- **fvm_config.json** - (deprecated) This is a legacy configuration file.
- **release** - (internal use only) File containing the release version of FVM.
- **version** - (internal use only) File containing the version of FVM.

<Callout type="info">
Starting version 3.0 and above it is recommended to add the `.fvm` directory
to your `.gitignore` file. FVM will automatically add it to .gitignore when
pinning a version to a project, if `updateGitIgnore` is set to `true`.
</Callout>

### Android Studio

1. Go to `Languages & Frameworks > Flutter` or search for Flutter and change Flutter SDK path.
2. Copy the **_absolute_** path of fvm symbolic link in your root project directory. Example: `/absolute-project-path/.fvm/flutter_sdk`
3. Apply the changes.
4. Restart Android Studio to see the new settings applied.

<Callout type="warning">
For Android Studio to detect the dynamic change of SDKs, the installed SDK must have finished setup.

Using `fvm install <VERSION>` will ensure that setup during install.
## Envioronment Variables

If you have installed through another command and setup was not completed. You can finish by just running `fvm flutter --version`
Set environment variables at the system level to apply configurations globally. These are typically used for settings that remain constant across multiple projects or runtime environments.

Android Studio might take a few seconds to detect the dynamic SDK change.

</Callout>

If you want to ignore the Flutter SDK root directory within Android Studio you can add the following to `.idea/workspace.xml`.

```xml
<component name="VcsManagerConfiguration">
<ignored-roots>
<path value="$PROJECT_DIR$/.fvm/flutter_sdk" />
</ignored-roots>
</component>
...
```
## Supported Environment Variables:

If that doesn't work, go to Android Studio -> Preferences -> Editor -> File Types -> Ignored Files and Folders and add `flutter_sdk`:
- `FVM_CACHE_PATH`: Specifies the cache path for Flutter versions.
- `FVM_GIT_CACHE`: Enables/disables the git cache globally (`true`/`false`).
- `FVM_GIT_CACHE_PATH`: Sets the path for the local git reference cache.
- `FVM_FLUTTER_URL`: Defines the Flutter repository git URL.
- `FVM_PRIVILEDGED_ACCESS`: Enables/disables privileged access for FVM (`true`/`false`).
5 changes: 2 additions & 3 deletions lib/src/commands/dart_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ class DartCommand extends BaseCommand {
..detail('');
} else {
logger
..detail('$kPackageName: Running Dart version configured in path.')
..detail('$kPackageName: Running Dart version configured in PATH.')
..detail('');

// Running null will default to dart version on path
}
// Running null will default to dart version on path
final results = await runDart(args, version: cacheVersion);

return results.exitCode;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/commands/doctor_command.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:convert';
import 'dart:io';

import 'package:dart_console/dart_console.dart';
import 'package:io/io.dart';
import 'package:jsonc/jsonc.dart';
import 'package:path/path.dart';

import '../models/config_model.dart';
Expand Down Expand Up @@ -76,7 +76,7 @@ class DoctorCommand extends BaseCommand {
if (vscodeDir.existsSync()) {
if (settingsFile.existsSync()) {
try {
final settings = jsonDecode(settingsFile.readAsStringSync());
final settings = jsonc.decode(settingsFile.readAsStringSync());

final relativeSymlinkPath = relative(
project.localVersionSymlinkPath,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/commands/use_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class UseCommand extends BaseCommand {
}
}

final cacheVersion = await ensureCacheWorkflow(version);
final cacheVersion = await ensureCacheWorkflow(version, force: forceOption);

/// Run use workflow
await useVersionWorkflow(
Expand Down
6 changes: 3 additions & 3 deletions lib/src/models/config_model.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Use just for reference, should not change

import 'dart:convert';
import 'dart:io';

import 'package:args/args.dart';
import 'package:jsonc/jsonc.dart';

import '../utils/change_case.dart';
import '../utils/constants.dart';
Expand Down Expand Up @@ -204,7 +204,7 @@ class AppConfig extends Config {
}

factory AppConfig.fromJson(String source) {
return AppConfig.fromMap(json.decode(source) as Map<String, dynamic>);
return AppConfig.fromMap(jsonc.decode(source) as Map<String, dynamic>);
}

static AppConfig? loadFromPath(String path) {
Expand Down Expand Up @@ -321,7 +321,7 @@ class ProjectConfig extends Config {

/// Returns ConfigDto from a json string
factory ProjectConfig.fromJson(String source) =>
ProjectConfig.fromMap(json.decode(source) as Map<String, dynamic>);
ProjectConfig.fromMap(jsonc.decode(source) as Map<String, dynamic>);

static ProjectConfig? loadFromPath(String path) {
final configFile = File(path);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/services/logger_service.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'dart:async';

import 'package:dart_console/dart_console.dart';
import 'base_service.dart';
import '../utils/context.dart';
import 'package:interact/interact.dart' as interact;
import 'package:mason_logger/mason_logger.dart';
import 'package:tint/tint.dart';

import '../utils/context.dart';
import 'base_service.dart';

/// Sets default logger mode
LoggerService get logger => getProvider();

Expand Down
1 change: 1 addition & 0 deletions lib/src/utils/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Future<ProcessResult> runDart(
bool? echoOutput,
bool? throwOnError,
}) {
version ??= GlobalVersionService.fromContext.getGlobal();
if (version == null) {
return _runCmd(_dartCmd, args: args);
}
Expand Down
44 changes: 7 additions & 37 deletions lib/src/utils/deprecation_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,35 @@ import 'context.dart';
void deprecationWorkflow() {
_warnDeprecatedEnvVars();
final fvmDir = ctx.fvmDir;
final settingsFile = File(join(fvmDir, '.settings'));
final legacySettingsFile = File(join(fvmDir, '.settings'));

if (!settingsFile.existsSync()) {
if (!legacySettingsFile.existsSync()) {
return;
}

final payload = settingsFile.readAsStringSync();
final payload = legacySettingsFile.readAsStringSync();
try {
final settings = jsonDecode(payload);
final settingsCachePath = settings['cachePath'] as String?;
if (settingsCachePath != null && settingsCachePath != fvmDir) {
var appConfig = ConfigRepository.loadFile();
appConfig = appConfig.copyWith(cachePath: fvmDir);
ConfigRepository.save(appConfig);
settingsFile.deleteSync(recursive: true);
legacySettingsFile.deleteSync(recursive: true);
logger.success(
'We have moved the settings file ${settingsFile.path}'
'We have moved the settings file ${legacySettingsFile.path}'
'Your settings have been migrated to $kAppConfigFile'
'Your cachePath is now $settingsCachePath. FVM will exit now. Please run the command again.',
);
// Exit to prevent execution with wrong cache path
exit(ExitCode.success.code);
}
} catch (_) {
logger.warn('Could not parse legact settings file');
logger.warn('Could not parse legacy settings file');
legacySettingsFile.deleteSync(recursive: true);
}
}

// Future<void> _migrateVersionSyntax() async {
// final versions = await CacheService.fromContext.getAllVersions();

// final oldVersions = versions.where((version) {
// final versionName = version.name;
// final versionParts = versionName.split('@');
// if (versionParts.length > 1) {
// return true;
// }
// return false;
// });

// if (oldVersions.isEmpty) {
// return;
// }

// logger.warn('You have a deprecated version / channel syntax. ');

// for (var element in oldVersions) {
// logger
// ..info(element.name)
// ..spacer
// ..info('Run: fvm remove ${element.name}}')
// ..spacer
// ..info('Then run: fvm install ${element.name.split('@').first}')
// ..info(
// 'if you need to force install a channel run: fvm install ${element.name.split('@').first} --channel beta',
// );
// }
// }

// TODO: Removed on future version of the app
// Deprecated on 3.0.0
void _warnDeprecatedEnvVars() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 143a6f6

Please sign in to comment.