Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
9708e7d1
Unverified
Commit
9708e7d1
authored
Dec 03, 2019
by
Jonah Williams
Committed by
GitHub
Dec 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use package-scheme imports for generated web entrypoint (#45934)
parent
3b2042a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
19 deletions
+37
-19
web.dart
packages/flutter_tools/lib/src/build_system/targets/web.dart
+17
-5
web_test.dart
...ols/test/general.shard/build_system/targets/web_test.dart
+20
-14
No files found.
packages/flutter_tools/lib/src/build_system/targets/web.dart
View file @
9708e7d1
...
...
@@ -7,6 +7,7 @@ import '../../base/file_system.dart';
import
'../../base/io.dart'
;
import
'../../base/process_manager.dart'
;
import
'../../build_info.dart'
;
import
'../../compile.dart'
;
import
'../../dart/package_map.dart'
;
import
'../../globals.dart'
;
import
'../../project.dart'
;
...
...
@@ -51,21 +52,32 @@ class WebEntrypointTarget extends Target {
final
String
targetFile
=
environment
.
defines
[
kTargetFile
];
final
bool
shouldInitializePlatform
=
environment
.
defines
[
kInitializePlatform
]
==
'true'
;
final
bool
hasPlugins
=
environment
.
defines
[
kHasWebPlugins
]
==
'true'
;
final
String
import
=
fs
.
file
(
fs
.
path
.
absolute
(
targetFile
)).
uri
.
toString
();
final
String
importPath
=
fs
.
path
.
absolute
(
targetFile
);
final
PackageUriMapper
packageUriMapper
=
PackageUriMapper
(
importPath
,
PackageMap
.
globalPackagesPath
,
null
,
null
,
);
final
Uri
mainImport
=
packageUriMapper
.
map
(
importPath
);
if
(
mainImport
==
null
)
{
throw
Exception
(
'Missing package definition for
$mainImport
'
);
}
String
contents
;
if
(
hasPlugins
)
{
final
String
generatedPath
=
environment
.
projectDir
.
childDirectory
(
'lib'
)
.
childFile
(
'generated_plugin_registrant.dart'
)
.
absolute
.
uri
.
toString
();
.
absolute
.
path
;
final
Uri
generatedImport
=
packageUriMapper
.
map
(
generatedPath
);
contents
=
'''
import '
dart:
ui
' as ui;
import '
package:
flutter_web_plugins
/
flutter_web_plugins
.
dart
';
import '
$generated
Path
';
import
"
$import
"
as entrypoint;
import '
$generated
Import
';
import
'
$mainImport
'
as entrypoint;
Future<void> main() async {
registerPlugins(webPluginRegistry);
...
...
@@ -79,7 +91,7 @@ Future<void> main() async {
contents
=
'''
import '
dart:
ui
' as ui;
import
"
$import
"
as entrypoint;
import
'
$mainImport
'
as entrypoint;
Future<void> main() async {
if (
$shouldInitializePlatform
) {
...
...
packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
View file @
9708e7d1
...
...
@@ -9,6 +9,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import
'package:flutter_tools/src/build_system/depfile.dart'
;
import
'package:flutter_tools/src/build_system/targets/dart.dart'
;
import
'package:flutter_tools/src/build_system/targets/web.dart'
;
import
'package:flutter_tools/src/dart/package_map.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
...
...
@@ -35,12 +36,17 @@ void main() {
when
(
mockWindowsPlatform
.
isLinux
).
thenReturn
(
false
);
testbed
=
Testbed
(
setup:
()
{
final
File
packagesFile
=
fs
.
file
(
fs
.
path
.
join
(
'foo'
,
'.packages'
))
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'foo:lib/
\n
'
);
PackageMap
.
globalPackagesPath
=
packagesFile
.
path
;
environment
=
Environment
(
projectDir:
fs
.
currentDirectory
,
projectDir:
fs
.
currentDirectory
.
childDirectory
(
'foo'
)
,
outputDir:
fs
.
currentDirectory
,
buildDir:
fs
.
currentDirectory
,
defines:
<
String
,
String
>{
kTargetFile:
fs
.
path
.
join
(
'lib'
,
'main.dart'
),
kTargetFile:
fs
.
path
.
join
(
'
foo'
,
'
lib'
,
'main.dart'
),
}
);
environment
.
buildDir
.
createSync
(
recursive:
true
);
...
...
@@ -57,7 +63,7 @@ void main() {
final
String
generated
=
environment
.
buildDir
.
childFile
(
'main.dart'
).
readAsStringSync
();
// Plugins
expect
(
generated
,
contains
(
"import '
file:///lib
/generated_plugin_registrant.dart';"
));
expect
(
generated
,
contains
(
"import '
package:foo
/generated_plugin_registrant.dart';"
));
expect
(
generated
,
contains
(
'registerPlugins(webPluginRegistry);'
));
// Platform
...
...
@@ -67,7 +73,7 @@ void main() {
expect
(
generated
,
contains
(
'entrypoint.main();'
));
// Import.
expect
(
generated
,
contains
(
'import "file:///lib/main.dart" as entrypoint;'
));
expect
(
generated
,
contains
(
"import 'package:foo/main.dart' as entrypoint;"
));
}));
test
(
'WebEntrypointTarget generates an entrypoint with plugins and init platform on windows'
,
()
=>
testbed
.
run
(()
async
{
...
...
@@ -78,7 +84,7 @@ void main() {
final
String
generated
=
environment
.
buildDir
.
childFile
(
'main.dart'
).
readAsStringSync
();
// Plugins
expect
(
generated
,
contains
(
"import '
file:///C:/lib
/generated_plugin_registrant.dart';"
));
expect
(
generated
,
contains
(
"import '
package:foo
/generated_plugin_registrant.dart';"
));
expect
(
generated
,
contains
(
'registerPlugins(webPluginRegistry);'
));
// Platform
...
...
@@ -88,7 +94,7 @@ void main() {
expect
(
generated
,
contains
(
'entrypoint.main();'
));
// Import.
expect
(
generated
,
contains
(
'import "file:///C:/lib/main.dart" as entrypoint;'
));
expect
(
generated
,
contains
(
"import 'package:foo/main.dart' as entrypoint;"
));
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
mockWindowsPlatform
,
}));
...
...
@@ -101,7 +107,7 @@ void main() {
final
String
generated
=
environment
.
buildDir
.
childFile
(
'main.dart'
).
readAsStringSync
();
// Plugins
expect
(
generated
,
isNot
(
contains
(
"import '
file:///lib
/generated_plugin_registrant.dart';"
)));
expect
(
generated
,
isNot
(
contains
(
"import '
package:foo
/generated_plugin_registrant.dart';"
)));
expect
(
generated
,
isNot
(
contains
(
'registerPlugins(webPluginRegistry);'
)));
// Platform
...
...
@@ -119,7 +125,7 @@ void main() {
final
String
generated
=
environment
.
buildDir
.
childFile
(
'main.dart'
).
readAsStringSync
();
// Plugins
expect
(
generated
,
contains
(
"import '
file:///lib
/generated_plugin_registrant.dart';"
));
expect
(
generated
,
contains
(
"import '
package:foo
/generated_plugin_registrant.dart';"
));
expect
(
generated
,
contains
(
'registerPlugins(webPluginRegistry);'
));
// Platform
...
...
@@ -137,7 +143,7 @@ void main() {
final
String
generated
=
environment
.
buildDir
.
childFile
(
'main.dart'
).
readAsStringSync
();
// Plugins
expect
(
generated
,
isNot
(
contains
(
"import '
file:///lib
/generated_plugin_registrant.dart';"
)));
expect
(
generated
,
isNot
(
contains
(
"import '
package:foo
/generated_plugin_registrant.dart';"
)));
expect
(
generated
,
isNot
(
contains
(
'registerPlugins(webPluginRegistry);'
)));
// Platform
...
...
@@ -162,7 +168,7 @@ void main() {
'--no-minify'
,
// but uses unminified names for debugging
'-o'
,
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
absolute
.
path
,
'--packages=
.packages
'
,
'--packages=
${fs.path.join('foo', '.packages')}
'
,
'-Ddart.vm.profile=true'
,
environment
.
buildDir
.
childFile
(
'main.dart'
).
absolute
.
path
,
];
...
...
@@ -185,7 +191,7 @@ void main() {
'-O4'
,
// highest optimizations.
'-o'
,
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
absolute
.
path
,
'--packages=
.packages
'
,
'--packages=
${fs.path.join('foo', '.packages')}
'
,
'-Ddart.vm.product=true'
,
environment
.
buildDir
.
childFile
(
'main.dart'
).
absolute
.
path
,
];
...
...
@@ -209,7 +215,7 @@ void main() {
'-O3'
,
// configured optimizations.
'-o'
,
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
absolute
.
path
,
'--packages=
.packages
'
,
'--packages=
${fs.path.join('foo', '.packages')}
'
,
'-Ddart.vm.product=true'
,
environment
.
buildDir
.
childFile
(
'main.dart'
).
absolute
.
path
,
];
...
...
@@ -252,7 +258,7 @@ void main() {
'-O4'
,
'-o'
,
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
absolute
.
path
,
'--packages=
.packages
'
,
'--packages=
${fs.path.join('foo', '.packages')}
'
,
'-Ddart.vm.product=true'
,
'-DFOO=bar'
,
'-DBAZ=qux'
,
...
...
@@ -279,7 +285,7 @@ void main() {
'--no-minify'
,
'-o'
,
environment
.
buildDir
.
childFile
(
'main.dart.js'
).
absolute
.
path
,
'--packages=
.packages
'
,
'--packages=
${fs.path.join('foo', '.packages')}
'
,
'-Ddart.vm.profile=true'
,
'-DFOO=bar'
,
'-DBAZ=qux'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment