Skip to content

Commit

Permalink
fix(loader): Added check for Windows OS and use appropriate path API
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Roberts committed Sep 14, 2016
1 parent 27ac59a commit e630236
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module.exports = function(source, sourcemap) {
filePath = path.join(relativeDir, filePath);
}

filePath = utils.normalizeFilePath(filePath);

if (loader === 'system') {
return utils.getSystemLoader(filePath, moduleName);
} else {
Expand Down
21 changes: 14 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var os = require('os');
var path = require('path');

function getRequireLoader(filePath, moduleName) {
module.exports.getRequireLoader = function(filePath, moduleName) {
var result = [
'loadChildren: () => new Promise(function (resolve) {\n',
' (require as any).ensure([], function (require) {\n',
Expand All @@ -10,9 +11,9 @@ function getRequireLoader(filePath, moduleName) {
];

return result.join('');
}
};

function getSystemLoader(filePath, moduleName) {
module.exports.getSystemLoader = function(filePath, moduleName) {
var result = [
'loadChildren: () => System.import(\'' + filePath + '\')\n',
' .then(function(module) {\n',
Expand All @@ -21,12 +22,18 @@ function getSystemLoader(filePath, moduleName) {
];

return result.join('');
}
};

function getFilename(resourcePath) {
module.exports.getFilename = function(resourcePath) {
var filename = path.basename(resourcePath);

return path.basename(resourcePath, path.extname(filename));
}
};

module.exports = { getRequireLoader, getSystemLoader, getFilename };
module.exports.normalizeFilePath = function(filePath) {
if (os.platform() === 'win32') {
return newPath.replace(/\//g, '\\\\');
}

return filePath;
}

0 comments on commit e630236

Please sign in to comment.