Bump package:file version to 1.0.0 (#7371)

This commit is contained in:
Todd Volkert
2017-01-05 18:42:57 -08:00
committed by GitHub
parent 29a88cf817
commit 1c43c4e24d
7 changed files with 22 additions and 29 deletions

View File

@@ -4,28 +4,19 @@
import 'dart:io' as dart_io;
import 'package:file/io.dart';
import 'package:file/sync_io.dart';
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:file/memory.dart';
import 'package:path/path.dart' as path;
export 'package:file/io.dart';
export 'package:file/sync_io.dart';
export 'package:file/file.dart';
export 'package:file/local.dart';
/// Currently active implementation of the file system.
///
/// By default it uses local disk-based implementation. Override this in tests
/// with [MemoryFileSystem].
FileSystem fs = new LocalFileSystem();
SyncFileSystem syncFs = new SyncLocalFileSystem();
typedef String CurrentDirectoryGetter();
final CurrentDirectoryGetter _defaultCurrentDirectoryGetter = () {
return dart_io.Directory.current.path;
};
/// Points to the current working directory (like `pwd`).
CurrentDirectoryGetter getCurrentDirectory = _defaultCurrentDirectoryGetter;
/// Exits the process with the given [exitCode].
typedef void ExitFunction([int exitCode]);
@@ -37,20 +28,19 @@ final ExitFunction _defaultExitFunction = ([int exitCode]) {
/// Exits the process.
ExitFunction exit = _defaultExitFunction;
/// Restores [fs] and [syncFs] to the default local disk-based implementation.
/// Restores [fs] to the default local disk-based implementation.
void restoreFileSystem() {
fs = new LocalFileSystem();
syncFs = new SyncLocalFileSystem();
getCurrentDirectory = _defaultCurrentDirectoryGetter;
exit = _defaultExitFunction;
}
/// Uses in-memory replacments for `dart:io` functionality. Useful in tests.
void useInMemoryFileSystem({ String cwd: '/', ExitFunction exitFunction }) {
MemoryFileSystem memFs = new MemoryFileSystem();
fs = memFs;
syncFs = new SyncMemoryFileSystem(backedBy: memFs.storage);
getCurrentDirectory = () => cwd;
fs = new MemoryFileSystem();
if (!fs.directory(cwd).existsSync()) {
fs.directory(cwd).createSync(recursive: true);
}
fs.currentDirectory = cwd;
exit = exitFunction ?? ([int exitCode]) {
throw new Exception('Exited with code $exitCode');
};
@@ -60,9 +50,9 @@ void useInMemoryFileSystem({ String cwd: '/', ExitFunction exitFunction }) {
void ensureDirectoryExists(String filePath) {
String dirPath = path.dirname(filePath);
if (syncFs.type(dirPath) == FileSystemEntityType.DIRECTORY)
if (fs.typeSync(dirPath) == FileSystemEntityType.DIRECTORY)
return;
syncFs.directory(dirPath).create(recursive: true);
fs.directory(dirPath).createSync(recursive: true);
}
/// Recursively copies a folder from `srcPath` to `destPath`

View File

@@ -155,7 +155,7 @@ class DriveCommand extends RunCommandBase {
String appFile = path.normalize(targetFile);
// This command extends `flutter start` and therefore CWD == package dir
String packageDir = getCurrentDirectory();
String packageDir = fs.currentDirectory.path;
// Make appFile path relative to package directory because we are looking
// for the corresponding test file relative to it.