Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit d8034ca

Browse files
committed
fix Node windows support for paths
1 parent f59e09a commit d8034ca

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/system.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
var isWorker = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
1616
var isBrowser = typeof window != 'undefined' && !isWorker;
17+
var isWindows = typeof process != 'undefined' && !!process.platform.match(/^win/);
1718
var Promise = __global.Promise || require('when/es6-shim/Promise');
1819

1920
// Helpers
@@ -105,7 +106,12 @@
105106
else if (typeof require != 'undefined') {
106107
var fs;
107108
fetchTextFromURL = function(url, fulfill, reject) {
109+
if (url.substr(0, 5) != 'file:')
110+
throw 'Only file URLs of the form file: allowed running in Node.';
108111
fs = fs || require('fs');
112+
url = url.substr(5);
113+
if (isWindows)
114+
url = url.replace(/\//g, '\\');
109115
return fs.readFile(url, function(err, data) {
110116
if (err)
111117
return reject(err);
@@ -129,7 +135,9 @@
129135
this.baseURL = href.substring(0, href.lastIndexOf('/') + 1);
130136
}
131137
else if (typeof process != 'undefined' && process.cwd) {
132-
this.baseURL = process.cwd() + '/';
138+
this.baseURL = 'file:' + process.cwd() + '/';
139+
if (isWindows)
140+
this.baseURL = this.baseURL.replace(/\\/g, '/');
133141
}
134142
else {
135143
throw new TypeError('No environment baseURL');

test/test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<script src="../node_modules/when/es6-shim/Promise.js"></script>
1717

18-
<script src="../dist/es6-module-loader.src.js"></script>
18+
<script src="../dist/es6-module-loader.js"></script>
1919
<script>
2020
// test traceurOptions and anonymous errors
2121
// System.traceurOptions = { classes: false };

0 commit comments

Comments
 (0)