Refactor writing of package config in tests (#163734)
Seems like each test had its own way of doing this. Extracted from https://github.com/flutter/flutter/pull/160443
This commit is contained in:
parent
4da1dec288
commit
45b21ec3bb
@ -29,6 +29,7 @@ import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_build_system.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
@ -86,8 +87,8 @@ void main() {
|
||||
|
||||
// Sets up the minimal mock project files necessary to look like a Flutter project.
|
||||
void createCoreMockProjectFiles() {
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: my_app');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
}
|
||||
|
||||
@ -258,10 +259,7 @@ void main() {
|
||||
osUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
|
||||
final bool supported =
|
||||
|
@ -26,6 +26,7 @@ import '../../src/context.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_build_system.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
@ -93,8 +94,8 @@ void main() {
|
||||
|
||||
// Sets up the minimal mock project files necessary to look like a Flutter project.
|
||||
void createCoreMockProjectFiles() {
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: my_app');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
}
|
||||
|
||||
@ -287,10 +288,7 @@ void main() {
|
||||
osUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
|
||||
final bool supported =
|
||||
|
@ -23,6 +23,7 @@ import 'package:unified_analytics/unified_analytics.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_build_system.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
@ -60,7 +61,7 @@ void main() {
|
||||
// Creates the mock files necessary to look like a Flutter project.
|
||||
void setUpMockCoreProjectFiles() {
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
}
|
||||
|
||||
@ -685,10 +686,7 @@ project(runner LANGUAGES CXX)
|
||||
set(BINARY_NAME "fizz_bar")
|
||||
''');
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectoryTest(
|
||||
fileSystem.currentDirectory,
|
||||
);
|
||||
|
@ -27,6 +27,7 @@ import '../../src/context.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_build_system.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
@ -75,8 +76,9 @@ void main() {
|
||||
|
||||
// Sets up the minimal mock project files necessary to look like a Flutter project.
|
||||
void createCoreMockProjectFiles() {
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: my_app');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import 'package:flutter_tools/src/web/compile.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_build_system.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
@ -39,7 +40,7 @@ void main() {
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('name: foo\n');
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
writePackageConfigFile(mainLibName: 'foo', directory: fileSystem.currentDirectory);
|
||||
fileSystem.file(fileSystem.path.join('web', 'index.html')).createSync(recursive: true);
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
logger = BufferLogger.test();
|
||||
@ -505,27 +506,11 @@ void setupFileSystemForEndToEndTest(FileSystem fileSystem) {
|
||||
}
|
||||
|
||||
// Project files.
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "3.2"
|
||||
},
|
||||
{
|
||||
"name": "fizz",
|
||||
"rootUri": "../bar",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "3.2"
|
||||
}
|
||||
],
|
||||
"configVersion": 2
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: fileSystem.currentDirectory,
|
||||
mainLibName: 'foo',
|
||||
packages: <String, String>{'fizz': 'bar'},
|
||||
);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: foo
|
||||
|
||||
|
@ -19,6 +19,7 @@ import 'package:unified_analytics/unified_analytics.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
const String flutterRoot = r'C:\flutter';
|
||||
@ -62,7 +63,7 @@ void main() {
|
||||
// Creates the mock files necessary to look like a Flutter project.
|
||||
void setUpMockCoreProjectFiles() {
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import 'package:test/fake.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
void main() {
|
||||
@ -273,10 +274,8 @@ FlutterProject setupProjectUnderTest(Directory currentDirectory, bool setupXcode
|
||||
.createSync(recursive: true);
|
||||
}
|
||||
projectUnderTest.dartTool.createSync(recursive: true);
|
||||
projectUnderTest.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.jon')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: projectUnderTest.directory, mainLibName: 'my_app');
|
||||
|
||||
projectUnderTest.android.ephemeralDirectory.createSync(recursive: true);
|
||||
|
||||
projectUnderTest.ios.ephemeralDirectory.createSync(recursive: true);
|
||||
|
@ -19,6 +19,7 @@ import 'package:test/fake.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
@ -39,10 +40,7 @@ class FakePub extends Fake implements Pub {
|
||||
bool shouldSkipThirdPartyGenerator = true,
|
||||
PubOutputMode outputMode = PubOutputMode.all,
|
||||
}) async {
|
||||
project.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: project.directory, mainLibName: 'my_app');
|
||||
if (offline) {
|
||||
calledGetOffline += 1;
|
||||
} else {
|
||||
|
@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
@ -18,6 +20,7 @@ import 'package:unified_analytics/unified_analytics.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
const String minimalV2EmbeddingManifest = r'''
|
||||
@ -48,7 +51,7 @@ void main() {
|
||||
setUp(() {
|
||||
Cache.disableLocking();
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
pub = FakePub(fileSystem);
|
||||
pub = FakePub();
|
||||
logger = BufferLogger.test();
|
||||
});
|
||||
|
||||
@ -73,7 +76,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'pub get usage values are resilient to missing package config files before running "pub get"',
|
||||
() async {
|
||||
fileSystem.currentDirectory.childFile('pubspec.yaml').createSync();
|
||||
fileSystem.currentDirectory.childFile('pubspec.yaml').writeAsStringSync('name: my_app');
|
||||
fileSystem.currentDirectory.childFile('.flutter-plugins').createSync();
|
||||
fileSystem.currentDirectory.childFile('.flutter-plugins-dependencies').createSync();
|
||||
fileSystem.currentDirectory.childDirectory('android').childFile('AndroidManifest.xml')
|
||||
@ -152,8 +155,19 @@ void main() {
|
||||
await commandRunner.run(<String>['get', '--directory=${targetDirectory.path}']);
|
||||
final FlutterProject rootProject = FlutterProject.fromDirectory(targetDirectory);
|
||||
final File packageConfigFile = rootProject.dartTool.childFile('package_config.json');
|
||||
|
||||
expect(packageConfigFile.existsSync(), true);
|
||||
expect(packageConfigFile.readAsStringSync(), '{"configVersion":2,"packages":[]}');
|
||||
expect(json.decode(packageConfigFile.readAsStringSync()), <String, Object>{
|
||||
'configVersion': 2,
|
||||
'packages': <Object?>[
|
||||
<String, Object?>{
|
||||
'name': 'my_app',
|
||||
'rootUri': '../',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.7',
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Pub: () => pub,
|
||||
@ -328,9 +342,8 @@ void main() {
|
||||
}
|
||||
|
||||
class FakePub extends Fake implements Pub {
|
||||
FakePub(this.fileSystem);
|
||||
FakePub();
|
||||
|
||||
final FileSystem fileSystem;
|
||||
List<String>? expectedArguments;
|
||||
|
||||
@override
|
||||
@ -347,12 +360,7 @@ class FakePub extends Fake implements Pub {
|
||||
expect(arguments, expectedArguments);
|
||||
}
|
||||
if (project != null) {
|
||||
fileSystem
|
||||
.directory(project.directory)
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
writePackageConfigFile(directory: project.directory, mainLibName: 'my_app');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fake_devices.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
void main() {
|
||||
@ -174,15 +175,9 @@ void main() {
|
||||
artifacts = Artifacts.test();
|
||||
fs = MemoryFileSystem.test();
|
||||
|
||||
fs.currentDirectory.childFile('pubspec.yaml').writeAsStringSync('name: flutter_app');
|
||||
fs.currentDirectory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"packages": [],
|
||||
"configVersion": 2
|
||||
}
|
||||
''');
|
||||
fs.currentDirectory.childFile('pubspec.yaml').writeAsStringSync('name: my_app');
|
||||
writePackageConfigFile(directory: fs.currentDirectory, mainLibName: 'my_app');
|
||||
|
||||
final Directory libDir = fs.currentDirectory.childDirectory('lib');
|
||||
libDir.createSync();
|
||||
final File mainFile = libDir.childFile('main.dart');
|
||||
|
@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/memory.dart';
|
||||
@ -37,66 +36,16 @@ import '../../src/context.dart';
|
||||
import '../../src/fake_devices.dart';
|
||||
import '../../src/fake_vm_services.dart';
|
||||
import '../../src/logging_logger.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
final String _flutterToolsPackageConfigContents = json.encode(<String, Object>{
|
||||
'configVersion': 2,
|
||||
'packages': <Map<String, Object>>[
|
||||
<String, String>{
|
||||
'name': 'ffi',
|
||||
'rootUri': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/ffi-2.1.2',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.3',
|
||||
},
|
||||
<String, String>{
|
||||
'name': 'test',
|
||||
'rootUri': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/test-1.24.9',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.0',
|
||||
},
|
||||
<String, String>{
|
||||
'name': 'test_api',
|
||||
'rootUri': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/test_api-0.6.1',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.0',
|
||||
},
|
||||
<String, String>{
|
||||
'name': 'test_core',
|
||||
'rootUri': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/test_core-0.5.9',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.0',
|
||||
},
|
||||
],
|
||||
'generated': '2021-02-24T07:55:20.084834Z',
|
||||
'generator': 'pub',
|
||||
'generatorVersion': '2.13.0-68.0.dev',
|
||||
});
|
||||
const String _pubspecContents = '''
|
||||
name: my_app
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
integration_test:
|
||||
sdk: flutter''';
|
||||
final String _packageConfigContents = json.encode(<String, Object>{
|
||||
'configVersion': 2,
|
||||
'packages': <Map<String, Object>>[
|
||||
<String, String>{
|
||||
'name': 'test_api',
|
||||
'rootUri': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.19',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '2.12',
|
||||
},
|
||||
<String, String>{
|
||||
'name': 'integration_test',
|
||||
'rootUri': 'file:///path/to/flutter/packages/integration_test',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '2.12',
|
||||
},
|
||||
],
|
||||
'generated': '2021-02-24T07:55:20.084834Z',
|
||||
'generator': 'pub',
|
||||
'generatorVersion': '2.13.0-68.0.dev',
|
||||
});
|
||||
|
||||
void main() {
|
||||
Cache.disableLocking();
|
||||
@ -111,20 +60,30 @@ void main() {
|
||||
final Directory package = fs.directory('package');
|
||||
package.childFile('pubspec.yaml').createSync(recursive: true);
|
||||
package.childFile('pubspec.yaml').writeAsStringSync(_pubspecContents);
|
||||
(package.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)).writeAsStringSync(_packageConfigContents);
|
||||
writePackageConfigFile(
|
||||
directory: package,
|
||||
packages: <String, String>{
|
||||
'test_api': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.19',
|
||||
'integration_test': 'file:///path/to/flutter/packages/integration_test',
|
||||
},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
package.childDirectory('test').childFile('some_test.dart').createSync(recursive: true);
|
||||
package
|
||||
.childDirectory('integration_test')
|
||||
.childFile('some_integration_test.dart')
|
||||
.createSync(recursive: true);
|
||||
|
||||
final File flutterToolsPackageConfigFile = fs
|
||||
.directory(fs.path.join(getFlutterRoot(), 'packages', 'flutter_tools'))
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
flutterToolsPackageConfigFile.createSync(recursive: true);
|
||||
flutterToolsPackageConfigFile.writeAsStringSync(_flutterToolsPackageConfigContents);
|
||||
writePackageConfigFile(
|
||||
directory: fs.directory(fs.path.join(getFlutterRoot(), 'packages', 'flutter_tools')),
|
||||
packages: <String, String>{
|
||||
'ffi': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/ffi-2.1.2',
|
||||
'test': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/test-1.24.9',
|
||||
'test_api': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/test_api-0.6.1',
|
||||
'test_core': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dev/test_core-0.5.9',
|
||||
},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
|
||||
fs.currentDirectory = package.path;
|
||||
|
||||
@ -161,26 +120,14 @@ dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
''');
|
||||
fs
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.writeAsStringSync(
|
||||
json.encode(<String, Object>{
|
||||
'configVersion': 2,
|
||||
'packages': <Map<String, Object>>[
|
||||
<String, String>{
|
||||
'name': 'test_api',
|
||||
'rootUri':
|
||||
'file:///path/to/pubcache/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.19',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '2.12',
|
||||
},
|
||||
],
|
||||
'generated': '2021-02-24T07:55:20.084834Z',
|
||||
'generator': 'pub',
|
||||
'generatorVersion': '2.13.0-68.0.dev',
|
||||
}),
|
||||
);
|
||||
writePackageConfigFile(
|
||||
directory: fs.currentDirectory,
|
||||
packages: <String, String>{
|
||||
'test_api': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.19',
|
||||
},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
|
||||
final FakePackageTest fakePackageTest = FakePackageTest();
|
||||
final TestCommand testCommand = TestCommand(testWrapper: fakePackageTest);
|
||||
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
|
||||
@ -361,7 +308,7 @@ dev_dependencies:
|
||||
testUsingContext(
|
||||
'Coverage provides current library name to Coverage Collector by default',
|
||||
() async {
|
||||
const String currentPackageName = '';
|
||||
const String currentPackageName = 'my_app';
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(
|
||||
@ -1210,6 +1157,7 @@ const List<String> packageTestArgs = <String>[
|
||||
fs.file('vanilla.txt').writeAsStringSync('vanilla');
|
||||
fs.file('orange.txt').writeAsStringSync('orange');
|
||||
fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- path: vanilla.txt
|
||||
@ -1251,6 +1199,7 @@ dev_dependencies:
|
||||
fs.file('vanilla.txt').writeAsStringSync('vanilla');
|
||||
fs.file('flavorless.txt').writeAsStringSync('flavorless');
|
||||
fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- path: vanilla.txt
|
||||
@ -1321,6 +1270,7 @@ dev_dependencies:
|
||||
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
|
||||
fs.file('asset.txt').writeAsStringSync('1');
|
||||
fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- asset.txt
|
||||
|
@ -14,6 +14,7 @@ import 'package:test/fake.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
import '../../src/context.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
// An example pubspec.yaml from flutter, not necessary for it to be up to date.
|
||||
@ -116,7 +117,7 @@ void main() {
|
||||
..writeAsStringSync(kExamplesPubspecYaml);
|
||||
flutter.childFile('pubspec.yaml').writeAsStringSync(kFlutterPubspecYaml);
|
||||
Cache.flutterRoot = flutterSdk.absolute.path;
|
||||
pub = FakePub(fileSystem);
|
||||
pub = FakePub();
|
||||
processManager = FakeProcessManager.empty();
|
||||
});
|
||||
|
||||
@ -367,9 +368,8 @@ void main() {
|
||||
}
|
||||
|
||||
class FakePub extends Fake implements Pub {
|
||||
FakePub(this.fileSystem);
|
||||
FakePub();
|
||||
|
||||
final FileSystem fileSystem;
|
||||
final List<String> pubGetDirectories = <String>[];
|
||||
final List<String> pubBatchDirectories = <String>[];
|
||||
final List<String> pubspecYamls = <String>[];
|
||||
@ -405,9 +405,7 @@ packages:
|
||||
sdks:
|
||||
dart: ">=2.14.0 <3.0.0"
|
||||
''');
|
||||
fileSystem.currentDirectory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
writePackageConfigFile(directory: project.directory, mainLibName: 'my_app');
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -19,6 +19,7 @@ import 'package:test_api/fake.dart';
|
||||
import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
group('WidgetPreviewStartCommand', () {
|
||||
@ -174,19 +175,6 @@ flutter:
|
||||
- deferredComponentArg
|
||||
- path: package/deferredComponentUri''';
|
||||
|
||||
static const String basicPackageConfig = '''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "test",
|
||||
"rootUri": "fileSystem.currentDirectory.path",
|
||||
"packageUri": "lib/"
|
||||
}
|
||||
]
|
||||
}
|
||||
''';
|
||||
|
||||
final String projectRoot;
|
||||
final FileSystem fileSystem;
|
||||
final Logger logger;
|
||||
@ -212,10 +200,9 @@ flutter:
|
||||
|
||||
@override
|
||||
late final File packageConfig = () {
|
||||
final File file = fileSystem
|
||||
.directory(fileSystem.path.join(projectRoot, '.dart_tool'))
|
||||
.childFile('package_config.json')..createSync(recursive: true);
|
||||
file.writeAsStringSync(basicPackageConfig);
|
||||
return file;
|
||||
return writePackageConfigFile(
|
||||
directory: fileSystem.directory(projectRoot),
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
}();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fake_process_manager.dart';
|
||||
import '../src/fakes.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
group('Apk with partial Android SDK works', () {
|
||||
@ -982,9 +983,7 @@ class FakeAndroidSdkVersion extends Fake implements AndroidSdkVersion {
|
||||
|
||||
Future<FlutterProject> aModuleProject() async {
|
||||
final Directory directory = globals.fs.directory('module_project');
|
||||
directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
writePackageConfigFile(directory: directory, mainLibName: 'my_app');
|
||||
directory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_module
|
||||
flutter:
|
||||
|
@ -12,6 +12,7 @@ import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
Future<ManifestAssetBundle> buildBundleWithFlavor(
|
||||
@ -50,10 +51,8 @@ void main() {
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FakePlatform platform = FakePlatform();
|
||||
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'example');
|
||||
|
||||
fileSystem
|
||||
.file(fileSystem.path.join('assets', 'common', 'image.png'))
|
||||
.createSync(recursive: true);
|
||||
@ -129,10 +128,8 @@ flutter:
|
||||
);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FakePlatform platform = FakePlatform();
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'example');
|
||||
|
||||
fileSystem.file(fileSystem.path.join('assets', 'unflavored.png')).createSync(recursive: true);
|
||||
fileSystem
|
||||
.file(fileSystem.path.join('assets', 'vanillaOrange.png'))
|
||||
@ -174,10 +171,7 @@ flutter:
|
||||
);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FakePlatform platform = FakePlatform();
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'example');
|
||||
fileSystem.file(fileSystem.path.join('vanilla', 'vanilla.png')).createSync(recursive: true);
|
||||
fileSystem
|
||||
.file(fileSystem.path.join('vanilla', 'flavorless.png'))
|
||||
@ -217,10 +211,7 @@ flutter:
|
||||
);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FakePlatform platform = FakePlatform();
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'example');
|
||||
fileSystem.file('orange.png').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
@ -258,10 +249,7 @@ flutter:
|
||||
);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FakePlatform platform = FakePlatform();
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'example');
|
||||
fileSystem
|
||||
.file(fileSystem.path.join('vanilla', 'actually-strawberry.png'))
|
||||
.createSync(recursive: true);
|
||||
|
@ -14,6 +14,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
String fixPath(String path) {
|
||||
@ -47,26 +48,6 @@ $fontsSection
|
||||
''');
|
||||
}
|
||||
|
||||
void writePackageConfigFile(Map<String, String> packages) {
|
||||
globals.fs.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(
|
||||
json.encode(<String, dynamic>{
|
||||
'packages': <dynamic>[
|
||||
...packages.entries.map((MapEntry<String, String> entry) {
|
||||
return <String, dynamic>{
|
||||
'name': entry.key,
|
||||
'rootUri': '../${entry.value}',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.2',
|
||||
};
|
||||
}),
|
||||
],
|
||||
'configVersion': 2,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> buildAndVerifyFonts(
|
||||
List<String> localFonts,
|
||||
List<String> packageFonts,
|
||||
@ -116,8 +97,13 @@ $fontsSection
|
||||
testUsingContext(
|
||||
'App includes neither font manifest nor fonts when no defines fonts',
|
||||
() async {
|
||||
final Map<String, String> deps = <String, String>{'test_package': 'p/p/'};
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
packages: deps,
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
@ -146,8 +132,14 @@ $fontsSection
|
||||
fonts:
|
||||
- asset: packages/test_package/bar
|
||||
''';
|
||||
writePubspecFile('pubspec.yaml', 'test', fontsSection: fontsSection);
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePubspecFile('pubspec.yaml', 'my_app', fontsSection: fontsSection);
|
||||
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
const String font = 'bar';
|
||||
@ -177,8 +169,13 @@ $fontsSection
|
||||
- asset: packages/test_package/bar
|
||||
- asset: a/bar
|
||||
''';
|
||||
writePubspecFile('pubspec.yaml', 'test', fontsSection: fontsSection);
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePubspecFile('pubspec.yaml', 'my_app', fontsSection: fontsSection);
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
const String packageFont = 'bar';
|
||||
@ -202,8 +199,14 @@ $fontsSection
|
||||
testUsingContext(
|
||||
'App uses package font with own font file',
|
||||
() async {
|
||||
final Map<String, String> deps = <String, String>{'test_package': 'p/p/'};
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
|
||||
packages: deps,
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
const String fontsSection = '''
|
||||
- family: foo
|
||||
fonts:
|
||||
@ -233,8 +236,17 @@ $fontsSection
|
||||
testUsingContext(
|
||||
'App uses package font with font file from another package',
|
||||
() async {
|
||||
final Map<String, String> deps = <String, String>{
|
||||
'test_package': 'p/p/',
|
||||
'test_package2': 'p2/p/',
|
||||
};
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/', 'test_package2': 'p2/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
|
||||
packages: deps,
|
||||
mainLibName: 'test',
|
||||
);
|
||||
const String fontsSection = '''
|
||||
- family: foo
|
||||
fonts:
|
||||
@ -265,8 +277,14 @@ $fontsSection
|
||||
testUsingContext(
|
||||
'App uses package font with properties and own font file',
|
||||
() async {
|
||||
final Map<String, String> deps = <String, String>{'test_package': 'p/p/'};
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
|
||||
packages: deps,
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
|
||||
const String pubspec = '''
|
||||
- family: foo
|
||||
@ -298,13 +316,19 @@ $fontsSection
|
||||
testUsingContext(
|
||||
'App uses local font and package font with own font file.',
|
||||
() async {
|
||||
final Map<String, String> deps = <String, String>{'test_package': 'p/p/'};
|
||||
const String fontsSection = '''
|
||||
- family: foo
|
||||
fonts:
|
||||
- asset: a/bar
|
||||
''';
|
||||
writePubspecFile('pubspec.yaml', 'test', fontsSection: fontsSection);
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
packages: deps,
|
||||
mainLibName: 'test',
|
||||
);
|
||||
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package', fontsSection: fontsSection);
|
||||
|
||||
const String font = 'a/bar';
|
||||
|
@ -16,6 +16,7 @@ import 'package:standard_message_codec/standard_message_codec.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
String fixPath(String path) {
|
||||
@ -71,26 +72,6 @@ $assetsSection
|
||||
''');
|
||||
}
|
||||
|
||||
void writePackageConfigFile(Map<String, String> packages) {
|
||||
globals.fs.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(
|
||||
json.encode(<String, dynamic>{
|
||||
'packages': <dynamic>[
|
||||
...packages.entries.map((MapEntry<String, String> entry) {
|
||||
return <String, dynamic>{
|
||||
'name': entry.key,
|
||||
'rootUri': '../${entry.value}',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.2',
|
||||
};
|
||||
}),
|
||||
],
|
||||
'configVersion': 2,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Map<Object, Object> assetManifestBinToJson(Map<Object, Object> manifest) {
|
||||
List<Object> convertList(List<Object> variants) =>
|
||||
variants.map((Object variant) => (variant as Map<Object?, Object?>)['asset']!).toList();
|
||||
@ -159,7 +140,11 @@ $assetsSection
|
||||
'No assets are bundled when the package has no assets',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
@ -190,7 +175,11 @@ $assetsSection
|
||||
'No assets are bundled when the package has an asset that is not listed',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
final List<String> assets = <String>['a/foo'];
|
||||
@ -225,7 +214,11 @@ $assetsSection
|
||||
'asset its pubspec',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
|
||||
final List<String> assets = <String>['a/foo'];
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package', assets: assets);
|
||||
@ -252,7 +245,11 @@ $assetsSection
|
||||
() async {
|
||||
final List<String> assetEntries = <String>['packages/test_package/a/foo'];
|
||||
writePubspecFile('pubspec.yaml', 'test', assets: assetEntries);
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
final List<String> assets = <String>['a/foo'];
|
||||
@ -276,7 +273,11 @@ $assetsSection
|
||||
'has an asset and a variant, and lists the asset in its pubspec',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package', assets: <String>['a/foo', 'a/bar']);
|
||||
|
||||
final List<String> assets = <String>['a/foo', 'a/2x/foo', 'a/bar'];
|
||||
@ -305,7 +306,11 @@ $assetsSection
|
||||
'has an asset and a variant, and the app lists the asset in its pubspec',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test', assets: <String>['packages/test_package/a/foo']);
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
|
||||
final List<String> assets = <String>['a/foo', 'a/2x/foo'];
|
||||
@ -331,7 +336,11 @@ $assetsSection
|
||||
'two assets in its pubspec',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assets = <String>['a/foo', 'a/bar'];
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package', assets: assets);
|
||||
@ -362,7 +371,11 @@ $assetsSection
|
||||
'packages/test_package/a/bar',
|
||||
];
|
||||
writePubspecFile('pubspec.yaml', 'test', assets: assetEntries);
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assets = <String>['a/foo', 'a/bar'];
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
@ -389,7 +402,11 @@ $assetsSection
|
||||
'Two assets are bundled when two packages each have and list an asset their pubspec',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/', 'test_package2': 'p2/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/', 'test_package2': 'p2/p/'},
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package', assets: <String>['a/foo']);
|
||||
writePubspecFile('p2/p/pubspec.yaml', 'test_package2', assets: <String>['a/foo']);
|
||||
|
||||
@ -427,7 +444,11 @@ $assetsSection
|
||||
'packages/test_package2/a/foo',
|
||||
];
|
||||
writePubspecFile('pubspec.yaml', 'test', assets: assetEntries);
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/', 'test_package2': 'p2/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/', 'test_package2': 'p2/p/'},
|
||||
);
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||
writePubspecFile('p2/p/pubspec.yaml', 'test_package2');
|
||||
|
||||
@ -462,7 +483,11 @@ $assetsSection
|
||||
'listing in its pubspec an asset from another package',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/', 'test_package2': 'p2/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/', 'test_package2': 'p2/p/'},
|
||||
);
|
||||
writePubspecFile(
|
||||
'p/p/pubspec.yaml',
|
||||
'test_package',
|
||||
@ -492,7 +517,11 @@ $assetsSection
|
||||
'Flavored assets are bundled when the app depends on a package',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
writePubspecFile(
|
||||
'p/p/pubspec.yaml',
|
||||
'test_package',
|
||||
@ -526,7 +555,11 @@ $assetsSection
|
||||
'Asset paths can contain URL reserved characters',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assets = <String>['a/foo', 'a/foo [x]'];
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package', assets: assets);
|
||||
@ -553,7 +586,11 @@ $assetsSection
|
||||
'Asset paths can contain URL reserved characters',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assets = <String>['a/foo', 'a/foo [x]'];
|
||||
writePubspecFile('p/p/pubspec.yaml', 'test_package', assets: assets);
|
||||
@ -581,7 +618,11 @@ $assetsSection
|
||||
'Two assets are bundled when scanning their directory',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assetsOnDisk = <String>['a/foo', 'a/bar'];
|
||||
final List<String> assetsOnManifest = <String>['a/'];
|
||||
@ -610,7 +651,11 @@ $assetsSection
|
||||
'Two assets are bundled when listing one and scanning second directory',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assetsOnDisk = <String>['a/foo', 'abc/bar'];
|
||||
final List<String> assetOnManifest = <String>['a/foo', 'abc/'];
|
||||
@ -639,7 +684,11 @@ $assetsSection
|
||||
'One asset is bundled with variant, scanning wrong directory',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assetsOnDisk = <String>['a/foo', 'a/b/foo', 'a/bar'];
|
||||
final List<String> assetOnManifest = <String>[
|
||||
@ -672,7 +721,11 @@ $assetsSection
|
||||
'One asset is bundled with variant, scanning directory',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assetsOnDisk = <String>['a/foo', 'a/2x/foo'];
|
||||
final List<String> assetOnManifest = <String>['a/'];
|
||||
@ -698,7 +751,11 @@ $assetsSection
|
||||
'No asset is bundled with variant, no assets or directories are listed',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assetsOnDisk = <String>['a/foo', 'a/2x/foo'];
|
||||
final List<String> assetOnManifest = <String>[];
|
||||
@ -722,7 +779,11 @@ $assetsSection
|
||||
'Expect error generating manifest, wrong non-existing directory is listed',
|
||||
() async {
|
||||
writePubspecFile('pubspec.yaml', 'test');
|
||||
writePackageConfigFile(<String, String>{'test_package': 'p/p/'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'test_package': 'p/p/'},
|
||||
);
|
||||
|
||||
final List<String> assetOnManifest = <String>['c/'];
|
||||
|
||||
|
@ -23,34 +23,11 @@ import 'package:standard_message_codec/standard_message_codec.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
const String shaderLibDir = '/./shader_lib';
|
||||
|
||||
File createPackageConfig(
|
||||
FileSystem fileSystem, {
|
||||
Map<String, String> packages = const <String, String>{},
|
||||
}) {
|
||||
final File file = fileSystem.directory('.dart_tool').childFile('package_config.json');
|
||||
file.createSync(recursive: true);
|
||||
file.writeAsStringSync(
|
||||
json.encode(<String, dynamic>{
|
||||
'packages': <dynamic>[
|
||||
...packages.entries.map((MapEntry<String, String> entry) {
|
||||
return <String, dynamic>{
|
||||
'name': entry.key,
|
||||
'rootUri': '../${entry.value}',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '3.2',
|
||||
};
|
||||
}),
|
||||
],
|
||||
'configVersion': 2,
|
||||
}),
|
||||
);
|
||||
return file;
|
||||
}
|
||||
|
||||
group('AssetBundle.build (using context)', () {
|
||||
late FileSystem testFileSystem;
|
||||
late Platform platform;
|
||||
@ -115,9 +92,9 @@ void main() {
|
||||
testUsingContext(
|
||||
'wildcard directories do not include subdirectories',
|
||||
() async {
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: test
|
||||
name: my_app
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
@ -164,14 +141,18 @@ flutter:
|
||||
testUsingContext(
|
||||
'wildcard directories are updated when filesystem changes',
|
||||
() async {
|
||||
final File packageFile = createPackageConfig(globals.fs);
|
||||
final File packageFile = writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
|
||||
globals.fs
|
||||
.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
|
||||
.createSync(recursive: true);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/
|
||||
@ -224,12 +205,15 @@ flutter:
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/
|
||||
''');
|
||||
final File packageConfig = createPackageConfig(globals.fs);
|
||||
final File packageConfig = writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(packageConfigPath: '.dart_tool/package_config.json');
|
||||
expect(
|
||||
@ -250,7 +234,7 @@ flutter:
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example''')
|
||||
name: my_app''')
|
||||
..setLastModifiedSync(modifiedTime);
|
||||
|
||||
// touch the package config to make sure its change time is after pubspec.yaml's
|
||||
@ -292,12 +276,12 @@ name: example''')
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/
|
||||
''');
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
await bundle.build(packageConfigPath: '.dart_tool/package_config.json');
|
||||
expect(
|
||||
@ -322,7 +306,7 @@ flutter:
|
||||
testUsingContext(
|
||||
'deferred assets are parsed',
|
||||
() async {
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs
|
||||
.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
|
||||
.createSync(recursive: true);
|
||||
@ -335,7 +319,7 @@ flutter:
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/
|
||||
@ -380,7 +364,7 @@ flutter:
|
||||
testUsingContext(
|
||||
'deferred assets are parsed regularly when splitDeferredAssets Disabled',
|
||||
() async {
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs
|
||||
.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
|
||||
.createSync(recursive: true);
|
||||
@ -393,7 +377,7 @@ flutter:
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/
|
||||
@ -430,7 +414,10 @@ flutter:
|
||||
testUsingContext(
|
||||
'deferred assets wildcard parsed',
|
||||
() async {
|
||||
final File packageFile = createPackageConfig(globals.fs);
|
||||
final File packageFile = writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
globals.fs
|
||||
.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
|
||||
.createSync(recursive: true);
|
||||
@ -443,7 +430,7 @@ flutter:
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/
|
||||
@ -523,11 +510,11 @@ flutter:
|
||||
userMessages: UserMessages(),
|
||||
);
|
||||
|
||||
createPackageConfig(fileSystem);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- https://mywebsite.com/images/
|
||||
@ -577,7 +564,7 @@ flutter:
|
||||
fileSystem: fileSystem,
|
||||
userMessages: UserMessages(),
|
||||
);
|
||||
createPackageConfig(fileSystem);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
@ -612,11 +599,11 @@ flutter:
|
||||
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FakePlatform platform = FakePlatform();
|
||||
createPackageConfig(fileSystem);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- path: my-asset.txt
|
||||
@ -649,7 +636,7 @@ flutter:
|
||||
expect(bundle.entries['my-asset.txt']!.content.isModified, isFalse);
|
||||
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- path: my-asset.txt
|
||||
@ -717,9 +704,9 @@ flutter:
|
||||
testUsingContext(
|
||||
'pubspec contains an asset',
|
||||
() async {
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs.file('pubspec.yaml').writeAsStringSync(r'''
|
||||
name: test
|
||||
name: my_app
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
@ -809,12 +796,12 @@ flutter:
|
||||
testUsingContext(
|
||||
'does not unnecessarily recreate asset manifest, font manifest, license',
|
||||
() async {
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/bar.txt
|
||||
@ -843,12 +830,12 @@ assets:
|
||||
'inserts dummy file into additionalDependencies when '
|
||||
'wildcards are used',
|
||||
() async {
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs.file(globals.fs.path.join('assets', 'bar.txt')).createSync(recursive: true);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/
|
||||
@ -872,12 +859,12 @@ flutter:
|
||||
'Does not insert dummy file into additionalDependencies '
|
||||
'when wildcards are not used',
|
||||
() async {
|
||||
createPackageConfig(globals.fs);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs.file(globals.fs.path.join('assets', 'bar.txt')).createSync(recursive: true);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- assets/bar.txt
|
||||
@ -920,11 +907,11 @@ flutter:
|
||||
testUsingContext(
|
||||
'Including a shader triggers the shader compiler',
|
||||
() async {
|
||||
createPackageConfig(fileSystem);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
shaders:
|
||||
- assets/shader.frag
|
||||
@ -978,11 +965,11 @@ flutter:
|
||||
testUsingContext(
|
||||
'Included shaders are compiled for the web',
|
||||
() async {
|
||||
createPackageConfig(fileSystem);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
shaders:
|
||||
- assets/shader.frag
|
||||
@ -1040,7 +1027,7 @@ flutter:
|
||||
testUsingContext(
|
||||
'Material shaders are compiled for the web',
|
||||
() async {
|
||||
createPackageConfig(fileSystem);
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
|
||||
final String materialIconsPath = fileSystem.path.join(
|
||||
getFlutterRoot(),
|
||||
@ -1090,7 +1077,7 @@ flutter:
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
''');
|
||||
@ -1130,12 +1117,16 @@ flutter:
|
||||
'Does not insert dummy file into additionalDependencies '
|
||||
'when wildcards are used by dependencies',
|
||||
() async {
|
||||
createPackageConfig(globals.fs, packages: <String, String>{'example': '', 'foo': 'foo'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'foo': 'foo'},
|
||||
);
|
||||
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
dependencies:
|
||||
foo: any
|
||||
''');
|
||||
@ -1164,12 +1155,16 @@ flutter:
|
||||
testUsingContext(
|
||||
'does not track wildcard directories from dependencies',
|
||||
() async {
|
||||
createPackageConfig(globals.fs, packages: <String, String>{'example': '', 'foo': 'foo'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'foo': 'foo'},
|
||||
);
|
||||
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
dependencies:
|
||||
foo: any
|
||||
''');
|
||||
@ -1215,12 +1210,16 @@ flutter:
|
||||
'reports package that causes asset bundle error when it is '
|
||||
'a dependency',
|
||||
() async {
|
||||
createPackageConfig(globals.fs, packages: <String, String>{'example': '', 'foo': 'foo'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'foo': 'foo'},
|
||||
);
|
||||
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
dependencies:
|
||||
foo: any
|
||||
''');
|
||||
@ -1249,11 +1248,15 @@ flutter:
|
||||
'does not report package that causes asset bundle error '
|
||||
'when it is from own pubspec',
|
||||
() async {
|
||||
createPackageConfig(globals.fs, packages: <String, String>{'example': '', 'foo': 'foo'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'foo': 'foo'},
|
||||
);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
flutter:
|
||||
assets:
|
||||
- bar.txt
|
||||
@ -1274,11 +1277,15 @@ flutter:
|
||||
'does not include Material Design assets if uses-material-design: true is '
|
||||
'specified only by a dependency',
|
||||
() async {
|
||||
createPackageConfig(globals.fs, packages: <String, String>{'example': '', 'foo': 'foo'});
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'foo': 'foo'},
|
||||
);
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
dependencies:
|
||||
foo: any
|
||||
|
||||
@ -1310,11 +1317,11 @@ flutter:
|
||||
testUsingContext(
|
||||
'does not include assets in project directories as asset variants',
|
||||
() async {
|
||||
createPackageConfig(globals.fs, packages: <String, String>{'example': ''});
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
@ -1354,11 +1361,11 @@ flutter:
|
||||
testUsingContext(
|
||||
'deferred and regular assets are included in manifest alphabetically',
|
||||
() async {
|
||||
createPackageConfig(globals.fs, packages: <String, String>{'example': ''});
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'my_app');
|
||||
globals.fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
name: my_app
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
|
@ -19,6 +19,7 @@ import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:standard_message_codec/standard_message_codec.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
Future<Map<String, List<String>>> extractAssetManifestJsonFromBundle(
|
||||
@ -58,14 +59,7 @@ void main() {
|
||||
fileSystem: fs,
|
||||
userMessages: UserMessages(),
|
||||
);
|
||||
fs.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": []
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: fs.currentDirectory, mainLibName: 'test');
|
||||
});
|
||||
|
||||
void createPubspec({required List<String> assets}) {
|
||||
@ -292,14 +286,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
|
||||
userMessages: UserMessages(),
|
||||
);
|
||||
|
||||
fs.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": []
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: fs.currentDirectory, mainLibName: 'test');
|
||||
|
||||
fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: test
|
||||
|
@ -16,6 +16,7 @@ import 'package:flutter_tools/src/build_system/targets/android.dart';
|
||||
import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fake_process_manager.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
late FakeProcessManager processManager;
|
||||
@ -552,10 +553,7 @@ void main() {
|
||||
fileSystem
|
||||
.file('pubspec.yaml')
|
||||
.writeAsStringSync('name: hello\nflutter:\n shaders:\n - shader.glsl');
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'hello');
|
||||
fileSystem.file('shader.glsl').writeAsStringSync('test');
|
||||
|
||||
processManager.addCommands(<FakeCommand>[
|
||||
|
@ -21,6 +21,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fake_process_manager.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
late Environment environment;
|
||||
@ -47,7 +48,6 @@ void main() {
|
||||
.createSync(recursive: true);
|
||||
fileSystem.file('assets/foo/bar.png').createSync(recursive: true);
|
||||
fileSystem.file('assets/wildcard/#bar.png').createSync(recursive: true);
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
@ -64,20 +64,11 @@ flutter:
|
||||
testUsingContext(
|
||||
'includes LICENSE file inputs in dependencies',
|
||||
() async {
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "file:///bar",
|
||||
"packageUri": "lib/"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'example',
|
||||
packages: <String, String>{'foo': 'bar'},
|
||||
);
|
||||
fileSystem.file('bar/LICENSE')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('THIS IS A LICENSE');
|
||||
@ -104,6 +95,7 @@ flutter:
|
||||
testUsingContext(
|
||||
'Copies files to correct asset directory',
|
||||
() async {
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'example');
|
||||
await const CopyAssets().build(environment);
|
||||
|
||||
expect(
|
||||
@ -152,6 +144,7 @@ flutter:
|
||||
flavors:
|
||||
- strawberry
|
||||
''');
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'example');
|
||||
|
||||
fileSystem.file('assets/common/image.png').createSync(recursive: true);
|
||||
fileSystem.file('assets/vanilla/ice-cream.png').createSync(recursive: true);
|
||||
@ -200,6 +193,7 @@ flutter:
|
||||
flavors:
|
||||
- strawberry
|
||||
''');
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'example');
|
||||
|
||||
fileSystem.file('assets/common/image.png').createSync(recursive: true);
|
||||
fileSystem.file('assets/vanilla/ice-cream.png').createSync(recursive: true);
|
||||
@ -251,11 +245,6 @@ flutter:
|
||||
defines: <String, String>{kBuildMode: BuildMode.debug.cliName},
|
||||
);
|
||||
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
@ -268,6 +257,8 @@ flutter:
|
||||
args: ["-a", "-b", "--color", "green"]
|
||||
''');
|
||||
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'example');
|
||||
|
||||
fileSystem.file('input.txt')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('abc');
|
||||
@ -341,11 +332,6 @@ flutter:
|
||||
defines: <String, String>{kBuildMode: BuildMode.debug.cliName},
|
||||
);
|
||||
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
@ -358,6 +344,8 @@ flutter:
|
||||
args: ["-a", "-b", "--color", "green"]
|
||||
''');
|
||||
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'example');
|
||||
|
||||
await fileSystem.file('input.txt').create(recursive: true);
|
||||
|
||||
await expectToolExitLater(
|
||||
@ -441,11 +429,6 @@ flutter:
|
||||
defines: <String, String>{kBuildMode: BuildMode.debug.cliName},
|
||||
);
|
||||
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
@ -457,6 +440,8 @@ flutter:
|
||||
- package: my_capitalizer_transformer
|
||||
''');
|
||||
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'example');
|
||||
|
||||
fileSystem.file('input.txt')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('abc');
|
||||
|
@ -17,6 +17,7 @@ import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fake_pub_deps.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
|
||||
const String _kEmptyPubspecFile = '''
|
||||
name: path_provider_example
|
||||
@ -26,40 +27,6 @@ dependencies:
|
||||
sdk: flutter
|
||||
''';
|
||||
|
||||
const String _kEmptyPackageJson = '''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "path_provider_example",
|
||||
"rootUri": "../",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.12"
|
||||
}
|
||||
]
|
||||
}
|
||||
''';
|
||||
|
||||
const String _kSamplePackageJson = '''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "path_provider_linux",
|
||||
"rootUri": "/path_provider_linux",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.12"
|
||||
},
|
||||
{
|
||||
"name": "path_provider_example",
|
||||
"rootUri": "../",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.12"
|
||||
}
|
||||
]
|
||||
}
|
||||
''';
|
||||
|
||||
const String _kSamplePubspecFile = '''
|
||||
name: path_provider_example
|
||||
description: Demonstrates how to use the path_provider plugin.
|
||||
@ -174,11 +141,15 @@ void main() {
|
||||
generateDartPluginRegistry: true,
|
||||
);
|
||||
|
||||
projectDir.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(_kSamplePackageJson);
|
||||
writePackageConfigFile(
|
||||
directory: projectDir,
|
||||
mainLibName: 'path_provider_example',
|
||||
packages: <String, String>{'path_provider_linux': '/path_provider_linux'},
|
||||
);
|
||||
|
||||
projectDir.childFile('pubspec.yaml').createSync();
|
||||
projectDir.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
name: path_provider_example
|
||||
''');
|
||||
|
||||
final FlutterProject testProject = FlutterProject.fromDirectoryTest(projectDir);
|
||||
await DartPluginRegistrantTarget.test(testProject).build(environment);
|
||||
@ -213,9 +184,12 @@ void main() {
|
||||
generateDartPluginRegistry: true,
|
||||
);
|
||||
|
||||
projectDir.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(_kSamplePackageJson);
|
||||
writePackageConfigFile(
|
||||
directory: projectDir,
|
||||
mainLibName: 'path_provider_example',
|
||||
packages: <String, String>{'path_provider_linux': '/path_provider_linux'},
|
||||
languageVersions: <String, String>{'path_provider_example': '2.12'},
|
||||
);
|
||||
|
||||
projectDir.childFile('pubspec.yaml').writeAsStringSync(_kSamplePubspecFile);
|
||||
|
||||
@ -296,10 +270,11 @@ void main() {
|
||||
},
|
||||
generateDartPluginRegistry: true,
|
||||
);
|
||||
final File config =
|
||||
projectDir.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(_kSamplePackageJson);
|
||||
writePackageConfigFile(
|
||||
directory: projectDir,
|
||||
mainLibName: 'path_provider_example',
|
||||
packages: <String, String>{'path_provider_linux': '/path_provider_linux'},
|
||||
);
|
||||
|
||||
final File pubspec = projectDir.childFile('pubspec.yaml')
|
||||
..writeAsStringSync(_kSamplePubspecFile);
|
||||
@ -321,7 +296,7 @@ void main() {
|
||||
|
||||
// Simulate a user removing everything from pubspec.yaml.
|
||||
pubspec.writeAsStringSync(_kEmptyPubspecFile);
|
||||
config.writeAsStringSync(_kEmptyPackageJson);
|
||||
writePackageConfigFile(directory: projectDir, mainLibName: 'path_provider_example');
|
||||
|
||||
await DartPluginRegistrantTarget.test(testProject).build(environment);
|
||||
expect(generatedMain.existsSync(), isFalse);
|
||||
@ -350,9 +325,11 @@ void main() {
|
||||
generateDartPluginRegistry: true,
|
||||
);
|
||||
|
||||
projectDir.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(_kSamplePackageJson);
|
||||
writePackageConfigFile(
|
||||
directory: projectDir,
|
||||
mainLibName: 'path_provider_example',
|
||||
packages: <String, String>{'path_provider_linux': '/path_provider_linux'},
|
||||
);
|
||||
|
||||
projectDir.childFile('pubspec.yaml').writeAsStringSync(_kSamplePubspecFile);
|
||||
|
||||
|
@ -20,6 +20,7 @@ import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fake_process_manager.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
|
||||
final Platform macPlatform = FakePlatform(
|
||||
operatingSystem: 'macos',
|
||||
@ -208,11 +209,8 @@ void main() {
|
||||
.file(artifacts.getArtifactPath(Artifact.isolateSnapshotData, mode: BuildMode.debug))
|
||||
.createSync();
|
||||
// Project info
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: hello');
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: my_app');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
// Plist file
|
||||
fileSystem
|
||||
.file(fileSystem.path.join('ios', 'Flutter', 'AppFrameworkInfo.plist'))
|
||||
@ -390,11 +388,8 @@ void main() {
|
||||
// Project info
|
||||
fileSystem
|
||||
.file('pubspec.yaml')
|
||||
.writeAsStringSync('name: hello\nflutter:\n shaders:\n - shader.glsl');
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
.writeAsStringSync('name: my_app\nflutter:\n shaders:\n - shader.glsl');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
// Plist file
|
||||
fileSystem
|
||||
.file(fileSystem.path.join('ios', 'Flutter', 'AppFrameworkInfo.plist'))
|
||||
@ -474,11 +469,9 @@ void main() {
|
||||
environment.defines[kXcodeAction] = 'build';
|
||||
|
||||
// Project info
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: hello');
|
||||
fileSystem
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: my_app');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
|
||||
// Plist file
|
||||
fileSystem
|
||||
.file(fileSystem.path.join('ios', 'Flutter', 'AppFrameworkInfo.plist'))
|
||||
|
@ -23,6 +23,7 @@ import '../../../src/common.dart';
|
||||
import '../../../src/fake_process_manager.dart';
|
||||
import '../../../src/fake_pub_deps.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
import '../../../src/testbed.dart';
|
||||
|
||||
const List<String> _kDart2jsLinuxArgs = <String>[
|
||||
@ -61,21 +62,16 @@ void main() {
|
||||
setUp(() {
|
||||
testbed = Testbed(
|
||||
setup: () {
|
||||
globals.fs.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../foo/",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.7"
|
||||
}
|
||||
]
|
||||
}
|
||||
globals.fs.currentDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
name: foo
|
||||
''');
|
||||
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'foo': 'foo/'},
|
||||
languageVersions: <String, String>{'foo': '2.7'},
|
||||
);
|
||||
globals.fs.currentDirectory.childDirectory('bar').createSync();
|
||||
processManager = FakeProcessManager.empty();
|
||||
globals.fs
|
||||
|
@ -26,6 +26,7 @@ import 'package:test/fake.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
|
||||
void _writeCustomDevicesConfigFile(Directory dir, List<CustomDeviceConfig> configs) {
|
||||
dir.createSync();
|
||||
@ -298,7 +299,7 @@ void main() {
|
||||
testWithoutContext('CustomDevice.isSupportedForProject is true with editable host app', () async {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
|
||||
final FlutterProject flutterProject = _setUpFlutterProject(fileSystem.currentDirectory);
|
||||
|
||||
|
@ -17,6 +17,7 @@ import 'package:flutter_tools/src/project.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
@ -750,12 +751,11 @@ exit code: 66
|
||||
'get',
|
||||
'--example',
|
||||
],
|
||||
onRun: (_) {
|
||||
fileSystem.currentDirectory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
},
|
||||
onRun:
|
||||
(_) => writePackageConfigFile(
|
||||
directory: fileSystem.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
@ -907,12 +907,11 @@ exit code: 66
|
||||
'FLUTTER_ROOT': '',
|
||||
'PUB_ENVIRONMENT': 'flutter_cli:flutter_tests',
|
||||
},
|
||||
onRun: (_) {
|
||||
fileSystem.currentDirectory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
},
|
||||
onRun:
|
||||
(_) => writePackageConfigFile(
|
||||
directory: fileSystem.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/dart/package_map.dart';
|
||||
@ -23,6 +21,7 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fake_pub_deps.dart';
|
||||
import '../src/fakes.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
// TODO(matanlurey): Remove after `explicit-package-dependencies` is enabled by default.
|
||||
@ -47,10 +46,7 @@ void main() {
|
||||
..flutterPluginsFile = directory.childFile('.flutter-plugins')
|
||||
..flutterPluginsDependenciesFile = directory.childFile('.flutter-plugins-dependencies')
|
||||
..dartPluginRegistrant = directory.childFile('dart_plugin_registrant.dart');
|
||||
flutterProject.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: flutterProject.directory, mainLibName: 'my_app');
|
||||
});
|
||||
|
||||
group('resolvePlatformImplementation', () {
|
||||
@ -1282,7 +1278,7 @@ void main() {
|
||||
'Plugin without platform support throws tool exit',
|
||||
() async {
|
||||
flutterProject.isModule = false;
|
||||
|
||||
flutterManifest.dependencies.add('url_launcher_macos');
|
||||
createFakeDartPlugins(flutterProject, flutterManifest, fs, <String, String>{
|
||||
'url_launcher_macos': '''
|
||||
flutter:
|
||||
@ -1375,6 +1371,7 @@ void main() {
|
||||
'Does not create new entrypoint if there are no platform resolutions',
|
||||
() async {
|
||||
flutterProject.isModule = false;
|
||||
createFakeDartPlugins(flutterProject, flutterManifest, fs, <String, String>{});
|
||||
|
||||
final Directory libDir = flutterProject.directory.childDirectory('lib');
|
||||
libDir.createSync(recursive: true);
|
||||
@ -1456,23 +1453,6 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
void addToPackageConfig(FlutterProject project, String name, Directory packageDir) {
|
||||
final File packageConfigFile = project.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
|
||||
final Map<String, Object?> packageConfig =
|
||||
jsonDecode(packageConfigFile.readAsStringSync()) as Map<String, Object?>;
|
||||
|
||||
(packageConfig['packages']! as List<Object?>).add(<String, Object?>{
|
||||
'name': name,
|
||||
'rootUri': packageDir.uri.toString(),
|
||||
'packageUri': 'lib/',
|
||||
});
|
||||
|
||||
packageConfigFile.writeAsStringSync(jsonEncode(packageConfig));
|
||||
}
|
||||
|
||||
void createFakeDartPlugins(
|
||||
FakeFlutterProject flutterProject,
|
||||
FakeFlutterManifest flutterManifest,
|
||||
@ -1480,21 +1460,18 @@ void createFakeDartPlugins(
|
||||
Map<String, String> plugins,
|
||||
) {
|
||||
final Directory fakePubCache = fs.systemTempDirectory.childDirectory('cache');
|
||||
|
||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..deleteSync(recursive: true)
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"packages": [],
|
||||
"configVersion": 2
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: flutterProject.directory,
|
||||
mainLibName: flutterProject.manifest.appName,
|
||||
packages: <String, String>{
|
||||
for (final String name in plugins.keys)
|
||||
name: fakePubCache.childDirectory(name).uri.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
for (final MapEntry<String, String> entry in plugins.entries) {
|
||||
final String name = fs.path.basename(entry.key);
|
||||
final Directory pluginDirectory = fakePubCache.childDirectory(name);
|
||||
addToPackageConfig(flutterProject, name, pluginDirectory);
|
||||
pluginDirectory.childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(entry.value);
|
||||
@ -1505,6 +1482,9 @@ void createFakeDartPlugins(
|
||||
class FakeFlutterManifest extends Fake implements FlutterManifest {
|
||||
@override
|
||||
Set<String> dependencies = <String>{};
|
||||
|
||||
@override
|
||||
String get appName => 'myapp';
|
||||
}
|
||||
|
||||
class FakeFlutterProject extends Fake implements FlutterProject {
|
||||
|
@ -24,6 +24,7 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fake_pub_deps.dart';
|
||||
import '../src/fakes.dart';
|
||||
import '../src/package_config.dart';
|
||||
import 'hot_shared.dart';
|
||||
|
||||
void main() {
|
||||
@ -182,14 +183,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'setupHotRestart function fails',
|
||||
() async {
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": []
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
final FakeDevice device = FakeDevice();
|
||||
final List<FlutterDevice> devices = <FlutterDevice>[FakeFlutterDevice(device)];
|
||||
final OperationResult result = await HotRunner(
|
||||
@ -217,14 +211,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'setupHotReload function fails',
|
||||
() async {
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": []
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
final FakeDevice device = FakeDevice();
|
||||
final FakeFlutterDevice fakeFlutterDevice = FakeFlutterDevice(device);
|
||||
final List<FlutterDevice> devices = <FlutterDevice>[fakeFlutterDevice];
|
||||
@ -273,14 +260,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'shutdown hook called after signal',
|
||||
() async {
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": []
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
final FakeDevice device = FakeDevice();
|
||||
final List<FlutterDevice> devices = <FlutterDevice>[
|
||||
FlutterDevice(
|
||||
@ -310,14 +290,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'shutdown hook called after app stop',
|
||||
() async {
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": []
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
final FakeDevice device = FakeDevice();
|
||||
final List<FlutterDevice> devices = <FlutterDevice>[
|
||||
FlutterDevice(
|
||||
@ -680,14 +653,7 @@ void main() {
|
||||
'Exits with code 2 when HttpException is thrown '
|
||||
'during VM service connection',
|
||||
() async {
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": []
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
|
||||
final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
|
||||
final FakeDevice device = FakeDevice();
|
||||
|
@ -37,6 +37,7 @@ import '../../src/fake_devices.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
|
||||
List<String> _xattrArgs(FlutterProject flutterProject) {
|
||||
return <String>['xattr', '-r', '-d', 'com.apple.FinderInfo', flutterProject.directory.path];
|
||||
@ -1156,8 +1157,10 @@ void main() {
|
||||
}
|
||||
|
||||
void setUpIOSProject(FileSystem fileSystem, {bool createWorkspace = true}) {
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
''');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.directory('ios').createSync();
|
||||
if (createWorkspace) {
|
||||
fileSystem.directory('ios/Runner.xcworkspace').createSync();
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
@ -28,6 +26,7 @@ import '../../src/context.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
late BufferLogger logger;
|
||||
@ -658,7 +657,9 @@ duplicate symbol '_$s29plugin_1_name23PluginNamePluginC9setDouble3key5valueySS_S
|
||||
final FakeFlutterProject project = FakeFlutterProject(fileSystem: fs);
|
||||
project.ios.podfile.createSync(recursive: true);
|
||||
project.manifest = FakeFlutterManifest();
|
||||
createFakePlugins(project, fs, <String>['plugin_1_name', 'plugin_2_name']);
|
||||
final List<String> pluginNames = <String>['plugin_1_name', 'plugin_2_name'];
|
||||
project.manifest.dependencies.addAll(pluginNames);
|
||||
createFakePlugins(project, fs, pluginNames);
|
||||
fs.systemTempDirectory
|
||||
.childFile('cache/plugin_1_name/ios/plugin_1_name/Package.swift')
|
||||
.createSync(recursive: true);
|
||||
@ -770,23 +771,6 @@ duplicate symbol '_$s29plugin_1_name23PluginNamePluginC9setDouble3key5valueySS_S
|
||||
});
|
||||
}
|
||||
|
||||
void addToPackageConfig(FlutterProject flutterProject, String name, Directory packageDir) {
|
||||
final File packageConfigFile = flutterProject.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
|
||||
final Map<String, Object?> packageConfig =
|
||||
jsonDecode(packageConfigFile.readAsStringSync()) as Map<String, Object?>;
|
||||
|
||||
(packageConfig['packages']! as List<Object?>).add(<String, Object?>{
|
||||
'name': name,
|
||||
'rootUri': packageDir.uri.toString(),
|
||||
'packageUri': 'lib/',
|
||||
});
|
||||
|
||||
packageConfigFile.writeAsStringSync(jsonEncode(packageConfig));
|
||||
}
|
||||
|
||||
void createFakePlugins(
|
||||
FlutterProject flutterProject,
|
||||
FileSystem fileSystem,
|
||||
@ -803,17 +787,15 @@ void createFakePlugins(
|
||||
''';
|
||||
|
||||
final Directory fakePubCache = fileSystem.systemTempDirectory.childDirectory('cache');
|
||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"packages": [],
|
||||
"configVersion": 2
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: flutterProject.directory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{
|
||||
for (final String name in pluginNames) name: fakePubCache.childDirectory(name).path,
|
||||
},
|
||||
);
|
||||
for (final String name in pluginNames) {
|
||||
final Directory pluginDirectory = fakePubCache.childDirectory(name);
|
||||
addToPackageConfig(flutterProject, name, pluginDirectory);
|
||||
pluginDirectory.childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(pluginYamlTemplate.replaceAll('PLUGIN_CLASS', name));
|
||||
|
@ -18,6 +18,7 @@ import 'package:native_assets_cli/code_assets_builder.dart';
|
||||
import '../../../../src/common.dart';
|
||||
import '../../../../src/context.dart';
|
||||
import '../../../../src/fakes.dart';
|
||||
import '../../../../src/package_config.dart';
|
||||
import '../../fake_native_assets_build_runner.dart';
|
||||
|
||||
void main() {
|
||||
@ -73,7 +74,7 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('NativeAssets defaults to ios archs if missing', () async {
|
||||
await createPackageConfig(iosEnvironment);
|
||||
writePackageConfigFile(directory: iosEnvironment.projectDir, mainLibName: 'my_app');
|
||||
|
||||
iosEnvironment.defines.remove(kIosArchs);
|
||||
|
||||
@ -90,7 +91,7 @@ void main() {
|
||||
'NativeAssets throws error if missing sdk root',
|
||||
overrides: <Type, Generator>{FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: true)},
|
||||
() async {
|
||||
await createPackageConfig(iosEnvironment);
|
||||
writePackageConfigFile(directory: iosEnvironment.projectDir, mainLibName: 'my_app');
|
||||
|
||||
final FlutterNativeAssetsBuildRunner buildRunner = FakeFlutterNativeAssetsBuildRunner(
|
||||
packagesWithNativeAssetsResult: <String>['foo'],
|
||||
@ -116,7 +117,7 @@ void main() {
|
||||
FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: isNativeAssetsEnabled),
|
||||
},
|
||||
() async {
|
||||
await createPackageConfig(iosEnvironment);
|
||||
writePackageConfigFile(directory: iosEnvironment.projectDir, mainLibName: 'my_app');
|
||||
|
||||
final FlutterNativeAssetsBuildRunner buildRunner = FakeFlutterNativeAssetsBuildRunner();
|
||||
await DartBuildForNative(buildRunner: buildRunner).build(iosEnvironment);
|
||||
@ -186,7 +187,7 @@ void main() {
|
||||
FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: true),
|
||||
},
|
||||
() async {
|
||||
await createPackageConfig(iosEnvironment);
|
||||
writePackageConfigFile(directory: iosEnvironment.projectDir, mainLibName: 'my_app');
|
||||
|
||||
final List<CodeAsset> codeAssets = <CodeAsset>[
|
||||
CodeAsset(
|
||||
@ -252,7 +253,7 @@ void main() {
|
||||
FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: true),
|
||||
},
|
||||
() async {
|
||||
await createPackageConfig(androidEnvironment);
|
||||
writePackageConfigFile(directory: androidEnvironment.projectDir, mainLibName: 'my_app');
|
||||
await fileSystem.file('libfoo.so').create();
|
||||
|
||||
final List<CodeAsset> codeAssets = <CodeAsset>[
|
||||
@ -279,11 +280,3 @@ void main() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createPackageConfig(Environment iosEnvironment) async {
|
||||
final File packageConfig = iosEnvironment.projectDir
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
await packageConfig.parent.create();
|
||||
await packageConfig.create();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import 'package:package_config/package_config_types.dart';
|
||||
import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
import '../fake_native_assets_build_runner.dart';
|
||||
|
||||
void main() {
|
||||
@ -103,12 +104,10 @@ void main() {
|
||||
await fileSystem.file('/some/path/to/llvm-ar').create();
|
||||
await fileSystem.file('/some/path/to/ld.lld').create();
|
||||
|
||||
final File packageConfigFile = fileSystem
|
||||
.directory(projectUri)
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
await packageConfigFile.parent.create();
|
||||
await packageConfigFile.create();
|
||||
final File packageConfigFile = writePackageConfigFile(
|
||||
directory: fileSystem.directory(projectUri),
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
packageConfigFile,
|
||||
logger: environment.logger,
|
||||
|
@ -21,6 +21,7 @@ import 'package:package_config/package_config_types.dart';
|
||||
import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
import '../fake_native_assets_build_runner.dart';
|
||||
|
||||
void main() {
|
||||
@ -388,12 +389,10 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault
|
||||
return;
|
||||
}
|
||||
|
||||
final File packageConfigFile = fileSystem
|
||||
.directory(projectUri)
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
await packageConfigFile.parent.create();
|
||||
await packageConfigFile.create();
|
||||
final File packageConfigFile = writePackageConfigFile(
|
||||
directory: fileSystem.directory(projectUri),
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
packageConfigFile,
|
||||
logger: environment.logger,
|
||||
|
@ -22,6 +22,7 @@ import 'package:package_config/package_config_types.dart';
|
||||
import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
import '../fake_native_assets_build_runner.dart';
|
||||
|
||||
void main() {
|
||||
@ -76,13 +77,9 @@ void main() {
|
||||
ProcessManager: () => FakeProcessManager.empty(),
|
||||
},
|
||||
() async {
|
||||
final File packageConfig = environment.projectDir
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
writePackageConfigFile(directory: environment.projectDir, mainLibName: 'my_app');
|
||||
final Uri nonFlutterTesterAssetUri =
|
||||
environment.buildDir.childFile(InstallCodeAssets.nativeAssetsFilename).uri;
|
||||
await packageConfig.parent.create();
|
||||
await packageConfig.create();
|
||||
final File dylibAfterCompiling = fileSystem.file('bar.dll');
|
||||
// The mock doesn't create the file, so create it here.
|
||||
await dylibAfterCompiling.create();
|
||||
@ -255,12 +252,10 @@ void main() {
|
||||
);
|
||||
await msvcBinDir.create(recursive: true);
|
||||
|
||||
final File packageConfigFile = fileSystem
|
||||
.directory(projectUri)
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
await packageConfigFile.parent.create();
|
||||
await packageConfigFile.create();
|
||||
final File packageConfigFile = writePackageConfigFile(
|
||||
directory: fileSystem.directory(projectUri),
|
||||
mainLibName: 'my_app',
|
||||
);
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
packageConfigFile,
|
||||
logger: environment.logger,
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
@ -19,6 +17,7 @@ import 'package:test/fake.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
group('processPodsIfNeeded', () {
|
||||
@ -27,7 +26,11 @@ void main() {
|
||||
late BufferLogger logger;
|
||||
|
||||
// Adds basic properties to the flutterProject and its subprojects.
|
||||
void setUpProject(FakeFlutterProject flutterProject, MemoryFileSystem fileSystem) {
|
||||
void setUpProject(
|
||||
FakeFlutterProject flutterProject,
|
||||
MemoryFileSystem fileSystem, {
|
||||
List<String> pluginNames = const <String>[],
|
||||
}) {
|
||||
flutterProject
|
||||
..manifest = FakeFlutterManifest()
|
||||
..directory = fileSystem.systemTempDirectory.childDirectory('app')
|
||||
@ -40,28 +43,11 @@ void main() {
|
||||
..android = FakeAndroidProject()
|
||||
..web = FakeWebProject()
|
||||
..windows = FakeWindowsProject()
|
||||
..linux = FakeLinuxProject();
|
||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"packages": [],
|
||||
"configVersion": 2
|
||||
}
|
||||
''');
|
||||
}
|
||||
..linux = FakeLinuxProject()
|
||||
..packageConfig = flutterProject.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
|
||||
setUp(() async {
|
||||
fs = MemoryFileSystem.test();
|
||||
cocoaPods = FakeCocoaPods();
|
||||
logger = BufferLogger.test();
|
||||
});
|
||||
|
||||
void createFakePlugins(
|
||||
FlutterProject flutterProject,
|
||||
FileSystem fileSystem,
|
||||
List<String> pluginNames,
|
||||
) {
|
||||
const String pluginYamlTemplate = '''
|
||||
flutter:
|
||||
plugin:
|
||||
@ -73,36 +59,38 @@ void main() {
|
||||
''';
|
||||
|
||||
final Directory fakePubCache = fileSystem.systemTempDirectory.childDirectory('cache');
|
||||
final File packageConfigFile = flutterProject.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')..createSync(recursive: true);
|
||||
final Map<String, Object?> packageConfig = <String, Object?>{
|
||||
'packages': <Object?>[],
|
||||
'configVersion': 2,
|
||||
};
|
||||
|
||||
writePackageConfigFile(
|
||||
directory: flutterProject.directory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{
|
||||
for (final String plugin in pluginNames)
|
||||
plugin: fakePubCache.childDirectory(plugin).uri.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
for (final String name in pluginNames) {
|
||||
flutterProject.manifest.dependencies.add(name);
|
||||
final Directory pluginDirectory = fakePubCache.childDirectory(name);
|
||||
(packageConfig['packages']! as List<Object?>).add(<String, Object?>{
|
||||
'name': name,
|
||||
'rootUri': pluginDirectory.uri.toString(),
|
||||
'packageUri': 'lib/',
|
||||
});
|
||||
pluginDirectory.childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(pluginYamlTemplate.replaceAll('PLUGIN_CLASS', name));
|
||||
}
|
||||
|
||||
packageConfigFile.writeAsStringSync(jsonEncode(packageConfig));
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
fs = MemoryFileSystem.test();
|
||||
cocoaPods = FakeCocoaPods();
|
||||
logger = BufferLogger.test();
|
||||
});
|
||||
|
||||
group('for iOS', () {
|
||||
group('using CocoaPods only', () {
|
||||
testUsingContext(
|
||||
'processes when there are plugins',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
|
||||
await processPodsIfNeeded(
|
||||
flutterProject.ios,
|
||||
@ -191,8 +179,7 @@ void main() {
|
||||
'processes if podfile exists',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
flutterProject.ios.usesSwiftPackageManager = true;
|
||||
flutterProject.ios.podfile.createSync(recursive: true);
|
||||
|
||||
@ -215,8 +202,7 @@ void main() {
|
||||
'skip if podfile does not exists',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
flutterProject.ios.usesSwiftPackageManager = true;
|
||||
|
||||
await processPodsIfNeeded(
|
||||
@ -237,8 +223,7 @@ void main() {
|
||||
'process if podfile does not exists but forceCocoaPodsOnly is true',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
flutterProject.ios.usesSwiftPackageManager = true;
|
||||
final File generatedManifestFile = flutterProject.ios.flutterPluginSwiftPackageManifest;
|
||||
generatedManifestFile.createSync(recursive: true);
|
||||
@ -277,8 +262,7 @@ void main() {
|
||||
'processes when there are plugins',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
|
||||
await processPodsIfNeeded(
|
||||
flutterProject.macos,
|
||||
@ -367,8 +351,7 @@ void main() {
|
||||
'processes if podfile exists',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
flutterProject.macos.usesSwiftPackageManager = true;
|
||||
flutterProject.macos.podfile.createSync(recursive: true);
|
||||
|
||||
@ -391,8 +374,7 @@ void main() {
|
||||
'skip if podfile does not exists',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
flutterProject.macos.usesSwiftPackageManager = true;
|
||||
|
||||
await processPodsIfNeeded(
|
||||
@ -413,8 +395,7 @@ void main() {
|
||||
'process if podfile does not exists but forceCocoaPodsOnly is true',
|
||||
() async {
|
||||
final FakeFlutterProject flutterProject = FakeFlutterProject();
|
||||
setUpProject(flutterProject, fs);
|
||||
createFakePlugins(flutterProject, fs, <String>['plugin_one', 'plugin_two']);
|
||||
setUpProject(flutterProject, fs, pluginNames: <String>['plugin_one', 'plugin_two']);
|
||||
flutterProject.macos.usesSwiftPackageManager = true;
|
||||
final File generatedManifestFile =
|
||||
flutterProject.macos.flutterPluginSwiftPackageManifest;
|
||||
@ -489,6 +470,9 @@ class FakeFlutterProject extends Fake implements FlutterProject {
|
||||
|
||||
@override
|
||||
late WindowsProject windows;
|
||||
|
||||
@override
|
||||
late File packageConfig;
|
||||
}
|
||||
|
||||
class FakeMacOSProject extends Fake implements MacOSProject {
|
||||
|
@ -23,6 +23,7 @@ import '../../src/context.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
|
||||
enum _StdioStream { stdout, stderr }
|
||||
|
||||
@ -58,10 +59,19 @@ void main() {
|
||||
}
|
||||
|
||||
FlutterProject setupProjectUnderTest() {
|
||||
fileSystem.directory('project').childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
name: my_app
|
||||
environement:
|
||||
sdk: '^3.5.0'
|
||||
''');
|
||||
|
||||
// This needs to be run within testWithoutContext and not setUp since FlutterProject uses context.
|
||||
final FlutterProject projectUnderTest = FlutterProject.fromDirectory(
|
||||
fileSystem.directory('project'),
|
||||
);
|
||||
writePackageConfigFile(directory: projectUnderTest.directory, mainLibName: 'my_app');
|
||||
projectUnderTest.ios.xcodeProject.createSync(recursive: true);
|
||||
projectUnderTest.macos.xcodeProject.createSync(recursive: true);
|
||||
return projectUnderTest;
|
||||
@ -389,11 +399,6 @@ void main() {
|
||||
'includes Pod config in xcconfig files, if the user manually added Pod dependencies without using Flutter plugins',
|
||||
() async {
|
||||
final FlutterProject projectUnderTest = setupProjectUnderTest();
|
||||
final File packageConfigFile = fileSystem.file(
|
||||
fileSystem.path.join('project', '.dart_tool', 'package_config.json'),
|
||||
);
|
||||
packageConfigFile.createSync(recursive: true);
|
||||
packageConfigFile.writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
projectUnderTest.ios.podfile
|
||||
..createSync()
|
||||
..writeAsStringSync('Custom Podfile');
|
||||
|
@ -33,6 +33,7 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fake_pub_deps.dart';
|
||||
import '../src/fakes.dart' hide FakeOperatingSystemUtils;
|
||||
import '../src/package_config.dart';
|
||||
import '../src/pubspec_schema.dart';
|
||||
|
||||
/// Information for a platform entry in the 'platforms' section of a plugin's
|
||||
@ -197,14 +198,7 @@ void main() {
|
||||
|
||||
// Add basic properties to the Flutter project and subprojects
|
||||
setUpProject(fs);
|
||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"packages": [],
|
||||
"configVersion": 2
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: flutterProject.directory, mainLibName: 'my_app');
|
||||
});
|
||||
|
||||
void addToPackageConfig(String name, Directory packageDir) {
|
||||
@ -254,14 +248,7 @@ void main() {
|
||||
|
||||
final List<Directory> directories = <Directory>[];
|
||||
final Directory fakePubCache = fileSystem.systemTempDirectory.childDirectory('cache');
|
||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"packages": [],
|
||||
"configVersion": 2
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(directory: flutterProject.directory, mainLibName: 'my_app');
|
||||
for (final String nameOrPath in pluginNamesOrPaths) {
|
||||
final String name = fileSystem.path.basename(nameOrPath);
|
||||
final Directory pluginDirectory =
|
||||
@ -1317,7 +1304,7 @@ flutter:
|
||||
|
||||
final FlutterManifest manifest =
|
||||
FlutterManifest.createFromString('''
|
||||
name: test
|
||||
name: my_app
|
||||
version: 1.0.0
|
||||
|
||||
dependencies:
|
||||
@ -1590,7 +1577,7 @@ flutter:
|
||||
|
||||
final FlutterManifest manifest =
|
||||
FlutterManifest.createFromString('''
|
||||
name: test
|
||||
name: my_app
|
||||
version: 1.0.0
|
||||
|
||||
dependencies:
|
||||
@ -1663,7 +1650,7 @@ flutter:
|
||||
|
||||
final FlutterManifest manifest =
|
||||
FlutterManifest.createFromString('''
|
||||
name: test
|
||||
name: my_app
|
||||
version: 1.0.0
|
||||
|
||||
dependencies:
|
||||
@ -2445,10 +2432,7 @@ flutter:
|
||||
..flutterPluginsDependenciesFile = dependenciesFile
|
||||
..windows = windowsProject;
|
||||
|
||||
flutterProject.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: flutterProject.directory, mainLibName: 'my_app');
|
||||
|
||||
const String dependenciesFileContents = r'''
|
||||
{
|
||||
@ -2817,10 +2801,7 @@ flutter:
|
||||
)
|
||||
..windows = windowsProject;
|
||||
|
||||
flutterProject.directory
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.createSync(recursive: true);
|
||||
writePackageConfigFile(directory: flutterProject.directory, mainLibName: 'my_app');
|
||||
|
||||
createPluginSymlinks(
|
||||
flutterProject,
|
||||
|
@ -29,6 +29,7 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fake_pub_deps.dart';
|
||||
import '../src/fakes.dart';
|
||||
import '../src/package_config.dart';
|
||||
|
||||
void main() {
|
||||
// TODO(matanlurey): Remove after `explicit-package-dependencies` is enabled by default.
|
||||
@ -1825,9 +1826,7 @@ Future<FlutterProject> someProject({
|
||||
bool includePubspec = false,
|
||||
}) async {
|
||||
final Directory directory = globals.fs.directory('some_project');
|
||||
directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
writePackageConfigFile(directory: globals.fs.currentDirectory, mainLibName: 'hello');
|
||||
if (includePubspec) {
|
||||
directory.childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
@ -1926,9 +1925,7 @@ class MyPlugin extends FluttPlugin { /* ... */ }
|
||||
|
||||
Future<FlutterProject> aModuleProject() async {
|
||||
final Directory directory = globals.fs.directory('module_project');
|
||||
directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
writePackageConfigFile(mainLibName: 'my_module', directory: directory);
|
||||
directory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_module
|
||||
flutter:
|
||||
@ -1952,9 +1949,6 @@ void _testInMemory(
|
||||
}) {
|
||||
Cache.flutterRoot = getFlutterRoot();
|
||||
final FileSystem testFileSystem = fileSystem ?? getFileSystemForPlatform();
|
||||
testFileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
||||
// Transfer needed parts of the Flutter installation folder
|
||||
// to the in-memory file system used during testing.
|
||||
final Logger logger = BufferLogger.test();
|
||||
@ -1982,27 +1976,17 @@ void _testInMemory(
|
||||
testFileSystem,
|
||||
);
|
||||
// Set up enough of the packages to satisfy the templating code.
|
||||
final File packagesFile = testFileSystem
|
||||
.directory(Cache.flutterRoot)
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools')
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
final Directory dummyTemplateImagesDirectory = testFileSystem.directory(Cache.flutterRoot).parent;
|
||||
dummyTemplateImagesDirectory.createSync(recursive: true);
|
||||
packagesFile.createSync(recursive: true);
|
||||
packagesFile.writeAsStringSync(
|
||||
json.encode(<String, Object>{
|
||||
'configVersion': 2,
|
||||
'packages': <Object>[
|
||||
<String, Object>{
|
||||
'name': 'flutter_template_images',
|
||||
'rootUri': dummyTemplateImagesDirectory.uri.toString(),
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': '2.6',
|
||||
},
|
||||
],
|
||||
}),
|
||||
writePackageConfigFile(
|
||||
directory: testFileSystem
|
||||
.directory(Cache.flutterRoot)
|
||||
.childDirectory('packages')
|
||||
.childDirectory('flutter_tools'),
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{
|
||||
'flutter_template_images': dummyTemplateImagesDirectory.uri.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
|
@ -36,6 +36,7 @@ import '../src/context.dart';
|
||||
import '../src/fake_pub_deps.dart';
|
||||
import '../src/fake_vm_services.dart';
|
||||
import '../src/fakes.dart';
|
||||
import '../src/package_config.dart';
|
||||
import '../src/testbed.dart';
|
||||
import 'resident_runner_helpers.dart';
|
||||
|
||||
@ -1087,26 +1088,18 @@ void main() {
|
||||
}
|
||||
}''');
|
||||
globals.fs.file('l10n.yaml').createSync();
|
||||
globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n generate: true\n');
|
||||
globals.fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
flutter:
|
||||
generate: true''');
|
||||
|
||||
// Create necessary files for [DartPluginRegistrantTarget]
|
||||
final File packageConfig = globals.fs
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
packageConfig.createSync(recursive: true);
|
||||
packageConfig.writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "path_provider_linux",
|
||||
"rootUri": "../../../path_provider_linux",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.12"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'path_provider_linux': 'path_provider_linux'},
|
||||
);
|
||||
|
||||
// Start from an empty dart_plugin_registrant.dart file.
|
||||
globals.fs
|
||||
.directory('.dart_tool')
|
||||
@ -1141,6 +1134,7 @@ void main() {
|
||||
}''');
|
||||
globals.fs.file('l10n.yaml').createSync();
|
||||
globals.fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
flutter:
|
||||
generate: true
|
||||
|
||||
@ -1152,23 +1146,12 @@ dependencies:
|
||||
|
||||
// Create necessary files for [DartPluginRegistrantTarget], including a
|
||||
// plugin that will trigger generation.
|
||||
final File packageConfig = globals.fs
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
packageConfig.createSync(recursive: true);
|
||||
packageConfig.writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "path_provider_linux",
|
||||
"rootUri": "../path_provider_linux",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.12"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'path_provider_linux': 'path_provider_linux'},
|
||||
);
|
||||
|
||||
final Directory fakePluginDir = globals.fs.directory('path_provider_linux');
|
||||
final File pluginPubspec = fakePluginDir.childFile('pubspec.yaml');
|
||||
pluginPubspec.createSync(recursive: true);
|
||||
|
@ -28,6 +28,7 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fake_pub_deps.dart';
|
||||
import '../src/fakes.dart';
|
||||
import '../src/package_config.dart';
|
||||
import '../src/test_build_system.dart';
|
||||
|
||||
void main() {
|
||||
@ -48,8 +49,11 @@ void main() {
|
||||
mockFlutterDevice = FakeFlutterDevice(mockWebDevice);
|
||||
mockFlutterDevice._devFS = mockWebDevFS;
|
||||
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
''');
|
||||
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
fileSystem.file(fileSystem.path.join('web', 'index.html')).createSync(recursive: true);
|
||||
});
|
||||
|
@ -45,6 +45,7 @@ import '../src/fake_process_manager.dart';
|
||||
import '../src/fake_pub_deps.dart';
|
||||
import '../src/fake_vm_services.dart';
|
||||
import '../src/fakes.dart' as test_fakes;
|
||||
import '../src/package_config.dart';
|
||||
|
||||
const List<VmServiceExpectation> kAttachLogExpectations = <VmServiceExpectation>[
|
||||
FakeVmServiceRequest(method: 'streamListen', args: <String, Object>{'streamId': 'Stdout'}),
|
||||
@ -113,7 +114,10 @@ void main() {
|
||||
.._devFS = webDevFS
|
||||
..device = mockDevice
|
||||
..generator = residentCompiler;
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
''');
|
||||
writePackageConfigFile(directory: fileSystem.currentDirectory, mainLibName: 'my_app');
|
||||
fakeAnalytics = getInitializedFakeAnalyticsInstance(
|
||||
fs: fileSystem,
|
||||
fakeFlutterVersion: test_fakes.FakeFlutterVersion(),
|
||||
@ -1381,24 +1385,15 @@ void main() {
|
||||
}''');
|
||||
globals.fs.file('l10n.yaml').createSync();
|
||||
globals.fs.file('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_app
|
||||
flutter:
|
||||
generate: true
|
||||
''');
|
||||
globals.fs.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "path_provider_linux",
|
||||
"rootUri": "../../../path_provider_linux",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.12"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'path_provider_linux': '../../path_provider_linux'},
|
||||
);
|
||||
expect(await residentWebRunner.run(), 0);
|
||||
final File generatedLocalizationsFile = globals.fs
|
||||
.directory('lib')
|
||||
@ -1422,23 +1417,12 @@ flutter:
|
||||
'Does not generate dart_plugin_registrant.dart',
|
||||
() async {
|
||||
// Create necessary files for [DartPluginRegistrantTarget]
|
||||
final File packageConfig = globals.fs
|
||||
.directory('.dart_tool')
|
||||
.childFile('package_config.json');
|
||||
packageConfig.createSync(recursive: true);
|
||||
packageConfig.writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "path_provider_linux",
|
||||
"rootUri": "../../../path_provider_linux",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.12"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: globals.fs.currentDirectory,
|
||||
mainLibName: 'my_app',
|
||||
packages: <String, String>{'path_provider_linux': '../../path_provider_linux'},
|
||||
);
|
||||
|
||||
// Start with a dart_plugin_registrant.dart file.
|
||||
globals.fs
|
||||
.directory('.dart_tool')
|
||||
|
@ -22,6 +22,7 @@ import '../../src/context.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/logging_logger.dart';
|
||||
import '../../src/package_config.dart';
|
||||
|
||||
final Platform linuxPlatform = FakePlatform(environment: <String, String>{});
|
||||
|
||||
@ -46,9 +47,13 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
name: foo
|
||||
''');
|
||||
fileSystem.file('test/foo.dart').createSync(recursive: true);
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
writePackageConfigFile(mainLibName: 'foo', directory: fileSystem.currentDirectory);
|
||||
residentCompiler = FakeResidentCompiler(fileSystem);
|
||||
logger = LoggingLogger();
|
||||
});
|
||||
@ -216,20 +221,11 @@ dependencies:
|
||||
sdk: flutter
|
||||
a_plugin: 1.0.0
|
||||
''');
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "a_plugin",
|
||||
"rootUri": "/a_plugin/",
|
||||
"packageUri": "lib/"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
writePackageConfigFile(
|
||||
directory: fileSystem.currentDirectory,
|
||||
mainLibName: 'foo',
|
||||
packages: <String, String>{'a_plugin': '/a_plugin'},
|
||||
);
|
||||
fakeDartPlugin.childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
|
@ -19,6 +19,7 @@ import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fake_pub_deps.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/package_config.dart';
|
||||
import '../../src/test_build_system.dart';
|
||||
|
||||
void main() {
|
||||
@ -48,10 +49,16 @@ void main() {
|
||||
fs: fileSystem,
|
||||
fakeFlutterVersion: flutterVersion,
|
||||
);
|
||||
fileSystem.currentDirectory.childFile('pubspec.yaml')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
name: my_app
|
||||
environement:
|
||||
sdk: '^3.5.0'
|
||||
''');
|
||||
|
||||
flutterProject = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
|
||||
|
||||
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
|
||||
writePackageConfigFile(directory: flutterProject.directory, mainLibName: 'my_app');
|
||||
});
|
||||
|
||||
testUsingContext(
|
||||
|
@ -14,6 +14,7 @@ import 'package:flutter_tools/src/features.dart';
|
||||
import '../../../src/context.dart'; // legacy
|
||||
import '../../../src/fake_pub_deps.dart';
|
||||
import '../../../src/fakes.dart';
|
||||
import '../../../src/package_config.dart';
|
||||
import '../../../src/test_build_system.dart';
|
||||
import '../../../src/test_flutter_command_runner.dart'; // legacy
|
||||
|
||||
@ -284,4 +285,9 @@ flutter:
|
||||
class UrlLauncherPlugin {}
|
||||
''');
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).writeAsStringSync('void main() { }');
|
||||
writePackageConfigFile(
|
||||
directory: fileSystem.currentDirectory,
|
||||
mainLibName: 'foo',
|
||||
packages: <String, String>{'bar': 'bar'},
|
||||
);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:file/file.dart';
|
||||
|
||||
import '../../src/package_config.dart';
|
||||
import '../test_utils.dart';
|
||||
import 'deferred_components_config.dart';
|
||||
|
||||
@ -66,7 +67,7 @@ abstract class Project {
|
||||
writeFile(fileSystem.path.join(dir.path, 'web', 'index.html'), indexHtml);
|
||||
writeFile(fileSystem.path.join(dir.path, 'web', 'flutter.js'), '');
|
||||
writeFile(fileSystem.path.join(dir.path, 'web', 'flutter_service_worker.js'), '');
|
||||
writePackageConfig(dir.path);
|
||||
writePackageConfigFile(directory: dir, mainLibName: 'test');
|
||||
await getPackages(dir.path);
|
||||
}
|
||||
|
||||
|
@ -56,21 +56,6 @@ void writeBytesFile(String path, List<int> content) {
|
||||
..writeAsBytesSync(content, flush: true);
|
||||
}
|
||||
|
||||
void writePackageConfig(String folder) {
|
||||
writeFile(fileSystem.path.join(folder, '.dart_tool', 'package_config.json'), '''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "test",
|
||||
"rootUri": "fileSystem.currentDirectory.path"
|
||||
"packageUri": "lib/",
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> getPackages(String folder) async {
|
||||
final List<String> command = <String>[
|
||||
fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter'),
|
||||
|
47
packages/flutter_tools/test/src/package_config.dart
Normal file
47
packages/flutter_tools/test/src/package_config.dart
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:file/file.dart';
|
||||
|
||||
/// Writes a `.dart_tool/package_config.json` file at [directory].
|
||||
///
|
||||
/// If directory is not specified, it will be `globals.fs.currentDirectory`;
|
||||
///
|
||||
/// It will contain a package entry for [mainLibName] with `rootUri` at
|
||||
/// [directory].
|
||||
///
|
||||
/// [otherLibs] maps other package names to their `rootUri` relative to `directory`.
|
||||
///
|
||||
/// Returns the `File` Object representing the package config.
|
||||
File writePackageConfigFile({
|
||||
required Directory directory,
|
||||
required String mainLibName,
|
||||
Map<String, String> packages = const <String, String>{},
|
||||
Map<String, String> languageVersions = const <String, String>{},
|
||||
}) {
|
||||
return directory.childDirectory('.dart_tool').childFile('package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync(
|
||||
json.encode(<String, Object?>{
|
||||
'packages': <Object>[
|
||||
<String, Object?>{
|
||||
'name': mainLibName,
|
||||
'rootUri': '../',
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': languageVersions[mainLibName] ?? '3.7',
|
||||
},
|
||||
...packages.entries.map(
|
||||
(MapEntry<String, String> entry) => <String, Object?>{
|
||||
'name': entry.key,
|
||||
'rootUri': Uri.parse('../').resolve(entry.value).toString(),
|
||||
'packageUri': 'lib/',
|
||||
'languageVersion': languageVersions[entry.key] ?? '3.7',
|
||||
},
|
||||
),
|
||||
],
|
||||
'configVersion': 2,
|
||||
}),
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user