@@ -12,6 +12,7 @@ import '../asset.dart';
12
12
import '../base/common.dart' ;
13
13
import '../base/file_system.dart' ;
14
14
import '../base/io.dart' ;
15
+ import '../base/platform.dart' ;
15
16
import '../base/utils.dart' ;
16
17
import '../build_info.dart' ;
17
18
import '../bundle.dart' ;
@@ -61,6 +62,8 @@ class WebAssetServer {
61
62
final Map <String , Uint8List > _files = < String , Uint8List > {};
62
63
final Map <String , Uint8List > _sourcemaps = < String , Uint8List > {};
63
64
65
+ final RegExp _drivePath = RegExp (r'\/[A-Z]:\/' );
66
+
64
67
// handle requests for JavaScript source, dart sources maps, or asset files.
65
68
Future <void > _handleRequest (HttpRequest request) async {
66
69
final HttpResponse response = request.response;
@@ -79,11 +82,17 @@ class WebAssetServer {
79
82
await response.close ();
80
83
return ;
81
84
}
85
+ // TODO(jonahwilliams): better path normalization in frontend_server to remove
86
+ // this workaround.
87
+ String requestPath = request.uri.path;
88
+ if (requestPath.startsWith (_drivePath)) {
89
+ requestPath = requestPath.substring (3 );
90
+ }
82
91
83
92
// If this is a JavaScript file, it must be in the in-memory cache.
84
93
// Attempt to look up the file by URI.
85
- if (_files.containsKey (request.uri.path )) {
86
- final List <int > bytes = _files[request.uri.path ];
94
+ if (_files.containsKey (requestPath )) {
95
+ final List <int > bytes = _files[requestPath ];
87
96
response.headers
88
97
..add ('Content-Length' , bytes.length)
89
98
..add ('Content-Type' , 'application/javascript' );
@@ -93,8 +102,8 @@ class WebAssetServer {
93
102
}
94
103
// If this is a sourcemap file, then it might be in the in-memory cache.
95
104
// Attempt to lookup the file by URI.
96
- if (_sourcemaps.containsKey (request.uri.path )) {
97
- final List <int > bytes = _sourcemaps[request.uri.path ];
105
+ if (_sourcemaps.containsKey (requestPath )) {
106
+ final List <int > bytes = _sourcemaps[requestPath ];
98
107
response.headers
99
108
..add ('Content-Length' , bytes.length)
100
109
..add ('Content-Type' , 'application/json' );
@@ -193,7 +202,7 @@ class WebAssetServer {
193
202
codeStart,
194
203
codeEnd - codeStart,
195
204
);
196
- _files[filePath] = byteView;
205
+ _files[_filePathToUriFragment ( filePath) ] = byteView;
197
206
198
207
final int sourcemapStart = sourcemapOffsets[0 ];
199
208
final int sourcemapEnd = sourcemapOffsets[1 ];
@@ -206,7 +215,7 @@ class WebAssetServer {
206
215
sourcemapStart,
207
216
sourcemapEnd - sourcemapStart ,
208
217
);
209
- _sourcemaps['$filePath .map' ] = sourcemapView;
218
+ _sourcemaps['${ _filePathToUriFragment ( filePath )} .map' ] = sourcemapView;
210
219
211
220
modules.add (filePath);
212
221
}
@@ -303,15 +312,18 @@ class WebDevFS implements DevFS {
303
312
'dart_stack_trace_mapper.js' ,
304
313
));
305
314
_webAssetServer.writeFile ('/main.dart.js' , generateBootstrapScript (
306
- requireUrl: requireJS.path,
307
- mapperUrl: stackTraceMapper.path,
308
- entrypoint: '$mainPath .js' ,
315
+ requireUrl: _filePathToUriFragment ( requireJS.path) ,
316
+ mapperUrl: _filePathToUriFragment ( stackTraceMapper.path) ,
317
+ entrypoint: '${ _filePathToUriFragment ( mainPath )} .js' ,
309
318
));
310
319
_webAssetServer.writeFile ('/main_module.js' , generateMainModule (
311
- entrypoint: '$mainPath .js' ,
320
+ entrypoint: '${ _filePathToUriFragment ( mainPath )} .js' ,
312
321
));
313
322
_webAssetServer.writeFile ('/dart_sdk.js' , dartSdk.readAsStringSync ());
314
323
_webAssetServer.writeFile ('/dart_sdk.js.map' , dartSdkSourcemap.readAsStringSync ());
324
+ // TODO(jonahwilliams): refactor the asset code in this and the regular devfs to
325
+ // be shared.
326
+ await writeBundle (fs.directory (getAssetBuildDirectory ()), bundle.entries);
315
327
}
316
328
final DateTime candidateCompileTime = DateTime .now ();
317
329
if (fullRestart) {
@@ -344,6 +356,20 @@ class WebDevFS implements DevFS {
344
356
}
345
357
return UpdateFSReport (success: true , syncedBytes: codeFile.lengthSync (),
346
358
invalidatedSourcesCount: invalidatedFiles.length)
347
- ..invalidatedModules = modules;
359
+ ..invalidatedModules = modules.map (_filePathToUriFragment).toList ();
360
+ }
361
+ }
362
+
363
+ String _filePathToUriFragment (String path) {
364
+ if (platform.isWindows) {
365
+ final bool startWithSlash = path.startsWith ('/' );
366
+ final String partial = fs.path
367
+ .split (path)
368
+ .skip (startWithSlash ? 2 : 1 ).join ('/' );
369
+ if (partial.startsWith ('/' )) {
370
+ return partial;
371
+ }
372
+ return '/$partial ' ;
348
373
}
374
+ return path;
349
375
}
0 commit comments