mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] don't force service worker cache files to be absolute (#52606)
This commit is contained in:
parent
69fbbef2fe
commit
a7011c4817
@ -12,11 +12,11 @@ found in the LICENSE file. -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="apple-mobile-web-app-title" content="Flutter Gallery">
|
||||
<link rel="apple-touch-icon" href="/icons/Icon-192.png">
|
||||
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
||||
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<title>Flutter Gallery</title>
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
<link rel="manifest" href="manifest.json">
|
||||
</head>
|
||||
<body>
|
||||
<!-- This script installs service_worker.js to provide PWA functionality to
|
||||
@ -25,7 +25,7 @@ found in the LICENSE file. -->
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function () {
|
||||
navigator.serviceWorker.register('/flutter_service_worker.js');
|
||||
navigator.serviceWorker.register('flutter_service_worker.js');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
@ -340,18 +340,26 @@ class WebServiceWorker extends Target {
|
||||
.where((File file) => !file.path.endsWith('flutter_service_worker.js')
|
||||
&& !globals.fs.path.basename(file.path).startsWith('.'))
|
||||
.toList();
|
||||
// TODO(jonahwilliams): determine whether this needs to be made more efficient.
|
||||
final Map<String, String> uriToHash = <String, String>{
|
||||
for (File file in contents)
|
||||
// Do not force caching of source maps.
|
||||
if (!file.path.endsWith('main.dart.js.map'))
|
||||
'/${globals.fs.path.toUri(globals.fs.path.relative(file.path, from: environment.outputDir.path)).toString()}':
|
||||
md5.convert(await file.readAsBytes()).toString(),
|
||||
};
|
||||
|
||||
final Map<String, String> urlToHash = <String, String>{};
|
||||
for (final File file in contents) {
|
||||
// Do not force caching of source maps.
|
||||
if (file.path.endsWith('main.dart.js.map')) {
|
||||
continue;
|
||||
}
|
||||
final String url = globals.fs.path.toUri(
|
||||
globals.fs.path.relative(
|
||||
file.path,
|
||||
from: environment.outputDir.path),
|
||||
).toString();
|
||||
final String hash = md5.convert(await file.readAsBytes()).toString();
|
||||
urlToHash[url] = hash;
|
||||
}
|
||||
|
||||
final File serviceWorkerFile = environment.outputDir
|
||||
.childFile('flutter_service_worker.js');
|
||||
final Depfile depfile = Depfile(contents, <File>[serviceWorkerFile]);
|
||||
final String serviceWorker = generateServiceWorker(uriToHash);
|
||||
final String serviceWorker = generateServiceWorker(urlToHash);
|
||||
serviceWorkerFile
|
||||
.writeAsStringSync(serviceWorker);
|
||||
final DepfileService depfileService = DepfileService(
|
||||
|
@ -452,7 +452,7 @@ void main() {
|
||||
expect(environment.outputDir.childFile('flutter_service_worker.js'), exists);
|
||||
// Contains file hash.
|
||||
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
|
||||
contains('"/a/a.txt": "7fc56270e7a70fa81a5935b72eacbe29"'));
|
||||
contains('"a/a.txt": "7fc56270e7a70fa81a5935b72eacbe29"'));
|
||||
expect(environment.buildDir.childFile('service_worker.d'), exists);
|
||||
// Depends on resource file.
|
||||
expect(environment.buildDir.childFile('service_worker.d').readAsStringSync(), contains('a/a.txt'));
|
||||
|
Loading…
Reference in New Issue
Block a user