Fix global.location.
The previous implementation would always fail on Windows. This one only
fails in edge-cases involving characters that are invalid in URIs.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f5068a5..01c0787 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
## 1.1.0
+* Set `global.location` so that `Uri.base()` works properly on Windows in most
+ cases.
+
* Define `global.export` so that it's visible to the compiled JS.
diff --git a/lib/preamble.dart b/lib/preamble.dart
index 8699f1a..a7a8764 100644
--- a/lib/preamble.dart
+++ b/lib/preamble.dart
@@ -1,7 +1,16 @@
library node_preamble;
var _NODE_PREAMBLE = r"""
- global.location = { href: "file://" + process.cwd() + "/" };
+ // TODO: This isn't really a correct transformation. For example, it will fail
+ // for paths that contain characters that need to be escaped in URLs. Once
+ // dart-lang/sdk#27979 is fixed, it should be possible to make it better.
+ global.location = {
+ href: "file://" + (function() {
+ var cwd = process.cwd();
+ if (process.platform != 'win32') return cwd;
+ return '/' + cwd.replace('\\', '/');
+ }) + "/"
+ };
global.scheduleImmediate = setImmediate;
global.self = global;
global.require = require;