-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(CLI-Bundler, Aliases): improve alias support
Define multiple aliases when they can be applied for a path. Closes #1093
- Loading branch information
1 parent
5d39d85
commit 19ea1ec
Showing
4 changed files
with
132 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// if moduleId is above surface (default src/), the '../../' confuses hell out of | ||
// requirejs as it tried to understand it as a relative module id. | ||
// replace '..' with '__dot_dot__' to enforce absolute module id. | ||
const toDotDot = (moduleId) => moduleId.split('/').map(p => p === '..' ? '__dot_dot__' : p).join('/'); | ||
const fromDotDot = (moduleId) => moduleId.split('/').map(p => p === '__dot_dot__' ? '..' : p).join('/'); | ||
|
||
const getAliases = (moduleId, paths) => { | ||
const aliases = []; | ||
const _moduleId = fromDotDot(moduleId); | ||
for (let i = 0, keys = Object.keys(paths); i < keys.length; i++) { | ||
let key = keys[i]; | ||
let target = paths[key]; | ||
if (key === 'root') continue; | ||
if (key === target) continue; | ||
|
||
if (_moduleId.startsWith(target + '/')) { | ||
aliases.push({ | ||
fromId: toDotDot(key + _moduleId.slice(target.length)), | ||
toId: toDotDot(moduleId) | ||
}); | ||
} | ||
} | ||
|
||
return aliases; | ||
}; | ||
|
||
module.exports = { toDotDot, fromDotDot, getAliases }; |
Oops, something went wrong.