[flutter_tools] dont allow creating package name that is invalid (#67786)
According to https://dart.dev/tools/pub/pubspec#name , uppercase is not permitted for package names.
This commit is contained in:
@@ -134,12 +134,11 @@ class CreateCommand extends FlutterCommand {
|
||||
defaultsTo: 'kotlin',
|
||||
allowed: <String>['java', 'kotlin'],
|
||||
);
|
||||
// TODO(egarciad): Remove this flag. https://github.com/flutter/flutter/issues/52363
|
||||
argParser.addFlag(
|
||||
'androidx',
|
||||
'skip-name-checks',
|
||||
help: 'integration test only parameter to allow creating applications/plugins with '
|
||||
'invalid names.',
|
||||
hide: true,
|
||||
negatable: true,
|
||||
help: 'Deprecated. Setting this flag has no effect.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -396,9 +395,11 @@ class CreateCommand extends FlutterCommand {
|
||||
}
|
||||
|
||||
final String projectName = stringArg('project-name') ?? globals.fs.path.basename(projectDirPath);
|
||||
error = _validateProjectName(projectName);
|
||||
if (error != null) {
|
||||
throwToolExit(error);
|
||||
if (!boolArg('skip-name-checks')) {
|
||||
error = _validateProjectName(projectName);
|
||||
if (error != null) {
|
||||
throwToolExit(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (boolArg('with-driver-test')) {
|
||||
@@ -889,9 +890,10 @@ const Set<String> _packageDependencies = <String>{
|
||||
'yaml',
|
||||
};
|
||||
|
||||
// A valid Dart identifier.
|
||||
// A valid Dart identifier that can be used for a package, i.e. no
|
||||
// capital letters.
|
||||
// https://dart.dev/guides/language/language-tour#important-concepts
|
||||
final RegExp _identifierRegExp = RegExp('[a-zA-Z_][a-zA-Z0-9_]*');
|
||||
final RegExp _identifierRegExp = RegExp('[a-z_][a-z0-9_]*');
|
||||
|
||||
// non-contextual dart keywords.
|
||||
//' https://dart.dev/guides/language/language-tour#keywords
|
||||
|
||||
@@ -2037,7 +2037,7 @@ void main() {
|
||||
|
||||
const String projectName = 'foo_BarBaz';
|
||||
final Directory projectDir = tempDir.childDirectory(projectName);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=linux', projectDir.path]);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=linux', '--skip-name-checks', projectDir.path]);
|
||||
final Directory platformDir = projectDir.childDirectory('linux');
|
||||
|
||||
const String classFilenameBase = 'foo_bar_baz_plugin';
|
||||
@@ -2070,7 +2070,7 @@ void main() {
|
||||
|
||||
const String projectName = 'foo_BarBaz';
|
||||
final Directory projectDir = tempDir.childDirectory(projectName);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=windows', projectDir.path]);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=windows', '--skip-name-checks', projectDir.path]);
|
||||
final Directory platformDir = projectDir.childDirectory('windows');
|
||||
|
||||
const String classFilenameBase = 'foo_bar_baz_plugin';
|
||||
|
||||
@@ -16,5 +16,7 @@ void main() {
|
||||
expect(isValidPackageName('foo_bar'), true);
|
||||
expect(isValidPackageName('_foo_bar'), true);
|
||||
expect(isValidPackageName('fizz93'), true);
|
||||
|
||||
expect(isValidPackageName('Foo_bar'), false);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user